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.
Files changed (105) hide show
  1. package/dist/components/Arc.svelte +170 -144
  2. package/dist/components/Area.svelte +96 -67
  3. package/dist/components/Area.svelte.d.ts +1 -0
  4. package/dist/components/Axis.svelte +205 -155
  5. package/dist/components/Bar.svelte +72 -45
  6. package/dist/components/Bars.svelte +45 -34
  7. package/dist/components/Blur.svelte +5 -3
  8. package/dist/components/Bounds.svelte +37 -21
  9. package/dist/components/Brush.svelte +269 -112
  10. package/dist/components/Brush.svelte.d.ts +7 -0
  11. package/dist/components/Calendar.svelte +51 -38
  12. package/dist/components/Chart.svelte +295 -74
  13. package/dist/components/Chart.svelte.d.ts +17 -17
  14. package/dist/components/ChartClipPath.svelte +8 -5
  15. package/dist/components/ChartContext.svelte +243 -93
  16. package/dist/components/ChartContext.svelte.d.ts +15 -23
  17. package/dist/components/Circle.svelte +25 -16
  18. package/dist/components/CircleClipPath.svelte +16 -10
  19. package/dist/components/ClipPath.svelte +11 -7
  20. package/dist/components/ColorRamp.svelte +12 -10
  21. package/dist/components/ForceSimulation.svelte +185 -116
  22. package/dist/components/Frame.svelte +10 -6
  23. package/dist/components/GeoCircle.svelte +15 -9
  24. package/dist/components/GeoContext.svelte +109 -62
  25. package/dist/components/GeoEdgeFade.svelte +20 -14
  26. package/dist/components/GeoPath.svelte +107 -69
  27. package/dist/components/GeoPoint.svelte +32 -18
  28. package/dist/components/GeoSpline.svelte +30 -22
  29. package/dist/components/GeoTile.svelte +40 -30
  30. package/dist/components/GeoVisible.svelte +10 -7
  31. package/dist/components/Graticule.svelte +14 -8
  32. package/dist/components/Grid.svelte +75 -48
  33. package/dist/components/Group.svelte +43 -31
  34. package/dist/components/Highlight.svelte +284 -243
  35. package/dist/components/HitCanvas.svelte +75 -42
  36. package/dist/components/Hull.svelte +40 -20
  37. package/dist/components/Labels.svelte +81 -70
  38. package/dist/components/Legend.svelte +105 -74
  39. package/dist/components/Legend.svelte.d.ts +1 -1
  40. package/dist/components/Line.svelte +65 -19
  41. package/dist/components/Line.svelte.d.ts +13 -1
  42. package/dist/components/LinearGradient.svelte +21 -15
  43. package/dist/components/Link.svelte +94 -22
  44. package/dist/components/Link.svelte.d.ts +17 -1
  45. package/dist/components/Marker.svelte +81 -0
  46. package/dist/components/Marker.svelte.d.ts +28 -0
  47. package/dist/components/MonthPath.svelte +23 -16
  48. package/dist/components/MotionPath.svelte +34 -25
  49. package/dist/components/Pack.svelte +21 -14
  50. package/dist/components/Partition.svelte +35 -20
  51. package/dist/components/Pattern.svelte +8 -6
  52. package/dist/components/Pie.svelte +76 -57
  53. package/dist/components/Point.svelte +11 -7
  54. package/dist/components/Points.svelte +178 -143
  55. package/dist/components/RadialGradient.svelte +25 -18
  56. package/dist/components/Rect.svelte +33 -19
  57. package/dist/components/RectClipPath.svelte +16 -11
  58. package/dist/components/Rule.svelte +50 -42
  59. package/dist/components/Sankey.svelte +55 -30
  60. package/dist/components/Spline.svelte +167 -96
  61. package/dist/components/Spline.svelte.d.ts +15 -0
  62. package/dist/components/Text.svelte +137 -104
  63. package/dist/components/Threshold.svelte +18 -7
  64. package/dist/components/TileImage.svelte +56 -50
  65. package/dist/components/TransformContext.svelte +235 -135
  66. package/dist/components/TransformControls.svelte +57 -29
  67. package/dist/components/TransformControls.svelte.d.ts +1 -1
  68. package/dist/components/Tree.svelte +33 -23
  69. package/dist/components/Treemap.svelte +69 -41
  70. package/dist/components/Voronoi.svelte +55 -28
  71. package/dist/components/charts/AreaChart.svelte +138 -87
  72. package/dist/components/charts/AreaChart.svelte.d.ts +4 -4
  73. package/dist/components/charts/BarChart.svelte +179 -114
  74. package/dist/components/charts/BarChart.svelte.d.ts +4 -4
  75. package/dist/components/charts/LineChart.svelte +97 -53
  76. package/dist/components/charts/LineChart.svelte.d.ts +4 -4
  77. package/dist/components/charts/PieChart.svelte +104 -54
  78. package/dist/components/charts/PieChart.svelte.d.ts +3 -3
  79. package/dist/components/charts/ScatterChart.svelte +83 -48
  80. package/dist/components/charts/ScatterChart.svelte.d.ts +4 -4
  81. package/dist/components/layout/Canvas.svelte +63 -43
  82. package/dist/components/layout/Html.svelte +28 -18
  83. package/dist/components/layout/Svg.svelte +47 -32
  84. package/dist/components/tooltip/Tooltip.svelte +137 -91
  85. package/dist/components/tooltip/Tooltip.svelte.d.ts +1 -1
  86. package/dist/components/tooltip/TooltipContext.svelte +315 -249
  87. package/dist/components/tooltip/TooltipHeader.svelte +9 -3
  88. package/dist/components/tooltip/TooltipItem.svelte +17 -9
  89. package/dist/components/tooltip/TooltipList.svelte +2 -1
  90. package/dist/components/tooltip/TooltipSeparator.svelte +3 -2
  91. package/dist/docs/Blockquote.svelte +4 -3
  92. package/dist/docs/Code.svelte +15 -8
  93. package/dist/docs/CurveMenuField.svelte +17 -12
  94. package/dist/docs/GeoDebug.svelte +13 -9
  95. package/dist/docs/Header1.svelte +2 -1
  96. package/dist/docs/Json.svelte +6 -4
  97. package/dist/docs/Layout.svelte +6 -6
  98. package/dist/docs/PathDataMenuField.svelte +52 -44
  99. package/dist/docs/Preview.svelte +39 -33
  100. package/dist/docs/TilesetField.svelte +80 -62
  101. package/dist/docs/TransformDebug.svelte +8 -5
  102. package/dist/docs/ViewSourceButton.svelte +13 -9
  103. package/dist/stores/motionStore.d.ts +1 -1
  104. package/dist/utils/scales.d.ts +3 -3
  105. package/package.json +29 -30
