hilbert-chart-3d 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 Vasco Asturiano
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,79 @@
1
- # Temporary Holding Version
1
+ Hilbert Chart 3D
2
+ ================
3
+
4
+ [![NPM package][npm-img]][npm-url]
5
+ [![Build Size][build-size-img]][build-size-url]
6
+ [![NPM Downloads][npm-downloads-img]][npm-downloads-url]
7
+ [![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=L398E7PKP47E8&currency_code=USD&source=url)
8
+
9
+ A 3D hilbert space-filling curve chart for representing one-dimensional lengths on a three-dimensional space.
10
+
11
+ Uses [ThreeJS](https://github.com/mrdoob/three.js/)/WebGL for 3D rendering.
12
+
13
+ ## Examples
14
+
15
+ * [IPv4 Address Space](https://vasturiano.github.io/hilbert-chart-3d/examples/ipv4-address-space/) ([source](https://github.com/vasturiano/hilbert-chart-3d/blob/master/examples/ipv4-address-space/index.html))
16
+ * [Ordinal (cubic pie chart)](https://vasturiano.github.io/hilbert-chart-3d/examples/ordinal/) ([source](https://github.com/vasturiano/hilbert-chart-3d/blob/master/examples/ordinal/index.html))
17
+
18
+ ## Quick start
19
+
20
+ ```js
21
+ import HilbertChart3D from 'hilbert-chart-3d';
22
+ ```
23
+ or using a *script* tag
24
+ ```html
25
+ <script src="//cdn.jsdelivr.net/npm/hilbert-chart-3d"></script>
26
+ ```
27
+ then
28
+ ```js
29
+ const myChart = new HilbertChart3D(<myDOMElement>)
30
+ .hilbertOrder(<hilbertOrder>)
31
+ .data(<myData>);
32
+ ```
33
+
34
+ ## API reference
35
+
36
+ ### Initialisation
37
+ ```js
38
+ new HilbertChart3D(<domElement>, { configOptions })
39
+ ```
40
+
41
+ | Config options | Description | Default |
42
+ | --- | --- | :--: |
43
+ | <b>controlType</b>: <i>str</i> | Which type of control to use to control the camera. Choice between [trackball](https://threejs.org/examples/misc_controls_trackball.html), [orbit](https://threejs.org/examples/#misc_controls_orbit) or [fly](https://threejs.org/examples/misc_controls_fly.html). | `orbit` |
44
+
45
+ ### Methods
46
+
47
+ | Method | Description | Default |
48
+ | ------------------ | -------------------------------------------------------------------------------------------------------------------------- | ------------- |
49
+ | <b>width</b>([<i>px</i>]) | Getter/setter for the canvas width. | *&lt;window width&gt;* |
50
+ | <b>height</b>([<i>px</i>]) | Getter/setter for the canvas height. | *&lt;window height&gt;* |
51
+ | <b>hilbertOrder</b>([<i>number</i>]) | Getter/setter for the extent of the hilbert curve range, determined by `8^order`. Orders above `17` use BigInt arithmetic; supply BigInt values or safe integer Numbers for exact input. | 3 |
52
+ | <b>data</b>([<i>array</i>]) | Getter/setter for the list of ranges to render. Each range object should follow the minimum syntax of `{start: <number or bigint>, length: <number or bigint>}`. | `[]` |
53
+ | <b>color</b>([<i>string</i> or <i>fn</i>]) | Getter/setter for the range object color accessor function (`fn(range)`) or attribute. | (cycle through d3.schemeCategory20 for unique labels) |
54
+ | <b>label</b>([<i>string</i> or <i>fn</i>]) | Getter/setter for the range object label accessor function (`fn(range)`) or attribute. | `name` |
55
+ | <b>labelColor</b>([<i>string</i> or <i>fn</i>]) | Getter/setter for the range object label color accessor function (`fn(range)`) or attribute. | `() => 'white'` |
56
+ | <b>padding</b>([<i>number</i>, <i>string</i> or <i>fn</i>]) | Getter/setter for the range object padding ratio accessor function (`fn(range)`), attribute or a constant number for all ranges. The padding ratio should be a number between `0` and `1` representing the proportional size of the padding space compared to the width of the path. | 0 |
57
+ | <b>valFormatter</b>([<i>fn</i>]) | Getter/setter for the value formatting function (`fn(value)`), in default tooltips. Values may be Numbers or BigInts; should return a string. | `d => d` |
58
+ | <b>simplifyCurves</b>([<i>boolean</i>]) | Getter/setter for whether to simplify the resolution of the curve to the most canonical 2-bit boundary that fits the range integral. For example, in a 2nd order curve (64 values), a range from 8 to 23 can be simplified from 16 vertices to 2 (each filling a cube with 8 values). This simplification greatly reduces the number of vertices in the curve and improves the calculation and rendering performance, specially for high-order ranges which tend to fall on bit boundaries. | `true` |
59
+ | <b>focusOn</b>(<i>pos</i>, <i>length</i>, [<i>ms</i>]) | Zoom-in on a particular area of the chart, defined by [`pos`, `pos+length-1`]. `pos` and `length` may be Numbers or BigInts. An optional 3rd argument defines the duration of the transition (in ms) to animate the zooming motion. A value of 0 (default) jumps immediately to the final position. ||
60
+ | <b>zoomToFit</b>([<i>ms</i>], [<i>px</i>], [<i>nodeFilterFn</i>]) | Automatically moves the camera so that all of the hilbert segments become visible within its field of view. It accepts two optional arguments: the first defines the duration of the transition (in ms) to animate the camera motion (default: 0ms). The second argument is the amount of padding (in px) between the edge of the canvas and the outermost node location (default: 10px). | `(0, 10)` |
61
+ | <b>tooltipContent</b>([<i>string</i> or <i>fn</i>]) | Getter/setter for the range object tooltip content accessor function or attribute. Supports plain text or HTML content. | `<label>: <start> - <end>` |
62
+ | <b>onHover</b>(<i>fn</i>) | Callback function for range mouse over events. The range object (or `null` if hovering out) is included as single argument `onHover(range)`. | - |
63
+ | <b>onClick</b>(<i>fn</i>) | Callback function for range clicks. The range object is included as single argument `onRangeClick(range)`. | - |
64
+
65
+ Use BigInt literals (for example, `12345678901234567890n`) when values exceed JavaScript's safe integer range.
66
+
67
+ ## ❤️ Support This Project
68
+
69
+ If you find this module useful and would like to support its development, you can [buy me a ☕](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=L398E7PKP47E8&currency_code=USD&source=url). Your contributions help keep open-source sustainable!
70
+ [![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=L398E7PKP47E8&currency_code=USD&source=url)
71
+
72
+
73
+ [npm-img]: https://img.shields.io/npm/v/hilbert-chart-3d
74
+ [npm-url]: https://npmjs.org/package/hilbert-chart-3d
75
+ [build-size-img]: https://img.shields.io/bundlephobia/minzip/hilbert-chart-3d
76
+ [build-size-url]: https://bundlephobia.com/result?p=hilbert-chart-3d
77
+ [npm-downloads-img]: https://img.shields.io/npm/dt/hilbert-chart-3d
78
+ [npm-downloads-url]: https://www.npmtrends.com/hilbert-chart-3d
2
79
 
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.
@@ -0,0 +1,51 @@
1
+ type Accessor<In, Out> = Out | string | ((obj: In) => Out);
2
+ type NumericValue = number | bigint;
3
+
4
+ interface Range {
5
+ start: NumericValue;
6
+ length: NumericValue;
7
+ [key: string]: any;
8
+ }
9
+
10
+ type RangeBounds = Pick<Range, 'start' | 'length'>;
11
+ type RangeAccessor<R extends RangeBounds, T> = Accessor<R, T>;
12
+ type NumFormatter = (num: NumericValue) => string;
13
+
14
+ declare class HilbertChart<R extends RangeBounds = Range> {
15
+ constructor(element: HTMLElement);
16
+
17
+ width(): number;
18
+ width(width: number): HilbertChart<R>;
19
+ height(): number;
20
+ height(width: number): HilbertChart<R>;
21
+
22
+ hilbertOrder(): number;
23
+ hilbertOrder(height: number): HilbertChart<R>;
24
+
25
+ data(): R[];
26
+ data<T extends RangeBounds>(data: T[]): HilbertChart<T>;
27
+ color(): RangeAccessor<R, string>;
28
+ color(colorAccessor: RangeAccessor<R, string>): HilbertChart<R>;
29
+ label(): RangeAccessor<R, string>;
30
+ label(textAccessor: RangeAccessor<R, string>): HilbertChart<R>;
31
+ labelColor(): RangeAccessor<R, string>;
32
+ labelColor(colorAccessor: RangeAccessor<R, string>): HilbertChart<R>;
33
+ padding(): RangeAccessor<R, number>;
34
+ padding(paddingAccessor: RangeAccessor<R, number>): HilbertChart<R>;
35
+ valFormatter(): NumFormatter;
36
+ valFormatter(formatter: NumFormatter): HilbertChart<R>;
37
+ simplifyCurves(): boolean;
38
+ simplifyCurves(simplifyCurves: boolean): HilbertChart<R>;
39
+
40
+ focusOn(pos: NumericValue, length: NumericValue, ms?: number): HilbertChart<R>;
41
+
42
+ tooltipContent(): RangeAccessor<R, string>;
43
+ tooltipContent(contentAccessor: RangeAccessor<R, string>): HilbertChart<R>;
44
+
45
+ onHover(cb: (range: R | null) => void): HilbertChart<R>;
46
+ onClick(cb: (range: R) => void): HilbertChart<R>;
47
+ onBackgroundClick(cb: () => void): HilbertChart<R>;
48
+ }
49
+
50
+ export { HilbertChart as default };
51
+ export type { Range };