|
1 | 1 | <script lang="ts"> |
2 | | - import type { Writable } from "svelte/store"; |
3 | 2 | import type { PlotInputs } from "../../common/types"; |
4 | 3 | import { renderPlot } from "../../common/utils"; |
5 | 4 | 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"; |
8 | 6 |
|
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; |
10 | 11 |
|
11 | 12 | let target: HTMLElement; |
12 | 13 |
|
13 | 14 | $: { |
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( |
16 | 16 | (acc, [key, val]) => { |
17 | 17 | acc[key] = val.value; |
18 | 18 | return acc; |
19 | 19 | }, |
20 | 20 | {} |
21 | 21 | ); |
22 | | - $optionsStore.data.forEach((datum) => { |
| 22 | + options.data.forEach((datum) => { |
23 | 23 | datum.scope = scope; |
24 | 24 | }); |
25 | 25 | } |
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); |
31 | 27 | </script> |
32 | 28 |
|
33 | 29 | <div> |
34 | 30 | <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> |
46 | 40 | </div> |
47 | 41 | </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> |
0 commit comments