@rokkit/chart 1.0.0-next.151 → 1.0.0-next.158

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.
Files changed (86) hide show
  1. package/dist/PlotState.svelte.d.ts +26 -0
  2. package/dist/index.d.ts +6 -1
  3. package/dist/lib/brewing/BoxBrewer.svelte.d.ts +3 -5
  4. package/dist/lib/brewing/QuartileBrewer.svelte.d.ts +9 -0
  5. package/dist/lib/brewing/ViolinBrewer.svelte.d.ts +3 -4
  6. package/dist/lib/brewing/colors.d.ts +10 -1
  7. package/dist/lib/brewing/marks/points.d.ts +17 -2
  8. package/dist/lib/keyboard-nav.d.ts +15 -0
  9. package/dist/lib/plot/preset.d.ts +1 -1
  10. package/dist/lib/preset.d.ts +30 -0
  11. package/package.json +2 -1
  12. package/src/AnimatedPlot.svelte +375 -207
  13. package/src/Chart.svelte +81 -84
  14. package/src/ChartProvider.svelte +10 -0
  15. package/src/FacetPlot/Panel.svelte +30 -16
  16. package/src/FacetPlot.svelte +100 -76
  17. package/src/Plot/Area.svelte +26 -19
  18. package/src/Plot/Axis.svelte +81 -59
  19. package/src/Plot/Bar.svelte +47 -89
  20. package/src/Plot/Grid.svelte +23 -19
  21. package/src/Plot/Legend.svelte +213 -147
  22. package/src/Plot/Line.svelte +31 -21
  23. package/src/Plot/Point.svelte +35 -22
  24. package/src/Plot/Root.svelte +46 -91
  25. package/src/Plot/Timeline.svelte +82 -82
  26. package/src/Plot/Tooltip.svelte +68 -62
  27. package/src/Plot.svelte +290 -174
  28. package/src/PlotState.svelte.js +338 -265
  29. package/src/Sparkline.svelte +95 -56
  30. package/src/charts/AreaChart.svelte +22 -20
  31. package/src/charts/BarChart.svelte +23 -21
  32. package/src/charts/BoxPlot.svelte +15 -15
  33. package/src/charts/BubbleChart.svelte +17 -17
  34. package/src/charts/LineChart.svelte +20 -20
  35. package/src/charts/PieChart.svelte +30 -20
  36. package/src/charts/ScatterPlot.svelte +20 -19
  37. package/src/charts/ViolinPlot.svelte +15 -15
  38. package/src/crossfilter/CrossFilter.svelte +33 -29
  39. package/src/crossfilter/FilterBar.svelte +17 -25
  40. package/src/crossfilter/FilterHistogram.svelte +290 -0
  41. package/src/crossfilter/FilterSlider.svelte +69 -65
  42. package/src/crossfilter/createCrossFilter.svelte.js +94 -90
  43. package/src/geoms/Arc.svelte +114 -69
  44. package/src/geoms/Area.svelte +67 -39
  45. package/src/geoms/Bar.svelte +184 -126
  46. package/src/geoms/Box.svelte +101 -91
  47. package/src/geoms/LabelPill.svelte +11 -11
  48. package/src/geoms/Line.svelte +110 -86
  49. package/src/geoms/Point.svelte +130 -90
  50. package/src/geoms/Violin.svelte +51 -41
  51. package/src/geoms/lib/areas.js +122 -99
  52. package/src/geoms/lib/bars.js +195 -144
  53. package/src/index.js +21 -14
  54. package/src/lib/brewing/BoxBrewer.svelte.js +8 -50
  55. package/src/lib/brewing/CartesianBrewer.svelte.js +11 -7
  56. package/src/lib/brewing/PieBrewer.svelte.js +5 -5
  57. package/src/lib/brewing/QuartileBrewer.svelte.js +51 -0
  58. package/src/lib/brewing/ViolinBrewer.svelte.js +8 -49
  59. package/src/lib/brewing/brewer.svelte.js +242 -195
  60. package/src/lib/brewing/colors.js +34 -5
  61. package/src/lib/brewing/marks/arcs.js +28 -28
  62. package/src/lib/brewing/marks/areas.js +54 -41
  63. package/src/lib/brewing/marks/bars.js +34 -34
  64. package/src/lib/brewing/marks/boxes.js +51 -51
  65. package/src/lib/brewing/marks/lines.js +37 -30
  66. package/src/lib/brewing/marks/points.js +74 -26
  67. package/src/lib/brewing/marks/violins.js +57 -57
  68. package/src/lib/brewing/patterns.js +25 -11
  69. package/src/lib/brewing/scales.js +17 -17
  70. package/src/lib/brewing/stats.js +37 -29
  71. package/src/lib/brewing/symbols.js +1 -1
  72. package/src/lib/chart.js +2 -1
  73. package/src/lib/keyboard-nav.js +37 -0
  74. package/src/lib/plot/crossfilter.js +5 -5
  75. package/src/lib/plot/facet.js +30 -30
  76. package/src/lib/plot/frames.js +30 -29
  77. package/src/lib/plot/helpers.js +4 -4
  78. package/src/lib/plot/preset.js +48 -34
  79. package/src/lib/plot/scales.js +64 -39
  80. package/src/lib/plot/stat.js +47 -47
  81. package/src/lib/preset.js +41 -0
  82. package/src/patterns/DefinePatterns.svelte +24 -24
  83. package/src/patterns/README.md +3 -0
  84. package/src/patterns/patterns.js +328 -176
  85. package/src/patterns/scale.js +61 -32
  86. package/src/spec/chart-spec.js +64 -21
