p1-charts 0.2.0 → 0.4.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 (168) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/README.md +158 -4
  3. package/dist/CategoryBarChart-KYzsjGwg.js +715 -0
  4. package/dist/CategoryBarChart-KYzsjGwg.js.map +1 -0
  5. package/dist/ChartFrame-DOEsou-R.js +403 -0
  6. package/dist/ChartFrame-DOEsou-R.js.map +1 -0
  7. package/dist/ChartLegend-B8ZmIG2y.js +46 -0
  8. package/dist/ChartLegend-B8ZmIG2y.js.map +1 -0
  9. package/dist/{Heatmap-C1XcTUg1.js → Heatmap-Bwhf305C.js} +278 -272
  10. package/dist/Heatmap-Bwhf305C.js.map +1 -0
  11. package/dist/{PieLegend-BZsv9IbF.js → PieLegend-16E6W10x.js} +94 -111
  12. package/dist/PieLegend-16E6W10x.js.map +1 -0
  13. package/dist/PolarChart-C_vPz-3K.js +489 -0
  14. package/dist/PolarChart-C_vPz-3K.js.map +1 -0
  15. package/dist/Sparkline-BApLVWfg.js +110 -0
  16. package/dist/Sparkline-BApLVWfg.js.map +1 -0
  17. package/dist/{TimeSeriesChart-BIwJxgnD.js → TimeSeriesChart-BZMLERDZ.js} +530 -529
  18. package/dist/{TimeSeriesChart-BIwJxgnD.js.map → TimeSeriesChart-BZMLERDZ.js.map} +1 -1
  19. package/dist/category.d.ts +5 -2
  20. package/dist/category.d.ts.map +1 -1
  21. package/dist/category.js +4 -3
  22. package/dist/charts/CategoryBarChart/index.d.ts +3 -1
  23. package/dist/charts/CategoryBarChart/index.d.ts.map +1 -1
  24. package/dist/charts/Heatmap/index.d.ts.map +1 -1
  25. package/dist/charts/PolarChart/index.d.ts.map +1 -1
  26. package/dist/charts/ScatterChart/index.d.ts +1 -1
  27. package/dist/charts/ScatterChart/index.d.ts.map +1 -1
  28. package/dist/charts/Sparkline/index.d.ts +5 -2
  29. package/dist/charts/Sparkline/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/ChartLegend/index.d.ts +13 -0
  33. package/dist/components/ChartLegend/index.d.ts.map +1 -0
  34. package/dist/components/ChartStory/index.d.ts +7 -0
  35. package/dist/components/ChartStory/index.d.ts.map +1 -0
  36. package/dist/components/HeatmapCells/index.d.ts +1 -1
  37. package/dist/components/HeatmapCells/index.d.ts.map +1 -1
  38. package/dist/{css-C-rsk7-l.js → css-BTZA9hea.js} +2 -2
  39. package/dist/{css-C-rsk7-l.js.map → css-BTZA9hea.js.map} +1 -1
  40. package/dist/heatmap.js +1 -1
  41. package/dist/hooks/useMarkMemory.d.ts +9 -0
  42. package/dist/hooks/useMarkMemory.d.ts.map +1 -0
  43. package/dist/hooks/usePieTween.d.ts.map +1 -1
  44. package/dist/hooks/useSteps.d.ts +4 -0
  45. package/dist/hooks/useSteps.d.ts.map +1 -0
  46. package/dist/hooks/useTween.d.ts +12 -0
  47. package/dist/hooks/useTween.d.ts.map +1 -0
  48. package/dist/index.d.ts +16 -1
  49. package/dist/index.d.ts.map +1 -1
  50. package/dist/index.js +122 -117
  51. package/dist/index.js.map +1 -1
  52. package/dist/motion.utils-DFoqptDi.js +55 -0
  53. package/dist/motion.utils-DFoqptDi.js.map +1 -0
  54. package/dist/pie.js +1 -1
  55. package/dist/scatter.d.ts +4 -1
  56. package/dist/scatter.d.ts.map +1 -1
  57. package/dist/scatter.js +3 -2
  58. package/dist/series.js +1 -1
  59. package/dist/{tooltip.utils-D7xaBSUK.js → shared-C1pGJV4T.js} +3 -7
  60. package/dist/shared-C1pGJV4T.js.map +1 -0
  61. package/dist/sparkline.d.ts +1 -1
  62. package/dist/sparkline.d.ts.map +1 -1
  63. package/dist/sparkline.js +2 -2
  64. package/dist/standalone/p1-charts.standalone.js +13 -0
  65. package/dist/standalone.d.ts +27 -0
  66. package/dist/standalone.d.ts.map +1 -0
  67. package/dist/story.d.ts +11 -0
  68. package/dist/story.d.ts.map +1 -0
  69. package/dist/story.js +7 -0
  70. package/dist/theme.js +3 -3
  71. package/dist/{theme.utils-CP1XtGIe.js → theme.utils-DF_e8LxQ.js} +132 -113
  72. package/dist/theme.utils-DF_e8LxQ.js.map +1 -0
  73. package/dist/tooltip.utils-CXD_NapA.js +9 -0
  74. package/dist/tooltip.utils-CXD_NapA.js.map +1 -0
  75. package/dist/types/category.d.ts +26 -0
  76. package/dist/types/category.d.ts.map +1 -1
  77. package/dist/types/heatmap.d.ts +3 -0
  78. package/dist/types/heatmap.d.ts.map +1 -1
  79. package/dist/types/heatmapParts.d.ts +2 -0
  80. package/dist/types/heatmapParts.d.ts.map +1 -1
  81. package/dist/types/motion.d.ts +31 -0
  82. package/dist/types/motion.d.ts.map +1 -0
  83. package/dist/types/pie.d.ts +3 -4
  84. package/dist/types/pie.d.ts.map +1 -1
  85. package/dist/types/polar.d.ts +3 -0
  86. package/dist/types/polar.d.ts.map +1 -1
  87. package/dist/types/scatter.d.ts +34 -0
  88. package/dist/types/scatter.d.ts.map +1 -1
  89. package/dist/types/sparkline.d.ts +3 -0
  90. package/dist/types/sparkline.d.ts.map +1 -1
  91. package/dist/types/story.d.ts +73 -0
  92. package/dist/types/story.d.ts.map +1 -0
  93. package/dist/{useChartTheme-B06p_jvu.js → useChartTheme-D0bQ3LQq.js} +2 -2
  94. package/dist/{useChartTheme-B06p_jvu.js.map → useChartTheme-D0bQ3LQq.js.map} +1 -1
  95. package/dist/useControllable-Crsr0byh.js +11 -0
  96. package/dist/useControllable-Crsr0byh.js.map +1 -0
  97. package/dist/useMarkMemory-CLNY6TtT.js +15 -0
  98. package/dist/useMarkMemory-CLNY6TtT.js.map +1 -0
  99. package/dist/useTween-B0G0CcvM.js +46 -0
  100. package/dist/useTween-B0G0CcvM.js.map +1 -0
  101. package/dist/utils/category.utils.d.ts +15 -1
  102. package/dist/utils/category.utils.d.ts.map +1 -1
  103. package/dist/utils/color.utils.d.ts +9 -0
  104. package/dist/utils/color.utils.d.ts.map +1 -1
  105. package/dist/utils/csv.utils.d.ts +6 -0
  106. package/dist/utils/csv.utils.d.ts.map +1 -0
  107. package/dist/utils/motion.utils.d.ts +25 -0
  108. package/dist/utils/motion.utils.d.ts.map +1 -1
  109. package/dist/utils/pieTween.utils.d.ts +1 -1
  110. package/dist/utils/pieTween.utils.d.ts.map +1 -1
  111. package/dist/utils/scatter.utils.d.ts +17 -1
  112. package/dist/utils/scatter.utils.d.ts.map +1 -1
  113. package/dist/utils/sparkline.utils.d.ts +15 -0
  114. package/dist/utils/sparkline.utils.d.ts.map +1 -1
  115. package/dist/utils/theme.utils.d.ts +1 -1
  116. package/dist/utils/theme.utils.d.ts.map +1 -1
  117. package/dist/{visibility.utils-nMI5a_Et.js → visibility.utils-wuc3ZS8D.js} +18 -25
  118. package/dist/visibility.utils-wuc3ZS8D.js.map +1 -0
  119. package/package.json +16 -5
  120. package/src/category.ts +5 -1
  121. package/src/charts/CategoryBarChart/index.tsx +310 -62
  122. package/src/charts/Heatmap/index.tsx +4 -0
  123. package/src/charts/PolarChart/index.tsx +98 -5
  124. package/src/charts/ScatterChart/index.tsx +164 -18
  125. package/src/charts/Sparkline/index.tsx +54 -7
  126. package/src/components/ChartFrame/index.tsx +180 -0
  127. package/src/components/ChartLegend/index.tsx +46 -0
  128. package/src/components/ChartStory/index.tsx +184 -0
  129. package/src/components/HeatmapCells/index.tsx +5 -2
  130. package/src/hooks/useMarkMemory.ts +29 -0
  131. package/src/hooks/usePieTween.ts +9 -44
  132. package/src/hooks/useSteps.ts +77 -0
  133. package/src/hooks/useTween.ts +112 -0
  134. package/src/index.ts +24 -1
  135. package/src/scatter.ts +4 -1
  136. package/src/sparkline.ts +1 -1
  137. package/src/standalone.tsx +68 -0
  138. package/src/story.ts +19 -0
  139. package/src/types/category.ts +27 -0
  140. package/src/types/heatmap.ts +3 -0
  141. package/src/types/heatmapParts.ts +2 -0
  142. package/src/types/motion.ts +35 -0
  143. package/src/types/pie.ts +3 -3
  144. package/src/types/polar.ts +3 -0
  145. package/src/types/scatter.ts +23 -0
  146. package/src/types/sparkline.ts +3 -0
  147. package/src/types/story.ts +103 -0
  148. package/src/utils/category.utils.ts +111 -2
  149. package/src/utils/color.utils.ts +48 -0
  150. package/src/utils/csv.utils.ts +28 -0
  151. package/src/utils/motion.utils.ts +124 -0
  152. package/src/utils/pieTween.utils.ts +1 -2
  153. package/src/utils/scatter.utils.ts +22 -5
  154. package/src/utils/sparkline.utils.ts +69 -0
  155. package/src/utils/theme.utils.ts +18 -15
  156. package/dist/CategoryBarChart-YEJ9VB8h.js +0 -453
  157. package/dist/CategoryBarChart-YEJ9VB8h.js.map +0 -1
  158. package/dist/Heatmap-C1XcTUg1.js.map +0 -1
  159. package/dist/PieLegend-BZsv9IbF.js.map +0 -1
  160. package/dist/PolarChart-BUEhn3CI.js +0 -334
  161. package/dist/PolarChart-BUEhn3CI.js.map +0 -1
  162. package/dist/Sparkline-DtNhxGVo.js +0 -67
  163. package/dist/Sparkline-DtNhxGVo.js.map +0 -1
  164. package/dist/motion.utils-C1eaZJdQ.js +0 -9
  165. package/dist/motion.utils-C1eaZJdQ.js.map +0 -1
  166. package/dist/theme.utils-CP1XtGIe.js.map +0 -1
  167. package/dist/tooltip.utils-D7xaBSUK.js.map +0 -1
  168. package/dist/visibility.utils-nMI5a_Et.js.map +0 -1
