layerchart 0.44.0 → 0.51.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 +18 -1
- package/dist/components/Arc.svelte.d.ts +3 -0
- package/dist/components/Area.svelte +49 -18
- package/dist/components/Area.svelte.d.ts +0 -1
- package/dist/components/Axis.svelte +2 -1
- package/dist/components/Axis.svelte.d.ts +2 -1
- package/dist/components/Bar.svelte +18 -8
- package/dist/components/Bar.svelte.d.ts +6 -3
- package/dist/components/Bars.svelte +18 -11
- package/dist/components/Bars.svelte.d.ts +3 -3
- package/dist/components/Blur.svelte +1 -1
- package/dist/components/Brush.svelte +2 -1
- package/dist/components/Calendar.svelte +2 -2
- package/dist/components/Calendar.svelte.d.ts +1 -1
- package/dist/components/Chart.svelte +85 -25
- package/dist/components/Chart.svelte.d.ts +77 -37
- package/dist/components/ChartContext.svelte +124 -6
- package/dist/components/ChartContext.svelte.d.ts +50 -2
- package/dist/components/Circle.svelte +1 -1
- package/dist/components/CircleClipPath.svelte +1 -1
- package/dist/components/ClipPath.svelte +1 -1
- package/dist/components/GeoPath.svelte +1 -1
- package/dist/components/GeoPath.svelte.d.ts +1 -1
- package/dist/components/Highlight.svelte +45 -19
- package/dist/components/Highlight.svelte.d.ts +2 -3
- package/dist/components/HitCanvas.svelte +1 -1
- package/dist/components/Hull.svelte +1 -1
- package/dist/components/Labels.svelte +39 -73
- package/dist/components/Labels.svelte.d.ts +2 -5
- package/dist/components/Legend.svelte +5 -5
- package/dist/components/Legend.svelte.d.ts +2 -2
- package/dist/components/Line.svelte +1 -1
- package/dist/components/LinearGradient.svelte +1 -1
- package/dist/components/MotionPath.svelte +1 -1
- package/dist/components/Pie.svelte +18 -41
- package/dist/components/Pie.svelte.d.ts +2 -3
- package/dist/components/Points.svelte +110 -56
- package/dist/components/Points.svelte.d.ts +20 -2
- package/dist/components/RadialGradient.svelte +1 -1
- package/dist/components/Rect.svelte +2 -1
- package/dist/components/Rect.svelte.d.ts +1 -0
- package/dist/components/RectClipPath.svelte +1 -1
- package/dist/components/Rule.svelte +1 -1
- package/dist/components/Spline.svelte +26 -18
- package/dist/components/Spline.svelte.d.ts +1 -1
- package/dist/components/Text.svelte +1 -1
- package/dist/components/Threshold.svelte +19 -81
- package/dist/components/Threshold.svelte.d.ts +13 -20
- package/dist/components/TransformContext.svelte.d.ts +2 -2
- package/dist/components/TransformControls.svelte +2 -1
- package/dist/components/TransformControls.svelte.d.ts +2 -2
- package/dist/components/Voronoi.svelte +15 -5
- package/dist/components/Voronoi.svelte.d.ts +6 -1
- package/dist/components/charts/AreaChart.svelte +182 -0
- package/dist/components/charts/AreaChart.svelte.d.ts +261 -0
- package/dist/components/charts/BarChart.svelte +207 -0
- package/dist/components/charts/BarChart.svelte.d.ts +241 -0
- package/dist/components/charts/LineChart.svelte +138 -0
- package/dist/components/charts/LineChart.svelte.d.ts +260 -0
- package/dist/components/charts/PieChart.svelte +146 -0
- package/dist/components/charts/PieChart.svelte.d.ts +220 -0
- package/dist/components/charts/ScatterChart.svelte +133 -0
- package/dist/components/charts/ScatterChart.svelte.d.ts +236 -0
- package/dist/components/charts/index.d.ts +5 -0
- package/dist/components/charts/index.js +5 -0
- package/dist/components/index.d.ts +2 -6
- package/dist/components/index.js +3 -6
- package/dist/components/layout/Canvas.svelte +1 -1
- package/dist/components/layout/Html.svelte +1 -1
- package/dist/components/layout/Svg.svelte +14 -4
- package/dist/components/layout/Svg.svelte.d.ts +1 -0
- package/dist/components/{Tooltip.svelte → tooltip/Tooltip.svelte} +5 -28
- package/dist/components/{Tooltip.svelte.d.ts → tooltip/Tooltip.svelte.d.ts} +1 -5
- package/dist/components/{TooltipContext.svelte → tooltip/TooltipContext.svelte} +20 -12
- package/dist/components/tooltip/TooltipHeader.svelte +21 -0
- package/dist/components/tooltip/TooltipHeader.svelte.d.ts +23 -0
- package/dist/components/tooltip/TooltipItem.svelte +37 -0
- package/dist/components/{TooltipItem.svelte.d.ts → tooltip/TooltipItem.svelte.d.ts} +4 -1
- package/dist/components/tooltip/TooltipList.svelte +12 -0
- package/dist/components/tooltip/TooltipList.svelte.d.ts +18 -0
- package/dist/components/tooltip/TooltipSeparator.svelte +4 -0
- package/dist/components/tooltip/index.d.ts +6 -0
- package/dist/components/tooltip/index.js +6 -0
- package/dist/docs/Blockquote.svelte +2 -1
- package/dist/docs/Code.svelte +2 -1
- package/dist/docs/CurveMenuField.svelte +2 -1
- package/dist/docs/GeoDebug.svelte +3 -1
- package/dist/docs/Json.svelte +1 -1
- package/dist/docs/Preview.svelte +2 -1
- package/dist/docs/TransformDebug.svelte +2 -1
- package/dist/utils/common.d.ts +1 -1
- package/dist/utils/common.js +2 -2
- package/dist/utils/common.test.d.ts +8 -0
- package/dist/utils/common.test.js +38 -0
- package/dist/utils/event.js +1 -1
- package/dist/utils/genData.d.ts +2 -2
- package/dist/utils/genData.js +20 -20
- package/dist/utils/math.d.ts +2 -2
- package/dist/utils/math.js +8 -2
- package/dist/utils/rect.d.ts +4 -10
- package/dist/utils/rect.js +15 -19
- package/dist/utils/scales.d.ts +8 -2
- package/dist/utils/scales.js +15 -1
- package/dist/utils/stack.d.ts +2 -2
- package/dist/utils/stack.js +37 -20
- package/dist/utils/stack.test.d.ts +6 -0
- package/dist/utils/stack.test.js +136 -0
- package/dist/utils/string.js +41 -0
- package/dist/utils/ticks.js +1 -2
- package/package.json +9 -3
- package/dist/components/AreaStack.svelte +0 -47
- package/dist/components/AreaStack.svelte.d.ts +0 -28
- package/dist/components/TooltipItem.svelte +0 -26
- package/dist/components/TooltipSeparator.svelte +0 -4
- /package/dist/components/{TooltipContext.svelte.d.ts → tooltip/TooltipContext.svelte.d.ts} +0 -0
- /package/dist/components/{TooltipSeparator.svelte.d.ts → tooltip/TooltipSeparator.svelte.d.ts} +0 -0
|
@@ -1,22 +1,29 @@
|
|
|
1
|
-
<script>import {} from 'svelte';
|
|
1
|
+
<script>import { getContext } from 'svelte';
|
|
2
2
|
import { extent } from 'd3-array';
|
|
3
3
|
import { pointRadial } from 'd3-shape';
|
|
4
|
-
import { notNull } from '
|
|
4
|
+
import { notNull } from '@layerstack/utils/typeGuards';
|
|
5
5
|
import { chartContext } from './ChartContext.svelte';
|
|
6
6
|
import Circle from './Circle.svelte';
|
|
7
7
|
import Link from './Link.svelte';
|
|
8
8
|
import { isScaleBand } from '../utils/scales.js';
|
|
9
9
|
const context = chartContext();
|
|
10
|
-
const { data: contextData, xGet, y,
|
|
10
|
+
const { data: contextData, x, xScale, xGet, y, yScale, yGet, cGet, rGet, padding, containerWidth, containerHeight, config, radial, } = context;
|
|
11
11
|
/** Override data instead of using context */
|
|
12
12
|
export let data = undefined;
|
|
13
13
|
export let r = 5;
|
|
14
14
|
export let offsetX = undefined;
|
|
15
15
|
export let offsetY = undefined;
|
|
16
|
-
/** Use radial instead of cartesian line generator, mapping `x` to `angle` and `y` to `radius`. Radial points are positioned relative to the origin, use transform (ex. `<Group center>`) to change the origin */
|
|
17
|
-
export let radial = false;
|
|
18
16
|
/** Enable showing links between related points (array x/y accessors) */
|
|
19
17
|
export let links = false;
|
|
18
|
+
export let fill = undefined;
|
|
19
|
+
export let stroke = undefined;
|
|
20
|
+
export let strokeWidth = undefined;
|
|
21
|
+
/** Render to canvas */
|
|
22
|
+
export let render = undefined;
|
|
23
|
+
let className = undefined;
|
|
24
|
+
export { className as class };
|
|
25
|
+
const canvas = getContext('canvas');
|
|
26
|
+
const DEFAULT_FILL = 'rgb(0, 0, 0)';
|
|
20
27
|
function getOffset(value, offset, scale) {
|
|
21
28
|
if (typeof offset === 'function') {
|
|
22
29
|
return offset(value, context);
|
|
@@ -24,7 +31,7 @@ function getOffset(value, offset, scale) {
|
|
|
24
31
|
else if (offset != null) {
|
|
25
32
|
return offset;
|
|
26
33
|
}
|
|
27
|
-
else if (isScaleBand(scale) &&
|
|
34
|
+
else if (isScaleBand(scale) && !$radial) {
|
|
28
35
|
return scale.bandwidth() / 2;
|
|
29
36
|
}
|
|
30
37
|
else {
|
|
@@ -32,51 +39,62 @@ function getOffset(value, offset, scale) {
|
|
|
32
39
|
}
|
|
33
40
|
}
|
|
34
41
|
$: pointsData = data ?? $contextData;
|
|
35
|
-
$: points = pointsData
|
|
36
|
-
|
|
42
|
+
$: points = pointsData
|
|
43
|
+
.flatMap((d) => {
|
|
44
|
+
const xValue = $x(d);
|
|
45
|
+
const yValue = $y(d);
|
|
46
|
+
if (Array.isArray(xValue)) {
|
|
37
47
|
/*
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return
|
|
42
|
-
.filter(notNull)
|
|
43
|
-
.map((x) => {
|
|
48
|
+
x={["prop1" ,"prop2"]}
|
|
49
|
+
y="prop3"
|
|
50
|
+
*/
|
|
51
|
+
return xValue.filter(notNull).map((xValue) => {
|
|
44
52
|
return {
|
|
45
|
-
x:
|
|
46
|
-
y: $
|
|
53
|
+
x: $xScale(xValue) + getOffset($xScale(xValue), offsetX, $xScale),
|
|
54
|
+
y: $yScale(yValue) + getOffset($yScale(yValue), offsetY, $yScale),
|
|
55
|
+
r: $config.r ? $rGet(d) : r,
|
|
56
|
+
xValue,
|
|
57
|
+
yValue,
|
|
47
58
|
data: d,
|
|
48
59
|
};
|
|
49
60
|
});
|
|
50
61
|
}
|
|
51
|
-
else if (Array.isArray(
|
|
62
|
+
else if (Array.isArray(yValue)) {
|
|
52
63
|
/*
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return
|
|
57
|
-
.filter(notNull)
|
|
58
|
-
.map((y) => {
|
|
64
|
+
x="prop1"
|
|
65
|
+
y={["prop2" ,"prop3"]}
|
|
66
|
+
*/
|
|
67
|
+
return yValue.filter(notNull).map((yValue) => {
|
|
59
68
|
return {
|
|
60
|
-
x: $
|
|
61
|
-
y:
|
|
69
|
+
x: $xScale(xValue) + getOffset($xScale(xValue), offsetX, $xScale),
|
|
70
|
+
y: $yScale(yValue) + getOffset($yScale(yValue), offsetY, $yScale),
|
|
71
|
+
r: $config.r ? $rGet(d) : r,
|
|
72
|
+
xValue,
|
|
73
|
+
yValue,
|
|
62
74
|
data: d,
|
|
63
75
|
};
|
|
64
76
|
});
|
|
65
77
|
}
|
|
66
|
-
else {
|
|
78
|
+
else if (xValue != null && yValue != null) {
|
|
67
79
|
/*
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
80
|
+
x="prop1"
|
|
81
|
+
y="prop2"
|
|
82
|
+
*/
|
|
71
83
|
return {
|
|
72
|
-
x: $
|
|
73
|
-
y: $
|
|
84
|
+
x: $xScale(xValue) + getOffset($xScale(xValue), offsetX, $xScale),
|
|
85
|
+
y: $yScale(yValue) + getOffset($yScale(yValue), offsetY, $yScale),
|
|
86
|
+
r: $config.r ? $rGet(d) : r,
|
|
87
|
+
xValue,
|
|
88
|
+
yValue,
|
|
74
89
|
data: d,
|
|
75
90
|
};
|
|
76
91
|
}
|
|
77
|
-
})
|
|
92
|
+
})
|
|
93
|
+
.filter((p) => p);
|
|
78
94
|
$: _links = pointsData.flatMap((d) => {
|
|
79
|
-
|
|
95
|
+
const xValue = $x(d);
|
|
96
|
+
const yValue = $y(d);
|
|
97
|
+
if (Array.isArray(xValue)) {
|
|
80
98
|
/*
|
|
81
99
|
x={["prop1" ,"prop2"]}
|
|
82
100
|
y="prop3"
|
|
@@ -85,16 +103,16 @@ $: _links = pointsData.flatMap((d) => {
|
|
|
85
103
|
const y = $yGet(d) + getOffset($yGet(d), offsetY, $yScale);
|
|
86
104
|
return {
|
|
87
105
|
source: {
|
|
88
|
-
x: xMin + getOffset(xMin, offsetX, $xScale) + r,
|
|
106
|
+
x: xMin + getOffset(xMin, offsetX, $xScale) + ($config.r ? $rGet(d) : r),
|
|
89
107
|
y,
|
|
90
108
|
},
|
|
91
109
|
target: {
|
|
92
|
-
x: xMax + getOffset(xMax, offsetX, $xScale) - r,
|
|
110
|
+
x: xMax + getOffset(xMax, offsetX, $xScale) - ($config.r ? $rGet(d) : r),
|
|
93
111
|
y: y,
|
|
94
112
|
},
|
|
95
113
|
};
|
|
96
114
|
}
|
|
97
|
-
else if (Array.isArray(
|
|
115
|
+
else if (Array.isArray(yValue)) {
|
|
98
116
|
/*
|
|
99
117
|
x="prop1"
|
|
100
118
|
y={["prop2" ,"prop3"]}
|
|
@@ -113,31 +131,67 @@ $: _links = pointsData.flatMap((d) => {
|
|
|
113
131
|
};
|
|
114
132
|
}
|
|
115
133
|
});
|
|
134
|
+
$: renderContext = canvas ? 'canvas' : 'svg';
|
|
135
|
+
$: ctx = canvas?.ctx;
|
|
136
|
+
$: if (renderContext === 'canvas' && $ctx) {
|
|
137
|
+
let computedStyles = {};
|
|
138
|
+
// Transfer classes defined on <GeoPath> to <canvas> to enable window.getComputedStyle() retrieval (Tailwind classes, etc)
|
|
139
|
+
if (className) {
|
|
140
|
+
$ctx.canvas.classList.add(...className.split(' '));
|
|
141
|
+
computedStyles = window.getComputedStyle($ctx.canvas);
|
|
142
|
+
}
|
|
143
|
+
// Clear with negative offset due to Canvas `context.translate(...)`
|
|
144
|
+
$ctx.clearRect(-$padding.left, -$padding.top, $containerWidth, $containerHeight);
|
|
145
|
+
if (render) {
|
|
146
|
+
render($ctx, points);
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
points.forEach((point) => {
|
|
150
|
+
$ctx.beginPath();
|
|
151
|
+
$ctx.arc(point.x, point.y, point.r, 0, 2 * Math.PI, false);
|
|
152
|
+
$ctx.lineWidth = Number(strokeWidth ?? 0);
|
|
153
|
+
$ctx.strokeStyle =
|
|
154
|
+
(stroke ?? computedStyles.stroke === 'none')
|
|
155
|
+
? 'transparent'
|
|
156
|
+
: (computedStyles.stroke ?? '');
|
|
157
|
+
$ctx.stroke();
|
|
158
|
+
$ctx.fillStyle =
|
|
159
|
+
fill ??
|
|
160
|
+
(computedStyles.fill !== DEFAULT_FILL ? computedStyles.fill : undefined) ??
|
|
161
|
+
'transparent';
|
|
162
|
+
$ctx.fill();
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}
|
|
116
166
|
</script>
|
|
117
167
|
|
|
118
168
|
<slot {points}>
|
|
119
|
-
{#if
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
169
|
+
{#if renderContext === 'svg'}
|
|
170
|
+
{#if links}
|
|
171
|
+
<g class="link-group">
|
|
172
|
+
{#each _links as link}
|
|
173
|
+
<Link
|
|
174
|
+
data={link}
|
|
175
|
+
class="stroke-surface-content/50"
|
|
176
|
+
{...typeof links === 'object' ? links : null}
|
|
177
|
+
/>
|
|
178
|
+
{/each}
|
|
179
|
+
</g>
|
|
180
|
+
{/if}
|
|
181
|
+
|
|
182
|
+
<g class="point-group">
|
|
183
|
+
{#each points as point}
|
|
184
|
+
{@const radialPoint = pointRadial(point.x, point.y)}
|
|
185
|
+
<Circle
|
|
186
|
+
cx={$radial ? radialPoint[0] : point.x}
|
|
187
|
+
cy={$radial ? radialPoint[1] : point.y}
|
|
188
|
+
r={point.r}
|
|
189
|
+
fill={fill ?? ($config.c ? $cGet(point.data) : null)}
|
|
190
|
+
{stroke}
|
|
191
|
+
class={className}
|
|
192
|
+
{...$$restProps}
|
|
126
193
|
/>
|
|
127
194
|
{/each}
|
|
128
195
|
</g>
|
|
129
196
|
{/if}
|
|
130
|
-
|
|
131
|
-
<g class="point-group">
|
|
132
|
-
{#each points as point}
|
|
133
|
-
{@const radialPoint = pointRadial(point.x, point.y)}
|
|
134
|
-
<Circle
|
|
135
|
-
cx={radial ? radialPoint[0] : point.x}
|
|
136
|
-
cy={radial ? radialPoint[1] : point.y}
|
|
137
|
-
{r}
|
|
138
|
-
fill={$config.r ? $rGet(point.data) : null}
|
|
139
|
-
{...$$restProps}
|
|
140
|
-
/>
|
|
141
|
-
{/each}
|
|
142
|
-
</g>
|
|
143
197
|
</slot>
|
|
@@ -8,15 +8,33 @@ declare const __propDef: {
|
|
|
8
8
|
r?: number | undefined;
|
|
9
9
|
offsetX?: number | ((value: number, context: any) => number) | undefined;
|
|
10
10
|
offsetY?: number | ((value: number, context: any) => number) | undefined;
|
|
11
|
-
radial?: boolean | undefined;
|
|
12
11
|
links?: (boolean | Partial<ComponentProps<Link>>) | undefined;
|
|
12
|
+
fill?: string | undefined;
|
|
13
|
+
stroke?: string | undefined;
|
|
14
|
+
strokeWidth?: number | string | undefined;
|
|
15
|
+
render?: ((ctx: CanvasRenderingContext2D, points: {
|
|
16
|
+
x: number;
|
|
17
|
+
y: number;
|
|
18
|
+
r: number;
|
|
19
|
+
xValue: any;
|
|
20
|
+
yValue: any;
|
|
21
|
+
data: any;
|
|
22
|
+
}[]) => any) | undefined;
|
|
23
|
+
class?: string | undefined;
|
|
13
24
|
};
|
|
14
25
|
events: {
|
|
15
26
|
[evt: string]: CustomEvent<any>;
|
|
16
27
|
};
|
|
17
28
|
slots: {
|
|
18
29
|
default: {
|
|
19
|
-
points:
|
|
30
|
+
points: {
|
|
31
|
+
x: number;
|
|
32
|
+
y: number;
|
|
33
|
+
r: number;
|
|
34
|
+
xValue: any;
|
|
35
|
+
yValue: any;
|
|
36
|
+
data: any;
|
|
37
|
+
}[];
|
|
20
38
|
};
|
|
21
39
|
};
|
|
22
40
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<script>import { uniqueId } from '
|
|
1
|
+
<script>import { uniqueId } from '@layerstack/utils';
|
|
2
2
|
/** Unique id for linearGradient */
|
|
3
3
|
export let id = uniqueId('radialGradient-');
|
|
4
4
|
/** Array array of strings (colors), will equally distributed from 0-100%. If array of tuples, will use first value as the offset, and second as color */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script>import { tick } from 'svelte';
|
|
2
|
-
import { cls } from '
|
|
2
|
+
import { cls } from '@layerstack/tailwind';
|
|
3
3
|
import { motionStore, resolveOptions, } from '../stores/motionStore.js';
|
|
4
4
|
export let x = 0;
|
|
5
5
|
export let initialX = x;
|
|
@@ -33,6 +33,7 @@ $: tick().then(() => {
|
|
|
33
33
|
class={cls($$props.fill == null && 'fill-surface-content')}
|
|
34
34
|
{...$$restProps}
|
|
35
35
|
on:click
|
|
36
|
+
on:pointerenter
|
|
36
37
|
on:pointerover
|
|
37
38
|
on:pointermove
|
|
38
39
|
on:pointerout
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script>import { extent } from 'd3-array';
|
|
2
|
-
import { cls } from '
|
|
2
|
+
import { cls } from '@layerstack/tailwind';
|
|
3
3
|
import { chartContext } from './ChartContext.svelte';
|
|
4
4
|
import Line from './Line.svelte';
|
|
5
5
|
const { xScale, yScale, xRange, yRange } = chartContext();
|
|
@@ -6,22 +6,21 @@ import { cubicInOut } from 'svelte/easing';
|
|
|
6
6
|
import { line as d3Line, lineRadial } from 'd3-shape';
|
|
7
7
|
// import { interpolateString } from 'd3-interpolate';
|
|
8
8
|
import { interpolatePath } from 'd3-interpolate-path';
|
|
9
|
-
import {
|
|
9
|
+
import { max } from 'd3-array';
|
|
10
|
+
import { cls } from '@layerstack/tailwind';
|
|
10
11
|
import { chartContext } from './ChartContext.svelte';
|
|
11
12
|
import Group from './Group.svelte';
|
|
12
13
|
import { motionStore } from '../stores/motionStore.js';
|
|
13
14
|
import { accessor } from '../utils/common.js';
|
|
14
15
|
import { isScaleBand } from '../utils/scales.js';
|
|
15
|
-
const { data: contextData, xScale, yScale, x: contextX, y: contextY } = chartContext();
|
|
16
|
+
const { data: contextData, xScale, yScale, x: contextX, y: contextY, radial } = chartContext();
|
|
16
17
|
/** Override data instead of using context */
|
|
17
18
|
export let data = undefined;
|
|
18
19
|
/** Pass `<path d={...} />` explicitly instead of calculating from data / context */
|
|
19
20
|
export let pathData = undefined;
|
|
20
|
-
/**
|
|
21
|
-
export let radial = false;
|
|
22
|
-
/** Override `x` accessor from Chart context. Applies to `angle` when `radial=true` */
|
|
21
|
+
/** Override `x` accessor from Chart context */
|
|
23
22
|
export let x = undefined;
|
|
24
|
-
/** Override `y` accessor from Chart context
|
|
23
|
+
/** Override `y` accessor from Chart context */
|
|
25
24
|
export let y = undefined;
|
|
26
25
|
/** Interpolate path data using d3-interpolate-path. Works best without `draw` enabled */
|
|
27
26
|
export let tweened = undefined;
|
|
@@ -39,17 +38,21 @@ export let draw = undefined;
|
|
|
39
38
|
export let curve = undefined;
|
|
40
39
|
export let defined = undefined;
|
|
41
40
|
function getScaleValue(data, scale, accessor) {
|
|
41
|
+
let value = accessor(data);
|
|
42
|
+
if (Array.isArray(value)) {
|
|
43
|
+
value = max(value);
|
|
44
|
+
}
|
|
42
45
|
if (scale.domain().length) {
|
|
43
46
|
// If scale is defined with domain, map value
|
|
44
|
-
return scale(
|
|
47
|
+
return scale(value);
|
|
45
48
|
}
|
|
46
49
|
else {
|
|
47
50
|
// Use raw value
|
|
48
|
-
return
|
|
51
|
+
return value;
|
|
49
52
|
}
|
|
50
53
|
}
|
|
51
|
-
const
|
|
52
|
-
const
|
|
54
|
+
const xAccessor = x ? accessor(x) : $contextX;
|
|
55
|
+
const yAccessor = y ? accessor(y) : $contextY;
|
|
53
56
|
$: xOffset = isScaleBand($xScale) ? $xScale.bandwidth() / 2 : 0;
|
|
54
57
|
$: yOffset = isScaleBand($yScale) ? $yScale.bandwidth() / 2 : 0;
|
|
55
58
|
let d = '';
|
|
@@ -57,17 +60,16 @@ let d = '';
|
|
|
57
60
|
$: tweenedOptions = tweened ? { interpolate: interpolatePath, ...tweened } : false;
|
|
58
61
|
$: tweened_d = motionStore('', { tweened: tweenedOptions });
|
|
59
62
|
$: {
|
|
60
|
-
const path = radial
|
|
63
|
+
const path = $radial
|
|
61
64
|
? lineRadial()
|
|
62
|
-
.angle((d) => getScaleValue(d, $xScale,
|
|
63
|
-
.radius((d) => getScaleValue(d, $yScale,
|
|
65
|
+
.angle((d) => getScaleValue(d, $xScale, xAccessor))
|
|
66
|
+
.radius((d) => getScaleValue(d, $yScale, yAccessor))
|
|
64
67
|
: d3Line()
|
|
65
|
-
.x((d) => getScaleValue(d, $xScale,
|
|
66
|
-
.y((d) => getScaleValue(d, $yScale,
|
|
68
|
+
.x((d) => getScaleValue(d, $xScale, xAccessor) + xOffset)
|
|
69
|
+
.y((d) => getScaleValue(d, $yScale, yAccessor) + yOffset);
|
|
70
|
+
path.defined(defined ?? ((d) => xAccessor(d) != null && yAccessor(d) != null));
|
|
67
71
|
if (curve)
|
|
68
72
|
path.curve(curve);
|
|
69
|
-
if (defined)
|
|
70
|
-
path.defined(defined);
|
|
71
73
|
d = pathData ?? path(data ?? $contextData) ?? '';
|
|
72
74
|
tweened_d.set(d);
|
|
73
75
|
}
|
|
@@ -115,9 +117,15 @@ $: {
|
|
|
115
117
|
<path
|
|
116
118
|
d={$tweened_d}
|
|
117
119
|
{...$$restProps}
|
|
118
|
-
class={cls(
|
|
120
|
+
class={cls(
|
|
121
|
+
'path-line',
|
|
122
|
+
!$$props.fill && 'fill-none',
|
|
123
|
+
!$$props.stroke && 'stroke-surface-content',
|
|
124
|
+
$$props.class
|
|
125
|
+
)}
|
|
119
126
|
in:drawTransition|global={typeof draw === 'object' ? draw : undefined}
|
|
120
127
|
on:click
|
|
128
|
+
on:pointerenter
|
|
121
129
|
on:pointermove
|
|
122
130
|
on:pointerleave
|
|
123
131
|
bind:this={pathEl}
|
|
@@ -8,7 +8,6 @@ declare const __propDef: {
|
|
|
8
8
|
[x: string]: any;
|
|
9
9
|
data?: any;
|
|
10
10
|
pathData?: string | undefined | null;
|
|
11
|
-
radial?: boolean | undefined;
|
|
12
11
|
x?: Accessor;
|
|
13
12
|
y?: Accessor;
|
|
14
13
|
tweened?: boolean | Parameters<typeof tweenedStore>[1];
|
|
@@ -18,6 +17,7 @@ declare const __propDef: {
|
|
|
18
17
|
};
|
|
19
18
|
events: {
|
|
20
19
|
click: MouseEvent;
|
|
20
|
+
pointerenter: PointerEvent;
|
|
21
21
|
pointermove: PointerEvent;
|
|
22
22
|
pointerleave: PointerEvent;
|
|
23
23
|
} & {
|
|
@@ -1,91 +1,29 @@
|
|
|
1
|
-
<script
|
|
2
|
-
See also:
|
|
3
|
-
- https://observablehq.com/@d3/difference-chart
|
|
4
|
-
- https://github.com/airbnb/visx/issues/245
|
|
5
|
-
*/
|
|
6
|
-
import { area as d3Area, line as d3Line } from 'd3-shape';
|
|
7
|
-
import { min, max } from 'd3-array';
|
|
1
|
+
<script>import { min } from 'd3-array';
|
|
8
2
|
import { chartContext } from './ChartContext.svelte';
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export let data = undefined; // TODO: Update Type
|
|
13
|
-
export let x = undefined;
|
|
14
|
-
export let y0 = undefined;
|
|
15
|
-
export let y1 = undefined;
|
|
3
|
+
import Area from './Area.svelte';
|
|
4
|
+
import ClipPath from './ClipPath.svelte';
|
|
5
|
+
const { y, yDomain } = chartContext();
|
|
16
6
|
export let curve = undefined;
|
|
17
7
|
export let defined = undefined;
|
|
18
|
-
export let id = Math.random().toString(16).slice(-4);
|
|
19
|
-
const _x = accessor(x);
|
|
20
|
-
const _y0 = accessor(y0);
|
|
21
|
-
const _y1 = accessor(y1);
|
|
22
|
-
$: areaPath = d3Area()
|
|
23
|
-
.x(x ? _x : $xGet)
|
|
24
|
-
.y0(y0 ? _y0 : (d) => $yGet(d)[0])
|
|
25
|
-
.y1(y1 ? _y1 : (d) => $yGet(d)[1]);
|
|
26
|
-
$: if (curve)
|
|
27
|
-
areaPath.curve(curve);
|
|
28
|
-
$: if (defined)
|
|
29
|
-
areaPath.defined(defined);
|
|
30
|
-
$: clipPathBelow = d3Area()
|
|
31
|
-
.x(x ? _x : $xGet)
|
|
32
|
-
.y0(y0 ? _y0 : (d) => $yGet(d)[0])
|
|
33
|
-
.y1(y1 ? _y1 : (d) => max($yRange));
|
|
34
|
-
$: if (curve)
|
|
35
|
-
clipPathBelow.curve(curve);
|
|
36
|
-
$: if (defined)
|
|
37
|
-
clipPathBelow.defined(defined);
|
|
38
|
-
$: clipPathAbove = d3Area()
|
|
39
|
-
.x(x ? _x : $xGet)
|
|
40
|
-
.y0(y0 ? _y0 : (d) => max($yRange))
|
|
41
|
-
.y1(y1 ? _y1 : (d) => $yGet(d)[1]);
|
|
42
|
-
$: if (curve)
|
|
43
|
-
clipPathAbove.curve(curve);
|
|
44
|
-
$: if (defined)
|
|
45
|
-
clipPathAbove.defined(defined);
|
|
46
|
-
$: linePathAbove = d3Line()
|
|
47
|
-
.x(x ? _x : $xGet)
|
|
48
|
-
.y(y0 ? _y0 : (d) => $yGet(d)[0]);
|
|
49
|
-
$: if (curve)
|
|
50
|
-
linePathAbove.curve(curve);
|
|
51
|
-
$: if (defined)
|
|
52
|
-
linePathAbove.defined(defined);
|
|
53
|
-
$: linePathBelow = d3Line()
|
|
54
|
-
.x(x ? _x : $xGet)
|
|
55
|
-
.y(y1 ? _y1 : (d) => $yGet(d)[1]);
|
|
56
|
-
$: if (curve)
|
|
57
|
-
linePathBelow.curve(curve);
|
|
58
|
-
$: if (defined)
|
|
59
|
-
linePathBelow.defined(defined);
|
|
60
8
|
</script>
|
|
61
9
|
|
|
62
10
|
<!-- Recreate on curve change as otherwise is 1 state change behind for some reason -->
|
|
63
11
|
{#key curve}
|
|
64
|
-
<
|
|
65
|
-
<
|
|
66
|
-
<
|
|
67
|
-
|
|
68
|
-
</clipPath>
|
|
69
|
-
<clipPath id="threshold-clip-above-{id}">
|
|
70
|
-
<path d={clipPathAbove(data ?? $contextData)} />
|
|
71
|
-
</clipPath>
|
|
72
|
-
</defs>
|
|
73
|
-
</g>
|
|
12
|
+
<ClipPath>
|
|
13
|
+
<svelte:fragment slot="clip">
|
|
14
|
+
<Area y0={(d) => $y(d)[0]} y1={(d) => min($yDomain)} {curve} {defined} />
|
|
15
|
+
</svelte:fragment>
|
|
74
16
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
areaPathData={areaPath(data ?? $contextData)}
|
|
78
|
-
clipPath="url(#threshold-clip-below-{id})"
|
|
79
|
-
linePathData={linePathAbove(data ?? $contextData)}
|
|
80
|
-
/>
|
|
17
|
+
<slot name="above" {curve} {defined} />
|
|
18
|
+
</ClipPath>
|
|
81
19
|
|
|
82
|
-
<
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
20
|
+
<ClipPath>
|
|
21
|
+
<svelte:fragment slot="clip">
|
|
22
|
+
<Area y0={(d) => min($yDomain)} y1={(d) => $y(d)[1]} {curve} {defined} />
|
|
23
|
+
</svelte:fragment>
|
|
24
|
+
|
|
25
|
+
<slot name="below" {curve} {defined} />
|
|
26
|
+
</ClipPath>
|
|
89
27
|
|
|
90
|
-
|
|
91
|
-
|
|
28
|
+
<slot {curve} {defined} />
|
|
29
|
+
{/key}
|
|
@@ -1,35 +1,28 @@
|
|
|
1
1
|
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import type { ComponentProps } from 'svelte';
|
|
2
3
|
import type { CurveFactory } from 'd3-shape';
|
|
3
|
-
import
|
|
4
|
+
import Area from './Area.svelte';
|
|
4
5
|
declare const __propDef: {
|
|
5
6
|
props: {
|
|
6
|
-
data?: any;
|
|
7
|
-
x?: Accessor;
|
|
8
|
-
y0?: Accessor;
|
|
9
|
-
y1?: Accessor;
|
|
10
7
|
curve?: CurveFactory | undefined;
|
|
11
|
-
defined?:
|
|
12
|
-
(): (d: [number, number], index: number, data: [number, number][]) => boolean;
|
|
13
|
-
(defined: boolean): import("d3-shape").Area<[number, number]>;
|
|
14
|
-
(defined: (d: [number, number], index: number, data: [number, number][]) => boolean): import("d3-shape").Area<[number, number]>;
|
|
15
|
-
}>[0] | undefined;
|
|
16
|
-
id?: string;
|
|
8
|
+
defined?: ComponentProps<Area>["defined"] | undefined;
|
|
17
9
|
};
|
|
18
10
|
events: {
|
|
19
11
|
[evt: string]: CustomEvent<any>;
|
|
20
12
|
};
|
|
21
13
|
slots: {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
linePathData: string | null;
|
|
14
|
+
above: {
|
|
15
|
+
curve: CurveFactory | undefined;
|
|
16
|
+
defined: ((d: any, index: number, data: any[]) => boolean) | undefined;
|
|
26
17
|
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
18
|
+
below: {
|
|
19
|
+
curve: CurveFactory | undefined;
|
|
20
|
+
defined: ((d: any, index: number, data: any[]) => boolean) | undefined;
|
|
21
|
+
};
|
|
22
|
+
default: {
|
|
23
|
+
curve: CurveFactory | undefined;
|
|
24
|
+
defined: ((d: any, index: number, data: any[]) => boolean) | undefined;
|
|
31
25
|
};
|
|
32
|
-
default: {};
|
|
33
26
|
};
|
|
34
27
|
};
|
|
35
28
|
export type ThresholdProps = typeof __propDef.props;
|
|
@@ -62,7 +62,7 @@ declare const __propDef: {
|
|
|
62
62
|
y: number;
|
|
63
63
|
}>;
|
|
64
64
|
initialScale?: number | undefined;
|
|
65
|
-
scale?: import("svelte/motion").Spring<number> | import("svelte/motion").Tweened<number
|
|
65
|
+
scale?: Writable<number> | import("svelte/motion").Spring<number> | import("svelte/motion").Tweened<number>;
|
|
66
66
|
setScrollMode?: (mode: TransformScrollMode) => void;
|
|
67
67
|
reset?: () => void;
|
|
68
68
|
zoomIn?: () => void;
|
|
@@ -137,7 +137,7 @@ export default class TransformContext extends SvelteComponentTyped<TransformCont
|
|
|
137
137
|
x: number;
|
|
138
138
|
y: number;
|
|
139
139
|
}> | undefined>;
|
|
140
|
-
get scale(): NonNullable<import("svelte/motion").Spring<number> | import("svelte/motion").Tweened<number> |
|
|
140
|
+
get scale(): NonNullable<Writable<number> | import("svelte/motion").Spring<number> | import("svelte/motion").Tweened<number> | undefined>;
|
|
141
141
|
get setScrollMode(): (mode: TransformScrollMode) => void;
|
|
142
142
|
get reset(): () => void;
|
|
143
143
|
get zoomIn(): () => void;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
<script>import { Button, Icon, MenuButton, Tooltip
|
|
1
|
+
<script>import { Button, Icon, MenuButton, Tooltip } from 'svelte-ux';
|
|
2
|
+
import { cls } from '@layerstack/tailwind';
|
|
2
3
|
import { mdiArrowULeftTop, mdiMagnifyPlusOutline, mdiMagnifyMinusOutline, mdiImageFilterCenterFocus, mdiChevronDown, mdiResize, mdiArrowExpandAll, mdiCancel, } from '@mdi/js';
|
|
3
4
|
import { transformContext } from './TransformContext.svelte';
|
|
4
5
|
export let placement = 'top-right';
|
|
@@ -2,9 +2,9 @@ import { SvelteComponentTyped } from "svelte";
|
|
|
2
2
|
declare const __propDef: {
|
|
3
3
|
props: {
|
|
4
4
|
[x: string]: any;
|
|
5
|
-
placement?: ("
|
|
5
|
+
placement?: ("left" | "right" | "center" | "bottom" | "top" | "top-left" | "top-right" | "bottom-left" | "bottom-right") | undefined;
|
|
6
6
|
orientation?: ("horizontal" | "vertical") | undefined;
|
|
7
|
-
show?: ("reset" | "
|
|
7
|
+
show?: ("reset" | "scrollMode" | "zoomIn" | "zoomOut" | "center")[] | undefined;
|
|
8
8
|
};
|
|
9
9
|
events: {
|
|
10
10
|
[evt: string]: CustomEvent<any>;
|