p1-charts 0.1.0 → 0.3.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.
Files changed (160) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +114 -2
  3. package/dist/CategoryBarChart-1Kn3Vozc.js +580 -0
  4. package/dist/CategoryBarChart-1Kn3Vozc.js.map +1 -0
  5. package/dist/ChartFrame-B1bVFM2E.js +403 -0
  6. package/dist/ChartFrame-B1bVFM2E.js.map +1 -0
  7. package/dist/{Heatmap-C1XcTUg1.js → Heatmap-CFC753mV.js} +278 -272
  8. package/dist/Heatmap-CFC753mV.js.map +1 -0
  9. package/dist/{PieLegend-BZsv9IbF.js → PieLegend-CbpjaOJH.js} +94 -111
  10. package/dist/PieLegend-CbpjaOJH.js.map +1 -0
  11. package/dist/PolarChart-hcNTWKfJ.js +450 -0
  12. package/dist/PolarChart-hcNTWKfJ.js.map +1 -0
  13. package/dist/Sparkline-BApLVWfg.js +110 -0
  14. package/dist/Sparkline-BApLVWfg.js.map +1 -0
  15. package/dist/{TimeSeriesChart-tYmzRNzV.js → TimeSeriesChart-BzeHEtQl.js} +553 -487
  16. package/dist/TimeSeriesChart-BzeHEtQl.js.map +1 -0
  17. package/dist/category.d.ts +2 -2
  18. package/dist/category.d.ts.map +1 -1
  19. package/dist/category.js +1 -1
  20. package/dist/charts/CategoryBarChart/index.d.ts +1 -1
  21. package/dist/charts/CategoryBarChart/index.d.ts.map +1 -1
  22. package/dist/charts/Heatmap/index.d.ts.map +1 -1
  23. package/dist/charts/PolarChart/index.d.ts.map +1 -1
  24. package/dist/charts/ScatterChart/index.d.ts +1 -1
  25. package/dist/charts/ScatterChart/index.d.ts.map +1 -1
  26. package/dist/charts/Sparkline/index.d.ts +5 -2
  27. package/dist/charts/Sparkline/index.d.ts.map +1 -1
  28. package/dist/charts/TimeSeriesChart/index.d.ts +1 -1
  29. package/dist/charts/TimeSeriesChart/index.d.ts.map +1 -1
  30. package/dist/components/ChartFrame/index.d.ts +7 -0
  31. package/dist/components/ChartFrame/index.d.ts.map +1 -0
  32. package/dist/components/ChartStory/index.d.ts +7 -0
  33. package/dist/components/ChartStory/index.d.ts.map +1 -0
  34. package/dist/components/HeatmapCells/index.d.ts +1 -1
  35. package/dist/components/HeatmapCells/index.d.ts.map +1 -1
  36. package/dist/{css-C-rsk7-l.js → css-BtFQ2bM4.js} +2 -2
  37. package/dist/{css-C-rsk7-l.js.map → css-BtFQ2bM4.js.map} +1 -1
  38. package/dist/heatmap.js +1 -1
  39. package/dist/hooks/useMarkMemory.d.ts +9 -0
  40. package/dist/hooks/useMarkMemory.d.ts.map +1 -0
  41. package/dist/hooks/usePieTween.d.ts.map +1 -1
  42. package/dist/hooks/useSteps.d.ts +4 -0
  43. package/dist/hooks/useSteps.d.ts.map +1 -0
  44. package/dist/hooks/useTween.d.ts +12 -0
  45. package/dist/hooks/useTween.d.ts.map +1 -0
  46. package/dist/index.d.ts +14 -3
  47. package/dist/index.d.ts.map +1 -1
  48. package/dist/index.js +122 -118
  49. package/dist/index.js.map +1 -1
  50. package/dist/motion.utils-DFoqptDi.js +55 -0
  51. package/dist/motion.utils-DFoqptDi.js.map +1 -0
  52. package/dist/pie.js +1 -1
  53. package/dist/scatter.js +1 -1
  54. package/dist/series.d.ts +1 -1
  55. package/dist/series.d.ts.map +1 -1
  56. package/dist/series.js +1 -1
  57. package/dist/{tooltip.utils-D7xaBSUK.js → shared-C1pGJV4T.js} +3 -7
  58. package/dist/shared-C1pGJV4T.js.map +1 -0
  59. package/dist/sparkline.d.ts +1 -1
  60. package/dist/sparkline.d.ts.map +1 -1
  61. package/dist/sparkline.js +2 -2
  62. package/dist/story.d.ts +11 -0
  63. package/dist/story.d.ts.map +1 -0
  64. package/dist/story.js +7 -0
  65. package/dist/theme.js +3 -3
  66. package/dist/{theme.utils-CP1XtGIe.js → theme.utils-DgmWROoe.js} +40 -20
  67. package/dist/theme.utils-DgmWROoe.js.map +1 -0
  68. package/dist/tooltip.utils-CXD_NapA.js +9 -0
  69. package/dist/tooltip.utils-CXD_NapA.js.map +1 -0
  70. package/dist/types/category.d.ts +51 -2
  71. package/dist/types/category.d.ts.map +1 -1
  72. package/dist/types/heatmap.d.ts +3 -0
  73. package/dist/types/heatmap.d.ts.map +1 -1
  74. package/dist/types/heatmapParts.d.ts +2 -0
  75. package/dist/types/heatmapParts.d.ts.map +1 -1
  76. package/dist/types/motion.d.ts +31 -0
  77. package/dist/types/motion.d.ts.map +1 -0
  78. package/dist/types/pie.d.ts +3 -4
  79. package/dist/types/pie.d.ts.map +1 -1
  80. package/dist/types/polar.d.ts +10 -1
  81. package/dist/types/polar.d.ts.map +1 -1
  82. package/dist/types/scatter.d.ts +16 -0
  83. package/dist/types/scatter.d.ts.map +1 -1
  84. package/dist/types/sparkline.d.ts +3 -0
  85. package/dist/types/sparkline.d.ts.map +1 -1
  86. package/dist/types/story.d.ts +73 -0
  87. package/dist/types/story.d.ts.map +1 -0
  88. package/dist/types/timeSeries.d.ts +31 -0
  89. package/dist/types/timeSeries.d.ts.map +1 -1
  90. package/dist/{useChartTheme-B06p_jvu.js → useChartTheme-KKtc1C4K.js} +2 -2
  91. package/dist/{useChartTheme-B06p_jvu.js.map → useChartTheme-KKtc1C4K.js.map} +1 -1
  92. package/dist/useControllable-Crsr0byh.js +11 -0
  93. package/dist/useControllable-Crsr0byh.js.map +1 -0
  94. package/dist/useMarkMemory-CLNY6TtT.js +15 -0
  95. package/dist/useMarkMemory-CLNY6TtT.js.map +1 -0
  96. package/dist/useTween-B0G0CcvM.js +46 -0
  97. package/dist/useTween-B0G0CcvM.js.map +1 -0
  98. package/dist/utils/category.utils.d.ts +48 -7
  99. package/dist/utils/category.utils.d.ts.map +1 -1
  100. package/dist/utils/color.utils.d.ts +9 -0
  101. package/dist/utils/color.utils.d.ts.map +1 -1
  102. package/dist/utils/csv.utils.d.ts +6 -0
  103. package/dist/utils/csv.utils.d.ts.map +1 -0
  104. package/dist/utils/motion.utils.d.ts +25 -0
  105. package/dist/utils/motion.utils.d.ts.map +1 -1
  106. package/dist/utils/pieTween.utils.d.ts +1 -1
  107. package/dist/utils/pieTween.utils.d.ts.map +1 -1
  108. package/dist/utils/sparkline.utils.d.ts +15 -0
  109. package/dist/utils/sparkline.utils.d.ts.map +1 -1
  110. package/dist/{visibility.utils-nMI5a_Et.js → visibility.utils-wuc3ZS8D.js} +18 -25
  111. package/dist/visibility.utils-wuc3ZS8D.js.map +1 -0
  112. package/package.json +10 -3
  113. package/src/category.ts +14 -2
  114. package/src/charts/CategoryBarChart/index.tsx +462 -52
  115. package/src/charts/Heatmap/index.tsx +4 -0
  116. package/src/charts/PolarChart/index.tsx +159 -21
  117. package/src/charts/ScatterChart/index.tsx +143 -16
  118. package/src/charts/Sparkline/index.tsx +54 -7
  119. package/src/charts/TimeSeriesChart/index.tsx +117 -2
  120. package/src/components/ChartFrame/index.tsx +180 -0
  121. package/src/components/ChartStory/index.tsx +184 -0
  122. package/src/components/HeatmapCells/index.tsx +5 -2
  123. package/src/hooks/useMarkMemory.ts +29 -0
  124. package/src/hooks/usePieTween.ts +9 -44
  125. package/src/hooks/useSteps.ts +77 -0
  126. package/src/hooks/useTween.ts +112 -0
  127. package/src/index.ts +32 -1
  128. package/src/series.ts +4 -0
  129. package/src/sparkline.ts +1 -1
  130. package/src/story.ts +19 -0
  131. package/src/types/category.ts +58 -2
  132. package/src/types/heatmap.ts +3 -0
  133. package/src/types/heatmapParts.ts +2 -0
  134. package/src/types/motion.ts +35 -0
  135. package/src/types/pie.ts +3 -3
  136. package/src/types/polar.ts +14 -1
  137. package/src/types/scatter.ts +16 -0
  138. package/src/types/sparkline.ts +3 -0
  139. package/src/types/story.ts +103 -0
  140. package/src/types/timeSeries.ts +35 -0
  141. package/src/utils/category.utils.ts +343 -43
  142. package/src/utils/color.utils.ts +48 -0
  143. package/src/utils/csv.utils.ts +28 -0
  144. package/src/utils/motion.utils.ts +124 -0
  145. package/src/utils/pieTween.utils.ts +1 -2
  146. package/src/utils/sparkline.utils.ts +69 -0
  147. package/dist/CategoryBarChart-CV58kvIr.js +0 -182
  148. package/dist/CategoryBarChart-CV58kvIr.js.map +0 -1
  149. package/dist/Heatmap-C1XcTUg1.js.map +0 -1
  150. package/dist/PieLegend-BZsv9IbF.js.map +0 -1
  151. package/dist/PolarChart-D_ULWctY.js +0 -282
  152. package/dist/PolarChart-D_ULWctY.js.map +0 -1
  153. package/dist/Sparkline-DtNhxGVo.js +0 -67
  154. package/dist/Sparkline-DtNhxGVo.js.map +0 -1
  155. package/dist/TimeSeriesChart-tYmzRNzV.js.map +0 -1
  156. package/dist/motion.utils-C1eaZJdQ.js +0 -9
  157. package/dist/motion.utils-C1eaZJdQ.js.map +0 -1
  158. package/dist/theme.utils-CP1XtGIe.js.map +0 -1
  159. package/dist/tooltip.utils-D7xaBSUK.js.map +0 -1
  160. package/dist/visibility.utils-nMI5a_Et.js.map +0 -1
