@unpunnyfuns/d3-blockmap 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 unpunnyfuns
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,119 @@
1
- # Temporary Holding Version
1
+ # d3-blockmap
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Canvas progress bar for millions of blocks: one pixel column per bin, drawn from a packed bitset. Zoomable, themable with CSS variables, with an optional axis and a React component.
4
+
5
+ ![10 million blocks as a zoomable canvas bar with axis ticks](demo/example.png)
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm i @unpunnyfuns/d3-blockmap
11
+ ```
12
+
13
+ Peer dependency for the React component: `react >= 19`.
14
+
15
+ ## Quick start
16
+
17
+ ```ts
18
+ import { createBlockMap } from '@unpunnyfuns/d3-blockmap';
19
+
20
+ const map = createBlockMap(document.querySelector('#progress')!, {
21
+ totalBlocks: 10_000_000,
22
+ });
23
+
24
+ map.addBlocks(newIndices); // Uint32Array or number[]
25
+ map.addRanges([[0, 123], [256, 1024]]); // [start, end) tuples
26
+ map.getProgress(); // { completed, total }
27
+ ```
28
+
29
+ The container needs a height; the canvas fills it. Leave a little space below if you turn the axis on.
30
+
31
+ ```tsx
32
+ import { useRef, useState } from 'react';
33
+ import { BlockMap } from '@unpunnyfuns/d3-blockmap/react';
34
+ import type { BlockMapHandle } from '@unpunnyfuns/d3-blockmap/react';
35
+
36
+ export const Download = ({ totalBlocks }: { totalBlocks: number }) => {
37
+ const ref = useRef<BlockMapHandle>(null);
38
+ const [highlight, setHighlight] = useState(false);
39
+
40
+ // Call ref.current?.addRanges(...) from your data source as ranges complete.
41
+
42
+ return (
43
+ <>
44
+ <BlockMap ref={ref} totalBlocks={totalBlocks} axis highlight={highlight} style={{ height: 12 }} />
45
+ <button onClick={() => setHighlight((on) => !on)}>Highlight missing</button>
46
+ </>
47
+ );
48
+ };
49
+ ```
50
+
51
+ ## Options
52
+
53
+ | Option | Type | Default | What it does |
54
+ |---|---|---|---|
55
+ | `totalBlocks` | `number` | required | Number of blocks, up to 2^32 − 1. |
56
+ | `initialBlocks` | `ArrayLike<number>` | | Indices already complete. |
57
+ | `initialRanges` | `RangeInput` | | `[start, end)` tuples (or a flat `Uint32Array` of pairs) already complete. |
58
+ | `partial` | `"coverage" \| "gradient"` | `"coverage"` | How partly filled columns are coloured. See Theming. |
59
+ | `view` | `{ start, end }` | full range | Initial zoom window, `end` exclusive. |
60
+ | `interactive` | `boolean` | `true` | Ctrl/⌘+wheel zooms, drag pans, double-click resets. |
61
+ | `onViewChange` | `(view) => void` | | Called when the view changes. |
62
+ | `axis` | `boolean \| { format?, tickCount? }` | `false` | Tick labels under the bar. |
63
+
64
+ ## Methods
65
+
66
+ | Method | What it does |
67
+ |---|---|
68
+ | `setBlocks(indices)` | Replace everything with these indices. |
69
+ | `addBlocks(indices)` | Mark indices complete. Cheapest way to add single blocks. |
70
+ | `setRanges(ranges)` | Replace everything with a snapshot of ranges. |
71
+ | `addRanges(ranges)` | Mark ranges complete. Overlap is fine and counted once. |
72
+ | `removeRanges(ranges)` | Mark ranges missing again. |
73
+ | `getProgress()` | `{ completed, total }`. |
74
+ | `setView(view)` / `resetView()` / `getView()` | Zoom window control. |
75
+ | `setHighlight(on)` | Blink incomplete columns. Steady under `prefers-reduced-motion`. |
76
+ | `getScale()` | `{ domain, range, x(block), block(x) }` to draw your own axis. |
77
+ | `destroy()` | Remove everything. |
78
+
79
+ Ranges use exclusive ends: `[0, 10]` means blocks 0 through 9. Unsorted, overlapping, and out-of-range input is normalised.
80
+
81
+ ## React
82
+
83
+ Props mirror the options plus `blocks`, `ranges`, `highlight`, `className`, `style`. `ref` is a plain prop exposing the methods above, except `setBlocks` and `destroy`, as `BlockMapHandle`.
84
+
85
+ - `blocks` and `ranges` apply when their identity changes, so keep the references stable.
86
+ - `partial`, `interactive`, and `axis` recreate the instance when they change; memoise an object `axis`.
87
+ - For high-frequency updates use the ref (`addBlocks`, `addRanges`) rather than props.
88
+
89
+ ## Theming
90
+
91
+ Set these CSS custom properties on the container or an ancestor:
92
+
93
+ | Property | Default | Used for |
94
+ |---|---|---|
95
+ | `--blockmap-missing` | `#2b2b2b` | empty columns |
96
+ | `--blockmap-complete` | `#2ecc71` | full columns |
97
+ | `--blockmap-partial` | `#e0a500` | midpoint of the `coverage` fade |
98
+ | `--blockmap-partial-low` / `-high` | `#5b3a00` / `#e0a500` | the `gradient` style |
99
+ | `--blockmap-highlight` | `#ff4d4f` | blinking incomplete columns |
100
+ | `--blockmap-axis-color` | `currentColor` | tick labels |
101
+
102
+ `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
+
104
+ The tooltip is a `div[data-blockmap-tooltip]` and ticks are `span[data-blockmap-tick]` inside `div[data-blockmap-axis]`; style them with CSS.
105
+
106
+ ## Notes
107
+
108
+ - Memory is 1 bit per block plus one counter per pixel column. Updates cost in proportion to what changed, not to `totalBlocks`.
109
+ - When the view is narrower than the pixel width, each block is drawn as a discrete segment.
110
+ - The axis sits just below the container at `top: 100%`; don't clip it with `overflow: hidden`.
111
+
112
+ ## Development
113
+
114
+ ```bash
115
+ npm run verify # lint, format check, typecheck, tests, build
116
+ npm run demo # serves the repo; open /demo/
117
+ ```
118
+
119
+ Tests run in headless Chromium through Vitest browser mode; pure modules run in Node. One-time setup: `npx playwright install chromium`. Shared test fakes live in `src/testing/`.