svelte-plotly.js 0.5.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -11
- package/dist/Plot.svelte +16 -5
- package/dist/Plot.svelte.d.ts +39 -9
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -58,17 +58,18 @@ If you don't use Vite, or this approach doesn't work for you, you can also use t
|
|
|
58
58
|
|
|
59
59
|
## Properties
|
|
60
60
|
|
|
61
|
-
| Prop
|
|
62
|
-
|
|
|
63
|
-
| **required `data`**
|
|
64
|
-
| `layout`
|
|
65
|
-
| `config`
|
|
66
|
-
| `class`
|
|
67
|
-
| `fillParent`
|
|
68
|
-
| `debounce`
|
|
69
|
-
| `libPlotly`
|
|
70
|
-
| `
|
|
71
|
-
| `bind:
|
|
61
|
+
| Prop | Type | Description |
|
|
62
|
+
| -------------------------- | -------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
63
|
+
| **required `data`** | `Data[]` | array of trace data, see https://plot.ly/javascript/reference/ |
|
|
64
|
+
| `layout` | `Partial<Layout>` | layout of the plot, see https://plot.ly/javascript/reference/#layout |
|
|
65
|
+
| `config` | `Partial<Config>` | configuration, see https://plot.ly/javascript/configuration-options/ |
|
|
66
|
+
| `class` | `string` | class that will be passed to the HTML element wrapping the plot |
|
|
67
|
+
| `fillParent` | `boolean \| 'width' \| 'height'` | automatically resize the plot to fill the width and/or height of its parent element |
|
|
68
|
+
| `debounce` | `number \| DebounceOptions` | debounce all changes to the plot |
|
|
69
|
+
| `libPlotly` | `Plotly \| null \| undefined` | an alternative Plotly bundle to use; if undefined, it defaults to the `plotly.js-dist` package; if null, no plot will be drawn and no library will be downloaded |
|
|
70
|
+
| `configReactivityStrategy` | `'none' \| 'static-plot'` | walkaround for an [upstream bug](https://github.com/m93a/svelte-plotly.js/issues/10) causing `config` not to update, enabled by default |
|
|
71
|
+
| `bind:element` | `HTMLDivElement` | the HTML element wrapping the plot |
|
|
72
|
+
| `bind:plot` | `PlotlyHTMLElement` | the inner HTML element containing the plot |
|
|
72
73
|
|
|
73
74
|
## Events
|
|
74
75
|
|
package/dist/Plot.svelte
CHANGED
|
@@ -65,6 +65,7 @@ export let layout = void 0;
|
|
|
65
65
|
export let config = void 0;
|
|
66
66
|
export let fillParent = false;
|
|
67
67
|
export let debounce = 0;
|
|
68
|
+
export let configReactivityStrategy = "static-plot";
|
|
68
69
|
let className = "";
|
|
69
70
|
export { className as class };
|
|
70
71
|
onMount(async () => {
|
|
@@ -81,7 +82,8 @@ $: debounceOptions = typeof debounce === "object" ? debounce : {};
|
|
|
81
82
|
$: data, datarevision = (datarevision + 1) % 1e3;
|
|
82
83
|
$: layout_ = { datarevision, width, height, ...layout };
|
|
83
84
|
$: config_ = { displaylogo: false, ...config };
|
|
84
|
-
|
|
85
|
+
let configUpdated = false;
|
|
86
|
+
$: config_, configUpdated = true;
|
|
85
87
|
$: {
|
|
86
88
|
if (element && previousLib !== libPlotly) {
|
|
87
89
|
previousLib?.purge(element);
|
|
@@ -97,16 +99,25 @@ $: if (previousPlot !== plot) {
|
|
|
97
99
|
}
|
|
98
100
|
previousPlot = plot;
|
|
99
101
|
}
|
|
100
|
-
const drawUndebounced = (
|
|
101
|
-
if (
|
|
102
|
+
const drawUndebounced = async () => {
|
|
103
|
+
if (!libPlotly || !element) return;
|
|
104
|
+
if (configUpdated && configReactivityStrategy === "static-plot") {
|
|
105
|
+
configUpdated = false;
|
|
106
|
+
await libPlotly.react(element, data, layout_, {
|
|
107
|
+
...config_,
|
|
108
|
+
staticPlot: !config_.staticPlot
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
plot = await libPlotly.react(element, data, layout_, config_);
|
|
102
112
|
};
|
|
103
113
|
$: draw = debouncify(drawUndebounced, debounceWait, debounceOptions);
|
|
114
|
+
$: libPlotly, element, data, layout_, config_, configUpdated, draw();
|
|
104
115
|
onDestroy(() => element && libPlotly?.purge(element));
|
|
105
116
|
$: fillParent, nextFrame(onResize);
|
|
106
117
|
$: fillParentWidth = fillParent === true || fillParent === "width";
|
|
107
118
|
$: fillParentHeight = fillParent === true || fillParent === "height";
|
|
108
|
-
$: parent = element?.parentElement;
|
|
109
|
-
let lastParent =
|
|
119
|
+
$: parent = element?.parentElement ?? void 0;
|
|
120
|
+
let lastParent = void 0;
|
|
110
121
|
$: {
|
|
111
122
|
parentMounted(parent);
|
|
112
123
|
parentUnmounted(lastParent);
|
package/dist/Plot.svelte.d.ts
CHANGED
|
@@ -17,15 +17,45 @@ export interface PlotUpdateEvent {
|
|
|
17
17
|
}
|
|
18
18
|
declare const __propDef: {
|
|
19
19
|
props: {
|
|
20
|
-
element?: HTMLDivElement |
|
|
21
|
-
plot?: PlotlyHTMLElement |
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
/** The HTML element wrapping the plot. */ element?: HTMLDivElement | undefined;
|
|
21
|
+
/** The inner HTML element containing the plot. */ plot?: PlotlyHTMLElement | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Alternative Plotly bundle to use. If `undefined`, it defaults to
|
|
24
|
+
* the `plotly.js-dist` package; if null, no plot will be drawn and
|
|
25
|
+
* no library will be downloaded.
|
|
26
|
+
*/ libPlotly?: typeof import("plotly.js-dist") | null | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Array of trace data, see https://plot.ly/javascript/reference/
|
|
29
|
+
*/ data: Data[];
|
|
30
|
+
/**
|
|
31
|
+
* Layout of the plot, see https://plot.ly/javascript/reference/#layout
|
|
32
|
+
*/ layout?: Partial<Layout> | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Configuration, see https://plot.ly/javascript/configuration-options/
|
|
35
|
+
*/ config?: Partial<Config> | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* Automatically resize the plot to fill the width and/or
|
|
38
|
+
* height of its parent element.
|
|
39
|
+
*/ fillParent?: FillParent;
|
|
40
|
+
/**
|
|
41
|
+
* Debounce all changes to the plot.
|
|
42
|
+
*/ debounce?: number | DebounceOptions;
|
|
43
|
+
/**
|
|
44
|
+
* Because of an [upstream bug](https://github.com/m93a/svelte-plotly.js/issues/10),
|
|
45
|
+
* changes in the `config` prop don't always render.
|
|
46
|
+
* This prop enables a walkaround, which makes sure
|
|
47
|
+
* that changes in `config` just work.
|
|
48
|
+
*
|
|
49
|
+
* - `'static-plot'` – when changing `config`, briefly disable
|
|
50
|
+
* chart interactivity to force update
|
|
51
|
+
*
|
|
52
|
+
* - `'none'` – disable the walkaround; updating mode bar
|
|
53
|
+
* buttons might not work
|
|
54
|
+
*/ configReactivityStrategy?: "none" | "static-plot";
|
|
55
|
+
/**
|
|
56
|
+
* Class attribute that will be passed to the HTML element
|
|
57
|
+
* wrapping the plot
|
|
58
|
+
*/ class?: string;
|
|
29
59
|
};
|
|
30
60
|
slots: {};
|
|
31
61
|
events: {
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED