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,37 +1,49 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
export let
|
|
14
|
-
export let
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
let
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
32
|
-
|
|
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>
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
export let
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
let
|
|
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
|
-
|
|
48
|
-
$:
|
|
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
|
-
|
|
93
|
+
axis = defaultAxis;
|
|
60
94
|
}
|
|
95
|
+
|
|
61
96
|
if (axis === 'x' || axis === 'both') {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
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
|
-
|
|
252
|
-
|
|
253
|
-
|
|
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
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
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
|
-
|
|
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}
|