blockcharts 0.0.1 → 0.0.3

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 (87) hide show
  1. package/README.md +274 -171
  2. package/package.json +43 -6
  3. package/release/bc.d.ts +35 -2
  4. package/release/blocks/guide.axis.js +2 -2
  5. package/release/blocks/guide.grid.js +2 -2
  6. package/release/blocks/guide.kpi.js +2 -2
  7. package/release/blocks/guide.legend.js +2 -2
  8. package/release/blocks/interaction.animate.js +2 -2
  9. package/release/blocks/interaction.brush.js +2 -2
  10. package/release/blocks/interaction.click.js +3 -0
  11. package/release/blocks/interaction.crosshair.js +2 -2
  12. package/release/blocks/interaction.legend-filter.js +2 -2
  13. package/release/blocks/interaction.tooltip.js +2 -2
  14. package/release/blocks/interaction.zoom-controls.js +2 -2
  15. package/release/blocks/interaction.zoom.js +2 -2
  16. package/release/blocks/lib.columns.js +2 -2
  17. package/release/blocks/lib.curve.js +2 -2
  18. package/release/blocks/lib.pointer.js +2 -2
  19. package/release/blocks/lib.stats.js +2 -2
  20. package/release/blocks/lib.ticks.js +2 -2
  21. package/release/blocks/lib.view.js +2 -2
  22. package/release/blocks/mark.arc.js +2 -2
  23. package/release/blocks/mark.area.js +2 -2
  24. package/release/blocks/mark.boxplot.js +2 -2
  25. package/release/blocks/mark.candlestick.js +2 -2
  26. package/release/blocks/mark.line.js +2 -2
  27. package/release/blocks/mark.point.js +2 -2
  28. package/release/blocks/mark.polygon.js +2 -2
  29. package/release/blocks/mark.rect.js +2 -2
  30. package/release/blocks/mark.rule.js +2 -2
  31. package/release/blocks/mark.sankey.js +2 -2
  32. package/release/blocks/mark.text.js +2 -2
  33. package/release/blocks/mark.violin.js +2 -2
  34. package/release/blocks/renderer.canvas.js +2 -2
  35. package/release/blocks/renderer.svg.js +2 -2
  36. package/release/blocks/scale.band.js +2 -2
  37. package/release/blocks/scale.color.js +2 -2
  38. package/release/blocks/scale.linear.js +2 -2
  39. package/release/blocks/scale.log.js +2 -2
  40. package/release/blocks/scale.sequential.js +2 -2
  41. package/release/blocks/scale.size.js +2 -2
  42. package/release/blocks/scale.time.js +2 -2
  43. package/release/blocks/transform.aggregate.js +2 -2
  44. package/release/blocks/transform.bin.js +2 -2
  45. package/release/blocks/transform.calculate.js +2 -2
  46. package/release/blocks/transform.calendar.js +2 -2
  47. package/release/blocks/transform.contour.js +2 -2
  48. package/release/blocks/transform.decimate.js +2 -2
  49. package/release/blocks/transform.density.js +2 -2
  50. package/release/blocks/transform.filter.js +2 -2
  51. package/release/blocks/transform.fold.js +2 -2
  52. package/release/blocks/transform.funnel.js +2 -2
  53. package/release/blocks/transform.hexbin.js +2 -2
  54. package/release/blocks/transform.highlight.js +2 -2
  55. package/release/blocks/transform.marimekko.js +2 -2
  56. package/release/blocks/transform.quartiles.js +2 -2
  57. package/release/blocks/transform.sankey.js +2 -2
  58. package/release/blocks/transform.sort.js +2 -2
  59. package/release/blocks/transform.stack.js +2 -2
  60. package/release/blocks/transform.treemap.js +2 -2
  61. package/release/blocks/transform.waterfall.js +2 -2
  62. package/release/blocks/transform.window.js +2 -2
  63. package/release/core.js +3 -3
  64. package/release/frameworks/controller.d.mts +51 -0
  65. package/release/frameworks/controller.mjs +181 -0
  66. package/release/frameworks/element.d.mts +32 -0
  67. package/release/frameworks/element.mjs +95 -0
  68. package/release/frameworks/react.d.mts +10 -0
  69. package/release/frameworks/react.mjs +30 -0
  70. package/release/frameworks/svelte.d.mts +9 -0
  71. package/release/frameworks/svelte.mjs +17 -0
  72. package/release/frameworks/vue.d.mts +40 -0
  73. package/release/frameworks/vue.mjs +44 -0
  74. package/release/kits/basic.js +25 -22
  75. package/release/kits/basic.mjs +25 -22
  76. package/release/kits/composition.js +39 -36
  77. package/release/kits/composition.mjs +39 -36
  78. package/release/kits/dashboard.js +37 -34
  79. package/release/kits/dashboard.mjs +37 -34
  80. package/release/kits/full.js +64 -61
  81. package/release/kits/full.mjs +64 -61
  82. package/release/kits/timeseries.js +35 -32
  83. package/release/kits/timeseries.mjs +35 -32
  84. package/release/loader.js +2 -2
  85. package/release/manifest.json +326 -221
  86. package/release/schema/chart.schema.json +4155 -0
  87. package/release/schema/page.schema.json +4547 -0
package/README.md CHANGED
@@ -1,211 +1,267 @@
1
1
  # blockcharts
2
2
 
