@rokkit/chart 1.1.17 → 1.1.18
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/package.json +1 -1
- package/src/Plot.svelte +19 -10
package/package.json
CHANGED
package/src/Plot.svelte
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import { setContext, getContext, untrack } from 'svelte'
|
|
3
|
-
import { zoom as d3Zoom } from 'd3-zoom'
|
|
4
|
-
import { select } from 'd3-selection'
|
|
5
3
|
import { PlotState } from './PlotState.svelte.js'
|
|
6
4
|
import { defaultPreset } from './lib/preset.js'
|
|
7
5
|
import Axis from './Plot/Axis.svelte'
|
|
@@ -132,15 +130,26 @@
|
|
|
132
130
|
|
|
133
131
|
$effect(() => {
|
|
134
132
|
if (!zoom || !svgEl) return
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
133
|
+
// d3-zoom/d3-selection are client-only; load them dynamically so they are
|
|
134
|
+
// not bundled into (and tree-shaken-as-unused from) the SSR/main bundle.
|
|
135
|
+
let cancelled = false
|
|
136
|
+
let detach
|
|
137
|
+
Promise.all([import('d3-zoom'), import('d3-selection')]).then(
|
|
138
|
+
([{ zoom: d3Zoom }, { select }]) => {
|
|
139
|
+
if (cancelled || !svgEl) return
|
|
140
|
+
const zoomBehavior = d3Zoom()
|
|
141
|
+
.scaleExtent([1, 8])
|
|
142
|
+
.on('zoom', (event) => {
|
|
143
|
+
plotState.applyZoom(event.transform)
|
|
144
|
+
})
|
|
145
|
+
const sel = select(svgEl)
|
|
146
|
+
sel.call(zoomBehavior)
|
|
147
|
+
detach = () => sel.on('.zoom', null)
|
|
148
|
+
}
|
|
149
|
+
)
|
|
142
150
|
return () => {
|
|
143
|
-
|
|
151
|
+
cancelled = true
|
|
152
|
+
detach?.()
|
|
144
153
|
plotState.resetZoom()
|
|
145
154
|
}
|
|
146
155
|
})
|