layerchart 0.42.0 → 0.43.1
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 +27 -20
- package/dist/components/Arc.svelte.d.ts +2 -2
- package/dist/components/Area.svelte +11 -7
- package/dist/components/Area.svelte.d.ts +3 -3
- package/dist/components/AreaStack.svelte +3 -2
- package/dist/components/Axis.svelte +38 -41
- package/dist/components/Axis.svelte.d.ts +5 -4
- package/dist/components/Bar.svelte +6 -5
- package/dist/components/Bar.svelte.d.ts +3 -2
- package/dist/components/Bars.svelte +5 -4
- package/dist/components/Bars.svelte.d.ts +3 -2
- package/dist/components/Bounds.svelte +7 -5
- package/dist/components/Bounds.svelte.d.ts +8 -8
- package/dist/components/Brush.svelte +8 -6
- package/dist/components/Brush.svelte.d.ts +2 -2
- package/dist/components/Calendar.svelte +4 -3
- package/dist/components/Chart.svelte +71 -85
- package/dist/components/Chart.svelte.d.ts +216 -24
- package/dist/components/ChartClipPath.svelte +6 -6
- package/dist/components/ChartContext.svelte +19 -0
- package/dist/components/ChartContext.svelte.d.ts +89 -0
- package/dist/components/Circle.svelte +1 -0
- package/dist/components/ClipPath.svelte +1 -0
- package/dist/components/ForceSimulation.svelte +4 -3
- package/dist/components/ForceSimulation.svelte.d.ts +1 -2
- package/dist/components/Frame.svelte +8 -7
- package/dist/components/Frame.svelte.d.ts +1 -1
- package/dist/components/GeoCircle.svelte.d.ts +1 -2
- package/dist/components/GeoContext.svelte +2 -1
- package/dist/components/GeoContext.svelte.d.ts +5 -5
- package/dist/components/GeoEdgeFade.svelte +2 -5
- package/dist/components/GeoPath.svelte +9 -5
- package/dist/components/GeoPath.svelte.d.ts +7 -4
- package/dist/components/GeoPoint.svelte +0 -1
- package/dist/components/GeoSpline.svelte +2 -11
- package/dist/components/GeoTile.svelte +3 -1
- package/dist/components/Group.svelte +4 -2
- package/dist/components/Highlight.svelte +16 -10
- package/dist/components/Highlight.svelte.d.ts +16 -15
- package/dist/components/HitCanvas.svelte +5 -2
- package/dist/components/HitCanvas.svelte.d.ts +1 -1
- package/dist/components/Hull.svelte +6 -3
- package/dist/components/Labels.svelte +5 -4
- package/dist/components/Labels.svelte.d.ts +0 -1
- package/dist/components/Legend.svelte +4 -4
- package/dist/components/Legend.svelte.d.ts +2 -2
- package/dist/components/Line.svelte +1 -0
- package/dist/components/Link.svelte +3 -1
- package/dist/components/Pack.svelte +4 -3
- package/dist/components/Partition.svelte +3 -3
- package/dist/components/Partition.svelte.d.ts +2 -1
- package/dist/components/Pie.svelte +7 -6
- package/dist/components/Pie.svelte.d.ts +2 -4
- package/dist/components/Point.svelte +2 -2
- package/dist/components/Points.svelte +4 -3
- package/dist/components/RadialGradient.svelte +2 -2
- package/dist/components/RadialGradient.svelte.d.ts +0 -1
- package/dist/components/Rect.svelte +1 -0
- package/dist/components/Rule.svelte +3 -3
- package/dist/components/Sankey.svelte +9 -3
- package/dist/components/Sankey.svelte.d.ts +2 -2
- package/dist/components/Spline.svelte +9 -6
- package/dist/components/Spline.svelte.d.ts +2 -2
- package/dist/components/Text.svelte +1 -2
- package/dist/components/Threshold.svelte +2 -2
- package/dist/components/Threshold.svelte.d.ts +2 -2
- package/dist/components/TileImage.svelte +4 -1
- package/dist/components/Tooltip.svelte +3 -3
- package/dist/components/TooltipContext.svelte +46 -15
- package/dist/components/TooltipContext.svelte.d.ts +1 -1
- package/dist/components/TooltipItem.svelte.d.ts +1 -1
- package/dist/components/TransformContext.svelte +17 -6
- package/dist/components/TransformControls.svelte +1 -0
- package/dist/components/Tree.svelte +4 -3
- package/dist/components/Tree.svelte.d.ts +3 -3
- package/dist/components/Treemap.svelte +11 -12
- package/dist/components/Treemap.svelte.d.ts +6 -6
- package/dist/components/Voronoi.svelte +8 -3
- package/dist/components/layout/Canvas.svelte +5 -3
- package/dist/components/layout/Html.svelte +3 -3
- package/dist/components/layout/Svg.svelte +6 -3
- package/dist/docs/Code.svelte +2 -3
- package/dist/docs/GeoDebug.svelte +4 -4
- package/dist/docs/Link.svelte +2 -4
- package/dist/docs/Link.svelte.d.ts +14 -5
- package/dist/docs/Preview.svelte +1 -1
- package/dist/docs/TilesetField.svelte +1 -1
- package/dist/docs/TilesetField.svelte.d.ts +1 -1
- package/dist/docs/ViewSourceButton.svelte +4 -4
- package/dist/docs/ViewSourceButton.svelte.d.ts +5 -3
- package/dist/stores/motionStore.d.ts +2 -2
- package/dist/stores/motionStore.js +4 -2
- package/dist/utils/array.d.ts +5 -0
- package/dist/utils/array.js +7 -0
- package/dist/utils/common.d.ts +2 -0
- package/dist/utils/common.js +18 -0
- package/dist/utils/genData.d.ts +23 -23
- package/dist/utils/genData.js +3 -2
- package/dist/utils/geo.d.ts +3 -3
- package/dist/utils/geo.js +2 -0
- package/dist/utils/graph.d.ts +1 -1
- package/dist/utils/graph.js +3 -3
- package/dist/utils/hierarchy.d.ts +1 -1
- package/dist/utils/hierarchy.js +1 -0
- package/dist/utils/rect.d.ts +5 -3
- package/dist/utils/rect.js +7 -11
- package/dist/utils/scales.d.ts +21 -12
- package/dist/utils/scales.js +3 -1
- package/dist/utils/stack.d.ts +5 -2
- package/dist/utils/stack.js +20 -7
- package/dist/utils/threshold.js +1 -0
- package/dist/utils/treemap.d.ts +5 -2
- package/dist/utils/treemap.js +1 -1
- package/package.json +5 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
<script>import {
|
|
2
|
-
import { pie as d3pie } from 'd3-shape';
|
|
1
|
+
<script>import { pie as d3pie } from 'd3-shape';
|
|
3
2
|
import { min, max } from 'd3-array';
|
|
4
3
|
import Arc from './Arc.svelte';
|
|
4
|
+
import { chartContext } from './ChartContext.svelte';
|
|
5
5
|
import Group from './Group.svelte';
|
|
6
6
|
import { degreesToRadians } from '../utils/math.js';
|
|
7
7
|
import { motionStore } from '../stores/motionStore.js';
|
|
@@ -51,17 +51,18 @@ export let offset = 0;
|
|
|
51
51
|
* Tooltip context to setup mouse events to show tooltip for related data
|
|
52
52
|
*/
|
|
53
53
|
export let tooltip = undefined;
|
|
54
|
-
const { data: contextData, x, y, xRange, rGet, config, width, height } =
|
|
54
|
+
const { data: contextData, x, y, xRange, rGet, config, width, height } = chartContext();
|
|
55
|
+
// @ts-expect-error
|
|
55
56
|
$: resolved_endAngle = endAngle ?? degreesToRadians($config.xRange ? max($xRange) : max(range));
|
|
56
57
|
let tweened_endAngle = motionStore(0, { spring, tweened });
|
|
57
58
|
$: tweened_endAngle.set(resolved_endAngle);
|
|
58
59
|
$: pie = d3pie()
|
|
60
|
+
// @ts-expect-error
|
|
59
61
|
.startAngle(startAngle ?? degreesToRadians($config.xRange ? min($xRange) : min(range)))
|
|
60
62
|
.endAngle($tweened_endAngle)
|
|
61
63
|
.padAngle(padAngle)
|
|
62
64
|
.value($x);
|
|
63
|
-
$: arcs = pie(data ?? $contextData);
|
|
64
|
-
// $: console.log({ arcs, $yRange });
|
|
65
|
+
$: arcs = pie(data ?? (Array.isArray($contextData) ? $contextData : []));
|
|
65
66
|
$: radius = Math.min($width / 2, $height / 2);
|
|
66
67
|
$: coords = {
|
|
67
68
|
x: placement === 'left'
|
|
@@ -77,7 +78,7 @@ $: coords = {
|
|
|
77
78
|
|
|
78
79
|
<Group x={coords.x} y={coords.y}>
|
|
79
80
|
<slot {arcs}>
|
|
80
|
-
{#each arcs as arc
|
|
81
|
+
{#each arcs as arc}
|
|
81
82
|
<Arc
|
|
82
83
|
startAngle={arc.startAngle}
|
|
83
84
|
endAngle={arc.endAngle}
|
|
@@ -3,7 +3,7 @@ import type { spring as springStore, tweened as tweenedStore } from 'svelte/moti
|
|
|
3
3
|
import type { TooltipContextValue } from './TooltipContext.svelte';
|
|
4
4
|
declare const __propDef: {
|
|
5
5
|
props: {
|
|
6
|
-
data?: any;
|
|
6
|
+
data?: any[] | undefined;
|
|
7
7
|
/**
|
|
8
8
|
* Range [min,max] in degrees. See also startAngle/endAngle
|
|
9
9
|
*/ range?: number[];
|
|
@@ -40,9 +40,7 @@ declare const __propDef: {
|
|
|
40
40
|
};
|
|
41
41
|
slots: {
|
|
42
42
|
default: {
|
|
43
|
-
arcs: import("d3-shape").PieArcDatum<
|
|
44
|
-
valueOf(): number;
|
|
45
|
-
}>[];
|
|
43
|
+
arcs: import("d3-shape").PieArcDatum<any>[];
|
|
46
44
|
};
|
|
47
45
|
};
|
|
48
46
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
<script>import {
|
|
2
|
-
const context =
|
|
1
|
+
<script>import { chartContext } from './ChartContext.svelte';
|
|
2
|
+
const context = chartContext();
|
|
3
3
|
const { xGet, yGet } = context;
|
|
4
4
|
/** Single data point to translate to x/y */
|
|
5
5
|
export let d;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
<script>import {
|
|
1
|
+
<script>import {} from 'svelte';
|
|
2
2
|
import { extent } from 'd3-array';
|
|
3
|
+
import { pointRadial } from 'd3-shape';
|
|
3
4
|
import { notNull } from 'svelte-ux';
|
|
5
|
+
import { chartContext } from './ChartContext.svelte';
|
|
4
6
|
import Circle from './Circle.svelte';
|
|
5
7
|
import Link from './Link.svelte';
|
|
6
8
|
import { isScaleBand } from '../utils/scales.js';
|
|
7
|
-
|
|
8
|
-
const context = getContext('LayerCake');
|
|
9
|
+
const context = chartContext();
|
|
9
10
|
const { data: contextData, xGet, y, yGet, xScale, yScale, rGet, config } = context;
|
|
10
11
|
/** Override data instead of using context */
|
|
11
12
|
export let data = undefined;
|
|
@@ -11,7 +11,8 @@ export let cy = '50%';
|
|
|
11
11
|
export let fx = cx;
|
|
12
12
|
export let fy = cy;
|
|
13
13
|
export let r = '50%';
|
|
14
|
-
|
|
14
|
+
// TODO: Svelte / Typescript does not know `<radialRadiant fr="...">`
|
|
15
|
+
// export let fr = '0%';
|
|
15
16
|
/** Indicates how the gradient behaves if it starts or ends inside the bounds of the shape containing the gradient */
|
|
16
17
|
export let spreadMethod = 'pad';
|
|
17
18
|
export let transform = undefined;
|
|
@@ -27,7 +28,6 @@ export let units = 'objectBoundingBox';
|
|
|
27
28
|
{fx}
|
|
28
29
|
{fy}
|
|
29
30
|
{r}
|
|
30
|
-
{fr}
|
|
31
31
|
{spreadMethod}
|
|
32
32
|
gradientTransform={transform}
|
|
33
33
|
gradientUnits={units}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
<script>import {
|
|
1
|
+
<script>import { extent } from 'd3-array';
|
|
2
2
|
import { cls } from 'svelte-ux';
|
|
3
|
-
import {
|
|
3
|
+
import { chartContext } from './ChartContext.svelte';
|
|
4
4
|
import Line from './Line.svelte';
|
|
5
|
-
const { xScale, yScale, xRange, yRange } =
|
|
5
|
+
const { xScale, yScale, xRange, yRange } = chartContext();
|
|
6
6
|
$: [xRangeMin, xRangeMax] = extent($xRange);
|
|
7
7
|
$: [yRangeMin, yRangeMax] = extent($yRange);
|
|
8
8
|
/**
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
<script>// https://github.com/d3/d3-sankey
|
|
2
|
-
import { createEventDispatcher
|
|
2
|
+
import { createEventDispatcher } from 'svelte';
|
|
3
3
|
import { sankey as d3Sankey, sankeyLeft, sankeyCenter, sankeyRight, sankeyJustify, } from 'd3-sankey';
|
|
4
|
+
import { chartContext } from './ChartContext.svelte';
|
|
4
5
|
const dispatch = createEventDispatcher();
|
|
5
|
-
const { data, width, height
|
|
6
|
+
const { data, width, height } = chartContext();
|
|
6
7
|
export let nodes = (d) => d.nodes;
|
|
7
8
|
export let nodeId = (d) => d.index;
|
|
8
9
|
/**
|
|
@@ -29,11 +30,16 @@ $: sankey = d3Sankey()
|
|
|
29
30
|
: nodeAlign)
|
|
30
31
|
.nodeWidth(nodeWidth)
|
|
31
32
|
.nodePadding(nodePadding)
|
|
33
|
+
// @ts-expect-error
|
|
32
34
|
.nodeSort(nodeSort)
|
|
33
35
|
.links(links)
|
|
36
|
+
// @ts-expect-error
|
|
34
37
|
.linkSort(linkSort);
|
|
38
|
+
// @ts-expect-error
|
|
35
39
|
$: sankeyData = sankey($data);
|
|
40
|
+
$: _nodes = sankeyData.nodes;
|
|
41
|
+
$: _links = sankeyData.links;
|
|
36
42
|
$: dispatch('update', sankeyData);
|
|
37
43
|
</script>
|
|
38
44
|
|
|
39
|
-
<slot nodes={
|
|
45
|
+
<slot nodes={_nodes} links={_links} />
|
|
@@ -20,8 +20,8 @@ declare const __propDef: {
|
|
|
20
20
|
};
|
|
21
21
|
slots: {
|
|
22
22
|
default: {
|
|
23
|
-
nodes:
|
|
24
|
-
links:
|
|
23
|
+
nodes: SankeyNode<Record<string, any>, any>[];
|
|
24
|
+
links: any[];
|
|
25
25
|
};
|
|
26
26
|
};
|
|
27
27
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<script>import {
|
|
1
|
+
<script>import { tick } from 'svelte';
|
|
2
2
|
import { writable } from 'svelte/store';
|
|
3
3
|
import { tweened as tweenedStore } from 'svelte/motion';
|
|
4
4
|
import { draw as _drawTransition } from 'svelte/transition';
|
|
@@ -7,9 +7,10 @@ import { line as d3Line, lineRadial } from 'd3-shape';
|
|
|
7
7
|
// import { interpolateString } from 'd3-interpolate';
|
|
8
8
|
import { interpolatePath } from 'd3-interpolate-path';
|
|
9
9
|
import { cls } from 'svelte-ux';
|
|
10
|
-
import {
|
|
10
|
+
import { chartContext } from './ChartContext.svelte';
|
|
11
11
|
import Group from './Group.svelte';
|
|
12
|
-
|
|
12
|
+
import { motionStore } from '../stores/motionStore.js';
|
|
13
|
+
const { data: contextData, xScale, yScale, x: contextX, y: contextY } = chartContext();
|
|
13
14
|
/** Override data instead of using context */
|
|
14
15
|
export let data = undefined;
|
|
15
16
|
/** Pass `<path d={...} />` explicitly instead of calculating from data / context */
|
|
@@ -46,6 +47,7 @@ function getScaleValue(data, scale, accessor) {
|
|
|
46
47
|
}
|
|
47
48
|
}
|
|
48
49
|
let d = '';
|
|
50
|
+
// @ts-expect-error
|
|
49
51
|
$: tweenedOptions = tweened ? { interpolate: interpolatePath, ...tweened } : false;
|
|
50
52
|
$: tweened_d = motionStore('', { tweened: tweenedOptions });
|
|
51
53
|
$: {
|
|
@@ -60,7 +62,7 @@ $: {
|
|
|
60
62
|
path.curve(curve);
|
|
61
63
|
if (defined)
|
|
62
64
|
path.defined(defined);
|
|
63
|
-
d = pathData ?? path(data ?? $contextData);
|
|
65
|
+
d = pathData ?? path(data ?? $contextData) ?? '';
|
|
64
66
|
tweened_d.set(d);
|
|
65
67
|
}
|
|
66
68
|
$: drawTransition = draw ? _drawTransition : () => ({});
|
|
@@ -79,8 +81,8 @@ $: endPoint = motionStore(undefined, {
|
|
|
79
81
|
easing: (typeof draw === 'object' && draw.easing) || cubicInOut,
|
|
80
82
|
interpolate(a, b) {
|
|
81
83
|
return (t) => {
|
|
82
|
-
const totalLength = pathEl
|
|
83
|
-
const point = pathEl
|
|
84
|
+
const totalLength = pathEl?.getTotalLength() ?? 0;
|
|
85
|
+
const point = pathEl?.getPointAtLength(totalLength * t);
|
|
84
86
|
return point;
|
|
85
87
|
};
|
|
86
88
|
},
|
|
@@ -103,6 +105,7 @@ $: {
|
|
|
103
105
|
</script>
|
|
104
106
|
|
|
105
107
|
{#key key}
|
|
108
|
+
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
|
106
109
|
<path
|
|
107
110
|
d={$tweened_d}
|
|
108
111
|
{...$$restProps}
|
|
@@ -8,8 +8,8 @@ declare const __propDef: {
|
|
|
8
8
|
data?: any;
|
|
9
9
|
pathData?: string | undefined | null;
|
|
10
10
|
radial?: boolean;
|
|
11
|
-
x?: any;
|
|
12
|
-
y?: any;
|
|
11
|
+
x?: ((d: any) => any) | undefined;
|
|
12
|
+
y?: ((d: any) => any) | undefined;
|
|
13
13
|
tweened?: boolean | Parameters<typeof tweenedStore>[1];
|
|
14
14
|
draw?: boolean | Parameters<typeof _drawTransition>[1];
|
|
15
15
|
curve?: CurveFactory | CurveFactoryLineOnly | undefined;
|
|
@@ -73,9 +73,8 @@ $: lines = wordsByLines.length;
|
|
|
73
73
|
*/
|
|
74
74
|
function getPixelValue(cssValue) {
|
|
75
75
|
// TODO: Properly measure pixel values using DOM (handle inherited font size, zoom, etc)
|
|
76
|
-
//
|
|
76
|
+
// @ts-expect-error
|
|
77
77
|
const [match, value, units] = cssValue.match(/([\d.]+)(\D+)/);
|
|
78
|
-
// console.log({ value, units });
|
|
79
78
|
const number = Number(value);
|
|
80
79
|
switch (units) {
|
|
81
80
|
case 'px':
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
- https://observablehq.com/@d3/difference-chart
|
|
4
4
|
- https://github.com/airbnb/visx/issues/245
|
|
5
5
|
*/
|
|
6
|
-
import { getContext } from 'svelte';
|
|
7
6
|
import { area as d3Area, line as d3Line } from 'd3-shape';
|
|
8
7
|
import { min, max } from 'd3-array';
|
|
9
|
-
|
|
8
|
+
import { chartContext } from './ChartContext.svelte';
|
|
9
|
+
const { data: contextData, xGet, yGet, yRange } = chartContext();
|
|
10
10
|
// Properties to override what is used from context
|
|
11
11
|
export let data = undefined; // TODO: Update Type
|
|
12
12
|
export let x = undefined; // TODO: Update Type
|
|
@@ -6,12 +6,12 @@ declare const __propDef: {
|
|
|
6
6
|
x?: any;
|
|
7
7
|
y0?: any;
|
|
8
8
|
y1?: any;
|
|
9
|
-
curve?: CurveFactory;
|
|
9
|
+
curve?: CurveFactory | undefined;
|
|
10
10
|
defined?: Parameters<{
|
|
11
11
|
(): (d: [number, number], index: number, data: [number, number][]) => boolean;
|
|
12
12
|
(defined: boolean): import("d3-shape").Area<[number, number]>;
|
|
13
13
|
(defined: (d: [number, number], index: number, data: [number, number][]) => boolean): import("d3-shape").Area<[number, number]>;
|
|
14
|
-
}>[0];
|
|
14
|
+
}>[0] | undefined;
|
|
15
15
|
id?: string;
|
|
16
16
|
};
|
|
17
17
|
events: {
|
|
@@ -32,8 +32,11 @@ function loadImage(url) {
|
|
|
32
32
|
img.onload = function () {
|
|
33
33
|
var canvas = document.createElement('canvas');
|
|
34
34
|
var context = canvas.getContext('2d');
|
|
35
|
+
// @ts-expect-error
|
|
35
36
|
canvas.height = this.naturalHeight;
|
|
37
|
+
// @ts-expect-error
|
|
36
38
|
canvas.width = this.naturalWidth;
|
|
39
|
+
// @ts-expect-error
|
|
37
40
|
context.drawImage(this, 0, 0);
|
|
38
41
|
var dataUri = canvas.toDataURL('image/jpeg');
|
|
39
42
|
// console.log('from load', { x, y, z });
|
|
@@ -41,7 +44,7 @@ function loadImage(url) {
|
|
|
41
44
|
resolve(dataUri);
|
|
42
45
|
};
|
|
43
46
|
img.onerror = (err) => {
|
|
44
|
-
|
|
47
|
+
tileCache.delete(key);
|
|
45
48
|
reject(err);
|
|
46
49
|
};
|
|
47
50
|
img.src = url;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
<script>import {
|
|
2
|
-
import { fade } from 'svelte/transition';
|
|
1
|
+
<script>import { fade } from 'svelte/transition';
|
|
3
2
|
import { cls } from 'svelte-ux';
|
|
3
|
+
import { chartContext } from './ChartContext.svelte';
|
|
4
4
|
import { tooltipContext } from './TooltipContext.svelte';
|
|
5
5
|
import { motionStore } from '../stores/motionStore.js';
|
|
6
6
|
/** `x` position of tooltip. By default uses the pointer/mouse, can also snap to data or an explicit fixed position. */
|
|
@@ -18,7 +18,7 @@ export let variant = 'default';
|
|
|
18
18
|
export let motion = true;
|
|
19
19
|
export let header = undefined;
|
|
20
20
|
export let classes = {};
|
|
21
|
-
const { padding, xGet, yGet, containerWidth, containerHeight } =
|
|
21
|
+
const { padding, xGet, yGet, containerWidth, containerHeight } = chartContext();
|
|
22
22
|
const tooltip = tooltipContext();
|
|
23
23
|
let tooltipWidth = 0;
|
|
24
24
|
let tooltipHeight = 0;
|
|
@@ -21,12 +21,13 @@ import { bisector, max, min } from 'd3-array';
|
|
|
21
21
|
import { quadtree as d3Quadtree } from 'd3-quadtree';
|
|
22
22
|
import { cls, sortFunc } from 'svelte-ux';
|
|
23
23
|
import { Svg } from './Chart.svelte';
|
|
24
|
+
import { chartContext } from './ChartContext.svelte';
|
|
24
25
|
import ChartClipPath from './ChartClipPath.svelte';
|
|
25
26
|
import Voronoi from './Voronoi.svelte';
|
|
26
27
|
import { localPoint } from '../utils/event.js';
|
|
27
28
|
import { isScaleBand, scaleInvert } from '../utils/scales.js';
|
|
28
29
|
import { quadtreeRects } from '../utils/quadtree.js';
|
|
29
|
-
const { flatData, x, xScale, xGet, xRange, y, yScale, yGet, yRange, width, height, containerWidth, containerHeight, padding, } =
|
|
30
|
+
const { flatData, x, xScale, xGet, xRange, y, yScale, yGet, yRange, width, height, containerWidth, containerHeight, padding, } = chartContext();
|
|
30
31
|
/*
|
|
31
32
|
TODO: Defaults to consider (if possible to detect scale type, which might not be possible)
|
|
32
33
|
- scaleTime / scaleLinear: bisect
|
|
@@ -54,7 +55,13 @@ export let radius = Infinity;
|
|
|
54
55
|
/** Enable debug view (show hit targets, etc) */
|
|
55
56
|
export let debug = false;
|
|
56
57
|
export let onClick = () => { };
|
|
57
|
-
const tooltip = writable({
|
|
58
|
+
const tooltip = writable({
|
|
59
|
+
y: 0,
|
|
60
|
+
x: 0,
|
|
61
|
+
data: null,
|
|
62
|
+
show: showTooltip,
|
|
63
|
+
hide: hideTooltip,
|
|
64
|
+
});
|
|
58
65
|
setTooltipContext(tooltip);
|
|
59
66
|
let hideTimeoutId;
|
|
60
67
|
$: bisectX = bisector((d) => {
|
|
@@ -112,10 +119,15 @@ function showTooltip(e, tooltipData) {
|
|
|
112
119
|
const point = localPoint(referenceNode, e);
|
|
113
120
|
const localX = point?.x ?? 0;
|
|
114
121
|
const localY = point?.y ?? 0;
|
|
115
|
-
if (
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
122
|
+
if (
|
|
123
|
+
// @ts-expect-error
|
|
124
|
+
e.offsetX < e.currentTarget?.offsetLeft ||
|
|
125
|
+
// @ts-expect-error
|
|
126
|
+
e.offsetX > e.currentTarget?.offsetLeft + e.currentTarget?.offsetWidth ||
|
|
127
|
+
// @ts-expect-error
|
|
128
|
+
e.offsetY < e.currentTarget?.offsetTop ||
|
|
129
|
+
// @ts-expect-error
|
|
130
|
+
e.offsetY > e.currentTarget?.offsetTop + e.currentTarget?.offsetHeight) {
|
|
119
131
|
// Ignore if within padding of chart
|
|
120
132
|
hideTooltip();
|
|
121
133
|
return;
|
|
@@ -148,7 +160,9 @@ function showTooltip(e, tooltipData) {
|
|
|
148
160
|
const yValueAtPoint = scaleInvert($yScale, localY);
|
|
149
161
|
if (isScaleBand($xScale)) {
|
|
150
162
|
// Find point closest to pointer within the x band
|
|
151
|
-
const bandData = $flatData
|
|
163
|
+
const bandData = $flatData
|
|
164
|
+
.filter((d) => $x(d) === xValueAtPoint)
|
|
165
|
+
.sort(sortFunc($y)); // sort for bisect
|
|
152
166
|
const index = bisectY(bandData, yValueAtPoint, 1);
|
|
153
167
|
const previousValue = bandData[index - 1];
|
|
154
168
|
const currentValue = bandData[index];
|
|
@@ -156,7 +170,9 @@ function showTooltip(e, tooltipData) {
|
|
|
156
170
|
}
|
|
157
171
|
else if (isScaleBand($yScale)) {
|
|
158
172
|
// Find point closest to pointer within the y band
|
|
159
|
-
const bandData = $flatData
|
|
173
|
+
const bandData = $flatData
|
|
174
|
+
.filter((d) => $y(d) === yValueAtPoint)
|
|
175
|
+
.sort(sortFunc($x)); // sort for bisect
|
|
160
176
|
const index = bisectX(bandData, xValueAtPoint, 1);
|
|
161
177
|
const previousValue = bandData[index - 1];
|
|
162
178
|
const currentValue = bandData[index];
|
|
@@ -232,6 +248,7 @@ $: if (mode === 'quadtree') {
|
|
|
232
248
|
}
|
|
233
249
|
let rects = [];
|
|
234
250
|
$: if (mode === 'bounds' || mode === 'band') {
|
|
251
|
+
// @ts-expect-error
|
|
235
252
|
rects = $flatData
|
|
236
253
|
.map((d) => {
|
|
237
254
|
const xValue = $xGet(d);
|
|
@@ -240,7 +257,9 @@ $: if (mode === 'bounds' || mode === 'band') {
|
|
|
240
257
|
const y = Array.isArray(yValue) ? yValue[0] : yValue;
|
|
241
258
|
const xOffset = isScaleBand($xScale) ? ($xScale.padding() * $xScale.step()) / 2 : 0;
|
|
242
259
|
const yOffset = isScaleBand($yScale) ? ($yScale.padding() * $yScale.step()) / 2 : 0;
|
|
260
|
+
// @ts-expect-error
|
|
243
261
|
const fullWidth = max($xRange) - min($xRange);
|
|
262
|
+
// @ts-expect-error
|
|
244
263
|
const fullHeight = max($yRange) - min($yRange);
|
|
245
264
|
if (mode === 'band') {
|
|
246
265
|
// full band width/height regardless of value
|
|
@@ -266,7 +285,8 @@ $: if (mode === 'bounds' || mode === 'band') {
|
|
|
266
285
|
? yValue[1] - yValue[0]
|
|
267
286
|
: isScaleBand($yScale)
|
|
268
287
|
? $yScale.step()
|
|
269
|
-
:
|
|
288
|
+
: // @ts-expect-error
|
|
289
|
+
max($yRange) - y,
|
|
270
290
|
data: d,
|
|
271
291
|
};
|
|
272
292
|
}
|
|
@@ -276,6 +296,8 @@ $: if (mode === 'bounds' || mode === 'band') {
|
|
|
276
296
|
$: triggerPointEvents = ['bisect-x', 'bisect-y', 'bisect-band', 'quadtree'].includes(mode);
|
|
277
297
|
</script>
|
|
278
298
|
|
|
299
|
+
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
|
300
|
+
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
|
279
301
|
<div
|
|
280
302
|
style:width="{$width}px"
|
|
281
303
|
style:height="{$height}px"
|
|
@@ -299,19 +321,26 @@ $: triggerPointEvents = ['bisect-x', 'bisect-y', 'bisect-band', 'quadtree'].incl
|
|
|
299
321
|
class="absolute"
|
|
300
322
|
style:width="{$containerWidth}px"
|
|
301
323
|
style:height="{$containerHeight}px"
|
|
302
|
-
style:top="{
|
|
303
|
-
style:left="{
|
|
324
|
+
style:top="-{$padding.top ?? 0}px"
|
|
325
|
+
style:left="-{$padding.left ?? 0}px"
|
|
304
326
|
>
|
|
305
327
|
<slot tooltip={$tooltip} />
|
|
306
328
|
|
|
307
329
|
{#if mode === 'voronoi'}
|
|
308
330
|
<Svg>
|
|
309
331
|
<Voronoi
|
|
310
|
-
on:pointerenter={(e) =>
|
|
311
|
-
|
|
332
|
+
on:pointerenter={(e) => {
|
|
333
|
+
// @ts-expect-error
|
|
334
|
+
showTooltip(e.detail.event, e.detail.data);
|
|
335
|
+
}}
|
|
336
|
+
on:pointermove={(e) => {
|
|
337
|
+
showTooltip(e.detail.event, e.detail.data);
|
|
338
|
+
}}
|
|
312
339
|
on:pointerleave={hideTooltip}
|
|
313
340
|
on:pointerdown={(e) => {
|
|
314
|
-
|
|
341
|
+
// @ts-expect-error
|
|
342
|
+
if (e.target?.hasPointerCapture(e.pointerId)) {
|
|
343
|
+
// @ts-expect-error
|
|
315
344
|
e.target.releasePointerCapture(e.pointerId);
|
|
316
345
|
}
|
|
317
346
|
}}
|
|
@@ -335,7 +364,9 @@ $: triggerPointEvents = ['bisect-x', 'bisect-y', 'bisect-band', 'quadtree'].incl
|
|
|
335
364
|
on:pointermove={(e) => showTooltip(e, rect.data)}
|
|
336
365
|
on:pointerleave={hideTooltip}
|
|
337
366
|
on:pointerdown={(e) => {
|
|
338
|
-
|
|
367
|
+
// @ts-expect-error
|
|
368
|
+
if (e.target?.hasPointerCapture(e.pointerId)) {
|
|
369
|
+
// @ts-expect-error
|
|
339
370
|
e.target.releasePointerCapture(e.pointerId);
|
|
340
371
|
}
|
|
341
372
|
}}
|
|
@@ -28,8 +28,9 @@ function setTransformContext(transform) {
|
|
|
28
28
|
</script>
|
|
29
29
|
|
|
30
30
|
<script>import { createEventDispatcher } from 'svelte';
|
|
31
|
+
import { chartContext } from './ChartContext.svelte';
|
|
31
32
|
import { motionStore, motionFinishHandler } from '../stores/motionStore.js';
|
|
32
|
-
const { width, height } =
|
|
33
|
+
const { width, height } = chartContext();
|
|
33
34
|
export let mode = 'none';
|
|
34
35
|
/** Translate towards point (ex. mouse cursor/center) while zooming in/out */
|
|
35
36
|
export let translateOnScale = false;
|
|
@@ -111,8 +112,11 @@ function onPointerMove(e) {
|
|
|
111
112
|
}
|
|
112
113
|
if ($dragging) {
|
|
113
114
|
e.stopPropagation(); // Stop tooltip from trigging (along with `capture: true`)
|
|
114
|
-
|
|
115
|
-
|
|
115
|
+
// @ts-expect-error
|
|
116
|
+
e.currentTarget?.setPointerCapture(e.pointerId);
|
|
117
|
+
setTranslate(processTranslate(startTranslate.x, startTranslate.y, deltaX, deltaY, $scale),
|
|
118
|
+
// @ts-expect-error
|
|
119
|
+
spring ? { hard: true } : tweened ? { duration: 0 } : undefined);
|
|
116
120
|
}
|
|
117
121
|
}
|
|
118
122
|
function onPointerUp(e) {
|
|
@@ -142,10 +146,14 @@ function onWheel(e) {
|
|
|
142
146
|
if ($scrollMode === 'scale' || pinchToZoom) {
|
|
143
147
|
// https://github.com/d3/d3-zoom#zoom_wheelDelta
|
|
144
148
|
const scaleBy = -e.deltaY * (e.deltaMode === 1 ? 0.05 : e.deltaMode ? 1 : 0.002) * (e.ctrlKey ? 10 : 1);
|
|
145
|
-
scaleTo(Math.pow(2, scaleBy), point,
|
|
149
|
+
scaleTo(Math.pow(2, scaleBy), point,
|
|
150
|
+
// @ts-expect-error
|
|
151
|
+
spring ? { hard: true } : tweened ? { duration: 0 } : undefined);
|
|
146
152
|
}
|
|
147
153
|
else if ($scrollMode === 'translate') {
|
|
148
|
-
translate.update((startTranslate) => processTranslate(startTranslate.x, startTranslate.y, -e.deltaX, -e.deltaY, $scale),
|
|
154
|
+
translate.update((startTranslate) => processTranslate(startTranslate.x, startTranslate.y, -e.deltaX, -e.deltaY, $scale),
|
|
155
|
+
// @ts-expect-error
|
|
156
|
+
spring ? { hard: true } : tweened ? { duration: 0 } : undefined);
|
|
149
157
|
}
|
|
150
158
|
}
|
|
151
159
|
/**
|
|
@@ -172,9 +180,11 @@ const translating = motionFinishHandler();
|
|
|
172
180
|
const scaling = motionFinishHandler();
|
|
173
181
|
const moving = derived([dragging, translating, scaling], ([dragging, translating, scaling]) => dragging || translating || scaling);
|
|
174
182
|
export function setTranslate(point, options) {
|
|
183
|
+
// @ts-expect-error
|
|
175
184
|
translating.handle(translate.set(point, options));
|
|
176
185
|
}
|
|
177
186
|
export function setScale(value, options) {
|
|
187
|
+
// @ts-expect-error
|
|
178
188
|
scaling.handle(scale.set(value, options));
|
|
179
189
|
}
|
|
180
190
|
function localPoint(e) {
|
|
@@ -207,8 +217,9 @@ setTransformContext({
|
|
|
207
217
|
});
|
|
208
218
|
</script>
|
|
209
219
|
|
|
220
|
+
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
|
210
221
|
<div
|
|
211
|
-
on:
|
|
222
|
+
on:wheel={onWheel}
|
|
212
223
|
on:pointerdown={onPointerDown}
|
|
213
224
|
on:pointermove={onPointerMove}
|
|
214
225
|
on:touchmove={(e) => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
<script>import {
|
|
2
|
-
import {
|
|
3
|
-
const { data, width, height
|
|
1
|
+
<script>import { tree as d3Tree } from 'd3-hierarchy';
|
|
2
|
+
import { chartContext } from './ChartContext.svelte';
|
|
3
|
+
const { data, width, height } = chartContext();
|
|
4
4
|
/**
|
|
5
5
|
* Sets this tree layout’s node size to the specified two-element array of numbers `[width, height]`.
|
|
6
6
|
* If unset, layout size is used instead. When a node size is specified, the root node is always
|
|
@@ -24,6 +24,7 @@ $: {
|
|
|
24
24
|
tree.separation(separation);
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
+
// @ts-expect-error
|
|
27
28
|
$: treeData = tree($data);
|
|
28
29
|
</script>
|
|
29
30
|
|
|
@@ -11,7 +11,7 @@ declare const __propDef: {
|
|
|
11
11
|
*/ nodeSize?: [number, number] | undefined;
|
|
12
12
|
/**
|
|
13
13
|
* see: https://github.com/d3/d3-hierarchy#tree_separation
|
|
14
|
-
*/ separation?: (a: HierarchyPointNode<any>, b: HierarchyPointNode<any>) => number;
|
|
14
|
+
*/ separation?: ((a: HierarchyPointNode<any>, b: HierarchyPointNode<any>) => number) | undefined;
|
|
15
15
|
orientation?: "vertical" | "horizontal";
|
|
16
16
|
};
|
|
17
17
|
events: {
|
|
@@ -19,8 +19,8 @@ declare const __propDef: {
|
|
|
19
19
|
};
|
|
20
20
|
slots: {
|
|
21
21
|
default: {
|
|
22
|
-
nodes: any;
|
|
23
|
-
links: any;
|
|
22
|
+
nodes: HierarchyPointNode<any>[];
|
|
23
|
+
links: import("d3-hierarchy").HierarchyPointLink<any>[];
|
|
24
24
|
};
|
|
25
25
|
};
|
|
26
26
|
};
|