blockcharts 0.0.2 → 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 +118 -17
  2. package/package.json +43 -6
  3. package/release/bc.d.ts +35 -2
  4. package/release/blocks/guide.axis.js +1 -1
  5. package/release/blocks/guide.grid.js +1 -1
  6. package/release/blocks/guide.kpi.js +1 -1
  7. package/release/blocks/guide.legend.js +1 -1
  8. package/release/blocks/interaction.animate.js +1 -1
  9. package/release/blocks/interaction.brush.js +1 -1
  10. package/release/blocks/interaction.click.js +3 -0
  11. package/release/blocks/interaction.crosshair.js +1 -1
  12. package/release/blocks/interaction.legend-filter.js +1 -1
  13. package/release/blocks/interaction.tooltip.js +2 -2
  14. package/release/blocks/interaction.zoom-controls.js +1 -1
  15. package/release/blocks/interaction.zoom.js +1 -1
  16. package/release/blocks/lib.columns.js +1 -1
  17. package/release/blocks/lib.curve.js +1 -1
  18. package/release/blocks/lib.pointer.js +2 -2
  19. package/release/blocks/lib.stats.js +1 -1
  20. package/release/blocks/lib.ticks.js +1 -1
  21. package/release/blocks/lib.view.js +1 -1
  22. package/release/blocks/mark.arc.js +1 -1
  23. package/release/blocks/mark.area.js +1 -1
  24. package/release/blocks/mark.boxplot.js +1 -1
  25. package/release/blocks/mark.candlestick.js +1 -1
  26. package/release/blocks/mark.line.js +1 -1
  27. package/release/blocks/mark.point.js +1 -1
  28. package/release/blocks/mark.polygon.js +1 -1
  29. package/release/blocks/mark.rect.js +1 -1
  30. package/release/blocks/mark.rule.js +1 -1
  31. package/release/blocks/mark.sankey.js +1 -1
  32. package/release/blocks/mark.text.js +1 -1
  33. package/release/blocks/mark.violin.js +1 -1
  34. package/release/blocks/renderer.canvas.js +1 -1
  35. package/release/blocks/renderer.svg.js +1 -1
  36. package/release/blocks/scale.band.js +1 -1
  37. package/release/blocks/scale.color.js +1 -1
  38. package/release/blocks/scale.linear.js +1 -1
  39. package/release/blocks/scale.log.js +1 -1
  40. package/release/blocks/scale.sequential.js +1 -1
  41. package/release/blocks/scale.size.js +1 -1
  42. package/release/blocks/scale.time.js +1 -1
  43. package/release/blocks/transform.aggregate.js +1 -1
  44. package/release/blocks/transform.bin.js +1 -1
  45. package/release/blocks/transform.calculate.js +1 -1
  46. package/release/blocks/transform.calendar.js +1 -1
  47. package/release/blocks/transform.contour.js +1 -1
  48. package/release/blocks/transform.decimate.js +1 -1
  49. package/release/blocks/transform.density.js +1 -1
  50. package/release/blocks/transform.filter.js +1 -1
  51. package/release/blocks/transform.fold.js +1 -1
  52. package/release/blocks/transform.funnel.js +1 -1
  53. package/release/blocks/transform.hexbin.js +1 -1
  54. package/release/blocks/transform.highlight.js +1 -1
  55. package/release/blocks/transform.marimekko.js +1 -1
  56. package/release/blocks/transform.quartiles.js +1 -1
  57. package/release/blocks/transform.sankey.js +1 -1
  58. package/release/blocks/transform.sort.js +1 -1
  59. package/release/blocks/transform.stack.js +1 -1
  60. package/release/blocks/transform.treemap.js +1 -1
  61. package/release/blocks/transform.waterfall.js +1 -1
  62. package/release/blocks/transform.window.js +1 -1
  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 +8 -5
  75. package/release/kits/basic.mjs +8 -5
  76. package/release/kits/composition.js +8 -5
  77. package/release/kits/composition.mjs +8 -5
  78. package/release/kits/dashboard.js +8 -5
  79. package/release/kits/dashboard.mjs +8 -5
  80. package/release/kits/full.js +8 -5
  81. package/release/kits/full.mjs +8 -5
  82. package/release/kits/timeseries.js +8 -5
  83. package/release/kits/timeseries.mjs +8 -5
  84. package/release/loader.js +1 -1
  85. package/release/manifest.json +227 -122
  86. package/release/schema/chart.schema.json +4155 -0
  87. package/release/schema/page.schema.json +4547 -0
package/README.md CHANGED
@@ -22,7 +22,7 @@ Charts are described in JSON, drawn in SVG or on a canvas, and every part can be
22
22
  One script tag, and a chart described in JSON where it should appear:
23
23
 
24
24
  ```html
25
- <script src="https://cdn.jsdelivr.net/npm/blockcharts@0.0.2/release/kits/basic.js"></script>
25
+ <script src="https://cdn.jsdelivr.net/npm/blockcharts@0.0.3/release/kits/basic.js"></script>
26
26
 
27
27
  <script type="application/json" id="bc-data">
28
28
  { "sales": [ { "region": "North", "total": 42 }, { "region": "South", "total": 58 }, { "region": "East", "total": 31 } ] }
@@ -52,7 +52,7 @@ const chart = BC.chart(document.getElementById('chart'), spec); // update, setVi
52
52
  ## Why blockcharts
53
53
 
54
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 58 blocks, 71 KB of code instead of 214<!-- /build -->; a whole
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
56
  executive dashboard (KPI tiles, a trend, a donut, a waterfall, a funnel, animated) carries <!-- build:dashboard-blocks -->24<!-- /build -->. Nobody lists
57
57
  blocks by hand, so the list is never too long.
58
58
  - **Charts are data, checked before they are drawn.** A chart is a plain JSON spec, not code. It is checked against
@@ -85,7 +85,8 @@ Every kind is live in the [gallery](https://blockcharts.online/examples/), with
85
85
  | --- | --- |
86
86
  | Charts in your own page, one `<script>` | a **kit**: the core and a set of blocks in one file |
87
87
  | Each page to fetch only what it uses | the **loader**: `loader.js`, the core and single block files |
88
- | A bundler or a framework component | the **npm package**: `import BC from 'blockcharts'` |
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` |
89
90
  | One report file, nothing to host | the **composer**: JSON and data in, one HTML file out |
90
91
 
91
92
  ### Kits
@@ -97,11 +98,11 @@ A kit is the core and a set of blocks in one file: a classic script (`kits/<name
97
98
 
98
99
  | Kit | Blocks | Contents | Minified (gzip) |
99
100
  |---|---|---|---|
100
- | `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) |
101
- | `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. | 141 KB (52 KB) |
102
- | `composition` | 33 | Parts of a whole and distributions: stacked bars and areas, pie, heatmap, histogram, boxplot, waterfall, funnel, treemap, aggregation. | 149 KB (54 KB) |
103
- | `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) |
104
- | `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) |
105
106
 
106
107
  <!-- /build -->
107
108
 
@@ -111,7 +112,7 @@ Charts mount themselves on `DOMContentLoaded`; or call `BC.chart(element, spec)`
111
112
  ### The loader
112
113
 
113
114
  ```html
114
- <script src="https://cdn.jsdelivr.net/npm/blockcharts@0.0.2/release/loader.js" data-auto></script>
115
+ <script src="https://cdn.jsdelivr.net/npm/blockcharts@0.0.3/release/loader.js" data-auto></script>
115
116
  <!-- your data and <script data-bc-chart> specs -->
116
117
  ```
117
118
 
@@ -120,7 +121,7 @@ only those (with their dependencies) and draws. By hand:
120
121
 
121
122
  ```js
