@fundar/data-chart-telling 1.10.0 → 1.11.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/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  All notable changes to this project are documented here. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project adheres to [Semantic Versioning](https://semver.org/).
4
4
 
5
+ ## [1.11.0] - 2026-11-04
6
+
7
+ ### Changed
8
+
9
+ - The dots of a `delta` take the color of the series their end measures, as the plot draws it. Before, they took the line's `stroke` and, with none set, a neutral color. The line's `stroke` still wins when it is set, and the delta's own `dot` wins over both; an end on an axis keeps the neutral color. `usePlot()` now also gives `colorForSeries`.
10
+ - **Breaking:** a delta's line is styled with `stroke`, not `line`, like the rest of the styles (`DeltaMarkerConfig.line`, also as a function of the position). Rename it where it is set.
11
+
5
12
  ## [1.10.0] - 2026-11-03
6
13
 
7
14
  ### Added
@@ -238,7 +238,8 @@
238
238
  scales: () => scales,
239
239
  axes: () => state.axes,
240
240
  data: () => data,
241
- size: () => ({ width, height })
241
+ size: () => ({ width, height }),
242
+ colorForSeries: () => state.colorForSeries
242
243
  });
243
244
 
244
245
  /** The domains `ScalesLayout` widens an axis to, for an edge tick's `'extend'` (see `EdgeTicks`). */
@@ -16,6 +16,8 @@ export type PlotContextParts<T extends Record<string, unknown>> = {
16
16
  width: number;
17
17
  height: number;
18
18
  };
19
+ /** Each series' color, by name - axis kinds only. */
20
+ colorForSeries?: () => ((name: string) => string) | undefined;
19
21
  };
20
22
  /**
21
23
  * Everything one plot is, gathered where what draws inside it can reach it:
@@ -36,6 +38,7 @@ export declare class PlotContext<T extends Record<string, unknown> = Record<stri
36
38
  get scales(): object | undefined;
37
39
  get axes(): PlotAxes | undefined;
38
40
  get data(): T[];
41
+ get colorForSeries(): ((name: string) => string) | undefined;
39
42
  get width(): number;
40
43
  get height(): number;
41
44
  }
@@ -37,6 +37,9 @@ export class PlotContext {
37
37
  get data() {
38
38
  return this.#parts.data();
39
39
  }
40
+ get colorForSeries() {
41
+ return this.#parts.colorForSeries?.();
42
+ }
40
43
  get width() {
41
44
  return this.#parts.size().width;
42
45
  }
@@ -126,6 +126,8 @@ export declare class PublicPlotContext<T extends Record<string, unknown> = Recor
126
126
  get axes(): PlotAxes | undefined;
127
127
  /** The rows the plot draws and hovers over. */
128
128
  get data(): T[];
129
+ /** The color a series is drawn in, by its name - `undefined` for a plot with no series (a map). */
130
+ get colorForSeries(): ((name: string) => string) | undefined;
129
131
  get width(): number;
130
132
  get height(): number;
131
133
  }
