Skip to content

Commit 5c96704

Browse files
committed
commit local work
1 parent d318eeb commit 5c96704

14 files changed

Lines changed: 148 additions & 109 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77

88
jobs:
99
build:
10-
name: Build ⚙️
10+
name: build
1111
runs-on: ubuntu-latest
1212

1313
steps:
@@ -36,7 +36,7 @@ jobs:
3636
3737
test:
3838
runs-on: ubuntu-latest
39-
name: Test 🧪
39+
name: test
4040
steps:
4141
- uses: actions/checkout@v2
4242

@@ -52,7 +52,7 @@ jobs:
5252

5353
lint:
5454
runs-on: ubuntu-latest
55-
name: Lint ✔
55+
name: lint:prod
5656
steps:
5757
- uses: actions/checkout@v2
5858

.github/workflows/delete-runs.yml

Lines changed: 0 additions & 27 deletions
This file was deleted.

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
node_modules/
21
yarn-error.log
32
main.js
43
!*/**/main.js

.prettierrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"svelteSortOrder": "scripts-markup-styles",
2+
"svelteSortOrder": "options-scripts-markup-styles",
33
"plugins": ["prettier-plugin-svelte"]
44
}

release-notes.md

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/common/defaults.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@ export const RENDERER_OPTIONS: { [_ in rendererType]: string } = {
3636
image: "Image (exportable)",
3737
};
3838

39-
export const DEFAULT_FUNCTION_INPUTS: Omit<
40-
FunctionInputs,
41-
"fn" | "vector" | "r"
42-
> = {
39+
export const DEFAULT_FUNCTION_INPUTS: Omit<FunctionInputs, "fn" | "r"> = {
4340
id: "",
4441
scope: {},
4542
fnType: "linear",
@@ -48,13 +45,17 @@ export const DEFAULT_FUNCTION_INPUTS: Omit<
4845
x: null,
4946
y: null,
5047
},
48+
vector: {
49+
x: null,
50+
y: null,
51+
},
5152
range: {
5253
min: null,
5354
max: null,
5455
},
5556
skipTip: false,
5657
color: null,
57-
graphType: null,
58+
graphType: "polyline",
5859
nSamples: null,
5960
};
6061

src/common/utils.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ import type {
2020
FunctionPlotOptions,
2121
} from "function-plot/dist/types";
2222

