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,37 +1,49 @@
1
- <script>import { tick } from 'svelte';
2
- import { chartContext } from './ChartContext.svelte';
3
- import { motionStore } from '../stores/motionStore.js';
4
- const { width, height } = chartContext();
5
- /**
6
- * Translate x
7
- */
8
- export let x = undefined;
9
- export let initialX = x;
10
- /**
11
- * Translate x
12
- */
13
- export let y = undefined;
14
- export let initialY = y;
15
- /**
16
- * Center within chart
17
- */
18
- export let center = false;
19
- /**
20
- * Prevent `touchmove` default, which can interfer with `pointermove` when used with `Tooltip`, for example
21
- */
22
- export let preventTouchMove = false;
23
- export let spring = undefined;
24
- export let tweened = undefined;
25
- let tweened_x = motionStore(initialX, { spring, tweened });
26
- let tweened_y = motionStore(initialY, { spring, tweened });
27
- $: tick().then(() => {
1
+ <script lang="ts">
2
+ import { tick } from 'svelte';
3
+ import type { spring as springStore, tweened as tweenedStore } from 'svelte/motion';
4
+
5
+ import { chartContext } from './ChartContext.svelte';
6
+ import { motionStore } from '../stores/motionStore.js';
7
+
8
+ const { width, height } = chartContext();
9
+
10
+ /**
11
+ * Translate x
12
+ */
13
+ export let x: number | undefined = undefined;
14
+ export let initialX = x;
15
+
16
+ /**
17
+ * Translate x
18
+ */
19
+ export let y: number | undefined = undefined;
20
+ export let initialY = y;
21
+
22
+ /**
23
+ * Center within chart
24
+ */
25
+ export let center: boolean | 'x' | 'y' = false;
26
+
27
+ /**
28
+ * Prevent `touchmove` default, which can interfer with `pointermove` when used with `Tooltip`, for example
29
+ */
30
+ export let preventTouchMove = false;
31
+
32
+ export let spring: boolean | Parameters<typeof springStore>[1] = undefined;
33
+ export let tweened: boolean | Parameters<typeof tweenedStore>[1] = undefined;
34
+
35
+ let tweened_x = motionStore(initialX, { spring, tweened });
36
+ let tweened_y = motionStore(initialY, { spring, tweened });
37
+
38
+ $: tick().then(() => {
28
39
  tweened_x.set(x ?? (center === 'x' || center === true ? $width / 2 : 0));
29
40
  tweened_y.set(y ?? (center === 'y' || center === true ? $height / 2 : 0));
30
- });
31
- let transform = undefined;
32
- $: if (center || x != null || y != null) {
41
+ });
42
+
43
+ let transform: string | undefined = undefined;
44
+ $: if (center || x != null || y != null) {
33
45
  transform = `translate(${$tweened_x ?? 0}, ${$tweened_y ?? 0})`;
34
- }
46
+ }
35
47
  </script>
36
48
 
37
49
  <!-- svelte-ignore a11y-no-static-element-interactions -->