package/CHANGELOG.md ADDED
@@ -0,0 +1,54 @@
1
+ # Changelog
2
+
3
+ ## 0.4.0
4
+
5
+ Benchmark charts: a dot plot per category, a calibration plot, round axes, legends, and a script
6
+ for pages without React. Built for the Chaos benchmark scorecard, which now draws its v4 charts
7
+ with this release.
8
+
9
+ ### Added
10
+
11
+ - **`CategoryBarChart` `mode="dot"`**: each series is a dot at its value on the category's row (or column), and a line joins each category's lowest and highest dot. That is a dot plot, or a dumbbell when there are two series. It works with `orientation`, `sort`, `domain`, `reference`, the tooltip, the keyboard and `onSelect`. Dots carry `data-part="dot"` and the joining line `data-part="dot-span"`. A dot fades in place rather than growing from zero.
12
+ - **`legend`** on `CategoryBarChart` and `ScatterChart`: `true` for a swatch and name per series (and per labelled scatter reference, dashed), or your own items, for example when bars are coloured by family. `ChartLegend` is exported for use beside any chart.
13
+ - **`ScatterChart` `xDomain` / `yDomain`** (`{ min?, max? }`): fix an axis extent, such as 0 to 1 for a probability. A missing end is still fitted.
14
+ - **`ScatterChart` `formatX` / `formatY`**: the tick text, such as a percentage.
15
+ - **`ScatterChart` `references`**: dashed lines between two points, such as a calibration plot's diagonal. They count towards the fitted extent but are not points.
16
+ - **`CategoryBarChart` `labelWidth`**: room for the category labels. A horizontal chart now fits its longest name by default (never under the old 108), so long names are no longer cut off.
17
+ - **`CategoryBarChart` `nice`** (default `true`): fitted axis ends are rounded so the four ticks fall on round numbers (0.239 becomes 0.24, in steps of 0.06). A fixed `domain` end is kept. `nice={false}` restores the old fit. `niceStep` and `niceExtent` are exported.
18
+ - **Standalone script** (`p1-charts/standalone`, `dist/standalone/p1-charts.standalone.js`): React and the SVG charts in one file that sets `window.P1Charts`. `P1Charts.render(el, "CategoryBarChart", props)` mounts or updates a chart and `P1Charts.unmount(el)` removes it. It is for static pages, artifacts and notebooks. Canvas charts stay in the React entries. The script starts with React's MIT notice, has no source map (about 294 kB, 97 kB gzipped), and does not include lightweight-charts.
19
+ - `ScatterDomain`, `ScatterReference` and `ChartLegendItem` types.
20
+
21
+ ### Changed
22
+
23
+ - `ScatterChart` axis titles have their own room: the y title runs up the left edge and the x title sits under the ticks. Before, the y title overlapped the top tick.
24
+ - A `ScatterChart` series line with no `color` now takes its series colour, like its points. Before, it was drawn in the text colour.
25
+ - A horizontal `CategoryBarChart` with a long category name gets a wider label column (see `labelWidth`).
26
+ - `CategoryBarChart` value axes are rounded by default (see `nice`).
27
+ - The theme helpers import only types from `lightweight-charts`, so a bundle of the SVG charts alone no longer pulls in the canvas engine.
28
+
29
+ ## 0.3.0
30
+
31
+ Motion, stories and chart furniture, in the spirit of Flourish's built-in animation and storytelling.
32
+
33
+ ### Added
34
+
35
+ - **`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.
36
+ - **Axis motion**: value ticks on `CategoryBarChart`, and x/y ticks and grid lines on `ScatterChart`, slide and fade between scales.
37
+ - **Scrolling sparkline**: when new `Sparkline` data is the old data moved along (a live window), the line scrolls instead of morphing.
38
+ - **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`.
39
+ - **`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.
40
+ - **`useSteps`**: the stepping logic on its own, for custom controls or scroll-driven steps.
41
+ - **`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".
42
+ - **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`.
43
+ - **New subpath**: `p1-charts/story`.
44
+
45
+ ### Changed
46
+
47
+ - `PieAnimate` is now an alias of the shared `ChartAnimate` type. Existing values still work.
48
+ - `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.
49
+ - `ScatterChart` ticks and `CategoryBarChart` category and value ticks are keyed by value or label rather than position.
50
+ - Themed `Heatmap` cells carry a `transition` style for fill and opacity. Unstyled cells carry none. Pass `animate={false}` to turn it off.
51
+
52
+ ### Not animated
53
+
54
+ - The canvas charts (`TimeSeriesChart`, `LineChart`, `BarChart`, `HistogramChart`, `CandlestickChart`). Lightweight Charts redraws everything on each `setData`.
package/README.md CHANGED
@@ -27,6 +27,8 @@ 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` |
31
+ | `p1-charts/standalone` | One script with React and the SVG charts, for pages without React (see [Standalone](#standalone)) |
30
32
 
31
33
  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
34
 
@@ -48,7 +50,9 @@ The package is unscoped (`p1-charts`). `prepack` builds `dist/` before the tarba
48
50
  | Full-height tint over a time range (a regime) | `LineChart` `bands` |
49
51
  | One series, terminal chrome | `LineChart`, `BarChart`, `HistogramChart`, `CandlestickChart` |
50
52
  | Grouped, stacked, or overlaid category columns, horizontal or on two axes | `CategoryBarChart` |
53
+ | Several values per category as dots, joined from lowest to highest (dot plot, dumbbell) | `CategoryBarChart` `mode="dot"` |
51
54
  | Statistical histogram | `bin()`, then `CategoryBarChart` |
55
+ | Forecast calibration (chance against outcome) | `ScatterChart` on 0..1 with `references` for the diagonal |
52
56
  | Columns on a time axis | `BarChart` or `HistogramChart` |
53
57
  | Numeric x and y | `ScatterChart` |
54
58
  | Wind rose | `PolarChart` (default `mode="bar"`) |
@@ -138,19 +142,24 @@ Square axis and crosshair labels are a `roundRect` patch scoped to the chart ele
138
142
 
139
143
  | Behaviour | Detail |
140
144
  | --- | --- |
141
- | `mode` | `"group"` (default), `"stack"`, or `"overlay"`. Overlay bars share a slot at opacity `0.72`. Stack separates positive and negative runs |
145
+ | `mode` | `"group"` (default), `"stack"`, `"overlay"`, or `"dot"`. Overlay bars share a slot at opacity `0.72`. Stack separates positive and negative runs. Dot draws each value as a dot (`data-part="dot"`) and joins a category's lowest and highest dot (`data-part="dot-span"`); set `domain` when the values sit far from zero |
142
146
  | `orientation` | `"vertical"` (default) or `"horizontal"`. Horizontal puts the categories on the vertical axis. Arrow keys follow that axis |
147
+ | `labelWidth` | Room on the left for category labels (horizontal: fitted to the longest name, at least `108`) or value ticks (vertical, default `44`), in viewBox units |
148
+ | `nice` | Default `true`: fitted axis ends are rounded so the ticks are round numbers. A fixed `domain` end is kept. `false` fits the data exactly |
149
+ | `legend` | `true` for a swatch and name per series above the chart, or `[{ label, color, dashed? }]` for your own (say, when bars are coloured by family) |
143
150
  | `series[].scale` | `"left"` (default) or `"right"`. A right scale is a second value axis. Each scale has its own extent |
144
151
  | `series[].data` | A number, or `{ value, color?, label? }`. `label` is drawn outside that bar |
145
152
  | `domain`, `rightDomain` | `{ min?, max? }` fixes an extent instead of fitting the data |
146
153
  | `reference`, `references` | Dashed lines across the plot at `value`, with an optional `label`. Both are drawn |
147
154
  | `bands` | A tint between `from` and `to`, behind the bars |
148
155
  | `activeIndex` | Category marked when the pointer is not over a bar |
149
- | `onSelect` | Called with the category label and its index when a bar is clicked or chosen from the keyboard |
156
+ | `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` |
157
+ | `sort` | `"none"` (default), `"descending"` or `"ascending"` by each category's total across series. Ties keep input order |
158
+ | `animate` | Bars and category ticks tween between data states, keyed by series and category label, so a sorted chart races. See [Motion](#motion) |
150
159
  | Keyboard | Left and right move the active category and stop at the ends |
151
160
  | Pointer | Entering a bar selects its category |
152
161
  | Tooltip | Always shows the active category. `formatValue(seriesId, value)` formats each row. `renderTooltip(category, rows)` replaces the default |
153
- | 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` |
162
+ | 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` |
154
163
  | Label | `ariaLabel` defaults to `"Bar chart"` |
155
164
 
156
165
  `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.