@@ -231,6 +231,10 @@ export class PublicPlotContext {
231
231
  get data() {
232
232
  return this.#context.data;
233
233
  }
234
+ /** The color a series is drawn in, by its name - `undefined` for a plot with no series (a map). */
235
+ get colorForSeries() {
236
+ return this.#context.colorForSeries;
237
+ }
234
238
  get width() {
235
239
  return this.#context.width;
236
240
  }
@@ -18,7 +18,7 @@ export declare class Delta {
18
18
  #private;
19
19
  /**
20
20
  * The deltas a marker draws: one for its `at`, or one for each position of a list, each with the
21
- * `line`, `text` and `dot` its style functions give for that position.
21
+ * `stroke`, `text` and `dot` its style functions give for that position.
22
22
  */
23
23
  static points(marker: DeltaMarkerConfig): DeltaPointConfig[];
24
24
  /** The delta `config` asks for over `allSeries`, or `undefined` while an end has no value there. */
@@ -7,7 +7,7 @@ import { resolveAccessor } from '../../utils/accessors';
7
7
  export class Delta {
8
8
  /**
9
9
  * The deltas a marker draws: one for its `at`, or one for each position of a list, each with the
10
- * `line`, `text` and `dot` its style functions give for that position.
10
+ * `stroke`, `text` and `dot` its style functions give for that position.
11
11
  */
12
12
  static points(marker) {
13
13
  const positions = Array.isArray(marker.at) ? marker.at : [marker.at];
@@ -15,7 +15,7 @@ export class Delta {
15
15
  return positions.map((at) => ({
16
16
  ...marker,
17
17
  at,
18
- line: own(marker.line, at),
18
+ stroke: own(marker.stroke, at),
19
19
  text: own(marker.text, at),
20
20
  dot: own(marker.dot, at)
21
21
  }));
@@ -6,7 +6,7 @@
6
6
 
7
7
  /**
8
8
  * A delta annotation: one at `marker.at`, or, when it is a list, one at each position - all with the
9
- * same ends. `line`, `text` and `dot` can be functions of the position.
9
+ * same ends. `stroke`, `text` and `dot` can be functions of the position.
10
10
  */
11
11
  let { marker, data = [] }: { marker: DeltaMarkerConfig; data?: Series<TData>[] } = $props();
12
12
 
@@ -3,6 +3,7 @@
3
3
  import DotMarker from '../dot/DotMarker.svelte';
4
4
  import TextMarker from '../text/TextMarker.svelte';
5
5
  import { Delta } from './Delta';
6
+ import { usePlot } from '../../layout/plot/usePlot';
6
7
  import { getConfiguration } from '../../configuration/config.svelte';
7
8
  import type { Series } from '../../types/plots/data/common';
8
9
  import type { DeltaPointConfig } from '../../types/markers/axis/delta';
@@ -10,6 +11,8 @@
10
11
  /** One delta, at the one position `marker.at` names. See {@link DeltaMarker} for a list of them. */
11
12
  let { marker, data = [] }: { marker: DeltaPointConfig; data?: Series<TData>[] } = $props();
12
13
 
14
+ const plot = usePlot();
15
+
13
16
  const resolved = $derived(Delta.build(marker.axis, data, marker));
14
17
  const label = $derived(getConfiguration().delta.text[marker.axis]);
15
18
  const lineAnchor = $derived(marker.text?.lineAnchor ?? label.lineAnchor);
@@ -54,13 +57,22 @@
54
57
  };
55
58
  });
56
59
 
57
- const dotStyles = $derived({
58
- dotRadius: 4,
59
- dotFill: marker.line?.stroke,
60
- dotStroke: marker.line?.stroke,
61
- dotStrokeWidth: 2,
62
- ...marker.dot
63
- });
60
+ /**
61
+ * The dot of one end: in the delta's own `stroke` when it sets one, else in the color of the series the end
62
+ * measures - an axis end has none, and takes the dot's default. `dot` wins over both.
63
+ */
64
+ function dotStyles(target: DeltaPointConfig['from'] | undefined) {
65
+ const color =
66
+ marker.stroke?.stroke ??
67
+ (target?.type === 'series' ? plot.colorForSeries?.(target.series) : undefined);
68
+ return {
69
+ dotRadius: 4,
70
+ dotFill: color,
71
+ dotStroke: color,
72
+ dotStrokeWidth: 2,
73
+ ...marker.dot
74
+ };
75
+ }
64
76
  </script>
65
77
 
66
78
  {#if coords}
@@ -68,14 +80,18 @@
68
80
  data={coords.lineData}
69
81
  x={(p) => p.x}
70
82
  y={(p) => p.y}
71
- stroke={marker.line?.stroke ?? 'currentColor'}
72
- strokeWidth={marker.line?.strokeWidth ?? 2}
73
- strokeOpacity={marker.line?.strokeOpacity ?? 0.8}
74
- strokeDasharray={marker.line?.strokeDasharray ?? '6 6'}
75
- strokeLinecap={marker.line?.strokeLinecap ?? 'round'}
83
+ stroke={marker.stroke?.stroke ?? 'currentColor'}
84
+ strokeWidth={marker.stroke?.strokeWidth ?? 2}
85
+ strokeOpacity={marker.stroke?.strokeOpacity ?? 0.8}
86
+ strokeDasharray={marker.stroke?.strokeDasharray ?? '6 6'}
87
+ strokeLinecap={marker.stroke?.strokeLinecap ?? 'round'}
88
+ />
89
+ <DotMarker
90
+ marker={{ type: 'dot', x: coords.fromPt.x, y: coords.fromPt.y, styles: dotStyles(marker.from) }}
91
+ />
92
+ <DotMarker
93
+ marker={{ type: 'dot', x: coords.toPt.x, y: coords.toPt.y, styles: dotStyles(marker.to) }}
76
94
  />
77
- <DotMarker marker={{ type: 'dot', x: coords.fromPt.x, y: coords.fromPt.y, styles: dotStyles }} />
78
- <DotMarker marker={{ type: 'dot', x: coords.toPt.x, y: coords.toPt.y, styles: dotStyles }} />
79
95
  <TextMarker
80
96
  marker={{
81
97
  type: 'text',
@@ -86,7 +102,7 @@
86
102
  fontWeight: 'bold',
87
103
  fontSize: 14,
88
104
  textAnchor: label.textAnchor,
89
- fill: marker.line?.stroke ?? 'currentColor',
105
+ fill: marker.stroke?.stroke ?? 'currentColor',
90
106
  ...marker.text,
91
107
  dx: marker.text?.dx ?? label.dx,
92
108
  dy: marker.text?.dy ?? label.dy,
@@ -15,7 +15,7 @@ export type DeltaConfig = {
15
15
  from: DeltaTarget;
16
16
  to?: DeltaTarget;
17
17
  formatDiff?: (diff: number) => string;
18
- line?: StrokeStyle;
18
+ stroke?: StrokeStyle;
19
19
  text?: FontStyle;
20
20
  dot?: DotStyle;
21
21
  };
@@ -29,12 +29,12 @@ export type DeltaPointConfig = {
29
29
  export type PerPosition<T> = T | ((at: AxisValue) => T);
30
30
  /**
31
31
  * A delta annotation between two points on a line chart. `at` can be a list of positions: one delta is
32
- * drawn at each, with the same ends. `line`, `text` and `dot` can be functions of the position, to style
32
+ * drawn at each, with the same ends. `stroke`, `text` and `dot` can be functions of the position, to style
33
33
  * each delta on its own - a label to the left of the last one, say, so it stays inside the plot.
34
34
  */
35
- export type DeltaMarkerConfig = Omit<DeltaPointConfig, 'at' | 'line' | 'text' | 'dot'> & {
35
+ export type DeltaMarkerConfig = Omit<DeltaPointConfig, 'at' | 'stroke' | 'text' | 'dot'> & {
36
36
  at: AxisValue | AxisValue[];
37
- line?: PerPosition<StrokeStyle>;
37
+ stroke?: PerPosition<StrokeStyle>;
38
38
  text?: PerPosition<FontStyle>;
39
39
  dot?: PerPosition<DotStyle>;
40
40
  };
package/docs/markers.md CHANGED
@@ -102,7 +102,7 @@ markers={[
102
102
  ]}
103
103
  ```
104
104
 
105
- A delta's `line`, `text` and `dot` can be functions of the position, to style each one on its own - a label to the left of the last one, say, so it stays inside the plot:
105
+ A delta's `stroke`, `text` and `dot` can be functions of the position, to style each one on its own - a label to the left of the last one, say, so it stays inside the plot:
106
106
 
107
107
  ```ts
108
108
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fundar/data-chart-telling",
3
- "version": "1.10.0",
3
+ "version": "1.11.0",
4
4
  "description": "Declarative charts, maps and small multiples for Svelte, built on svelteplot.",
5
5
  "license": "MIT",
6
6
  "author": "Ezequiel Puerta",