Skip to content

Commit 6497b99

Browse files
committed
some more features
1 parent 42b14f9 commit 6497b99

22 files changed

Lines changed: 635 additions & 452 deletions

.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
41+
run: yarn build --env production
4242

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

declaration.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
declare module '*.svelte'
1+
declare module "*.svelte";

jest.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
console.log('jest config loaded')
1+
console.log("jest config loaded");
22

33
export default {
44
roots: ["<rootDir>/src"],

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"eslint": "^8.26.0",
2424
"eslint-config-prettier": "^8.5.0",
2525
"jest": "^29.2.2",
26+
"nested-object-assign": "^1.0.4",
2627
"prettier": "^2.7.1",
2728
"sass": "^1.54.4",
2829
"sass-loader": "^13.0.2",
@@ -41,6 +42,7 @@
4142
},
4243
"dependencies": {
4344
"function-plot": "^1.23.1",
45+
"html-to-image": "^1.11.3",
4446
"obsidian": "0.16.3"
4547
}
4648
}

src/app/CreatePlotModal.ts

Lines changed: 16 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -1,170 +1,34 @@
1-
import { Editor, Modal, Setting } from "obsidian";
2-
import {
3-
DEFAULT_PLOT_OPTIONS,
4-
} from "../common/defaults";
1+
import { Editor, Modal } from "obsidian";
52
import type { PlotOptions } from "../common/types";
63
import type ObsidianFunctionPlot from "../main";
7-
import FunctionsList from "../components/CreatePlot/FunctionsList.svelte";
8-
import functionPlot from "function-plot";
4+
import PlotModal from "../components/PlotModal/PlotModal.svelte";
5+
import { DEFAULT_PLOT_INPUTS } from "../common/defaults";
6+
import { insertPlot } from "../common/utils";
97

