Skip to content

Commit 56bf6e1

Browse files
committed
clean up and minor fixes.
1 parent 4419510 commit 56bf6e1

5 files changed

Lines changed: 44 additions & 61 deletions

File tree

src/common/utils.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function parseLaTeX(
3333
? latex
3434
: latex
3535
.replace(plugin.settings.decimalSeparator, ".")
36-
.replace("f(x)=", "")
36+
.replace(/\w+\(x\)=/, "") // Replace any function name(x)= pattern
3737
.replace(/\\frac\{([^{}]+)\}\{([^{}]+)\}/g, "($1)/($2)")
3838
.replace(/\\cdot/g, "*")
3939
.replace(/\^{([^}]*)}/g, "^($1)")
@@ -93,7 +93,10 @@ export function toFunctionPlotOptions(
9393
inputs.offset.y ?? FALLBACK_FUNCTION_INPUTS.offset.y,
9494
]
9595
: undefined,
96-
r: inputs.fnType === "polar" ? inputs.r ?? undefined : undefined,
96+
r:
97+
inputs.fnType === "polar"
98+
? parseLaTeX(inputs.r, plugin) ?? undefined
99+
: undefined,
97100
color: inputs.color ?? undefined,
98101
range:
99102
inputs.range.min || inputs.range.max

src/components/Plot/Plot.svelte

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,7 @@
9292
return;
9393
}
9494
95-
new CreatePlotModal(
96-
plugin,
97-
activeLeaf.editor,
98-
options,
99-
(options: PlotInputs, renderer: rendererType) => {
100-
insertPlot(this.plugin, this.editor, options, renderer);
101-
this.close();
102-
}
103-
).open();
95+
new CreatePlotModal(plugin, activeLeaf.editor, options).open();
10496
});
10597
});
10698
}
@@ -130,6 +122,7 @@
130122
grid-template-columns: 1fr min-content;
131123
gap: 1em;
132124
}
125+
133126
.fplt-constants {
134127
display: flex;
135128
margin-left: 2em;

src/components/PlotModal/PlotModal.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import OptionsFloater from "../Primitives/OptionsFloater.svelte";
5959
6060
onMount(async () => {
61+
// Get the currently selected text and set it as the first function
6162
const activeLeaf = plugin.app.workspace.getActiveViewOfType(MarkdownView);
6263
let selectedText = "";
6364

src/components/Primitives/Slider.svelte

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,39 @@
1414
{step}
1515
bind:value
1616
/>
17+
18+
<style>
19+
.slider {
20+
-webkit-appearance: none;
21+
appearance: none;
22+
width: 100%;
23+
height: 0.5em;
24+
background: #d3d3d3;
25+
outline: none;
26+
opacity: 0.7;
27+
-webkit-transition: 0.2s;
28+
transition: opacity 0.2s;
29+
border-radius: 0.25em;
30+
}
31+
32+
.slider:hover {
33+
opacity: 1;
34+
}
35+
36+
.slider::-webkit-slider-thumb {
37+
-webkit-appearance: none;
38+
appearance: none;
39+
width: 1em;
40+
height: 1em;
41+
cursor: pointer;
42+
border-radius: 50%;
43+
margin-top: 0.2em; /* Position the thumb on the track */
44+
}
45+
46+
.slider::-moz-range-thumb {
47+
width: 1em;
48+
height: 1em;
49+
cursor: pointer;
50+
border-radius: 50%;
51+
}
52+
</style>

src/main.ts

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -66,53 +66,3 @@ export default class ObsidianFunctionPlot extends Plugin {
6666
};
6767
}
6868
}
69-
70-
71-
/*
72-
const activeLeaf = this.app.workspace.activeLeaf;
73-
let selectedText = "";
74-
75-
if (activeLeaf) {
76-
if (activeLeaf && activeLeaf.view instanceof MarkdownView) {
77-
const editor = activeLeaf.view.editor;
78-
selectedText = editor.getSelection();
79-
80-
if (selectedText !== "") {
81-
editor.setCursor(
82-
editor.getCursor().line + 1,
83-
editor.getCursor().ch
84-
);
85-
}
86-
}
87-
}
88-
*/
89-
90-
/*
91-
plot.tip.renderer(
92-
(x: number, y: number, index: number) => {
93-
return (
94-
(plot as NameChart).names[index].replace(
95-
"x",
96-
x.toPrecision(2).toString()
97-
) +
98-
"=" +
99-
y.toPrecision(2).toString()
100-
);
101-
}
102-
);
103-
*/
104-
/*
105-
plot.tip.renderer((x: number, y: number, index: number) => {
106-
return (
107-
(plot as NameChart).names[index] +
108-
"=" +
109-
(
110-
"(" +
111-
x.toPrecision(2) +
112-
"|" +
113-
y.toPrecision(2).toString() +
114-
")"
115-
).replace(".", plugin.settings.decimal_seperator)
116-
);
117-
});
118-
*/

0 commit comments

Comments
 (0)