svelte-plotly.js 0.1.5 → 0.2.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/Plot.svelte +54 -4
- package/Plot.svelte.d.ts +51 -5
- package/README.md +2 -1
- package/package.json +3 -3
package/Plot.svelte
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
<script context="module">export {};
|
|
2
2
|
</script>
|
|
3
3
|
|
|
4
|
-
<script>import { onMount, onDestroy } from 'svelte';
|
|
5
|
-
import { debounce as debouncify } from 'lodash';
|
|
4
|
+
<script>import { onMount, onDestroy, createEventDispatcher } from 'svelte';
|
|
5
|
+
import { debounce as debouncify } from 'lodash-es';
|
|
6
6
|
const browser = typeof window === 'object';
|
|
7
7
|
const nextFrame = browser ? requestAnimationFrame : () => void 0;
|
|
8
8
|
async function loadPlotly() {
|
|
@@ -16,6 +16,46 @@ async function loadPlotly() {
|
|
|
16
16
|
}
|
|
17
17
|
const DEFAULT_WIDTH = 500;
|
|
18
18
|
const DEFAULT_HEIGHT = 300;
|
|
19
|
+
const events = {
|
|
20
|
+
plotly_afterexport: 'afterExport',
|
|
21
|
+
plotly_afterplot: 'afterPlot',
|
|
22
|
+
plotly_animated: 'animated',
|
|
23
|
+
plotly_animating: 'animating',
|
|
24
|
+
plotly_animatingframe: 'animatingFrame',
|
|
25
|
+
plotly_animationinterrupted: 'animationInterrupted',
|
|
26
|
+
plotly_autosize: 'autoSize',
|
|
27
|
+
plotly_beforeexport: 'beforeExport',
|
|
28
|
+
plotly_beforehover: 'beforeHover',
|
|
29
|
+
plotly_beforeplot: 'beforePlot',
|
|
30
|
+
plotly_buttonclicked: 'buttonClicked',
|
|
31
|
+
plotly_click: 'click',
|
|
32
|
+
plotly_clickannotation: 'clickAnnotation',
|
|
33
|
+
plotly_deselect: 'deselect',
|
|
34
|
+
plotly_doubleclick: 'doubleClick',
|
|
35
|
+
plotly_framework: 'framework',
|
|
36
|
+
plotly_hover: 'hover',
|
|
37
|
+
plotly_legendclick: 'legendClick',
|
|
38
|
+
plotly_legenddoubleclick: 'legendDoubleClick',
|
|
39
|
+
plotly_react: 'react',
|
|
40
|
+
plotly_redraw: 'redraw',
|
|
41
|
+
plotly_relayout: 'relayout',
|
|
42
|
+
plotly_relayouting: 'relayouting',
|
|
43
|
+
plotly_restyle: 'restyle',
|
|
44
|
+
plotly_selected: 'selected',
|
|
45
|
+
plotly_selecting: 'selecting',
|
|
46
|
+
plotly_sliderchange: 'sliderChange',
|
|
47
|
+
plotly_sliderend: 'sliderEnd',
|
|
48
|
+
plotly_sliderstart: 'sliderStart',
|
|
49
|
+
plotly_sunburstclick: 'sunburstClick',
|
|
50
|
+
plotly_transitioned: 'transitioned',
|
|
51
|
+
plotly_transitioning: 'transitioning',
|
|
52
|
+
plotly_transitioninterrupted: 'transitionInterrupted',
|
|
53
|
+
plotly_unhover: 'unhover',
|
|
54
|
+
plotly_update: 'update',
|
|
55
|
+
plotly_webglcontextlost: 'webGLContextLost',
|
|
56
|
+
// TODO add all plotly_${traceType}click
|
|
57
|
+
};
|
|
58
|
+
const dispatch = createEventDispatcher();
|
|
19
59
|
// bind props
|
|
20
60
|
export let element = undefined;
|
|
21
61
|
export let plot = undefined;
|
|
@@ -31,11 +71,12 @@ export { className as class };
|
|
|
31
71
|
// set up
|
|
32
72
|
onMount(async () => {
|
|
33
73
|
window.global = window;
|
|
34
|
-
loadPlotly();
|
|
74
|
+
await loadPlotly();
|
|
35
75
|
});
|
|
36
76
|
// state props
|
|
37
77
|
let datarevision = 0;
|
|
38
78
|
let previousLib = libPlotly;
|
|
79
|
+
let previousPlot = plot;
|
|
39
80
|
let width = DEFAULT_WIDTH;
|
|
40
81
|
let height = DEFAULT_HEIGHT;
|
|
41
82
|
// updates
|
|
@@ -46,11 +87,20 @@ $: layout_ = { datarevision, width, height, ...layout };
|
|
|
46
87
|
$: config_ = { displaylogo: false, ...config };
|
|
47
88
|
$: draw(libPlotly, element, data, layout_, config_);
|
|
48
89
|
$: {
|
|
49
|
-
if (element && previousLib !== libPlotly)
|
|
90
|
+
if (element && previousLib !== libPlotly) {
|
|
50
91
|
previousLib?.purge(element);
|
|
92
|
+
plot = undefined;
|
|
93
|
+
}
|
|
51
94
|
previousLib = libPlotly;
|
|
52
95
|
loadPlotly();
|
|
53
96
|
}
|
|
97
|
+
$: if (previousPlot !== plot) {
|
|
98
|
+
for (const [plotlyEvent, svelteEvent] of Object.entries(events)) {
|
|
99
|
+
previousPlot?.removeAllListeners?.(plotlyEvent);
|
|
100
|
+
plot?.on(plotlyEvent, (e) => dispatch(svelteEvent, e));
|
|
101
|
+
}
|
|
102
|
+
previousPlot = plot;
|
|
103
|
+
}
|
|
54
104
|
const drawUndebounced = (lib, e, d, l, c) => {
|
|
55
105
|
if (e)
|
|
56
106
|
lib?.react(e, d, l, c).then(p => (plot = p));
|
package/Plot.svelte.d.ts
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
|
+
/// <reference types="lodash" />
|
|
1
2
|
import { SvelteComponentTyped } from "svelte";
|
|
2
|
-
import type { Data, Layout, Config, PlotlyHTMLElement } from 'plotly.js';
|
|
3
|
-
export type { Data, Layout, Config, PlotlyHTMLElement };
|
|
3
|
+
import type { Data, Layout, Config, PlotlyHTMLElement, BeforePlotEvent, ClickAnnotationEvent, FrameAnimationEvent, LegendClickEvent, PlotMouseEvent, PlotRelayoutEvent, PlotRestyleEvent, PlotSelectionEvent, SliderEndEvent, SliderChangeEvent, SliderStartEvent, SunburstClickEvent } from 'plotly.js';
|
|
4
|
+
export type { Data, Layout, Config, PlotlyHTMLElement, BeforePlotEvent, ClickAnnotationEvent, FrameAnimationEvent, LegendClickEvent, PlotMouseEvent, PlotRelayoutEvent, PlotRestyleEvent, PlotSelectionEvent, SliderChangeEvent, SliderStartEvent, SunburstClickEvent };
|
|
4
5
|
export declare type FillParent = boolean | 'width' | 'height';
|
|
5
|
-
import type { DebounceSettings } from 'lodash';
|
|
6
|
+
import type { DebounceSettings } from 'lodash-es';
|
|
6
7
|
export interface DebounceOptions extends DebounceSettings {
|
|
7
8
|
wait: number;
|
|
8
9
|
}
|
|
10
|
+
export interface ButtonClickedEvent {
|
|
11
|
+
menu: any;
|
|
12
|
+
button: any;
|
|
13
|
+
active: any;
|
|
14
|
+
}
|
|
15
|
+
export interface PlotUpdateEvent {
|
|
16
|
+
data: Data;
|
|
17
|
+
layout: Layout;
|
|
18
|
+
}
|
|
9
19
|
declare const __propDef: {
|
|
10
20
|
props: {
|
|
11
21
|
element?: (null | undefined) | HTMLDivElement;
|
|
@@ -18,10 +28,46 @@ declare const __propDef: {
|
|
|
18
28
|
debounce?: number | DebounceOptions | undefined;
|
|
19
29
|
class?: string | undefined;
|
|
20
30
|
};
|
|
31
|
+
slots: {};
|
|
32
|
+
getters: {};
|
|
21
33
|
events: {
|
|
22
|
-
|
|
34
|
+
afterExport: undefined;
|
|
35
|
+
afterPlot: undefined;
|
|
36
|
+
animated: undefined;
|
|
37
|
+
animating: undefined;
|
|
38
|
+
animatingFrame: FrameAnimationEvent;
|
|
39
|
+
animationInterrupted: undefined;
|
|
40
|
+
autoSize: undefined;
|
|
41
|
+
beforeExport: undefined;
|
|
42
|
+
beforeHover: PlotMouseEvent;
|
|
43
|
+
beforePlot: BeforePlotEvent;
|
|
44
|
+
buttonClicked: ButtonClickedEvent;
|
|
45
|
+
click: PlotMouseEvent;
|
|
46
|
+
clickAnnotation: ClickAnnotationEvent;
|
|
47
|
+
deselect: undefined;
|
|
48
|
+
doubleClick: undefined;
|
|
49
|
+
framework: undefined;
|
|
50
|
+
hover: PlotMouseEvent;
|
|
51
|
+
legendClick: LegendClickEvent;
|
|
52
|
+
legendDoubleClick: LegendClickEvent;
|
|
53
|
+
react: PlotUpdateEvent;
|
|
54
|
+
redraw: undefined;
|
|
55
|
+
relayout: PlotRelayoutEvent;
|
|
56
|
+
relayouting: PlotRelayoutEvent;
|
|
57
|
+
restyle: PlotRestyleEvent;
|
|
58
|
+
selected: PlotSelectionEvent;
|
|
59
|
+
selecting: PlotSelectionEvent;
|
|
60
|
+
sliderChange: SliderChangeEvent;
|
|
61
|
+
sliderEnd: SliderEndEvent;
|
|
62
|
+
sliderStart: SliderStartEvent;
|
|
63
|
+
sunburstClick: SunburstClickEvent;
|
|
64
|
+
transitioned: undefined;
|
|
65
|
+
transitioning: undefined;
|
|
66
|
+
transitionInterrupted: undefined;
|
|
67
|
+
unhover: PlotMouseEvent;
|
|
68
|
+
update: PlotUpdateEvent;
|
|
69
|
+
webGLContextLost: undefined;
|
|
23
70
|
};
|
|
24
|
-
slots: {};
|
|
25
71
|
};
|
|
26
72
|
export declare type PlotProps = typeof __propDef.props;
|
|
27
73
|
export declare type PlotEvents = typeof __propDef.events;
|
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ This is an unofficial package that lets you efficiently use [plotly.js](https://
|
|
|
24
24
|
margin: { t: 0 }
|
|
25
25
|
}}
|
|
26
26
|
fillParent='width'
|
|
27
|
-
debounce=250
|
|
27
|
+
debounce={250}
|
|
28
28
|
/>
|
|
29
29
|
```
|
|
30
30
|
|
|
@@ -45,5 +45,6 @@ This is an unofficial package that lets you efficiently use [plotly.js](https://
|
|
|
45
45
|
# Roadmap
|
|
46
46
|
* [x] add autosizing
|
|
47
47
|
* [x] add debouncing
|
|
48
|
+
* [ ] add event redirecting
|
|
48
49
|
* [ ] add unit tests
|
|
49
50
|
* [ ] add SSR rendering to an image
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svelte-plotly.js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"author": {
|
|
5
5
|
"name": "Michal Grňo (m93a)",
|
|
6
6
|
"url": "https://github.com/m93a/"
|
|
@@ -37,9 +37,9 @@
|
|
|
37
37
|
},
|
|
38
38
|
"type": "module",
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@types/lodash": "^4.
|
|
40
|
+
"@types/lodash-es": "^4.17.6",
|
|
41
41
|
"@types/plotly.js": "^1.54.20",
|
|
42
|
-
"lodash": "^4.17.21",
|
|
42
|
+
"lodash-es": "^4.17.21",
|
|
43
43
|
"plotly.js-dist": "^2.12.1"
|
|
44
44
|
},
|
|
45
45
|
"types": "./Plot.svelte.d.ts",
|