layerchart 0.43.2 → 0.43.3
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/Highlight.svelte +63 -21
- package/package.json +1 -1
|
@@ -142,31 +142,73 @@ $: if (highlightData) {
|
|
|
142
142
|
}
|
|
143
143
|
// points
|
|
144
144
|
if (Array.isArray(xCoord)) {
|
|
145
|
-
// `x` accessor with multiple properties (ex. `x={['start', 'end']}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
145
|
+
// `x` accessor with multiple properties (ex. `x={['start', 'end']}` or `x={[0, 1]}`)
|
|
146
|
+
if (Array.isArray(highlightData)) {
|
|
147
|
+
// Stack series (ex. `y={[['apples', 'bananas', 'oranges']]})`)
|
|
148
|
+
// `highlightData` is a single stack layer/point, which is an 2 element array with an extra `data` property `[number, number, data: any]`.
|
|
149
|
+
const highlightSeriesPoint = highlightData;
|
|
150
|
+
// Ignore non-array data such as hierarchy and graph (make Typescript happy)
|
|
151
|
+
if (Array.isArray($contextData)) {
|
|
152
|
+
// For each series, find the related data point
|
|
153
|
+
const seriesPointsData = $contextData.map((series) => {
|
|
154
|
+
return {
|
|
155
|
+
series,
|
|
156
|
+
point: series.find((d) => $y(d) === $y(highlightSeriesPoint)),
|
|
157
|
+
};
|
|
158
|
+
});
|
|
159
|
+
_points = seriesPointsData.map((seriesPoint, i) => ({
|
|
160
|
+
x: $xScale(seriesPoint.point[1]) + xOffset,
|
|
161
|
+
y: yCoord + yOffset,
|
|
162
|
+
fill: $config.r ? $rGet(seriesPoint.series) : null,
|
|
163
|
+
}));
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
// Multi series / etc (ex. `y={['apples', 'bananas', 'oranges']}`)
|
|
168
|
+
_points = xCoord.filter(notNull).map((xItem, i) => {
|
|
169
|
+
const $key = $config.x[i];
|
|
170
|
+
return {
|
|
171
|
+
x: xItem + xOffset,
|
|
172
|
+
y: $xGet(highlightData) + yOffset,
|
|
173
|
+
// TODO: is there a better way to expose the series key/value?
|
|
174
|
+
fill: $config.r ? $rGet({ ...highlightData, $key }) : null,
|
|
175
|
+
};
|
|
176
|
+
});
|
|
177
|
+
}
|
|
151
178
|
}
|
|
152
|
-
else if (Array.isArray(
|
|
153
|
-
//
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
//
|
|
159
|
-
|
|
179
|
+
else if (Array.isArray(yCoord)) {
|
|
180
|
+
// `y` accessor with multiple properties (ex. `y={['apples', 'bananas', 'oranges']}` or `y={[0, 1]})
|
|
181
|
+
if (Array.isArray(highlightData)) {
|
|
182
|
+
// Stack series (ex. `y={[['apples', 'bananas', 'oranges']]})`)
|
|
183
|
+
// `highlightData` is a single stack layer/point, which is an 2 element array with an extra `data` property `[number, number, data: any]`.
|
|
184
|
+
const highlightSeriesPoint = highlightData;
|
|
185
|
+
// Ignore non-array data such as hierarchy and graph (make Typescript happy)
|
|
186
|
+
if (Array.isArray($contextData)) {
|
|
187
|
+
// For each series, find the related data point
|
|
188
|
+
const seriesPointsData = $contextData.map((series) => {
|
|
189
|
+
return {
|
|
190
|
+
series,
|
|
191
|
+
point: series.find((d) => $x(d) === $x(highlightSeriesPoint)),
|
|
192
|
+
};
|
|
193
|
+
});
|
|
194
|
+
_points = seriesPointsData.map((seriesPoint, i) => ({
|
|
195
|
+
x: xCoord + xOffset,
|
|
196
|
+
y: $yScale(seriesPoint.point[1]) + yOffset,
|
|
197
|
+
fill: $config.r ? $rGet(seriesPoint.series) : null,
|
|
198
|
+
}));
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
// Multi series / etc (ex. `y={['apples', 'bananas', 'oranges']}`)
|
|
203
|
+
_points = yCoord.filter(notNull).map((yItem, i) => {
|
|
204
|
+
const $key = $config.y[i];
|
|
160
205
|
return {
|
|
161
|
-
|
|
162
|
-
|
|
206
|
+
x: $xGet(highlightData) + xOffset,
|
|
207
|
+
y: yItem + yOffset,
|
|
208
|
+
// TODO: is there a better way to expose the series key/value?
|
|
209
|
+
fill: $config.r ? $rGet({ ...highlightData, $key }) : null,
|
|
163
210
|
};
|
|
164
211
|
});
|
|
165
|
-
_points = seriesPointsData.map((seriesPoint, i) => ({
|
|
166
|
-
x: xCoord + xOffset,
|
|
167
|
-
y: $yScale(seriesPoint.point[1]) + yOffset,
|
|
168
|
-
fill: $config.r ? $rGet(seriesPoint.series) : null,
|
|
169
|
-
}));
|
|
170
212
|
}
|
|
171
213
|
}
|
|
172
214
|
else {
|