@@ -1,272 +1,313 @@
1
- <script>import {} from 'svelte';
2
- import { max, min } from 'd3-array';
3
- import { pointRadial } from 'd3-shape';
4
- import { notNull } from '@layerstack/utils/typeGuards';
5
- import { cls } from '@layerstack/tailwind';
6
- import { chartContext } from './ChartContext.svelte';
7
- import Circle from './Circle.svelte';
8
- import Line from './Line.svelte';
9
- import Bar from './Bar.svelte';
10
- import Rect from './Rect.svelte';
11
- import { tooltipContext } from './tooltip/TooltipContext.svelte';
12
- import { isScaleBand } from '../utils/scales.js';
13
- import { accessor } from '../utils/common.js';
14
- const { data: contextData, flatData, x: xContext, xDomain, xScale, xRange, y: yContext, yDomain, yScale, yRange, cGet, config, radial, } = chartContext();
15
- const tooltip = tooltipContext();
16
- /** Highlight specific data (annotate), espect uses tooltip data */
17
- export let data = undefined;
18
- /**
19
- * Override `x` from context
20
- */
21
- export let x = $xContext;
22
- /**
23
- * Override `y` from context
24
- */
25
- export let y = $yContext;
26
- export let axis = undefined;
27
- /** Show points and pass props to Circles */
28
- export let points = false;
29
- /** Show lines and pass props to Lines */
30
- export let lines = false;
31
- /** Show area and pass props to Rect */
32
- export let area = false;
33
- /** Show bar and pass props to Rect */
34
- export let bar = false;
35
- /** Set to false to disable spring transitions */
36
- export let motion = true;
37
- const _x = accessor(x);
38
- const _y = accessor(y);
39
- let _points = [];
40
- let _lines = [];
41
- let _area = {
1
+ <script lang="ts">
2
+ import { type ComponentProps } from 'svelte';
3
+ import { max, min } from 'd3-array';
4
+ import { pointRadial, type Series, type SeriesPoint } from 'd3-shape';
5
+ import { notNull } from '@layerstack/utils/typeGuards';
6
+ import { cls } from '@layerstack/tailwind';
7
+
8
+ import { chartContext } from './ChartContext.svelte';
9
+ import Circle from './Circle.svelte';
10
+ import Line from './Line.svelte';
11
+ import Bar from './Bar.svelte';
12
+ import Rect from './Rect.svelte';
13
+ import { tooltipContext } from './tooltip/TooltipContext.svelte';
14
+
15
+ import { isScaleBand } from '../utils/scales.js';
16
+ import { accessor, type Accessor } from '../utils/common.js';
17
+
18
+ const {
19
+ data: contextData,
20
+ flatData,
21
+ x: xContext,
22
+ xDomain,
23
+ xScale,
24
+ xRange,
25
+ y: yContext,
26
+ yDomain,
27
+ yScale,
28
+ yRange,
29
+ cGet,
30
+ config,
31
+ radial,
32
+ } = chartContext();
33
+ const tooltip = tooltipContext();
34
+
35
+ /** Highlight specific data (annotate), espect uses tooltip data */
36
+ export let data: any = undefined;
37
+
38
+ /**
39
+ * Override `x` from context
40
+ */
41
+ export let x: Accessor = $xContext;
42
+
43
+ /**
44
+ * Override `y` from context
45
+ */
46
+ export let y: Accessor = $yContext;
47
+
48
+ export let axis: 'x' | 'y' | 'both' | 'none' | undefined = undefined;
49
+
50
+ /** Show points and pass props to Circles */
51
+ export let points: boolean | Partial<ComponentProps<Circle>> = false;
52
+
53
+ /** Show lines and pass props to Lines */
54
+ export let lines: boolean | Partial<ComponentProps<Line>> = false;
55
+
56
+ /** Show area and pass props to Rect */
57
+ export let area: boolean | Partial<ComponentProps<Rect>> = false;
58
+
59
+ /** Show bar and pass props to Rect */
60
+ export let bar: boolean | Partial<ComponentProps<Bar>> = false;
61
+
62
+ /** Set to false to disable spring transitions */
63
+ export let motion = true;
64
+
65
+ const _x = accessor(x);
66
+ const _y = accessor(y);
67
+
68
+ let _points: { x: number; y: number; fill: string }[] = [];
69
+ let _lines: { x1: number; y1: number; x2: number; y2: number }[] = [];
70
+ let _area = {
42
71
  x: 0,
43
72
  y: 0,
44
73
  width: 0,
45
74
  height: 0,
46
- };
47
- $: highlightData = data ?? $tooltip.data;
48
- $: if (highlightData) {
75
+ };
76
+
77
+ $: highlightData = data ?? $tooltip.data;
78
+
79
+ $: if (highlightData) {
49
80
  const xValue = _x(highlightData);
50
81
  const xCoord = Array.isArray(xValue) ? xValue.map((v) => $xScale(v)) : $xScale(xValue);
51
82
  const xOffset = isScaleBand($xScale) && !$radial ? $xScale.bandwidth() / 2 : 0;
83
+
52
84
  const yValue = _y(highlightData);
53
85
  const yCoord = Array.isArray(yValue) ? yValue.map((v) => $yScale(v)) : $yScale(yValue);
54
86
  const yOffset = isScaleBand($yScale) && !$radial ? $yScale.bandwidth() / 2 : 0;
87
+
55
88
  // Reset lines
56
89
  _lines = [];
90
+
57
91
  const defaultAxis = isScaleBand($yScale) ? 'y' : 'x';
58
92
  if (axis == null) {
59
- axis = defaultAxis;
93
+ axis = defaultAxis;
60
94
  }
95
+
61
96
  if (axis === 'x' || axis === 'both') {
62
- // x lines
63
- if (Array.isArray(xCoord)) {
64
- // `x` accessor with multiple properties (ex. `x={['start', 'end']})`)
65
- _lines = [
66
- ..._lines,
67
- ...xCoord.filter(notNull).map((xItem, i) => ({
68
- x1: xItem + xOffset,
69
- y1: min($yRange),
70
- x2: xItem + xOffset,
71
- y2: max($yRange),
72
- })),
73
- ];
74
- }
75
- else if (xCoord) {
76
- _lines = [
77
- ..._lines,
78
- {
79
- x1: xCoord + xOffset,
80
- y1: min($yRange),
81
- x2: xCoord + xOffset,
82
- y2: max($yRange),
83
- },
84
- ];
85
- }
86
- // x area
87
- if (Array.isArray(xCoord)) {
88
- // `x` accessor with multiple properties (ex. `x={['start', 'end']})`)
89
- _area.width = max(xCoord) - min(xCoord); // Use first/last values for width
90
- }
91
- else if (isScaleBand($xScale)) {
92
- _area.width = $xScale.step();
93
- }
94
- else {
95
- // Find width to next data point
96
- const index = $flatData.findIndex((d) => Number(_x(d)) === Number(_x(highlightData)));
97
- const isLastPoint = index + 1 === $flatData.length;
98
- const nextDataPoint = isLastPoint ? max($xDomain) : _x($flatData[index + 1]);
99
- _area.width = ($xScale(nextDataPoint) ?? 0) - (xCoord ?? 0);
100
- }
101
- // If array, use left-most value for top left of rect
102
- _area.x =
103
- (Array.isArray(xCoord) ? min(xCoord) : xCoord) -
104
- (isScaleBand($xScale) ? ($xScale.padding() * $xScale.step()) / 2 : 0);
105
- if (axis === 'x') {
106
- _area.height = max($yRange);
107
- }
97
+ // x lines
98
+ if (Array.isArray(xCoord)) {
99
+ // `x` accessor with multiple properties (ex. `x={['start', 'end']})`)
100
+ _lines = [
101
+ ..._lines,
102
+ ...xCoord.filter(notNull).map((xItem, i) => ({
103
+ x1: xItem + xOffset,
104
+ y1: min($yRange) as unknown as number,
105
+ x2: xItem + xOffset,
106
+ y2: max($yRange) as unknown as number,
107
+ })),
108
+ ];
109
+ } else if (xCoord) {
110
+ _lines = [
111
+ ..._lines,
112
+ {
113
+ x1: xCoord + xOffset,
114
+ y1: min($yRange) as unknown as number,
115
+ x2: xCoord + xOffset,
116
+ y2: max($yRange) as unknown as number,
117
+ },
118
+ ];
119
+ }
120
+
121
+ // x area
122
+ if (Array.isArray(xCoord)) {
123
+ // `x` accessor with multiple properties (ex. `x={['start', 'end']})`)
124
+ _area.width = max(xCoord) - min(xCoord); // Use first/last values for width
125
+ } else if (isScaleBand($xScale)) {
126
+ _area.width = $xScale.step();
127
+ } else {
128
+ // Find width to next data point
129
+ const index = $flatData.findIndex((d) => Number(_x(d)) === Number(_x(highlightData)));
130
+ const isLastPoint = index + 1 === $flatData.length;
131
+ const nextDataPoint = isLastPoint ? max($xDomain) : _x($flatData[index + 1]);
132
+ _area.width = ($xScale(nextDataPoint) ?? 0) - (xCoord ?? 0);
133
+ }
134
+
135
+ // If array, use left-most value for top left of rect
136
+ _area.x =
137
+ (Array.isArray(xCoord) ? min(xCoord) : xCoord) -
138
+ (isScaleBand($xScale) ? ($xScale.padding() * $xScale.step()) / 2 : 0);
139
+
140
+ if (axis === 'x') {
141
+ _area.height = max($yRange) as unknown as number;
142
+ }
108
143
  }
144
+
109
145
  if (axis === 'y' || axis === 'both') {
110
- // y lines
111
- if (Array.isArray(yCoord)) {
112
- // `y` accessor with multiple properties (ex. `y={['start', 'end']})`)
113
- _lines = [
114
- ..._lines,
115
- ...yCoord.filter(notNull).map((yItem, i) => ({
116
- x1: min($xRange),
117
- y1: yItem + yOffset,
118
- x2: max($xRange),
119
- y2: yItem + yOffset,
120
- })),
121
- ];
122
- }
123
- else if (yCoord) {
124
- _lines = [
125
- ..._lines,
126
- {
127
- x1: min($xRange),
128
- y1: yCoord + yOffset,
129
- x2: max($xRange),
130
- y2: yCoord + yOffset,
131
- },
132
- ];
133
- }
134
- // y area
135
- if (Array.isArray(yCoord)) {
136
- // `y` accessor with multiple properties (ex. `y={['start', 'end']})`)
137
- _area.height = max(yCoord) - min(yCoord); // Use first/last values for width
138
- }
139
- else if (isScaleBand($yScale)) {
140
- _area.height = $yScale.step();
141
- }
142
- else {
143
- // Find width to next data point
144
- const index = $flatData.findIndex((d) => Number(_x(d)) === Number(_x(highlightData)));
145
- const isLastPoint = index + 1 === $flatData.length;
146
- const nextDataPoint = isLastPoint ? max($yDomain) : _x($flatData[index + 1]);
147
- _area.height = ($yScale(nextDataPoint) ?? 0) - (yCoord ?? 0);
148
- }
149
- // If array, use left-most value for top left of rect
150
- _area.y =
151
- (Array.isArray(yCoord) ? min(yCoord) : yCoord) -
152
- (isScaleBand($yScale) ? ($yScale.padding() * $yScale.step()) / 2 : 0);
153
- if (axis === 'y') {
154
- _area.width = max($xRange);
155
- }
146
+ // y lines
147
+ if (Array.isArray(yCoord)) {
148
+ // `y` accessor with multiple properties (ex. `y={['start', 'end']})`)
149
+ _lines = [
150
+ ..._lines,
151
+ ...yCoord.filter(notNull).map((yItem, i) => ({
152
+ x1: min($xRange) as unknown as number,
153
+ y1: yItem + yOffset,
154
+ x2: max($xRange) as unknown as number,
155
+ y2: yItem + yOffset,
156
+ })),
157
+ ];
158
+ } else if (yCoord) {
159
+ _lines = [
160
+ ..._lines,
161
+ {
162
+ x1: min($xRange) as unknown as number,
163
+ y1: yCoord + yOffset,
164
+ x2: max($xRange) as unknown as number,
165
+ y2: yCoord + yOffset,
166
+ },
167
+ ];
168
+ }
169
+
170
+ // y area
171
+ if (Array.isArray(yCoord)) {
172
+ // `y` accessor with multiple properties (ex. `y={['start', 'end']})`)
173
+ _area.height = max(yCoord) - min(yCoord); // Use first/last values for width
174
+ } else if (isScaleBand($yScale)) {
175
+ _area.height = $yScale.step();
176
+ } else {
177
+ // Find width to next data point
178
+ const index = $flatData.findIndex((d) => Number(_x(d)) === Number(_x(highlightData)));
179
+ const isLastPoint = index + 1 === $flatData.length;
180
+ const nextDataPoint = isLastPoint ? max($yDomain) : _x($flatData[index + 1]);
181
+ _area.height = ($yScale(nextDataPoint) ?? 0) - (yCoord ?? 0);
182
+ }
183
+
184
+ // If array, use left-most value for top left of rect
185
+ _area.y =
186
+ (Array.isArray(yCoord) ? min(yCoord) : yCoord) -
187
+ (isScaleBand($yScale) ? ($yScale.padding() * $yScale.step()) / 2 : 0);
188
+
189
+ if (axis === 'y') {
190
+ _area.width = max($xRange) as unknown as number;
191
+ }
156
192
  }
193
+
157
194
  // points
158
195
  if (Array.isArray(xCoord)) {
159
- // `x` accessor with multiple properties (ex. `x={['start', 'end']}` or `x={[0, 1]}`)
160
- if (Array.isArray(highlightData)) {
161
- // Stack series (ex. `y={[['apples', 'bananas', 'oranges']]})`)
162
- // `highlightData` is a single stack layer/point, which is an 2 element array with an extra `data` property `[number, number, data: any]`.
163
- const highlightSeriesPoint = highlightData;
164
- // Ignore non-array data such as hierarchy and graph (make Typescript happy)
165
- if (Array.isArray($contextData)) {
166
- // For each series, find the related data point
167
- const seriesPointsData = $contextData
168
- .map((series) => {
169
- return {
170
- series,
171
- point: series.find((d) => _y(d) === _y(highlightSeriesPoint)),
172
- };
173
- })
174
- .filter((d) => d.point); // remove if no point found (ex. Histogram);
175
- _points = seriesPointsData.map((seriesPoint, i) => {
176
- return {
177
- x: $xScale(seriesPoint.point[1]) + xOffset,
178
- y: yCoord + yOffset,
179
- fill: $config.c ? $cGet(seriesPoint.series) : null,
180
- };
181
- });
182
- }
183
- }
184
- else {
185
- // Multi series / etc (ex. `y={['apples', 'bananas', 'oranges']}`)
186
- _points = xCoord.filter(notNull).map((xItem, i) => {
187
- const $key = $config.x[i];
188
- return {
189
- x: xItem + xOffset,
190
- y: yCoord + yOffset,
191
- // TODO: is there a better way to expose the series key/value?
192
- fill: $config.c ? $cGet({ ...highlightData, $key }) : null,
193
- };
194
- });
195
- }
196
- }
197
- else if (Array.isArray(yCoord)) {
198
- // `y` accessor with multiple properties (ex. `y={['apples', 'bananas', 'oranges']}` or `y={[0, 1]})
199
- if (Array.isArray(highlightData)) {
200
- // Stack series (ex. `y={[['apples', 'bananas', 'oranges']]})`)
201
- // `highlightData` is a single stack layer/point, which is an 2 element array with an extra `data` property `[number, number, data: any]`.
202
- const highlightSeriesPoint = highlightData;
203
- // Ignore non-array data such as hierarchy and graph (make Typescript happy)
204
- if (Array.isArray($contextData)) {
205
- // For each series, find the related data point
206
- const seriesPointsData = $contextData
207
- .map((series) => {
208
- return {
209
- series,
210
- point: series.find((d) => _x(d) === _x(highlightSeriesPoint)),
211
- };
212
- })
213
- .filter((d) => d.point); // remove if no point found (ex. Histogram)
214
- _points = seriesPointsData.map((seriesPoint, i) => ({
215
- x: xCoord + xOffset,
216
- y: $yScale(seriesPoint.point[1]) + yOffset,
217
- fill: $config.c ? $cGet(seriesPoint.series) : null,
218
- }));
219
- }
220
- }
221
- else {
222
- // Multi series / etc (ex. `y={['apples', 'bananas', 'oranges']}`)
223
- _points = yCoord.filter(notNull).map((yItem, i) => {
224
- const $key = $config.y[i];
225
- return {
226
- x: xCoord + xOffset,
227
- y: yItem + yOffset,
228
- // TODO: is there a better way to expose the series key/value?
229
- fill: $config.c ? $cGet({ ...highlightData, $key }) : null,
230
- };
231
- });
232
- }
233
- }
234
- else if (xCoord != null && yCoord != null) {
235
- _points = [
236
- {
237
- x: xCoord + xOffset,
238
- y: yCoord + yOffset,
239
- fill: $config.c ? $cGet(highlightData) : null,
240
- },
241
- ];
242
- }
243
- else {
244
- _points = [];
245
- }
246
- if ($radial) {
247
- // Translate x/y to angle/radius
248
- _points = _points.map((p) => {
249
- const [x, y] = pointRadial(p.x, p.y);
196
+ // `x` accessor with multiple properties (ex. `x={['start', 'end']}` or `x={[0, 1]}`)
197
+
198
+ if (Array.isArray(highlightData)) {
199
+ // Stack series (ex. `y={[['apples', 'bananas', 'oranges']]})`)
200
+ // `highlightData` is a single stack layer/point, which is an 2 element array with an extra `data` property `[number, number, data: any]`.
201
+ const highlightSeriesPoint = highlightData as SeriesPoint<any>;
202
+
203
+ // Ignore non-array data such as hierarchy and graph (make Typescript happy)
204
+ if (Array.isArray($contextData)) {
205
+ // For each series, find the related data point
206
+ const seriesPointsData = $contextData
207
+ .map((series: Series<any, any>) => {
208
+ return {
209
+ series,
210
+ point: series.find((d) => _y(d) === _y(highlightSeriesPoint))!,
211
+ };
212
+ })
213
+ .filter((d) => d.point); // remove if no point found (ex. Histogram);
214
+
215
+ _points = seriesPointsData.map((seriesPoint, i) => {
250
216
  return {
251
- ...p,
252
- x,
253
- y,
217
+ x: $xScale(seriesPoint.point[1]) + xOffset,
218
+ y: yCoord + yOffset,
219
+ fill: $config.c ? $cGet(seriesPoint.series) : null,
254
220
  };
221
+ });
222
+ }
223
+ } else {
224
+ // Multi series / etc (ex. `y={['apples', 'bananas', 'oranges']}`)
225
+ _points = xCoord.filter(notNull).map((xItem, i) => {
226
+ const $key = $config.x[i];
227
+ return {
228
+ x: xItem + xOffset,
229
+ y: yCoord + yOffset,
230
+ // TODO: is there a better way to expose the series key/value?
231
+ fill: $config.c ? $cGet({ ...highlightData, $key }) : null,
232
+ };
255
233
  });
256
- _lines = _lines.map((l) => {
257
- const [x1, y1] = pointRadial(l.x1, l.y1);
258
- const [x2, y2] = pointRadial(l.x2, l.y2);
259
- return {
260
- ...l,
261
- x1,
262
- y1,
263
- x2,
264
- y2,
265
- };
234
+ }
235
+ } else if (Array.isArray(yCoord)) {
236
+ // `y` accessor with multiple properties (ex. `y={['apples', 'bananas', 'oranges']}` or `y={[0, 1]})
237
+
238
+ if (Array.isArray(highlightData)) {
239
+ // Stack series (ex. `y={[['apples', 'bananas', 'oranges']]})`)
240
+ // `highlightData` is a single stack layer/point, which is an 2 element array with an extra `data` property `[number, number, data: any]`.
241
+ const highlightSeriesPoint = highlightData as SeriesPoint<any>;
242
+
243
+ // Ignore non-array data such as hierarchy and graph (make Typescript happy)
244
+ if (Array.isArray($contextData)) {
245
+ // For each series, find the related data point
246
+ const seriesPointsData = $contextData
247
+ .map((series: Series<any, any>) => {
248
+ return {
249
+ series,
250
+ point: series.find((d) => _x(d) === _x(highlightSeriesPoint))!,
251
+ };
252
+ })
253
+ .filter((d) => d.point); // remove if no point found (ex. Histogram)
254
+
255
+ _points = seriesPointsData.map((seriesPoint, i) => ({
256
+ x: xCoord + xOffset,
257
+ y: $yScale(seriesPoint.point[1]) + yOffset,
258
+ fill: $config.c ? $cGet(seriesPoint.series) : null,
259
+ }));
260
+ }
261
+ } else {
262
+ // Multi series / etc (ex. `y={['apples', 'bananas', 'oranges']}`)
263
+ _points = yCoord.filter(notNull).map((yItem, i) => {
264
+ const $key = $config.y[i];
265
+ return {
266
+ x: xCoord + xOffset,
267
+ y: yItem + yOffset,
268
+ // TODO: is there a better way to expose the series key/value?
269
+ fill: $config.c ? $cGet({ ...highlightData, $key }) : null,
270
+ };
266
271
  });
267
- // TODO: How to handle _areas
272
+ }
273
+ } else if (xCoord != null && yCoord != null) {
274
+ _points = [
275
+ {
276
+ x: xCoord + xOffset,
277
+ y: yCoord + yOffset,
278
+ fill: $config.c ? $cGet(highlightData) : null,
279
+ },
280
+ ];
281
+ } else {
282
+ _points = [];
283
+ }
284
+
285
+ if ($radial) {
286
+ // Translate x/y to angle/radius
287
+ _points = _points.map((p) => {
288
+ const [x, y] = pointRadial(p.x, p.y);
289
+ return {
290
+ ...p,
291
+ x,
292
+ y,
293
+ };
294
+ });
295
+
296
+ _lines = _lines.map((l) => {
297
+ const [x1, y1] = pointRadial(l.x1, l.y1);
298
+ const [x2, y2] = pointRadial(l.x2, l.y2);
299
+ return {
300
+ ...l,
301
+ x1,
302
+ y1,
303
+ x2,
304
+ y2,
305
+ };
306
+ });
307
+
308
+ // TODO: How to handle _areas
268
309
  }
269
- }
310
+ }
270
311
  </script>
271
312
 
272
313
  {#if highlightData}