svelte-plotly.js 0.5.1 → 1.1.0-rc1

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 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 | 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
- | `bind:element` | `HTMLDivElement` | the HTML element wrapping the plot |
71
- | `bind:plot` | `PlotlyHTMLElement` | the inner HTML element containing the plot |
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
- $: draw(libPlotly, element, data, layout_, config_);
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 = (lib, e, d, l, c) => {
101
- if (e) lib?.react(e, d, l, c).then((p) => plot = p);
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 = null;
119
+ $: parent = element?.parentElement ?? void 0;
120
+ let lastParent = void 0;
110
121
  $: {
111
122
  parentMounted(parent);
112
123
  parentUnmounted(lastParent);
@@ -17,55 +17,89 @@ export interface PlotUpdateEvent {
17
17
  }
18
18
  declare const __propDef: {
19
19
  props: {
20
- element?: HTMLDivElement | (null | undefined);
21
- plot?: PlotlyHTMLElement | (null | undefined);
22
- libPlotly?: typeof import("plotly.js-dist") | null | undefined;
23
- data: Data[];
24
- layout?: Partial<Layout> | undefined;
25
- config?: Partial<Config> | undefined;
26
- fillParent?: FillParent;
27
- debounce?: number | DebounceOptions;
28
- class?: string;
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
- slots: {};
31
60
  events: {
32
- afterExport: undefined;
33
- afterPlot: undefined;
34
- animated: undefined;
35
- animating: undefined;
36
- animatingFrame: FrameAnimationEvent;
37
- animationInterrupted: undefined;
38
- autoSize: undefined;
39
- beforeExport: undefined;
40
- beforeHover: PlotMouseEvent;
41
- beforePlot: BeforePlotEvent;
42
- buttonClicked: ButtonClickedEvent;
43
- click: PlotMouseEvent;
44
- clickAnnotation: ClickAnnotationEvent;
45
- deselect: undefined;
46
- doubleClick: undefined;
47
- framework: undefined;
48
- hover: PlotHoverEvent;
49
- legendClick: LegendClickEvent;
50
- legendDoubleClick: LegendClickEvent;
51
- react: PlotUpdateEvent;
52
- redraw: undefined;
53
- relayout: PlotRelayoutEvent;
54
- relayouting: PlotRelayoutEvent;
55
- restyle: PlotRestyleEvent;
56
- selected: PlotSelectionEvent;
57
- selecting: PlotSelectionEvent;
58
- sliderChange: SliderChangeEvent;
59
- sliderEnd: SliderEndEvent;
60
- sliderStart: SliderStartEvent;
61
- sunburstClick: SunburstClickEvent;
62
- transitioned: undefined;
63
- transitioning: undefined;
64
- transitionInterrupted: undefined;
65
- unhover: PlotMouseEvent;
66
- update: PlotUpdateEvent;
67
- webGLContextLost: undefined;
61
+ afterExport: CustomEvent<undefined>;
62
+ afterPlot: CustomEvent<undefined>;
63
+ animated: CustomEvent<undefined>;
64
+ animating: CustomEvent<undefined>;
65
+ animatingFrame: CustomEvent<FrameAnimationEvent>;
66
+ animationInterrupted: CustomEvent<undefined>;
67
+ autoSize: CustomEvent<undefined>;
68
+ beforeExport: CustomEvent<undefined>;
69
+ beforeHover: CustomEvent<PlotMouseEvent>;
70
+ beforePlot: CustomEvent<BeforePlotEvent>;
71
+ buttonClicked: CustomEvent<ButtonClickedEvent>;
72
+ click: CustomEvent<PlotMouseEvent>;
73
+ clickAnnotation: CustomEvent<ClickAnnotationEvent>;
74
+ deselect: CustomEvent<undefined>;
75
+ doubleClick: CustomEvent<undefined>;
76
+ framework: CustomEvent<undefined>;
77
+ hover: CustomEvent<PlotHoverEvent>;
78
+ legendClick: CustomEvent<LegendClickEvent>;
79
+ legendDoubleClick: CustomEvent<LegendClickEvent>;
80
+ react: CustomEvent<PlotUpdateEvent>;
81
+ redraw: CustomEvent<undefined>;
82
+ relayout: CustomEvent<PlotRelayoutEvent>;
83
+ relayouting: CustomEvent<PlotRelayoutEvent>;
84
+ restyle: CustomEvent<PlotRestyleEvent>;
85
+ selected: CustomEvent<PlotSelectionEvent>;
86
+ selecting: CustomEvent<PlotSelectionEvent>;
87
+ sliderChange: CustomEvent<SliderChangeEvent>;
88
+ sliderEnd: CustomEvent<SliderEndEvent>;
89
+ sliderStart: CustomEvent<SliderStartEvent>;
90
+ sunburstClick: CustomEvent<SunburstClickEvent>;
91
+ transitioned: CustomEvent<undefined>;
92
+ transitioning: CustomEvent<undefined>;
93
+ transitionInterrupted: CustomEvent<undefined>;
94
+ unhover: CustomEvent<PlotMouseEvent>;
95
+ update: CustomEvent<PlotUpdateEvent>;
96
+ webGLContextLost: CustomEvent<undefined>;
97
+ } & {
98
+ [evt: string]: CustomEvent<any>;
68
99
  };
100
+ slots: {};
101
+ exports?: {} | undefined;
102
+ bindings?: string | undefined;
69
103
  };
70
104
  export type PlotProps = typeof __propDef.props;
71
105
  export type PlotEvents = typeof __propDef.events;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-plotly.js",
3
- "version": "0.5.1",
3
+ "version": "1.1.0-rc1",
4
4
  "author": {
5
5
  "name": "Michal Grňo (m93a)",
6
6
  "url": "https://github.com/m93a/"