layerchart 0.81.3 → 0.90.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 +49 -14
- package/dist/components/Area.svelte +35 -11
- package/dist/components/Bar.svelte +15 -10
- package/dist/components/Bars.svelte +3 -3
- package/dist/components/Brush.svelte +20 -21
- package/dist/components/Calendar.svelte +2 -2
- package/dist/components/Chart.svelte +17 -4
- package/dist/components/Chart.svelte.d.ts +21 -10
- package/dist/components/ChartClipPath.svelte +0 -1
- package/dist/components/ChartClipPath.svelte.d.ts +0 -2
- package/dist/components/ChartContext.svelte +4 -11
- package/dist/components/ChartContext.svelte.d.ts +1 -1
- package/dist/components/Circle.svelte +35 -11
- package/dist/components/ClipPath.svelte +1 -1
- package/dist/components/ClipPath.svelte.d.ts +0 -5
- package/dist/components/ForceSimulation.svelte +8 -12
- package/dist/components/ForceSimulation.svelte.d.ts +6 -8
- package/dist/components/Frame.svelte +4 -7
- package/dist/components/Frame.svelte.d.ts +1 -5
- package/dist/components/GeoCircle.svelte +7 -1
- package/dist/components/GeoCircle.svelte.d.ts +6 -7
- package/dist/components/GeoPath.svelte +68 -39
- package/dist/components/GeoPath.svelte.d.ts +6 -12
- package/dist/components/GeoPoint.svelte +3 -24
- package/dist/components/GeoPoint.svelte.d.ts +4 -5
- package/dist/components/Graticule.svelte.d.ts +12 -6
- package/dist/components/Group.svelte +26 -6
- package/dist/components/Highlight.svelte +22 -12
- package/dist/components/Hull.svelte +20 -15
- package/dist/components/Hull.svelte.d.ts +7 -9
- package/dist/components/Legend.svelte +7 -7
- package/dist/components/Legend.svelte.d.ts +3 -3
- package/dist/components/Line.svelte +35 -10
- package/dist/components/Link.svelte +16 -9
- package/dist/components/Points.svelte +24 -57
- package/dist/components/Points.svelte.d.ts +0 -1
- package/dist/components/Rect.svelte +46 -15
- package/dist/components/Sankey.svelte +3 -4
- package/dist/components/Sankey.svelte.d.ts +1 -2
- package/dist/components/Spline.svelte +47 -11
- package/dist/components/Text.svelte +12 -6
- package/dist/components/TransformContext.svelte +8 -10
- package/dist/components/TransformContext.svelte.d.ts +9 -9
- package/dist/components/Voronoi.svelte +62 -40
- package/dist/components/Voronoi.svelte.d.ts +14 -13
- package/dist/components/charts/AreaChart.svelte +23 -15
- package/dist/components/charts/BarChart.svelte +24 -11
- package/dist/components/charts/LineChart.svelte +23 -15
- package/dist/components/charts/PieChart.svelte +22 -15
- package/dist/components/charts/PieChart.svelte.d.ts +29 -7
- package/dist/components/charts/ScatterChart.svelte +13 -7
- package/dist/components/index.d.ts +0 -1
- package/dist/components/index.js +0 -1
- package/dist/components/layout/Canvas.svelte +148 -7
- package/dist/components/layout/Canvas.svelte.d.ts +15 -2
- package/dist/components/tooltip/TooltipContext.svelte +25 -20
- package/dist/components/tooltip/TooltipContext.svelte.d.ts +6 -2
- package/dist/utils/canvas.js +39 -33
- package/dist/utils/color.d.ts +15 -0
- package/dist/utils/color.js +15 -0
- package/package.json +1 -1
- package/dist/components/Brush.svelte.d.ts +0 -65
- package/dist/components/HitCanvas.svelte +0 -118
- package/dist/components/HitCanvas.svelte.d.ts +0 -32
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
import { arc as d3arc } from 'd3-shape';
|
|
24
24
|
import { scaleLinear } from 'd3-scale';
|
|
25
25
|
import { min, max } from 'd3-array';
|
|
26
|
+
import { merge } from 'lodash-es';
|
|
26
27
|
|
|
27
28
|
import { objectId } from '@layerstack/utils/object';
|
|
28
29
|
|
|
@@ -31,7 +32,7 @@
|
|
|
31
32
|
import { degreesToRadians } from '../utils/math.js';
|
|
32
33
|
import type { TooltipContextValue } from './tooltip/TooltipContext.svelte';
|
|
33
34
|
import { getCanvasContext } from './layout/Canvas.svelte';
|
|
34
|
-
import { renderPathData } from '../utils/canvas.js';
|
|
35
|
+
import { renderPathData, type ComputedStylesOptions } from '../utils/canvas.js';
|
|
35
36
|
|
|
36
37
|
export let spring: boolean | Parameters<typeof springStore>[1] = undefined;
|
|
37
38
|
export let tweened: boolean | Parameters<typeof tweenedStore>[1] = undefined;
|
|
@@ -94,6 +95,11 @@
|
|
|
94
95
|
|
|
95
96
|
export let track: boolean | SVGAttributes<SVGPathElement> = false;
|
|
96
97
|
|
|
98
|
+
export let onclick: ((e: MouseEvent) => void) | undefined = undefined;
|
|
99
|
+
export let onpointerenter: ((e: PointerEvent) => void) | undefined = undefined;
|
|
100
|
+
export let onpointermove: ((e: PointerEvent) => void) | undefined = undefined;
|
|
101
|
+
export let onpointerleave: ((e: PointerEvent) => void) | undefined = undefined;
|
|
102
|
+
|
|
97
103
|
const { yRange } = chartContext();
|
|
98
104
|
|
|
99
105
|
$: scale = scaleLinear().domain(domain).range(range);
|
|
@@ -199,7 +205,10 @@
|
|
|
199
205
|
const canvasContext = getCanvasContext();
|
|
200
206
|
const renderContext = canvasContext ? 'canvas' : 'svg';
|
|
201
207
|
|
|
202
|
-
function render(
|
|
208
|
+
function render(
|
|
209
|
+
ctx: CanvasRenderingContext2D,
|
|
210
|
+
styleOverrides: ComputedStylesOptions | undefined
|
|
211
|
+
) {
|
|
203
212
|
ctx.translate(xOffset, yOffset);
|
|
204
213
|
|
|
205
214
|
// Track
|
|
@@ -216,10 +225,16 @@
|
|
|
216
225
|
});
|
|
217
226
|
|
|
218
227
|
// Arc
|
|
219
|
-
renderPathData(
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
228
|
+
renderPathData(
|
|
229
|
+
ctx,
|
|
230
|
+
arc(),
|
|
231
|
+
styleOverrides
|
|
232
|
+
? merge({ styles: { strokeWidth } }, styleOverrides)
|
|
233
|
+
: {
|
|
234
|
+
styles: { fill, fillOpacity, stroke, strokeWidth },
|
|
235
|
+
classes: className,
|
|
236
|
+
}
|
|
237
|
+
);
|
|
223
238
|
}
|
|
224
239
|
|
|
225
240
|
// TODO: Use objectId to work around Svelte 4 reactivity issue (even when memoizing gradients)
|
|
@@ -232,9 +247,32 @@
|
|
|
232
247
|
canvasContext.invalidate();
|
|
233
248
|
}
|
|
234
249
|
|
|
250
|
+
// Hide `tooltip` reactivity
|
|
251
|
+
function _onPointerEnter(e: PointerEvent) {
|
|
252
|
+
onpointerenter?.(e);
|
|
253
|
+
tooltip?.show(e, data);
|
|
254
|
+
}
|
|
255
|
+
function _onPointerMove(e: PointerEvent) {
|
|
256
|
+
onpointermove?.(e);
|
|
257
|
+
tooltip?.show(e, data);
|
|
258
|
+
}
|
|
259
|
+
function _onPointerLeave(e: PointerEvent) {
|
|
260
|
+
onpointerleave?.(e);
|
|
261
|
+
tooltip?.hide();
|
|
262
|
+
}
|
|
263
|
+
|
|
235
264
|
let canvasUnregister: ReturnType<typeof canvasContext.register>;
|
|
236
265
|
$: if (renderContext === 'canvas') {
|
|
237
|
-
canvasUnregister = canvasContext.register({
|
|
266
|
+
canvasUnregister = canvasContext.register({
|
|
267
|
+
name: 'Arc',
|
|
268
|
+
render,
|
|
269
|
+
events: {
|
|
270
|
+
click: onclick,
|
|
271
|
+
pointerenter: _onPointerEnter,
|
|
272
|
+
pointermove: _onPointerMove,
|
|
273
|
+
pointerleave: _onPointerLeave,
|
|
274
|
+
},
|
|
275
|
+
});
|
|
238
276
|
}
|
|
239
277
|
|
|
240
278
|
onDestroy(() => {
|
|
@@ -264,19 +302,16 @@
|
|
|
264
302
|
stroke-width={strokeWidth}
|
|
265
303
|
class={className}
|
|
266
304
|
{...$$restProps}
|
|
267
|
-
on:
|
|
268
|
-
on:
|
|
269
|
-
on:
|
|
305
|
+
on:click={onclick}
|
|
306
|
+
on:pointerenter={onpointerenter}
|
|
307
|
+
on:pointermove={_onPointerMove}
|
|
308
|
+
on:pointerleave={_onPointerLeave}
|
|
270
309
|
on:touchmove={(e) => {
|
|
271
310
|
if (tooltip) {
|
|
272
311
|
// Prevent touch to not interfer with pointer when using tooltip
|
|
273
312
|
e.preventDefault();
|
|
274
313
|
}
|
|
275
314
|
}}
|
|
276
|
-
on:click
|
|
277
|
-
on:pointerenter
|
|
278
|
-
on:pointermove
|
|
279
|
-
on:pointerleave
|
|
280
315
|
on:touchmove
|
|
281
316
|
/>
|
|
282
317
|
{/if}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import type { CurveFactory } from 'd3-shape';
|
|
6
6
|
import { max, min } from 'd3-array';
|
|
7
7
|
import { interpolatePath } from 'd3-interpolate-path';
|
|
8
|
+
import { merge } from 'lodash-es';
|
|
8
9
|
|
|
9
10
|
import { cls } from '@layerstack/tailwind';
|
|
10
11
|
import { objectId } from '@layerstack/utils/object';
|
|
@@ -15,8 +16,8 @@
|
|
|
15
16
|
import Spline from './Spline.svelte';
|
|
16
17
|
import { accessor, type Accessor } from '../utils/common.js';
|
|
17
18
|
import { isScaleBand } from '../utils/scales.js';
|
|
18
|
-
import { renderPathData } from '../utils/canvas.js';
|
|
19
19
|
import { getCanvasContext } from './layout/Canvas.svelte';
|
|
20
|
+
import { renderPathData, type ComputedStylesOptions } from '../utils/canvas.js';
|
|
20
21
|
|
|
21
22
|
const {
|
|
22
23
|
data: contextData,
|
|
@@ -63,6 +64,11 @@
|
|
|
63
64
|
let className: string | undefined = undefined;
|
|
64
65
|
export { className as class };
|
|
65
66
|
|
|
67
|
+
export let onclick: ((e: MouseEvent) => void) | undefined = undefined;
|
|
68
|
+
export let onpointerenter: ((e: PointerEvent) => void) | undefined = undefined;
|
|
69
|
+
export let onpointermove: ((e: PointerEvent) => void) | undefined = undefined;
|
|
70
|
+
export let onpointerleave: ((e: PointerEvent) => void) | undefined = undefined;
|
|
71
|
+
|
|
66
72
|
$: xAccessor = x ? accessor(x) : $contextX;
|
|
67
73
|
$: y0Accessor = y0 ? accessor(y0) : (d: any) => min($yDomain);
|
|
68
74
|
$: y1Accessor = y1 ? accessor(y1) : $y;
|
|
@@ -140,11 +146,20 @@
|
|
|
140
146
|
const canvasContext = getCanvasContext();
|
|
141
147
|
const renderContext = canvasContext ? 'canvas' : 'svg';
|
|
142
148
|
|
|
143
|
-
function render(
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
149
|
+
function render(
|
|
150
|
+
ctx: CanvasRenderingContext2D,
|
|
151
|
+
styleOverrides: ComputedStylesOptions | undefined
|
|
152
|
+
) {
|
|
153
|
+
renderPathData(
|
|
154
|
+
ctx,
|
|
155
|
+
$tweened_d,
|
|
156
|
+
styleOverrides
|
|
157
|
+
? merge({ styles: { strokeWidth } }, styleOverrides)
|
|
158
|
+
: {
|
|
159
|
+
styles: { fill, fillOpacity, stroke, strokeWidth },
|
|
160
|
+
classes: className,
|
|
161
|
+
}
|
|
162
|
+
);
|
|
148
163
|
}
|
|
149
164
|
|
|
150
165
|
// TODO: Use objectId to work around Svelte 4 reactivity issue (even when memoizing gradients)
|
|
@@ -159,7 +174,16 @@
|
|
|
159
174
|
|
|
160
175
|
let canvasUnregister: ReturnType<typeof canvasContext.register>;
|
|
161
176
|
$: if (renderContext === 'canvas') {
|
|
162
|
-
canvasUnregister = canvasContext.register({
|
|
177
|
+
canvasUnregister = canvasContext.register({
|
|
178
|
+
name: 'Area',
|
|
179
|
+
render,
|
|
180
|
+
events: {
|
|
181
|
+
click: onclick,
|
|
182
|
+
pointerenter: onpointerenter,
|
|
183
|
+
pointermove: onpointermove,
|
|
184
|
+
pointerleave: onpointerleave,
|
|
185
|
+
},
|
|
186
|
+
});
|
|
163
187
|
|
|
164
188
|
tweened_d.subscribe(() => {
|
|
165
189
|
canvasContext.invalidate();
|
|
@@ -173,7 +197,6 @@
|
|
|
173
197
|
});
|
|
174
198
|
</script>
|
|
175
199
|
|
|
176
|
-
<!-- TODO: Find way to not clear <Canvas> when rendering Spline (remove Area rendering). Idea: https://github.com/techniq/layerchart/issues/158#issuecomment-2543416108 -->
|
|
177
200
|
{#if line}
|
|
178
201
|
<Spline
|
|
179
202
|
{data}
|
|
@@ -197,8 +220,9 @@
|
|
|
197
220
|
stroke-width={strokeWidth}
|
|
198
221
|
{...$$restProps}
|
|
199
222
|
class={cls('path-area', className)}
|
|
200
|
-
on:click
|
|
201
|
-
on:
|
|
202
|
-
on:
|
|
223
|
+
on:click={onclick}
|
|
224
|
+
on:pointerenter={onpointerenter}
|
|
225
|
+
on:pointermove={onpointermove}
|
|
226
|
+
on:pointerleave={onpointerleave}
|
|
203
227
|
/>
|
|
204
228
|
{/if}
|
|
@@ -56,6 +56,11 @@
|
|
|
56
56
|
|
|
57
57
|
export let insets: Insets | undefined = undefined;
|
|
58
58
|
|
|
59
|
+
export let onclick: ((e: MouseEvent) => void) | undefined = undefined;
|
|
60
|
+
export let onpointerenter: ((e: PointerEvent) => void) | undefined = undefined;
|
|
61
|
+
export let onpointermove: ((e: PointerEvent) => void) | undefined = undefined;
|
|
62
|
+
export let onpointerleave: ((e: PointerEvent) => void) | undefined = undefined;
|
|
63
|
+
|
|
59
64
|
export let spring: ComponentProps<Rect>['spring'] = undefined;
|
|
60
65
|
export let tweened: ComponentProps<Rect>['tweened'] = undefined;
|
|
61
66
|
|
|
@@ -120,13 +125,13 @@
|
|
|
120
125
|
{stroke}
|
|
121
126
|
{strokeWidth}
|
|
122
127
|
rx={radius}
|
|
128
|
+
{onclick}
|
|
129
|
+
{onpointerenter}
|
|
130
|
+
{onpointermove}
|
|
131
|
+
{onpointerleave}
|
|
132
|
+
on:touchmove
|
|
123
133
|
{...dimensions}
|
|
124
134
|
{...$$restProps}
|
|
125
|
-
on:click
|
|
126
|
-
on:pointerenter
|
|
127
|
-
on:pointermove
|
|
128
|
-
on:pointerleave
|
|
129
|
-
on:touchmove
|
|
130
135
|
/>
|
|
131
136
|
{:else}
|
|
132
137
|
<Spline
|
|
@@ -136,11 +141,11 @@
|
|
|
136
141
|
{tweened}
|
|
137
142
|
{stroke}
|
|
138
143
|
{strokeWidth}
|
|
139
|
-
{
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
on:pointerleave
|
|
144
|
+
{onclick}
|
|
145
|
+
{onpointerenter}
|
|
146
|
+
{onpointermove}
|
|
147
|
+
{onpointerleave}
|
|
144
148
|
on:touchmove
|
|
149
|
+
{...$$restProps}
|
|
145
150
|
/>
|
|
146
151
|
{/if}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import Bar from './Bar.svelte';
|
|
6
6
|
import Rect from './Rect.svelte';
|
|
7
7
|
import { chartDataArray, type Accessor } from '../utils/common.js';
|
|
8
|
-
import type { Insets } from '../
|
|
8
|
+
import type { Insets } from '../utils/rect.js';
|
|
9
9
|
|
|
10
10
|
const { data: contextData, cGet, config } = chartContext();
|
|
11
11
|
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
export let tweened: ComponentProps<Rect>['tweened'] = undefined;
|
|
50
50
|
|
|
51
51
|
/** Event dispatched when individual Bar is clicked */
|
|
52
|
-
export let
|
|
52
|
+
export let onbarclick: (e: MouseEvent, detail: { data: any }) => void = () => {};
|
|
53
53
|
|
|
54
54
|
$: _data = chartDataArray(data ?? $contextData);
|
|
55
55
|
</script>
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
{insets}
|
|
71
71
|
{spring}
|
|
72
72
|
{tweened}
|
|
73
|
-
|
|
73
|
+
onclick={(e) => onbarclick(e, { data: d })}
|
|
74
74
|
{...$$restProps}
|
|
75
75
|
/>
|
|
76
76
|
{/each}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { type ComponentProps } from 'svelte';
|
|
3
|
-
import type { SVGAttributes } from 'svelte/elements';
|
|
4
3
|
import { extent, min, max } from 'd3-array';
|
|
5
4
|
import { clamp } from '@layerstack/utils';
|
|
6
5
|
import { cls } from '@layerstack/tailwind';
|
|
@@ -14,6 +13,7 @@
|
|
|
14
13
|
import { localPoint } from '../utils/event.js';
|
|
15
14
|
import type { DomainType } from '../utils/scales.js';
|
|
16
15
|
import { asAny } from '../utils/types.js';
|
|
16
|
+
import Rect from './Rect.svelte';
|
|
17
17
|
|
|
18
18
|
const { xScale, yScale, width, height, padding, config } = chartContext();
|
|
19
19
|
|
|
@@ -45,10 +45,10 @@
|
|
|
45
45
|
$: [yDomainMin, yDomainMax] = extent<number>($yScale.domain()) as [number, number];
|
|
46
46
|
|
|
47
47
|
/** Attributes passed to range <rect> element */
|
|
48
|
-
export let range:
|
|
48
|
+
export let range: Partial<ComponentProps<Rect>> | undefined = undefined;
|
|
49
49
|
|
|
50
50
|
/** Attributes passed to handle <rect> elements */
|
|
51
|
-
export let handle:
|
|
51
|
+
export let handle: Partial<ComponentProps<Rect>> | undefined = undefined;
|
|
52
52
|
|
|
53
53
|
/** Apply format to labels, if shown */
|
|
54
54
|
export let format: FormatType | undefined = undefined;
|
|
@@ -235,16 +235,15 @@
|
|
|
235
235
|
<g class={cls('Brush select-none', classes.root, $$props.class)}>
|
|
236
236
|
<Frame
|
|
237
237
|
class={cls('frame', 'fill-transparent', classes.frame)}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
bind:
|
|
238
|
+
onpointerdown={createRange}
|
|
239
|
+
ondblclick={() => selectAll()}
|
|
240
|
+
bind:element={frameEl}
|
|
241
241
|
/>
|
|
242
242
|
|
|
243
243
|
{#if isActive}
|
|
244
|
-
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
|
245
244
|
<Group x={rangeLeft} y={rangeTop} class="range">
|
|
246
245
|
<slot name="range" {rangeWidth} {rangeHeight}>
|
|
247
|
-
<
|
|
246
|
+
<Rect
|
|
248
247
|
width={rangeWidth}
|
|
249
248
|
height={rangeHeight}
|
|
250
249
|
class={cls(
|
|
@@ -252,8 +251,8 @@
|
|
|
252
251
|
range?.fill == null && 'fill-surface-content/10',
|
|
253
252
|
classes.range
|
|
254
253
|
)}
|
|
255
|
-
|
|
256
|
-
|
|
254
|
+
onpointerdown={adjustRange}
|
|
255
|
+
ondblclick={() => reset()}
|
|
257
256
|
{...range}
|
|
258
257
|
/>
|
|
259
258
|
</slot>
|
|
@@ -264,8 +263,8 @@
|
|
|
264
263
|
x={rangeLeft}
|
|
265
264
|
y={rangeTop}
|
|
266
265
|
class="handle top"
|
|
267
|
-
|
|
268
|
-
|
|
266
|
+
onpointerdown={adjustTop}
|
|
267
|
+
ondblclick={() => {
|
|
269
268
|
if (yDomain) {
|
|
270
269
|
yDomain[0] = yDomainMin;
|
|
271
270
|
onChange({ xDomain, yDomain });
|
|
@@ -273,7 +272,7 @@
|
|
|
273
272
|
}}
|
|
274
273
|
>
|
|
275
274
|
<slot name="handle" edge="top" {rangeWidth} {rangeHeight}>
|
|
276
|
-
<
|
|
275
|
+
<Rect
|
|
277
276
|
width={rangeWidth}
|
|
278
277
|
height={handleSize}
|
|
279
278
|
class={cls('fill-transparent cursor-ns-resize select-none', classes.handle)}
|
|
@@ -286,15 +285,15 @@
|
|
|
286
285
|
x={rangeLeft}
|
|
287
286
|
y={bottom - handleSize + 1}
|
|
288
287
|
class="handle bottom"
|
|
289
|
-
|
|
290
|
-
|
|
288
|
+
onpointerdown={adjustBottom}
|
|
289
|
+
ondblclick={() => {
|
|
291
290
|
if (yDomain) {
|
|
292
291
|
yDomain[1] = yDomainMax;
|
|
293
292
|
}
|
|
294
293
|
}}
|
|
295
294
|
>
|
|
296
295
|
<slot name="handle" edge="bottom" {rangeWidth} {rangeHeight}>
|
|
297
|
-
<
|
|
296
|
+
<Rect
|
|
298
297
|
width={rangeWidth}
|
|
299
298
|
height={handleSize}
|
|
300
299
|
class={cls('fill-transparent cursor-ns-resize select-none', classes.handle)}
|
|
@@ -309,8 +308,8 @@
|
|
|
309
308
|
x={rangeLeft}
|
|
310
309
|
y={rangeTop}
|
|
311
310
|
class="handle left"
|
|
312
|
-
|
|
313
|
-
|
|
311
|
+
onpointerdown={adjustLeft}
|
|
312
|
+
ondblclick={() => {
|
|
314
313
|
if (xDomain) {
|
|
315
314
|
xDomain[0] = xDomainMin;
|
|
316
315
|
onChange({ xDomain, yDomain });
|
|
@@ -331,8 +330,8 @@
|
|
|
331
330
|
x={right - handleSize + 1}
|
|
332
331
|
y={rangeTop}
|
|
333
332
|
class="handle right"
|
|
334
|
-
|
|
335
|
-
|
|
333
|
+
onpointerdown={adjustRight}
|
|
334
|
+
ondblclick={() => {
|
|
336
335
|
if (xDomain) {
|
|
337
336
|
xDomain[1] = xDomainMax;
|
|
338
337
|
onChange({ xDomain, yDomain });
|
|
@@ -340,7 +339,7 @@
|
|
|
340
339
|
}}
|
|
341
340
|
>
|
|
342
341
|
<slot name="handle" edge="right" {rangeWidth} {rangeHeight}>
|
|
343
|
-
<
|
|
342
|
+
<Rect
|
|
344
343
|
width={handleSize}
|
|
345
344
|
height={rangeHeight}
|
|
346
345
|
class={cls('fill-transparent cursor-ew-resize select-none', classes.handle)}
|
|
@@ -64,8 +64,8 @@
|
|
|
64
64
|
width={cellWidth}
|
|
65
65
|
height={cellHeight}
|
|
66
66
|
fill={cell.color}
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
onpointermove={(e) => tooltip?.show(e, cell.data)}
|
|
68
|
+
onpointerleave={(e) => tooltip?.hide()}
|
|
69
69
|
class="stroke-surface-content/5"
|
|
70
70
|
{...$$restProps}
|
|
71
71
|
/>
|
|
@@ -209,6 +209,14 @@
|
|
|
209
209
|
|
|
210
210
|
/** Exposed via bind: to support `bind:tooltipContext` for external access (ex. `tooltipContext.data) */
|
|
211
211
|
tooltipContext?: typeof tooltipContext;
|
|
212
|
+
|
|
213
|
+
// ChartContext callback events
|
|
214
|
+
onresize?: typeof onresize;
|
|
215
|
+
|
|
216
|
+
// TransformContext callback events
|
|
217
|
+
ondragstart?: typeof ondragstart;
|
|
218
|
+
ondragend?: typeof ondragend;
|
|
219
|
+
ontransform?: typeof ontransform;
|
|
212
220
|
}
|
|
213
221
|
|
|
214
222
|
export let data: TData[] | HierarchyNode<TData> | SankeyGraph<any, any> = [];
|
|
@@ -284,6 +292,11 @@
|
|
|
284
292
|
/** Expose bound tooltip context */
|
|
285
293
|
export let tooltipContext: ComponentProps<TooltipContext>['tooltip'] = undefined;
|
|
286
294
|
|
|
295
|
+
export let onresize: ComponentProps<ChartContext<TData>>['onresize'] = undefined;
|
|
296
|
+
export let ondragstart: ComponentProps<TransformContext>['ondragstart'] = undefined;
|
|
297
|
+
export let ondragend: ComponentProps<TransformContext>['ondragend'] = undefined;
|
|
298
|
+
export let ontransform: ComponentProps<TransformContext>['ontransform'] = undefined;
|
|
299
|
+
|
|
287
300
|
// Track when mounted since LayerCake initializes width/height with `100` until bound `clientWidth`/`clientWidth` can run
|
|
288
301
|
// Useful to key/remount TransformContext with correct `initialTranslate` / `initialScale` values
|
|
289
302
|
let isMounted = false;
|
|
@@ -370,7 +383,7 @@
|
|
|
370
383
|
let:c
|
|
371
384
|
let:cScale
|
|
372
385
|
let:cGet
|
|
373
|
-
|
|
386
|
+
{onresize}
|
|
374
387
|
>
|
|
375
388
|
{#key isMounted}
|
|
376
389
|
<TransformContext
|
|
@@ -401,9 +414,9 @@
|
|
|
401
414
|
: undefined}
|
|
402
415
|
{...transform}
|
|
403
416
|
let:transform={_transform}
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
417
|
+
{ondragstart}
|
|
418
|
+
{ontransform}
|
|
419
|
+
{ondragend}
|
|
407
420
|
>
|
|
408
421
|
<GeoContext {...geo} bind:geo={geoProjection} let:projection>
|
|
409
422
|
{@const tooltipProps = typeof tooltip === 'object' ? tooltip : {}}
|
|
@@ -184,13 +184,13 @@ declare class __sveltets_Render<TData> {
|
|
|
184
184
|
}> | undefined;
|
|
185
185
|
/** Props passed to TooltipContext */
|
|
186
186
|
tooltip?: boolean | Partial<{
|
|
187
|
-
mode?: "bisect-x" | "bisect-y" | "band" | "bisect-band" | "bounds" | "voronoi" | "quadtree"
|
|
187
|
+
mode?: "manual" | "bisect-x" | "bisect-y" | "band" | "bisect-band" | "bounds" | "voronoi" | "quadtree";
|
|
188
188
|
findTooltipData?: "closest" | "left" | "right";
|
|
189
189
|
raiseTarget?: boolean;
|
|
190
190
|
locked?: boolean;
|
|
191
191
|
radius?: number;
|
|
192
192
|
debug?: boolean;
|
|
193
|
-
|
|
193
|
+
onclick?: ({ data }: {
|
|
194
194
|
data: any;
|
|
195
195
|
}) => any;
|
|
196
196
|
tooltip?: import("svelte/store").Writable<{
|
|
@@ -199,6 +199,7 @@ declare class __sveltets_Render<TData> {
|
|
|
199
199
|
data: any;
|
|
200
200
|
show: (e: PointerEvent, tooltipData?: any) => void;
|
|
201
201
|
hide: () => void;
|
|
202
|
+
mode: "manual" | "bisect-x" | "bisect-y" | "band" | "bisect-band" | "bounds" | "voronoi" | "quadtree";
|
|
202
203
|
}>;
|
|
203
204
|
}> | undefined;
|
|
204
205
|
/** Props passed to TransformContext */
|
|
@@ -214,6 +215,15 @@ declare class __sveltets_Render<TData> {
|
|
|
214
215
|
disablePointer?: boolean;
|
|
215
216
|
initialScrollMode?: "none" | "scale" | "translate";
|
|
216
217
|
clickDistance?: number;
|
|
218
|
+
ondragstart?: (() => void) | undefined;
|
|
219
|
+
ondragend?: (() => void) | undefined;
|
|
220
|
+
ontransform?: ((e: {
|
|
221
|
+
scale: number;
|
|
222
|
+
translate: {
|
|
223
|
+
x: number;
|
|
224
|
+
y: number;
|
|
225
|
+
};
|
|
226
|
+
}) => void) | undefined;
|
|
217
227
|
initialTranslate?: {
|
|
218
228
|
x: number;
|
|
219
229
|
y: number;
|
|
@@ -259,20 +269,20 @@ declare class __sveltets_Render<TData> {
|
|
|
259
269
|
data: any;
|
|
260
270
|
show: (e: PointerEvent, tooltipData?: any) => void;
|
|
261
271
|
hide: () => void;
|
|
272
|
+
mode: "manual" | "bisect-x" | "bisect-y" | "band" | "bisect-band" | "bounds" | "voronoi" | "quadtree";
|
|
262
273
|
}> | undefined;
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
274
|
+
onresize?: ((e: import("./ChartContext.svelte").ChartResizeDetail) => void) | undefined;
|
|
275
|
+
ondragstart?: (() => void) | undefined;
|
|
276
|
+
ondragend?: (() => void) | undefined;
|
|
277
|
+
ontransform?: ((e: {
|
|
267
278
|
scale: number;
|
|
268
279
|
translate: {
|
|
269
280
|
x: number;
|
|
270
281
|
y: number;
|
|
271
282
|
};
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
} & {
|
|
283
|
+
}) => void) | undefined;
|
|
284
|
+
};
|
|
285
|
+
events(): {} & {
|
|
276
286
|
[evt: string]: CustomEvent<any>;
|
|
277
287
|
};
|
|
278
288
|
slots(): {
|
|
@@ -310,6 +320,7 @@ declare class __sveltets_Render<TData> {
|
|
|
310
320
|
data: any;
|
|
311
321
|
show: (e: PointerEvent, tooltipData?: any) => void;
|
|
312
322
|
hide: () => void;
|
|
323
|
+
mode: "manual" | "bisect-x" | "bisect-y" | "band" | "bisect-band" | "bounds" | "voronoi" | "quadtree";
|
|
313
324
|
};
|
|
314
325
|
x: Function;
|
|
315
326
|
xScale: any;
|
|
@@ -3,13 +3,7 @@
|
|
|
3
3
|
import { createScale, type AnyScale } from '../utils/scales.js';
|
|
4
4
|
|
|
5
5
|
import type { HierarchyNode } from 'd3-hierarchy';
|
|
6
|
-
import {
|
|
7
|
-
createEventDispatcher,
|
|
8
|
-
getContext,
|
|
9
|
-
onMount,
|
|
10
|
-
setContext,
|
|
11
|
-
type ComponentProps,
|
|
12
|
-
} from 'svelte';
|
|
6
|
+
import { getContext, onMount, setContext } from 'svelte';
|
|
13
7
|
import { derived, writable, type Readable } from 'svelte/store';
|
|
14
8
|
|
|
15
9
|
export const chartContextKey = Symbol();
|
|
@@ -102,8 +96,6 @@
|
|
|
102
96
|
containerHeight: number;
|
|
103
97
|
};
|
|
104
98
|
|
|
105
|
-
export type ChartResizeEvent = CustomEvent<ChartResizeDetail>;
|
|
106
|
-
|
|
107
99
|
export type ChartContext<TData> = LayerCakeContext<TData> & {
|
|
108
100
|
// Additional context values
|
|
109
101
|
radial: Readable<boolean>;
|
|
@@ -266,9 +258,10 @@
|
|
|
266
258
|
};
|
|
267
259
|
setChartContext(chartContext);
|
|
268
260
|
|
|
269
|
-
|
|
261
|
+
export let onresize: ((e: ChartResizeDetail) => void) | undefined = undefined;
|
|
262
|
+
|
|
270
263
|
$: if (isMounted) {
|
|
271
|
-
|
|
264
|
+
onresize?.({
|
|
272
265
|
width: $width,
|
|
273
266
|
height: $height,
|
|
274
267
|
containerWidth: $containerWidth,
|
|
@@ -88,7 +88,6 @@ export type ChartResizeDetail = {
|
|
|
88
88
|
containerWidth: number;
|
|
89
89
|
containerHeight: number;
|
|
90
90
|
};
|
|
91
|
-
export type ChartResizeEvent = CustomEvent<ChartResizeDetail>;
|
|
92
91
|
export type ChartContext<TData> = LayerCakeContext<TData> & {
|
|
93
92
|
radial: Readable<boolean>;
|
|
94
93
|
};
|
|
@@ -109,6 +108,7 @@ declare class __sveltets_Render<TData> {
|
|
|
109
108
|
cDomain?: any;
|
|
110
109
|
cRange?: any;
|
|
111
110
|
/** Use radial instead of cartesian coordinates, mapping `x` to `angle` and `y`` to radial. Radial lines are positioned relative to the origin, use transform (ex. `<Group center>`) to change the origin */ radial?: boolean;
|
|
111
|
+
onresize?: ((e: ChartResizeDetail) => void) | undefined;
|
|
112
112
|
data?: SankeyGraph<any, any> | TData[] | HierarchyNode<TData> | undefined;
|
|
113
113
|
};
|
|
114
114
|
events(): {} & {
|