package/CHANGELOG.md ADDED
@@ -0,0 +1,28 @@
1
+ # Changelog
2
+
3
+ ## 0.3.0
4
+
5
+ Motion, stories and chart furniture, in the spirit of Flourish's built-in animation and storytelling.
6
+
7
+ ### Added
8
+
9
+ - **`animate` on every SVG chart**: `CategoryBarChart`, `ScatterChart`, `PolarChart`, `Sparkline`, `Heatmap`, plus `PieChart` as before. It takes `true` (default), `false`, or `{ duration, easing, stagger, appear }`. Marks are matched by a stable key and tween between data states. New marks grow in and removed marks shrink out. Reduced motion always jumps to the final frame. The first render is final unless `appear` is set.
10
+ - **Axis motion**: value ticks on `CategoryBarChart`, and x/y ticks and grid lines on `ScatterChart`, slide and fade between scales.
11
+ - **Scrolling sparkline**: when new `Sparkline` data is the old data moved along (a live window), the line scrolls instead of morphing.
12
+ - **Racing bars**: `CategoryBarChart` `sort="descending" | "ascending"` ranks categories by total. With `animate`, bars glide to their new rank. `onSelect` still reports the index in your `categories`.
13
+ - **`ChartStory`**: steps a chart through states with prev/next, play/pause, dots or a slider, captions, autoplay, interval and loop. Autoplay is off under reduced motion, and picking a step pauses.
14
+ - **`useSteps`**: the stepping logic on its own, for custom controls or scroll-driven steps.
15
+ - **`ChartFrame`**: title, subtitle, a summary for screen readers, source and notes around any chart. With `data`, it adds "Show data" (a real table) and "Download CSV".
16
+ - **Helpers**: `useTween` and `useMarkMemory` (motion for custom SVG marks); `toCsv` and `downloadCsv` (RFC 4180, with spreadsheet formula injection defused); `readableInk` and `contrastRatio` (WCAG contrast for labels on marks); `sparklineShapes` and `shiftOffset`; easings `linear`, `easeOutCubic`, `easeInOutCubic`.
17
+ - **New subpath**: `p1-charts/story`.
18
+
19
+ ### Changed
20
+
21
+ - `PieAnimate` is now an alias of the shared `ChartAnimate` type. Existing values still work.
22
+ - `CategoryBarChart` bars are keyed by series and category label, and carry `data-key`. `data-category` is the displayed position, which differs from the input index only when `sort` is set.
23
+ - `ScatterChart` ticks and `CategoryBarChart` category and value ticks are keyed by value or label rather than position.
24
+ - Themed `Heatmap` cells carry a `transition` style for fill and opacity. Unstyled cells carry none. Pass `animate={false}` to turn it off.
25
+
26
+ ### Not animated
27
+
28
+ - The canvas charts (`TimeSeriesChart`, `LineChart`, `BarChart`, `HistogramChart`, `CandlestickChart`). Lightweight Charts redraws everything on each `setData`.
package/README.md CHANGED
@@ -27,6 +27,7 @@ Subpath imports keep a page from loading charts it does not draw:
27
27
  | `p1-charts/category` | `CategoryBarChart`, `bin` |