3
- **[blockcharts.online](https://blockcharts.online)** · [the principles](docs/spec/principles.md) · [the documentation](docs/README.md)
3
+ [![npm](https://img.shields.io/npm/v/blockcharts?color=2563eb)](https://www.npmjs.com/package/blockcharts)
4
+ [![CI](https://github.com/boligolov/blockcharts/actions/workflows/ci.yml/badge.svg)](https://github.com/boligolov/blockcharts/actions/workflows/ci.yml)
5
+ [![License: MIT](https://img.shields.io/badge/license-MIT-2563eb)](LICENSE)
4
6
 
5
7
  **Atomic charts for HTML dashboards: a page carries only the chart code it needs. Nothing more.**
6
8
 
7
9
  blockcharts is a chart library cut into atoms — a scale, a bar, an axis, a tooltip, each a block of <!-- build:block-range -->0.4–12 KB<!-- /build -->.
8
- A page gets the core (about <!-- build:core-gzip -->12 KB<!-- /build --> gzipped) and exactly the blocks its own charts use, never the whole library;
9
- anything can be customized, down to blocks of your own. The agent skill turns a table or a CSV file into one
10
- light `.html` report with interactive charts that opens offline and can be emailed.
10
+ A page gets the core (about <!-- build:core-gzip -->12 KB<!-- /build --> gzipped) and exactly the blocks its own charts use, never the whole library.
11
+ Charts are described in JSON, drawn in SVG or on a canvas, and every part can be customized, down to blocks of your own.
11
12
 
12
- ## Install the skill
13
+ **[Website](https://blockcharts.online)** · **[Gallery](https://blockcharts.online/examples/)** · **[Guide](https://blockcharts.online/guide/)** · **[Blocks](https://blockcharts.online/blocks/)** · [Principles](docs/spec/principles.md)
13
14
 
14
- **Claude Code** — from this repository, which is a plugin marketplace:
15
-
16
- ```
17
- /plugin marketplace add boligolov/blockcharts
18
- /plugin install blockcharts@blockcharts
19
- ```
20
-
21
- It updates by itself once auto-update is on for the marketplace (`/plugin` → *Marketplaces*), or by hand with
22
- `claude plugin update blockcharts@blockcharts`.
23
-
24
- **Claude.ai and Claude Desktop** — download **[blockcharts.skill](https://blockcharts.online/blockcharts.skill)**
25
- and upload it under *Settings → Capabilities → Skills* (skills need code execution enabled).
26
-
27
- **Any other agent that reads skill folders** — copy [`skills/blockcharts/`](skills/blockcharts/) into its
28
- skills folder (`~/.claude/skills/` for Claude Code). It needs Node.js 22+.
29
-
30
- Then ask — *"an HTML report of monthly revenue by region from sales.csv"*, *"a dashboard of these KPIs"*.
31
- Scopes and details: [docs/skill.md](docs/skill.md).
32
-
33
- ## How it works
34
-
35
- Charts are drawn by small independent **blocks** (`scale.time`, `mark.rect`, `guide.axis`,
36
- `interaction.zoom`, …). A chart is a JSON spec that names them; the blocks a page needs are read from its
37
- specs, closed over their dependencies, and only those go into the page: a bar chart with labels and a tooltip
38
- carries <!-- build:bar -->10 of the 58 blocks, 71 KB of code instead of 214<!-- /build -->; a whole executive dashboard
39
- (KPI tiles, a trend, a donut, a waterfall, a funnel, animated) carries <!-- build:dashboard-blocks -->24<!-- /build -->. Nobody lists blocks by hand, so the list is never too long.
40
-
41
- The agent never writes chart code. It writes the JSON, and a composer bundled with the skill checks every
42
- chart against the real data, reports each mistake with its place in the JSON, and only then writes the page.
43
-
44
- **Customizable at every level**: block parameters (formats, locales, axes, tooltips), CSS variables and
45
- classes (brand colors, dark mode, print), your own set of blocks (a kit per page, or the loader), functions
46
- by name (`BC.defineFn`), and blocks of your own — a small script calling `BC.define`, the same contract the
47
- built-in blocks use ([an example](https://blockcharts.online/embed/block/)).
48
-
49
- ## The principles behind it
50
-
51
- [`docs/spec/principles.md`](docs/spec/principles.md) — *blockcharts principles v<!-- build:principles-version -->1.1<!-- /build -->*: how a report is built
52
- from blocks so that a page carries exactly the code its charts need — and what follows from that.
53
-
54
- - **Exactly what the charts need, nothing more** (§1): blocks are chosen mechanically from the specs, never by hand.
55
- - **Blocks are atoms** (§2): one role, one job; a bar chart is `band + linear + rect`, a new chart is a recipe.
56
- - **Customizable at every level** (§3): parameters, CSS, your own set of blocks, functions, your own blocks.
57
- - **The page is the product** (§4): one HTML file that opens from disk, offline, anywhere.
58
- - **The chart is data** (§5–6), **checked before it is written** (§7).
59
- - **Heavy data stays light** (§8), **same input, same bytes** (§9), **nothing leaves the page** (§10).
60
- - **One set of files, three ways in** (§11) and the **requirements** for pages, blocks and composers (§12).
15
+ [![An executive dashboard made with blockcharts: KPI tiles with sparklines, revenue against plan, revenue by channel, a waterfall and a checkout funnel](https://raw.githubusercontent.com/boligolov/blockcharts/main/docs/images/executive-dashboard.png)](https://blockcharts.online/examples/executive-dashboard/)
61
16
 
62
- ## The library for your own pages
17
+ *KPI tiles, a trend against plan, a donut, a waterfall and a funnel: one standalone HTML file,
18
+ [live in the gallery](https://blockcharts.online/examples/executive-dashboard/).*
63
19
 
64
- The same blocks work without the skill.
20
+ ## Quick start
65
21
 
66
- ### Three ways to use it
22
+ One script tag, and a chart described in JSON where it should appear:
67
23
 
68
- | You want | Use | Files |
69
- | --- | --- | --- |
70
- | One report file, nothing to host | the **composer** | `node scripts/compose.js page.json report.html` |
71
- | Charts in your own page, one `<script>` from a CDN | a **kit** | `release/kits/<name>.js` (or `.mjs`) |
72
- | Fetch only what a page uses, from a CDN or a folder | the **loader** | `release/loader.js` + `core.js` + `blocks/*.js` |
24
+ ```html
25
+ <script src="https://cdn.jsdelivr.net/npm/blockcharts@0.0.3/release/kits/basic.js"></script>
73
26
 
74
- #### 1. The composer: JSON in, one HTML file out
27
+ <script type="application/json" id="bc-data">
28
+ { "sales": [ { "region": "North", "total": 42 }, { "region": "South", "total": 58 }, { "region": "East", "total": 31 } ] }
29
+ </script>
30
+ <script type="application/json" data-bc-chart>
31
+ { "data": "sales",
32
+ "scales": { "x": { "type": "band" }, "y": { "type": "linear", "zero": true } },
33
+ "guides": [ { "type": "axis", "scale": "x" }, { "type": "axis", "scale": "y" } ],
34
+ "marks": [ { "type": "rect", "x": "region", "y": "total" } ],
35
+ "interaction": [ { "type": "tooltip" } ] }
36
+ </script>
37
+ ```
75
38
 
76
- The composer is a script of this repository (the skill carries a copy), not part of the npm package: run it in a clone.
39
+ Charts draw themselves when the page loads. With a bundler or a framework:
77
40
 
78
41
  ```sh
79
- git clone https://github.com/boligolov/blockcharts.git
80
- cd blockcharts
81
- npm install
82
- npm run build && npm run manifest
83
- node scripts/compose.js skills/blockcharts/recipes/report-from-csv.json report.html
42
+ npm install blockcharts
84
43
  ```
85
44
 
86
- `page.json`:
45
+ ```js
46
+ import BC from 'blockcharts';
87
47
 
88
- ```json
89
- {
90
- "title": "Sales",
91
- "data": { "sales": [ { "region": "North", "total": 42 }, { "region": "South", "total": 58 } ] },
92
- "charts": [
93
- {
94
- "title": "Sales by region",
95
- "spec": {
96
- "data": "sales",
97
- "scales": { "x": { "type": "band" }, "y": { "type": "linear", "zero": true } },
98
- "guides": [ { "type": "grid", "scale": "y" }, { "type": "axis", "scale": "x" }, { "type": "axis", "scale": "y" } ],
99
- "marks": [ { "type": "rect", "x": "region", "y": "total" } ],
100
- "interaction": [ { "type": "tooltip" } ]
101
- }
102
- }
103
- ]
104
- }
48
+ BC.data('sales', rows);
49
+ const chart = BC.chart(document.getElementById('chart'), spec); // update, setView, getView, destroy, ready
105
50
  ```
106
51
 
107
- The composer works out which blocks the charts need, checks every spec against the data (unknown field, wrong scale type, ... each reported with its path in the JSON), builds each chart once in a sandbox to catch anything that only shows up when drawing, and writes the page. The same input always gives the same bytes. It writes nothing until every chart is valid. Because it has already checked everything, the page carries a lighter core without the checks (`BC.validate`, `BC.needs`), and without the data decoder unless a dataset is stored gzipped: about <!-- build:core-saving -->14 KB<!-- /build --> less per report. The kits for your own pages keep the full core.
52
+ ## Why blockcharts
108
53
 
109
- Datasets can be rows, `{"columns": {...}}`, `{"csv": "text"}`, or `{"csvFile": "orders.csv"}` (next to `page.json`). Large datasets are stored gzipped automatically. For long numeric series from a pipeline, `scripts/encode-columns.js` stores columns as raw typed values (`{"columns": {"t": {"dtype": "float64", "encoding": "gzip+base64", "data": "..."}}}`), never lossy unless you ask for `float32`. Against the gzip a page gets anyway this saves about a third on small integers and a seventh on floats with every digit, and nothing on values rounded to a few decimals; `float32` takes floats to about a third.
54
+ - **Only the code your charts use.** The blocks a page needs are read from its specs and closed over their
55
+ dependencies: a bar chart with labels and a tooltip carries <!-- build:bar -->10 of the 59 blocks, 71 KB of code instead of 216<!-- /build -->; a whole
56
+ executive dashboard (KPI tiles, a trend, a donut, a waterfall, a funnel, animated) carries <!-- build:dashboard-blocks -->24<!-- /build -->. Nobody lists
57
+ blocks by hand, so the list is never too long.
58
+ - **Charts are data, checked before they are drawn.** A chart is a plain JSON spec, not code. It is checked against
59
+ the real data, and every mistake comes back with its place in the JSON.
60
+ - **One file that opens anywhere.** The composer turns JSON and data into a single HTML report that opens from disk,
61
+ offline, can be emailed or printed, and loads nothing from the network. The same input always gives the same bytes.
62
+ - **Customizable at every level.** Block parameters (formats, locales, axes, tooltips), CSS variables and classes
63
+ (brand colors, dark mode, print), your own set of blocks, functions by name (`BC.defineFn`), and blocks of your
64
+ own — a small script calling `BC.define`, the same contract the built-in blocks use
65
+ ([an example](https://blockcharts.online/embed/block/)).
66
+ - **Heavy data stays light.** A canvas renderer for tens of thousands of points, decimation, aggregation, and large
67
+ datasets stored gzipped in the page.
68
+ - **No dependencies.** Plain ES2020 in every modern browser, typed for TypeScript, MIT-licensed.
110
69
 
111
- A dashboard is the same file with a grid: `"layout": {"columns": 4}` and a `span` per chart (KPI tiles `span: 1`, a trend `span: 3`); `title` and `subtitle` head the page. Every chart sits in a card; on a phone the cards stack.
70
+ What it is built on: [the blockcharts principles](docs/spec/principles.md), v<!-- build:principles-version -->1.1<!-- /build -->.
112
71
 
113
- Ready-made pages to copy live in `skills/blockcharts/recipes/`, <!-- build:recipes -->48<!-- /build --> of them, among them an executive dashboard (KPI tiles in a grid), waterfall, funnel, bullet, treemap, bar, stacked and grouped bars, dot plot, boxplot, lines with zoom, a slope chart, a moving average and running totals, scatter, a hexbin and density contours of thousands of points, bubbles, dual axis, 100% stacked area, histogram, heatmap, pie, long series, and a CSV report with aggregation and currency formatting.
72
+ ## What it draws
114
73
 
115
- #### 2. Kits: core + blocks in one file
74
+ Bars (stacked, grouped, 100%), lines and areas, scatter and bubbles, hexbins and density contours, pie and donut,
75
+ heatmaps and calendars, histograms, boxplots and violins, waterfalls, funnels, treemaps, sankey and marimekko
76
+ diagrams, candlesticks, KPI tiles with sparklines, bullet and target lines — with tooltips, a crosshair, zoom and
77
+ brush, legend filters and animation.
116
78
 
117
- ```sh
118
- npm run release # in the clone: writes release/ (the npm package ships the same files)
119
- ```
79
+ Every kind is live in the [gallery](https://blockcharts.online/examples/), with its JSON and the HTML to embed it. The
80
+ <!-- build:recipes -->48<!-- /build --> ready-made pages behind it are in [`skills/blockcharts/recipes/`](skills/blockcharts/recipes/), to copy.
120
81
 
121
- ```html
122
- <script src="https://cdn.jsdelivr.net/npm/blockcharts@0.0.1/release/kits/timeseries.js"></script>
82
+ ## Ways to ship it
123
83
 
124
- <script type="application/json" id="bc-data">{ "d": [ { "day": "2024-01-01", "v": 1200 }, { "day": "2024-02-01", "v": 3400 } ] }</script>
125
- <script type="application/json" data-bc-chart>
126
- { "data": "d", "scales": { "x": { "type": "time" }, "y": { "type": "linear", "zero": true } },
127
- "guides": [ { "type": "axis", "scale": "x" }, { "type": "axis", "scale": "y", "format": "compact" } ],
128
- "marks": [ { "type": "line", "x": "day", "y": "v" } ] }
129
- </script>
130
- ```
84
+ | You want | Use |
85
+ | --- | --- |
86
+ | Charts in your own page, one `<script>` | a **kit**: the core and a set of blocks in one file |
87
+ | Each page to fetch only what it uses | the **loader**: `loader.js`, the core and single block files |
88
+ | A bundler | the **npm package**: `import BC from 'blockcharts'` |
89
+ | A component in React, Vue or Svelte, or a custom element | the **wrappers**: `blockcharts/react`, `/vue`, `/svelte`, `/element` |
90
+ | One report file, nothing to host | the **composer**: JSON and data in, one HTML file out |
131
91
 
132
- Charts mount themselves on `DOMContentLoaded`. Or call `BC.chart(element, spec)` yourself and keep the returned handle (`setView`, `getView`, `update`, `destroy`, `ready`).
92
+ ### Kits
93
+
94
+ A kit is the core and a set of blocks in one file: a classic script (`kits/<name>.js`) or an ES module
95
+ (`kits/<name>.mjs`, `export default BC`; browsers load modules over http and https only, not from `file://`).
133
96
 
134
97
  <!-- build:kits -->
135
98
 
136
99
  | Kit | Blocks | Contents | Minified (gzip) |
137
100
  |---|---|---|---|
138
- | `basic` | 19 | Bars, lines, points and areas on linear, log, time and band scales, with axes, grid, legend and tooltip, and fields calculated from the data. | 112 KB (42 KB) |
139
- | `timeseries` | 29 | Long series over time: lines and areas with zoom, brush, legend filter, decimation, aggregation, wide tables and moving averages; also the canvas renderer for very large series. | 140 KB (51 KB) |
140
- | `composition` | 33 | Parts of a whole and distributions: stacked bars and areas, pie, heatmap, histogram, boxplot, waterfall, funnel, treemap, aggregation. | 148 KB (54 KB) |
141
- | `dashboard` | 31 | Business dashboards: KPI tiles with sparklines, bars, lines and areas, waterfall, funnel, treemap, bullet and target lines, donut, with axes, grid, legend, tooltip and legend filter. | 149 KB (55 KB) |
142
- | `full` | 58 | Every block. | 226 KB (81 KB) |
101
+ | `basic` | 20 | Bars, lines, points and areas on linear, log, time and band scales, with axes, grid, legend, tooltip and click events, and fields calculated from the data. | 114 KB (43 KB) |
102
+ | `timeseries` | 30 | Long series over time: lines and areas with zoom, brush, legend filter, decimation, aggregation, wide tables, moving averages and click events; also the canvas renderer for very large series. | 142 KB (52 KB) |
103
+ | `composition` | 34 | Parts of a whole and distributions: stacked bars and areas, pie, heatmap, histogram, boxplot, waterfall, funnel, treemap, aggregation, click events. | 150 KB (55 KB) |
104
+ | `dashboard` | 32 | Business dashboards: KPI tiles with sparklines, bars, lines and areas, waterfall, funnel, treemap, bullet and target lines, donut, with axes, grid, legend, tooltip, legend filter and click events. | 151 KB (56 KB) |
105
+ | `full` | 59 | Every block. | 228 KB (82 KB) |
143
106
 
144
107
  <!-- /build -->
145
108
 
146
- Everything in `release/` is minified (esbuild, ES2020) and stripped of the parameter docs, which a running chart never reads; `buildRelease({ minify: false })` keeps the readable code for debugging. Kits are defined in `kits.json`. A kit made for one page contains exactly the blocks that page uses:
109
+ Everything is minified (esbuild, ES2020) and stripped of the parameter docs, which a running chart never reads.
110
+ Charts mount themselves on `DOMContentLoaded`; or call `BC.chart(element, spec)` and keep the handle.
147
111
 
148
- ```sh
149
- node scripts/build-dist.js --page page.json=report # in the clone: adds release/kits/report.js
112
+ ### The loader
113
+
114
+ ```html
115
+ <script src="https://cdn.jsdelivr.net/npm/blockcharts@0.0.3/release/loader.js" data-auto></script>
116
+ <!-- your data and <script data-bc-chart> specs -->
150
117
  ```
151
118
 
152
- `kits/<name>.mjs` is the same code as an ES module with `export default BC` (browsers load modules over http/https only, not `file://`).
119
+ The loader reads `manifest.json` next to it, loads the core, asks it which blocks the charts on the page need, loads
120
+ only those (with their dependencies) and draws. By hand:
153
121
 
154
- #### From npm
122
+ ```js
123
+ await BCLoader.load({
124
+ base: 'https://cdn.jsdelivr.net/npm/blockcharts@0.0.3/release/', // default: the folder of loader.js
125
+ blocks: ['interaction.zoom'], // extra blocks besides the ones found in the page
126
+ scan: true, // find charts on the page (default)
127
+ mount: true, // draw them when loaded (default)
128
+ integrity: true, // put the manifest's SRI hashes on the script tags
129
+ });
130
+ ```
131
+
132
+ ### npm
155
133
 
156
134
  ```sh
157
135
  npm install blockcharts
158
136
  ```
159
137
 
160
- The package ships the minified files of `release/` (kits, blocks, loader, manifest, types), not the composer or the scripts, and resolves them through `exports`:
161
-
162
138
  ```js
163
139
  import BC from 'blockcharts'; // the full kit, typed
164
140
  import BC from 'blockcharts/kits/basic.mjs'; // a smaller kit
165
141
  import manifest from 'blockcharts/manifest.json' with { type: 'json' };
166
142
  const BC = require('blockcharts'); // CommonJS: the same full kit
167
- // a <script src> names the file where it is: node_modules/blockcharts/release/kits/timeseries.js (exports are for import/require)
168
143
  ```
169
144
 
170
- Every kit has a `.d.mts` (and a `.d.ts` for `require`); `blockcharts/bc.d.ts` declares the global `BC` and every spec type. `npm pack` and `npm publish` build the release first (`prepack`).
145
+ The package carries the built files: kits, single blocks, the loader, the manifest, the types, the JSON Schemas and
146
+ the framework wrappers. Every kit has a
147
+ `.d.mts` (and a `.d.ts` for `require`); `blockcharts/bc.d.ts` declares the global `BC` and every spec type. A
148
+ `<script src>` names the file where it is: `node_modules/blockcharts/release/kits/basic.js`.
171
149
 
172
- #### 3. The loader: separate files, fetched on demand
150
+ ### React, Vue, Svelte and `<block-chart>`
173
151
 
174
- ```html
175
- <script src="https://cdn.jsdelivr.net/npm/blockcharts@0.0.1/release/loader.js" data-auto></script>
176
- <!-- your data and <script data-bc-chart> specs -->
152
+ A wrapper is a subpath of the package with no blocks of its own: it draws with the kit the app imported once, so the
153
+ app carries only the blocks it chose.
154
+
155
+ ```jsx
156
+ import 'blockcharts/kits/basic.mjs'; // once, before a chart mounts
157
+ import { BlockChart } from 'blockcharts/react';
158
+
159
+ <BlockChart spec={spec} data={rows} onClick={(d) => openRegion(d.values.region)} />;
177
160
  ```
178
161
 
179
- The loader reads `manifest.json` next to it, loads the core, asks it which blocks the charts on the page need, loads those (and their dependencies), and mounts. Manual control:
162
+ ```vue
163
+ <script setup>
164
+ import 'blockcharts/kits/basic.mjs';
165
+ import { BlockChart } from 'blockcharts/vue';
166
+ </script>
180
167
 
181
- ```js
182
- await BCLoader.load({
183
- base: 'https://cdn.jsdelivr.net/npm/blockcharts@0.0.1/release/', // default: the folder of loader.js
184
- blocks: ['interaction.zoom'], // extra blocks besides the ones found in the page
185
- scan: true, // find charts on the page (default)
186
- mount: true, // mount them when loaded (default)
187
- integrity: true, // put the manifest's SRI hashes on the script tags
188
- });
168
+ <template>
169
+ <BlockChart :spec="spec" :data="rows" @click="(d) => openRegion(d.values.region)" />
170
+ </template>
189
171
  ```
190
172
 
191
- #### From a CDN
173
+ ```svelte
174
+ <script>
175
+ import 'blockcharts/kits/basic.mjs';
176
+ import { blockchart } from 'blockcharts/svelte';
177
+ </script>
192
178
 
193
- jsDelivr and unpkg serve every file of the npm package on its own, at the path it has in the package:
194
- `https://cdn.jsdelivr.net/npm/blockcharts@<version>/release/<file>` (or `https://unpkg.com/blockcharts@<version>/release/<file>`),
195
- where `<file>` is `core.js`, `blocks/<role.type>.js`, `kits/<name>.js` or `.mjs`, `loader.js`, `manifest.json` or `bc.d.ts`.
196
- The loader takes the core and the blocks from the folder it came from, so it needs nothing more than its own address.
179
+ <div use:blockchart={{ spec, data: rows, onClick: (d) => openRegion(d.values.region) }}></div>
180
+ ```
197
181
 
198
- #### Pinning with SRI
182
+ ```js
183
+ // Angular (with CUSTOM_ELEMENTS_SCHEMA), Lit, Solid or a plain page
184
+ import 'blockcharts/kits/basic.mjs';
185
+ import 'blockcharts/element'; // defines <block-chart>
186
+
187
+ const el = document.createElement('block-chart');
188
+ el.spec = spec; // or <block-chart spec='{"data": "sales", ...}'>
189
+ el.data = rows;
190
+ el.addEventListener('bc-click', (e) => openRegion(e.detail.values.region)); // with {"type": "click"} in the spec
191
+ ```
199
192
 
200
- `release/manifest.json` lists a `sha384` hash for every file, ready for the `integrity` attribute:
193
+ - `spec` is a chart spec. `data` is the chart's own rows, `{"columns": {...}}` or an encoded dataset, kept under a
194
+ name of its own while the chart lives and taken away after; left out, the spec's `data` names a dataset given to
195
+ `BC.data`.
196
+ - The chart is drawn again only when the spec changes in content or `data` is a new array or object. Rendering the
197
+ same spec again costs nothing, and rows changed in place are not seen: give a new array.
198
+ - `onClick` (`@click` in Vue) gets the clicked row ([Clicks](#clicks)) and adds `{"type": "click"}` to the spec when it
199
+ has none; the kit must have that block (all of them do).
200
+ - The React ref and the Vue component's ref have `chart` (the handle: `diagnostics`, `getView`), `setView` and
201
+ `getView`; `<block-chart>` has `el.chart`.
202
+ - On a server a component renders an empty `<div>`, and the chart is drawn after mount. Without a kit on the page the
203
+ chart's place says which one to import, and the app goes on.
204
+ - React 18 and later, Vue 3.3 and later, Svelte 4 and 5 (the action is plain JavaScript): optional peer
205
+ dependencies. The custom element needs no framework.
206
+
207
+ ### CDN and integrity
208
+
209
+ jsDelivr and unpkg serve every file of the package at its path in it:
210
+ `https://cdn.jsdelivr.net/npm/blockcharts@<version>/release/<file>` (or `https://unpkg.com/blockcharts@<version>/release/<file>`),
211
+ where `<file>` is `core.js`, `blocks/<role.type>.js`, `kits/<name>.js` or `.mjs`, `loader.js`, `manifest.json`,
212
+ `bc.d.ts`, `schema/chart.schema.json` or `schema/page.schema.json`. Pin an exact version (`@0.0.3`, not `@0` or
213
+ `@latest`): files of a version never change, and `manifest.json` lists a `sha384` hash of every file for the
214
+ `integrity` attribute:
201
215
 
202
216
  ```html
203
- <script src="https://cdn.jsdelivr.net/npm/blockcharts@0.0.1/release/kits/basic.js" integrity="sha384-..." crossorigin="anonymous"></script>
217
+ <script src="https://cdn.jsdelivr.net/npm/blockcharts@0.0.3/release/kits/basic.js" integrity="sha384-..." crossorigin="anonymous"></script>
204
218
  ```
205
219
 
206
- Always pin an exact version in the CDN path (`@0.0.1`, not `@0` or `@latest`); files of a version never change.
220
+ ### The composer: one standalone report
207
221
 
208
- ## Spec anatomy
222
+ The composer is a script of this repository, not part of the npm package: run it in a clone.
223
+
224
+ ```sh
225
+ git clone https://github.com/boligolov/blockcharts.git
226
+ cd blockcharts
227
+ npm install
228
+ npm run build && npm run manifest
229
+ node scripts/compose.js skills/blockcharts/recipes/report-from-csv.json report.html
230
+ ```
231
+
232
+ `page.json`:
233
+
234
+ ```json
235
+ {
236
+ "title": "Sales",
237
+ "data": { "sales": [ { "region": "North", "total": 42 }, { "region": "South", "total": 58 } ] },
238
+ "charts": [
239
+ {
240
+ "title": "Sales by region",
241
+ "spec": {
242
+ "data": "sales",
243
+ "scales": { "x": { "type": "band" }, "y": { "type": "linear", "zero": true } },
244
+ "guides": [ { "type": "grid", "scale": "y" }, { "type": "axis", "scale": "x" }, { "type": "axis", "scale": "y" } ],
245
+ "marks": [ { "type": "rect", "x": "region", "y": "total" } ],
246
+ "interaction": [ { "type": "tooltip" } ]
247
+ }
248
+ }
249
+ ]
250
+ }
251
+ ```
252
+
253
+ The composer works out which blocks the charts need, checks every spec against the data (an unknown field, a wrong
254
+ scale type, … each reported with its path in the JSON), draws each chart once in a sandbox to catch what only shows
255
+ up when drawing, and writes the page; nothing is written until every chart is valid. Having checked everything, the
256
+ page carries a lighter core, without the checks and, unless a dataset is stored gzipped, without the data decoder:
257
+ about <!-- build:core-saving -->14 KB<!-- /build --> less per report.
258
+
259
+ Datasets can be rows, `{"columns": {...}}`, `{"csv": "text"}`, or `{"csvFile": "orders.csv"}` (next to `page.json`);
260
+ large ones are stored gzipped automatically. A dashboard is the same file with a grid: `"layout": {"columns": 4}` and
261
+ a `span` per chart (KPI tiles `span: 1`, a trend `span: 3`), with a `title` and a `subtitle` on top. Every chart sits
262
+ in a card, and on a phone the cards stack.
263
+
264
+ ## How a chart is described
209
265
 
210
266
  ```json
211
267
  {
@@ -219,11 +275,55 @@ Always pin an exact version in the CDN path (`@0.0.1`, not `@0` or `@latest`); f
219
275
  }
220
276
  ```
221
277
 
222
- Scales are declared once and named. Marks read data through channels (`"x": "region"` means field `region` on the scale named `x`). Guides attach to scales, not marks; several scales per axis direction are fine (dual axis). A block is referred to by its `type`, so `{"type": "rect"}` is `mark.rect`.
278
+ Scales are declared once and named. Marks read data through channels (`"x": "region"` means the field `region` on
279
+ the scale named `x`). Guides attach to scales, not to marks, and several scales per direction are fine (a dual axis).
280
+ A block is named by its `type`, so `{"type": "rect"}` is `mark.rect`. Custom tooltip content is a function registered
281
+ with `BC.defineFn(name, fn)` and named in the spec (`"content": "name"`), so specs stay plain JSON.
282
+
283
+ ### Clicks
284
+
285
+ `{"type": "click"}` among the interactions makes the data clickable: a click or a tap on a bar, a point, a slice or a
286
+ cell sends `bc-click` from the chart's element. It bubbles, so one listener can serve every chart of a page:
287
+
288
+ ```js
289
+ document.addEventListener('bc-click', (e) => {
290
+ const { values, row, mark, event } = e.detail; // values: { region: 'North', total: 42 }
291
+ if (event.metaKey || event.ctrlKey) window.open('/regions/' + values.region);
292
+ });
293
+ ```
294
+
295
+ `values` is the row with every column, not only the ones the mark reads; `row` is its index in the chart's table
296
+ (`table`), and `rows` every row a shape stands for (a line, a hexbin). `mark` and `markIndex` say which mark was hit,
297
+ `x` and `y` where it is in the chart, and `event` is the browser's click with its modifier keys. What a click hits is
298
+ what the tooltip shows there. A drag (a pan, a brush) is not a click, a double click sends one, a click on a legend
299
+ item stays the legend filter's, and the pointer is a hand over what can be clicked (`"cursor": false` keeps it as
300
+ it is). In TypeScript the event is typed: `HTMLElementEventMap['bc-click']` is `CustomEvent<BC.ClickDetail>`.
301
+
302
+ A report made by the composer has no script of its own to receive the event, so there the block is a warning.
303
+
304
+ ### JSON Schema
305
+
306
+ A spec and a `page.json` have a JSON Schema each, made from the blocks themselves: every block, parameter, channel
307
+ and value it may take, with its documentation. Name it in the file, and an editor completes keys and block types,
308
+ explains each on hover, and underlines a mistake while you type:
309
+
310
+ ```json
311
+ {
312
+ "$schema": "https://cdn.jsdelivr.net/npm/blockcharts@0.0.3/release/schema/page.schema.json",
313
+ "title": "Sales",
314
+ "data": { "sales": [ { "region": "North", "total": 42 } ] },
315
+ "charts": [ { "spec": { "data": "sales", "marks": [ { "type": "rect", "x": "region", "y": "total" } ] } } ]
316
+ }
317
+ ```
318
+
319
+ A chart spec on its own takes `schema/chart.schema.json`. The core and the composer accept the `$schema` key and
320
+ ignore it. Both schemas are draft-07, also in the package (`blockcharts/schema/chart.schema.json`) for a validator
321
+ such as Ajv. They catch what has no data behind it (an unknown block or key, a wrong value); a field missing from
322
+ the data is caught only by `BC.validate` and the composer, which read the data.
223
323
 
224
324
  ## Blocks
225
325
 
226
- The <!-- build:blocks -->58<!-- /build --> blocks, by role:
326
+ The <!-- build:blocks -->59<!-- /build --> blocks, by role:
227
327
 
228
328
  <!-- build:roles -->
229
329
 
@@ -234,54 +334,57 @@ The <!-- build:blocks -->58<!-- /build --> blocks, by role:
234
334
  | transform | `aggregate`, `bin`, `calculate`, `calendar`, `contour`, `decimate`, `density`, `filter`, `fold`, `funnel`, `hexbin`, `highlight`, `marimekko`, `quartiles`, `sankey`, `sort`, `stack`, `treemap`, `waterfall`, `window` |
235
335
  | mark | `arc`, `area`, `boxplot`, `candlestick`, `line`, `point`, `polygon`, `rect`, `rule`, `sankey`, `text`, `violin` |
236
336
  | guide | `axis`, `grid`, `kpi`, `legend` |
237
- | interaction | `animate`, `brush`, `crosshair`, `legend-filter`, `tooltip`, `zoom`, `zoom-controls` |
337
+ | interaction | `animate`, `brush`, `click`, `crosshair`, `legend-filter`, `tooltip`, `zoom`, `zoom-controls` |
238
338
  | renderer | `canvas`, `svg` |
239
339
 
240
340
  <!-- /build -->
241
341
 
242
- Every parameter of every block is documented in [`skills/blockcharts/reference/blocks.md`](skills/blockcharts/reference/blocks.md) (generated from the code by `npm run skill`).
243
-
244
- Custom tooltip content is a function registered in a script with `BC.defineFn(name, fn)` and referenced from the spec by name (`"content": "name"`), so specs stay plain JSON.
342
+ Every parameter of every block: [the block reference](https://blockcharts.online/blocks/), also in
343
+ [`skills/blockcharts/reference/blocks.md`](skills/blockcharts/reference/blocks.md).
245
344
 
246
- ## Website
247
-
248
- `site/` is an [Astro](https://astro.build) project: a gallery with every recipe live (its JSON, the composed report, the HTML to embed it), demos of every way to embed (one script tag, the loader, an ES module, the handle API with a custom tooltip, themes, data forms), a guide, and the block reference generated from the code. Every snippet shown is the code that runs above it.
249
-
250
- ```sh
251
- npm run site # builds the library, the release and the site -> site/dist, then checks links and charts
252
- SITE_BASE=/blockcharts/ npm run site # for a site served from a subfolder (GitHub Pages)
253
- npm run dev -w site # develop it (run npm run build and npm run manifest first)
254
- ```
345
+ ## Browser support
255
346
 
256
- The site has its own `package.json` and is an npm workspace of the root: one `npm install` at the root installs both, into one `node_modules`, from one lockfile (Node 22.22.1 or later for the site). The library has no runtime dependencies, nor has the composer; the dev dependencies are the tools that build and test it: TypeScript, esbuild (minifying), fflate (the `.skill` zip, gzip sizes), Prettier and playwright-core (the Chrome checks, with the system Chrome). `scripts/check-site.js` checks the result without a browser: every link, script and anchor resolves, and every chart spec on every page is valid against the data on that page.
347
+ Chrome and Edge 80, Firefox 74, Safari 14.1 or later: the code is ES2020, and compact numbers (`12K`) are `Intl`'s. A
348
+ dataset stored gzipped, which the composer does with a large one, is read with `DecompressionStream`: Firefox 113 and
349
+ Safari 16.4 (Chrome and Edge 80); an older browser shows a message in the chart's place. The composer needs Node 22+.
257
350
 
258
351
  ## Development
259
352
 
260
353
  ```sh
261
354
  npm install
262
- npm test # build, manifest, then core/blocks, canvas, composer, CSV, skill and release tests
355
+ npm test # build, then the core, blocks, canvas, composer, CSV, skill and release tests
263
356
  npm run test:chrome # layout in a real browser (the system Chrome)
264
- npm run skill # refresh the skill's generated parts (skills/blockcharts) and the figures this README quotes, write dist/blockcharts.skill
265
- npm run release # CDN files, kits, loader -> release/ (minified)
266
- npm run site # the website -> site/dist
267
- npm run test:site # every page of it in Chrome at phone widths
357
+ npm run release # kits, single blocks and the loader -> release/
358
+ npm run skill # the skill's generated parts and the figures this README quotes
268
359
  ```
269
360
 
270
- Layout, tests and releasing: [docs/development.md](docs/development.md). What is left to do:
361
+ Layout, tests, the website and releasing: [docs/development.md](docs/development.md). What is left to do:
271
362
  [ROADMAP.md](ROADMAP.md). Design decisions: [docs/Design.md](docs/Design.md).
272
363
 
273
- ## Browser support
364
+ ## For AI agents: the blockcharts skill
274
365
 
275
- Chrome and Edge 80, Firefox 74, Safari 14.1 or later: the code is ES2020, and compact numbers (`12K`) are `Intl`'s. A
276
- dataset stored gzipped, which the composer does with a large one, is read with `DecompressionStream`: Firefox 113 and
277
- Safari 16.4 (Chrome and Edge 80); an older browser shows a message in the chart's place. The composer needs Node 22+.
366
+ An agent skill turns a table or a CSV file into one light `.html` report with interactive charts. The agent writes
367
+ only the JSON; the composer bundled with the skill checks every chart against the data and writes the page.
368
+
369
+ **Claude Code** — from this repository, which is a plugin marketplace:
370
+
371
+ ```
372
+ /plugin marketplace add boligolov/blockcharts
373
+ /plugin install blockcharts@blockcharts
374
+ ```
375
+
376
+ It updates by itself once auto-update is on for the marketplace (`/plugin` → *Marketplaces*), or by hand with
377
+ `claude plugin update blockcharts@blockcharts`.
378
+
379
+ **Claude.ai and Claude Desktop** — download **[blockcharts.skill](https://blockcharts.online/blockcharts.skill)**
380
+ and upload it under *Settings → Capabilities → Skills* (skills need code execution enabled).
278
381
 
279
- ## Versions
382
+ **Any other agent that reads skill folders** — copy [`skills/blockcharts/`](skills/blockcharts/) into its skills
383
+ folder (`~/.claude/skills/` for Claude Code). It needs Node.js 22+.
280
384
 
281
- The skill and the library are versioned apart. The skill's version (`metadata.version` in `SKILL.md`, `version` in
282
- its `plugin.json`) goes up with every change to `skills/blockcharts/`, the composer and the code it carries included,
283
- so that Claude Code offers the update. The library's (`package.json`, the path of the CDN files, `BC.version`) goes up
284
- with a release of the npm package.
385
+ Then ask — *"an HTML report of monthly revenue by region from sales.csv"*, *"a dashboard of these KPIs"*. Scopes and
386
+ details: [docs/skill.md](docs/skill.md). The skill is versioned apart from the library (`metadata.version` in
387
+ `SKILL.md`, `version` in its `plugin.json`), so that Claude Code offers each update.
285
388
 
286
389
  ## License
287
390