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.
- package/README.md +274 -171
- package/package.json +43 -6
- package/release/bc.d.ts +35 -2
- package/release/blocks/guide.axis.js +2 -2
- package/release/blocks/guide.grid.js +2 -2
- package/release/blocks/guide.kpi.js +2 -2
- package/release/blocks/guide.legend.js +2 -2
- package/release/blocks/interaction.animate.js +2 -2
- package/release/blocks/interaction.brush.js +2 -2
- package/release/blocks/interaction.click.js +3 -0
- package/release/blocks/interaction.crosshair.js +2 -2
- package/release/blocks/interaction.legend-filter.js +2 -2
- package/release/blocks/interaction.tooltip.js +2 -2
- package/release/blocks/interaction.zoom-controls.js +2 -2
- package/release/blocks/interaction.zoom.js +2 -2
- package/release/blocks/lib.columns.js +2 -2
- package/release/blocks/lib.curve.js +2 -2
- package/release/blocks/lib.pointer.js +2 -2
- package/release/blocks/lib.stats.js +2 -2
- package/release/blocks/lib.ticks.js +2 -2
- package/release/blocks/lib.view.js +2 -2
- package/release/blocks/mark.arc.js +2 -2
- package/release/blocks/mark.area.js +2 -2
- package/release/blocks/mark.boxplot.js +2 -2
- package/release/blocks/mark.candlestick.js +2 -2
- package/release/blocks/mark.line.js +2 -2
- package/release/blocks/mark.point.js +2 -2
- package/release/blocks/mark.polygon.js +2 -2
- package/release/blocks/mark.rect.js +2 -2
- package/release/blocks/mark.rule.js +2 -2
- package/release/blocks/mark.sankey.js +2 -2
- package/release/blocks/mark.text.js +2 -2
- package/release/blocks/mark.violin.js +2 -2
- package/release/blocks/renderer.canvas.js +2 -2
- package/release/blocks/renderer.svg.js +2 -2
- package/release/blocks/scale.band.js +2 -2
- package/release/blocks/scale.color.js +2 -2
- package/release/blocks/scale.linear.js +2 -2
- package/release/blocks/scale.log.js +2 -2
- package/release/blocks/scale.sequential.js +2 -2
- package/release/blocks/scale.size.js +2 -2
- package/release/blocks/scale.time.js +2 -2
- package/release/blocks/transform.aggregate.js +2 -2
- package/release/blocks/transform.bin.js +2 -2
- package/release/blocks/transform.calculate.js +2 -2
- package/release/blocks/transform.calendar.js +2 -2
- package/release/blocks/transform.contour.js +2 -2
- package/release/blocks/transform.decimate.js +2 -2
- package/release/blocks/transform.density.js +2 -2
- package/release/blocks/transform.filter.js +2 -2
- package/release/blocks/transform.fold.js +2 -2
- package/release/blocks/transform.funnel.js +2 -2
- package/release/blocks/transform.hexbin.js +2 -2
- package/release/blocks/transform.highlight.js +2 -2
- package/release/blocks/transform.marimekko.js +2 -2
- package/release/blocks/transform.quartiles.js +2 -2
- package/release/blocks/transform.sankey.js +2 -2
- package/release/blocks/transform.sort.js +2 -2
- package/release/blocks/transform.stack.js +2 -2
- package/release/blocks/transform.treemap.js +2 -2
- package/release/blocks/transform.waterfall.js +2 -2
- package/release/blocks/transform.window.js +2 -2
- package/release/core.js +3 -3
- package/release/frameworks/controller.d.mts +51 -0
- package/release/frameworks/controller.mjs +181 -0
- package/release/frameworks/element.d.mts +32 -0
- package/release/frameworks/element.mjs +95 -0
- package/release/frameworks/react.d.mts +10 -0
- package/release/frameworks/react.mjs +30 -0
- package/release/frameworks/svelte.d.mts +9 -0
- package/release/frameworks/svelte.mjs +17 -0
- package/release/frameworks/vue.d.mts +40 -0
- package/release/frameworks/vue.mjs +44 -0
- package/release/kits/basic.js +25 -22
- package/release/kits/basic.mjs +25 -22
- package/release/kits/composition.js +39 -36
- package/release/kits/composition.mjs +39 -36
- package/release/kits/dashboard.js +37 -34
- package/release/kits/dashboard.mjs +37 -34
- package/release/kits/full.js +64 -61
- package/release/kits/full.mjs +64 -61
- package/release/kits/timeseries.js +35 -32
- package/release/kits/timeseries.mjs +35 -32
- package/release/loader.js +2 -2
- package/release/manifest.json +326 -221
- package/release/schema/chart.schema.json +4155 -0
- package/release/schema/page.schema.json +4547 -0
package/README.md
CHANGED
|
@@ -1,211 +1,267 @@
|
|
|
1
1
|
# blockcharts
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/blockcharts)
|
|
4
|
+
[](https://github.com/boligolov/blockcharts/actions/workflows/ci.yml)
|
|
5
|
+
[](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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
+
[](https://blockcharts.online/examples/executive-dashboard/)
|
|
61
16
|
|
|
62
|
-
|
|
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
|
-
|
|
20
|
+
## Quick start
|
|
65
21
|
|
|
66
|
-
|
|
22
|
+
One script tag, and a chart described in JSON where it should appear:
|
|
67
23
|
|
|
68
|
-
|
|
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
|
-
|
|
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
|
-
|
|
39
|
+
Charts draw themselves when the page loads. With a bundler or a framework:
|
|
77
40
|
|
|
78
41
|
```sh
|
|
79
|
-
|
|
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
|
-
|
|
45
|
+
```js
|
|
46
|
+
import BC from 'blockcharts';
|
|
87
47
|
|
|
88
|
-
|
|
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
|
-
|
|
52
|
+
## Why blockcharts
|
|
108
53
|
|
|
109
|
-
|
|
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
|
-
|
|
70
|
+
What it is built on: [the blockcharts principles](docs/spec/principles.md), v<!-- build:principles-version -->1.1<!-- /build -->.
|
|
112
71
|
|
|
113
|
-
|
|
72
|
+
## What it draws
|
|
114
73
|
|
|
115
|
-
|
|
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
|
-
|
|
118
|
-
|
|
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
|
-
|
|
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
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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
|
-
|
|
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` |
|
|
139
|
-
| `timeseries` |
|
|
140
|
-
| `composition` |
|
|
141
|
-
| `dashboard` |
|
|
142
|
-
| `full` |
|
|
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
|
|
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
|
-
|
|
149
|
-
|
|
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
|
-
`
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
150
|
+
### React, Vue, Svelte and `<block-chart>`
|
|
173
151
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
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
|
-
|
|
162
|
+
```vue
|
|
163
|
+
<script setup>
|
|
164
|
+
import 'blockcharts/kits/basic.mjs';
|
|
165
|
+
import { BlockChart } from 'blockcharts/vue';
|
|
166
|
+
</script>
|
|
180
167
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
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
|
-
|
|
173
|
+
```svelte
|
|
174
|
+
<script>
|
|
175
|
+
import 'blockcharts/kits/basic.mjs';
|
|
176
|
+
import { blockchart } from 'blockcharts/svelte';
|
|
177
|
+
</script>
|
|
192
178
|
|
|
193
|
-
|
|
194
|
-
|
|
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
|
-
|
|
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
|
-
`
|
|
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.
|
|
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
|
-
|
|
220
|
+
### The composer: one standalone report
|
|
207
221
|
|
|
208
|
-
|
|
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
|
|
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 -->
|
|
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
|
|
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
|
-
##
|
|
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
|
-
|
|
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
|
|
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
|
|
265
|
-
npm run
|
|
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
|
-
##
|
|
364
|
+
## For AI agents: the blockcharts skill
|
|
274
365
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
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
|
-
|
|
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
|
-
|
|
282
|
-
|
|
283
|
-
|
|
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
|
|