@fundar/data-chart-telling 0.0.2 → 0.0.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.
@@ -218,7 +218,7 @@
218
218
  </Plot>
219
219
 
220
220
  {#if tooltip && ctrl.showTooltip && ctrl.tooltipPosition}
221
- <Tooltip x={ctrl.tooltipPosition.x} y={ctrl.tooltipPosition.y}>
221
+ <Tooltip x={ctrl.tooltipPosition?.x ?? 0} y={ctrl.tooltipPosition?.y ?? 0}>
222
222
  {#if tooltip.content}
223
223
  {@render tooltip.content({ rows: ctrl.matchedRows.map((p) => p.row) })}
224
224
  {:else}
@@ -59,15 +59,27 @@
59
59
  ? Math.min(fromVis, toVis)
60
60
  : (fromVis + toVis) / 2;
61
61
  }
62
- </script>
63
62
 
64
- {#if resolved}
65
- {@const fromVis = clamp(resolved.from)}
66
- {@const toVis = clamp(resolved.to)}
67
- {@const textPt = pt(resolved.at, textVaryCoord(fromVis, toVis))}
63
+ // Pre-derive all coordinates as script-level signals so prop getters read safe
64
+ // values during Svelte 5 teardown, before the {#if} guard finishes unmounting.
65
+ const coords = $derived.by(() => {
66
+ if (!resolved) return null;
67
+ const fromVis = clamp(resolved.from ?? 0);
68
+ const toVis = clamp(resolved.to ?? 0);
69
+ const at = resolved.at ?? 0;
70
+ return {
71
+ fromPt: pt(at, fromVis),
72
+ toPt: pt(at, toVis),
73
+ textPt: pt(at, textVaryCoord(fromVis, toVis)),
74
+ lineData: [pt(at, fromVis), pt(at, toVis)],
75
+ diff: resolved.diff ?? 0,
76
+ };
77
+ });
78
+ </script>
68
79
 
80
+ {#if coords}
69
81
  <Line
70
- data={[pt(resolved.at, fromVis), pt(resolved.at, toVis)]}
82
+ data={coords.lineData}
71
83
  x={(p) => p.x}
72
84
  y={(p) => p.y}
73
85
  stroke={strokeStyle?.stroke ?? 'currentColor'}
@@ -77,19 +89,19 @@
77
89
  strokeLinecap={strokeStyle?.strokeLinecap ?? 'round'}
78
90
  />
79
91
  <DotMarker
80
- x={pt(resolved.at, fromVis).x}
81
- y={pt(resolved.at, fromVis).y}
92
+ x={coords?.fromPt?.x ?? 0}
93
+ y={coords?.fromPt?.y ?? 0}
82
94
  style={{ dotRadius: 4, dotFill: strokeStyle?.stroke, dotStroke: strokeStyle?.stroke, dotStrokeWidth: 2, ...dotStyle }}
83
95
  />
84
96
  <DotMarker
85
- x={pt(resolved.at, toVis).x}
86
- y={pt(resolved.at, toVis).y}
97
+ x={coords?.toPt?.x ?? 0}
98
+ y={coords?.toPt?.y ?? 0}
87
99
  style={{ dotRadius: 4, dotFill: strokeStyle?.stroke, dotStroke: strokeStyle?.stroke, dotStrokeWidth: 2, ...dotStyle }}
88
100
  />
89
101
  <TextMarker
90
- x={textPt.x}
91
- y={textPt.y}
92
- text={(formatDiff ?? ((v: number) => v.toFixed(1)))(resolved.diff)}
102
+ x={coords?.textPt?.x ?? 0}
103
+ y={coords?.textPt?.y ?? 0}
104
+ text={(formatDiff ?? ((v: number) => v.toFixed(1)))(coords?.diff ?? 0)}
93
105
  style={{
94
106
  fontWeight: 'bold',
95
107
  fontSize: 14,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fundar/data-chart-telling",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "build": "svelte-package",