@@ -1,26 +1,40 @@
1
- <script>import { tick } from 'svelte';
2
- import { cls } from '@layerstack/tailwind';
3
- import { motionStore, resolveOptions, } from '../stores/motionStore.js';
4
- export let x = 0;
5
- export let initialX = x;
6
- export let y = 0;
7
- export let initialY = y;
8
- export let width;
9
- export let initialWidth = width;
10
- export let height;
11
- export let initialHeight = height;
12
- export let spring = undefined;
13
- export let tweened = undefined;
14
- let tweened_x = motionStore(initialX, resolveOptions('x', { spring, tweened }));
15
- let tweened_y = motionStore(initialY, resolveOptions('y', { spring, tweened }));
16
- let tweened_width = motionStore(initialWidth, resolveOptions('width', { spring, tweened }));
17
- let tweened_height = motionStore(initialHeight, resolveOptions('height', { spring, tweened }));
18
- $: tick().then(() => {
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>import { uniqueId } from '@layerstack/utils';
2
- import ClipPath from './ClipPath.svelte';
3
- import Rect from './Rect.svelte';
4
- /** Unique id for clipPath */
5
- export let id = uniqueId('clipPath-');
6
- export let x = 0;
7
- export let y = 0;
8
- export let width;
9
- export let height;
10
- export let spring = undefined;
11
- export let tweened = undefined;
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>import { extent } from 'd3-array';
2
- import { pointRadial } from 'd3-shape';
3
- import { cls } from '@layerstack/tailwind';
4
- import { chartContext } from './ChartContext.svelte';
5
- import Circle from './Circle.svelte';
6
- import Line from './Line.svelte';
7
- const { xScale, yScale, xRange, yRange, radial } = chartContext();
8
- $: [xRangeMin, xRangeMax] = extent($xRange);
9
- $: [yRangeMin, yRangeMax] = extent($yRange);
10
- /**
11
- * Create a vertical `x` line
12
- * - If true or 'left', will draw at chart left (xRange[0])
13
- * - If 'right', will draw at chart right (xRange[1])
14
- * - Use `0` for baseline (yScale(0))
15
- * - Use number | Date value for annotation (yScale(value))
16
- */
17
- export let x = false;
18
- /** Pixel offset to apply to `x` coordinate */
19
- export let xOffset = 0;
20
- /**
21
- * Create a horizontal `y` line
22
- * - If true or 'bottom', will draw at chart bottom (yRange[0])
23
- * - If 'top', will draw at chart top (yRange[1])
24
- * - Use `0` for baseline (xScale(0))
25
- * - Use number | Date value for annotation (xScale(value))
26
- */
27
- export let y = false;
28
- /** Pixel offset to apply to `y` coordinate */
29
- export let yOffset = 0;
30
- function showRule(value, axis) {
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
- case 'boolean':
33
- return value;
34
- case 'string':
35
- return true;
36
- default:
37
- if (axis === 'x') {
38
- return $xScale(value) >= xRangeMin && $xScale(value) <= xRangeMax;
39
- }
40
- else {
41
- return $yScale(value) >= yRangeMin && $yScale(value) <= yRangeMax;
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>// https://github.com/d3/d3-sankey
2
- import { createEventDispatcher } from 'svelte';
3
- import { sankey as d3Sankey, sankeyLeft, sankeyCenter, sankeyRight, sankeyJustify, } from 'd3-sankey';
4
- import { chartContext } from './ChartContext.svelte';
5
- const dispatch = createEventDispatcher();
6
- const { data, width, height } = chartContext();
7
- export let nodes = (d) => d.nodes;
8
- export let nodeId = (d) => d.index;
9
- /**
10
- * see: https://github.com/d3/d3-sankey#alignments
11
- */
12
- export let nodeAlign = sankeyJustify;
13
- export let nodeWidth = 4;
14
- export let nodePadding = 10;
15
- export let nodeSort = undefined;
16
- export let links = (d) => d.links;
17
- export let linkSort = undefined;
18
- $: sankey = d3Sankey()
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(nodeAlign === 'left'
23
- ? sankeyLeft
24
- : nodeAlign === 'center'
25
- ? sankeyCenter
26
- : nodeAlign === 'right'
42
+ .nodeAlign(
43
+ nodeAlign === 'left'
44
+ ? sankeyLeft
45
+ : nodeAlign === 'center'
46
+ ? sankeyCenter
47
+ : nodeAlign === 'right'
27
48
  ? sankeyRight
28
49
  : nodeAlign === 'justify'
29
- ? sankeyJustify
30
- : nodeAlign)
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
- // @ts-expect-error
39
- $: sankeyData = sankey($data);
40
- $: _nodes = sankeyData.nodes;
41
- $: _links = sankeyData.links;
42
- $: dispatch('update', sankeyData);
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>import { tick } from 'svelte';
2
- import { writable } from 'svelte/store';
3
- import { tweened as tweenedStore } from 'svelte/motion';
4
- import { draw as _drawTransition } from 'svelte/transition';
5
- import { cubicInOut } from 'svelte/easing';
6
- import { line as d3Line, lineRadial } from 'd3-shape';
7
- // import { interpolateString } from 'd3-interpolate';
8
- import { interpolatePath } from 'd3-interpolate-path';
9
- import { max } from 'd3-array';
10
- import { cls } from '@layerstack/tailwind';
11
- import { chartContext } from './ChartContext.svelte';
12
- import Group from './Group.svelte';
13
- import { motionStore } from '../stores/motionStore.js';
14
- import { accessor } from '../utils/common.js';
15
- import { isScaleBand } from '../utils/scales.js';
16
- const { data: contextData, xScale, yScale, x: contextX, y: contextY, radial } = chartContext();
17
- /** Override data instead of using context */
18
- export let data = undefined;
19
- /** Pass `<path d={...} />` explicitly instead of calculating from data / context */
20
- export let pathData = undefined;
21
- /** Override `x` accessor from Chart context */
22
- export let x = undefined;
23
- /** Override `y` accessor from Chart context */
24
- export let y = undefined;
25
- /** Interpolate path data using d3-interpolate-path. Works best without `draw` enabled */
26
- export let tweened = undefined;
27
- /** Draw path over time. Works best without `tweened` enabled */
28
- export let draw = undefined;
29
- /**
30
- * Curve of spline drawn. Imported via d3-shape.
31
- *
32
- * @example
33
- * import { curveNatural } from 'd3-shape';
34
- * <Spline curve={curveNatrual} />
35
- *
36
- * @type {CurveFactory | CurveFactoryLineOnly | undefined}
37
- */
38
- export let curve = undefined;
39
- export let defined = undefined;
40
- function getScaleValue(data, scale, accessor) {
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
- value = max(value);
75
+ value = max(value);
44
76
  }
77
+
45
78
  if (scale.domain().length) {
46
- // If scale is defined with domain, map value
47
- return scale(value);
48
- }
49
- else {
50
- // Use raw value
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
- const xAccessor = x ? accessor(x) : $contextX;
55
- const yAccessor = y ? accessor(y) : $contextY;
56
- $: xOffset = isScaleBand($xScale) ? $xScale.bandwidth() / 2 : 0;
57
- $: yOffset = isScaleBand($yScale) ? $yScale.bandwidth() / 2 : 0;
58
- let d = '';
59
- // @ts-expect-error
60
- $: tweenedOptions = tweened ? { interpolate: interpolatePath, ...tweened } : false;
61
- $: tweened_d = motionStore('', { tweened: tweenedOptions });
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
- ? lineRadial()
65
- .angle((d) => getScaleValue(d, $xScale, xAccessor))
66
- .radius((d) => getScaleValue(d, $yScale, yAccessor))
67
- : d3Line()
68
- .x((d) => getScaleValue(d, $xScale, xAccessor) + xOffset)
69
- .y((d) => getScaleValue(d, $yScale, yAccessor) + yOffset);
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
- if (curve)
72
- path.curve(curve);
107
+
108
+ if (curve) path.curve(curve);
109
+
73
110
  d = pathData ?? path(data ?? $contextData) ?? '';
74
111
  tweened_d.set(d);
75
- }
76
- $: drawTransition = draw ? _drawTransition : () => ({});
77
- let key = Symbol();
78
- $: if (draw) {
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
- let pathEl = undefined;
84
- const startPoint = writable(undefined);
85
- $: endPoint = motionStore(undefined, {
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
- duration: (typeof draw === 'object' && draw.duration) || 800,
89
- easing: (typeof draw === 'object' && draw.easing) || cubicInOut,
90
- interpolate(a, b) {
91
- return (t) => {
92
- const totalLength = pathEl?.getTotalLength() ?? 0;
93
- const point = pathEl?.getPointAtLength(totalLength * t);
94
- return point;
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
- : false,
99
- });
100
- $: {
138
+ : false,
139
+ });
140
+
141
+ $: {
101
142
  if ($$slots.start || $$slots.end) {
102
- // Wait for path data to update DOM, then update
103
- d;
104
- tick().then(() => {
105
- if (pathEl) {
106
- startPoint.set(pathEl.getPointAtLength(0));
107
- const totalLength = pathEl.getTotalLength();
108
- endPoint.set(pathEl.getPointAtLength(totalLength));
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
  };