layerchart 0.80.0 → 0.81.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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import {
|
|
2
|
+
import { type ComponentProps } from 'svelte';
|
|
3
3
|
import type { SVGAttributes } from 'svelte/elements';
|
|
4
4
|
import { extent, min, max } from 'd3-array';
|
|
5
5
|
import { clamp } from '@layerstack/utils';
|
|
@@ -17,12 +17,6 @@
|
|
|
17
17
|
|
|
18
18
|
const { xScale, yScale, width, height, padding } = chartContext();
|
|
19
19
|
|
|
20
|
-
const dispatch = createEventDispatcher<{
|
|
21
|
-
change: { xDomain?: DomainType; yDomain?: DomainType };
|
|
22
|
-
brushStart: { xDomain?: DomainType; yDomain?: DomainType };
|
|
23
|
-
brushEnd: { xDomain?: DomainType; yDomain?: DomainType };
|
|
24
|
-
}>();
|
|
25
|
-
|
|
26
20
|
/** Axis to apply brushing */
|
|
27
21
|
export let axis: 'x' | 'y' | 'both' = 'x';
|
|
28
22
|
|
|
@@ -61,6 +55,10 @@
|
|
|
61
55
|
labels?: string;
|
|
62
56
|
} = {};
|
|
63
57
|
|
|
58
|
+
export let onChange: (e: { xDomain?: DomainType; yDomain?: DomainType }) => void = () => {};
|
|
59
|
+
export let onBrushStart: (e: { xDomain?: DomainType; yDomain?: DomainType }) => void = () => {};
|
|
60
|
+
export let onBrushEnd: (e: { xDomain?: DomainType; yDomain?: DomainType }) => void = () => {};
|
|
61
|
+
|
|
64
62
|
let frameEl: SVGRectElement;
|
|
65
63
|
|
|
66
64
|
function handler(
|
|
@@ -83,7 +81,7 @@
|
|
|
83
81
|
},
|
|
84
82
|
};
|
|
85
83
|
|
|
86
|
-
|
|
84
|
+
onBrushStart({ xDomain, yDomain });
|
|
87
85
|
|
|
88
86
|
const onPointerMove = (e: PointerEvent) => {
|
|
89
87
|
fn(start, {
|
|
@@ -95,17 +93,17 @@
|
|
|
95
93
|
// // Ignore?
|
|
96
94
|
// // TODO: What about when using `x` or `y` axis?
|
|
97
95
|
// } else {
|
|
98
|
-
|
|
96
|
+
onChange({ xDomain, yDomain });
|
|
99
97
|
// }
|
|
100
98
|
};
|
|
101
99
|
|
|
102
100
|
const onPointerUp = (e: PointerEvent) => {
|
|
103
101
|
if (e.target === frameEl) {
|
|
104
102
|
reset();
|
|
105
|
-
|
|
103
|
+
onChange({ xDomain, yDomain });
|
|
106
104
|
}
|
|
107
105
|
|
|
108
|
-
|
|
106
|
+
onBrushEnd({ xDomain, yDomain });
|
|
109
107
|
|
|
110
108
|
if (resetOnEnd) {
|
|
111
109
|
reset();
|
|
@@ -258,7 +256,7 @@
|
|
|
258
256
|
on:dblclick={() => {
|
|
259
257
|
if (yDomain) {
|
|
260
258
|
yDomain[0] = yDomainMin;
|
|
261
|
-
|
|
259
|
+
onChange({ xDomain, yDomain });
|
|
262
260
|
}
|
|
263
261
|
}}
|
|
264
262
|
>
|
|
@@ -303,7 +301,7 @@
|
|
|
303
301
|
on:dblclick={() => {
|
|
304
302
|
if (xDomain) {
|
|
305
303
|
xDomain[0] = xDomainMin;
|
|
306
|
-
|
|
304
|
+
onChange({ xDomain, yDomain });
|
|
307
305
|
}
|
|
308
306
|
}}
|
|
309
307
|
>
|
|
@@ -325,7 +323,7 @@
|
|
|
325
323
|
on:dblclick={() => {
|
|
326
324
|
if (xDomain) {
|
|
327
325
|
xDomain[1] = xDomainMax;
|
|
328
|
-
|
|
326
|
+
onChange({ xDomain, yDomain });
|
|
329
327
|
}
|
|
330
328
|
}}
|
|
331
329
|
>
|
|
@@ -23,21 +23,20 @@ declare const __propDef: {
|
|
|
23
23
|
handle?: string;
|
|
24
24
|
labels?: string;
|
|
25
25
|
} | undefined;
|
|
26
|
-
|
|
27
|
-
events: {
|
|
28
|
-
change: CustomEvent<{
|
|
26
|
+
onChange?: ((e: {
|
|
29
27
|
xDomain?: DomainType;
|
|
30
28
|
yDomain?: DomainType;
|
|
31
|
-
}
|
|
32
|
-
|
|
29
|
+
}) => void) | undefined;
|
|
30
|
+
onBrushStart?: ((e: {
|
|
33
31
|
xDomain?: DomainType;
|
|
34
32
|
yDomain?: DomainType;
|
|
35
|
-
}
|
|
36
|
-
|
|
33
|
+
}) => void) | undefined;
|
|
34
|
+
onBrushEnd?: ((e: {
|
|
37
35
|
xDomain?: DomainType;
|
|
38
36
|
yDomain?: DomainType;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
37
|
+
}) => void) | undefined;
|
|
38
|
+
};
|
|
39
|
+
events: {
|
|
41
40
|
[evt: string]: CustomEvent<any>;
|
|
42
41
|
};
|
|
43
42
|
slots: {
|
|
@@ -398,15 +398,16 @@
|
|
|
398
398
|
|
|
399
399
|
{#if brush && brush.mode === 'integrated'}
|
|
400
400
|
<Svg>
|
|
401
|
+
{@const brushProps = { ...(typeof brush === 'object' ? brush : null), ...props.brush }}
|
|
401
402
|
<Brush
|
|
402
403
|
axis="x"
|
|
403
404
|
resetOnEnd
|
|
404
405
|
{xDomain}
|
|
405
|
-
|
|
406
|
-
|
|
406
|
+
{...brushProps}
|
|
407
|
+
onBrushEnd={(e) => {
|
|
408
|
+
xDomain = e.xDomain;
|
|
409
|
+
brushProps.onBrushEnd?.(e);
|
|
407
410
|
}}
|
|
408
|
-
{...typeof brush === 'object' ? brush : null}
|
|
409
|
-
{...props.brush}
|
|
410
411
|
/>
|
|
411
412
|
</Svg>
|
|
412
413
|
{/if}
|
|
@@ -324,15 +324,16 @@
|
|
|
324
324
|
|
|
325
325
|
{#if brush && brush.mode === 'integrated'}
|
|
326
326
|
<Svg>
|
|
327
|
+
{@const brushProps = { ...(typeof brush === 'object' ? brush : null), ...props.brush }}
|
|
327
328
|
<Brush
|
|
328
329
|
axis="x"
|
|
329
330
|
resetOnEnd
|
|
330
331
|
{xDomain}
|
|
331
|
-
|
|
332
|
-
|
|
332
|
+
{...brushProps}
|
|
333
|
+
onBrushEnd={(e) => {
|
|
334
|
+
xDomain = e.xDomain;
|
|
335
|
+
brushProps.onBrushEnd?.(e);
|
|
333
336
|
}}
|
|
334
|
-
{...typeof brush === 'object' ? brush : null}
|
|
335
|
-
{...props.brush}
|
|
336
337
|
/>
|
|
337
338
|
</Svg>
|
|
338
339
|
{/if}
|
|
@@ -272,17 +272,18 @@
|
|
|
272
272
|
<!-- TODO: Determine how to coordinate with `tooltip={{ mode: 'voronoi' }} -->
|
|
273
273
|
{#if brush && brush.mode === 'integrated'}
|
|
274
274
|
<Svg>
|
|
275
|
+
{@const brushProps = { ...(typeof brush === 'object' ? brush : null), ...props.brush }}
|
|
275
276
|
<Brush
|
|
276
277
|
axis="both"
|
|
277
278
|
resetOnEnd
|
|
278
279
|
{xDomain}
|
|
279
280
|
{yDomain}
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
281
|
+
{...brushProps}
|
|
282
|
+
onBrushEnd={(e) => {
|
|
283
|
+
xDomain = e.xDomain;
|
|
284
|
+
yDomain = e.yDomain;
|
|
285
|
+
brushProps.onBrushEnd?.(e);
|
|
283
286
|
}}
|
|
284
|
-
{...typeof brush === 'object' ? brush : null}
|
|
285
|
-
{...props.brush}
|
|
286
287
|
/>
|
|
287
288
|
</Svg>
|
|
288
289
|
{/if}
|