@unpunnyfuns/d3-blockmap 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -5
- package/dist/{chunk-WIDC3EN2.js → chunk-6BBJWE5O.js} +495 -194
- package/dist/chunk-6BBJWE5O.js.map +1 -0
- package/dist/index.d.ts +60 -8
- package/dist/index.js +1 -1
- package/dist/react/index.d.ts +8 -3
- package/dist/react/index.js +49 -38
- package/dist/react/index.js.map +1 -1
- package/package.json +11 -3
- package/dist/chunk-WIDC3EN2.js.map +0 -1
package/README.md
CHANGED
|
@@ -57,9 +57,14 @@ export const Download = ({ totalBlocks }: { totalBlocks: number }) => {
|
|
|
57
57
|
| `initialRanges` | `RangeInput` | | `[start, end)` tuples (or a flat `Uint32Array` of pairs) already complete. |
|
|
58
58
|
| `partial` | `"coverage" \| "gradient"` | `"coverage"` | How partly filled columns are coloured. See Theming. |
|
|
59
59
|
| `view` | `{ start, end }` | full range | Initial zoom window, `end` exclusive. |
|
|
60
|
-
| `interactive` | `boolean` | `true` | Ctrl/⌘+wheel zooms, drag pans, double-click resets. |
|
|
60
|
+
| `interactive` | `boolean` | `true` | Ctrl/⌘+wheel zooms, drag pans, double-click resets; keyboard controls when focused, see Behaviour. |
|
|
61
61
|
| `onViewChange` | `(view) => void` | | Called when the view changes. |
|
|
62
62
|
| `axis` | `boolean \| { format?, tickCount? }` | `false` | Tick labels under the bar. |
|
|
63
|
+
| `brush` | `boolean` | `false` | A mouse or pen drag selects a block range; panning then needs Shift. See Behaviour. |
|
|
64
|
+
| `onBrush` | `(selection) => void` | | Called on every brush move with the live `[start, end)` or `null`. |
|
|
65
|
+
| `onBrushEnd` | `(selection) => void` | | Called when the gesture ends, with the snapped `[start, end)`, or `null` when it cleared the selection. A gesture that leaves the selection as it was fires nothing. |
|
|
66
|
+
| `onBlockClick` | `(event) => void` | | Called on click with `{ block, range, completed, total, originalEvent }`. Works even when `interactive` is `false`. |
|
|
67
|
+
| `label` | `(progress) => string` | | Overrides the canvas `aria-label`. See Behaviour. |
|
|
63
68
|
|
|
64
69
|
## Methods
|
|
65
70
|
|
|
@@ -72,18 +77,29 @@ export const Download = ({ totalBlocks }: { totalBlocks: number }) => {
|
|
|
72
77
|
| `removeRanges(ranges)` | Mark ranges missing again. |
|
|
73
78
|
| `getProgress()` | `{ completed, total }`. |
|
|
74
79
|
| `setView(view)` / `resetView()` / `getView()` | Zoom window control. |
|
|
80
|
+
| `setBrush(selection)` | Select `[start, end)` blocks, or `null` to clear. Fires no callbacks. |
|
|
81
|
+
| `getBrush()` | The current selection as a copy, or `null`. |
|
|
75
82
|
| `setHighlight(on)` | Blink incomplete columns. Steady under `prefers-reduced-motion`. |
|
|
76
83
|
| `getScale()` | `{ domain, range, x(block), block(x) }` to draw your own axis. |
|
|
77
84
|
| `destroy()` | Remove everything. |
|
|
78
85
|
|
|
79
86
|
Ranges use exclusive ends: `[0, 10]` means blocks 0 through 9. Unsorted, overlapping, and out-of-range input is normalised.
|
|
80
87
|
|
|
88
|
+
## Behaviour
|
|
89
|
+
|
|
90
|
+
- The canvas is focusable (`tabindex="0"`) when `interactive` isn't `false`, and announces progress through `role="img"` plus an `aria-label`: `label` overrides the default `Download progress: 4,343,270 of 10,000,000 blocks (43%)` text.
|
|
91
|
+
- With the canvas focused: `+`/`-` (or `=`/`_`) zoom in or out around the centre of the current view, arrow keys pan by 10% of the view length, Shift+arrow by 50%, and `Home` or `0` resets to the full range.
|
|
92
|
+
- With `brush: true`, a mouse or pen drag selects a block range and Shift+drag pans; click an empty spot to clear. The brush is a mouse and pen gesture only, so a touch drag keeps panning and needs no modifier.
|
|
93
|
+
- `onBlockClick` reports the block under the pointer, or the column's range when a column covers several blocks. It does not fire for a click that lands 3 px or more from where the press began, which is how a pan or a brush drag ends, nor for a click outside the canvas. A plain click with no selection present reports the block it hit; the click that clears an existing selection does not.
|
|
94
|
+
|
|
81
95
|
## React
|
|
82
96
|
|
|
83
|
-
Props mirror the options plus `blocks`, `ranges`, `highlight`, `className`, `style`. `ref` is a plain prop exposing
|
|
97
|
+
Props mirror the options, including `label`, `brush`, `onBrush`, `onBrushEnd`, `onBlockClick`, plus `blocks`, `ranges`, `highlight`, `className`, `style`. `ref` is a plain prop exposing every method above except `destroy`, as `BlockMapHandle`.
|
|
84
98
|
|
|
85
99
|
- `blocks` and `ranges` apply when their identity changes, so keep the references stable.
|
|
86
|
-
- `partial`, `interactive`, and `
|
|
100
|
+
- `partial`, `interactive`, `axis`, and `brush` recreate the instance when they change; memoise an object `axis`.
|
|
101
|
+
- `onViewChange`, `onBrush`, `onBrushEnd`, `onBlockClick`, and `label` can be inline, added, or removed: the latest function is called without recreating the instance. A changed `label` applies on the next progress update.
|
|
102
|
+
- `setBlocks` and `setRanges` on the ref hold until the `blocks` or `ranges` prop next changes.
|
|
87
103
|
- For high-frequency updates use the ref (`addBlocks`, `addRanges`) rather than props.
|
|
88
104
|
|
|
89
105
|
## Theming
|
|
@@ -97,17 +113,20 @@ Set these CSS custom properties on the container or an ancestor:
|
|
|
97
113
|
| `--blockmap-partial` | `#e0a500` | midpoint of the `coverage` fade |
|
|
98
114
|
| `--blockmap-partial-low` / `-high` | `#5b3a00` / `#e0a500` | the `gradient` style |
|
|
99
115
|
| `--blockmap-highlight` | `#ff4d4f` | blinking incomplete columns |
|
|
116
|
+
| `--blockmap-brush` | `#ffffff` | brush selection |
|
|
100
117
|
| `--blockmap-axis-color` | `currentColor` | tick labels |
|
|
101
118
|
|
|
102
119
|
`coverage` fades missing → partial → complete by how full a column is, so range edges look crisp. `gradient` fades low → high instead, which shows density when blocks arrive scattered.
|
|
103
120
|
|
|
104
|
-
The tooltip is a `div[data-blockmap-tooltip]
|
|
121
|
+
The tooltip is a `div[data-blockmap-tooltip]`, ticks are `span[data-blockmap-tick]` inside `div[data-blockmap-axis]`, and the brush overlay is an `svg[data-blockmap-brush]`; style them with CSS.
|
|
105
122
|
|
|
106
123
|
## Notes
|
|
107
124
|
|
|
108
125
|
- Memory is 1 bit per block plus one counter per pixel column. Updates cost in proportion to what changed, not to `totalBlocks`.
|
|
109
126
|
- When the view is narrower than the pixel width, each block is drawn as a discrete segment.
|
|
110
127
|
- The axis sits just below the container at `top: 100%`; don't clip it with `overflow: hidden`.
|
|
128
|
+
- d3 packages are external imports, not bundled; they dedupe with your own D3.
|
|
129
|
+
- Editing a selection that is partly outside the view re-derives both edges from the visible span, so the off-screen edge snaps to the view bound.
|
|
111
130
|
|
|
112
131
|
## Development
|
|
113
132
|
|
|
@@ -116,4 +135,6 @@ npm run verify # lint, format check, typecheck, tests, build
|
|
|
116
135
|
npm run demo # serves the repo; open /demo/
|
|
117
136
|
```
|
|
118
137
|
|
|
119
|
-
|
|
138
|
+
Files named `*.browser.test.ts(x)` run in headless Chromium; every other test is a Node unit test. One-time setup: `npx playwright install chromium` and `npm run prepare` (installs the commit-message hook). Shared test fakes live in `src/testing/`.
|
|
139
|
+
|
|
140
|
+
Commits follow [Conventional Commits](https://www.conventionalcommits.org); commitlint checks each message. Releases are automated: release-please opens a release PR from the commit history, and merging it tags the version, publishes the GitHub release, and stages the npm publish for approval with 2FA. There is no npm token anywhere.
|