p1-charts 0.3.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 (74) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/README.md +58 -2
  3. package/dist/CategoryBarChart-KYzsjGwg.js +715 -0
  4. package/dist/CategoryBarChart-KYzsjGwg.js.map +1 -0
  5. package/dist/{ChartFrame-B1bVFM2E.js → ChartFrame-DOEsou-R.js} +2 -2
  6. package/dist/{ChartFrame-B1bVFM2E.js.map → ChartFrame-DOEsou-R.js.map} +1 -1
  7. package/dist/ChartLegend-B8ZmIG2y.js +46 -0
  8. package/dist/ChartLegend-B8ZmIG2y.js.map +1 -0
  9. package/dist/{Heatmap-CFC753mV.js → Heatmap-Bwhf305C.js} +2 -2
  10. package/dist/{Heatmap-CFC753mV.js.map → Heatmap-Bwhf305C.js.map} +1 -1
  11. package/dist/{PieLegend-CbpjaOJH.js → PieLegend-16E6W10x.js} +3 -3
  12. package/dist/{PieLegend-CbpjaOJH.js.map → PieLegend-16E6W10x.js.map} +1 -1
  13. package/dist/PolarChart-C_vPz-3K.js +489 -0
  14. package/dist/PolarChart-C_vPz-3K.js.map +1 -0
  15. package/dist/{TimeSeriesChart-BzeHEtQl.js → TimeSeriesChart-BZMLERDZ.js} +451 -451
  16. package/dist/{TimeSeriesChart-BzeHEtQl.js.map → TimeSeriesChart-BZMLERDZ.js.map} +1 -1
  17. package/dist/category.d.ts +4 -1
  18. package/dist/category.d.ts.map +1 -1
  19. package/dist/category.js +4 -3
  20. package/dist/charts/CategoryBarChart/index.d.ts +3 -1
  21. package/dist/charts/CategoryBarChart/index.d.ts.map +1 -1
  22. package/dist/charts/ScatterChart/index.d.ts +1 -1
  23. package/dist/charts/ScatterChart/index.d.ts.map +1 -1
  24. package/dist/components/ChartLegend/index.d.ts +13 -0
  25. package/dist/components/ChartLegend/index.d.ts.map +1 -0
  26. package/dist/{css-BtFQ2bM4.js → css-BTZA9hea.js} +2 -2
  27. package/dist/{css-BtFQ2bM4.js.map → css-BTZA9hea.js.map} +1 -1
  28. package/dist/heatmap.js +1 -1
  29. package/dist/index.d.ts +5 -1
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +64 -63
  32. package/dist/index.js.map +1 -1
  33. package/dist/pie.js +1 -1
  34. package/dist/scatter.d.ts +4 -1
  35. package/dist/scatter.d.ts.map +1 -1
  36. package/dist/scatter.js +3 -2
  37. package/dist/series.js +1 -1
  38. package/dist/standalone/p1-charts.standalone.js +13 -0
  39. package/dist/standalone.d.ts +27 -0
  40. package/dist/standalone.d.ts.map +1 -0
  41. package/dist/story.js +2 -2
  42. package/dist/theme.js +2 -2
  43. package/dist/{theme.utils-DgmWROoe.js → theme.utils-DF_e8LxQ.js} +118 -119
  44. package/dist/theme.utils-DF_e8LxQ.js.map +1 -0
  45. package/dist/types/category.d.ts +16 -0
  46. package/dist/types/category.d.ts.map +1 -1
  47. package/dist/types/scatter.d.ts +31 -0
  48. package/dist/types/scatter.d.ts.map +1 -1
  49. package/dist/{useChartTheme-KKtc1C4K.js → useChartTheme-D0bQ3LQq.js} +2 -2
  50. package/dist/{useChartTheme-KKtc1C4K.js.map → useChartTheme-D0bQ3LQq.js.map} +1 -1
  51. package/dist/utils/category.utils.d.ts +13 -1
  52. package/dist/utils/category.utils.d.ts.map +1 -1
  53. package/dist/utils/scatter.utils.d.ts +17 -1
  54. package/dist/utils/scatter.utils.d.ts.map +1 -1
  55. package/dist/utils/theme.utils.d.ts +1 -1
  56. package/dist/utils/theme.utils.d.ts.map +1 -1
  57. package/package.json +7 -3
  58. package/src/category.ts +4 -1
  59. package/src/charts/CategoryBarChart/index.tsx +108 -19
  60. package/src/charts/ScatterChart/index.tsx +73 -10
  61. package/src/components/ChartLegend/index.tsx +46 -0
  62. package/src/index.ts +5 -1
  63. package/src/scatter.ts +4 -1
  64. package/src/standalone.tsx +68 -0
  65. package/src/types/category.ts +16 -0
  66. package/src/types/scatter.ts +20 -0
  67. package/src/utils/category.utils.ts +89 -2
  68. package/src/utils/scatter.utils.ts +22 -5
  69. package/src/utils/theme.utils.ts +18 -15
  70. package/dist/CategoryBarChart-1Kn3Vozc.js +0 -580
  71. package/dist/CategoryBarChart-1Kn3Vozc.js.map +0 -1
  72. package/dist/PolarChart-hcNTWKfJ.js +0 -450
  73. package/dist/PolarChart-hcNTWKfJ.js.map +0 -1
  74. package/dist/theme.utils-DgmWROoe.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # Changelog
2
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
+
3
29
  ## 0.3.0
4
30
 
5
31
  Motion, stories and chart furniture, in the spirit of Flourish's built-in animation and storytelling.
package/README.md CHANGED
@@ -28,6 +28,7 @@ Subpath imports keep a page from loading charts it does not draw:
28
28
  | `p1-charts/sparkline` | `Sparkline` |
29
29
  | `p1-charts/theme` | `p1Theme`, `p1ThemeFromCss`, `createTheme` |
30
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)) |
31
32
 
32
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.
33
34
 
@@ -49,7 +50,9 @@ The package is unscoped (`p1-charts`). `prepack` builds `dist/` before the tarba
49
50
  | Full-height tint over a time range (a regime) | `LineChart` `bands` |
50
51
  | One series, terminal chrome | `LineChart`, `BarChart`, `HistogramChart`, `CandlestickChart` |
51
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"` |
52
54
  | Statistical histogram | `bin()`, then `CategoryBarChart` |
55
+ | Forecast calibration (chance against outcome) | `ScatterChart` on 0..1 with `references` for the diagonal |
53
56
  | Columns on a time axis | `BarChart` or `HistogramChart` |
54
57
  | Numeric x and y | `ScatterChart` |
55
58
  | Wind rose | `PolarChart` (default `mode="bar"`) |
@@ -139,8 +142,11 @@ Square axis and crosshair labels are a `roundRect` patch scoped to the chart ele
139
142
 
140
143
  | Behaviour | Detail |
141
144
  | --- | --- |
142
- | `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 |
143
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) |
144
150
  | `series[].scale` | `"left"` (default) or `"right"`. A right scale is a second value axis. Each scale has its own extent |
145
151
  | `series[].data` | A number, or `{ value, color?, label? }`. `label` is drawn outside that bar |
146
152
  | `domain`, `rightDomain` | `{ min?, max? }` fixes an extent instead of fitting the data |
@@ -186,12 +192,62 @@ const counts = bin(samples, { bins: 12 });
186
192
  <Sparkline data={[1, 2, null, 4]} area />
187
193
  ```
188
194
 
189
- `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"`.
190
210
 
191
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"`.
192
212
 
193
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"`.
194
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
+
195
251
  ### Theme
196
252
 
197
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.