@@ -1,215 +1,383 @@
1
1
  <script>
2
- import { onMount, onDestroy } from 'svelte'
3
- import { extractFrames, completeFrames, computeStaticDomains } from './lib/plot/frames.js'
4
- import { applyGeomStat } from './lib/plot/stat.js'
5
- import Timeline from './Plot/Timeline.svelte'
6
- import PlotChart from './Plot.svelte'
7
-
8
- /**
9
- * @type {{
10
- * data: Object[],
11
- * animate: { by: string, duration?: number, loop?: boolean },
12
- * x?: string,
13
- * y?: string,
14
- * color?: string,
15
- * geoms?: import('./lib/plot/types.js').GeomSpec[],
16
- * helpers?: import('./lib/plot/types.js').PlotHelpers,
17
- * width?: number,
18
- * height?: number,
19
- * mode?: 'light' | 'dark',
20
- * grid?: boolean,
21
- * legend?: boolean,
22
- * children?: import('svelte').Snippet
23
- * }}
24
- */
25
- let {
26
- data = [],
27
- animate,
28
- x,
29
- y,
30
- color,
31
- geoms = [],
32
- helpers = {},
33
- width = 600,
34
- height = 400,
35
- mode = 'light',
36
- grid = true,
37
- legend = false,
38
- children
39
- } = $props()
40
-
41
- // Pre-aggregate and complete frames when any geom has a non-identity stat:
42
- // 1. applyGeomStat: aggregate data by (x, color?, by) → one row per combination
43
- // 2. completeFrames: alignBy(by) ensures all frame values appear for every (x, color?)
44
- // group, filling missing rows with y=0 so bars animate smoothly
45
- // Geoms are returned with stat: 'identity' so PlotChart renders the pre-aggregated values as-is.
46
- const prepared = $derived.by(() => {
47
- const firstNonIdentity = geoms.find((g) => g.stat && g.stat !== 'identity')
48
- if (!firstNonIdentity) return { data, geoms }
49
-
50
- const aggChannels = { y }
51
- if (x) aggChannels.x = x
52
- if (color) aggChannels.color = color
53
- aggChannels.frame = animate.by // 'frame' is not a value channel, so it becomes a group-by
54
-
55
- const aggregated = applyGeomStat(
56
- data,
57
- { stat: firstNonIdentity.stat, channels: aggChannels },
58
- helpers
59
- )
60
- const completeData = completeFrames(aggregated, { x, y, color }, animate.by)
61
-
62
- return { data: completeData, geoms: geoms.map((g) => ({ ...g, stat: 'identity' })) }
63
- })
64
-
65
- // Extract frames and compute stable domains from the full prepared dataset
66
- const rawFrames = $derived(extractFrames(prepared.data, animate.by))
67
- const frameKeys = $derived([...rawFrames.keys()])
68
-
69
- const channels = $derived({ x, y, color })
70
- const staticDomains = $derived(
71
- x && y ? computeStaticDomains(prepared.data, channels) : { xDomain: undefined, yDomain: undefined }
72
- )
73
-
74
- // Playback state
75
- let currentIndex = $state(0)
76
- let playing = $state(false)
77
- let speed = $state(1)
78
-
79
- // Current frame data already complete (all x/color combos present)
80
- const currentFrameData = $derived.by(() => {
81
- const key = frameKeys[currentIndex]
82
- return rawFrames.get(key) ?? []
83
- })
84
-
85
- // Reduced motion preference
86
- let prefersReducedMotion = $state(false)
87
- onMount(() => {
88
- if (typeof window.matchMedia !== 'function') return
89
- const mq = window.matchMedia('(prefers-reduced-motion: reduce)')
90
- prefersReducedMotion = mq.matches
91
- const handler = (e) => { prefersReducedMotion = e.matches }
92
- mq.addEventListener('change', handler)
93
- return () => mq.removeEventListener('change', handler)
94
- })
95
-
96
- // Animation loop
97
- const baseDuration = $derived(animate.duration ?? 800)
98
- const msPerFrame = $derived(Math.round(baseDuration / speed))
99
- let lastTime = 0
100
- let rafId = 0
101
-
102
- function advanceFrame() {
103
- currentIndex = currentIndex + 1
104
- if (currentIndex >= frameKeys.length) {
105
- if (animate.loop ?? false) currentIndex = 0
106
- else playing = false
107
- }
108
- }
109
-
110
- function tick(time) {
111
- if (!playing) return
112
- if (time - lastTime >= msPerFrame) {
113
- lastTime = time
114
- advanceFrame()
115
- if (!playing) return
116
- }
117
- rafId = requestAnimationFrame(tick)
118
- }
119
-
120
- $effect(() => {
121
- // Reading msPerFrame here makes it a tracked dependency — effect re-runs on speed changes,
122
- // which resets lastTime=0 to re-anchor frame pacing.
123
- const _ms = msPerFrame
124
- if (playing && !prefersReducedMotion) {
125
- lastTime = 0
126
- rafId = requestAnimationFrame(tick)
127
- } else {
128
- cancelAnimationFrame(rafId)
129
- }
130
- return () => cancelAnimationFrame(rafId)
131
- })
132
-
133
- // Reduced motion: step frames on interval instead
134
- let reducedInterval = 0
135
- $effect(() => {
136
- if (!playing || !prefersReducedMotion) {
137
- clearInterval(reducedInterval)
138
- return
139
- }
140
- reducedInterval = setInterval(() => {
141
- currentIndex = currentIndex + 1
142
- if (currentIndex >= frameKeys.length) {
143
- if (animate.loop ?? false) currentIndex = 0
144
- else { playing = false; clearInterval(reducedInterval) }
145
- }
146
- }, msPerFrame)
147
- return () => clearInterval(reducedInterval)
148
- })
149
-
150
- onDestroy(() => {
151
- cancelAnimationFrame(rafId)
152
- clearInterval(reducedInterval)
153
- })
154
-
155
- $effect(() => {
156
- const len = frameKeys.length
157
- if (currentIndex >= len && len > 0) {
158
- currentIndex = len - 1
159
- playing = false
160
- } else if (len === 0) {
161
- currentIndex = 0
162
- playing = false
163
- }
164
- })
165
-
166
- function handlePlay() { playing = true }
167
- function handlePause() { playing = false }
168
- function handleScrub(index) {
169
- playing = false
170
- currentIndex = index
171
- }
172
- function handleSpeed(s) { speed = s }
173
-
174
- // Build spec for the current frame, with static domain overrides
175
- const frameSpec = $derived({
176
- data: currentFrameData,
177
- x, y, color,
178
- geoms: prepared.geoms,
179
- xDomain: staticDomains.xDomain,
180
- yDomain: staticDomains.yDomain
181
- })
2
+ import { onMount, onDestroy } from 'svelte'
3
+ import { tweened } from 'svelte/motion'
4
+ import { sineInOut } from 'svelte/easing'
5
+ import { extractFrames, completeFrames, computeStaticDomains } from './lib/plot/frames.js'
6
+ import { applyGeomStat } from './lib/plot/stat.js'
7
+ import Timeline from './Plot/Timeline.svelte'
8
+ import PlotChart from './Plot.svelte'
9
+
10
+ /**
11
+ * @type {{
12
+ * data: Object[],
13
+ * animate: { by: string, duration?: number, loop?: boolean },
14
+ * x?: string,
15
+ * y?: string,
16
+ * color?: string,
17
+ * fill?: string,
18
+ * pattern?: string,
19
+ * symbol?: string,
20
+ * geom?: string,
21
+ * stat?: string,
22
+ * geoms?: import('./lib/plot/types.js').GeomSpec[],
23
+ * helpers?: import('./lib/plot/types.js').PlotHelpers,
24
+ * width?: number,
25
+ * height?: number,
26
+ * mode?: 'light' | 'dark',
27
+ * grid?: boolean,
28
+ * legend?: boolean,
29
+ * tween?: boolean,
30
+ * sorted?: boolean,
31
+ * dynamicDomain?: boolean,
32
+ * label?: boolean | string | ((data: Record<string, unknown>) => string),
33
+ * children?: import('svelte').Snippet
34
+ * }}
35
+ */
36
+ let {
37
+ data = [],
38
+ animate,
39
+ x,
40
+ y,
41
+ color,
42
+ fill = undefined,
43
+ pattern = undefined,
44
+ symbol = undefined,
45
+ geom = 'bar',
46
+ stat = 'identity',
47
+ geoms = [],
48
+ helpers = {},
49
+ width = 600,
50
+ height = 400,
51
+ mode = 'light',
52
+ grid = true,
53
+ legend = false,
54
+ tween = true,
55
+ sorted = false,
56
+ dynamicDomain = false,
57
+ label = false,
58
+ children
59
+ } = $props()
60
+
61
+ // Effective geom list: explicit array takes precedence; otherwise build from shorthand props
62
+ const effectiveGeoms = $derived(
63
+ geoms.length > 0
64
+ ? geoms
65
+ : [
66
+ {
67
+ type: geom,
68
+ stat,
69
+ ...(fill !== undefined && { fill }),
70
+ ...(pattern !== undefined && { pattern }),
71
+ ...(symbol !== undefined && { symbol })
72
+ }
73
+ ]
74
+ )
75
+
76
+ // Pre-aggregate and complete frames when any geom has a non-identity stat
77
+ const prepared = $derived.by(() => {
78
+ const firstNonIdentity = effectiveGeoms.find((g) => g.stat && g.stat !== 'identity')
79
+ if (!firstNonIdentity) return { data, geoms: effectiveGeoms }
80
+
81
+ const aggChannels = { y }
82
+ if (x) aggChannels.x = x
83
+ if (color) aggChannels.color = color
84
+ aggChannels.frame = animate.by
85
+
86
+ const aggregated = applyGeomStat(
87
+ data,
88
+ { stat: firstNonIdentity.stat, channels: aggChannels },
89
+ helpers
90
+ )
91
+ const completeData = completeFrames(aggregated, { x, y, color }, animate.by)
92
+ return { data: completeData, geoms: effectiveGeoms.map((g) => ({ ...g, stat: 'identity' })) }
93
+ })
94
+
95
+ // Extract frames and compute stable domains from the full prepared dataset
96
+ const rawFrames = $derived(extractFrames(prepared.data, animate.by))
97
+ const frameKeys = $derived([...rawFrames.keys()])
98
+
99
+ const channels = $derived({ x, y, color })
100
+ const staticDomains = $derived(
101
+ x && y
102
+ ? computeStaticDomains(prepared.data, channels)
103
+ : { xDomain: undefined, yDomain: undefined }
104
+ )
105
+
106
+ // Tweened x-domain for dynamic axis animation (opt-in via dynamicDomain prop)
107
+ const xDomainTween = tweened([0, 1], { duration: 0 })
108
+ let xDomainInitialized = false
109
+
110
+ // Playback state
111
+ let currentIndex = $state(0)
112
+ let playing = $state(false)
113
+ let speed = $state(1)
114
+
115
+ // Current frame data — already complete (all x/color combos present)
116
+ const currentFrameData = $derived.by(() => {
117
+ const key = frameKeys[currentIndex]
118
+ return rawFrames.get(key) ?? []
119
+ })
120
+
121
+ // Reduced motion preference
122
+ let prefersReducedMotion = $state(false)
123
+ onMount(() => {
124
+ if (typeof window.matchMedia !== 'function') return
125
+ const mq = window.matchMedia('(prefers-reduced-motion: reduce)')
126
+ prefersReducedMotion = mq.matches
127
+ const handler = (e) => { prefersReducedMotion = e.matches }
128
+ mq.addEventListener('change', handler)
129
+ return () => mq.removeEventListener('change', handler)
130
+ })
131
+
132
+ // Animation timing
133
+ const baseDuration = $derived(animate.duration ?? 800)
134
+ const msPerFrame = $derived(Math.round(baseDuration / speed))
135
+
136
+ // rAF-based frame timer — advances currentIndex every msPerFrame ms.
137
+ // Separate from the tween: the tween handles visual interpolation only.
138
+ let lastTime = 0
139
+ let rafId = 0
140
+
141
+ function advanceFrame() {
142
+ currentIndex = currentIndex + 1
143
+ if (currentIndex >= frameKeys.length) {
144
+ if (animate.loop ?? false) currentIndex = 0
145
+ else playing = false
146
+ }
147
+ }
148
+
149
+ function tick(time) {
150
+ if (!playing) return
151
+ if (time - lastTime >= msPerFrame) {
152
+ lastTime = time
153
+ advanceFrame()
154
+ if (!playing) return
155
+ }
156
+ rafId = requestAnimationFrame(tick)
157
+ }
158
+
159
+ $effect(() => {
160
+ // msPerFrame is a tracked dependency: re-runs on speed change, resetting lastTime=0
161
+ const _ms = msPerFrame
162
+ if (playing && !prefersReducedMotion) {
163
+ lastTime = 0
164
+ rafId = requestAnimationFrame(tick)
165
+ } else {
166
+ cancelAnimationFrame(rafId)
167
+ }
168
+ return () => cancelAnimationFrame(rafId)
169
+ })
170
+
171
+ // Reduced motion: step frames on interval instead of rAF
172
+ let reducedInterval = 0
173
+ $effect(() => {
174
+ if (!playing || !prefersReducedMotion) {
175
+ clearInterval(reducedInterval)
176
+ return
177
+ }
178
+ reducedInterval = setInterval(() => {
179
+ currentIndex = currentIndex + 1
180
+ if (currentIndex >= frameKeys.length) {
181
+ if (animate.loop ?? false) currentIndex = 0
182
+ else { playing = false; clearInterval(reducedInterval) }
183
+ }
184
+ }, msPerFrame)
185
+ return () => clearInterval(reducedInterval)
186
+ })
187
+
188
+ onDestroy(() => {
189
+ cancelAnimationFrame(rafId)
190
+ clearInterval(reducedInterval)
191
+ })
192
+
193
+ $effect(() => {
194
+ const len = frameKeys.length
195
+ if (currentIndex >= len && len > 0) {
196
+ currentIndex = len - 1
197
+ playing = false
198
+ } else if (len === 0) {
199
+ currentIndex = 0
200
+ playing = false
201
+ }
202
+ })
203
+
204
+ function handlePlay() { playing = true }
205
+ function handlePause() { playing = false }
206
+ function handleScrub(index) { playing = false; currentIndex = index }
207
+ function handleSpeed(s) { speed = s }
208
+
209
+ // Detect horizontal bar chart race: sorted=true AND y is a categorical string field
210
+ const isHorizontalRace = $derived.by(() => {
211
+ if (!sorted || !prepared.data.length) return false
212
+ const sample = prepared.data[0]
213
+ return y && typeof sample[y] === 'string'
214
+ })
215
+
216
+ // Number of unique entities (y categories) for horizontal race yDomain
217
+ const entityCount = $derived.by(() => {
218
+ if (!isHorizontalRace) return 0
219
+ return new Set(prepared.data.map((d) => d[y])).size
220
+ })
221
+
222
+ // Tweened display data — smoothly interpolates values between frames.
223
+ // Tween duration is 1.1× the frame interval so tweens always overlap:
224
+ // when the next frame fires, the previous tween is ~91% complete.
225
+ // displayTween.set() starts from the current in-flight value → seamless continuous motion.
226
+ const displayTween = tweened([], { duration: 0 })
227
+
228
+ $effect(() => {
229
+ const raw = currentFrameData
230
+ const xField = x
231
+ const yField = y
232
+
233
+ // Build display target for this frame
234
+ let target
235
+ if (isHorizontalRace) {
236
+ const ranked = raw.slice().sort((a, b) => Number(b[xField]) - Number(a[xField]))
237
+ const n = ranked.length
238
+ target = ranked.map((row, i) => ({
239
+ ...row,
240
+ _entity: row[yField],
241
+ _rank: n - 1 - i
242
+ }))
243
+ } else if (sorted) {
244
+ target = raw.slice().sort((a, b) => Number(b[yField]) - Number(a[yField]))
245
+ } else {
246
+ target = raw
247
+ }
248
+
249
+ // Tween duration slightly longer than frame interval → guaranteed overlap, no pause
250
+ const tweenDuration = Math.round(msPerFrame * 1.1)
251
+
252
+ if (!tween || prefersReducedMotion) {
253
+ displayTween.set(target, { duration: 0 })
254
+ } else if (isHorizontalRace) {
255
+ displayTween.set(target, {
256
+ duration: tweenDuration,
257
+ easing: sineInOut,
258
+ interpolate: (a, b) => {
259
+ const aMap = new Map(a.map((r) => [r._entity, r]))
260
+ return (t) =>
261
+ b.map((r) => {
262
+ const p = aMap.get(r._entity) ?? r
263
+ return {
264
+ ...r,
265
+ [xField]: Number(p[xField] ?? 0) * (1 - t) + Number(r[xField]) * t,
266
+ _rank: Number(p._rank ?? r._rank) * (1 - t) + Number(r._rank) * t
267
+ }
268
+ })
269
+ }
270
+ })
271
+ } else if (sorted) {
272
+ displayTween.set(target, {
273
+ duration: tweenDuration,
274
+ easing: sineInOut,
275
+ interpolate: (a, b) => {
276
+ const aMap = new Map(a.map((r) => [r[xField], r]))
277
+ return (t) =>
278
+ b.map((r) => {
279
+ const p = aMap.get(r[xField]) ?? r
280
+ return { ...r, [yField]: Number(p[yField] ?? 0) * (1 - t) + Number(r[yField]) * t }
281
+ })
282
+ }
283
+ })
284
+ } else {
285
+ // Unsorted: if y is categorical (string), key by y-value and lerp x (bar width).
286
+ // This keeps bars at stable band positions while widths animate smoothly.
287
+ const yCategorical = yField && raw.length > 0 && typeof raw[0][yField] === 'string'
288
+ if (yCategorical) {
289
+ displayTween.set(target, {
290
+ duration: tweenDuration,
291
+ easing: sineInOut,
292
+ interpolate: (a, b) => {
293
+ const aMap = new Map(a.map((r) => [r[yField], r]))
294
+ return (t) =>
295
+ b.map((r) => {
296
+ const p = aMap.get(r[yField]) ?? r
297
+ return { ...r, [xField]: Number(p[xField] ?? 0) * (1 - t) + Number(r[xField]) * t }
298
+ })
299
+ }
300
+ })
301
+ } else {
302
+ displayTween.set(target, {
303
+ duration: tweenDuration,
304
+ easing: sineInOut,
305
+ interpolate: (a, b) => (t) =>
306
+ b.map((r, i) => ({
307
+ ...r,
308
+ [yField]: Number(a[i]?.[yField] ?? 0) * (1 - t) + Number(r[yField]) * t
309
+ }))
310
+ })
311
+ }
312
+ }
313
+ })
314
+
315
+ // Tween the x-domain per frame for dynamic axis animation (opt-in).
316
+ // First update is instant to avoid a jarring jump when toggled.
317
+ $effect(() => {
318
+ if (!dynamicDomain || !x || !currentFrameData.length) {
319
+ if (!dynamicDomain) xDomainInitialized = false
320
+ return
321
+ }
322
+ const vals = currentFrameData.map((d) => Number(d[x])).filter((v) => !isNaN(v))
323
+ if (vals.length === 0) return
324
+ const max = Math.max(...vals)
325
+ xDomainTween.set([0, max], {
326
+ duration: xDomainInitialized ? Math.round(msPerFrame * 1.1) : 0,
327
+ easing: sineInOut
328
+ })
329
+ xDomainInitialized = true
330
+ })
331
+
332
+ // For horizontal race: inject orientation, label, and labelInside into each geom
333
+ const raceGeoms = $derived(
334
+ prepared.geoms.map((g) => ({
335
+ ...g,
336
+ ...(label && { label: '_entity' }),
337
+ options: {
338
+ ...(g.options ?? {}),
339
+ orientation: 'horizontal',
340
+ ...(label && { labelInside: true })
341
+ }
342
+ }))
343
+ )
344
+
345
+ const xDomainForFrame = $derived(
346
+ isHorizontalRace && dynamicDomain ? $xDomainTween : staticDomains.xDomain
347
+ )
348
+ const frameSpec = $derived({
349
+ data: $displayTween,
350
+ x,
351
+ y: isHorizontalRace ? '_rank' : y,
352
+ color,
353
+ geoms: isHorizontalRace ? raceGeoms : prepared.geoms,
354
+ xDomain: xDomainForFrame,
355
+ yDomain: isHorizontalRace ? [0, entityCount - 1] : staticDomains.yDomain,
356
+ orientation: isHorizontalRace ? 'horizontal' : undefined
357
+ })
182
358
  </script>