108
export default class CreatePlotModal extends Modal {
11-
options: PlotOptions;
129
plugin: ObsidianFunctionPlot;
1310
editor: Editor;
14-
rendertarget: HTMLElement;
1511

1612
constructor(plugin: ObsidianFunctionPlot, editor: Editor) {
1713
super(plugin.app);
1814
this.plugin = plugin;
1915
this.editor = editor;
2016
}
2117

22-
reloadPreview() {
23-
if (!this.rendertarget) return;
24-
console.log(this.options)
25-
functionPlot(
26-
Object.assign({}, this.options, {target: this.rendertarget})
27-
)
28-
}
29-
3018
async onOpen() {
31-
// fix modal size
32-
document
33-
.getElementsByClassName("modal")[0]
34-
.setAttribute(
35-
"style",
36-
"width: var(--max-modal-width); height: var(--max-modal-height);"
37-
);
38-
39-
this.options = JSON.parse(JSON.stringify(DEFAULT_PLOT_OPTIONS)); // deepcopy to avoid side effects
40-
41-
const { contentEl } = this;
42-
contentEl.empty();
43-
44-
// Header
45-
contentEl.createEl("h1", { text: "Create a plot" });
46-
47-
const flex = contentEl.createDiv({
48-
attr: { style: "display: flex; align-items: center" },
49-
});
50-
51-
const settings = flex.createDiv();
52-
const preview = flex.createDiv({ attr: { style: "padding: 1em" } });
53-
this.rendertarget = preview.createDiv()
54-
55-
preview.createEl("p", {
56-
text: "Preview - Zoom is disabled while in preview",
57-
attr: {
58-
style: "margin: 0 3em; font-size: 0.8em; color: var(--text-faint)",
19+
new PlotModal({
20+
target: this.contentEl,
21+
props: {
22+
options: Object.assign(
23+
JSON.parse(JSON.stringify(DEFAULT_PLOT_INPUTS)),
24+
{ renderer: this.plugin.settings.defaultRenderer } // assign default renderer as initial dropdown state
25+
),
26+
plugin: this.plugin,
27+
submit: (options: PlotOptions) => {
28+
insertPlot(this.plugin, this.editor, options);
29+
this.close();
30+
},
5931
},
6032
});
61-
62-
new Setting(settings).setName("Title").addText((text) => {
63-
text.onChange(async (value) => {
64-
this.options.title = value;
65-
this.reloadPreview();
66-
});
67-
});
68-
69-
new Setting(settings).setName("Label X").addText((text) => {
70-
text.onChange(async (value) => {
71-
this.options.xAxis.label = value;
72-
this.reloadPreview();
73-
});
74-
});
75-
new Setting(settings).setName("Label Y").addText((text) => {
76-
text.onChange(async (value) => {
77-
this.options.yAxis.label = value;
78-
this.reloadPreview();
79-
});
80-
});
81-
82-
/*const placeholders = ["X min", "X max", "Y min", "Y max"];
83-
84-
const bounds = new Setting(settings).setName("Bounds");
85-
86-
placeholders.forEach((placeholder, i) => {
87-
bounds.addText((text) => {
88-
text
89-
.setPlaceholder(placeholder)
90-
.onChange((value) => {
91-
if (value && !isNaN(+value)) {
92-
this.options.bounds[i] = +value;
93-
this.reloadPreview();
94-
} else {
95-
this.options.bounds[i] = DEFAULT_PLOT_OPTIONS.bounds[i];
96-
this.reloadPreview();
97-
}
98-
})
99-
.inputEl.setAttribute("style", "width: 4em");
100-
});
101-
});*/
102-
103-
new Setting(settings).setName("Disable Zoom").addToggle((com) => {
104-
com.setValue(this.options.disableZoom);
105-
com.onChange(async (value) => {
106-
this.options.disableZoom = value;
107-
this.reloadPreview();
108-
});
109-
});
110-
111-
new Setting(settings).setName("Enable Grid").addToggle((com) => {
112-
com.setValue(this.options.grid);
113-
com.onChange(async (value) => {
114-
this.options.grid = value;
115-
this.reloadPreview();
116-
});
117-
});
118-
119-
const dataSetting = new Setting(settings)
120-
.setName("Data")
121-
dataSetting.settingEl.setAttribute("style", "display: block");
122-
123-
new FunctionsList({
124-
target: dataSetting.controlEl,
125-
props: {
126-
options: this.options,
127-
reloadPreview: this.reloadPreview.bind(this),
128-
}
129-
})
130-
131-
new Setting(contentEl)
132-
/*.addDropdown((com) => {
133-
com
134-
.addOptions(rendererOptions)
135-
.setValue(this.plugin.settings.defaultRenderer)
136-
.onChange((value: rendererType) => {
137-
this.renderer = value;
138-
});
139-
})*/
140-
.addButton((btn) => {
141-
btn
142-
.setButtonText("Plot")
143-
.setCta()
144-
.onClick(async () => {
145-
// await this.handleFinalPlotCreate(this.options);
146-
});
147-
});
148-
}
149-
150-
/*
151-
async handleFinalPlotCreate(options: PlotOptions) {
152-
// render and insert chosen plot using renderer
153-
switch ("interactive") {
154-
case "interactive":
155-
renderPlotAsInteractive(this.plugin, this.editor, options);
156-
break;
157-
/*
158-
case "image":
159-
await renderPlotAsImage(this.plugin, this.editor, options);
160-
break; *//*
161-
}
162-
163-
this.close();
164-
}
165-
*/
166-
167-
onClose() {
168-
this.contentEl.empty();
16933
}
17034
}

src/app/SettingsTab.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import {
66
ValueComponent,
77
} from "obsidian";
88
import type ObsidianFunctionPlot from "../main.js";
9-
import { DEFAULT_PLUGIN_SETTINGS } from "../common/defaults";
10-
import type { PluginSettings } from "../common/types";
9+
import { DEFAULT_PLUGIN_SETTINGS, rendererOptions } from "../common/defaults";
10+
import type { PluginSettings, rendererType } from "../common/types";
1111

1212
export default class SettingsTab extends PluginSettingTab {
1313
plugin: ObsidianFunctionPlot;
@@ -30,7 +30,6 @@ export default class SettingsTab extends PluginSettingTab {
3030
*/
3131

3232
containerEl.createEl("h3", { text: "Default Plot Options" });
33-
/*
3433
new Setting(containerEl)
3534
.setName("Default Render Type")
3635
.setDesc("The default renderer to use.")
@@ -44,7 +43,7 @@ export default class SettingsTab extends PluginSettingTab {
4443
await this.plugin.saveSettings();
4544
});
4645
});
47-
*/
46+
4847
/*
4948
* Font Sizes
5049
*/
@@ -200,7 +199,6 @@ export default class SettingsTab extends PluginSettingTab {
200199
input.setValue(this.plugin.settings[key]);
201200
}
202201
this.plugin.saveSettings();
203-
// skipcq: JS-0078
204202
new Notice("Settings reset to default");
205203
});
206204
});

0 commit comments

Comments
 (0)