@@ -183,12 +192,62 @@ const counts = bin(samples, { bins: 12 });
183
192
  <Sparkline data={[1, 2, null, 4]} area />
184
193
  ```
185
194
 
186
- `ScatterChart` plots numeric `{ x, y }` points. The viewBox is 640×360. Arrow keys walk the points in series order and stop at the ends. The active point is the larger mark. `renderTooltip({ series, point, index })` replaces the default `"name x, y"` line. Parts: `grid`, `tick`, `axis-label`, `point` (`data-series`, `data-active`), `tooltip`. `ariaLabel` defaults to `"Scatter chart"`.
195
+ `ScatterChart` plots numeric `{ x, y }` points. The viewBox is 640×360. `xDomain` and `yDomain` (`{ min?, max? }`) fix an axis; a missing end is fitted. `formatX` and `formatY` write the tick text. `references` are dashed lines between two points (`data-part="reference"`). `legend` works as on `CategoryBarChart` and lists labelled references with a dashed swatch. Axis titles have their own room: `yLabel` runs up the left edge.
196
+
197
+ ```tsx
198
+ <ScatterChart
199
+ legend
200
+ xLabel="forecast chance"
201
+ yLabel="share that came true"
202
+ xDomain={{ min: 0, max: 1 }}
203
+ yDomain={{ min: 0, max: 1 }}
204
+ formatX={(v) => `${Math.round(v * 100)}%`}
205
+ formatY={(v) => `${Math.round(v * 100)}%`}
206
+ references={[{ from: { x: 0, y: 0 }, to: { x: 1, y: 1 }, label: "Perfect calibration" }]}
207
+ series={[{ id: "model", name: "Model", line: true, data: bins }]}
208
+ />
209
+ ``` Arrow keys walk the points in series order and stop at the ends. The active point is the larger mark. `renderTooltip({ series, point, index })` replaces the default `"name x, y"` line. Parts: `grid`, `tick`, `axis-label`, `point` (`data-series`, `data-active`), `tooltip`. `ariaLabel` defaults to `"Scatter chart"`.
187
210
 
188
211
  `PolarChart` defaults to a wind rose. Angle `0` is north. `direction` defaults to `"clockwise"` (`"counterclockwise"` turns the other way). In bar mode each category is one wedge and each series paints that wedge; a value that is not greater than zero is omitted. Sector opacity is `0.72`. `mode="scatter"` plots `{ angle, radius }` with `angle` in degrees. Arrow keys wrap. Parts: root `data-mode` (`bar` or `scatter`), `ring`, `tick`, `unit`, `sector` or `point`, `tooltip`. `renderTooltip({ series, label, value })` replaces the default text. `ariaLabel` defaults to `"Polar chart"`.
189
212
 
190
213
  `Sparkline` is one SVG, 80×22 by default, stroke `currentColor`, width `1.5`. It does not import `lightweight-charts`. `data` accepts `number`, `null`, `undefined`, or `{ value }`. A null, a missing value, or a non-finite number breaks the line into separate `data-part="line"` paths. `area` adds a `data-part="area"` fill at opacity `0.12`. `ariaLabel` defaults to `"Sparkline"`.
191
214
 
215
+ ### Dot plot
216
+
217
+ ```tsx
218
+ <CategoryBarChart
219
+ mode="dot"
220
+ orientation="horizontal"
221
+ legend
222
+ categories={["AAPL", "MSFT", "KO"]}
223
+ series={[
224
+ { id: "before", name: "Read before", data: [0.117, 0.112, 0.112] },
225
+ { id: "now", name: "Read now", data: [0.103, 0.084, 0.092] },
226
+ ]}
227
+ />
228
+ ```
229
+
230
+ Each value is a dot (`data-part="dot"`); a line joins each category's lowest and highest dot (`data-part="dot-span"`). Everything else (orientation, sort, domain, references, tooltip, keyboard) is as for bars.
231
+
232
+ ### Standalone
233
+
234
+ For a page that does not run React or a bundler (a static page, an artifact, a notebook), load one script and call `render`:
235
+
236
+ ```html
237
+ <script src="https://unpkg.com/p1-charts@0.4.0/dist/standalone/p1-charts.standalone.js"></script>
238
+ <div id="chart"></div>
239
+ <script>
240
+ P1Charts.render(document.getElementById("chart"), "CategoryBarChart", {
241
+ orientation: "horizontal",
242
+ categories: ["Chaos", "TimesFM"],
243
+ series: [{ id: "brier", name: "Brier", data: [0.117, 0.132] }],
244
+ theme: P1Charts.createTheme({ palette: { text: "#ccc", grid: "#333" } }),
245
+ });
246
+ </script>
247
+ ```
248
+
249
+ `render(el, chart, props)` mounts on the first call and updates in place on later ones; `unmount(el)` removes it. Charts by name: `CategoryBarChart`, `ScatterChart`, `PolarChart`, `PieChart`, `Heatmap`, `Sparkline`, `ChartLegend` (`P1Charts.chartNames`). Also on `P1Charts`: `createTheme`, `p1Theme`, `p1ThemeFromCss`, `bin`, `niceStep`, `niceExtent`, `version`. React is inside the file (about 97 KB gzipped); colours passed into props reach SVG attributes, so give resolved colours, not `var(...)`. The canvas charts are not in it.
250
+
192
251
  ### Theme
193
252
 
194
253
  `defaultTheme` stays the neutral Lightweight Charts palette. Pass `theme` on a chart, or wrap a tree in `ChartThemeProvider`. `unstyled` skips the theme fills on the SVG charts.
@@ -315,6 +374,101 @@ Selection props do nothing until `selectionMode` is set, the same as React Aria.
315
374
 
316
375
  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.
317
376
 
377
+ ## Motion
378
+
379
+ 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.
380
+
381
+ ```tsx
382
+ <CategoryBarChart animate={false} … />
383
+ <ScatterChart animate={{ duration: 600, stagger: 12 }} … />
384
+ <CategoryBarChart animate={{ appear: true }} … /> // grow from the baseline on mount
385
+ ```
386
+
387
+ | Option | Default | Detail |
388
+ | --- | --- | --- |
389
+ | `duration` | `240` | Milliseconds per mark |
390
+ | `easing` | `easeInOutCubic` | `(t) => number`. `linear`, `easeOutCubic` and `easeInOutCubic` are exported |
391
+ | `stagger` | `0` | Delay between successive marks |
392
+ | `appear` | `false` | Tween in from the baseline on first mount |
393
+
394
+ | Chart | What moves | Key | A new mark | A removed mark |
395
+ | --- | --- | --- | --- | --- |
396
+ | `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 |
397
+ | `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 |
398
+ | `PolarChart` | Wedge and radar vertex radius; scatter position | `series:category` or `series:index` | Grows from the centre | Returns to the centre |
399
+ | `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 |
400
+ | `PieChart` | Slice angles (as before) | slice key | Opens from its start angle | Dropped |
401
+ | `Heatmap` | Cell fill and opacity, through a CSS transition with the same easing | cell | | |
402
+
403
+ 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.
404
+
405
+ 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.
406
+
407
+ 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.
408
+
409
+ `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.
410
+
411
+ ## Stories
412
+
413
+ `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.
414
+
415
+ ```tsx
416
+ <ChartStory steps={years} controls="slider" loop interval={900} stepLabel={String}>
417
+ {(year) => (
418
+ <CategoryBarChart
419
+ orientation="horizontal"
420
+ sort="descending"
421
+ categories={ports}
422
+ series={[{ id: "teu", name: "TEU", data: byYear[year] }]}
423
+ animate={{ duration: 600 }}
424
+ />
425
+ )}
426
+ </ChartStory>
427
+
428
+ <ChartStory steps={slides} caption={(slide) => slide.text}>
429
+ {(slide) => <ScatterChart series={slide.series} />}
430
+ </ChartStory>
431
+ ```
432
+
433
+ | Behaviour | Detail |
434
+ | --- | --- |
435
+ | `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 |
436
+ | `index`, `defaultIndex`, `onIndexChange` | Controlled or uncontrolled step |
437
+ | `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 |
438
+ | `caption(step, index)` | Shown above the chart. It is `aria-live="polite"` while paused and silent while playing |
439
+ | `stepLabel(step, index)` | Names each dot, the slider value (`aria-valuetext`) and the position readout. Default `"Step n"` |
440
+ | 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 |
441
+ | Parts | `root`, `caption`, `stage`, `controls`, `play`, `prev`, `next`, `dots`, `dot` (`aria-current="step"`), `slider`, `position`. `classNames`, `styles` and `unstyled` work as on the charts |
442
+
443
+ `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`.
444
+
445
+ ## Frame, data table and CSV
446
+
447
+ `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.
448
+
449
+ ```tsx
450
+ <ChartFrame
451
+ title="Container throughput by port"
452
+ subtitle="Thousand TEU, 2025"
453
+ summary="Sines handles twice the volume of any other port."
454
+ source="Port authority"
455
+ data={{ columns: ["Port", "TEU"], rows: [["Sines", 1800], ["Leixões", 700]] }}
456
+ filename="throughput.csv"
457
+ >
458
+ <CategoryBarChart … />
459
+ </ChartFrame>
460
+ ```
461
+
462
+ | Behaviour | Detail |
463
+ | --- | --- |
464
+ | Title | `h3` by default (`level` 2–6). It labels the `figure` |
465
+ | `subtitle`, `summary` | Both describe the `figure`. `summary` is visible to screen readers only |
466
+ | `source`, `note` | Footer lines. `source` is printed as `"Source: …"` |
467
+ | `data` | `{ columns, rows }`. "Show data" toggles a real `table` (first column is a row header). "Download CSV" saves `filename` (default `data.csv`) |
468
+ | Parts | `root`, `header`, `title`, `subtitle`, `summary`, `body`, `footer`, `source`, `note`, `actions`, `table-toggle`, `download`, `table` |
469
+
470
+ `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.
471
+
318
472
  ## Development
319
473
 
320
474
  ```bash