28
28
  | `p1-charts/sparkline` | `Sparkline` |
29
29
  | `p1-charts/theme` | `p1Theme`, `p1ThemeFromCss`, `createTheme` |
30
+ | `p1-charts/story` | `ChartStory`, `ChartFrame`, `useSteps`, `useTween`, `useMarkMemory`, `toCsv`, `readableInk` |
30
31
 
31
32
  Peer dependencies: `react`, `react-dom` (>= 18), and `lightweight-charts` (^5.2.1). The sparkline, pie, heatmap, scatter, and category entries do not mount a Lightweight Charts instance. `lightweight-charts` stays a peer so the app and this package share one copy.
32
33
 
@@ -47,11 +48,12 @@ The package is unscoped (`p1-charts`). `prepack` builds `dist/` before the tarba
47
48
  | Fill between two value lines (P10–P90) | `TimeSeriesChart` `ribbons` |
48
49
  | Full-height tint over a time range (a regime) | `LineChart` `bands` |
49
50
  | One series, terminal chrome | `LineChart`, `BarChart`, `HistogramChart`, `CandlestickChart` |
50
- | Grouped, stacked, or overlaid category columns | `CategoryBarChart` |
51
+ | Grouped, stacked, or overlaid category columns, horizontal or on two axes | `CategoryBarChart` |
51
52
  | Statistical histogram | `bin()`, then `CategoryBarChart` |
