layerchart 0.70.2 → 0.70.4

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.
@@ -75,6 +75,9 @@
75
75
  export let classes: {
76
76
  root?: string;
77
77
  label?: string;
78
+ rule?: string;
79
+ tick?: string;
80
+ tickLabel?: string;
78
81
  } = {};
79
82
 
80
83
  $: [xRangeMin, xRangeMax] = extent<number>($xRange) as [number, number];
@@ -236,7 +239,7 @@
236
239
  {tweened}
237
240
  {spring}
238
241
  {...ruleProps}
239
- class={cls('rule stroke-surface-content/50', ruleProps?.class)}
242
+ class={cls('rule stroke-surface-content/50', classes.rule, ruleProps?.class)}
240
243
  />
241
244
  {/if}
242
245
 
@@ -261,6 +264,7 @@
261
264
  ...tickLabelProps,
262
265
  class: cls(
263
266
  'tickLabel text-[10px] stroke-surface-100 [stroke-width:2px] font-light',
267
+ classes.tickLabel,
264
268
  tickLabelProps?.class
265
269
  ),
266
270
  }}
@@ -274,7 +278,7 @@
274
278
  {tweened}
275
279
  {spring}
276
280
  {...ruleProps}
277
- class={cls('grid stroke-surface-content/10', ruleProps?.class)}
281
+ class={cls('grid stroke-surface-content/10', classes.rule, ruleProps?.class)}
278
282
  />
279
283
  {/if}
280
284
 
@@ -287,7 +291,7 @@
287
291
  y2={tickCoords.y + (placement === 'top' ? -tickLength : tickLength)}
288
292
  {tweened}
289
293
  {spring}
290
- class="tick stroke-surface-content/50"
294
+ class={cls('tick stroke-surface-content/50', classes.tick)}
291
295
  />
292
296
  {:else if orientation === 'vertical'}
293
297
  <Line
@@ -297,7 +301,7 @@
297
301
  y2={tickCoords.y}
298
302
  {tweened}
299
303
  {spring}
300
- class="tick stroke-surface-content/50"
304
+ class={cls('tick stroke-surface-content/50', classes.tick)}
301
305
  />
302
306
  {:else if orientation === 'angle'}
303
307
  <Line
@@ -307,7 +311,7 @@
307
311
  y2={radialTickMarkCoordsY}
308
312
  {tweened}
309
313
  {spring}
310
- class="tick stroke-surface-content/50"
314
+ class={cls('tick stroke-surface-content/50', classes.tick)}
311
315
  />
312
316
  {/if}
313
317
  <!-- TODO: Add tick marks for radial (angle)? -->
@@ -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
 
@@ -254,7 +255,7 @@
254
255
  <slot name="highlight" {...slotProps}>
255
256
  {#each series as s, i (s.key)}
256
257
  {@const seriesTooltipData =
257
- s.data && tooltip.data ? s.data.find((d) => x(d) === x(tooltip.data)) : null}
258
+ s.data && tooltip.data ? findRelatedData(s.data, tooltip.data, x) : null}
258
259
 
259
260
  <Highlight
260
261
  data={seriesTooltipData}
@@ -295,12 +296,12 @@
295
296
  <!-- Reverse series order so tooltip items match stacks -->
296
297
  {@const seriesItems = stackSeries ? [...series].reverse() : series}
297
298
  {#each seriesItems as s}
298
- {@const seriesTooltipData = s.data ? s.data.find((d) => x(d) === x(data)) : data}
299
+ {@const seriesTooltipData = s.data ? findRelatedData(s.data, data, x) : data}
299
300
  {@const valueAccessor = accessor(s.value ?? (s.data ? (y as any) : s.key))}
300
301
 
301
302
  <Tooltip.Item
302
303
  label={s.label ?? (s.key !== 'default' ? s.key : 'value')}
303
- value={valueAccessor(seriesTooltipData)}
304
+ value={seriesTooltipData ? valueAccessor(seriesTooltipData) : null}
304
305
  color={s.color}
305
306
  {format}
306
307
  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
 
@@ -199,8 +200,7 @@
199
200
  <slot name="highlight" {...slotProps}>
200
201
  {#each series as s, i (s.key)}
201
202
  {@const seriesTooltipData =
202
- s.data && tooltip.data ? s.data.find((d) => x(d) === x(tooltip.data)) : null}
203
-
203
+ s.data && tooltip.data ? findRelatedData(s.data, tooltip.data, x) : null}
204
204
  <Highlight
205
205
  data={seriesTooltipData}
206
206
  y={s.value ?? (s.data ? undefined : s.key)}
@@ -234,12 +234,12 @@
234
234
  <Tooltip.Header>{format(x(data))}</Tooltip.Header>
235
235
  <Tooltip.List>
236
236
  {#each series as s}
237
- {@const seriesTooltipData = s.data ? s.data.find((d) => x(d) === x(data)) : data}
237
+ {@const seriesTooltipData = s.data ? findRelatedData(s.data, data, x) : data}
238
238
  {@const valueAccessor = accessor(s.value ?? (s.data ? (y as any) : s.key))}
239
239
 
240
240
  <Tooltip.Item
241
241
  label={s.label ?? (s.key !== 'default' ? s.key : 'value')}
242
- value={valueAccessor(seriesTooltipData)}
242
+ value={seriesTooltipData ? valueAccessor(seriesTooltipData) : null}
243
243
  color={s.color}
244
244
  {format}
245
245
  />
@@ -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 {};
@@ -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
+ }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "author": "Sean Lynch <techniq35@gmail.com>",
5
5
  "license": "MIT",
6
6
  "repository": "techniq/layerchart",
7
- "version": "0.70.2",
7
+ "version": "0.70.4",
8
8
  "devDependencies": {
9
9
  "@changesets/cli": "^2.27.10",
10
10
  "@mdi/js": "^7.4.47",