layerchart 0.12.1 → 0.13.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.
Files changed (39) hide show
  1. package/components/Arc.svelte +8 -1
  2. package/components/Arc.svelte.d.ts +2 -0
  3. package/components/Area.svelte +3 -0
  4. package/components/Area.svelte.d.ts +4 -0
  5. package/components/AreaStack.svelte +3 -3
  6. package/components/Baseline.svelte +11 -10
  7. package/components/Baseline.svelte.d.ts +1 -0
  8. package/components/Chart.svelte +9 -1
  9. package/components/Chart.svelte.d.ts +3 -0
  10. package/components/Circle.svelte +9 -1
  11. package/components/Circle.svelte.d.ts +4 -0
  12. package/components/CircleClipPath.svelte +1 -1
  13. package/components/CircleClipPath.svelte.d.ts +2 -0
  14. package/components/Group.svelte +1 -1
  15. package/components/Group.svelte.d.ts +2 -0
  16. package/components/HighlightLine.svelte +78 -60
  17. package/components/HighlightLine.svelte.d.ts +5 -2
  18. package/components/HighlightRect.svelte +50 -45
  19. package/components/HighlightRect.svelte.d.ts +0 -1
  20. package/components/Line.svelte +10 -1
  21. package/components/Line.svelte.d.ts +4 -0
  22. package/components/Path.svelte +10 -1
  23. package/components/Path.svelte.d.ts +4 -0
  24. package/components/Pie.svelte +6 -0
  25. package/components/Pie.svelte.d.ts +4 -0
  26. package/components/RectClipPath.svelte +1 -1
  27. package/components/RectClipPath.svelte.d.ts +2 -0
  28. package/components/Sankey.svelte.d.ts +1 -1
  29. package/components/Tooltip.svelte +39 -343
  30. package/components/Tooltip.svelte.d.ts +2 -13
  31. package/components/TooltipContext.svelte +351 -0
  32. package/components/TooltipContext.svelte.d.ts +46 -0
  33. package/components/TooltipItem.svelte +9 -5
  34. package/components/TooltipItem.svelte.d.ts +1 -0
  35. package/components/index.d.ts +1 -1
  36. package/components/index.js +1 -1
  37. package/package.json +26 -26
  38. package/components/TooltipContainer.svelte +0 -18
  39. package/components/TooltipContainer.svelte.d.ts +0 -19
@@ -110,6 +110,13 @@ $: yOffset = -Math.cos(angle) * offset;
110
110
  <path d={trackArc()} class="track" bind:this={trackArcEl} {...track} />
111
111
  {/if}
112
112
 
113
- <path d={arc()} transform="translate({xOffset}, {yOffset})" {...$$restProps} on:click />
113
+ <path
114
+ d={arc()}
115
+ transform="translate({xOffset}, {yOffset})"
116
+ {...$$restProps}
117
+ on:click
118
+ on:mousemove
119
+ on:mouseleave
120
+ />
114
121
 
115
122
  <slot value={$tweened_value} centroid={trackArcCentroid} {boundingBox} />
@@ -19,6 +19,8 @@ declare const __propDef: {
19
19
  };
20
20
  events: {
21
21
  click: MouseEvent;
22
+ mousemove: MouseEvent;
23
+ mouseleave: MouseEvent;
22
24
  } & {
23
25
  [evt: string]: CustomEvent<any>;
24
26
  };
