@pepperui/charts 1.1.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.
package/README.md ADDED
@@ -0,0 +1,117 @@
1
+ # @pepperui/charts
2
+
3
+ **One palette, four renderers.** The Mobupps design system's chart theme: the per-accent series
4
+ palettes, the two-slice donut rule, the narrow-band axis floor and the shared number-format object —
5
+ all generated from `tokens/*.json`, so no chart palette is typed by hand anywhere (**DL-10**, closes
6
+ **G13**).
7
+
8
+ Before this package the same colours were mirrored in three places by hand: Paggy's `charts.js`,
9
+ the quarter builder's `pptx_export.py` and the dashboard skill's `chart-recipes.md`. Three copies of
10
+ a number is three chances to drift, and they had drifted.
11
+
12
+ ## What is in it
13
+
14
+ | Path | What it is |
15
+ |---|---|
16
+ | `dist/theme.json` | **generated** by `npm run build` — every colour a chart paints with, and the token path each one came from (`$sources`) |
17
+ | `dist/pepper-charts.js` | the browser build: one `<script>` tag, defines `window.PepperCharts`, mounts every `[data-chart]` on load |
18
+ | `dist/pepper-charts.mjs` | the same code as an ES module, side-effect free |
19
+ | `src/format.js` | the number-format object (`{style, prefix, suffix, decimals}`) and the retired legacy readers |
20
+ | `src/rules.js` | the palette lookup, the narrow-band floor, the two-slice donut, the recipe geometry |
21
+ | `src/echarts.js` | `echartsTheme()` (a `registerTheme` payload) and `buildOption()` (the whole house chart) |
22
+ | `src/mount.js` | the optional DOM adapter — `renderAll` / `refit`, with the ResizeObserver refit |
23
+ | `src/api.js` | the public object |
24
+
25
+ `src/index.js` is the order the parts are concatenated in; they share one scope and are not
26
+ standalone modules — `build/charts.js` is the whole build and it is 80 lines of `readFileSync`.
27
+
28
+ ## Install
29
+
30
+ ```sh
31
+ npm install @pepperui/charts
32
+ ```
33
+
34
+ **On npm from 1.1.0** (item 1.2.3). It carries the palette, not the renderer: bring your own ECharts or
35
+ Chart.js. A version on the registry is always a version this repository tags — `charts-v1.1.0` — and never one
36
+ without (`RELEASING.md` §1).
37
+
38
+ ```js
39
+ import { buildOption, echartsTheme, valueFormatter } from '@pepperui/charts';
40
+ ```
41
+
42
+ ```html
43
+ <script src="node_modules/@pepperui/charts/dist/pepper-charts.js"></script>
44
+ ```
45
+
46
+ ## Use it
47
+
48
+ ```html
49
+ <script src="…/echarts.min.js"></script>
50
+ <script src="…/pepper-charts.js"></script>
51
+
52
+ <div class="echart" data-chart style="position:relative;width:760px;height:380px">
53
+ <script type="application/json">
54
+ {"type":"bar","labels":["Jan","Feb","Mar"],
55
+ "datasets":[{"label":"Revenue","data":[820000,1044000,310500]}],
56
+ "axis":{"fmt":{"style":"compact","prefix":"$"}}}
57
+ </script>
58
+ </div>
59
+ ```
60
+
61
+ The accent comes from the nearest `[data-accent]` ancestor — the same attribute `@pepperui/tokens`
62
+ switches its accent modes on — so **the mode recolours a chart** and nothing else has to change.
63
+ Without one it is `blue`.
64
+
65
+ ```js
66
+ import { buildOption, echartsTheme, valueFormatter } from '@pepperui/charts';
67
+
68
+ echarts.registerTheme('pepper-red', echartsTheme('red')); // defaults for a hand-written chart
69
+ chart.setOption(buildOption(cfg, { w: el.clientWidth, h: el.clientHeight }));
70
+ ```
71
+
72
+ ## The rules it carries, and where they came from
73
+
74
+ - **The series palettes are monochromatic per accent** — the accent's own tints — and every accent's
75
+ **second series is a readable MID tint**, never a pale one: pale tints vanish on the grey chart card
76
+ (stress-tests T03 / S03, 2026-07-09). Yellow's second series is grey for the same reason. Multicolor
77
+ is distinct hues instead: red → yellow → blue → grey, and past five series it continues with the same
78
+ hues one tint lighter. Source: `accent/<mode>/chart/1–5`.
79
+ - **A donut with exactly two slices reads as share-vs-rest** (Fedor, 2026-08-12): slice 1 keeps the
80
+ accent's main colour, slice 2 is always `chart/rest`. Three or more slices use the normal palette.
81
+ An explicit `colors` always wins.
82
+ - **The narrow-band axis floor**: when every value sits in a narrow high band (spread under 5% of the
83
+ maximum — uptime 99.92–99.99 on a 0–100 axis) the value axis lifts just below the band, so the
84
+ variation is visible instead of five identical full bars (stress-test S04). An explicit `axis.min`
85
+ wins; mixed-sign data is left alone.
86
+ - **The number format is an object, currency-neutral** (Fedor, 2026-08-14): a style, a *verbatim*
87
+ prefix and suffix, and an optional decimals override — because a dollar sign baked into a renderer
88
+ ships dollar labels on a euro column. `compact` picks its magnitude **per value** at three
89
+ significant digits, so `$820K` sits beside `$1.04M`. The retired `currency_M` / `currency_K` /
90
+ `percent` / `plain` strings stay forever as *readers*, so a deck built before the panel existed is
91
+ never silently repainted.
92
+ - **Pie is retired.** Every circular chart is the house donut; a config that arrives carrying none of
93
+ the house flags is restyled at render time rather than shipping as a default-ECharts pie.
94
+ - **Charts are static** (`animation: false`) so the SVG output is clean vector for PDF and PPTX.
95
+
96
+ The geometry — 4px column tops and none when stacked, 4px splines with no dots, 10px circular legend
97
+ markers 18 apart, the 72% donut cutout with 3px `chart/on-fill` borders — is in `src/rules.js` under
98
+ `GEOMETRY`, and is drawn on the Figma page **Chart recipes** (`281:2`).
99
+
100
+ ## The theme is the tokens
101
+
102
+ `dist/theme.json` carries a `$sources` map: `"series.yellow.1": "accent.yellow.chart.2"`, and so on
103
+ for all 32 values. `npm test` reads every one of them back out of `packages/tokens/dist/tokens.css` —
104
+ a different output of the same source, so the two cannot drift together — and fails if any value is
105
+ not what its token says. It also fails if a colour is typed anywhere in `src/`, which is the JS twin
106
+ of the stylelint rule on `@pepperui/css`.
107
+
108
+ To change a chart colour, change the token and run `npm run build`. Never edit `dist/`.
109
+
110
+ ## Consumers
111
+
112
+ | Consumer | How it takes the theme |
113
+ |---|---|
114
+ | **Paggy** (slides, ECharts) | `app/static/js/charts.js` **is** `dist/pepper-charts.js` — 3.1.1, delivered, 141/141 slides and 54/54 gallery plots pixel-identical |
115
+ | **the quarter builder** (Chart.js) | 3.1.2 |
116
+ | **`pptx_export.py`** | reads `pepper_tokens.py` — 3.1.3 |
117
+ | **the Figma chart recipes** | cite the same numbers — 3.1.4 |