layerchart 0.43.3 → 0.43.5

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.
@@ -45,13 +45,13 @@ declare class __sveltets_Render<TData> {
45
45
  /** The r accessor. The key in each row of data that corresponds to the r-field. This can be a string, an accessor function, a number or an array of any combination of those types. This property gets converted to a function when you access it through the context. */
46
46
  r?: Accessor<TData>;
47
47
  /** Set a min or max. For linear scales, if you want to inherit the value from the data's extent, set that value to `null`. This value can also be an array because sometimes your scales are [piecewise](https://github.com/d3/d3-scale#continuous_domain) or are a list of discrete values such as in [ordinal scales](https://github.com/d3/d3-scale#ordinal-scales), useful for color series. Set it to a function that receives the computed domain and lets you return a modified domain, useful for sorting values. */
48
- xDomain?: Function | string[] | [number | Date | null, number | Date | null] | (number | null)[] | Date[] | null[] | null;
48
+ xDomain?: Function | (string | number | Date | null | undefined)[] | null;
49
49
  /** Set a min or max. For linear scales, if you want to inherit the value from the data's extent, set that value to `null`. Set it to a function that receives the computed domain and lets you return a modified domain, useful for sorting values. */
50
- yDomain?: Function | string[] | [number | Date | null, number | Date | null] | (number | null)[] | Date[] | null[] | null;
50
+ yDomain?: Function | (string | number | Date | null | undefined)[] | null;
51
51
  /** Set a min or max. For linear scales, if you want to inherit the value from the data's extent, set that value to `null`. This value can also be an array because sometimes your scales are [piecewise](https://github.com/d3/d3-scale#continuous_domain) or are a list of discrete values such as in [ordinal scales](https://github.com/d3/d3-scale#ordinal-scales), useful for color series. Set it to a function that receives the computed domain and lets you return a modified domain, useful for sorting values. */
52
- zDomain?: Function | string[] | [number | Date | null, number | Date | null] | (number | null)[] | Date[] | null[] | null;
52
+ zDomain?: Function | (string | number | Date | null | undefined)[] | null;
53
53
  /** Set a min or max. For linear scales, if you want to inherit the value from the data's extent, set that value to `null`. This value can also be an array because sometimes your scales are [piecewise](https://github.com/d3/d3-scale#continuous_domain) or are a list of discrete values such as in [ordinal scales](https://github.com/d3/d3-scale#ordinal-scales), useful for color series. Set it to a function that receives the computed domain and lets you return a modified domain, useful for sorting values. */
54
- rDomain?: Function | string[] | [number | Date | null, number | Date | null] | (number | null)[] | Date[] | null[] | null;
54
+ rDomain?: Function | (string | number | Date | null | undefined)[] | null;
55
55
  /** Applies D3's [scale.nice()](https://github.com/d3/d3-scale#continuous_nice) to the x domain. @default false */
56
56
  xNice?: boolean | number;
57
57
  /** Applies D3's [scale.nice()](https://github.com/d3/d3-scale#continuous_nice) to the y domain. @default false */
@@ -8,10 +8,19 @@ import Bar from './Bar.svelte';
8
8
  import Rect from './Rect.svelte';
9
9
  import { tooltipContext } from './TooltipContext.svelte';
10
10
  import { isScaleBand } from '../utils/scales.js';
11
- const { data: contextData, flatData, x, xDomain, xScale, xRange, xGet, y, yDomain, yScale, yRange, yGet, rGet, config, } = chartContext();
11
+ import { accessor } from '../utils/common.js';
12
+ const { data: contextData, flatData, x: xContext, xDomain, xScale, xRange, y: yContext, yDomain, yScale, yRange, rGet, config, } = chartContext();
12
13
  const tooltip = tooltipContext();
13
14
  /** Highlight specific data (annotate), espect uses tooltip data */
14
15
  export let data = undefined;
16
+ /**
17
+ * Override `x` from context
18
+ */
19
+ export let x = $xContext;
20
+ /**
21
+ * Override `y` from context
22
+ */
23
+ export let y = $yContext;
15
24
  export let axis = undefined;
16
25
  /** Show points and pass props to Circles */
17
26
  export let points = false;
@@ -24,6 +33,8 @@ export let bar = false;
24
33
  /** Set to false to disable spring transitions */
25
34
  export let motion = true;
26
35
  // TODO: Fix circle points being backwards for stack (see AreaStack)
36
+ const _x = accessor(x);
37
+ const _y = accessor(y);
27
38
  let _points = [];
28
39
  let _lines = [];
29
40
  let _area = {
@@ -34,10 +45,12 @@ let _area = {
34
45
  };
35
46
  $: highlightData = data ?? $tooltip.data;
36
47
  $: if (highlightData) {
37
- let xCoord = $xGet(highlightData);
38
- let xOffset = isScaleBand($xScale) ? $xScale.bandwidth() / 2 : 0;
39
- let yCoord = $yGet(highlightData);
40
- let yOffset = isScaleBand($yScale) ? $yScale.bandwidth() / 2 : 0;
48
+ const xValue = _x(highlightData);
49
+ const xCoord = Array.isArray(xValue) ? xValue.map((v) => $xScale(v)) : $xScale(xValue);
50
+ const xOffset = isScaleBand($xScale) ? $xScale.bandwidth() / 2 : 0;
51
+ const yValue = _y(highlightData);
52
+ const yCoord = Array.isArray(yValue) ? yValue.map((v) => $yScale(v)) : $yScale(yValue);
53
+ const yOffset = isScaleBand($yScale) ? $yScale.bandwidth() / 2 : 0;
41
54
  // Reset lines
42
55
  _lines = [];
43
56
  const defaultAxis = isScaleBand($yScale) ? 'y' : 'x';
@@ -79,9 +92,9 @@ $: if (highlightData) {
79
92
  }
80
93
  else {
81
94
  // Find width to next data point
82
- const index = $flatData.findIndex((d) => Number($x(d)) === Number($x(highlightData)));
95
+ const index = $flatData.findIndex((d) => Number(_x(d)) === Number(_x(highlightData)));
83
96
  const isLastPoint = index + 1 === $flatData.length;
84
- const nextDataPoint = isLastPoint ? max($xDomain) : $x($flatData[index + 1]);
97
+ const nextDataPoint = isLastPoint ? max($xDomain) : _x($flatData[index + 1]);
85
98
  _area.width = ($xScale(nextDataPoint) ?? 0) - (xCoord ?? 0);
86
99
  }
87
100
  // If array, use left-most value for top left of rect
@@ -127,9 +140,9 @@ $: if (highlightData) {
127
140
  }
128
141
  else {
129
142
  // Find width to next data point
130
- const index = $flatData.findIndex((d) => Number($x(d)) === Number($x(highlightData)));
143
+ const index = $flatData.findIndex((d) => Number(_x(d)) === Number(_x(highlightData)));
131
144
  const isLastPoint = index + 1 === $flatData.length;
132
- const nextDataPoint = isLastPoint ? max($yDomain) : $x($flatData[index + 1]);
145
+ const nextDataPoint = isLastPoint ? max($yDomain) : _x($flatData[index + 1]);
133
146
  _area.height = ($yScale(nextDataPoint) ?? 0) - (yCoord ?? 0);
134
147
  }
135
148
  // If array, use left-most value for top left of rect
@@ -153,7 +166,7 @@ $: if (highlightData) {
153
166
  const seriesPointsData = $contextData.map((series) => {
154
167
  return {
155
168
  series,
156
- point: series.find((d) => $y(d) === $y(highlightSeriesPoint)),
169
+ point: series.find((d) => _y(d) === _y(highlightSeriesPoint)),
157
170
  };
158
171
  });
159
172
  _points = seriesPointsData.map((seriesPoint, i) => ({
@@ -169,7 +182,7 @@ $: if (highlightData) {
169
182
  const $key = $config.x[i];
170
183
  return {
171
184
  x: xItem + xOffset,
172
- y: $xGet(highlightData) + yOffset,
185
+ y: yCoord + yOffset,
173
186
  // TODO: is there a better way to expose the series key/value?
174
187
  fill: $config.r ? $rGet({ ...highlightData, $key }) : null,
175
188
  };
@@ -188,7 +201,7 @@ $: if (highlightData) {
188
201
  const seriesPointsData = $contextData.map((series) => {
189
202
  return {
190
203
  series,
191
- point: series.find((d) => $x(d) === $x(highlightSeriesPoint)),
204
+ point: series.find((d) => _x(d) === _x(highlightSeriesPoint)),
192
205
  };
193
206
  });
194
207
  _points = seriesPointsData.map((seriesPoint, i) => ({
@@ -203,7 +216,7 @@ $: if (highlightData) {
203
216
  _points = yCoord.filter(notNull).map((yItem, i) => {
204
217
  const $key = $config.y[i];
205
218
  return {
206
- x: $xGet(highlightData) + xOffset,
219
+ x: xCoord + xOffset,
207
220
  y: yItem + yOffset,
208
221
  // TODO: is there a better way to expose the series key/value?
209
222
  fill: $config.r ? $rGet({ ...highlightData, $key }) : null,
@@ -215,7 +228,7 @@ $: if (highlightData) {
215
228
  _points = [
216
229
  {
217
230
  x: xCoord + xOffset,
218
- y: $yGet(highlightData) + yOffset,
231
+ y: yCoord + yOffset,
219
232
  fill: $config.r ? $rGet(highlightData) : null,
220
233
  },
221
234
  ];
@@ -292,7 +305,7 @@ $: if (highlightData) {
292
305
  {...typeof points === 'object' ? points : null}
293
306
  class={cls(
294
307
  'stroke-[6] stroke-white [paint-order:stroke] drop-shadow',
295
- !point.fill && 'fill-primary',
308
+ !point.fill && (typeof points === 'boolean' || !points.fill) && 'fill-primary',
296
309
  typeof points === 'object' ? points.class : null
297
310
  )}
298
311
  />
@@ -4,9 +4,16 @@ import Circle from './Circle.svelte';
4
4
  import Line from './Line.svelte';
5
5
  import Bar from './Bar.svelte';
6
6
  import Rect from './Rect.svelte';
7
+ import { type Accessor } from '../utils/common.js';
7
8
  declare const __propDef: {
8
9
  props: {
9
10
  /** Highlight specific data (annotate), espect uses tooltip data */ data?: any;
11
+ /**
12
+ * Override `x` from context
13
+ */ x?: Accessor;
14
+ /**
15
+ * Override `y` from context
16
+ */ y?: Accessor;
10
17
  axis?: "x" | "y" | "both" | "none" | undefined;
11
18
  /** Show points and pass props to Circles */ points?: boolean | Partial<ComponentProps<Circle>>;
12
19
  /** Show lines and pass props to Lines */ lines?: boolean | Partial<ComponentProps<Line>>;
@@ -32,8 +39,8 @@ declare const __propDef: {
32
39
  bar: boolean | Partial<{
33
40
  [x: string]: any;
34
41
  bar: Object;
35
- x?: import("..").Accessor;
36
- y?: import("..").Accessor;
42
+ x?: Accessor;
43
+ y?: Accessor;
37
44
  fill?: string | undefined;
38
45
  stroke?: string;
39
46
  strokeWidth?: number;
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.43.3",
7
+ "version": "0.43.5",
8
8
  "devDependencies": {
9
9
  "@changesets/cli": "^2.27.5",
10
10
  "@mdi/js": "^7.4.47",