122
123
  await BCLoader.load({
123
- base: 'https://cdn.jsdelivr.net/npm/blockcharts@0.0.2/release/', // default: the folder of loader.js
124
+ base: 'https://cdn.jsdelivr.net/npm/blockcharts@0.0.3/release/', // default: the folder of loader.js
124
125
  blocks: ['interaction.zoom'], // extra blocks besides the ones found in the page
125
126
  scan: true, // find charts on the page (default)
126
127
  mount: true, // draw them when loaded (default)
@@ -141,20 +142,79 @@ import manifest from 'blockcharts/manifest.json' with { type: 'json' };
141
142
  const BC = require('blockcharts'); // CommonJS: the same full kit
142
143
  ```
143
144
 
144
- The package carries the built files: kits, single blocks, the loader, the manifest and the types. Every kit has a
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
145
147
  `.d.mts` (and a `.d.ts` for `require`); `blockcharts/bc.d.ts` declares the global `BC` and every spec type. A
146
148
  `<script src>` names the file where it is: `node_modules/blockcharts/release/kits/basic.js`.
147
149
 
150
+ ### React, Vue, Svelte and `<block-chart>`
151
+
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)} />;
160
+ ```
161
+
162
+ ```vue
163
+ <script setup>
164
+ import 'blockcharts/kits/basic.mjs';
165
+ import { BlockChart } from 'blockcharts/vue';
166
+ </script>
167
+
168
+ <template>
169
+ <BlockChart :spec="spec" :data="rows" @click="(d) => openRegion(d.values.region)" />
170
+ </template>
171
+ ```
172
+
173
+ ```svelte
174
+ <script>
175
+ import 'blockcharts/kits/basic.mjs';
176
+ import { blockchart } from 'blockcharts/svelte';
177
+ </script>
178
+
179
+ <div use:blockchart={{ spec, data: rows, onClick: (d) => openRegion(d.values.region) }}></div>
180
+ ```
181
+
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
+ ```
192
+
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
+
148
207
  ### CDN and integrity
149
208
 
150
209
  jsDelivr and unpkg serve every file of the package at its path in it:
151
210
  `https://cdn.jsdelivr.net/npm/blockcharts@<version>/release/<file>` (or `https://unpkg.com/blockcharts@<version>/release/<file>`),
152
- where `<file>` is `core.js`, `blocks/<role.type>.js`, `kits/<name>.js` or `.mjs`, `loader.js`, `manifest.json` or
153
- `bc.d.ts`. Pin an exact version (`@0.0.2`, not `@0` or `@latest`): files of a version never change, and
154
- `manifest.json` lists a `sha384` hash of every file for the `integrity` attribute:
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:
155
215
 
156
216
  ```html
157
- <script src="https://cdn.jsdelivr.net/npm/blockcharts@0.0.2/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>
158
218
  ```
159
219
 
160
220
  ### The composer: one standalone report
@@ -220,9 +280,50 @@ the scale named `x`). Guides attach to scales, not to marks, and several scales
220
280
  A block is named by its `type`, so `{"type": "rect"}` is `mark.rect`. Custom tooltip content is a function registered
221
281
  with `BC.defineFn(name, fn)` and named in the spec (`"content": "name"`), so specs stay plain JSON.
222
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.
323
+
223
324
  ## Blocks
224
325
 
225
- The <!-- build:blocks -->58<!-- /build --> blocks, by role:
326
+ The <!-- build:blocks -->59<!-- /build --> blocks, by role:
226
327
 
227
328
  <!-- build:roles -->
228
329
 
@@ -233,7 +334,7 @@ The <!-- build:blocks -->58<!-- /build --> blocks, by role:
233
334
  | transform | `aggregate`, `bin`, `calculate`, `calendar`, `contour`, `decimate`, `density`, `filter`, `fold`, `funnel`, `hexbin`, `highlight`, `marimekko`, `quartiles`, `sankey`, `sort`, `stack`, `treemap`, `waterfall`, `window` |
234
335
  | mark | `arc`, `area`, `boxplot`, `candlestick`, `line`, `point`, `polygon`, `rect`, `rule`, `sankey`, `text`, `violin` |
235
336
  | guide | `axis`, `grid`, `kpi`, `legend` |
236
- | interaction | `animate`, `brush`, `crosshair`, `legend-filter`, `tooltip`, `zoom`, `zoom-controls` |
337
+ | interaction | `animate`, `brush`, `click`, `crosshair`, `legend-filter`, `tooltip`, `zoom`, `zoom-controls` |
237
338
  | renderer | `canvas`, `svg` |
238
339
 
239
340
  <!-- /build -->
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blockcharts",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "Interactive SVG and canvas charts described as JSON, assembled from independent blocks. For standalone HTML reports and for pages of your own.",
5
5
  "keywords": [
6
6
  "charts",
@@ -47,6 +47,23 @@
47
47
  "./loader.js": "./release/loader.js",
48
48
  "./manifest.json": "./release/manifest.json",
49
49
  "./bc.d.ts": "./release/bc.d.ts",
50
+ "./schema/*": "./release/schema/*",
51
+ "./react": {
52
+ "types": "./release/frameworks/react.d.mts",
53
+ "default": "./release/frameworks/react.mjs"
54
+ },
55
+ "./vue": {
56
+ "types": "./release/frameworks/vue.d.mts",
57
+ "default": "./release/frameworks/vue.mjs"
58
+ },
59
+ "./svelte": {
60
+ "types": "./release/frameworks/svelte.d.mts",
61
+ "default": "./release/frameworks/svelte.mjs"
62
+ },
63
+ "./element": {
64
+ "types": "./release/frameworks/element.d.mts",
65
+ "default": "./release/frameworks/element.mjs"
66
+ },
50
67
  "./package.json": "./package.json"
51
68
  },
52
69
  "files": [
@@ -58,29 +75,49 @@
58
75
  "engines": {
59
76
  "node": ">=22"
60
77
  },
78
+ "peerDependencies": {
79
+ "react": ">=18",
80
+ "vue": ">=3.3"
81
+ },
82
+ "peerDependenciesMeta": {
83
+ "react": {
84
+ "optional": true
85
+ },
86
+ "vue": {
87
+ "optional": true
88
+ }
89
+ },
61
90
  "workspaces": [
62
91
  "site"
63
92
  ],
64
93
  "scripts": {
65
- "build": "tsc",
94
+ "build": "tsc && tsc -p tsconfig.frameworks.json",
66
95
  "manifest": "node scripts/build-manifest.js && node scripts/minify.js",
67
- "test": "npm run build && npm run manifest && node scripts/test.js && node scripts/test-canvas.js && node scripts/test-compose.js && node scripts/test-csv.js && node scripts/test-skill.js && node scripts/test-dist.js",
96
+ "test": "npm run build && npm run manifest && node scripts/test.js && node scripts/test-canvas.js && node scripts/test-compose.js && node scripts/test-csv.js && node scripts/test-skill.js && node scripts/test-dist.js && node scripts/test-schema.js",
68
97
  "test:chrome": "npm run build && npm run manifest && node scripts/test-chrome.js",
98
+ "test:frameworks": "npm run build && npm run manifest && node scripts/test-frameworks.js",
69
99
  "skill": "npm run build && npm run manifest && node scripts/build-skill.js && node scripts/build-docs.js",
70
100
  "release": "npm run build && npm run manifest && node scripts/build-dist.js",
71
101
  "og": "node scripts/og-image.js",
72
102
  "test:site": "node scripts/check-site-phone.js",
73
103
  "site": "npm run build && npm run manifest && npm run build -w site && node scripts/check-site.js",
74
104
  "prepack": "npm run release",
75
- "format": "prettier --write \"src/**/*.ts\" \"scripts/**/*.js\" \"site/src/**/*.{mjs,css}\" site/astro.config.mjs",
76
- "format:check": "prettier --check \"src/**/*.ts\" \"scripts/**/*.js\" \"site/src/**/*.{mjs,css}\" site/astro.config.mjs"
105
+ "format": "prettier --write \"src/**/*.{ts,mts}\" \"scripts/**/*.js\" \"site/src/**/*.{mjs,css}\" site/astro.config.mjs",
106
+ "format:check": "prettier --check \"src/**/*.{ts,mts}\" \"scripts/**/*.js\" \"site/src/**/*.{mjs,css}\" site/astro.config.mjs"
77
107
  },
78
108
  "devDependencies": {
109
+ "@types/react": "^19.3.1",
110
+ "@types/react-dom": "^19.3.0",
111
+ "ajv": "^8.20.0",
79
112
  "esbuild": "^0.28.2",
80
113
  "fflate": "^0.8.3",
81
114
  "playwright-core": "^1.64.1",
82
115
  "prettier": "^3.9.10",
83
- "typescript": "^7.0.2"
116
+ "react": "^19.3.1",
117
+ "react-dom": "^19.3.1",
118
+ "svelte": "^5.59.1",
119
+ "typescript": "^7.0.2",
120
+ "vue": "^3.5.46"
84
121
  },
85
122
  "allowScripts": {
86
123
  "esbuild": true,
package/release/bc.d.ts CHANGED
@@ -61,6 +61,8 @@ declare namespace BC {
61
61
  }
62
62
 
63
63
  interface ChartSpec {
64
+ /** The JSON Schema the spec follows (release/schema/chart.schema.json), for an editor; the chart ignores it. */
65
+ $schema?: string;
64
66
  id?: string;
65
67
  /** Key in the data lake. */
66
68
  data: string;
@@ -141,6 +143,25 @@ declare namespace BC {
141
143
  table: Table;
142
144
  }
143
145
 
146
+ /** What interaction.click sends with its `bc-click` event (`event.detail`), from the chart's element, for a click or a tap
147
+ * on the data: the datum the tooltip shows there. */
148
+ interface ClickDetail {
149
+ /** Row of the table (after the transforms) that was clicked. */
150
+ row: number;
151
+ /** Every row the shape stands for (see Pick.rows); just `row` for most shapes. */
152
+ rows: number[];
153
+ /** Every column of that row, not only the ones the mark reads. */
154
+ values: Record<string, unknown>;
155
+ mark: MarkSpec;
156
+ markIndex: number;
157
+ /** Anchor of the datum, in display-list px. */
158
+ x: number;
159
+ y: number;
160
+ table: Table;
161
+ /** The browser's click: modifier keys, the button, where on the page. */
162
+ event: MouseEvent;
163
+ }
164
+
144
165
  /** What a tooltip `content` function may return. A string is inserted as text. `{ html }` is inserted as markup
145
166
  * (the caller is responsible for escaping data in it). A Node is inserted as is. An array inserts each item.
146
167
  * null / false hides the tooltip; undefined keeps the default content. */
@@ -613,6 +634,9 @@ declare namespace BC {
613
634
 
614
635
  interface InteractionDef extends BlockBase {
615
636
  role: 'interaction';
637
+ /** DOM events it sends from the chart's element (`host`, they bubble) for a script of the page: "bc-click". Listed in the
638
+ * manifest; a page the composer makes from JSON alone has no script to listen, and gets a warning. */
639
+ events?: readonly string[];
616
640
  /** For an overlay that sits in a corner of the chart: which one, and how far along its edge from the end of the chart.
617
641
  * Read at layout, so what is drawn along that edge can keep clear of it. */
618
642
  corner?(spec: InteractionSpec, ctx: ChartCtx): { edge: 'top' | 'bottom'; side: 'left' | 'right'; width: number } | null;
@@ -706,8 +730,9 @@ declare namespace BC {
706
730
 
707
731
  /** Add/replace a dataset in the data lake (the page's #bc-data is loaded on mount). Rows and columns are
708
732
  * available at once; an EncodedDataset is decoded in the background (a failure is reported by the charts
709
- * that use it, and by console.error). A malformed plain dataset throws. */
710
- data(name: string, input: DatasetInput): void;
733
+ * that use it, and by console.error). A malformed plain dataset throws. `null` removes the dataset (a decode still
734
+ * running for it is dropped); a chart already drawn from it keeps its drawing until it is built again. */
735
+ data(name: string, input: DatasetInput | null): void;
711
736
  /** Resolves when every dataset that was being decoded has settled. Never rejects. */
712
737
  ready(): Promise<void>;
713
738
  /** Register a function that specs can refer to by name (e.g. tooltip `content: "myTip"`), because JSON
@@ -752,6 +777,8 @@ declare namespace BC {
752
777
  closure: BlockName[];
753
778
  params?: Record<string, ParamDef>;
754
779
  channels?: Record<string, ChannelDef>;
780
+ /** InteractionDef.events */
781
+ events?: string[];
755
782
  doc?: string;
756
783
  }
757
784
 
@@ -762,3 +789,9 @@ declare namespace BC {
762
789
  }
763
790
 
764
791
  declare const BC: BC.Runtime;
792
+
793
+ /** The events a chart sends from its element, typed for addEventListener. */
794
+ interface HTMLElementEventMap {
795
+ /** interaction.click: a click on the data of a chart. It bubbles, so one listener on the page hears every chart. */
796
+ 'bc-click': CustomEvent<BC.ClickDetail>;
797
+ }
@@ -1,3 +1,3 @@
1
- /*! blockcharts 0.0.2 | MIT License */
1
+ /*! blockcharts 0.0.3 | MIT License */
2
2
  "use strict";(function(E){const ot="var(--bc-axis, #888)",S="var(--bc-text, #444)",z="var(--bc-label, var(--bc-text, #444))",I=t=>t.ticks===!0?9:8,K=(t,e)=>t.line==="on"?!0:t.line==="off"?!1:e==="top"||e==="bottom";function L(t,e){return t.position?t.position:t.scale&&e.orientation(t.scale)==="vertical"?"left":"bottom"}const F=new WeakMap,A=.71,st=14,V=19,G=20,_=6,it=.85,lt=/^\s*-?\d[\d.,:\/-]*(T[\d:.]+Z?)?\s*$/;function P(t,e){let i=0,o=0;for(const n of e.spec.guides||[])if(n!==t)if(n.type==="axis"){const s=n.scale?L(n,e):"top",a=(s==="left"||s==="right")&&nt.measure(n,e)[s]||0;s==="left"?i+=a:s==="right"&&(o+=a)}else{const s=E.get(`guide.${n.type}`),a=s&&s.measure?s.measure(n,e):{};i+=a.left||0,o+=a.right||0}return{x:e.plot.x+i,w:e.plot.w-i-o}}function rt(t,e,i){const o=t.scale?e.scales[t.scale]:void 0;if(!o||o.input!=="category"||i==="left"||i==="right"||e.orientation(t.scale)!=="horizontal")return 0;const n=o.domain(),s=P(t,e).w;return n.length<2||s/n.length<st||n.every(a=>typeof a=="number"||a instanceof Date||lt.test(String(a)))||X(t,e,s)>=n.length?0:s/n.length<V?90:45}const at=/[、。,.・:;?!)」』】〕》〉ーゝゞ々ぁぃぅぇぉっゃゅょゎァィゥェォッャュョヮヵヶ]/,ft=/[(「『【〔《〈]/,H=/\d/;function q(t,e){const i=[];for(let o=1;o<t.length;o++){const n=t[o-1],s=t[o];!e.wide(n)||at.test(s)||ft.test(n)||H.test(s)&&!(o>=2&&H.test(t[o-2]))||i.push(o)}return i}function B(t,e,i){const o=Array.from(t),n=(r,u)=>i.measure(o.slice(r,u).join(""),11).w;let s=-1,a=1/0;for(const r of q(o,i)){const u=n(0,r);if(u>e)break;const m=Math.max(u,n(r,o.length));m<a&&(a=m,s=r)}if(s<0){const r=q(o,i);if(!r.length)return[t];s=r[0]}return[o.slice(0,s).join(""),o.slice(s).join("")]}function X(t,e,i){const o=t.scale,n=e.orientation(o)==="horizontal";let s=0;for(const a of e.scales[o].domain()){const r=String(a);if(!n){s=Math.max(s,e.measure(r,11).h);continue}const u=e.measure(r,11).w,m=r.split(/\s+/).filter(Boolean),l=m.length===1&&e.wide(r)?Math.max(...B(r,1/0,e).map(f=>e.measure(f,11).w)):m.reduce((f,h)=>Math.max(f,e.measure(h,11).w),0);s=Math.max(s,Math.min(u,Math.max(l,u/2)))}return Math.floor(i/(n?s*.9+4:s+3))}const D=t=>t.length>G?t.slice(0,G-1)+"\u2026":t;function R(t,e){return ut(mt(t,e),t,e)}function ut(t,e,i){if(i.scales[e.scale].input==="category"||i.orientation(e.scale)!=="horizontal")return t;const o=Q(e),n=t.filter((u,m)=>m===0||u.label!==t[m-1].label);if(n.length<2)return n;let s=1/0;for(let u=1;u<n.length;u++)s=Math.min(s,Math.abs(n[u].pos-n[u-1].pos));const a=n.reduce((u,m)=>Math.max(u,i.measure(m.label,11).w),0),r=s>0?Math.ceil((a+_)/s):1;return r>1?n.filter((u,m)=>o(m,n.length,r)):n}const Q=t=>(e,i,o)=>(t.anchor==="end"?i-1-e:e)%o===0;function ht(t,e){if(t.format===void 0||e.orientation(t.scale)!=="horizontal")return 0;const i=E.formatter(t.format),o=e.scales[t.scale].domain(),n=o.reduce((s,a)=>Math.max(s,e.measure(i(a),11).w),0);return Math.min(o.length,Math.floor(e.plot.w/(n+_)))}function ct(t,e){const i=t.scale,o=e.scales[i],n=typeof t.count=="number"&&t.count>=1?Math.round(t.count):void 0;if(o.input!=="category")return n===void 0?e.ticks(i):e.ticks(i,n);const s=Math.max(e.ticks(i).length,ht(t,e)),a=n===void 0?s:Math.min(n,s);if(t.anchor!=="end")return e.ticks(i,a);const r=e.ticks(i,o.domain().length),u=Math.max(1,Math.ceil(r.length/Math.max(1,a))),m=Q(t);return r.filter((l,f)=>m(f,r.length,u))}function mt(t,e){const i=e.scales[t.scale],o=F.has(t)?e.ticks(t.scale,i.domain().length):ct(t,e);if(t.format===void 0||i.output!=="position")return o;const{input:n}=i,s=E.formatter(t.format,n==="date"?"date":n==="category"?void 0:"number");return o.map(a=>({value:a.value,pos:a.pos,label:s(a.value)}))}const U=(t,e)=>F.has(t)?R(t,e).map(i=>({...i,label:D(i.label)})):R(t,e),x=t=>typeof t.title=="string"?t.title:"",N=11*1.25,dt=.3;function Z(t,e,i){if(i.measure(t,11).w<=e)return t;const o=Array.from(t);let n=0,s=o.length;for(;n<s;){const a=n+s+1>>1;i.measure(o.slice(0,a).join("")+"\u2026",11).w<=e?n=a:s=a-1}return o.slice(0,n).join("").trimEnd()+"\u2026"}function gt(t,e,i){const o=t.split(/\s+/).filter(Boolean);if(o.length<2){if(!i.wide(t))return null;const a=Array.from(t);let r=0;for(;r<a.length-1&&i.measure(a.slice(0,r+1).join(""),11).w<=e;)r++;return r?[a.slice(0,r).join(""),a.slice(r).join("")]:null}if(i.measure(o[0],11).w>e)return null;let n=o[0],s=1;for(;s<o.length-1&&i.measure(n+" "+o[s],11).w<=e;)n+=" "+o[s++];return[n,o.slice(s).join(" ")]}function wt(t,e){const i=e.scales[t.scale],o=i.input==="category"?i.domain().length:0,n=Math.max(44,e.size.w*dt),s=o>0&&e.plot.h/o>=2*N+2;return a=>{if(e.measure(a,11).w<=n)return[a];const r=s?gt(a,n,e):null;return r?[r[0],Z(r[1],n,e)]:[Z(a,n,e)]}}function j(t,e,i){if(t.scale&&(i==="left"||i==="right"))return wt(t,e);const o=t.scale?e.scales[t.scale]:void 0,n=o&&o.input==="category"?o.domain().length:0;if(!n)return a=>[a];const s=e.plot.w/n-6;return a=>J(a,s,e)}function J(t,e,i){if(i.measure(t,11).w<=e)return[t];const o=t.split(/\s+/).filter(Boolean);if(o.length<2)return i.wide(t)?B(t,e,i):[t];let n=o[0],s=1;for(;s<o.length-1&&i.measure(n+" "+o[s],11).w<=e;)n+=" "+o[s++];return[n,o.slice(s).join(" ")]}const Y=new WeakMap;function W(t,e){const{text:i,from:o,to:n}=t;if(i===void 0&&o===void 0&&n===void 0)return null;if(typeof i!="string"||typeof o!="string"||typeof n!="string")throw new Error('an axis that names spans needs all three of "text", "from" and "to"');const s=L(t,e);if(s==="left"||s==="right")throw new Error('"text", "from" and "to" name spans along a horizontal axis (top or bottom)');return{text:i,from:o,to:n}}function Tt(t,e,i){const o=W(t,e),n=e.table.columns,s=n[o.text],a=n[o.from],r=n[o.to],u=e.scales[t.scale];if(!s||!a||!r||!u)return[];const m=t.format!==void 0?E.formatter(t.format):null,l=e.plot,f=g=>i.x+(g-l.x)*i.w/l.w,h=[],c=new Set;for(let g=0;g<e.table.length;g++){const T=s[g];if(T==null||T==="")continue;const O=m?m(T):String(T),d=u(a[g]),b=u(r[g]);if(!O||typeof d!="number"||typeof b!="number"||!isFinite(d)||!isFinite(b))continue;const k=(d+b)/2;if(k<l.x-.5||k>l.x+l.w+.5)continue;const y=`${d},${b}|${O}`;if(c.has(y))continue;c.add(y);const p=f(Math.min(d,b)),w=f(Math.max(d,b));h.push({label:O,lo:p,hi:w,mid:(p+w)/2})}return h.sort((g,T)=>g.mid-T.mid)}function bt(t,e,i,o){const n=t.map(l=>{const f=J(l.label,l.hi-l.lo-_,e),h=f.reduce((g,T)=>Math.max(g,e.textWidth(T,11)),0),c=f.reduce((g,T)=>Math.max(g,e.measure(T,11).w),h);return{...l,lines:f,w:h,room:c,x:l.mid}}),s=n.length;if(!s)return{named:n,ok:!0};const a=[0];for(let l=1;l<s;l++)a.push(a[l-1]+(n[l-1].w+n[l].w)/2+_);const r=[];for(let l=0;l<s;l++){let f={first:l,last:l,sum:n[l].mid-a[l]};for(;r.length;){const h=r[r.length-1];if(h.sum/(h.last-h.first+1)<f.sum/(f.last-f.first+1))break;r.pop(),f={first:h.first,last:f.last,sum:h.sum+f.sum}}r.push(f)}for(const l of r)for(let f=l.first;f<=l.last;f++)n[f].x=l.sum/(l.last-l.first+1)+a[f];const u=l=>a[l]-a[l-1];n[s-1].x=Math.min(n[s-1].x,o-n[s-1].room/2);for(let l=s-2;l>=0;l--)n[l].x=Math.min(n[l].x,n[l+1].x-u(l+1));n[0].x=Math.max(n[0].x,i+n[0].room/2);for(let l=1;l<s;l++)n[l].x=Math.max(n[l].x,n[l-1].x+u(l));const m=n[s-1].x+n[s-1].room/2<=o+.5&&n.every(l=>Math.abs(l.x-l.mid)<=l.w/2);return{named:n,ok:m}}const Mt=2;function tt(t,e,i){const o=i?P(t,e):{x:e.plot.x,w:e.plot.w},n=Tt(t,e,o).filter(r=>r.hi-r.lo>=Mt),s=i?void 0:Y.get(t),a=[];for(const r of n){const u=a[a.length-1];if(u&&r.mid-u.mid<V){r.hi-r.lo>u.hi-u.lo&&(a[a.length-1]=r);continue}a.push(r)}if(!s){const r=m=>bt(m,e,0,e.size.w);let u=r(n);if(!u.ok){const m=n.map((c,g)=>g).sort((c,g)=>n[c].hi-n[c].lo-(n[g].hi-n[g].lo)),l=c=>{const g=new Set(m.slice(0,c));return n.filter((T,O)=>!g.has(O))};let f=1,h=n.length;for(;f<h;){const c=f+h>>1;r(l(c)).ok?h=c:f=c+1}u=r(l(f))}if(s===0||u.named.length>=a.length)return{angle:0,named:u.named}}return{angle:45,named:a.map(r=>({...r,label:D(r.label),lines:[D(r.label)],w:0,room:0,x:r.mid}))}}function et(t,e,i,o,n){const s=o===90?0:A,a=o===90?1:A;let r=0,u=0,m=0;for(const f of n){const h=e.textWidth(f.label,11),c=(h+11)*s;r=Math.max(r,h*a),i==="bottom"?u=Math.max(u,e.plot.x-(f.pos-c)):m=Math.max(m,f.pos+c-(e.plot.x+e.plot.w))}const l={overhang:{top:0,right:m,bottom:0,left:u}};return l[i]=I(t)+r+11*A+4+(x(t)?20.4:0),l}const nt={role:"guide",type:"axis",version:20,params:{scale:{kind:"scale",required:!0},position:{kind:"enum",values:["top","right","bottom","left"]},title:{kind:"string"},format:{kind:"format"},line:{kind:"enum",values:["auto","on","off"],default:"auto"},ticks:{kind:"boolean",default:!1},count:{kind:"number"},anchor:{kind:"enum",values:["start","end"],default:"start"},text:{kind:"field"},from:{kind:"field"},to:{kind:"field"}},fits:X,measure(t,e){if(!t.scale)return{};const i=L(t,e),o=i==="left"||i==="right";if(W(t,e)){const{angle:l,named:f}=tt(t,e,!0);if(Y.set(t,l),l)return et(t,e,i,l,f.map(d=>({pos:d.x,label:d.label})));const h=P(t,e);let c=0,g=0,T=0;for(const d of f)c=Math.max(c,d.lines.length>1?d.lines.length*N:e.measure(d.label,11).h),g=Math.max(g,h.x-(d.x-d.room/2)),T=Math.max(T,d.x+d.room/2-(h.x+h.w));const O={overhang:{top:0,right:T,bottom:0,left:g}};return O[i]=I(t)+c+4+(x(t)?20.4:0),O}const n=rt(t,e,i);if(n?F.set(t,n):F.delete(t),n)return et(t,e,i,n,U(t,e));let s=0;const a={top:0,right:0,bottom:0,left:0},r=e.plot,u=j(t,e,i);for(const l of R(t,e)){const f=u(l.label),h=f.reduce((c,g)=>{const T=e.measure(g,11);return{w:Math.max(c.w,T.w),h:c.h}},{w:0,h:f.length>1?f.length*N:e.measure(l.label,11).h});if(s=Math.max(s,o?h.w:h.h),o){const c=l.pos-(f.length-1)/2*N;a.top=Math.max(a.top,r.y-(l.pos-h.h/2),r.y-(c-it*11)),a.bottom=Math.max(a.bottom,l.pos+h.h/2-(r.y+r.h))}else a.left=Math.max(a.left,r.x-(l.pos-h.w/2)),a.right=Math.max(a.right,l.pos+h.w/2-(r.x+r.w))}const m={overhang:a};return m[i]=I(t)+s+4+(x(t)?20.4:0),m},render(t,e,i){if(!t.scale)return{};const o=L(t,e),{x:n,y:s,w:a,h:r}=e.plot,u=W(t,e),m=u?[]:U(t,e),l=[],f=x(t);let h,c=0;const g=I(t),T=t.ticks===!0;if(o==="left"||o==="right"){const d=o==="left"?-1:1,b=o==="left"?n-i.left:n+a+i.right;h=K(t,o)?`M${b} ${s}V${s+r}`:"";const k=j(t,e,o);for(const w of m){T&&(h+=`M${b} ${w.pos}H${b+d*5}`);const M=k(w.label),v=M.length===1&&M[0]===w.label?void 0:w.label;M.forEach(($,C)=>{c=Math.max(c,e.measure($,11).w),l.push({type:"text",x:b+d*g,y:w.pos+(C-(M.length-1)/2)*N,text:$,size:11,anchor:d<0?"end":"start",baseline:"middle",style:{fill:z},cls:"bc-axis-label",title:v})})}const y=b+d*(g+c+4+20.4/2);if(!!f&&Array.from(f).every(w=>e.wide(w))&&f.length*12*1.1<=r){const w=Array.from(f);w.forEach((M,v)=>{l.push({type:"text",x:y,y:s+r/2+(v-(w.length-1)/2)*12*1.1,text:M,size:12,weight:600,anchor:"middle",baseline:"middle",style:{fill:S},cls:"bc-axis-title"})})}else f&&l.push({type:"text",x:y,y:s+r/2,text:f,size:12,weight:600,anchor:"middle",baseline:"middle",rotate:d<0?-90:90,style:{fill:S},cls:"bc-axis-title"})}else{const d=o==="top"?-1:1,b=o==="top"?s-i.top:s+r+i.bottom;h=K(t,o)?`M${n} ${b}H${n+a}`:"";const k=(p,w,M)=>{c=Math.max(c,e.textWidth(w,11)*(M===90?1:A)+11*A),l.push({type:"text",x:p,y:b+d*g,text:w,size:11,anchor:d<0?"start":"end",baseline:"middle",rotate:-M,style:{fill:z},cls:"bc-axis-label"})},y=(p,w,M)=>{c=Math.max(c,M.length>1?M.length*N:e.measure(w,11).h),(d<0?M.slice().reverse():M).forEach(($,C)=>{l.push({type:"text",x:p,y:b+d*(g+C*N),text:$,size:11,anchor:"middle",baseline:d<0?"auto":"hanging",style:{fill:z},cls:"bc-axis-label"})})};if(u){const{angle:p,named:w}=tt(t,e,!1);for(const M of w)T&&(h+=`M${M.mid} ${b}V${b+d*5}`),p?k(M.mid,M.label,p):y(M.x,M.label,M.lines)}else{const p=j(t,e,o);for(const w of m)T&&(h+=`M${w.pos} ${b}V${b+d*5}`),F.has(t)?k(w.pos,w.label,F.get(t)):y(w.pos,w.label,p(w.label))}if(f){const p=b+d*(g+c+4+2);l.push({type:"text",x:n+a/2,y:p,text:f,size:12,weight:600,anchor:"middle",baseline:d<0?"auto":"hanging",style:{fill:S},cls:"bc-axis-title"})}}return{axes:[...h?[{type:"path",d:h,cls:"bc-axis",style:{fill:"none",stroke:ot,strokeWidth:1}}]:[],...l]}}};E.define(nt)})(globalThis.BC);
3
3
 
@@ -1,3 +1,3 @@
1
- /*! blockcharts 0.0.2 | MIT License */
1
+ /*! blockcharts 0.0.3 | MIT License */
2
2
  "use strict";(function(u){const c={role:"guide",type:"grid",version:3,narrow:!0,params:{scale:{kind:"scale",required:!0},count:{kind:"number"}},render(e,n){const t=e.scale;if(!t)return{};const a=n.orientation(t)==="vertical",{x:o,y:i,w:l,h:f}=n.plot;let r="";const s=typeof e.count=="number"&&e.count>=1?Math.round(e.count):void 0;for(const d of s===void 0?n.ticks(t):n.ticks(t,s))r+=a?`M${o} ${d.pos}H${o+l}`:`M${d.pos} ${i}V${i+f}`;return r?{grid:[{type:"path",d:r,cls:"bc-grid",style:{fill:"none",stroke:"var(--bc-grid, #e6e6e6)",strokeWidth:1}}]}:{}}};u.define(c)})(globalThis.BC);
3
3
 
@@ -1,3 +1,3 @@
1
- /*! blockcharts 0.0.2 | MIT License */
1
+ /*! blockcharts 0.0.3 | MIT License */
2
2
  "use strict";(function(m){const v="var(--bc-label, var(--bc-text, #666))",$="var(--bc-kpi, var(--bc-text, #111))",x="var(--bc-good, #12a150)",W="var(--bc-bad, #e5484d)",F="var(--bc-label, #888)",_=["last","first","sum","mean","min","max","count"];function p(t){const o=[];if(!t)return o;for(let n=0;n<t.length;n++){const e=t[n];typeof e=="number"&&isFinite(e)&&o.push(e)}return o}function I(t,o){if(o==="count")return t.length;if(!t.length)return NaN;switch(o){case"first":return t[0];case"sum":return t.reduce((n,e)=>n+e,0);case"mean":return t.reduce((n,e)=>n+e,0)/t.length;case"min":return t.reduce((n,e)=>e<n?e:n);case"max":return t.reduce((n,e)=>e>n?e:n);default:return t[t.length-1]}}const h=(t,o)=>t.baseTable.columns[o]||t.table.columns[o];function U(t,o){const n=typeof t.aggregate=="string"&&_.indexOf(t.aggregate)>=0?t.aggregate:"last",e=p(h(o,t.field)),a=I(e,n);let i=NaN;if(typeof t.against=="string")i=I(p(h(o,t.against)),n);else{const r=t.compare==="first"||t.compare==="none"||t.compare==="previous"?t.compare:n==="last"?"previous":"none";r==="previous"&&e.length>1?i=e[e.length-2]:r==="first"&&e.length>1&&(i=e[0])}return{value:a,base:i}}const V=t=>typeof t.note=="string"?t.note:"";function N(t,o,n,e,a,i){const r=t.textWidth(o,n,e);return r<=a?n:Math.max(Math.min(i,n),Math.floor(n*a/r*2)/2)}function L(t,o,n,e,a){if(t.textWidth(o,n,e)<=a)return o;const i=Array.from(o);let r=0,l=i.length;for(;r<l;){const s=r+l+1>>1;t.textWidth(i.slice(0,s).join("")+"\u2026",n,e)<=a?r=s:l=s-1}return r?i.slice(0,r).join("").trimEnd()+"\u2026":""}function M(t,o){const n=Math.max(1,o.size.w-o.plot.x-2),e=typeof t.size=="number"&&t.size>0&&isFinite(t.size)?t.size:30,a=B(t,o),i=typeof t.label=="string"?t.label:"",r=i&&a?`${i}: ${a}`:i||a,l=N(o,r,12,500,n,10),s=L(o,r,l,500,n),{value:u,base:c}=U(t,o),w=t.format!==void 0?m.formatter(t.format):d=>m.formatter("compact")(d),b=isFinite(u)?w(u):"\u2013",A=N(o,b,e,650,n,8);let f="",G="",O=F;if(isFinite(u)&&isFinite(c)){const d=u-c,k=d>0,z=d===0,J=t.better==="down"?!k:k;O=z?F:J?x:W;const D=t.deltaFormat!==void 0?m.formatter(t.deltaFormat):null,P=E=>k&&!/^[+]/.test(E)?"+"+E:E;let y;if(t.delta==="absolute")y=P((D||w)(d*(typeof t.deltaScale=="number"&&isFinite(t.deltaScale)?t.deltaScale:1)));else{const E=D||m.formatter({style:"percent",maximumFractionDigits:1});y=c!==0?P(E(d/Math.abs(c))):""}f=`${z?"\u25A0":k?"\u25B2":"\u25BC"} ${y}`.trim(),G=y}const g=V(t),T=f&&g?6:0,Z=(d=>(f?o.textWidth(f,d,600):0)+(g?o.textWidth(g,d,400):0))(12),S=T+Z<=n?12:Math.max(10,Math.floor(12*Math.max(0,n-T)/Z*2)/2);f&&(f=L(o,f,S,600,n));const X=g?L(o,g,S,400,n-(f?o.textWidth(f,S,600)+T:0)):"",q=f||g?18:0,R=(r?18:0)+A+q+10,H=[r,b,[G,g].filter(Boolean).join(" ")];return{labelled:!!r,label:s,labelSize:l,value:b,valueSize:A,change:f,changeColor:O,note:X,lineSize:S,height:R,spoken:H}}function B(t,o){if(typeof t.rowField!="string")return"";const n=h(o,t.rowField),e=h(o,t.field);if(!n||!e)return"";const a=typeof t.aggregate=="string"?t.aggregate:"last";let i=-1;for(let l=0;l<e.length;l++){const s=e[l];if(typeof s!="number"||!isFinite(s))continue;const u=i<0?NaN:e[i];if((i<0||a==="last"||a==="max"&&s>u||a==="min"&&s<u)&&(i=l),a==="first")break}const r=i<0?null:n[i];return r==null||r!==r?"":t.rowFormat!==void 0?m.formatter(t.rowFormat)(n[i]):String(n[i])}const j={role:"guide",type:"kpi",version:10,narrow:!0,params:{field:{kind:"field",required:!0},label:{kind:"string"},aggregate:{kind:"enum",values:_,default:"last"},compare:{kind:"enum",values:["previous","first","none"]},against:{kind:"field"},delta:{kind:"enum",values:["percent","absolute"],default:"percent"},deltaFormat:{kind:"format"},deltaScale:{kind:"number",default:1},better:{kind:"enum",values:["up","down"],default:"up"},format:{kind:"format"},note:{kind:"string"},rowField:{kind:"field"},rowFormat:{kind:"format"},size:{kind:"number",default:30}},measure(t,o){const n=typeof t.aggregate=="string"?t.aggregate:"last";if((t.compare==="previous"||t.compare==="first")&&n!=="last"&&typeof t.against!="string")throw new Error(`guide.kpi: compare "${t.compare}" compares one row with another, so it needs aggregate "last" (not "${n}"); to compare a ${n} with something, give "against" a field`);if(typeof t.rowField=="string"&&["last","first","min","max"].indexOf(n)<0)throw new Error(`guide.kpi: rowField names one row, and aggregate "${n}" comes from many; use last, first, min or max`);return{top:M(t,o).height}},render(t,o,n){if(typeof t.field!="string"||!h(o,t.field))return{};const e=M(t,o),a=o.plot.x;let i=o.plot.y-n.top-e.height;const r=[],l=(u,c,w,b,A,f)=>r.push({type:"text",x:c,y:i,text:u,size:w,weight:b,baseline:"hanging",style:{fill:A},cls:f});e.label&&l(e.label,a,e.labelSize,500,v,"bc-kpi-label"),e.labelled&&(i+=18),l(e.value,a,e.valueSize,650,$,"bc-kpi-value"),i+=e.valueSize+6;let s=a;e.change&&(l(e.change,a,e.lineSize,600,e.changeColor,"bc-kpi-delta"),s=a+o.textWidth(e.change,e.lineSize,600)+6),e.note&&l(e.note,s,e.lineSize,400,v,"bc-kpi-note");for(const u of e.spoken)o.say(u);return{axes:r}}};m.define(j)})(globalThis.BC);
3
3
 
@@ -1,3 +1,3 @@
1
- /*! blockcharts 0.0.2 | MIT License */
1
+ /*! blockcharts 0.0.3 | MIT License */
2
2
  "use strict";(function(j){const M="var(--bc-text, #444)",z=t=>t.output==="color"&&t.input==="category";function Y(t,e){const n=t.scale?e.scales[t.scale]:void 0;if(!n||!(n.output==="color"||n.output==="size"&&n.input==="number"))throw new Error("guide.legend needs a scale of colors, or of sizes for numbers");return n}function x(t,e,n){return C(t,e,3).filter(o=>isFinite(o.pos)&&o.pos>0).map(o=>({label:o.label,r:o.pos,w:E(o.label,n),drawn:n.textWidth(o.label,11)}))}const tt="var(--bc-label, var(--bc-text, #888))",N=t=>2*t.r+6+t.w,et=t=>2*t.r+6+t.drawn,p=(t,e)=>{const n=q(t,e);return Math.max(1,t.size.w-Math.max(8,n.left)-Math.max(8,n.right))},q=(t,e)=>e==="top"||e==="bottom"?t.edgeTaken(e):{left:0,right:0},W=(t,e,n,s)=>{const o=q(t,e);return Math.max(Math.max(8,o.left),Math.min(n,t.size.w-Math.max(8,o.right)-s))};function K(t,e){const n=[];let s=0;for(const o of t){const r=n[n.length-1];!r||r.items.length&&s+O+N(o)>e?(n.push({items:[o],h:Math.max(2*o.r,16)+4}),s=N(o)):(r.items.push(o),r.h=Math.max(r.h,Math.max(2*o.r,16)+4),s+=O+N(o))}return n}const E=(t,e)=>Math.max(e.measure(t,11).w,e.textWidth(t,11));function F(t,e,n=1/0){const s=new Set(t.domain()),o=t.range();return t.baseDomain().map((r,i)=>{const l=String(r),h=U(l,n-10-6,e);return{label:h,full:l,color:o[i],w:E(h,e),drawn:e.textWidth(h,11),hidden:!s.has(r),index:i}})}function U(t,e,n){if(!(e<1/0)||E(t,n)<=e)return t;const s=Array.from(t);let o=0,r=s.length;for(;o<r;){const i=o+r+1>>1;E(s.slice(0,i).join("")+"\u2026",n)<=e?o=i:r=i-1}return s.slice(0,o).join("").trimEnd()+"\u2026"}function C(t,e,n=4){const s=t.ticks?t.ticks(n):[];if(e.format===void 0)return s;const o=j.formatter(e.format,"number");return s.map(r=>({value:r.value,pos:r.pos,label:o(r.value)}))}const R=t=>typeof t.title=="string"&&t.title?t.title:"",H=t=>R(t)?16:0,nt=(t,e)=>R(t)?e.measure(R(t),11).w:0,ot=.2;function st(t,e){if(!z(t))return"right";const n=p(e,"top");return I(F(t,e,n),n).length<=2?"top":"right"}function k(t,e,n){const s=nt(t,n),o=H(t);if(e.output==="size"){const i=x(e,t,n),l=i.reduce((h,b)=>Math.max(h,b.r),0);return{w:Math.max(2*l+6+i.reduce((h,b)=>Math.max(h,b.w),0),s)+16,h:4+o+i.reduce((h,b)=>h+Math.max(2*b.r,16)+4,0)}}if(!z(e)){const i=C(e,t).reduce((l,h)=>Math.max(l,n.measure(h.label,11).w),0);return{w:Math.max(18+i,s)+16,h:0}}const r=F(e,n);return{w:Math.max(16+r.reduce((i,l)=>Math.max(i,l.w),0),s)+16,h:4+o+r.length*16+4}}function X(t,e,n){const s=t.position==="auto"?st(e,n):t.position||"right";if(!B(s))return s;const o=k(t,e,n);return o.w<=n.size.w*ot&&o.h<=n.size.h?s:"top"}const B=t=>t==="left"||t==="right",Z=(t,e,n)=>Math.max(e,Math.min(n,t)),O=14,J=t=>16+t.w,it=t=>16+t.drawn;function I(t,e){const n=[];let s=[],o=0;for(const r of t){const i=J(r);s.length&&o+O+i>e&&(n.push(s),s=[],o=0),o+=(s.length?O:0)+i,s.push(r)}return s.length&&n.push(s),n}function rt(t,e){return t?Z(e.plot.h*.6,80,200):Z(e.plot.w*.4,100,240)}const lt={role:"guide",type:"legend",version:16,shownOnce:!0,params:{scale:{kind:"scale",required:!0},position:{kind:"enum",values:["top","right","bottom","left","auto"],default:"right"},title:{kind:"string"},format:{kind:"format"}},measure(t,e){const n=Y(t,e),s=X(t,n,e),o=B(s),r=H(t),i={};if(n.output==="size"){const b=x(n,t,e);return i[s]=b.length?o?k(t,n,e).w:K(b,p(e,s)).reduce((T,w)=>T+w.h,0)+8+r:0,i}if(!z(n))return i[s]=o?k(t,n,e).w:12+e.measure("0",11).h+16+r,i;const l=p(e,s),h=F(n,e,o?1/0:l);return i[s]=h.length?o?k(t,n,e).w:I(h,l).length*16+8+r:0,i},render(t,e,n){const s=Y(t,e),o=X(t,s,e),r=B(o),{x:i,y:l,w:h,h:b}=e.plot,T=[],w=H(t),v=r?R(t):U(R(t),p(e,o),e),y=v?e.measure(v,11).w:0,S=(u,d)=>{w&&T.push({type:"text",x:u,y:d+16/2,text:v,size:11,weight:600,baseline:"middle",style:{fill:M},cls:"bc-legend-title"})};if(s.output==="size"){const u=x(s,t,e),d=u.reduce((m,f)=>Math.max(m,f.r),0),a=(m,f,A,c)=>{T.push({type:"circle",cx:m,cy:f,r:A.r,style:{fill:"none",stroke:tt,strokeWidth:1},cls:"bc-legend-size"}),T.push({type:"text",x:c,y:f,text:A.label,size:11,baseline:"middle",style:{fill:M}})};if(r){const m=Math.max(2*d+6+u.reduce((c,g)=>Math.max(c,g.w),0),y)+16,f=(o==="right"?i+h+n.right:i-n.left-m)+8;S(f,l+4);let A=l+4+w;for(const c of u){const g=Math.max(2*c.r,16)+4;a(f+d,A+g/2,c,f+2*d+6),A+=g}}else{const m=K(u,p(e,o));let f=o==="top"?l-n.top-(m.reduce((A,c)=>A+c.h,0)+8+w):l+b+n.bottom+8/2;S(W(e,o,i,y),f),f+=w;for(const A of m){let c=W(e,o,i,A.items.reduce((g,D,G)=>g+(G?O:0)+N(D),0));for(const g of A.items)a(c+g.r,f+A.h/2,g,c+2*g.r+6),c+=et(g)+O;f+=A.h}}return{axes:T}}if(!z(s)){const[u,d]=s.domain(),a=rt(r,e),m=C(s,t),f=m.reduce((P,L)=>Math.max(P,e.measure(L.label,11).w),0),A=Math.max(18+f,y)+16,c=o==="right"?i+h+n.right+8:i-n.left-A+8,g=o==="top"?l-n.top-(12+e.measure("0",11).h+16+w)+8:l+b+n.bottom+8,D=g+w,G=l+4+w+(w?11/2:0);r?S(c,l+4):S(W(e,o,i,y),g);const V=a/48*1.05;for(let P=0;P<48;P++){const L=r?d-(P+.5)/48*(d-u):u+(P+.5)/48*(d-u),$=s(L);T.push(r?{type:"rect",x:c,y:G+P*a/48,w:12,h:V,style:{fill:$},cls:"bc-legend-bar"}:{type:"rect",x:i+P*a/48,y:D,w:V,h:12,style:{fill:$},cls:"bc-legend-bar"})}for(const P of m)T.push(r?{type:"text",x:c+12+6,y:G+(1-P.pos)*a,text:P.label,size:11,baseline:"middle",style:{fill:M}}:{type:"text",x:i+P.pos*a,y:D+12+3,text:P.label,size:11,anchor:"middle",baseline:"hanging",style:{fill:M}});return{axes:T}}const _=F(s,e,r?1/0:p(e,o)),at=e.toggled(String(t.scale)),Q=(u,d,a)=>{T.push({type:"g",cls:"bc-legend-item",data:{"bc-legend-scale":String(t.scale),"bc-legend-index":String(a.index)},pressed:at?!a.hidden:void 0,style:a.hidden?{opacity:.4}:void 0,title:a.label!==a.full?a.full:void 0,children:[{type:"rect",x:u,y:d+6/2,w:10,h:10,r:10/2,style:{fill:a.color},cls:"bc-legend-swatch"},{type:"text",x:u+10+6,y:d+16/2,text:a.label,size:11,baseline:"middle",style:{fill:M}}]})};if(r){const u=Math.max(16+_.reduce((a,m)=>Math.max(a,m.w),0),y)+16,d=o==="right"?i+h+n.right:i-n.left-u;S(d+8,l+4),_.forEach((a,m)=>Q(d+8,l+4+w+m*16,a))}else{const u=I(_,p(e,o)),d=o==="top"?l-n.top-(u.length*16+8+w):l+b+n.bottom+8/2,a=d+w;S(W(e,o,i,y),d),u.forEach((m,f)=>{let A=W(e,o,i,m.reduce((c,g,D)=>c+(D?O:0)+J(g),0));for(const c of m)Q(A,a+f*16,c),A+=it(c)+O})}return{axes:T}}};j.define(lt)})(globalThis.BC);
3
3
 
@@ -1,3 +1,3 @@
1
- /*! blockcharts 0.0.2 | MIT License */
1
+ /*! blockcharts 0.0.3 | MIT License */
2
2
  "use strict";(function(l){const d=typeof WeakMap=="function"?new WeakMap:null,m=()=>typeof performance=="object"&&performance&&typeof performance.now=="function"?performance.now():Date.now();function y(t){const e=l.get(`mark.${t.type}`);return e&&e.enter}function b(t){const e=t.marks.map(y);return e.indexOf("pop")>=0?"pop":e.indexOf("grow")>=0&&e.indexOf("wipe")<0?"grow":e.indexOf("wipe")>=0?"wipe":"fade"}function g(t){const e=t.spec.marks.find(r=>y(r)==="grow");let a=!1;if(e)try{const r=t.channel(e,"y");a=!!(r.scale&&r.scale.bandwidth!==void 0)}catch{a=!1}const n=t.plot,i=a?t.scales.x:t.scales.y,o=i&&i.input==="number"?i(0):NaN;return a?{horizontal:a,at:isFinite(o)&&o>=n.x&&o<=n.x+n.w?o:n.x}:{horizontal:a,at:isFinite(o)&&o>=n.y&&o<=n.y+n.h?o:n.y+n.h}}const k={role:"interaction",type:"animate",version:4,params:{effect:{kind:"enum",values:["auto","grow","wipe","pop","fade"],default:"auto"},duration:{kind:"number",default:700},delay:{kind:"number",default:0}},attach(t,e){const a=e.root;let n=0;const i=d?d.get(e.host):void 0;i!==void 0?n=Math.max(0,m()-i):d&&d.set(e.host,m());const o=e.host.ownerDocument&&e.host.ownerDocument.defaultView||(typeof window<"u"?window:void 0);if(o&&typeof o.matchMedia=="function"&&o.matchMedia("(prefers-reduced-motion: reduce)").matches)return;const r=typeof t.duration=="number"&&t.duration>=0?Math.min(1e4,t.duration):700,w=typeof t.delay=="number"&&t.delay>=0?Math.min(1e4,t.delay):0,M={duration:r,delay:w,easing:"cubic-bezier(.2,.7,.2,1)",fill:"backwards"};if(i!==void 0&&n>=w+r)return;const p=t.effect==="grow"||t.effect==="wipe"||t.effect==="pop"||t.effect==="fade"?t.effect:b(e.spec),s=typeof a.querySelector=="function"?a.querySelector('[data-bc-layer="marks"]'):null,h=s||a;if(typeof h.animate!="function")return;const f=e.plot;let u;if(!s||p==="fade")u=[{opacity:0},{opacity:1}];else if(p==="wipe"){const c=e.size.w-(f.x+f.w);u=[{clipPath:`inset(0 ${e.size.w-f.x}px 0 0)`},{clipPath:`inset(0 ${Math.max(0,c-4)}px 0 0)`,offset:.999},{clipPath:"none"}]}else if(p==="pop")s.style.transformBox="view-box",s.style.transformOrigin=`${f.x+f.w/2}px ${f.y+f.h/2}px`,u=[{transform:"scale(0.6) rotate(-30deg)",opacity:0},{transform:"none",opacity:1}];else{const c=g(e);s.style.transformBox="view-box",s.style.transformOrigin=c.horizontal?`${c.at}px 0px`:`0px ${c.at}px`,u=[{transform:c.horizontal?"scaleX(0)":"scaleY(0)"},{transform:"none"}]}const x=h.animate(u,M);n>0&&(x.currentTime=n),e.cleanup(()=>{try{x.cancel()}catch{}})}};l.define(k)})(globalThis.BC);
3
3
 
@@ -1,3 +1,3 @@
1
- /*! blockcharts 0.0.2 | MIT License */
1
+ /*! blockcharts 0.0.3 | MIT License */
2
2
  "use strict";(function(k){const E=()=>k.get("lib.pointer").exports,j="bc-brush",I={role:"interaction",type:"brush",version:5,requires:["lib.pointer"],params:{scales:{kind:"list",default:["x"]},modifier:{kind:"enum",values:["shift","alt","ctrl","none"],default:"shift"},fit:{kind:"list"},minSize:{kind:"number",default:6}},attach(s,e){const a=(Array.isArray(s.scales)?s.scales.filter(t=>typeof t=="string"):["x"]).filter(t=>{const n=e.scales[t],o=!!n&&e.orientation(t)!==null&&(!!n.invert||n.bandwidth!==void 0);return o||console.warn(`[blockcharts] interaction.brush: scale "${t}" is not a positional scale that can be selected on, ignored`),o});if(!a.length)return;const L=(Array.isArray(s.fit)?s.fit:[]).filter(t=>{const n=typeof t=="string"&&!!e.scales[t]&&a.indexOf(t)<0;return!n&&typeof t=="string"&&console.warn(`[blockcharts] interaction.brush: cannot fit scale "${t}"`),n}),h=s.modifier==="alt"||s.modifier==="ctrl"||s.modifier==="none"?s.modifier:"shift",z=typeof s.minSize=="number"&&s.minSize>=0?s.minSize:6,r=e.root,y=e.host,p=y.ownerDocument||document,g=a.some(t=>e.orientation(t)==="horizontal"),w=a.some(t=>e.orientation(t)==="vertical");let u=null;const m=t=>E().toLogical(e,t),M=t=>E().inPlot(e,t),C=t=>{const n=e.plot;return{x:Math.max(n.x,Math.min(n.x+n.w,t.x)),y:Math.max(n.y,Math.min(n.y+n.h,t.y))}},S=t=>h==="none"||(h==="shift"?t.shiftKey:h==="alt"?t.altKey:t.ctrlKey||t.metaKey);e.claimDrag(S);let i=null;const v=t=>{const n=e.plot;return{x0:g?Math.min(t.x0,t.x1):n.x,x1:g?Math.max(t.x0,t.x1):n.x+n.w,y0:w?Math.min(t.y0,t.y1):n.y,y1:w?Math.max(t.y0,t.y1):n.y+n.h}},A=()=>{if(!i)return;const t=v(i),n=r.getBoundingClientRect(),o=y.getBoundingClientRect(),c=n.width/e.size.w;Object.assign(i.box.style,{left:n.left-o.left+t.x0*c+"px",top:n.top-o.top+t.y0*c+"px",width:(t.x1-t.x0)*c+"px",height:(t.y1-t.y0)*c+"px"})},b=()=>{i&&(i.box.parentNode&&i.box.parentNode.removeChild(i.box),i=null,p.removeEventListener("keydown",D),u&&(u(),u=null))},T=t=>{if(!(g&&t.x1-t.x0<z)&&!(w&&t.y1-t.y0<z)){for(const n of a){const o=e.scales[n],c=e.orientation(n)==="horizontal"?t.x0:t.y0,q=e.orientation(n)==="horizontal"?t.x1:t.y1;if(o.invert){const x=Number(o.invert(c)),f=Number(o.invert(q)),d=Math.min(x,f),l=Math.max(x,f),[B,R]=o.baseDomain(),$=R<B?[l,d]:[d,l];e.setView(n,l-d>=Math.abs(R-B)*(1-1e-9)?null:$)}else{const x=o.bandwidth,f=o.domain().filter(d=>{const l=o(d);return isFinite(l)&&l+x>=c&&l<=q});if(!f.length)continue;e.setView(n,f.length===o.baseDomain().length?null:f)}}for(const n of L)e.setView(n,e.fit(n,a[0]))}},D=t=>{t.key==="Escape"&&b()},P=t=>{if(t.button!==0||!S(t))return;const n=m(t);if(!M(n))return;const o=p.createElement("div");o.setAttribute("class",j),Object.assign(o.style,{position:"absolute",pointerEvents:"none",boxSizing:"border-box",zIndex:"5",background:"var(--bc-brush-fill, rgba(78,121,167,.22))",border:"1px solid var(--bc-brush-line, rgba(78,121,167,.9))"}),u=e.claimPosition(),y.appendChild(o),i={x0:n.x,y0:n.y,x1:n.x,y1:n.y,box:o},r.setPointerCapture&&r.setPointerCapture(t.pointerId),p.addEventListener("keydown",D),A(),t.preventDefault()},V=t=>{if(!i)return;const n=C(m(t));i.x1=n.x,i.y1=n.y,A()},K=t=>{if(!i)return;const n=C(m(t));i.x1=n.x,i.y1=n.y;const o=v(i);b(),T(o)},N=()=>b(),O=t=>{if(M(m(t))){for(const n of a)e.setView(n,null);for(const n of L)e.setView(n,e.fit(n,a[0]))}};r.addEventListener("pointerdown",P),r.addEventListener("pointermove",V),r.addEventListener("pointerup",K),r.addEventListener("pointercancel",N),r.addEventListener("dblclick",O),e.cleanup(()=>{b(),r.removeEventListener("pointerdown",P),r.removeEventListener("pointermove",V),r.removeEventListener("pointerup",K),r.removeEventListener("pointercancel",N),r.removeEventListener("dblclick",O)})}};k.define(I)})(globalThis.BC);
3
3
 
@@ -0,0 +1,3 @@
1
+ /*! blockcharts 0.0.3 | MIT License */
2
+ "use strict";(function(p){const x=["bc-mark","bc-row","bc-layer"],s=()=>p.get("lib.pointer").exports,L={role:"interaction",type:"click",version:1,requires:["lib.pointer"],events:["bc-click"],params:{cursor:{kind:"boolean",default:!0}},attach(O,o){const c=o.root,u=o.host,g=u.ownerDocument||document,C=t=>{const n=o.dataAt(t);return!!n&&Object.keys(n).some(l=>x.indexOf(l)<0)},w=t=>{const n=s().toLogical(o,t);return!s().inPlot(o,n,12)||C(t)?null:s().pickAt(o,n)};let a=null;const b=t=>{a={x:t.clientX,y:t.clientY}},m=t=>{const n=a;if(a=null,t.detail>1||n&&Math.hypot(t.clientX-n.x,t.clientY-n.y)>4)return;const l=w(t);if(!l)return;const{pick:e,mark:D,index:A}=l,d=o.table,y={};for(const E of Object.keys(d.columns))y[E]=d.columns[E][e.row];const P={row:e.row,rows:e.rows&&e.rows.length?e.rows.slice():[e.row],values:y,mark:D,markIndex:A,x:e.x,y:e.y,table:d,event:t},h=g.defaultView||globalThis;typeof h.CustomEvent!="function"||typeof u.dispatchEvent!="function"||u.dispatchEvent(new h.CustomEvent("bc-click",{bubbles:!0,detail:P}))};c.addEventListener("pointerdown",b),c.addEventListener("click",m);let i=!1,k="";const r=c.style,f=()=>{i&&r.cursor==="pointer"&&(r.cursor=k),i=!1};O.cursor!==!1&&r&&s().follow(o,t=>{if(!w(t))return f();i||r.cursor==="pointer"||(k=r.cursor||"",r.cursor="pointer",i=!0)},f,!0),o.cleanup(()=>{c.removeEventListener("pointerdown",b),c.removeEventListener("click",m),f()})}};p.define(L)})(globalThis.BC);
3
+
@@ -1,3 +1,3 @@
1
- /*! blockcharts 0.0.2 | MIT License */
1
+ /*! blockcharts 0.0.3 | MIT License */
2
2
  "use strict";(function(u){const g=()=>u.get("lib.pointer").exports,z=(r,t,f,b)=>u.get("lib.pointer").exports.follow(r,t,f,b);function E(r){const t=u.get(`mark.${r.type}`);return!!(t&&t.series)}const L={role:"interaction",type:"crosshair",version:6,requires:["lib.pointer"],alongX:!0,params:{snap:{kind:"enum",values:["lines","all","off"],default:"lines"},horizontal:{kind:"boolean",default:!1}},attach(r,t){const f=t.host,b=t.root,O=f.ownerDocument||document,T=t.claimPosition(),m=r.snap==="all"||r.snap==="off"?r.snap:"lines",w=(e,s)=>{const o=O.createElement("div");return o.setAttribute("class",e),Object.assign(o.style,s?{position:"absolute",display:"none",pointerEvents:"none",width:"0",marginLeft:"-0.5px",borderLeft:"1px dashed var(--bc-crosshair, var(--bc-axis, #999))"}:{position:"absolute",display:"none",pointerEvents:"none",height:"0",marginTop:"-0.5px",borderTop:"1px dashed var(--bc-crosshair, var(--bc-axis, #999))"}),f.appendChild(o),o},y=w("bc-crosshair",!0),d=r.horizontal===!0?w("bc-crosshair-h",!1):null,x=()=>{y.style.display="none",d&&(d.style.display="none")},C=(e,s)=>{let o=null;for(const n of t.spec.marks){if(m==="lines"&&!E(n))continue;let p,a=null,l=0;try{const i=t.channel(n,"x");if(!i.scale)continue;p=i.mapped,l=i.half;const c=t.channel(n,"y");c.scale&&(a=c.mapped)}catch{continue}const{from:h,to:F}=t.rows(n),{x:k,w:N}=t.plot;for(let i=h;i<F;i++){const c=p[i]+l;if(!isFinite(c)||c<k-.5||c>k+N+.5)continue;const j=Math.abs(c-e);(!o||j<o.d)&&(o={x:c,y:a&&isFinite(a[i])?a[i]:s,d:j})}}return o};z(t,e=>{const s=b.getBoundingClientRect(),o=f.getBoundingClientRect();if(!s.width)return x();const n=s.width/t.size.w,{x:p,y:a}=g().toLogical(t,e),l=t.plot;if(!g().inPlot(t,{x:p,y:a}))return x();const h=m==="off"?{x:p,y:a}:C(p,a);if(!h)return x();Object.assign(y.style,{left:s.left-o.left+h.x*n+"px",top:s.top-o.top+l.y*n+"px",height:l.h*n+"px",display:"block"}),d&&Object.assign(d.style,{top:s.top-o.top+h.y*n+"px",left:s.left-o.left+l.x*n+"px",width:l.w*n+"px",display:"block"})},x,!0),t.cleanup(()=>{for(const e of[y,d])e&&e.parentNode&&e.parentNode.removeChild(e);T()})}};u.define(L)})(globalThis.BC);
3
3
 
@@ -1,3 +1,3 @@
1
- /*! blockcharts 0.0.2 | MIT License */
1
+ /*! blockcharts 0.0.3 | MIT License */
2
2
  "use strict";(function(x){const O="bc-legend-scale",K="bc-legend-index",S="bc-legend-filter",A=s=>s.output==="color"&&s.input==="category",E=(s,o,a)=>{const l=(o.guides||[]).find(m=>typeof m.scale=="string"&&!!a[m.scale]&&A(a[m.scale])),d=typeof s.scale=="string"?s.scale:l?l.scale:void 0;return d&&a[d]&&A(a[d])?d:void 0},T=s=>s.key==="Enter"||s.key===" "||s.key==="Spacebar",I={role:"interaction",type:"legend-filter",version:6,outerLegend:!0,params:{scale:{kind:"scale"},legend:{kind:"string"},fit:{kind:"list"}},toggles:(s,o)=>typeof s.legend=="string"?void 0:E(s,o.spec,o.scales),attach(s,o){const a=typeof s.legend=="string"?s.legend:null,l=E(s,o.spec,o.scales),d=l?o.scales[l]:void 0;if(!l||!d){console.warn('[blockcharts] interaction.legend-filter: needs a categorical color scale (set "scale", or add a legend guide for one); ignored');return}const m=(Array.isArray(s.fit)?s.fit:[]).filter(t=>{const e=typeof t=="string"&&!!o.scales[t]&&t!==l;return!e&&typeof t=="string"&&console.warn(`[blockcharts] interaction.legend-filter: cannot fit scale "${t}"`),e}),i=o.root,c=d.baseDomain(),V=o.host.ownerDocument||document,f=a?V.getElementById(a):null;if(a&&!f)return;const k=()=>o.getView()[l],h=t=>{o.setView(l,t.length===0||t.length===c.length?null:t);for(const e of m)o.setView(e,o.fit(e,l));if(f){const e=t.length?t:c;f.querySelectorAll("[data-bc-legend-index]").forEach(n=>{const r=e.indexOf(c[Number(n.getAttribute("data-bc-legend-index"))])>=0;n.setAttribute("aria-pressed",r?"true":"false")})}},p=t=>{if(f){const r=t.target?.closest?.("[data-bc-legend-index]"),u=r?Number(r.getAttribute("data-bc-legend-index")):NaN;return Number.isInteger(u)&&u>=0&&u<c.length?{value:c[u]}:null}const e=o.dataAt(t);if(!e||e[O]!==l)return null;const n=Number(e[K]);return Number.isInteger(n)&&n>=0&&n<c.length?{value:c[n]}:null};let g=null;const v=t=>{if(t.detail>1)return;const e=p(t);if(!e)return;const n=k();g={shown:n.slice(),at:Date.now()},h(c.filter(r=>r===e.value?n.indexOf(r)<0:n.indexOf(r)>=0))},L=t=>{const e=p(t);if(!e)return;t.preventDefault();const n=g&&Date.now()-g.at<700?g.shown:k();g=null,h(n.length===1&&n[0]===e.value?c.slice():[e.value])},C=t=>{const e=t;if(!T(e)||e.altKey||e.ctrlKey||e.metaKey)return;const n=p(t);if(!n||(t.preventDefault(),e.repeat))return;const r=k();g=null,e.shiftKey?h(r.length===1&&r[0]===n.value?c.slice():[n.value]):h(c.filter(u=>u===n.value?r.indexOf(u)<0:r.indexOf(u)>=0))},b=f||i;b.addEventListener("click",v),b.addEventListener("dblclick",L),b.addEventListener("keydown",C);let y=null;const N=t=>{const e=i.style,n=!!p(t);n&&y===null?(y=e.cursor,e.cursor="pointer"):!n&&y!==null&&(e.cursor=y,y=null)},D=!f&&typeof i.getContext=="function";D&&i.addEventListener("pointermove",N);const w=i.getAttribute("class");i.setAttribute("class",((w||"")+" "+S).trim()),o.cleanup(()=>{b.removeEventListener("click",v),b.removeEventListener("dblclick",L),b.removeEventListener("keydown",C),D&&i.removeEventListener("pointermove",N),w===null?i.removeAttribute?i.removeAttribute("class"):i.setAttribute("class",""):i.setAttribute("class",w)})}};x.define(I)})(globalThis.BC);
3
3
 
@@ -1,3 +1,3 @@
1
- /*! blockcharts 0.0.2 | MIT License */
2
- "use strict";(function(M){const ht=i=>i==null||i===""||typeof i=="number"&&isNaN(i),bt=/\d|[a-z][A-Z]|_/;function gt(i){if(i==null)return"\u2013";if(typeof i=="number")return isNaN(i)?"\u2013":Number.isInteger(i)?String(i):String(+i.toPrecision(6));const o=String(i);return o.length>80?o.slice(0,79)+"\u2026":o}const Y=()=>M.get("lib.pointer").exports,yt=(i,o,S,H)=>M.get("lib.pointer").exports.follow(i,o,S,H),mt={role:"interaction",type:"tooltip",version:23,requires:["lib.pointer"],params:{fields:{kind:"fields"},formats:{kind:"formats"},labels:{kind:"any"},content:{kind:"any"},heading:{kind:"field"},marker:{kind:"enum",values:["auto","dot","box","none"],default:"auto"}},attach(i,o){const S=o.host,H=o.root,u=S.ownerDocument||document,_={};if(i.formats&&typeof i.formats=="object"&&!Array.isArray(i.formats)){const t=i.formats;for(const n of Object.keys(t))try{_[n]=o.format(t[n])}catch(r){console.warn(`[blockcharts] interaction.tooltip: format of "${n}" ignored: ${r instanceof Error?r.message:String(r)}`)}}else i.formats!==void 0&&console.warn('[blockcharts] interaction.tooltip: "formats" must be an object of field name to format; ignored');const v=o.format("date"),I={};for(const t of Array.isArray(o.spec.transforms)?o.spec.transforms:[]){const n=t&&M.get(`transform.${t.type}`);if(!(!n||typeof n.labels!="function"))try{Object.assign(I,n.labels(t))}catch{}}if(i.labels&&typeof i.labels=="object"&&!Array.isArray(i.labels)){const t=i.labels;for(const n of Object.keys(t))o.table.columns[n]?typeof t[n]!="string"?console.warn(`[blockcharts] interaction.tooltip: label of "${n}" must be text; ignored`):I[n]=t[n]:console.warn(`[blockcharts] interaction.tooltip: label of "${n}" ignored: no such field`)}else i.labels!==void 0&&console.warn('[blockcharts] interaction.tooltip: "labels" must be an object of field name to text; ignored');const G=Array.isArray(i.fields)?i.fields.filter(t=>typeof t=="string"):null,xt=o.claimPosition(),a=u.createElement("div");a.setAttribute("class","bc-tooltip"),a.setAttribute("role","tooltip"),Object.assign(a.style,{position:"absolute",display:"none",pointerEvents:"none",zIndex:"10",boxSizing:"border-box",whiteSpace:"normal",overflowWrap:"anywhere",fontSize:"12px",lineHeight:"1.45",fontVariantNumeric:"tabular-nums",padding:"8px 11px",borderRadius:"10px",background:"var(--bc-tooltip-bg, #fff)",color:"var(--bc-text, #333)",border:"1px solid var(--bc-tooltip-border, rgba(127,127,127,.22))",boxShadow:"var(--bc-tooltip-shadow, 0 10px 28px rgba(15,23,42,.14), 0 2px 6px rgba(15,23,42,.08))"});const b=u.createElement("div");b.setAttribute("class","bc-tooltip-dot"),Object.assign(b.style,{position:"absolute",display:"none",pointerEvents:"none",width:"12px",height:"12px",marginLeft:"-6px",marginTop:"-6px",boxSizing:"border-box",borderRadius:"50%",border:"2.5px solid var(--bc-tooltip-bg, #fff)",background:"var(--bc-text, #333)",boxShadow:"0 1px 4px rgba(15,23,42,.3)"});const j=u.createElement("div");j.setAttribute("class","bc-tooltip-highlight"),Object.assign(j.style,{position:"absolute",display:"none",pointerEvents:"none",boxSizing:"border-box",borderRadius:"3px",background:"var(--bc-tooltip-highlight-fill, rgba(127,127,127,.14))",outline:"1.5px solid var(--bc-tooltip-highlight-line, rgba(127,127,127,.45))",outlineOffset:"-1.5px"});const m=u.createElementNS("http://www.w3.org/2000/svg","svg");m.setAttribute("class","bc-tooltip-flows"),Object.assign(m.style,{position:"absolute",display:"none",pointerEvents:"none"}),S.appendChild(m),S.appendChild(b),S.appendChild(j),S.appendChild(a);const V=i.marker==="dot"||i.marker==="box"||i.marker==="none"?i.marker:"auto";let tt=!1,et=!1;const wt=()=>{const t=i.content;if(typeof t=="function")return t;if(typeof t!="string")return;const n=M.getFn(t);return!n&&!tt&&(tt=!0,console.warn(`[blockcharts] interaction.tooltip: no function "${t}" is registered (BC.defineFn); showing the default content`)),n},kt=t=>!!t&&typeof t=="object"&&typeof t.nodeType=="number",nt=t=>{if(!(t==null||t===!1)){if(typeof t=="string"||typeof t=="number"){if(t==="")return;const n=u.createElement("div");n.textContent=String(t),a.appendChild(n)}else if(Array.isArray(t))t.forEach(nt);else if(kt(t))a.appendChild(t);else if(typeof t.html=="string"){const n=u.createElement("div");n.innerHTML=t.html,a.appendChild(n)}}},X=()=>{a.style.display="none",b.style.display="none",j.style.display="none",m.style.display="none"},N=(t,n)=>{const r=o.table.columns[t][n];return _[t]?_[t](r)||"\u2013":gt(r)};function ot(t){if(typeof i.heading=="string"&&o.table.columns[i.heading])return i.heading;for(const n of["category","date"])for(const r of["x","y"])try{const e=o.channel(t,r);if(e.field&&e.scale&&e.scale.input===n&&o.table.columns[e.field])return e.field}catch{}return null}function st(t,n){for(const[r,e]of[["x","x2"],["y","y2"]])try{const s=o.channel(t,r),d=o.channel(t,e);if(!s.field||!d.field||s.field===d.field||!s.scale||s.scale!==d.scale||s.scale.input==="category"||!o.table.columns[s.field]||!o.table.columns[d.field]||n.indexOf(s.field)<0||n.indexOf(d.field)<0)continue;return{from:s.field,to:d.field,date:s.scale.input==="date"}}catch{}return null}const q=t=>M.get(`mark.${t.type}`);function Z(t,n,r){const e=q(t);if(!e||typeof e.color!="function")return"";try{const s=e.color(t,o,n,r);return typeof s=="string"?s:""}catch{return""}}function L(t,n){const r=[];for(const e of Object.keys(n.channels))try{const s=o.channel(t,e);s.field&&r.push(s.field)}catch{}return typeof t.group=="string"&&r.push(t.group),r}function Et(t,n,r,e,s){const d=Z(t,r,e);if(s===null||L(t,n).includes(s))return d;const p=o.spec.marks;for(let c=p.length-1;c>=0;c--){const x=q(p[c]);if(c===r||!x||!L(p[c],x).includes(s))continue;const h=Z(p[c],c,e);if(h)return h}return d}function it(t,n){const r=new Set;for(const e of Object.keys(n.channels))try{const s=o.channel(t,e);s.field&&s.scale&&s.scale.input==="date"&&r.add(s.field)}catch{}return(e,s)=>!_[e]&&r.has(e)&&v(o.table.columns[e][s])||N(e,s)}function At(t,n,r,e,s){const d=[],p=[],c=new Set(s),x=it(t,n),h=w=>{const $=o.table.columns[w];if(!$||c.has(w)||(c.add(w),ht($[r])))return;const k=x(w,r);e.some(T=>x(w,T)!==k)||(d.push([I[w]||w,k]),p.push(w))};return(G||L(t,n)).forEach(h),{lines:d,fields:p}}function Ot(t){const n=Y().toLogical(o,t);if(!Y().inPlot(o,n,12))return X();let r=null;if(o.spec.marks.forEach((f,l)=>{const g=M.get(`mark.${f.type}`);if(!g||!g.pick)return;let y=null;try{y=g.pick(f,o,l,n.x,n.y)}catch{return}y&&isFinite(y.dist)&&(!r||y.dist<=r.pick.dist)&&(r={pick:y,mark:f,def:g,index:l})}),!r)return X();const{pick:e,mark:s,def:d,index:p}=r,c=e.card,x=e.rows&&e.rows.length>1?e.rows:[e.row],h=c?null:ot(s),w=typeof i.heading=="string"&&!!o.table.columns[i.heading],$=c||w?null:st(s,G||L(s,d)),k=$&&(!h||h===$.from||h===$.to)?$:null,T=c?N:it(s,d),E=k&&x.every(f=>T(k.from,f)===T(k.from,e.row)&&T(k.to,f)===T(k.to,e.row))?k:null,O=!k&&h&&x.every(f=>N(h,f)===N(h,e.row))?h:null,rt=c?{lines:c.lines,fields:[]}:At(s,d,e.row,x,E?[E.from,E.to]:[]),J=rt.lines,lt=O?I[O]||O:null;let z;const at=c?void 0:wt();if(at){const f={};for(const l of Object.keys(o.table.columns))f[l]=o.table.columns[l][e.row];try{z=at({row:e.row,values:f,rows:x,lines:J,mark:s,markIndex:p,x:e.x,y:e.y,table:o.table})}catch(l){et||(et=!0,console.error("[blockcharts] interaction.tooltip: the content function threw, showing the default content:",l)),z=void 0}}if(z===null||z===!1)return X();a.textContent="";const Ct=Z(s,p,e.row),ct=rt.fields.find((f,l)=>J[l][0]!==lt),ft=c?c.color||"":Et(s,d,p,e.row,G&&ct!==void 0?ct:null);if(z===void 0){if(O||c||E){const l=u.createElement("div");if(l.setAttribute("class","bc-tooltip-heading"),O?l.setAttribute("data-bc-field",O):E&&l.setAttribute("data-bc-field",`${E.from} ${E.to}`),Object.assign(l.style,{display:"flex",alignItems:"center",gap:"7px",fontWeight:"600",marginBottom:"4px"}),ft){const F=u.createElement("span");F.setAttribute("class","bc-tooltip-swatch"),Object.assign(F.style,{width:"8px",height:"8px",borderRadius:"50%",background:ft,boxShadow:"inset 0 0 0 1px var(--bc-tooltip-highlight-line, rgba(127,127,127,.45))",flex:"none"}),l.appendChild(F)}const g=u.createElement("span"),y=o.table.columns[O],D=(()=>{for(const F of["x","y"])try{const W=o.channel(s,F);if(W.field===O&&W.scale&&W.scale.input==="date")return!0}catch{}return!1})(),U=O;if(c)g.textContent=c.title;else if(E){const F=[T(E.from,e.row),T(E.to,e.row)];g.textContent=F.join(F.some(W=>W.indexOf(" ")>=0)?" \u2013 ":"\u2013")}else g.textContent=!_[U]&&D&&v(y[e.row])||N(U,e.row);l.appendChild(g),a.appendChild(l)}const f=u.createElement("div");f.setAttribute("class","bc-tooltip-lines"),Object.assign(f.style,{display:"grid",gridTemplateColumns:"auto auto",columnGap:"16px",rowGap:"1px"});for(const[l,g]of J){if(l===lt)continue;const y=u.createElement("span");y.textContent=l,y.style.opacity="0.68";const D=u.createElement("span");D.textContent=g,Object.assign(D.style,{textAlign:"right",fontWeight:"600"}),f.appendChild(y),f.appendChild(D)}f.children.length&&a.appendChild(f)}else nt(z);if(!(a.childNodes?a.childNodes.length>0:a.children.length>0))return X();const C=H.getBoundingClientRect(),A=S.getBoundingClientRect(),R=C.width/o.size.w,P=C.left-A.left+e.x*R,B=C.top-A.top+e.y*R;m.textContent="";for(const f of e.flows||[]){const l=u.createElementNS("http://www.w3.org/2000/svg","path");l.setAttribute("d",f.d),l.setAttribute("fill",f.fill),l.setAttribute("fill-opacity","0.5"),m.appendChild(l)}e.flows&&e.flows.length?(m.setAttribute("viewBox",`0 0 ${o.size.w} ${o.size.h}`),Object.assign(m.style,{left:C.left-A.left+"px",top:C.top-A.top+"px",width:C.width+"px",height:C.height+"px",display:"block"})):m.style.display="none",(V==="box"||V==="auto"&&!!e.box)&&e.box?(Object.assign(j.style,{left:C.left-A.left+e.box.x*R+"px",top:C.top-A.top+e.box.y*R+"px",width:Math.max(0,e.box.w*R)+"px",height:Math.max(0,e.box.h*R)+"px",display:"block"}),b.style.display="none"):V!=="none"?(b.style.left=P+"px",b.style.top=B+"px",b.style.background=Ct||"var(--bc-text, #333)",b.style.display="block",j.style.display="none"):(b.style.display="none",j.style.display="none");const K=u.defaultView||globalThis,Q=Math.max(0,-A.left),dt=typeof K.innerWidth=="number"&&K.innerWidth>0?Math.min(A.width,K.innerWidth-A.left):A.width;a.style.display="block",a.style.maxWidth=Math.max(120,dt-Q)+"px",a.style.left=Q+"px";const pt=a.offsetWidth||0,ut=a.offsetHeight||0,St=P+12+pt>dt?P-12-pt:P+12,jt=B-12-ut>=0?B-12-ut:B+12;a.style.left=Math.max(Q,St)+"px",a.style.top=Math.max(0,jt)+"px"}if(i.content===void 0&&o.table){const t=[];for(const n of o.spec.marks){const r=q(n);if(!r||!r.pick)continue;const e=G||L(n,r),s=ot(n),d=typeof i.heading=="string"?null:st(n,e);for(const p of e)p===s||d&&(p===d.from||p===d.to)||!I[p]&&bt.test(p)&&o.table.columns[p]&&t.indexOf(p)<0&&t.push(p)}t.length&&console.warn(`[blockcharts] interaction.tooltip: the card shows ${t.map(n=>`"${n}"`).join(", ")} under ${t.length>1?"their own names; give them names":"its own name; give it a name"} a reader knows in "labels"`)}yt(o,Ot,X),o.cleanup(()=>{for(const t of[a,b,j,m])t.parentNode&&t.parentNode.removeChild(t);xt()})}};M.define(mt)})(globalThis.BC);
1
+ /*! blockcharts 0.0.3 | MIT License */
2
+ "use strict";(function(M){const ht=i=>i==null||i===""||typeof i=="number"&&isNaN(i),bt=/\d|[a-z][A-Z]|_/;function gt(i){if(i==null)return"\u2013";if(typeof i=="number")return isNaN(i)?"\u2013":Number.isInteger(i)?String(i):String(+i.toPrecision(6));const s=String(i);return s.length>80?s.slice(0,79)+"\u2026":s}const H=()=>M.get("lib.pointer").exports,yt=(i,s,O,V)=>M.get("lib.pointer").exports.follow(i,s,O,V),mt={role:"interaction",type:"tooltip",version:24,requires:["lib.pointer"],params:{fields:{kind:"fields"},formats:{kind:"formats"},labels:{kind:"any"},content:{kind:"any"},heading:{kind:"field"},marker:{kind:"enum",values:["auto","dot","box","none"],default:"auto"}},attach(i,s){const O=s.host,V=s.root,u=O.ownerDocument||document,D={};if(i.formats&&typeof i.formats=="object"&&!Array.isArray(i.formats)){const t=i.formats;for(const n of Object.keys(t))try{D[n]=s.format(t[n])}catch(r){console.warn(`[blockcharts] interaction.tooltip: format of "${n}" ignored: ${r instanceof Error?r.message:String(r)}`)}}else i.formats!==void 0&&console.warn('[blockcharts] interaction.tooltip: "formats" must be an object of field name to format; ignored');const v=s.format("date"),W={};for(const t of Array.isArray(s.spec.transforms)?s.spec.transforms:[]){const n=t&&M.get(`transform.${t.type}`);if(!(!n||typeof n.labels!="function"))try{Object.assign(W,n.labels(t))}catch{}}if(i.labels&&typeof i.labels=="object"&&!Array.isArray(i.labels)){const t=i.labels;for(const n of Object.keys(t))s.table.columns[n]?typeof t[n]!="string"?console.warn(`[blockcharts] interaction.tooltip: label of "${n}" must be text; ignored`):W[n]=t[n]:console.warn(`[blockcharts] interaction.tooltip: label of "${n}" ignored: no such field`)}else i.labels!==void 0&&console.warn('[blockcharts] interaction.tooltip: "labels" must be an object of field name to text; ignored');const B=Array.isArray(i.fields)?i.fields.filter(t=>typeof t=="string"):null,xt=s.claimPosition(),l=u.createElement("div");l.setAttribute("class","bc-tooltip"),l.setAttribute("role","tooltip"),Object.assign(l.style,{position:"absolute",display:"none",pointerEvents:"none",zIndex:"10",boxSizing:"border-box",whiteSpace:"normal",overflowWrap:"anywhere",fontSize:"12px",lineHeight:"1.45",fontVariantNumeric:"tabular-nums",padding:"8px 11px",borderRadius:"10px",background:"var(--bc-tooltip-bg, #fff)",color:"var(--bc-text, #333)",border:"1px solid var(--bc-tooltip-border, rgba(127,127,127,.22))",boxShadow:"var(--bc-tooltip-shadow, 0 10px 28px rgba(15,23,42,.14), 0 2px 6px rgba(15,23,42,.08))"});const b=u.createElement("div");b.setAttribute("class","bc-tooltip-dot"),Object.assign(b.style,{position:"absolute",display:"none",pointerEvents:"none",width:"12px",height:"12px",marginLeft:"-6px",marginTop:"-6px",boxSizing:"border-box",borderRadius:"50%",border:"2.5px solid var(--bc-tooltip-bg, #fff)",background:"var(--bc-text, #333)",boxShadow:"0 1px 4px rgba(15,23,42,.3)"});const C=u.createElement("div");C.setAttribute("class","bc-tooltip-highlight"),Object.assign(C.style,{position:"absolute",display:"none",pointerEvents:"none",boxSizing:"border-box",borderRadius:"3px",background:"var(--bc-tooltip-highlight-fill, rgba(127,127,127,.14))",outline:"1.5px solid var(--bc-tooltip-highlight-line, rgba(127,127,127,.45))",outlineOffset:"-1.5px"});const g=u.createElementNS("http://www.w3.org/2000/svg","svg");g.setAttribute("class","bc-tooltip-flows"),Object.assign(g.style,{position:"absolute",display:"none",pointerEvents:"none"}),O.appendChild(g),O.appendChild(b),O.appendChild(C),O.appendChild(l);const q=i.marker==="dot"||i.marker==="box"||i.marker==="none"?i.marker:"auto";let tt=!1,et=!1;const wt=()=>{const t=i.content;if(typeof t=="function")return t;if(typeof t!="string")return;const n=M.getFn(t);return!n&&!tt&&(tt=!0,console.warn(`[blockcharts] interaction.tooltip: no function "${t}" is registered (BC.defineFn); showing the default content`)),n},kt=t=>!!t&&typeof t=="object"&&typeof t.nodeType=="number",nt=t=>{if(!(t==null||t===!1)){if(typeof t=="string"||typeof t=="number"){if(t==="")return;const n=u.createElement("div");n.textContent=String(t),l.appendChild(n)}else if(Array.isArray(t))t.forEach(nt);else if(kt(t))l.appendChild(t);else if(typeof t.html=="string"){const n=u.createElement("div");n.innerHTML=t.html,l.appendChild(n)}}},_=()=>{l.style.display="none",b.style.display="none",C.style.display="none",g.style.display="none"},T=(t,n)=>{const r=s.table.columns[t][n];return D[t]?D[t](r)||"\u2013":gt(r)};function ot(t){if(typeof i.heading=="string"&&s.table.columns[i.heading])return i.heading;for(const n of["category","date"])for(const r of["x","y"])try{const e=s.channel(t,r);if(e.field&&e.scale&&e.scale.input===n&&s.table.columns[e.field])return e.field}catch{}return null}function st(t,n){for(const[r,e]of[["x","x2"],["y","y2"]])try{const o=s.channel(t,r),f=s.channel(t,e);if(!o.field||!f.field||o.field===f.field||!o.scale||o.scale!==f.scale||o.scale.input==="category"||!s.table.columns[o.field]||!s.table.columns[f.field]||n.indexOf(o.field)<0||n.indexOf(f.field)<0)continue;return{from:o.field,to:f.field,date:o.scale.input==="date"}}catch{}return null}const Z=t=>M.get(`mark.${t.type}`);function J(t,n,r){const e=Z(t);if(!e||typeof e.color!="function")return"";try{const o=e.color(t,s,n,r);return typeof o=="string"?o:""}catch{return""}}function I(t,n){const r=[];for(const e of Object.keys(n.channels))try{const o=s.channel(t,e);o.field&&r.push(o.field)}catch{}return typeof t.group=="string"&&r.push(t.group),r}function Et(t,n,r,e,o){const f=J(t,r,e);if(o===null||I(t,n).includes(o))return f;const d=s.spec.marks;for(let a=d.length-1;a>=0;a--){const y=Z(d[a]);if(a===r||!y||!I(d[a],y).includes(o))continue;const h=J(d[a],a,e);if(h)return h}return f}function it(t,n){const r=new Set;for(const e of Object.keys(n.channels))try{const o=s.channel(t,e);o.field&&o.scale&&o.scale.input==="date"&&r.add(o.field)}catch{}return(e,o)=>!D[e]&&r.has(e)&&v(s.table.columns[e][o])||T(e,o)}function At(t,n,r,e,o){const f=[],d=[],a=new Set(o),y=it(t,n),h=m=>{const F=s.table.columns[m];if(!F||a.has(m)||(a.add(m),ht(F[r])))return;const x=y(m,r);e.some(S=>y(m,S)!==x)||(f.push([W[m]||m,x]),d.push(m))};return(B||I(t,n)).forEach(h),{lines:f,fields:d}}function Ot(t){const n=H().toLogical(s,t);if(!H().inPlot(s,n,12))return _();const r=H().pickAt(s,n);if(!r)return _();const{pick:e,mark:o,def:f,index:d}=r,a=e.card,y=e.rows&&e.rows.length>1?e.rows:[e.row],h=a?null:ot(o),m=typeof i.heading=="string"&&!!s.table.columns[i.heading],F=a||m?null:st(o,B||I(o,f)),x=F&&(!h||h===F.from||h===F.to)?F:null,S=a?T:it(o,f),w=x&&y.every(p=>S(x.from,p)===S(x.from,e.row)&&S(x.to,p)===S(x.to,e.row))?x:null,E=!x&&h&&y.every(p=>T(h,p)===T(h,e.row))?h:null,rt=a?{lines:a.lines,fields:[]}:At(o,f,e.row,y,w?[w.from,w.to]:[]),K=rt.lines,lt=E?W[E]||E:null;let N;const at=a?void 0:wt();if(at){const p={};for(const c of Object.keys(s.table.columns))p[c]=s.table.columns[c][e.row];try{N=at({row:e.row,values:p,rows:y,lines:K,mark:o,markIndex:d,x:e.x,y:e.y,table:s.table})}catch(c){et||(et=!0,console.error("[blockcharts] interaction.tooltip: the content function threw, showing the default content:",c)),N=void 0}}if(N===null||N===!1)return _();l.textContent="";const Ct=J(o,d,e.row),ct=rt.fields.find((p,c)=>K[c][0]!==lt),ft=a?a.color||"":Et(o,f,d,e.row,B&&ct!==void 0?ct:null);if(N===void 0){if(E||a||w){const c=u.createElement("div");if(c.setAttribute("class","bc-tooltip-heading"),E?c.setAttribute("data-bc-field",E):w&&c.setAttribute("data-bc-field",`${w.from} ${w.to}`),Object.assign(c.style,{display:"flex",alignItems:"center",gap:"7px",fontWeight:"600",marginBottom:"4px"}),ft){const j=u.createElement("span");j.setAttribute("class","bc-tooltip-swatch"),Object.assign(j.style,{width:"8px",height:"8px",borderRadius:"50%",background:ft,boxShadow:"inset 0 0 0 1px var(--bc-tooltip-highlight-line, rgba(127,127,127,.45))",flex:"none"}),c.appendChild(j)}const z=u.createElement("span"),X=s.table.columns[E],L=(()=>{for(const j of["x","y"])try{const R=s.channel(o,j);if(R.field===E&&R.scale&&R.scale.input==="date")return!0}catch{}return!1})(),Y=E;if(a)z.textContent=a.title;else if(w){const j=[S(w.from,e.row),S(w.to,e.row)];z.textContent=j.join(j.some(R=>R.indexOf(" ")>=0)?" \u2013 ":"\u2013")}else z.textContent=!D[Y]&&L&&v(X[e.row])||T(Y,e.row);c.appendChild(z),l.appendChild(c)}const p=u.createElement("div");p.setAttribute("class","bc-tooltip-lines"),Object.assign(p.style,{display:"grid",gridTemplateColumns:"auto auto",columnGap:"16px",rowGap:"1px"});for(const[c,z]of K){if(c===lt)continue;const X=u.createElement("span");X.textContent=c,X.style.opacity="0.68";const L=u.createElement("span");L.textContent=z,Object.assign(L.style,{textAlign:"right",fontWeight:"600"}),p.appendChild(X),p.appendChild(L)}p.children.length&&l.appendChild(p)}else nt(N);if(!(l.childNodes?l.childNodes.length>0:l.children.length>0))return _();const A=V.getBoundingClientRect(),k=O.getBoundingClientRect(),$=A.width/s.size.w,G=A.left-k.left+e.x*$,P=A.top-k.top+e.y*$;g.textContent="";for(const p of e.flows||[]){const c=u.createElementNS("http://www.w3.org/2000/svg","path");c.setAttribute("d",p.d),c.setAttribute("fill",p.fill),c.setAttribute("fill-opacity","0.5"),g.appendChild(c)}e.flows&&e.flows.length?(g.setAttribute("viewBox",`0 0 ${s.size.w} ${s.size.h}`),Object.assign(g.style,{left:A.left-k.left+"px",top:A.top-k.top+"px",width:A.width+"px",height:A.height+"px",display:"block"})):g.style.display="none",(q==="box"||q==="auto"&&!!e.box)&&e.box?(Object.assign(C.style,{left:A.left-k.left+e.box.x*$+"px",top:A.top-k.top+e.box.y*$+"px",width:Math.max(0,e.box.w*$)+"px",height:Math.max(0,e.box.h*$)+"px",display:"block"}),b.style.display="none"):q!=="none"?(b.style.left=G+"px",b.style.top=P+"px",b.style.background=Ct||"var(--bc-text, #333)",b.style.display="block",C.style.display="none"):(b.style.display="none",C.style.display="none");const Q=u.defaultView||globalThis,U=Math.max(0,-k.left),dt=typeof Q.innerWidth=="number"&&Q.innerWidth>0?Math.min(k.width,Q.innerWidth-k.left):k.width;l.style.display="block",l.style.maxWidth=Math.max(120,dt-U)+"px",l.style.left=U+"px";const pt=l.offsetWidth||0,ut=l.offsetHeight||0,St=G+12+pt>dt?G-12-pt:G+12,jt=P-12-ut>=0?P-12-ut:P+12;l.style.left=Math.max(U,St)+"px",l.style.top=Math.max(0,jt)+"px"}if(i.content===void 0&&s.table){const t=[];for(const n of s.spec.marks){const r=Z(n);if(!r||!r.pick)continue;const e=B||I(n,r),o=ot(n),f=typeof i.heading=="string"?null:st(n,e);for(const d of e)d===o||f&&(d===f.from||d===f.to)||!W[d]&&bt.test(d)&&s.table.columns[d]&&t.indexOf(d)<0&&t.push(d)}t.length&&console.warn(`[blockcharts] interaction.tooltip: the card shows ${t.map(n=>`"${n}"`).join(", ")} under ${t.length>1?"their own names; give them names":"its own name; give it a name"} a reader knows in "labels"`)}yt(s,Ot,_),s.cleanup(()=>{for(const t of[l,b,C,g])t.parentNode&&t.parentNode.removeChild(t);xt()})}};M.define(mt)})(globalThis.BC);
3
3
 
@@ -1,3 +1,3 @@
1
- /*! blockcharts 0.0.2 | MIT License */
1
+ /*! blockcharts 0.0.3 | MIT License */
2
2
  "use strict";(function(u){const k=()=>u.get("lib.view").exports,w={role:"interaction",type:"zoom-controls",version:6,requires:["lib.view"],params:{scales:{kind:"list",default:["x"]},fit:{kind:"list"},step:{kind:"number",default:.5},maxZoom:{kind:"number",default:50},titles:{kind:"any"},corner:{kind:"enum",values:["top-right","top-left","bottom-right","bottom-left"],default:"top-right"}},corner(o,e){const[b,r]=(typeof o.corner=="string"?o.corner:"top-right").split("-"),f=(Array.isArray(o.scales)?o.scales:["x"]).some(a=>typeof a=="string"&&!!e.scales[a]&&!!e.scales[a].invert);return{edge:b,side:r,width:f?120:64}},attach(o,e){const r=(Array.isArray(o.scales)?o.scales.filter(t=>typeof t=="string"):["x"]).filter(t=>{const n=e.scales[t],c=!!n&&e.orientation(t)!==null&&(!!n.invert||n.bandwidth!==void 0);return c||console.warn(`[blockcharts] interaction.zoom-controls: scale "${t}" is not a positional scale, ignored`),c});if(!r.length)return;const l=r.filter(t=>!!e.scales[t].invert),f=(Array.isArray(o.fit)?o.fit:[]).filter(t=>{const n=typeof t=="string"&&!!e.scales[t]&&r.indexOf(t)<0;return!n&&typeof t=="string"&&console.warn(`[blockcharts] interaction.zoom-controls: cannot fit scale "${t}"`),n}),a=()=>{for(const t of f)e.setView(t,e.fit(t,r[0]))},p=typeof o.step=="number"&&o.step>0&&o.step<1?o.step:.5,A=typeof o.maxZoom=="number"&&o.maxZoom>1?o.maxZoom:50,z=o.corner==="top-left"||o.corner==="bottom-right"||o.corner==="bottom-left"?o.corner:"top-right",[v,E]=z.split("-"),T=()=>{for(const t of r)e.setView(t,null);a()},g=t=>{for(const n of l)k().zoom(e,n,t,A);a()},h=e.host,x=h.ownerDocument||document,i=x.createElement("div");i.setAttribute("class","bc-zoom-controls"),Object.assign(i.style,{position:"absolute",[v]:"8px",[E]:"8px",zIndex:"6",display:"flex",gap:"4px",font:"12px/1 system-ui, sans-serif"});const d=(t,n,c)=>{const s=x.createElement("button");return s.type="button",s.textContent=t,s.setAttribute("aria-label",n),s.title=n,Object.assign(s.style,{minWidth:"22px",height:"22px",padding:"0 6px",lineHeight:"20px",textAlign:"center",border:"1px solid var(--bc-axis, #ccc)",borderRadius:"4px",cursor:"pointer",whiteSpace:"nowrap",background:"var(--bc-tooltip-bg, #fff)",color:"var(--bc-text, #333)"}),s.addEventListener("click",D=>{D.preventDefault(),c()}),i.appendChild(s),s},y=o.titles&&typeof o.titles=="object"?o.titles:{},m=(t,n)=>typeof y[t]=="string"?y[t]:n;d("100%",m("reset","Reset zoom to the full range"),T),l.length&&(d("\u2212",m("out","Zoom out"),()=>g(1/p)),d("+",m("in","Zoom in"),()=>g(p)));const Z=e.claimPosition();h.appendChild(i),e.cleanup(()=>{i.parentNode&&i.parentNode.removeChild(i),Z()})}};u.define(w)})(globalThis.BC);
3
3
 
@@ -1,3 +1,3 @@
1
- /*! blockcharts 0.0.2 | MIT License */
1
+ /*! blockcharts 0.0.3 | MIT License */
2
2
  "use strict";(function(p){const h=()=>p.get("lib.pointer").exports,y=()=>p.get("lib.view").exports,A={role:"interaction",type:"zoom",version:7,requires:["lib.pointer","lib.view"],params:{scales:{kind:"list",default:["x"]},wheel:{kind:"enum",values:["ctrl","always","off"],default:"ctrl"},fit:{kind:"list"},pan:{kind:"boolean",default:!0},maxZoom:{kind:"number",default:50}},attach(r,e){const a=(Array.isArray(r.scales)?r.scales.filter(t=>typeof t=="string"):["x"]).filter(t=>{const o=!!e.scales[t]&&!!e.scales[t].invert&&e.orientation(t)!==null;return o||console.warn(`[blockcharts] interaction.zoom: scale "${t}" is not a continuous positional scale, ignored`),o});if(!a.length)return;const q=(Array.isArray(r.fit)?r.fit:[]).filter(t=>{const o=typeof t=="string"&&!!e.scales[t]&&a.indexOf(t)<0;return!o&&typeof t=="string"&&console.warn(`[blockcharts] interaction.zoom: cannot fit scale "${t}"`),o}),w=()=>{for(const t of q)e.setView(t,e.fit(t,a[0]))},L=r.wheel==="always"||r.wheel==="off"?r.wheel:"ctrl",C=r.pan!==!1,D=typeof r.maxZoom=="number"&&r.maxZoom>1?r.maxZoom:50,n=e.root,f=t=>h().toLogical(e,t),b=t=>h().inPlot(e,t),M=(t,o)=>e.orientation(t)==="horizontal"?o.x:o.y,k=t=>y().current(e,t),E=t=>{if(L==="off"||L==="ctrl"&&!(t.ctrlKey||t.metaKey))return;const o=f(t);if(!b(o))return;t.preventDefault();const s=t.deltaMode===1?t.deltaY*16:t.deltaY,i=Math.exp(s*.002);for(const c of a){const[u,g]=k(c),[x,m]=e.scales[c].range();y().zoom(e,c,i,D,u+(M(c,o)-x)/(m-x)*(g-u))}w()};let l=null;const z=t=>{if(t.button!==0||e.dragClaimed(t))return;const o=f(t);if(!b(o))return;const s={};for(const i of a)s[i]=k(i);l={x:o.x,y:o.y,start:s},n.setPointerCapture&&n.setPointerCapture(t.pointerId),n.style.cursor="grabbing"},P=t=>{if(!l)return;const o=f(t);for(const s of a){const[i,c]=l.start[s],[u,g]=e.scales[s].range(),m=-(e.orientation(s)==="horizontal"?o.x-l.x:o.y-l.y)/(g-u)*(c-i);y().show(e,s,i+m,c+m)}w()},d=()=>{l=null,n.style.cursor="grab"},Z=t=>{if(b(f(t))){for(const o of a)e.setView(o,null);w()}};n.addEventListener("wheel",E,{passive:!1}),n.addEventListener("dblclick",Z),C&&(n.addEventListener("pointerdown",z),n.addEventListener("pointermove",P),n.addEventListener("pointerup",d),n.addEventListener("pointercancel",d),n.style.cursor="grab"),e.cleanup(()=>{n.removeEventListener("wheel",E),n.removeEventListener("dblclick",Z),n.removeEventListener("pointerdown",z),n.removeEventListener("pointermove",P),n.removeEventListener("pointerup",d),n.removeEventListener("pointercancel",d),n.style.cursor=""})}};p.define(A)})(globalThis.BC);
3
3