layerchart 0.54.0 → 0.55.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/Arc.svelte +170 -144
- package/dist/components/Area.svelte +96 -67
- package/dist/components/Area.svelte.d.ts +1 -0
- package/dist/components/Axis.svelte +205 -155
- package/dist/components/Bar.svelte +72 -45
- package/dist/components/Bars.svelte +45 -34
- package/dist/components/Blur.svelte +5 -3
- package/dist/components/Bounds.svelte +37 -21
- package/dist/components/Brush.svelte +269 -112
- package/dist/components/Brush.svelte.d.ts +7 -0
- package/dist/components/Calendar.svelte +51 -38
- package/dist/components/Chart.svelte +295 -74
- package/dist/components/Chart.svelte.d.ts +17 -17
- package/dist/components/ChartClipPath.svelte +8 -5
- package/dist/components/ChartContext.svelte +243 -93
- package/dist/components/ChartContext.svelte.d.ts +15 -23
- package/dist/components/Circle.svelte +25 -16
- package/dist/components/CircleClipPath.svelte +16 -10
- package/dist/components/ClipPath.svelte +11 -7
- package/dist/components/ColorRamp.svelte +12 -10
- package/dist/components/ForceSimulation.svelte +185 -116
- package/dist/components/Frame.svelte +10 -6
- package/dist/components/GeoCircle.svelte +15 -9
- package/dist/components/GeoContext.svelte +109 -62
- package/dist/components/GeoEdgeFade.svelte +20 -14
- package/dist/components/GeoPath.svelte +107 -69
- package/dist/components/GeoPoint.svelte +32 -18
- package/dist/components/GeoSpline.svelte +30 -22
- package/dist/components/GeoTile.svelte +40 -30
- package/dist/components/GeoVisible.svelte +10 -7
- package/dist/components/Graticule.svelte +14 -8
- package/dist/components/Grid.svelte +75 -48
- package/dist/components/Group.svelte +43 -31
- package/dist/components/Highlight.svelte +284 -243
- package/dist/components/HitCanvas.svelte +75 -42
- package/dist/components/Hull.svelte +40 -20
- package/dist/components/Labels.svelte +81 -70
- package/dist/components/Legend.svelte +105 -74
- package/dist/components/Legend.svelte.d.ts +1 -1
- package/dist/components/Line.svelte +65 -19
- package/dist/components/Line.svelte.d.ts +13 -1
- package/dist/components/LinearGradient.svelte +21 -15
- package/dist/components/Link.svelte +94 -22
- package/dist/components/Link.svelte.d.ts +17 -1
- package/dist/components/Marker.svelte +81 -0
- package/dist/components/Marker.svelte.d.ts +28 -0
- package/dist/components/MonthPath.svelte +23 -16
- package/dist/components/MotionPath.svelte +34 -25
- package/dist/components/Pack.svelte +21 -14
- package/dist/components/Partition.svelte +35 -20
- package/dist/components/Pattern.svelte +8 -6
- package/dist/components/Pie.svelte +76 -57
- package/dist/components/Point.svelte +11 -7
- package/dist/components/Points.svelte +178 -143
- package/dist/components/RadialGradient.svelte +25 -18
- package/dist/components/Rect.svelte +33 -19
- package/dist/components/RectClipPath.svelte +16 -11
- package/dist/components/Rule.svelte +50 -42
- package/dist/components/Sankey.svelte +55 -30
- package/dist/components/Spline.svelte +167 -96
- package/dist/components/Spline.svelte.d.ts +15 -0
- package/dist/components/Text.svelte +137 -104
- package/dist/components/Threshold.svelte +18 -7
- package/dist/components/TileImage.svelte +56 -50
- package/dist/components/TransformContext.svelte +235 -135
- package/dist/components/TransformControls.svelte +57 -29
- package/dist/components/TransformControls.svelte.d.ts +1 -1
- package/dist/components/Tree.svelte +33 -23
- package/dist/components/Treemap.svelte +69 -41
- package/dist/components/Voronoi.svelte +55 -28
- package/dist/components/charts/AreaChart.svelte +138 -87
- package/dist/components/charts/AreaChart.svelte.d.ts +4 -4
- package/dist/components/charts/BarChart.svelte +179 -114
- package/dist/components/charts/BarChart.svelte.d.ts +4 -4
- package/dist/components/charts/LineChart.svelte +97 -53
- package/dist/components/charts/LineChart.svelte.d.ts +4 -4
- package/dist/components/charts/PieChart.svelte +104 -54
- package/dist/components/charts/PieChart.svelte.d.ts +3 -3
- package/dist/components/charts/ScatterChart.svelte +83 -48
- package/dist/components/charts/ScatterChart.svelte.d.ts +4 -4
- package/dist/components/layout/Canvas.svelte +63 -43
- package/dist/components/layout/Html.svelte +28 -18
- package/dist/components/layout/Svg.svelte +47 -32
- package/dist/components/tooltip/Tooltip.svelte +137 -91
- package/dist/components/tooltip/Tooltip.svelte.d.ts +1 -1
- package/dist/components/tooltip/TooltipContext.svelte +315 -249
- package/dist/components/tooltip/TooltipHeader.svelte +9 -3
- package/dist/components/tooltip/TooltipItem.svelte +17 -9
- package/dist/components/tooltip/TooltipList.svelte +2 -1
- package/dist/components/tooltip/TooltipSeparator.svelte +3 -2
- package/dist/docs/Blockquote.svelte +4 -3
- package/dist/docs/Code.svelte +15 -8
- package/dist/docs/CurveMenuField.svelte +17 -12
- package/dist/docs/GeoDebug.svelte +13 -9
- package/dist/docs/Header1.svelte +2 -1
- package/dist/docs/Json.svelte +6 -4
- package/dist/docs/Layout.svelte +6 -6
- package/dist/docs/PathDataMenuField.svelte +52 -44
- package/dist/docs/Preview.svelte +39 -33
- package/dist/docs/TilesetField.svelte +80 -62
- package/dist/docs/TransformDebug.svelte +8 -5
- package/dist/docs/ViewSourceButton.svelte +13 -9
- package/dist/stores/motionStore.d.ts +1 -1
- package/dist/utils/scales.d.ts +3 -3
- package/package.json +29 -30
|
@@ -1,26 +1,40 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export let
|
|
13
|
-
export let
|
|
14
|
-
|
|
15
|
-
let
|
|
16
|
-
let
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { tick } from 'svelte';
|
|
3
|
+
import { cls } from '@layerstack/tailwind';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
motionStore,
|
|
7
|
+
resolveOptions,
|
|
8
|
+
type SpringOptions,
|
|
9
|
+
type TweenedOptions,
|
|
10
|
+
} from '../stores/motionStore.js';
|
|
11
|
+
|
|
12
|
+
export let x = 0;
|
|
13
|
+
export let initialX = x;
|
|
14
|
+
|
|
15
|
+
export let y = 0;
|
|
16
|
+
export let initialY = y;
|
|
17
|
+
|
|
18
|
+
export let width: number;
|
|
19
|
+
export let initialWidth = width;
|
|
20
|
+
|
|
21
|
+
export let height: number;
|
|
22
|
+
export let initialHeight = height;
|
|
23
|
+
|
|
24
|
+
export let spring: boolean | SpringOptions | { [prop: string]: SpringOptions } = undefined;
|
|
25
|
+
export let tweened: boolean | TweenedOptions | { [prop: string]: TweenedOptions } = undefined;
|
|
26
|
+
|
|
27
|
+
let tweened_x = motionStore(initialX, resolveOptions('x', { spring, tweened }));
|
|
28
|
+
let tweened_y = motionStore(initialY, resolveOptions('y', { spring, tweened }));
|
|
29
|
+
let tweened_width = motionStore(initialWidth, resolveOptions('width', { spring, tweened }));
|
|
30
|
+
let tweened_height = motionStore(initialHeight, resolveOptions('height', { spring, tweened }));
|
|
31
|
+
|
|
32
|
+
$: tick().then(() => {
|
|
19
33
|
tweened_x.set(x);
|
|
20
34
|
tweened_y.set(y);
|
|
21
35
|
tweened_width.set(width);
|
|
22
36
|
tweened_height.set(height);
|
|
23
|
-
});
|
|
37
|
+
});
|
|
24
38
|
</script>
|
|
25
39
|
|
|
26
40
|
<!-- svelte-ignore a11y-mouse-events-have-key-events -->
|
|
@@ -1,14 +1,19 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export let
|
|
10
|
-
|
|
11
|
-
export let
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { ComponentProps } from 'svelte';
|
|
3
|
+
import { uniqueId } from '@layerstack/utils';
|
|
4
|
+
|
|
5
|
+
import ClipPath from './ClipPath.svelte';
|
|
6
|
+
import Rect from './Rect.svelte';
|
|
7
|
+
|
|
8
|
+
/** Unique id for clipPath */
|
|
9
|
+
export let id: string = uniqueId('clipPath-');
|
|
10
|
+
|
|
11
|
+
export let x: number = 0;
|
|
12
|
+
export let y: number = 0;
|
|
13
|
+
export let width: number;
|
|
14
|
+
export let height: number;
|
|
15
|
+
export let spring: ComponentProps<Rect>['spring'] = undefined;
|
|
16
|
+
export let tweened: ComponentProps<Rect>['tweened'] = undefined;
|
|
12
17
|
</script>
|
|
13
18
|
|
|
14
19
|
<ClipPath {id} let:url>
|
|
@@ -1,47 +1,55 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { extent } from 'd3-array';
|
|
3
|
+
import { pointRadial } from 'd3-shape';
|
|
4
|
+
import { cls } from '@layerstack/tailwind';
|
|
5
|
+
|
|
6
|
+
import { chartContext } from './ChartContext.svelte';
|
|
7
|
+
import Circle from './Circle.svelte';
|
|
8
|
+
import Line from './Line.svelte';
|
|
9
|
+
|
|
10
|
+
const { xScale, yScale, xRange, yRange, radial } = chartContext();
|
|
11
|
+
|
|
12
|
+
$: [xRangeMin, xRangeMax] = extent<number | Date>($xRange);
|
|
13
|
+
$: [yRangeMin, yRangeMax] = extent<number | Date>($yRange);
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Create a vertical `x` line
|
|
17
|
+
* - If true or 'left', will draw at chart left (xRange[0])
|
|
18
|
+
* - If 'right', will draw at chart right (xRange[1])
|
|
19
|
+
* - Use `0` for baseline (yScale(0))
|
|
20
|
+
* - Use number | Date value for annotation (yScale(value))
|
|
21
|
+
*/
|
|
22
|
+
export let x: number | Date | boolean | 'left' | 'right' = false;
|
|
23
|
+
|
|
24
|
+
/** Pixel offset to apply to `x` coordinate */
|
|
25
|
+
export let xOffset = 0;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Create a horizontal `y` line
|
|
29
|
+
* - If true or 'bottom', will draw at chart bottom (yRange[0])
|
|
30
|
+
* - If 'top', will draw at chart top (yRange[1])
|
|
31
|
+
* - Use `0` for baseline (xScale(0))
|
|
32
|
+
* - Use number | Date value for annotation (xScale(value))
|
|
33
|
+
*/
|
|
34
|
+
export let y: number | Date | boolean | 'top' | 'bottom' = false;
|
|
35
|
+
|
|
36
|
+
/** Pixel offset to apply to `y` coordinate */
|
|
37
|
+
export let yOffset = 0;
|
|
38
|
+
|
|
39
|
+
$: showRule = (value: typeof x | typeof y, axis: 'x' | 'y') => {
|
|
31
40
|
switch (typeof value) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
41
|
+
case 'boolean':
|
|
42
|
+
return value;
|
|
43
|
+
case 'string':
|
|
44
|
+
return true;
|
|
45
|
+
default:
|
|
46
|
+
if (axis === 'x') {
|
|
47
|
+
return $xScale(value) >= xRangeMin! && $xScale(value) <= xRangeMax!;
|
|
48
|
+
} else {
|
|
49
|
+
return $yScale(value) >= yRangeMin! && $yScale(value) <= yRangeMax!;
|
|
50
|
+
}
|
|
43
51
|
}
|
|
44
|
-
}
|
|
52
|
+
};
|
|
45
53
|
</script>
|
|
46
54
|
|
|
47
55
|
<g class="rule">
|
|
@@ -1,33 +1,55 @@
|
|
|
1
|
-
<script
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
// https://github.com/d3/d3-sankey
|
|
3
|
+
import { createEventDispatcher } from 'svelte';
|
|
4
|
+
import {
|
|
5
|
+
sankey as d3Sankey,
|
|
6
|
+
sankeyLeft,
|
|
7
|
+
sankeyCenter,
|
|
8
|
+
sankeyRight,
|
|
9
|
+
sankeyJustify,
|
|
10
|
+
type SankeyNode,
|
|
11
|
+
type SankeyLink,
|
|
12
|
+
} from 'd3-sankey';
|
|
13
|
+
|
|
14
|
+
import { chartContext } from './ChartContext.svelte';
|
|
15
|
+
|
|
16
|
+
const dispatch = createEventDispatcher();
|
|
17
|
+
|
|
18
|
+
const { data, width, height } = chartContext();
|
|
19
|
+
|
|
20
|
+
export let nodes = (d: any) => d.nodes;
|
|
21
|
+
export let nodeId = (d: any) => d.index;
|
|
22
|
+
/**
|
|
23
|
+
* see: https://github.com/d3/d3-sankey#alignments
|
|
24
|
+
*/
|
|
25
|
+
export let nodeAlign:
|
|
26
|
+
| ((node: SankeyNode<any, any>, n: number) => number)
|
|
27
|
+
| 'left'
|
|
28
|
+
| 'right'
|
|
29
|
+
| 'center'
|
|
30
|
+
| 'justify' = sankeyJustify;
|
|
31
|
+
export let nodeWidth = 4;
|
|
32
|
+
export let nodePadding = 10;
|
|
33
|
+
export let nodeSort = undefined;
|
|
34
|
+
|
|
35
|
+
export let links = (d: any) => d.links;
|
|
36
|
+
export let linkSort = undefined;
|
|
37
|
+
|
|
38
|
+
$: sankey = d3Sankey()
|
|
19
39
|
.size([$width, $height])
|
|
20
40
|
.nodes(nodes)
|
|
21
41
|
.nodeId(nodeId)
|
|
22
|
-
.nodeAlign(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
42
|
+
.nodeAlign(
|
|
43
|
+
nodeAlign === 'left'
|
|
44
|
+
? sankeyLeft
|
|
45
|
+
: nodeAlign === 'center'
|
|
46
|
+
? sankeyCenter
|
|
47
|
+
: nodeAlign === 'right'
|
|
27
48
|
? sankeyRight
|
|
28
49
|
: nodeAlign === 'justify'
|
|
29
|
-
|
|
30
|
-
|
|
50
|
+
? sankeyJustify
|
|
51
|
+
: nodeAlign
|
|
52
|
+
)
|
|
31
53
|
.nodeWidth(nodeWidth)
|
|
32
54
|
.nodePadding(nodePadding)
|
|
33
55
|
// @ts-expect-error
|
|
@@ -35,11 +57,14 @@ $: sankey = d3Sankey()
|
|
|
35
57
|
.links(links)
|
|
36
58
|
// @ts-expect-error
|
|
37
59
|
.linkSort(linkSort);
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
$:
|
|
41
|
-
|
|
42
|
-
$:
|
|
60
|
+
|
|
61
|
+
// @ts-expect-error
|
|
62
|
+
$: sankeyData = sankey($data);
|
|
63
|
+
type NodeExtraProperties = Record<string, any>;
|
|
64
|
+
$: _nodes = sankeyData.nodes as SankeyNode<NodeExtraProperties, any>[];
|
|
65
|
+
$: _links = sankeyData.links as SankeyLink<NodeExtraProperties, any>[];
|
|
66
|
+
|
|
67
|
+
$: dispatch('update', sankeyData);
|
|
43
68
|
</script>
|
|
44
69
|
|
|
45
70
|
<slot nodes={_nodes} links={_links} />
|
|
@@ -1,115 +1,157 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
*/
|
|
38
|
-
export let
|
|
39
|
-
|
|
40
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { tick, type ComponentProps } from 'svelte';
|
|
3
|
+
import { writable } from 'svelte/store';
|
|
4
|
+
import { tweened as tweenedStore } from 'svelte/motion';
|
|
5
|
+
import { draw as _drawTransition } from 'svelte/transition';
|
|
6
|
+
import { cubicInOut } from 'svelte/easing';
|
|
7
|
+
|
|
8
|
+
import { line as d3Line, lineRadial } from 'd3-shape';
|
|
9
|
+
import type { CurveFactory, CurveFactoryLineOnly, Line } from 'd3-shape';
|
|
10
|
+
// import { interpolateString } from 'd3-interpolate';
|
|
11
|
+
import { interpolatePath } from 'd3-interpolate-path';
|
|
12
|
+
import { max } from 'd3-array';
|
|
13
|
+
import { cls } from '@layerstack/tailwind';
|
|
14
|
+
import { uniqueId } from '@layerstack/utils';
|
|
15
|
+
|
|
16
|
+
import { chartContext } from './ChartContext.svelte';
|
|
17
|
+
import Group from './Group.svelte';
|
|
18
|
+
import Marker from './Marker.svelte';
|
|
19
|
+
|
|
20
|
+
import { motionStore } from '../stores/motionStore.js';
|
|
21
|
+
import { accessor, type Accessor } from '../utils/common.js';
|
|
22
|
+
import { isScaleBand } from '../utils/scales.js';
|
|
23
|
+
|
|
24
|
+
const { data: contextData, xScale, yScale, x: contextX, y: contextY, radial } = chartContext();
|
|
25
|
+
|
|
26
|
+
/** Override data instead of using context */
|
|
27
|
+
export let data: any = undefined;
|
|
28
|
+
|
|
29
|
+
/** Pass `<path d={...} />` explicitly instead of calculating from data / context */
|
|
30
|
+
export let pathData: string | undefined | null = undefined;
|
|
31
|
+
|
|
32
|
+
/** Override `x` accessor from Chart context */
|
|
33
|
+
export let x: Accessor = undefined;
|
|
34
|
+
/** Override `y` accessor from Chart context */
|
|
35
|
+
export let y: Accessor = undefined;
|
|
36
|
+
|
|
37
|
+
/** Interpolate path data using d3-interpolate-path. Works best without `draw` enabled */
|
|
38
|
+
export let tweened: boolean | Parameters<typeof tweenedStore>[1] = undefined;
|
|
39
|
+
/** Draw path over time. Works best without `tweened` enabled */
|
|
40
|
+
export let draw: boolean | Parameters<typeof _drawTransition>[1] = undefined;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Curve of spline drawn. Imported via d3-shape.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* import { curveNatural } from 'd3-shape';
|
|
47
|
+
* <Spline curve={curveNatrual} />
|
|
48
|
+
*
|
|
49
|
+
* @type {CurveFactory | CurveFactoryLineOnly | undefined}
|
|
50
|
+
*/
|
|
51
|
+
export let curve: CurveFactory | CurveFactoryLineOnly | undefined = undefined;
|
|
52
|
+
export let defined: Parameters<Line<any>['defined']>[0] | undefined = undefined;
|
|
53
|
+
|
|
54
|
+
/** Marker to attach to start, mid, and end points of path */
|
|
55
|
+
export let marker: ComponentProps<Marker>['type'] | ComponentProps<Marker> | undefined =
|
|
56
|
+
undefined;
|
|
57
|
+
/** Marker to attach to start point of path */
|
|
58
|
+
export let markerStart: ComponentProps<Marker>['type'] | ComponentProps<Marker> | undefined =
|
|
59
|
+
marker;
|
|
60
|
+
/** Marker to attach to all mid points of path */
|
|
61
|
+
export let markerMid: ComponentProps<Marker>['type'] | ComponentProps<Marker> | undefined =
|
|
62
|
+
marker;
|
|
63
|
+
/** Marker to attach to end point of path */
|
|
64
|
+
export let markerEnd: ComponentProps<Marker>['type'] | ComponentProps<Marker> | undefined =
|
|
65
|
+
marker;
|
|
66
|
+
|
|
67
|
+
$: markerStartId = markerStart || $$slots['markerStart'] ? uniqueId('marker-') : '';
|
|
68
|
+
$: markerMidId = markerMid || $$slots['markerMid'] ? uniqueId('marker-') : '';
|
|
69
|
+
$: markerEndId = markerEnd || $$slots['markerEnd'] ? uniqueId('marker-') : '';
|
|
70
|
+
|
|
71
|
+
function getScaleValue(data: any, scale: typeof $xScale | typeof $yScale, accessor: Function) {
|
|
41
72
|
let value = accessor(data);
|
|
73
|
+
|
|
42
74
|
if (Array.isArray(value)) {
|
|
43
|
-
|
|
75
|
+
value = max(value);
|
|
44
76
|
}
|
|
77
|
+
|
|
45
78
|
if (scale.domain().length) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return value;
|
|
79
|
+
// If scale is defined with domain, map value
|
|
80
|
+
return scale(value);
|
|
81
|
+
} else {
|
|
82
|
+
// Use raw value
|
|
83
|
+
return value;
|
|
52
84
|
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const xAccessor = x ? accessor(x) : $contextX;
|
|
88
|
+
const yAccessor = y ? accessor(y) : $contextY;
|
|
89
|
+
|
|
90
|
+
$: xOffset = isScaleBand($xScale) ? $xScale.bandwidth() / 2 : 0;
|
|
91
|
+
$: yOffset = isScaleBand($yScale) ? $yScale.bandwidth() / 2 : 0;
|
|
92
|
+
|
|
93
|
+
let d: string | null = '';
|
|
94
|
+
// @ts-expect-error
|
|
95
|
+
$: tweenedOptions = tweened ? { interpolate: interpolatePath, ...tweened } : false;
|
|
96
|
+
$: tweened_d = motionStore('', { tweened: tweenedOptions });
|
|
97
|
+
$: {
|
|
63
98
|
const path = $radial
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
99
|
+
? lineRadial()
|
|
100
|
+
.angle((d) => getScaleValue(d, $xScale, xAccessor))
|
|
101
|
+
.radius((d) => getScaleValue(d, $yScale, yAccessor))
|
|
102
|
+
: d3Line()
|
|
103
|
+
.x((d) => getScaleValue(d, $xScale, xAccessor) + xOffset)
|
|
104
|
+
.y((d) => getScaleValue(d, $yScale, yAccessor) + yOffset);
|
|
105
|
+
|
|
70
106
|
path.defined(defined ?? ((d) => xAccessor(d) != null && yAccessor(d) != null));
|
|
71
|
-
|
|
72
|
-
|
|
107
|
+
|
|
108
|
+
if (curve) path.curve(curve);
|
|
109
|
+
|
|
73
110
|
d = pathData ?? path(data ?? $contextData) ?? '';
|
|
74
111
|
tweened_d.set(d);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
$: drawTransition = draw ? _drawTransition : () => ({});
|
|
115
|
+
|
|
116
|
+
let key = Symbol();
|
|
117
|
+
$: if (draw) {
|
|
79
118
|
// Anytime the path data changes, redraw
|
|
80
119
|
$tweened_d;
|
|
81
120
|
key = Symbol();
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
let pathEl: SVGPathElement | undefined = undefined;
|
|
124
|
+
const startPoint = writable<DOMPoint | undefined>(undefined);
|
|
125
|
+
$: endPoint = motionStore<DOMPoint | undefined>(undefined, {
|
|
86
126
|
tweened: draw
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
127
|
+
? {
|
|
128
|
+
duration: (typeof draw === 'object' && draw.duration) || 800,
|
|
129
|
+
easing: (typeof draw === 'object' && draw.easing) || cubicInOut,
|
|
130
|
+
interpolate(a, b) {
|
|
131
|
+
return (t: number) => {
|
|
132
|
+
const totalLength = pathEl?.getTotalLength() ?? 0;
|
|
133
|
+
const point = pathEl?.getPointAtLength(totalLength * t);
|
|
134
|
+
return point;
|
|
135
|
+
};
|
|
136
|
+
},
|
|
97
137
|
}
|
|
98
|
-
|
|
99
|
-
});
|
|
100
|
-
|
|
138
|
+
: false,
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
$: {
|
|
101
142
|
if ($$slots.start || $$slots.end) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
143
|
+
// Wait for path data to update DOM, then update
|
|
144
|
+
d;
|
|
145
|
+
tick().then(() => {
|
|
146
|
+
if (pathEl) {
|
|
147
|
+
startPoint.set(pathEl.getPointAtLength(0));
|
|
148
|
+
|
|
149
|
+
const totalLength = pathEl.getTotalLength();
|
|
150
|
+
endPoint.set(pathEl.getPointAtLength(totalLength));
|
|
151
|
+
}
|
|
152
|
+
});
|
|
111
153
|
}
|
|
112
|
-
}
|
|
154
|
+
}
|
|
113
155
|
</script>
|
|
114
156
|
|
|
115
157
|
{#key key}
|
|
@@ -123,6 +165,9 @@ $: {
|
|
|
123
165
|
!$$props.stroke && 'stroke-surface-content',
|
|
124
166
|
$$props.class
|
|
125
167
|
)}
|
|
168
|
+
marker-start={markerStartId ? `url(#${markerStartId})` : undefined}
|
|
169
|
+
marker-mid={markerMidId ? `url(#${markerMidId})` : undefined}
|
|
170
|
+
marker-end={markerEndId ? `url(#${markerEndId})` : undefined}
|
|
126
171
|
in:drawTransition|global={typeof draw === 'object' ? draw : undefined}
|
|
127
172
|
on:click
|
|
128
173
|
on:pointerenter
|
|
@@ -131,6 +176,32 @@ $: {
|
|
|
131
176
|
bind:this={pathEl}
|
|
132
177
|
/>
|
|
133
178
|
|
|
179
|
+
<slot name="markerStart" id={markerStartId}>
|
|
180
|
+
{#if markerStart}
|
|
181
|
+
<Marker
|
|
182
|
+
id={markerStartId}
|
|
183
|
+
type={typeof markerStart === 'string' ? markerStart : undefined}
|
|
184
|
+
{...typeof markerStart === 'object' ? markerStart : null}
|
|
185
|
+
/>
|
|
186
|
+
{/if}
|
|
187
|
+
</slot>
|
|
188
|
+
|
|
189
|
+
<slot name="markerMid" id={markerMidId}>
|
|
190
|
+
<Marker
|
|
191
|
+
id={markerMidId}
|
|
192
|
+
type={typeof markerMid === 'string' ? markerMid : undefined}
|
|
193
|
+
{...typeof markerMid === 'object' ? markerMid : null}
|
|
194
|
+
/>
|
|
195
|
+
</slot>
|
|
196
|
+
|
|
197
|
+
<slot name="markerEnd" id={markerEndId}>
|
|
198
|
+
<Marker
|
|
199
|
+
id={markerEndId}
|
|
200
|
+
type={typeof markerEnd === 'string' ? markerEnd : undefined}
|
|
201
|
+
{...typeof markerEnd === 'object' ? markerEnd : null}
|
|
202
|
+
/>
|
|
203
|
+
</slot>
|
|
204
|
+
|
|
134
205
|
{#if $$slots.start && $startPoint}
|
|
135
206
|
<Group x={$startPoint.x} y={$startPoint.y}>
|
|
136
207
|
<slot name="start" point={$startPoint} />
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import { type ComponentProps } from 'svelte';
|
|
2
3
|
import { tweened as tweenedStore } from 'svelte/motion';
|
|
3
4
|
import { draw as _drawTransition } from 'svelte/transition';
|
|
4
5
|
import type { CurveFactory, CurveFactoryLineOnly, Line } from 'd3-shape';
|
|
6
|
+
import Marker from './Marker.svelte';
|
|
5
7
|
import { type Accessor } from '../utils/common.js';
|
|
6
8
|
declare const __propDef: {
|
|
7
9
|
props: {
|
|
@@ -14,6 +16,10 @@ declare const __propDef: {
|
|
|
14
16
|
draw?: boolean | Parameters<typeof _drawTransition>[1];
|
|
15
17
|
curve?: CurveFactory | CurveFactoryLineOnly | undefined;
|
|
16
18
|
defined?: Parameters<Line<any>["defined"]>[0] | undefined;
|
|
19
|
+
marker?: ComponentProps<Marker>["type"] | ComponentProps<Marker> | undefined;
|
|
20
|
+
markerStart?: ComponentProps<Marker>["type"] | ComponentProps<Marker> | undefined;
|
|
21
|
+
markerMid?: ComponentProps<Marker>["type"] | ComponentProps<Marker> | undefined;
|
|
22
|
+
markerEnd?: ComponentProps<Marker>["type"] | ComponentProps<Marker> | undefined;
|
|
17
23
|
};
|
|
18
24
|
events: {
|
|
19
25
|
click: MouseEvent;
|
|
@@ -24,6 +30,15 @@ declare const __propDef: {
|
|
|
24
30
|
[evt: string]: CustomEvent<any>;
|
|
25
31
|
};
|
|
26
32
|
slots: {
|
|
33
|
+
markerStart: {
|
|
34
|
+
id: string;
|
|
35
|
+
};
|
|
36
|
+
markerMid: {
|
|
37
|
+
id: string;
|
|
38
|
+
};
|
|
39
|
+
markerEnd: {
|
|
40
|
+
id: string;
|
|
41
|
+
};
|
|
27
42
|
start: {
|
|
28
43
|
point: DOMPoint | undefined;
|
|
29
44
|
};
|