52
53
  | Columns on a time axis | `BarChart` or `HistogramChart` |
53
54
  | Numeric x and y | `ScatterChart` |
54
55
  | Wind rose | `PolarChart` (default `mode="bar"`) |
56
+ | Radar polygon | `PolarChart` `mode="line"` |
55
57
  | Angle and radius points | `PolarChart` `mode="scatter"` |
56
58
  | Two categorical axes | `Heatmap` |
57
59
  | Shares of a whole | `PieChart` |
@@ -99,8 +101,13 @@ Points are `{ time, value }`. `time` is a unix timestamp in seconds, an ISO stri
99
101
  | `extraTooltipRows` | `(unixSeconds) => rows` appended after the series rows |
100
102
  | `renderTooltip` | Replaces the row list. The time heading still renders |
101
103
  | `chartOptions` | Deep-merged on top of the profile options, after `autoSize: true` |
104
+ | `ranges` | Full-height bands. `hatch` is a colour, or `false` for a fill only. This is the forecast region, not a ribbon between two lines. Endpoints are times. On an ordinal axis pass the unix-day number (`index * 86400`), because the band does not look up category labels |
105
+ | `guides` | Dashed horizontal lines at a value, on the series that shares `scale`. The price scale includes them, so a threshold above the series stays visible |
106
+ | `onPointClick` | `{ time, points }` for the series that have a value at that time |
102
107
  | `ariaLabel` | Default `"Time series chart"`. The canvas is `role="img"` |
