layerchart 0.70.1 → 0.70.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.
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
accessor,
|
|
24
24
|
chartDataArray,
|
|
25
25
|
defaultChartPadding,
|
|
26
|
+
findRelatedData,
|
|
26
27
|
type Accessor,
|
|
27
28
|
} from '../../utils/common.js';
|
|
28
29
|
|
|
@@ -133,7 +134,7 @@
|
|
|
133
134
|
? (d) => d.stackData[i][1]
|
|
134
135
|
: Array.isArray(s.value)
|
|
135
136
|
? s.value[1]
|
|
136
|
-
: (s.value ?? s.key),
|
|
137
|
+
: (s.value ?? (s.data ? undefined : s.key)),
|
|
137
138
|
fill: s.color,
|
|
138
139
|
fillOpacity: 0.3,
|
|
139
140
|
...props.area,
|
|
@@ -253,8 +254,12 @@
|
|
|
253
254
|
|
|
254
255
|
<slot name="highlight" {...slotProps}>
|
|
255
256
|
{#each series as s, i (s.key)}
|
|
257
|
+
{@const seriesTooltipData =
|
|
258
|
+
s.data && tooltip.data ? findRelatedData(s.data, tooltip.data, x) : null}
|
|
259
|
+
|
|
256
260
|
<Highlight
|
|
257
|
-
|
|
261
|
+
data={seriesTooltipData}
|
|
262
|
+
y={stackSeries ? (d) => d.stackData[i][1] : (s.value ?? (s.data ? undefined : s.key))}
|
|
258
263
|
points={{ fill: s.color }}
|
|
259
264
|
lines={i == 0}
|
|
260
265
|
{...props.highlight}
|
|
@@ -291,10 +296,12 @@
|
|
|
291
296
|
<!-- Reverse series order so tooltip items match stacks -->
|
|
292
297
|
{@const seriesItems = stackSeries ? [...series].reverse() : series}
|
|
293
298
|
{#each seriesItems as s}
|
|
294
|
-
{@const
|
|
299
|
+
{@const seriesTooltipData = s.data ? findRelatedData(s.data, data, x) : data}
|
|
300
|
+
{@const valueAccessor = accessor(s.value ?? (s.data ? (y as any) : s.key))}
|
|
301
|
+
|
|
295
302
|
<Tooltip.Item
|
|
296
303
|
label={s.label ?? (s.key !== 'default' ? s.key : 'value')}
|
|
297
|
-
value={valueAccessor(
|
|
304
|
+
value={seriesTooltipData ? valueAccessor(seriesTooltipData) : null}
|
|
298
305
|
color={s.color}
|
|
299
306
|
{format}
|
|
300
307
|
valueAlign="right"
|
|
@@ -307,8 +314,10 @@
|
|
|
307
314
|
<Tooltip.Item
|
|
308
315
|
label="total"
|
|
309
316
|
value={sum(series, (s) => {
|
|
310
|
-
const
|
|
311
|
-
|
|
317
|
+
const seriesTooltipData = s.data ? s.data.find((d) => x(d) === x(data)) : data;
|
|
318
|
+
const valueAccessor = accessor(s.value ?? (s.data ? (y as any) : s.key));
|
|
319
|
+
|
|
320
|
+
return valueAccessor(seriesTooltipData);
|
|
312
321
|
})}
|
|
313
322
|
format="integer"
|
|
314
323
|
valueAlign="right"
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
accessor,
|
|
21
21
|
chartDataArray,
|
|
22
22
|
defaultChartPadding,
|
|
23
|
+
findRelatedData,
|
|
23
24
|
type Accessor,
|
|
24
25
|
} from '../../utils/common.js';
|
|
25
26
|
|
|
@@ -198,9 +199,11 @@
|
|
|
198
199
|
|
|
199
200
|
<slot name="highlight" {...slotProps}>
|
|
200
201
|
{#each series as s, i (s.key)}
|
|
202
|
+
{@const seriesTooltipData =
|
|
203
|
+
s.data && tooltip.data ? findRelatedData(s.data, tooltip.data, x) : null}
|
|
201
204
|
<Highlight
|
|
202
|
-
data={
|
|
203
|
-
y={s.value ?? s.key}
|
|
205
|
+
data={seriesTooltipData}
|
|
206
|
+
y={s.value ?? (s.data ? undefined : s.key)}
|
|
204
207
|
points={{ fill: s.color }}
|
|
205
208
|
lines={i === 0}
|
|
206
209
|
{...props.highlight}
|
|
@@ -231,10 +234,12 @@
|
|
|
231
234
|
<Tooltip.Header>{format(x(data))}</Tooltip.Header>
|
|
232
235
|
<Tooltip.List>
|
|
233
236
|
{#each series as s}
|
|
234
|
-
{@const
|
|
237
|
+
{@const seriesTooltipData = s.data ? findRelatedData(s.data, data, x) : data}
|
|
238
|
+
{@const valueAccessor = accessor(s.value ?? (s.data ? (y as any) : s.key))}
|
|
239
|
+
|
|
235
240
|
<Tooltip.Item
|
|
236
241
|
label={s.label ?? (s.key !== 'default' ? s.key : 'value')}
|
|
237
|
-
value={valueAccessor(
|
|
242
|
+
value={seriesTooltipData ? valueAccessor(seriesTooltipData) : null}
|
|
238
243
|
color={s.color}
|
|
239
244
|
{format}
|
|
240
245
|
/>
|
package/dist/utils/common.d.ts
CHANGED
|
@@ -12,4 +12,9 @@ export declare function defaultChartPadding(axis: SimplifiedChartProps['axis'],
|
|
|
12
12
|
bottom: number;
|
|
13
13
|
right: number;
|
|
14
14
|
} | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Find the first instance within `data` with the same value as `original` using prop accessor.
|
|
17
|
+
* Handles complex objects such as `Date` by invoking `.valueOf()`
|
|
18
|
+
*/
|
|
19
|
+
export declare function findRelatedData(data: any[], original: any, accessor: Function): any;
|
|
15
20
|
export {};
|
package/dist/utils/common.js
CHANGED
|
@@ -44,3 +44,12 @@ export function defaultChartPadding(axis, legend) {
|
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Find the first instance within `data` with the same value as `original` using prop accessor.
|
|
49
|
+
* Handles complex objects such as `Date` by invoking `.valueOf()`
|
|
50
|
+
*/
|
|
51
|
+
export function findRelatedData(data, original, accessor) {
|
|
52
|
+
return data.find((d) => {
|
|
53
|
+
return accessor(d)?.valueOf() === accessor(original)?.valueOf();
|
|
54
|
+
});
|
|
55
|
+
}
|