layerchart 0.54.0 → 0.55.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/dist/components/Arc.svelte +170 -144
- package/dist/components/Area.svelte +96 -67
- package/dist/components/Area.svelte.d.ts +1 -0
- package/dist/components/Axis.svelte +205 -155
- package/dist/components/Bar.svelte +72 -45
- package/dist/components/Bars.svelte +45 -34
- package/dist/components/Blur.svelte +5 -3
- package/dist/components/Bounds.svelte +37 -21
- package/dist/components/Brush.svelte +269 -112
- package/dist/components/Brush.svelte.d.ts +7 -0
- package/dist/components/Calendar.svelte +51 -38
- package/dist/components/Chart.svelte +295 -74
- package/dist/components/Chart.svelte.d.ts +17 -17
- package/dist/components/ChartClipPath.svelte +8 -5
- package/dist/components/ChartContext.svelte +243 -93
- package/dist/components/ChartContext.svelte.d.ts +15 -23
- package/dist/components/Circle.svelte +25 -16
- package/dist/components/CircleClipPath.svelte +16 -10
- package/dist/components/ClipPath.svelte +11 -7
- package/dist/components/ColorRamp.svelte +12 -10
- package/dist/components/ForceSimulation.svelte +185 -116
- package/dist/components/Frame.svelte +10 -6
- package/dist/components/GeoCircle.svelte +15 -9
- package/dist/components/GeoContext.svelte +109 -62
- package/dist/components/GeoEdgeFade.svelte +20 -14
- package/dist/components/GeoPath.svelte +107 -69
- package/dist/components/GeoPoint.svelte +32 -18
- package/dist/components/GeoSpline.svelte +30 -22
- package/dist/components/GeoTile.svelte +40 -30
- package/dist/components/GeoVisible.svelte +10 -7
- package/dist/components/Graticule.svelte +14 -8
- package/dist/components/Grid.svelte +75 -48
- package/dist/components/Group.svelte +43 -31
- package/dist/components/Highlight.svelte +284 -243
- package/dist/components/HitCanvas.svelte +75 -42
- package/dist/components/Hull.svelte +40 -20
- package/dist/components/Labels.svelte +81 -70
- package/dist/components/Legend.svelte +105 -74
- package/dist/components/Legend.svelte.d.ts +1 -1
- package/dist/components/Line.svelte +65 -19
- package/dist/components/Line.svelte.d.ts +13 -1
- package/dist/components/LinearGradient.svelte +21 -15
- package/dist/components/Link.svelte +94 -22
- package/dist/components/Link.svelte.d.ts +17 -1
- package/dist/components/Marker.svelte +81 -0
- package/dist/components/Marker.svelte.d.ts +28 -0
- package/dist/components/MonthPath.svelte +23 -16
- package/dist/components/MotionPath.svelte +34 -25
- package/dist/components/Pack.svelte +21 -14
- package/dist/components/Partition.svelte +35 -20
- package/dist/components/Pattern.svelte +8 -6
- package/dist/components/Pie.svelte +76 -57
- package/dist/components/Point.svelte +11 -7
- package/dist/components/Points.svelte +178 -143
- package/dist/components/RadialGradient.svelte +25 -18
- package/dist/components/Rect.svelte +33 -19
- package/dist/components/RectClipPath.svelte +16 -11
- package/dist/components/Rule.svelte +50 -42
- package/dist/components/Sankey.svelte +55 -30
- package/dist/components/Spline.svelte +167 -96
- package/dist/components/Spline.svelte.d.ts +15 -0
- package/dist/components/Text.svelte +137 -104
- package/dist/components/Threshold.svelte +18 -7
- package/dist/components/TileImage.svelte +56 -50
- package/dist/components/TransformContext.svelte +235 -135
- package/dist/components/TransformControls.svelte +57 -29
- package/dist/components/TransformControls.svelte.d.ts +1 -1
- package/dist/components/Tree.svelte +33 -23
- package/dist/components/Treemap.svelte +69 -41
- package/dist/components/Voronoi.svelte +55 -28
- package/dist/components/charts/AreaChart.svelte +138 -87
- package/dist/components/charts/AreaChart.svelte.d.ts +4 -4
- package/dist/components/charts/BarChart.svelte +179 -114
- package/dist/components/charts/BarChart.svelte.d.ts +4 -4
- package/dist/components/charts/LineChart.svelte +97 -53
- package/dist/components/charts/LineChart.svelte.d.ts +4 -4
- package/dist/components/charts/PieChart.svelte +104 -54
- package/dist/components/charts/PieChart.svelte.d.ts +3 -3
- package/dist/components/charts/ScatterChart.svelte +83 -48
- package/dist/components/charts/ScatterChart.svelte.d.ts +4 -4
- package/dist/components/layout/Canvas.svelte +63 -43
- package/dist/components/layout/Html.svelte +28 -18
- package/dist/components/layout/Svg.svelte +47 -32
- package/dist/components/tooltip/Tooltip.svelte +137 -91
- package/dist/components/tooltip/Tooltip.svelte.d.ts +1 -1
- package/dist/components/tooltip/TooltipContext.svelte +315 -249
- package/dist/components/tooltip/TooltipHeader.svelte +9 -3
- package/dist/components/tooltip/TooltipItem.svelte +17 -9
- package/dist/components/tooltip/TooltipList.svelte +2 -1
- package/dist/components/tooltip/TooltipSeparator.svelte +3 -2
- package/dist/docs/Blockquote.svelte +4 -3
- package/dist/docs/Code.svelte +15 -8
- package/dist/docs/CurveMenuField.svelte +17 -12
- package/dist/docs/GeoDebug.svelte +13 -9
- package/dist/docs/Header1.svelte +2 -1
- package/dist/docs/Json.svelte +6 -4
- package/dist/docs/Layout.svelte +6 -6
- package/dist/docs/PathDataMenuField.svelte +52 -44
- package/dist/docs/Preview.svelte +39 -33
- package/dist/docs/TilesetField.svelte +80 -62
- package/dist/docs/TransformDebug.svelte +8 -5
- package/dist/docs/ViewSourceButton.svelte +13 -9
- package/dist/stores/motionStore.d.ts +1 -1
- package/dist/utils/scales.d.ts +3 -3
- package/package.json +29 -30
|
@@ -1,9 +1,34 @@
|
|
|
1
|
-
<script context="module">
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
1
|
+
<script lang="ts" context="module">
|
|
2
|
+
import { getContext, setContext } from 'svelte';
|
|
3
|
+
import { writable, type Readable, type Writable, derived } from 'svelte/store';
|
|
4
|
+
|
|
5
|
+
export const transformContextKey = Symbol();
|
|
6
|
+
|
|
7
|
+
type TransformMode = 'canvas' | 'manual' | 'none';
|
|
8
|
+
type TransformScrollMode = 'scale' | 'translate' | 'none';
|
|
9
|
+
|
|
10
|
+
export type TransformContextValue = {
|
|
11
|
+
mode: TransformMode;
|
|
12
|
+
scale: Writable<number>;
|
|
13
|
+
setScale(value: number, options?: MotionOptions): void;
|
|
14
|
+
translate: Writable<{ x: number; y: number }>;
|
|
15
|
+
setTranslate(point: { x: number; y: number }, options?: MotionOptions): void;
|
|
16
|
+
moving: Readable<boolean>;
|
|
17
|
+
dragging: Readable<boolean>;
|
|
18
|
+
scrollMode: Readable<TransformScrollMode>;
|
|
19
|
+
setScrollMode(mode: TransformScrollMode): void;
|
|
20
|
+
reset(): void;
|
|
21
|
+
zoomIn(): void;
|
|
22
|
+
zoomOut(): void;
|
|
23
|
+
translateCenter(): void;
|
|
24
|
+
zoomTo(center: { x: number; y: number }, rect?: { width: number; height: number }): void;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export type TransformContext = TransformContextValue;
|
|
28
|
+
|
|
29
|
+
const defaultTranslate = writable({ x: 0, y: 0 });
|
|
30
|
+
const defaultScale = writable(1);
|
|
31
|
+
const defaultContext: TransformContext = {
|
|
7
32
|
mode: 'none',
|
|
8
33
|
scale: defaultScale,
|
|
9
34
|
setScale: defaultScale.set,
|
|
@@ -12,194 +37,269 @@ const defaultContext = {
|
|
|
12
37
|
moving: writable(false),
|
|
13
38
|
dragging: writable(false),
|
|
14
39
|
scrollMode: writable('none'),
|
|
15
|
-
setScrollMode: () => {
|
|
16
|
-
reset: () => {
|
|
17
|
-
zoomIn: () => {
|
|
18
|
-
zoomOut: () => {
|
|
19
|
-
translateCenter: () => {
|
|
20
|
-
zoomTo: () => {
|
|
21
|
-
};
|
|
22
|
-
export function transformContext() {
|
|
23
|
-
return getContext(transformContextKey) ?? defaultContext;
|
|
24
|
-
}
|
|
25
|
-
|
|
40
|
+
setScrollMode: () => {},
|
|
41
|
+
reset: () => {},
|
|
42
|
+
zoomIn: () => {},
|
|
43
|
+
zoomOut: () => {},
|
|
44
|
+
translateCenter: () => {},
|
|
45
|
+
zoomTo: () => {},
|
|
46
|
+
};
|
|
47
|
+
export function transformContext() {
|
|
48
|
+
return getContext<TransformContext>(transformContextKey) ?? defaultContext;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function setTransformContext(transform: TransformContext) {
|
|
26
52
|
setContext(transformContextKey, transform);
|
|
27
|
-
}
|
|
53
|
+
}
|
|
28
54
|
</script>
|
|
29
55
|
|
|
30
|
-
<script>
|
|
31
|
-
import {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
export let
|
|
39
|
-
|
|
56
|
+
<script lang="ts">
|
|
57
|
+
import { createEventDispatcher } from 'svelte';
|
|
58
|
+
|
|
59
|
+
import { chartContext } from './ChartContext.svelte';
|
|
60
|
+
import { motionStore, type MotionOptions, motionFinishHandler } from '../stores/motionStore.js';
|
|
61
|
+
|
|
62
|
+
const { width, height } = chartContext();
|
|
63
|
+
|
|
64
|
+
export let mode: TransformMode = 'none';
|
|
65
|
+
/** Translate towards point (ex. mouse cursor/center) while zooming in/out */
|
|
66
|
+
export let translateOnScale = false;
|
|
67
|
+
|
|
68
|
+
export let spring: boolean | Parameters<typeof motionStore>[1]['spring'] = undefined;
|
|
69
|
+
export let tweened: boolean | Parameters<typeof motionStore>[1]['tweened'] = undefined;
|
|
70
|
+
|
|
71
|
+
export let processTranslate = (
|
|
72
|
+
x: number,
|
|
73
|
+
y: number,
|
|
74
|
+
deltaX: number,
|
|
75
|
+
deltaY: number,
|
|
76
|
+
scale: number
|
|
77
|
+
) => {
|
|
40
78
|
return {
|
|
41
|
-
|
|
42
|
-
|
|
79
|
+
x: x + deltaX / scale,
|
|
80
|
+
y: y + deltaY / scale,
|
|
43
81
|
};
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
export let
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
let
|
|
62
|
-
|
|
63
|
-
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
/** Disable pointer events including move/dragging. Useful for `mode="canvas" but only want zoomTo() interactions */
|
|
85
|
+
export let disablePointer = false;
|
|
86
|
+
|
|
87
|
+
/** Action to take during wheel scroll */
|
|
88
|
+
export let initialScrollMode: TransformScrollMode = 'none';
|
|
89
|
+
|
|
90
|
+
/** Distance/threshold to consider drag vs click (disable click propagation) */
|
|
91
|
+
export let clickDistance = 10;
|
|
92
|
+
|
|
93
|
+
const dispatch = createEventDispatcher<{
|
|
94
|
+
dragstart: null;
|
|
95
|
+
dragend: null;
|
|
96
|
+
transform: { scale: number; translate: { x: number; y: number } };
|
|
97
|
+
}>();
|
|
98
|
+
|
|
99
|
+
let pointerDown = false;
|
|
100
|
+
const dragging = writable(false);
|
|
101
|
+
const scrollMode = writable<TransformScrollMode>(initialScrollMode);
|
|
102
|
+
|
|
103
|
+
const DEFAULT_TRANSLATE = { x: 0, y: 0 };
|
|
104
|
+
export let initialTranslate: { x: number; y: number } | undefined = undefined;
|
|
105
|
+
export const translate = motionStore(initialTranslate ?? DEFAULT_TRANSLATE, { spring, tweened });
|
|
106
|
+
|
|
107
|
+
const DEFAULT_SCALE = 1;
|
|
108
|
+
export let initialScale: number | undefined = undefined;
|
|
109
|
+
export const scale = motionStore(initialScale ?? DEFAULT_SCALE, { spring, tweened });
|
|
110
|
+
|
|
111
|
+
let startPoint: { x: number; y: number } = { x: 0, y: 0 };
|
|
112
|
+
let startTranslate: { x: number; y: number } = { x: 0, y: 0 };
|
|
113
|
+
|
|
114
|
+
export function setScrollMode(mode: TransformScrollMode) {
|
|
64
115
|
$scrollMode = mode;
|
|
65
|
-
}
|
|
66
|
-
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function reset() {
|
|
67
119
|
$translate = initialTranslate ?? DEFAULT_TRANSLATE;
|
|
68
120
|
$scale = initialScale ?? DEFAULT_SCALE;
|
|
69
|
-
}
|
|
70
|
-
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function zoomIn() {
|
|
71
124
|
scaleTo(1.25, { x: $width / 2, y: $height / 2 });
|
|
72
|
-
}
|
|
73
|
-
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export function zoomOut() {
|
|
74
128
|
scaleTo(0.8, { x: $width / 2, y: $height / 2 });
|
|
75
|
-
}
|
|
76
|
-
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function translateCenter() {
|
|
77
132
|
$translate = {
|
|
78
|
-
|
|
79
|
-
|
|
133
|
+
x: 0,
|
|
134
|
+
y: 0,
|
|
80
135
|
};
|
|
81
|
-
}
|
|
82
|
-
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export function zoomTo(
|
|
139
|
+
center: { x: number; y: number },
|
|
140
|
+
rect?: { width: number; height: number }
|
|
141
|
+
) {
|
|
83
142
|
// TODO: Improve with geo/projection
|
|
143
|
+
|
|
84
144
|
$translate = {
|
|
85
|
-
|
|
86
|
-
|
|
145
|
+
x: $width / 2 - center.x,
|
|
146
|
+
y: $height / 2 - center.y,
|
|
87
147
|
};
|
|
148
|
+
|
|
88
149
|
if (rect) {
|
|
89
|
-
|
|
150
|
+
$scale = $width < $height ? $width / rect.width : $height / rect.height;
|
|
90
151
|
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function onPointerDown(e: PointerEvent & { currentTarget: HTMLDivElement }) {
|
|
155
|
+
if (mode === 'none' || disablePointer) return;
|
|
156
|
+
|
|
95
157
|
e.preventDefault();
|
|
158
|
+
|
|
96
159
|
pointerDown = true;
|
|
97
160
|
$dragging = false;
|
|
98
161
|
startPoint = localPoint(e);
|
|
99
162
|
startTranslate = $translate;
|
|
163
|
+
|
|
100
164
|
dispatch('dragstart');
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function onPointerMove(e: PointerEvent) {
|
|
168
|
+
if (!pointerDown) return;
|
|
169
|
+
|
|
105
170
|
e.preventDefault(); // Stop text selection
|
|
171
|
+
|
|
106
172
|
const endPoint = localPoint(e);
|
|
107
173
|
const deltaX = endPoint.x - startPoint.x;
|
|
108
174
|
const deltaY = endPoint.y - startPoint.y;
|
|
175
|
+
|
|
109
176
|
if (!$dragging) {
|
|
110
|
-
|
|
111
|
-
|
|
177
|
+
// If dragged beyond threshold, disable click propagation
|
|
178
|
+
$dragging = deltaX * deltaX + deltaY * deltaY > clickDistance;
|
|
112
179
|
}
|
|
180
|
+
|
|
113
181
|
if ($dragging) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
182
|
+
e.stopPropagation(); // Stop tooltip from trigging (along with `capture: true`)
|
|
183
|
+
// @ts-expect-error
|
|
184
|
+
e.currentTarget?.setPointerCapture(e.pointerId);
|
|
185
|
+
|
|
186
|
+
setTranslate(
|
|
187
|
+
processTranslate(startTranslate.x, startTranslate.y, deltaX, deltaY, $scale),
|
|
118
188
|
// @ts-expect-error
|
|
119
|
-
spring ? { hard: true } : tweened ? { duration: 0 } : undefined
|
|
189
|
+
spring ? { hard: true } : tweened ? { duration: 0 } : undefined
|
|
190
|
+
);
|
|
120
191
|
}
|
|
121
|
-
}
|
|
122
|
-
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function onPointerUp(e: PointerEvent) {
|
|
123
195
|
pointerDown = false;
|
|
124
196
|
$dragging = false;
|
|
125
197
|
dispatch('dragend');
|
|
126
|
-
}
|
|
127
|
-
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function onClick(e: MouseEvent) {
|
|
128
201
|
if ($dragging) {
|
|
129
|
-
|
|
130
|
-
|
|
202
|
+
// Do not propagate click event to children if drag/moved. Registered in capture phase (top-down)
|
|
203
|
+
e.stopPropagation();
|
|
131
204
|
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function onDoubleClick(e: MouseEvent) {
|
|
208
|
+
if (mode === 'none' || disablePointer) return;
|
|
136
209
|
const point = localPoint(e);
|
|
137
210
|
scaleTo(e.shiftKey ? 0.5 : 2, point);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function onWheel(e: WheelEvent) {
|
|
214
|
+
if (mode === 'none' || disablePointer || $scrollMode === 'none') return;
|
|
215
|
+
|
|
142
216
|
e.preventDefault();
|
|
217
|
+
|
|
143
218
|
const point = (startPoint = localPoint(e));
|
|
219
|
+
|
|
144
220
|
// Pinch to zoom is registered as a wheel event with control key
|
|
145
221
|
const pinchToZoom = e.ctrlKey;
|
|
222
|
+
|
|
146
223
|
if ($scrollMode === 'scale' || pinchToZoom) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
224
|
+
// https://github.com/d3/d3-zoom#zoom_wheelDelta
|
|
225
|
+
const scaleBy =
|
|
226
|
+
-e.deltaY * (e.deltaMode === 1 ? 0.05 : e.deltaMode ? 1 : 0.002) * (e.ctrlKey ? 10 : 1);
|
|
227
|
+
|
|
228
|
+
scaleTo(
|
|
229
|
+
Math.pow(2, scaleBy),
|
|
230
|
+
point,
|
|
150
231
|
// @ts-expect-error
|
|
151
|
-
spring ? { hard: true } : tweened ? { duration: 0 } : undefined
|
|
152
|
-
|
|
153
|
-
else if ($scrollMode === 'translate') {
|
|
154
|
-
|
|
232
|
+
spring ? { hard: true } : tweened ? { duration: 0 } : undefined
|
|
233
|
+
);
|
|
234
|
+
} else if ($scrollMode === 'translate') {
|
|
235
|
+
translate.update(
|
|
236
|
+
(startTranslate) =>
|
|
237
|
+
processTranslate(startTranslate.x, startTranslate.y, -e.deltaX, -e.deltaY, $scale),
|
|
155
238
|
// @ts-expect-error
|
|
156
|
-
spring ? { hard: true } : tweened ? { duration: 0 } : undefined
|
|
239
|
+
spring ? { hard: true } : tweened ? { duration: 0 } : undefined
|
|
240
|
+
);
|
|
157
241
|
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Apply scale and translate towards point
|
|
246
|
+
*/
|
|
247
|
+
function scaleTo(
|
|
248
|
+
value: number,
|
|
249
|
+
point: { x: number; y: number },
|
|
250
|
+
options: Parameters<typeof motionStore>[1] | undefined = undefined
|
|
251
|
+
) {
|
|
163
252
|
const currentScale = $scale;
|
|
164
253
|
const newScale = $scale * value;
|
|
165
254
|
setScale(newScale, options);
|
|
255
|
+
|
|
166
256
|
if (translateOnScale) {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
257
|
+
// Translate towards point (ex. mouse cursor/center) while zooming in/out
|
|
258
|
+
const invertTransformPoint = {
|
|
259
|
+
x: (point.x - $translate.x) / currentScale,
|
|
260
|
+
y: (point.y - $translate.y) / currentScale,
|
|
261
|
+
};
|
|
262
|
+
const newTranslate = {
|
|
263
|
+
x: point.x - invertTransformPoint.x * newScale,
|
|
264
|
+
y: point.y - invertTransformPoint.y * newScale,
|
|
265
|
+
};
|
|
266
|
+
setTranslate(newTranslate, options);
|
|
177
267
|
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
const
|
|
181
|
-
const
|
|
182
|
-
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
const translating = motionFinishHandler();
|
|
271
|
+
const scaling = motionFinishHandler();
|
|
272
|
+
const moving = derived(
|
|
273
|
+
[dragging, translating, scaling],
|
|
274
|
+
([dragging, translating, scaling]) => dragging || translating || scaling
|
|
275
|
+
);
|
|
276
|
+
export function setTranslate(point: { x: number; y: number }, options?: MotionOptions) {
|
|
183
277
|
// @ts-expect-error
|
|
184
278
|
translating.handle(translate.set(point, options));
|
|
185
|
-
}
|
|
186
|
-
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export function setScale(value: number, options?: MotionOptions) {
|
|
187
282
|
// @ts-expect-error
|
|
188
283
|
scaling.handle(scale.set(value, options));
|
|
189
|
-
}
|
|
190
|
-
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
function localPoint(e: PointerEvent | MouseEvent | WheelEvent) {
|
|
191
287
|
return {
|
|
192
|
-
|
|
193
|
-
|
|
288
|
+
x: e.offsetX,
|
|
289
|
+
y: e.offsetY,
|
|
194
290
|
};
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
$:
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
$: center = { x: $width / 2, y: $height / 2 };
|
|
294
|
+
|
|
295
|
+
$: viewportCenter = {
|
|
198
296
|
x: center.x - $translate.x,
|
|
199
297
|
y: center.y - $translate.y,
|
|
200
|
-
};
|
|
201
|
-
|
|
202
|
-
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
$: dispatch('transform', { scale: $scale, translate: $translate });
|
|
301
|
+
|
|
302
|
+
setTransformContext({
|
|
203
303
|
mode,
|
|
204
304
|
scale,
|
|
205
305
|
setScale,
|
|
@@ -214,7 +314,7 @@ setTransformContext({
|
|
|
214
314
|
zoomTo,
|
|
215
315
|
scrollMode,
|
|
216
316
|
setScrollMode,
|
|
217
|
-
});
|
|
317
|
+
});
|
|
218
318
|
</script>
|
|
219
319
|
|
|
220
320
|
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
|
@@ -1,36 +1,64 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { Button, Icon, MenuButton, Tooltip } from 'svelte-ux';
|
|
3
|
+
import { cls } from '@layerstack/tailwind';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
mdiArrowULeftTop,
|
|
7
|
+
mdiMagnifyPlusOutline,
|
|
8
|
+
mdiMagnifyMinusOutline,
|
|
9
|
+
mdiImageFilterCenterFocus,
|
|
10
|
+
mdiChevronDown,
|
|
11
|
+
mdiResize,
|
|
12
|
+
mdiArrowExpandAll,
|
|
13
|
+
mdiCancel,
|
|
14
|
+
} from '@mdi/js';
|
|
15
|
+
|
|
16
|
+
import { transformContext } from './TransformContext.svelte';
|
|
17
|
+
|
|
18
|
+
type Placement =
|
|
19
|
+
| 'top-left'
|
|
20
|
+
| 'top'
|
|
21
|
+
| 'top-right'
|
|
22
|
+
| 'left'
|
|
23
|
+
| 'center'
|
|
24
|
+
| 'right'
|
|
25
|
+
| 'bottom-left'
|
|
26
|
+
| 'bottom'
|
|
27
|
+
| 'bottom-right';
|
|
28
|
+
|
|
29
|
+
export let placement: Placement = 'top-right';
|
|
30
|
+
export let orientation: 'horizontal' | 'vertical' = 'vertical';
|
|
31
|
+
|
|
32
|
+
type Actions = 'zoomIn' | 'zoomOut' | 'center' | 'reset' | 'scrollMode';
|
|
33
|
+
export let show: Actions[] = ['zoomIn', 'zoomOut', 'center', 'reset', 'scrollMode'];
|
|
34
|
+
|
|
35
|
+
$: menuPlacementByOrientationAndPlacement = {
|
|
9
36
|
horizontal: {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
37
|
+
'top-left': 'bottom-end',
|
|
38
|
+
top: 'bottom-end',
|
|
39
|
+
'top-right': 'bottom-end',
|
|
40
|
+
left: 'bottom-end',
|
|
41
|
+
center: 'bottom-end',
|
|
42
|
+
right: 'bottom-end',
|
|
43
|
+
'bottom-left': 'top-end',
|
|
44
|
+
bottom: 'top-end',
|
|
45
|
+
'bottom-right': 'top-end',
|
|
19
46
|
},
|
|
20
47
|
vertical: {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
48
|
+
'top-left': 'right-start',
|
|
49
|
+
top: 'right-start',
|
|
50
|
+
'top-right': 'left-start',
|
|
51
|
+
left: 'right-start',
|
|
52
|
+
center: 'right-start',
|
|
53
|
+
right: 'left-start',
|
|
54
|
+
'bottom-left': 'right-end',
|
|
55
|
+
bottom: 'right-end',
|
|
56
|
+
'bottom-right': 'left-end',
|
|
30
57
|
},
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const
|
|
58
|
+
} as const;
|
|
59
|
+
|
|
60
|
+
const transform = transformContext();
|
|
61
|
+
const scrollMode = transform.scrollMode;
|
|
34
62
|
</script>
|
|
35
63
|
|
|
36
64
|
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
|
@@ -2,7 +2,7 @@ import { SvelteComponentTyped } from "svelte";
|
|
|
2
2
|
declare const __propDef: {
|
|
3
3
|
props: {
|
|
4
4
|
[x: string]: any;
|
|
5
|
-
placement?: ("
|
|
5
|
+
placement?: ("center" | "left" | "right" | "bottom" | "top" | "top-left" | "top-right" | "bottom-left" | "bottom-right") | undefined;
|
|
6
6
|
orientation?: ("horizontal" | "vertical") | undefined;
|
|
7
7
|
show?: ("reset" | "scrollMode" | "zoomIn" | "zoomOut" | "center")[] | undefined;
|
|
8
8
|
};
|
|
@@ -1,31 +1,41 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { type HierarchyPointNode, tree as d3Tree, type TreeLayout } from 'd3-hierarchy';
|
|
3
|
+
import { chartContext } from './ChartContext.svelte';
|
|
4
|
+
|
|
5
|
+
const { data, width, height } = chartContext();
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Sets this tree layout’s node size to the specified two-element array of numbers `[width, height]`.
|
|
9
|
+
* If unset, layout size is used instead. When a node size is specified, the root node is always
|
|
10
|
+
* positioned at `⟨0, 0⟩`.
|
|
11
|
+
*
|
|
12
|
+
* see: https://github.com/d3/d3-hierarchy#tree_nodeSize
|
|
13
|
+
*/
|
|
14
|
+
export let nodeSize: [number, number] | undefined = undefined;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* see: https://github.com/d3/d3-hierarchy#tree_separation
|
|
18
|
+
*/
|
|
19
|
+
export let separation:
|
|
20
|
+
| ((a: HierarchyPointNode<any>, b: HierarchyPointNode<any>) => number)
|
|
21
|
+
| undefined = undefined;
|
|
22
|
+
|
|
23
|
+
export let orientation: 'vertical' | 'horizontal' = 'horizontal';
|
|
24
|
+
|
|
25
|
+
let tree: TreeLayout<any>;
|
|
26
|
+
$: {
|
|
19
27
|
tree = d3Tree().size(orientation === 'horizontal' ? [$height, $width] : [$width, $height]);
|
|
28
|
+
|
|
20
29
|
if (nodeSize) {
|
|
21
|
-
|
|
30
|
+
tree.nodeSize(nodeSize);
|
|
22
31
|
}
|
|
23
32
|
if (separation) {
|
|
24
|
-
|
|
33
|
+
tree.separation(separation);
|
|
25
34
|
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// @ts-expect-error
|
|
38
|
+
$: treeData = tree($data);
|
|
29
39
|
</script>
|
|
30
40
|
|
|
31
41
|
<slot nodes={treeData.descendants()} links={treeData.links()} />
|