183
359
 
184
360
  <div data-plot-animated>
185
- <PlotChart
186
- spec={frameSpec}
187
- {helpers}
188
- {width}
189
- {height}
190
- {mode}
191
- {grid}
192
- {legend}
193
- >
194
- {@render children?.()}
195
- </PlotChart>
196
-
197
- <Timeline
198
- {frameKeys}
199
- {currentIndex}
200
- {playing}
201
- {speed}
202
- onplay={handlePlay}
203
- onpause={handlePause}
204
- onscrub={handleScrub}
205
- onspeed={handleSpeed}
206
- />
361
+ <PlotChart spec={frameSpec} {helpers} {width} {height} {mode} {grid} {legend}>
362
+ {@render children?.()}
363
+ </PlotChart>
364
+
365
+ <Timeline
366
+ {frameKeys}
367
+ {currentIndex}
368
+ {playing}
369
+ {speed}
370
+ onplay={handlePlay}
371
+ onpause={handlePause}
372
+ onscrub={handleScrub}
373
+ onspeed={handleSpeed}
374
+ />
207
375
  </div>
208
376
 
209
377
  <style>
210
- [data-plot-animated] {
211
- display: flex;
212
- flex-direction: column;
213
- width: 100%;
214
- }
378
+ [data-plot-animated] {
379
+ display: flex;
380
+ flex-direction: column;
381
+ width: 100%;
382
+ }
215
383
  </style>