@@ -45,4 +45,7 @@ $: {
45
45
  fill={color}
46
46
  fill-opacity={opacity}
47
47
  {...$$restProps}
48
+ on:click
49
+ on:mousemove
50
+ on:mouseleave
48
51
  />
@@ -19,6 +19,10 @@ declare const __propDef: {
19
19
  line?: boolean | any;
20
20
  };
21
21
  events: {
22
+ click: MouseEvent;
23
+ mousemove: MouseEvent;
24
+ mouseleave: MouseEvent;
25
+ } & {
22
26
  [evt: string]: CustomEvent<any>;
23
27
  };
24
28
  slots: {};
@@ -1,7 +1,7 @@
1
1
  <script>import { getContext } from 'svelte';
2
2
  import Area from './Area.svelte';
3
3
  import Path from './Path.svelte';
4
- const { data, yScale, zGet } = getContext('LayerCake');
4
+ const { data, yScale, rGet } = getContext('LayerCake');
5
5
  export let curve = undefined;
6
6
  export let defined = undefined;
7
7
  export let opacity = 0.3;
@@ -17,7 +17,7 @@ $: lineData = [...$data].reverse();
17
17
  <Path
18
18
  data={seriesData}
19
19
  y={(d) => $yScale(d[1])}
20
- color={$zGet(seriesData)}
20
+ color={$rGet(seriesData)}
21
21
  {curve}
22
22
  {defined}
23
23
  {tweened}
@@ -33,7 +33,7 @@ $: lineData = [...$data].reverse();
33
33
  data={seriesData}
34
34
  y0={(d) => $yScale(d[0])}
35
35
  y1={(d) => $yScale(d[1])}
36
- color={$zGet(seriesData)}
36
+ color={$rGet(seriesData)}
37
37
  {curve}
38
38
  {defined}
39
39
  {opacity}
@@ -1,5 +1,6 @@
1
- <script>import { getContext } from 'svelte';
2
- import { min, max } from 'd3-array';
1
+ <script>import { min, max } from 'd3-array';
2
+ import { getContext } from 'svelte';
3
+ import { cls } from 'svelte-ux/utils/styles';
3
4
  import { isScaleBand } from '../utils/scales';
4
5
  const { xRange, yScale, yRange } = getContext('LayerCake');
5
6
  export let x = false;
@@ -13,17 +14,17 @@ export let y = false;
13
14
  x2={max($xRange) || 0}
14
15
  y1={isScaleBand($yScale) ? max($yRange) : $yScale(0) || 0}
15
16
  y2={isScaleBand($yScale) ? max($yRange) : $yScale(0) || 0}
16
- class="baseline"
17
+ class={cls('stroke-gray-400', $$props.class)}
17
18
  />
18
19
  {/if}
19
20
 
20
21
  {#if y}
21
- <line x1={0} x2={0} y1={min($yRange) || 0} y2={max($yRange) || 0} class="baseline" />
22
+ <line
23
+ x1={0}
24
+ x2={0}
25
+ y1={min($yRange) || 0}
26
+ y2={max($yRange) || 0}
27
+ class={cls('stroke-gray-400', $$props.class)}
28
+ />
22
29
  {/if}
23
30
  </g>
24
-
25
- <style>
26
- .baseline {
27
- stroke: #777;
28
- }
29
- </style>
@@ -1,6 +1,7 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
2
  declare const __propDef: {
3
3
  props: {
4
+ [x: string]: any;
4
5
  x?: boolean;
5
6
  y?: boolean;
6
7
  };
@@ -10,6 +10,7 @@ export const Html = _Html;
10
10
  <script>import { max, min } from 'd3-array';
11
11
  import { get } from 'lodash-es';
12
12
  import { isScaleBand } from '../utils/scales';
13
+ import TooltipContext from './TooltipContext.svelte';
13
14
  /**
14
15
  * Resolve a value from data based on the accessor type
15
16
  */
@@ -55,6 +56,7 @@ $: if (yBaseline != null) {
55
56
  * see: https://github.com/mhkeller/layercake/issues/83
56
57
  */
57
58
  $: yReverse = yScale ? !isScaleBand(yScale) : true;
59
+ export let tooltip = undefined;
58
60
  </script>
59
61
 
60
62
  <LayerCake
@@ -73,5 +75,11 @@ $: yReverse = yScale ? !isScaleBand(yScale) : true;
73
75
  let:width
74
76
  let:element
75
77
  >
76
- <slot {aspectRatio} {containerHeight} {containerWidth} {height} {width} {element} />
78
+ {#if tooltip}
79
+ <TooltipContext {...tooltip} let:tooltip>
80
+ <slot {aspectRatio} {containerHeight} {containerWidth} {height} {width} {element} {tooltip} />
81
+ </TooltipContext>
82
+ {:else}
83
+ <slot {aspectRatio} {containerHeight} {containerWidth} {height} {width} {element} />
84
+ {/if}
77
85
  </LayerCake>
@@ -2,6 +2,8 @@ import { SvelteComponentTyped } from "svelte";
2
2
  import { Svg as _Svg, Html as _Html } from 'layercake';
3
3
  export declare const Svg: typeof _Svg;
4
4
  export declare const Html: typeof _Html;
5
+ import type { ComponentProps } from 'svelte';
6
+ import TooltipContext from './TooltipContext.svelte';
5
7
  declare const __propDef: {
6
8
  props: {
7
9
  [x: string]: any;
@@ -11,6 +13,7 @@ declare const __propDef: {
11
13
  yScale?: Function;
12
14
  xBaseline?: number | null;
13
15
  yBaseline?: number | null;
16
+ tooltip?: ComponentProps<TooltipContext> | undefined;
14
17
  };
15
18
  events: {
16
19
  [evt: string]: CustomEvent<any>;
@@ -12,4 +12,12 @@ $: tweened_cy.set(cy);
12
12
  $: tweened_r.set(r);
13
13
  </script>
14
14
 
15
- <circle cx={$tweened_cx} cy={$tweened_cy} r={$tweened_r} {...$$restProps} />
15
+ <circle
16
+ cx={$tweened_cx}
17
+ cy={$tweened_cy}
18
+ r={$tweened_r}
19
+ {...$$restProps}
20
+ on:click
21
+ on:mousemove
22
+ on:mouseleave
23
+ />
@@ -10,6 +10,10 @@ declare const __propDef: {
10
10
  tweened?: boolean | Parameters<typeof tweenedStore>[1];
11
11
  };
12
12
  events: {
13
+ click: MouseEvent;
14
+ mousemove: MouseEvent;
15
+ mouseleave: MouseEvent;
16
+ } & {
13
17
  [evt: string]: CustomEvent<any>;
14
18
  };
15
19
  slots: {};
@@ -15,7 +15,7 @@ export let tweened = undefined;
15
15
  </ClipPath>
16
16
 
17
17
  {#if $$slots.default}
18
- <g style="clip-path: url(#{id})" on:click>
18
+ <g style="clip-path: url(#{id})" on:click on:mousemove on:mouseleave>
19
19
  <slot {id} />
20
20
  </g>
21
21
  {/if}
@@ -11,6 +11,8 @@ declare const __propDef: {
11
11
  };
12
12
  events: {
13
13
  click: MouseEvent;
14
+ mousemove: MouseEvent;
15
+ mouseleave: MouseEvent;
14
16
  } & {
15
17
  [evt: string]: CustomEvent<any>;
16
18
  };
@@ -28,6 +28,6 @@ $: if (center) {
28
28
  }
29
29
  </script>
30
30
 
31
- <g {transform} {...$$restProps} on:click>
31
+ <g {transform} {...$$restProps} on:click on:mousemove on:mouseleave>
32
32
  <slot />
33
33
  </g>
@@ -11,6 +11,8 @@ declare const __propDef: {
11
11
  };
12
12
  events: {
13
13
  click: MouseEvent;
14
+ mousemove: MouseEvent;
15
+ mouseleave: MouseEvent;
14
16
  } & {
15
17
  [evt: string]: CustomEvent<any>;
16
18
  };
@@ -1,23 +1,39 @@
1
1
  <script>import { getContext } from 'svelte';
2
- import { get } from 'svelte/store';
2
+ import 'svelte/store';
3
3
  import { max } from 'd3-array';
4
4
  import { isScaleBand } from '../utils/scales';
5
5
  import Circle from './Circle.svelte';
6
6
  import Line from './Line.svelte';
7
- const { xScale, xRange, xGet, yScale, yRange, yGet, zScale } = getContext('LayerCake');
8
- export let data;
7
+ import { tooltipContext } from './TooltipContext.svelte';
8
+ const { xScale, xRange, xGet, yScale, yRange, yGet, rGet, y, config } = getContext('LayerCake');
9
+ const tooltip = tooltipContext();
9
10
  export let color = undefined;
10
11
  export let axis = 'x';
11
12
  // TODO: Fix circle points being backwards for stack (see AreaStack)
12
- $: x = $xGet(data);
13
- $: xOffset = isScaleBand($xScale) ? $xScale.bandwidth() / 2 : 0;
14
- $: y = $yGet(data);
15
- $: yOffset = isScaleBand($yScale) ? $yScale.bandwidth() / 2 : 0;
16
- function getColor(index) {
17
- return color ?? get(zScale)(index) ?? 'var(--color-blue-500)';
13
+ function getColor(item, index = undefined) {
14
+ if (color) {
15
+ if (typeof color === 'function') {
16
+ return color({ value: $y(item), item, index });
17
+ }
18
+ else {
19
+ return color;
20
+ }
21
+ }
22
+ else if ($config.r) {
23
+ return $rGet(item);
24
+ }
25
+ else {
26
+ return 'var(--color-blue-500)';
27
+ }
18
28
  }
19
29
  let lines = [];
20
- $: {
30
+ let points = [];
31
+ $: if ($tooltip.data) {
32
+ let x = $xGet($tooltip.data);
33
+ let xOffset = isScaleBand($xScale) ? $xScale.bandwidth() / 2 : 0;
34
+ let y = $yGet($tooltip.data);
35
+ let yOffset = isScaleBand($yScale) ? $yScale.bandwidth() / 2 : 0;
36
+ // Reset lines
21
37
  lines = [];
22
38
  if (axis === 'x' || axis === 'both') {
23
39
  if (Array.isArray(x)) {
@@ -69,58 +85,60 @@ $: {
69
85
  ];
70
86
  }
71
87
  }
72
- }
73
- let points = [];
74
- $: if (Array.isArray(x)) {
75
- // `x` accessor with multiple properties (ex. `x={['start', 'end']})`)
76
- points = x.map((xItem, i) => ({
77
- x: xItem + xOffset,
78
- y: $yGet(data) + yOffset,
79
- color: getColor(i)
80
- }));
81
- }
82
- else if (Array.isArray(data)) {
83
- // Stack series
84
- points = data.map((yValue, i) => ({
85
- x: x + xOffset,
86
- y: $yScale(yValue) + yOffset,
87
- color: getColor(i)
88
- }));
89
- }
90
- else {
91
- points = [
92
- {
88
+ if (Array.isArray(x)) {
89
+ // `x` accessor with multiple properties (ex. `x={['start', 'end']})`)
90
+ points = x.map((xItem, i) => ({
91
+ x: xItem + xOffset,
92
+ y: $yGet($tooltip.data) + yOffset,
93
+ color: getColor($tooltip.data) // TODO: improve
94
+ }));
95
+ }
96
+ else if (Array.isArray($tooltip.data)) {
97
+ // Stack series
98
+ points = $tooltip.data.map((yValue, i) => ({
93
99
  x: x + xOffset,
94
- y: $yGet(data) + yOffset,
95
- color: getColor(0)
96
- }
97
- ];
100
+ y: $yScale(yValue) + yOffset,
101
+ color: getColor($tooltip.data) // TODO: improve
102
+ }));
103
+ }
104
+ else {
105
+ points = [
106
+ {
107
+ x: x + xOffset,
108
+ y: $yGet($tooltip.data) + yOffset,
109
+ // color: $rGet($tooltip.data) //getColor($tooltip.data)
110
+ color: getColor($tooltip.data)
111
+ }
112
+ ];
113
+ }
98
114
  }
99
115
  </script>
100
116
 
101
- {#each lines as line}
102
- <Line
103
- spring
104
- x1={line.x1}
105
- y1={line.y1}
106
- x2={line.x2}
107
- y2={line.y2}
108
- stroke="rgba(0,0,0,.5)"
109
- stroke-width={2}
110
- style="pointerEvents: none"
111
- stroke-dasharray="2,2"
112
- />
113
- {/each}
117
+ {#if $tooltip.data}
118
+ {#each lines as line}
119
+ <Line
120
+ spring
121
+ x1={line.x1}
122
+ y1={line.y1}
123
+ x2={line.x2}
124
+ y2={line.y2}
125
+ stroke="rgba(0,0,0,.5)"
126
+ stroke-width={2}
127
+ style="pointerEvents: none"
128
+ stroke-dasharray="2,2"
129
+ />
130
+ {/each}
114
131
 
115
- {#each points as point}
116
- <Circle
117
- spring
118
- cx={point.x}
119
- cy={point.y}
120
- r={7}
121
- fill="rgba(255,255,255,.9)"
122
- stroke={point.color}
123
- stroke-width={2}
124
- />
125
- <Circle spring cx={point.x} cy={point.y} r={3} fill={point.color} />
126
- {/each}
132
+ {#each points as point}
133
+ <Circle
134
+ spring
135
+ cx={point.x}
136
+ cy={point.y}
137
+ r={7}
138
+ fill="rgba(255,255,255,.9)"
139
+ stroke={point.color}
140
+ stroke-width={2}
141
+ />
142
+ <Circle spring cx={point.x} cy={point.y} r={3} fill={point.color} />
143
+ {/each}
144
+ {/if}
@@ -1,8 +1,11 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
2
  declare const __propDef: {
3
3
  props: {
4
- data: any;
5
- color?: any;
4
+ color?: string | ((obj: {
5
+ value: any;
6
+ item: any;
7
+ index: number;
8
+ }) => string);
6
9
  axis?: 'x' | 'y' | 'both' | 'none';
7
10
  };
8
11
  events: {
@@ -2,11 +2,10 @@
2
2
  import { max, min } from 'd3-array';
3
3
  import { isScaleBand } from '../utils/scales';
4
4
  import Rect from './Rect.svelte';
5
+ import { tooltipContext } from './TooltipContext.svelte';
5
6
  const { flatData, x, xScale, xDomain, xRange, xGet, yScale, yDomain, yRange, yGet } = getContext('LayerCake');
6
- export let data;
7
+ const tooltip = tooltipContext();
7
8
  export let axis = isScaleBand($yScale) ? 'y' : 'x';
8
- $: xCoord = $xGet(data);
9
- $: yCoord = $yGet(data);
10
9
  let dimensions = {
11
10
  x: 0,
12
11
  y: 0,
@@ -14,53 +13,59 @@ let dimensions = {
14
13
  height: 0
15
14
  };
16
15
  $: {
17
- if (axis === 'x' || axis === 'both') {
18
- if (isScaleBand($xScale)) {
19
- dimensions.width = $xScale.step();
16
+ if ($tooltip.data) {
17
+ let xCoord = $xGet($tooltip.data);
18
+ let yCoord = $yGet($tooltip.data);
19
+ if (axis === 'x' || axis === 'both') {
20
+ if (isScaleBand($xScale)) {
21
+ dimensions.width = $xScale.step();
22
+ }
23
+ else if (Array.isArray(xCoord)) {
24
+ // `x` accessor with multiple properties (ex. `x={['start', 'end']})`)
25
+ // Use first/last values for width
26
+ dimensions.width = max(xCoord) - min(xCoord);
27
+ xCoord = min(xCoord); // Use left-most value for top left of rect
28
+ }
29
+ else {
30
+ // Find width to next data point
31
+ const index = $flatData.findIndex((d) => Number($x(d)) === Number($x($tooltip.data)));
32
+ const isLastPoint = index + 1 === $flatData.length;
33
+ const nextDataPoint = isLastPoint ? max($xDomain) : $x($flatData[index + 1]);
34
+ dimensions.width = ($xScale(nextDataPoint) ?? 0) - (xCoord ?? 0);
35
+ }
36
+ dimensions.x =
37
+ xCoord - (isScaleBand($xScale) ? ($xScale.padding() * $xScale.step()) / 2 : 0);
38
+ if (axis === 'x') {
39
+ dimensions.height = max($yRange);
40
+ }
20
41
  }
21
- else if (Array.isArray(xCoord)) {
22
- // `x` accessor with multiple properties (ex. `x={['start', 'end']})`)
23
- // Use first/last values for width
24
- dimensions.width = max(xCoord) - min(xCoord);
25
- xCoord = min(xCoord); // Use left-most value for top left of rect
26
- }
27
- else {
28
- // Find width to next data point
29
- const index = $flatData.findIndex((d) => Number($x(d)) === Number($x(data)));
30
- const isLastPoint = index + 1 === $flatData.length;
31
- const nextDataPoint = isLastPoint ? max($xDomain) : $x($flatData[index + 1]);
32
- dimensions.width = ($xScale(nextDataPoint) ?? 0) - (xCoord ?? 0);
33
- }
34
- dimensions.x = xCoord - (isScaleBand($xScale) ? ($xScale.padding() * $xScale.step()) / 2 : 0);
35
- if (axis === 'x') {
36
- dimensions.height = max($yRange);
37
- }
38
- }
39
- if (axis === 'y' || axis === 'both') {
40
- if (isScaleBand($yScale)) {
41
- dimensions.height = $yScale.step();
42
- }
43
- else if (Array.isArray(xCoord)) {
44
- // `y` accessor with multiple properties (ex. `y={['start', 'end']})`)
45
- // Use first/last values for width
46
- dimensions.height = max(yCoord) - min(yCoord);
47
- yCoord = min(yCoord); // Use left-most value for top left of rect
48
- }
49
- else {
50
- // Find width to next data point
51
- const index = $flatData.findIndex((d) => Number($x(d)) === Number($x(data)));
52
- const isLastPoint = index + 1 === $flatData.length;
53
- const nextDataPoint = isLastPoint ? max($yDomain) : $x($flatData[index + 1]);
54
- dimensions.height = ($yScale(nextDataPoint) ?? 0) - (yCoord ?? 0);
55
- }
56
- dimensions.y = yCoord - (isScaleBand($yScale) ? ($yScale.padding() * $yScale.step()) / 2 : 0);
57
- if (axis === 'y') {
58
- dimensions.width = max($xRange);
42
+ if (axis === 'y' || axis === 'both') {
43
+ if (isScaleBand($yScale)) {
44
+ dimensions.height = $yScale.step();
45
+ }
46
+ else if (Array.isArray(xCoord)) {
47
+ // `y` accessor with multiple properties (ex. `y={['start', 'end']})`)
48
+ // Use first/last values for width
49
+ dimensions.height = max(yCoord) - min(yCoord);
50
+ yCoord = min(yCoord); // Use left-most value for top left of rect
51
+ }
52
+ else {
53
+ // Find width to next data point
54
+ const index = $flatData.findIndex((d) => Number($x(d)) === Number($x($tooltip.data)));
55
+ const isLastPoint = index + 1 === $flatData.length;
56
+ const nextDataPoint = isLastPoint ? max($yDomain) : $x($flatData[index + 1]);
57
+ dimensions.height = ($yScale(nextDataPoint) ?? 0) - (yCoord ?? 0);
58
+ }
59
+ dimensions.y =
60
+ yCoord - (isScaleBand($yScale) ? ($yScale.padding() * $yScale.step()) / 2 : 0);
61
+ if (axis === 'y') {
62
+ dimensions.width = max($xRange);
63
+ }
59
64
  }
60
65
  }
61
66
  }
62
67
  </script>
63
68
 
64
- {#if Number.isFinite(dimensions.x)}
69
+ {#if $tooltip.data}
65
70
  <Rect spring {...dimensions} fill="rgba(0,0,0,.1)" on:click />
66
71
  {/if}
@@ -1,7 +1,6 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
2
  declare const __propDef: {
3
3
  props: {
4
- data: any;
5
4
  axis?: 'x' | 'y' | 'both';
6
5
  };
7
6
  events: {
@@ -15,4 +15,13 @@ $: tweened_x2.set(x2);
15
15
  $: tweened_y2.set(y2);
16
16
  </script>
17
17
 
18
- <line x1={$tweened_x1} y1={$tweened_y1} x2={$tweened_x2} y2={$tweened_y2} {...$$restProps} />
18
+ <line
19
+ x1={$tweened_x1}
20
+ y1={$tweened_y1}
21
+ x2={$tweened_x2}
22
+ y2={$tweened_y2}
23
+ {...$$restProps}
24
+ on:click
25
+ on:mousemove
26
+ on:mouseleave
27
+ />
@@ -11,6 +11,10 @@ declare const __propDef: {
11
11
  tweened?: boolean | Parameters<typeof tweenedStore>[1];
12
12
  };
13
13
  events: {
14
+ click: MouseEvent;
15
+ mousemove: MouseEvent;
16
+ mouseleave: MouseEvent;
17
+ } & {
14
18
  [evt: string]: CustomEvent<any>;
15
19
  };
16
20
  slots: {};
@@ -33,7 +33,16 @@ $: {
33
33
  }
34
34
  </script>
35
35
 
36
- <path class="path-line" d={$tweened_d} stroke={color} stroke-width={width} {...$$restProps} />
36
+ <path
37
+ class="path-line"
38
+ d={$tweened_d}
39
+ stroke={color}
40
+ stroke-width={width}
41
+ {...$$restProps}
42
+ on:click
43
+ on:mousemove
44
+ on:mouseleave
45
+ />
37
46
 
38
47
  <style>
39
48
  .path-line {
@@ -15,6 +15,10 @@ declare const __propDef: {
15
15
  width?: any;
16
16
  };
17
17
  events: {
18
+ click: MouseEvent;
19
+ mousemove: MouseEvent;
20
+ mouseleave: MouseEvent;
21
+ } & {
18
22
  [evt: string]: CustomEvent<any>;
19
23
  };
20
24
  slots: {};
@@ -47,6 +47,10 @@ export let tweened = undefined;
47
47
  * Offset all arcs from center
48
48
  */
49
49
  export let offset = 0;
50
+ /**
51
+ * Tooltip context to setup mouse events to show tooltip for related data
52
+ */
53
+ export let tooltip = undefined;
50
54
  const { data: contextData, x, y, xRange, rGet, config } = getContext('LayerCake');
51
55
  $: resolved_endAngle = endAngle ?? degreesToRadians($config.xRange ? max($xRange) : max(range));
52
56
  let tweened_endAngle = motionStore(0, { spring, tweened });
@@ -83,6 +87,8 @@ function getColor(item, index) {
83
87
  {cornerRadius}
84
88
  {offset}
85
89
  fill={getColor(arc.data, index)}
90
+ on:mousemove={(e) => tooltip?.show(e, arc.data)}
91
+ on:mouseleave={(e) => tooltip?.hide()}
86
92
  />
87
93
  {/each}
88
94
  </slot>
@@ -1,5 +1,6 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
2
  import type { spring as springStore, tweened as tweenedStore } from 'svelte/motion';
3
+ import type { TooltipContextValue } from './TooltipContext.svelte';
3
4
  declare const __propDef: {
4
5
  props: {
5
6
  data?: any;
@@ -34,6 +35,9 @@ declare const __propDef: {
34
35
  /**
35
36
  * Offset all arcs from center
36
37
  */ offset?: number;
38
+ /**
39
+ * Tooltip context to setup mouse events to show tooltip for related data
40
+ */ tooltip?: TooltipContextValue | undefined;
37
41
  };
38
42
  events: {
39
43
  [evt: string]: CustomEvent<any>;
@@ -16,7 +16,7 @@ export let tweened = undefined;
16
16
  </ClipPath>
17
17
 
18
18
  {#if $$slots.default}
19
- <g style="clip-path: url(#{id})" on:click>
19
+ <g style="clip-path: url(#{id})" on:click on:mousemove on:mouseleave>
20
20
  <slot {id} />
21
21
  </g>
22
22
  {/if}
@@ -12,6 +12,8 @@ declare const __propDef: {
12
12
  };
13
13
  events: {
14
14
  click: MouseEvent;
15
+ mousemove: MouseEvent;
16
+ mouseleave: MouseEvent;
15
17
  } & {
16
18
  [evt: string]: CustomEvent<any>;
17
19
  };
@@ -6,7 +6,7 @@ declare const __propDef: {
6
6
  nodeId?: (d: any) => any;
7
7
  /**
8
8
  * see: https://github.com/d3/d3-sankey#alignments
9
- */ nodeAlign?: "center" | "left" | "right" | "justify" | ((node: SankeyNode<any, any>, n: number) => number);
9
+ */ nodeAlign?: "left" | "right" | "center" | "justify" | ((node: SankeyNode<any, any>, n: number) => number);
10
10
  nodeWidth?: number;
11
11
  nodePadding?: number;
12
12
  nodeSort?: any;