hilbert-chart-3d 0.4.1 → 0.5.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 +35 -12
- package/dist/hilbert-chart-3d.d.ts +33 -15
- package/dist/hilbert-chart-3d.js +483 -568
- package/dist/hilbert-chart-3d.js.map +1 -1
- package/dist/hilbert-chart-3d.min.js +2 -2
- package/dist/hilbert-chart-3d.mjs +22 -6
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -42,29 +42,52 @@ new HilbertChart3D(<domElement>, { configOptions })
|
|
|
42
42
|
|
|
43
43
|
| Config options | Description | Default |
|
|
44
44
|
| --- | --- | :--: |
|
|
45
|
-
| <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)
|
|
46
|
-
|
|
47
|
-
### Methods
|
|
45
|
+
| <b>controlType</b>: <i>str</i> or <i>class</i> | Which type of control to use to control the camera. Choice between [trackball](https://threejs.org/examples/misc_controls_trackball.html), [arcball](https://threejs.org/examples/misc_controls_arcball.html), [orbit](https://threejs.org/examples/#misc_controls_orbit), [fly](https://threejs.org/examples/misc_controls_fly.html), or a custom [Three.js controls](https://threejs.org/docs/#Controls) class. | `arcball` |
|
|
48
46
|
|
|
47
|
+
### Container
|
|
49
48
|
| Method | Description | Default |
|
|
50
49
|
| ------------------ | -------------------------------------------------------------------------------------------------------------------------- | ------------- |
|
|
51
50
|
| <b>width</b>([<i>px</i>]) | Getter/setter for the canvas width. | *<window width>* |
|
|
52
51
|
| <b>height</b>([<i>px</i>]) | Getter/setter for the canvas height. | *<window height>* |
|
|
52
|
+
|
|
53
|
+
### Hilbert layout
|
|
54
|
+
| Method | Description | Default |
|
|
55
|
+
| ------------------ | -------------------------------------------------------------------------------------------------------------------------- | ------------- |
|
|
53
56
|
| <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 |
|
|
54
|
-
| <b>
|
|
55
|
-
| <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) |
|
|
56
|
-
| <b>label</b>([<i>string</i> or <i>fn</i>]) | Getter/setter for the range object label accessor function (`fn(range)`) or attribute. | `name` |
|
|
57
|
-
| <b>labelColor</b>([<i>string</i> or <i>fn</i>]) | Getter/setter for the range object label color accessor function (`fn(range)`) or attribute. A falsy value disables the label. | `() => 'white'` |
|
|
57
|
+
| <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` |
|
|
58
58
|
| <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 |
|
|
59
59
|
| <b>paddingAbsolute</b>([<i>number</i>, <i>string</i> or <i>fn</i>]) | Getter/setter for the range object absolute padding accessor function (`fn(range)`), attribute or a constant number for all ranges. The value represents the absolute padding size as a fraction of the full Hilbert width. | 0 |
|
|
60
|
-
| <b>
|
|
61
|
-
|
|
60
|
+
| <b>getPositionAtVal</b>(<i>value</i>) | Returns the `THREE.Vector3` position at the specified value along the curve. `value` may be a Number or BigInt. | |
|
|
61
|
+
|
|
62
|
+
### Data input
|
|
63
|
+
| Method | Description | Default |
|
|
64
|
+
| ------------------ | -------------------------------------------------------------------------------------------------------------------------- | ------------- |
|
|
65
|
+
| <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>}`; `start` and `length` must both be Numbers or both be BigInts. | `[]` |
|
|
66
|
+
| <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.schemePaired for unique labels) |
|
|
67
|
+
| <b>label</b>([<i>string</i> or <i>fn</i>]) | Getter/setter for the range object label accessor function (`fn(range)`) or attribute. | `name` |
|
|
68
|
+
| <b>labelColor</b>([<i>string</i>, <i>false</i> or <i>fn</i>]) | Getter/setter for the range object label color accessor function (`fn(range)`) or attribute. A falsy value disables the label. | `() => 'white'` |
|
|
69
|
+
| <b>valFormatter</b>([<i>fn</i>]) | Getter/setter for the value formatting function (`fn(value)`), in default tooltips. Values may be Numbers or BigInts. | `d => d` |
|
|
70
|
+
|
|
71
|
+
### Render control
|
|
72
|
+
| Method | Description | Default |
|
|
73
|
+
| --- | --- | :--: |
|
|
62
74
|
| <b>useInstancedMeshes</b>([<i>boolean</i>]) | Getter/setter for whether to render compatible segments with [THREE.InstancedMesh](https://threejs.org/docs/#InstancedMesh) to reduce draw calls. It's recommended to enable this for very large datasets. Segments that cannot be instanced use regular meshes. | `false` |
|
|
75
|
+
| <b>zoomToFit</b>([<i>ms</i>], [<i>px</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)` |
|
|
63
76
|
| <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. ||
|
|
64
|
-
| <b>
|
|
77
|
+
| <b>cameraPosition</b>([<i>{x,y,z}</i>], [<i>lookAt</i>], [<i>ms</i>]) | Getter/setter for the camera position, in terms of `x`, `y`, `z` coordinates. Each of the coordinates is optional, allowing for motion in just some dimensions. The optional second argument can be used to define the direction that the camera should aim at, in terms of an `{x,y,z}` point in the 3D space. The 3rd optional argument defines the duration of the transition (in ms) to animate the camera motion. A value of 0 (default) moves the camera immediately to the final position. | |
|
|
78
|
+
| <b>lights</b>([<i>array</i>]) | Getter/setter for the list of lights to use in the scene. Each item should be an instance of [Light](https://threejs.org/docs/#api/en/lights/Light). | [AmbientLight](https://threejs.org/docs/?q=ambient#api/en/lights/AmbientLight) + [DirectionalLight](https://threejs.org/docs/#api/en/lights/DirectionalLight) (from above) |
|
|
79
|
+
| <b>scene</b>() | Access the internal ThreeJS [Scene](https://threejs.org/docs/#api/scenes/Scene). | |
|
|
80
|
+
| <b>camera</b>() | Access the internal ThreeJS [Camera](https://threejs.org/docs/#api/cameras/PerspectiveCamera). | |
|
|
81
|
+
| <b>renderer</b>() | Access the internal ThreeJS [WebGL renderer](https://threejs.org/docs/#api/renderers/WebGLRenderer). ||
|
|
82
|
+
| <b>controls</b>() | Access the internal ThreeJS controls object. ||
|
|
83
|
+
|
|
84
|
+
### Interaction
|
|
85
|
+
| Method | Description | Default |
|
|
86
|
+
| --- | --- | :--: |
|
|
65
87
|
| <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>` |
|
|
66
|
-
| <b>onHover</b>(<i>fn</i>) | Callback function for range mouse over events.
|
|
67
|
-
| <b>onClick</b>(<i>fn</i>) | Callback function for range clicks.
|
|
88
|
+
| <b>onHover</b>(<i>fn</i>) | Callback function for range mouse over events. Receives the current range (or `null` if hovering out) and the previous range (or `null`). | - |
|
|
89
|
+
| <b>onClick</b>(<i>fn</i>) | Callback function for range clicks. Receives the range object and the mouse event. | - |
|
|
90
|
+
| <b>onBackgroundClick</b>(<i>fn</i>) | Callback function for click events on the empty background space. Receives the mouse event. | - |
|
|
68
91
|
|
|
69
92
|
Use BigInt literals (for example, `12345678901234567890n`) when values exceed JavaScript's safe integer range.
|
|
70
93
|
|
|
@@ -1,26 +1,33 @@
|
|
|
1
|
+
import { Controls, Vector3, Scene, Camera, WebGLRenderer, Light } from 'three';
|
|
2
|
+
|
|
1
3
|
type Accessor<In, Out> = Out | string | ((obj: In) => Out);
|
|
2
4
|
type NumericValue = number | bigint;
|
|
5
|
+
type ControlType = 'arcball' | 'trackball' | 'orbit' | 'fly' | Controls;
|
|
6
|
+
type Coordinates = { x: number; y: number; z: number };
|
|
7
|
+
type CameraPosition = Coordinates & { lookAt: Coordinates };
|
|
8
|
+
|
|
9
|
+
type Range =
|
|
10
|
+
| { start: number; length: number; [key: string]: any }
|
|
11
|
+
| { start: bigint; length: bigint; [key: string]: any };
|
|
3
12
|
|
|
4
|
-
interface
|
|
5
|
-
|
|
6
|
-
length: NumericValue;
|
|
7
|
-
[key: string]: any;
|
|
13
|
+
interface HilbertChartOptions {
|
|
14
|
+
controlType?: ControlType;
|
|
8
15
|
}
|
|
9
16
|
|
|
10
|
-
type RangeBounds =
|
|
17
|
+
type RangeBounds = { start: number; length: number } | { start: bigint; length: bigint };
|
|
11
18
|
type RangeAccessor<R extends RangeBounds, T> = Accessor<R, T>;
|
|
12
19
|
type NumFormatter = (num: NumericValue) => string;
|
|
13
20
|
|
|
14
21
|
declare class HilbertChart<R extends RangeBounds = Range> {
|
|
15
|
-
constructor(element: HTMLElement);
|
|
22
|
+
constructor(element: HTMLElement, options?: HilbertChartOptions);
|
|
16
23
|
|
|
17
24
|
width(): number;
|
|
18
25
|
width(width: number): HilbertChart<R>;
|
|
19
26
|
height(): number;
|
|
20
|
-
height(
|
|
27
|
+
height(height: number): HilbertChart<R>;
|
|
21
28
|
|
|
22
29
|
hilbertOrder(): number;
|
|
23
|
-
hilbertOrder(
|
|
30
|
+
hilbertOrder(order: number): HilbertChart<R>;
|
|
24
31
|
|
|
25
32
|
data(): R[];
|
|
26
33
|
data<T extends RangeBounds>(data: T[]): HilbertChart<T>;
|
|
@@ -28,8 +35,8 @@ declare class HilbertChart<R extends RangeBounds = Range> {
|
|
|
28
35
|
color(colorAccessor: RangeAccessor<R, string>): HilbertChart<R>;
|
|
29
36
|
label(): RangeAccessor<R, string>;
|
|
30
37
|
label(textAccessor: RangeAccessor<R, string>): HilbertChart<R>;
|
|
31
|
-
labelColor(): RangeAccessor<R, string>;
|
|
32
|
-
labelColor(colorAccessor: RangeAccessor<R, string>): HilbertChart<R>;
|
|
38
|
+
labelColor(): RangeAccessor<R, string | false>;
|
|
39
|
+
labelColor(colorAccessor: RangeAccessor<R, string | false>): HilbertChart<R>;
|
|
33
40
|
padding(): RangeAccessor<R, number>;
|
|
34
41
|
padding(paddingAccessor: RangeAccessor<R, number>): HilbertChart<R>;
|
|
35
42
|
paddingAbsolute(): RangeAccessor<R, number>;
|
|
@@ -41,15 +48,26 @@ declare class HilbertChart<R extends RangeBounds = Range> {
|
|
|
41
48
|
useInstancedMeshes(): boolean;
|
|
42
49
|
useInstancedMeshes(useInstancedMeshes: boolean): HilbertChart<R>;
|
|
43
50
|
|
|
44
|
-
focusOn(pos: NumericValue, length: NumericValue, ms?: number):
|
|
51
|
+
focusOn(pos: NumericValue, length: NumericValue, ms?: number): void;
|
|
52
|
+
zoomToFit(ms?: number, padding?: number): HilbertChart<R>;
|
|
53
|
+
cameraPosition(): CameraPosition;
|
|
54
|
+
cameraPosition(position: Partial<Coordinates>, lookAt?: Coordinates, transitionMs?: number): HilbertChart<R>;
|
|
55
|
+
getPositionAtVal(value: NumericValue): Vector3;
|
|
56
|
+
|
|
57
|
+
scene(): Scene;
|
|
58
|
+
camera(): Camera;
|
|
59
|
+
renderer(): WebGLRenderer;
|
|
60
|
+
controls(): Controls;
|
|
61
|
+
lights(): Light[];
|
|
62
|
+
lights(lights: Light[]): HilbertChart<R>;
|
|
45
63
|
|
|
46
64
|
tooltipContent(): RangeAccessor<R, string>;
|
|
47
65
|
tooltipContent(contentAccessor: RangeAccessor<R, string>): HilbertChart<R>;
|
|
48
66
|
|
|
49
|
-
onHover(cb: (range: R | null) => void): HilbertChart<R>;
|
|
50
|
-
onClick(cb: (range: R) => void): HilbertChart<R>;
|
|
51
|
-
onBackgroundClick(cb: () => void): HilbertChart<R>;
|
|
67
|
+
onHover(cb: (range: R | null, previousRange: R | null) => void): HilbertChart<R>;
|
|
68
|
+
onClick(cb: (range: R, event: MouseEvent) => void): HilbertChart<R>;
|
|
69
|
+
onBackgroundClick(cb: (event: MouseEvent) => void): HilbertChart<R>;
|
|
52
70
|
}
|
|
53
71
|
|
|
54
72
|
export { HilbertChart as default };
|
|
55
|
-
export type { Range };
|
|
73
|
+
export type { HilbertChartOptions, Range };
|