103
108
 
109
+ The time scale is fitted to the data after the series are drawn. A short series fills the frame.
110
+
104
111
  The root carries `data-profile` and `data-axis`. The tooltip carries `data-part="tooltip"`, `tooltip-time`, `tooltip-row`, and `swatch` (`data-swatch` is `bar` for a histogram and `line` otherwise). `formatTime`, `formatValue`, `extraTooltipRows`, and `renderTooltip` update without rebuilding the chart.
105
112
 
106
113
  An ordinal axis takes category labels. Point `time` is the label or a 0-based index. Each step is one unix day (`86400` seconds) so the scale can place them. Tick marks and the crosshair both print the category label.
@@ -133,10 +140,20 @@ Square axis and crosshair labels are a `roundRect` patch scoped to the chart ele
133
140
  | Behaviour | Detail |
134
141
  | --- | --- |
135
142
  | `mode` | `"group"` (default), `"stack"`, or `"overlay"`. Overlay bars share a slot at opacity `0.72`. Stack separates positive and negative runs |
143
+ | `orientation` | `"vertical"` (default) or `"horizontal"`. Horizontal puts the categories on the vertical axis. Arrow keys follow that axis |
144
+ | `series[].scale` | `"left"` (default) or `"right"`. A right scale is a second value axis. Each scale has its own extent |
145
+ | `series[].data` | A number, or `{ value, color?, label? }`. `label` is drawn outside that bar |
146
+ | `domain`, `rightDomain` | `{ min?, max? }` fixes an extent instead of fitting the data |
147
+ | `reference`, `references` | Dashed lines across the plot at `value`, with an optional `label`. Both are drawn |
148
+ | `bands` | A tint between `from` and `to`, behind the bars |
149
+ | `activeIndex` | Category marked when the pointer is not over a bar |
150
+ | `onSelect` | Called with the category label and its index in `categories` when a bar is clicked or chosen from the keyboard. The index ignores `sort` |
151
+ | `sort` | `"none"` (default), `"descending"` or `"ascending"` by each category's total across series. Ties keep input order |
152
+ | `animate` | Bars and category ticks tween between data states, keyed by series and category label, so a sorted chart races. See [Motion](#motion) |
136
153
  | Keyboard | Left and right move the active category and stop at the ends |
137
154
  | Pointer | Entering a bar selects its category |
138
155
  | Tooltip | Always shows the active category. `formatValue(seriesId, value)` formats each row. `renderTooltip(category, rows)` replaces the default |
139
- | Parts | Root `data-mode`. Bars are `data-part="bar"` with `data-series`, `data-category`, and `data-active`. Also `axis`, `tick`, `tooltip`, `tooltip-time`, `tooltip-row` |
156
+ | Parts | Root `data-mode`. Bars are `data-part="bar"` with `data-key` (the category label), `data-series`, `data-category` (displayed position), and `data-active`. Also `axis`, `tick`, `tooltip`, `tooltip-time`, `tooltip-row` |
140
157
  | Label | `ariaLabel` defaults to `"Bar chart"` |
141
158
 
142
159
  `bin(samples, options?)` turns raw observations into `{ from, to, count, label }[]`. The count defaults to Sturges' rule. `bins` sets an equal-width count. `min` and `max` set the domain. `edges` are explicit boundaries: a value lands in `[edge[i], edge[i + 1])`, and the last edge is inclusive. An empty sample list returns `[]`. `HistogramChart` draws columns on a time axis.
@@ -301,6 +318,101 @@ Selection props do nothing until `selectionMode` is set, the same as React Aria.
301
318
 
302
319
  Cells carry `data-step` (1 to N, 0 for a gap), `data-missing`, `data-dimmed`, `data-filtered`, `data-selected` and `data-extreme`; the root carries `data-emphasis`. Style them with the theme's `heatmap` slot (`gap`, `dimOpacity`, `filteredOpacity`, `missing`, `active`, `focus`, `selection`, `extreme`, `valueInk`), `classNames` / `styles`, or CSS on those attributes; `unstyled` emits no fills at all. Below 14px per cell the grid scrolls sideways inside its root instead of shrinking. `rangeStats`, `normaliseRange`, `extremes`, `heatmapLayout`, `useHeatmapState`, `useHeatmapSelection` and `useHeatmapSteps` are exported for a custom renderer.
303
320
 
321
+ ## Motion
322
+
323
+ Every SVG chart takes `animate`, and it is on by default. When the data changes, each mark moves from where it was drawn to where it belongs. Marks are matched by a stable key, so a bar keeps its identity when it changes rank. The first render draws the final frame. `prefers-reduced-motion: reduce` always jumps straight to it.
324
+
325
+ ```tsx
326
+ <CategoryBarChart animate={false} … />
327
+ <ScatterChart animate={{ duration: 600, stagger: 12 }} … />
328
+ <CategoryBarChart animate={{ appear: true }} … /> // grow from the baseline on mount
329
+ ```
330
+
331
+ | Option | Default | Detail |
332
+ | --- | --- | --- |
333
+ | `duration` | `240` | Milliseconds per mark |
334
+ | `easing` | `easeInOutCubic` | `(t) => number`. `linear`, `easeOutCubic` and `easeInOutCubic` are exported |
335
+ | `stagger` | `0` | Delay between successive marks |
336
+ | `appear` | `false` | Tween in from the baseline on first mount |
337
+
338
+ | Chart | What moves | Key | A new mark | A removed mark |
339
+ | --- | --- | --- | --- | --- |
340
+ | `CategoryBarChart` | Bar x, y, width and height; category labels; value-axis ticks | `series:category label` | Grows from the zero line, clamped to the axis | Shrinks back to the zero line |
341
+ | `ScatterChart` | Point position and radius, lines through them; x and y ticks and grid lines | `series:index` | Grows from radius 0 in place | Shrinks to radius 0 |
342
+ | `PolarChart` | Wedge and radar vertex radius; scatter position | `series:category` or `series:index` | Grows from the centre | Returns to the centre |
343
+ | `Sparkline` | Each value, so the scale moves with it. A window that slid along scrolls | absolute position | Slides in from the right, or appears in place | Slides out to the left |
344
+ | `PieChart` | Slice angles (as before) | slice key | Opens from its start angle | Dropped |
345
+ | `Heatmap` | Cell fill and opacity, through a CSS transition with the same easing | cell | | |
346
+
347
+ Axis ticks move like a D3 axis. A tick that stays slides to its new place. A new tick fades in from where its value sat on the old scale. A tick that goes fades out towards where its value sits on the new scale. At rest, nothing carries an `opacity` attribute.
348
+
349
+ A leaving mark keeps `data-part` and gains `data-leaving` and `pointer-events="none"`, so tooltips, keys and selection only ever see live data. `Sparkline` scrolls when the new values are the old ones moved along by k places, with at least two values in common. Anything else tweens value by value. The heatmap samples `easing` into CSS `linear()`, and draws no transition when `unstyled`, so your CSS decides.
350
+
351
+ The canvas charts (`TimeSeriesChart`, line, bar, histogram and candlestick) do not tween, because Lightweight Charts redraws everything on every `setData`. Live ticks there keep the existing price flash.
352
+
353
+ `useTween(frames, animate, { enter, exit })` is exported for a custom SVG mark. Pass `{ [key]: number[] }` and draw what it returns. While a removed key moves to `exit`, it stays in the returned frame. `useMarkMemory(current, drawn)` remembers how to draw each mark after its data is gone.
354
+
355
+ ## Stories
356
+
357
+ `ChartStory` steps a chart through states, such as slides with captions or a time slider. The chart stays mounted between steps, so `animate` carries each change. Combined with `sort` it makes a racing bar chart.
358
+
359
+ ```tsx
360
+ <ChartStory steps={years} controls="slider" loop interval={900} stepLabel={String}>
361
+ {(year) => (
362
+ <CategoryBarChart
363
+ orientation="horizontal"
364
+ sort="descending"
365
+ categories={ports}
366
+ series={[{ id: "teu", name: "TEU", data: byYear[year] }]}
367
+ animate={{ duration: 600 }}
368
+ />
369
+ )}
370
+ </ChartStory>
371
+
372
+ <ChartStory steps={slides} caption={(slide) => slide.text}>
373
+ {(slide) => <ScatterChart series={slide.series} />}
374
+ </ChartStory>
375
+ ```
376
+
377
+ | Behaviour | Detail |
378
+ | --- | --- |
379
+ | `controls` | `"dots"` (default) for a few slides, `"slider"` to scrub, `"none"` to drive it yourself. Prev, next and play/pause are always shown with dots or slider |
380
+ | `index`, `defaultIndex`, `onIndexChange` | Controlled or uncontrolled step |
381
+ | `autoplay`, `interval`, `loop` | Off by default. `interval` is 3000ms. Without `loop`, play stops on the last step, and pressing play there starts again from the first. Reduced motion never autoplays. Picking a dot or moving the slider pauses |
382
+ | `caption(step, index)` | Shown above the chart. It is `aria-live="polite"` while paused and silent while playing |
383
+ | `stepLabel(step, index)` | Names each dot, the slider value (`aria-valuetext`) and the position readout. Default `"Step n"` |
384
+ | Accessibility | The root is a `section` with `aria-roledescription="carousel"`. The stage is a group labelled `"<label>, n of N"` and described by the caption |
385
+ | Parts | `root`, `caption`, `stage`, `controls`, `play`, `prev`, `next`, `dots`, `dot` (`aria-current="step"`), `slider`, `position`. `classNames`, `styles` and `unstyled` work as on the charts |
386
+
387
+ `useSteps({ count, autoplay, interval, loop, … })` returns `{ index, playing, next, prev, goTo, play, pause, toggle, isFirst, isLast }` for your own controls, for example to drive scroll-linked steps from an `IntersectionObserver`.
388
+
389
+ ## Frame, data table and CSV
390
+
391
+ `ChartFrame` wraps any chart in a `figure` with a title, a subtitle, a source line and notes. Given `data`, it also adds a table view and a CSV download.
392
+
393
+ ```tsx
394
+ <ChartFrame
395
+ title="Container throughput by port"
396
+ subtitle="Thousand TEU, 2025"
397
+ summary="Sines handles twice the volume of any other port."
398
+ source="Port authority"
399
+ data={{ columns: ["Port", "TEU"], rows: [["Sines", 1800], ["Leixões", 700]] }}
400
+ filename="throughput.csv"
401
+ >
402
+ <CategoryBarChart … />
403
+ </ChartFrame>
404
+ ```
405
+
406
+ | Behaviour | Detail |
407
+ | --- | --- |
408
+ | Title | `h3` by default (`level` 2–6). It labels the `figure` |
409
+ | `subtitle`, `summary` | Both describe the `figure`. `summary` is visible to screen readers only |
410
+ | `source`, `note` | Footer lines. `source` is printed as `"Source: …"` |
411
+ | `data` | `{ columns, rows }`. "Show data" toggles a real `table` (first column is a row header). "Download CSV" saves `filename` (default `data.csv`) |
412
+ | Parts | `root`, `header`, `title`, `subtitle`, `summary`, `body`, `footer`, `source`, `note`, `actions`, `table-toggle`, `download`, `table` |
413
+
414
+ `toCsv(data)` writes RFC 4180 CSV with CRLF line ends. Text starting with `=`, `+`, `-` or `@` is prefixed with `'`, so a spreadsheet does not run it as a formula. `downloadCsv(data, filename)` saves the CSV with a UTF-8 BOM. `readableInk(background, candidates?)` returns the candidate with the highest WCAG contrast against `background` (default black or white), for labels drawn on marks. `contrastRatio(a, b)` gives the ratio itself.
415
+
304
416
  ## Development
305
417
 
306
418
  ```bash