23+
export function gcd(a: number, b: number): number {
24+
return !b ? a : gcd(b, a % b);
25+
}
26+
2327
// TODO make change to returned object reflect in input
2428
export function toFunctionPlotOptions(
2529
options: PlotInputs,
@@ -30,10 +34,7 @@ export function toFunctionPlotOptions(
3034
): FunctionPlotDatum {
3135
const output: FunctionPlotDatum = {
3236
fnType: inputs.fnType,
33-
graphType:
34-
inputs.graphType ?? ["vector", "polar"].includes(inputs.fnType)
35-
? "polyline"
36-
: undefined, // workaround for https://github.com/mauriciopoppe/function-plot/issues/224
37+
graphType: inputs.graphType ?? undefined,
3738
fn: inputs.fnType === "linear" ? inputs.fn ?? undefined : undefined,
3839
scope: inputs.scope,
3940
vector:
@@ -155,11 +156,17 @@ export function renderPlot(
155156
) {
156157
const stylingPlugin = createStylingPlugin(plugin);
157158
try {
158-
functionPlot(
159-
Object.assign({}, toFunctionPlotOptions(options, target), {
159+
const functionPlotOptions = Object.assign(
160+
{},
161+
toFunctionPlotOptions(options, target),
162+
{
160163
plugins: [stylingPlugin],
161-
})
162-
);
164+
width: 55,
165+
height: 35,
166+
}
167+
) as FunctionPlotOptions;
168+
functionPlot(functionPlotOptions);
169+
console.log(JSON.parse(JSON.stringify(functionPlotOptions)));
163170
} catch (err) {
164171
console.error(`Error rendering plot: ${err}`);
165172
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<script lang="ts">
2+
import type { ConstantInputs } from "../../common/types";
3+
import Slider from "../Primitives/Slider.svelte";
4+
5+
import Settings from "svelte-material-icons/Settings.svelte";
6+
import IconWrapper from "../Primitives/IconWrapper.svelte";
7+
import OptionsFloater from "../Primitives/OptionsFloater.svelte";
8+
import NumberInput from "../Primitives/NumberInput.svelte";
9+
10+
export let constant: ConstantInputs, name: string, showSettings: boolean;
11+
let showFloater = false;
12+
</script>
13+
14+
<div>
15+
<p>{name}</p>
16+
<Slider
17+
bind:value={constant.value}
18+
bind:min={constant.min}
19+
bind:max={constant.max}
20+
bind:step={constant.step}
21+
/>
22+
{#if showSettings}
23+
<IconWrapper
24+
on:click={() => {
25+
showFloater = true;
26+
}}
27+
>
28+
<Settings size="1.4em" />
29+
</IconWrapper>
30+
{#if showFloater}
31+
<OptionsFloater bind:show={showFloater}>
32+
<label for="constant-min">Min</label>
33+
<NumberInput placeholder="min" bind:value={constant.min} />
34+
<label for="constant-max">Max</label>
35+
<NumberInput placeholder="max" bind:value={constant.max} />
36+
<label for="constant-step">Step</label>
37+
<NumberInput placeholder="step" bind:value={constant.step} />
38+
</OptionsFloater>
39+
{/if}
40+
{/if}
41+
</div>
42+
43+
<style lang="scss">
44+
div {
45+
display: flex;
46+
flex-direction: row;
47+
gap: 0.5rem;
48+
align-items: center;
49+
}
50+
</style>

src/components/Plot/Plot.svelte

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,54 @@
11
<script lang="ts">
2-
import type { Writable } from "svelte/store";
32
import type { PlotInputs } from "../../common/types";
43
import { renderPlot } from "../../common/utils";
54
import type ObsidianFunctionPlot from "../../main";
6-
import SettingItem from "../Primitives/SettingItem.svelte";
7-
import Slider from "../Primitives/Slider.svelte";
5+
import Constant from "./Constant.svelte";
86
9-
export let optionsStore: Writable<PlotInputs>, plugin: ObsidianFunctionPlot;
7+
import Replay from "svelte-material-icons/Replay.svelte";
8+
import Button from "../Primitives/Button.svelte";
9+
10+
export let options: PlotInputs, plugin: ObsidianFunctionPlot;
1011
1112
let target: HTMLElement;
1213
1314
$: {
14-
console.log(`in reactive block: writing updated scope to all data items`);
15-
const scope = Object.entries($optionsStore.constants).reduce(
15+
const scope = Object.entries(options.constants).reduce(
1616
(acc, [key, val]) => {
1717
acc[key] = val.value;
1818
return acc;
1919
},
2020
{}
2121
);
22-
$optionsStore.data.forEach((datum) => {
22+
options.data.forEach((datum) => {
2323
datum.scope = scope;
2424
});
2525
}
26-
$: {
27-
console.log(`in reactive block: rendering plot`);
28-
console.log(JSON.parse(JSON.stringify($optionsStore)));
29-
renderPlot($optionsStore, target, plugin);
30-
}
26+
$: renderPlot(options, target, plugin);
3127
</script>
3228

3329
<div>
3430
<div class="fplot-plot" bind:this={target} />
35-
<div class="fplt-constants">
36-
{#each Object.entries($optionsStore.constants) as [key, constant]}
37-
<SettingItem name={key}>
38-
<Slider
39-
bind:value={constant.value}
40-
min={constant.min}
41-
max={constant.max}
42-
step={constant.step}
43-
/>
44-
</SettingItem>
45-
{/each}
31+
<div class="fplt-plot-options">
32+
<div class="fplt-constants">
33+
{#each Object.keys(options.constants) as name}
34+
<Constant {name} bind:constant={options.constants[name]} showSettings />
35+
{/each}
36+
</div>
37+
<Button>
38+
<Replay size="1.4em" />
39+
</Button>
4640
</div>
4741
</div>
42+
43+
<style lang="scss">
44+
.fplt-plot-options {
45+
display: grid;
46+
grid-template-columns: 1fr min-content;
47+
gap: 1em;
48+
}
49+
.fplt-constants {
50+
display: flex;
51+
flex-direction: row;
52+
gap: 0.5rem;
53+
}
54+
</style>

src/components/PlotModal/Function.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
</Dropdown>
2626

2727
{#if datum.fnType === "linear"}
28-
<TextInput placeholder="f(x)=" bind:value={datum.fn} />
28+
<TextInput placeholder="f(x)=" width="20ch" bind:value={datum.fn} />
2929
{/if}
3030

3131
{#if datum.fnType === "polar"}
32-
<TextInput placeholder="r(theta)=" bind:value={datum.r} />
32+
<TextInput placeholder="r(theta)=" width="20ch" bind:value={datum.r} />
3333
{/if}
3434

3535
{#if datum.fnType === "vector"}

0 commit comments

Comments
 (0)