Skip to content

Commit 8524c7c

Browse files
committed
a bunch of changes. currently working on grid layout for create modal
1 parent 6497b99 commit 8524c7c

18 files changed

Lines changed: 505 additions & 263 deletions

.eslintrc.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
"rules": {
1818
"no-unused-vars": "error",
1919
"@typescript-eslint/no-unused-vars": "off",
20-
"no-use-before-define": "warn"
20+
"no-use-before-define": "warn",
21+
"eqeqeq": "error",
22+
"no-console": "warn"
2123
}
2224
}

.eslintrc.prod.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": ["./.eslintrc.json"],
3+
"rules": {
4+
"no-console": "error"
5+
}
6+
}

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
git push origin master
3939
4040
- name: Build
41-
run: yarn build --env production
41+
run: yarn build:prod
4242

4343
- name: Upload assets to a Release
4444
uses: AButler/upload-release-assets@v2.0

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
node_modules/
22
yarn-error.log
33
main.js
4+
!*/**/main.js
45
data.json
56
package-lock.json
67
.nyc_output

jest.config.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
console.log("jest config loaded");
2-
31
export default {
42
roots: ["<rootDir>/src"],
53
testMatch: ["**/__tests__/**/*.+(ts)"],

package.json

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,33 @@
88
"license": "MIT",
99
"private": true,
1010
"scripts": {
11-
"build": "webpack",
11+
"build:prod": "yarn lint -c .eslintrc.prod.json && webpack --env=production",
12+
"build": "yarn lint && webpack",
1213
"test": "jest",
1314
"format": "yarn prettier --write .",
14-
"lint": "yarn eslint ."
15+
"lint": "yarn eslint .",
16+
"storybook": "start-storybook -p 6006",
17+
"build-storybook": "build-storybook"
1518
},
1619
"devDependencies": {
20+
"@babel/core": "^7.20.12",
1721
"@tsconfig/svelte": "^3.0.0",
1822
"@types/jest": "^29.2.3",
1923
"@types/node": "*",
2024
"@typescript-eslint/eslint-plugin": "^5.41.0",
2125
"@typescript-eslint/parser": "^5.41.0",
26+
"babel-loader": "^8.3.0",
2227
"css-loader": "^6.7.3",
2328
"eslint": "^8.26.0",
2429
"eslint-config-prettier": "^8.5.0",
30+
"eslint-plugin-storybook": "^0.6.10",
2531
"jest": "^29.2.2",
2632
"nested-object-assign": "^1.0.4",
2733
"prettier": "^2.7.1",
28-
"sass": "^1.54.4",
34+
"sass": "^1.58.0",
2935
"sass-loader": "^13.0.2",
3036
"style-loader": "^3.3.1",
31-
"svelte": "^3.53.1",
37+
"svelte": "^3.55.1",
3238
"svelte-loader": "^3.1.4",
3339
"svelte-material-icons": "^2.0.4",
3440
"svelte-preprocess": "^4.10.7",

src/app/CreatePlotModal.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Editor, Modal } from "obsidian";
2-
import type { PlotOptions } from "../common/types";
2+
import type { PlotInputs } from "../common/types";
33
import type ObsidianFunctionPlot from "../main";
44
import PlotModal from "../components/PlotModal/PlotModal.svelte";
55
import { DEFAULT_PLOT_INPUTS } from "../common/defaults";
@@ -16,15 +16,18 @@ export default class CreatePlotModal extends Modal {
1616
}
1717

1818
async onOpen() {
19+
this.titleEl.setText("Create a Plot");
20+
this.modalEl.addClass("fplt-modal");
21+
// attach svelte PlotModal component
1922
new PlotModal({
2023
target: this.contentEl,
2124
props: {
2225
options: Object.assign(
2326
JSON.parse(JSON.stringify(DEFAULT_PLOT_INPUTS)),
24-
{ renderer: this.plugin.settings.defaultRenderer } // assign default renderer as initial dropdown state
27+
{ renderer: this.plugin.settings.defaultRenderer } // assign default renderer as initial dropdown state
2528
),
2629
plugin: this.plugin,
27-
submit: (options: PlotOptions) => {
30+
submit: (options: PlotInputs) => {
2831
insertPlot(this.plugin, this.editor, options);
2932
this.close();
3033
},

src/common/defaults.ts

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type {
2-
FunctionOptions,
3-
PlotOptions,
2+
FunctionInputs,
3+
PlotInputs,
44
PluginSettings,
55
rendererType,
66
} from "./types";
@@ -25,65 +25,50 @@ export const DEFAULT_PLUGIN_SETTINGS: PluginSettings = {
2525
defaultRenderer: "interactive",
2626
};
2727

28-
export const FALLBACK_FUNCTION_OPTIONS: Partial<FunctionOptions> = {
29-
range: {
30-
min: -Infinity,
31-
max: Infinity,
32-
},
28+
/**
29+
* The options displayed for renderers
30+
*/
31+
// eslint-disable-next-line no-unused-vars
32+
export const rendererOptions: { [_ in rendererType]: string } = {
33+
interactive: "Interactive (zoomable)",
34+
image: "Image (exportable)",
3335
};
3436

35-
export const DEFAULT_FUNCTION_INPUTS: FunctionOptions = {
37+
export const DEFAULT_FUNCTION_INPUTS: FunctionInputs = {
3638
id: null,
37-
fnType: "linear", // always set by the plugin
38-
fn: "", // error if missing, no fallback
39+
fnType: undefined, // always set by the plugin
40+
fn: undefined, // error if missing, no fallback
3941
vector: {
40-
x: null,
41-
y: null,
42+
x: undefined,
43+
y: undefined,
4244
}, // error if missing, no fallback
43-
r: "", // error if missing, no fallback
44-
color: "#808080",
45+
r: undefined, // error if missing, no fallback
46+
color: null, // set by color generator. fallback value is gray
4547
offset: {
46-
x: null,
47-
y: null,
48+
x: undefined,
49+
y: undefined,
4850
},
4951
closed: false,
50-
graphType: null,
52+
graphType: undefined,
5153
range: {
52-
min: null,
53-
max: null,
54+
min: undefined,
55+
max: undefined,
5456
},
55-
nSamples: null,
57+
nSamples: undefined,
5658
skipTip: false,
5759
};
5860

59-
/**
60-
* The options displayed for renderers
61-
*/
62-
// eslint-disable-next-line no-unused-vars
63-
export const rendererOptions: { [_ in rendererType]: string } = {
64-
interactive: "Interactive (zoomable)",
65-
image: "Image (exportable)",
66-
};
67-
68-
export const FALLBACK_PLOT_OPTIONS: Partial<PlotOptions> = {
69-
xAxis: {
70-
domain: {
71-
min: -10,
72-
max: 10,
73-
},
74-
},
75-
yAxis: {
76-
domain: {
77-
min: -10,
78-
max: 10,
79-
},
61+
export const FALLBACK_FUNCTION_INPUTS: Partial<FunctionInputs> = {
62+
range: {
63+
min: -Infinity,
64+
max: Infinity,
8065
},
8166
};
8267

8368
/**
8469
* The default options for a plot.
8570
*/
86-
export const DEFAULT_PLOT_INPUTS: PlotOptions = {
71+
export const DEFAULT_PLOT_INPUTS: PlotInputs = {
8772
target: null, // set by rendering function
8873
renderer: null, // has initial state controlled by plugin.settings.defaultRenderer
8974
title: null,
@@ -102,3 +87,18 @@ export const DEFAULT_PLOT_INPUTS: PlotOptions = {
10287
disableZoom: false,
10388
data: [],
10489
};
90+
91+
export const FALLBACK_PLOT_INPUTS: Partial<PlotInputs> = {
92+
xAxis: {
93+
domain: {
94+
min: -10,
95+
max: 10,
96+
},
97+
},
98+
yAxis: {
99+
domain: {
100+
min: -10,
101+
max: 10,
102+
},
103+
},
104+
};

src/common/types.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import type { Chart } from "function-plot";
22
import type { EventEmitter } from "events";
3+
import type {
4+
FunctionPlotDatum,
5+
FunctionPlotOptions,
6+
} from "function-plot/dist/types";
37

48
export type rendererType = "interactive" | "image";
59

@@ -8,9 +12,9 @@ export type rendererType = "interactive" | "image";
812
*/
913
export type chartType = Chart & EventEmitter;
1014

11-
export interface FunctionOptions {
15+
export interface FunctionInputs {
1216
id: string;
13-
fnType: string;
17+
fnType: (FunctionPlotDatum["fnType"] & "linear") | "vector" | "polar";
1418
fn?: string;
1519
vector?: {
1620
x: number;
@@ -26,18 +30,18 @@ export interface FunctionOptions {
2630
min: number;
2731
max: number;
2832
};
29-
graphType?: string;
33+
graphType?: FunctionPlotDatum["graphType"];
3034
nSamples?: number;
3135
closed?: boolean;
3236
skipTip?: boolean;
3337
}
3438
/**
3539
* An interface specifying the options for a plot.
3640
*/
37-
export interface PlotOptions {
38-
data: FunctionOptions[];
41+
export interface PlotInputs {
42+
data: FunctionInputs[];
3943
renderer: rendererType;
40-
target: HTMLElement | Node | string;
44+
target: FunctionPlotOptions["target"];
4145
xAxis?: {
4246
label?: string;
4347
domain?: {

0 commit comments

Comments
 (0)