@kineviz/gl 0.6.1 → 0.7.1

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,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Kineviz, Inc.
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,33 @@
1
+ @kineviz/gl
2
+ Copyright 2026 Kineviz, Inc.
3
+
4
+ This product includes software developed at Kineviz, Inc.
5
+ Licensed under the Apache License, Version 2.0; see LICENSE.
6
+
7
+ The distributed bundles in dist/ include code from the following third-party
8
+ packages, each under its own license. Source maps are not distributed, so the
9
+ bundles contain no original TypeScript sources from this project.
10
+
11
+ three MIT https://github.com/mrdoob/three.js
12
+ @mapbox/tiny-sdf BSD-2-Clause https://github.com/mapbox/tiny-sdf
13
+ d3-force-3d MIT https://github.com/vasturiano/d3-force-3d
14
+ d3-binarytree MIT https://github.com/vasturiano/d3-binarytree
15
+ d3-octree MIT https://github.com/vasturiano/d3-octree
16
+ d3-hierarchy ISC https://github.com/d3/d3-hierarchy
17
+ d3-quadtree ISC https://github.com/d3/d3-quadtree
18
+ d3-dispatch ISC https://github.com/d3/d3-dispatch
19
+ d3-timer ISC https://github.com/d3/d3-timer
20
+ lodash MIT https://github.com/lodash/lodash
21
+ clsx MIT https://github.com/lukeed/clsx
22
+ zod MIT https://github.com/colinhacks/zod
23
+ @radix-ui/react-popover MIT https://github.com/radix-ui/primitives
24
+ @radix-ui/react-tooltip MIT https://github.com/radix-ui/primitives
25
+ fflate MIT https://github.com/101arrowz/fflate
26
+
27
+ License identifiers above are the `license` field each package declares in its
28
+ own package.json, read from the installed versions this release was built
29
+ against.
30
+
31
+ `three`, `react` and `react-dom` are peer dependencies (all MIT) and are not
32
+ bundled in the ESM or CJS entries. The UMD build (dist/kineviz-gl.umd.js) does
33
+ bundle its own copy of `three`.
package/README.md CHANGED
@@ -1,205 +1,263 @@
1
1
  # @kineviz/gl
2
2
 
3
- WebGL 3D graph visualization engine for React.
3
+ GPU-accelerated 3D graph visualization for React. Renders hundreds of thousands
4
+ of nodes and edges in a handful of instanced draw calls, with force layout,
5
+ geographic projection, picking, selection and cinematic effects built in.
4
6
 
5
- ---
6
-
7
- ## Getting started from zero
8
-
9
- This walkthrough takes you from an empty machine to a rendered graph in five steps.
10
-
11
- ### 1. Have a React 18 app
12
-
13
- Already have one? Skip ahead. Otherwise scaffold a fresh app (Vite shown here):
14
-
15
- ```bash
16
- npm create vite@latest my-graph-app -- --template react-ts
17
- cd my-graph-app
18
- npm install
19
- ```
20
-
21
- ### 2. Authenticate with npm
22
-
23
- `@kineviz/gl` is a **private, scoped package** published with restricted access. Before installing, log in to npm with an account that has been granted access to the `@kineviz` scope:
7
+ **[Documentation →](https://gl.kineviz.com)**
24
8
 
25
9
  ```bash
26
- npm login
27
- # then verify you can see the package:
28
- npm view @kineviz/gl version
10
+ npm install @kineviz/gl three react react-dom
29
11
  ```
30
12
 
31
- If `npm view` errors with `404` or `403`, your account doesn't yet have access — ask your Kineviz contact to add you to the `@kineviz` org.
32
-
33
- ### 3. Install the engine and its peer dependencies
34
-
35
- ```bash
36
- npm install @kineviz/gl
37
- npm install react@^18 react-dom@^18 three@~0.121.0
38
- ```
39
-
40
- `react`, `react-dom`, and `three` are **peer dependencies** — you install them yourself so your app controls the versions. `three` is **strict**: it must be `~0.121.0` (r122+ silently breaks edge/arrow rendering). See the table below.
13
+ ---
41
14
 
42
- ### 4. Render your first graph
15
+ ## Your first graph
43
16
 
44
- `GraphCanvas` renders into a DOM element you give it via the **`container`** prop — it does not create or own the host node, so you stay in control of layout and sizing. Create a host `<div>`, hand its element to `container`, import the CSS, and pass `data`:
17
+ Two things are required: the CSS import, and a parent with a real size.
45
18
 
46
19
  ```tsx
47
- import { useState } from "react";
48
20
  import { GraphCanvas } from "@kineviz/gl";
49
- import "@kineviz/gl/dist/index.css"; // required
50
-
51
- const nodes = [
52
- { id: "a", category: "Person", properties: { name: "Alice" } },
53
- { id: "b", category: "Person", properties: { name: "Bob" } },
54
- ];
55
- const edges = [
56
- { id: "e1", source: "a", target: "b", relationship: "KNOWS", properties: {} },
57
- ];
21
+ import "@kineviz/gl/dist/index.css";
22
+
23
+ const data = {
24
+ nodes: [
25
+ { id: "a", category: "Person", properties: { name: "Alice" } },
26
+ { id: "b", category: "Person", properties: { name: "Bob" } },
27
+ { id: "c", category: "Company", properties: { name: "Kineviz" } },
28
+ ],
29
+ edges: [
30
+ { id: "e1", source: "a", target: "b", relationship: "KNOWS", properties: {} },
31
+ { id: "e2", source: "a", target: "c", relationship: "WORKS_AT", properties: {} },
32
+ ],
33
+ };
58
34
 
59
35
  export default function App() {
60
- // Bind the host div with useState (NOT useRef) so the re-render mounts
61
- // <GraphCanvas> once the element is in the DOM.
62
- const [container, setContainer] = useState<HTMLDivElement | null>(null);
63
-
64
36
  return (
65
- <div ref={setContainer} style={{ width: "100%", height: 600 }}>
66
- {container && (
67
- <GraphCanvas
68
- container={container}
69
- data={{ nodes, edges }}
70
- forceLayout
71
- caption={{ visible: true, position: "bottom", property: "name", maxLength: 20 }}
72
- />
73
- )}
37
+ <div style={{ width: "100%", height: 600 }}>
38
+ <GraphCanvas data={data} forceLayout caption />
74
39
  </div>
75
40
  );
76
41
  }
77
42
  ```
78
43
 
79
- Two things that trip people up here:
80
-
81
- - **Use `useState`, not `useRef`** for the host element. A `ref` mutation doesn't trigger the re-render needed to mount `<GraphCanvas>` after the div is in the DOM, so the canvas never appears.
82
- - **The host div must have a non-zero size.** `GraphCanvas` fills its `container`; if the div is `0×0` (e.g. no height, or `display: inline`), you get a blank canvas. Size it explicitly (`style={{ width: "100%", height: 600 }}`) or wrap it in a sized parent.
83
-
84
- ### 5. Run it
85
-
86
- ```bash
87
- npm run dev
88
- ```
89
-
90
- You should see two labelled nodes connected by a `KNOWS` edge. If the canvas is blank, check **Common pitfalls** below — 9 times out of 10 it's the data shape or the missing CSS import.
44
+ That is the whole setup. `GraphCanvas` creates its own host `div` at
45
+ `100% × 100%`, so the size comes from the parent — give that parent a height or
46
+ you get a blank canvas. `forceLayout` starts the simulation; `caption` turns on
47
+ labels and picks the property itself (`name`, then `label`, `title`, `id`).
91
48
 
92
- ---
93
-
94
- ## Peer dependencies
49
+ ## Data shape
95
50
 
96
- | Package | Required range | Notes |
97
- | --- | --- | --- |
98
- | `react` | `^18.0.0` | React 18 only. |
99
- | `react-dom` | `^18.0.0` | |
100
- | `three` | `~0.121.0` | **Strict.** r122+ breaks engine internals. |
101
-
102
- Install three at exactly r121.x:
103
- ```bash
104
- npm install three@~0.121.0
105
- ```
106
-
107
- ## Data shape (REQUIRED — read before writing your data)
108
-
109
- `@kineviz/gl` is strict about the shape of nodes and edges. Missing `id`, missing `properties`, or using the wrong field name for the edge label results in silent rendering failure (8 nodes loaded, 0 visible).
51
+ The engine is strict here, and a wrong shape fails by rendering **nothing**
52
+ rather than by throwing. Worth getting right first.
110
53
 
111
54
  ```ts
112
55
  interface NodeData {
113
56
  id: string;
114
- category: string;
115
- properties: Record<string, string | number | boolean | null>; // REQUIRED, even if empty
57
+ category: string; // required — the node's type
58
+ properties: Record<string, string | number | boolean | null>; // required, {} is fine
116
59
  labels?: string[];
117
60
  tags?: string[];
118
61
  }
119
62
 
120
63
  interface EdgeData {
121
- id: string; // REQUIRED — unique edge ID
122
- source: string; // node id
123
- target: string; // node id
124
- relationship: string; // NOT `category` — edges use `relationship`
125
- properties: Record<string, string | number | boolean | null>; // REQUIRED, even if empty
64
+ id: string;
65
+ source: string; // a node id
66
+ target: string; // a node id
67
+ relationship: string; // required — NOT `category`
68
+ properties: Record<string, string | number | boolean | null>; // required, {} is fine
126
69
  }
127
70
  ```
128
71
 
129
- ## How `GraphCanvas` mounts and sizes itself
130
-
131
- `GraphCanvas` renders into the DOM element you pass as **`container`** — your app owns that node and its styling. The engine fills the container, so the container's size *is* the canvas size. Give it a real, non-zero size (a fixed `height`, or a sized parent like `<div style={{ width: "100vw", height: "100vh" }}>`).
72
+ The three that catch everyone: `properties` is **not** optional, edges use
73
+ `relationship` rather than `category`, and every edge needs its own `id`.
132
74
 
133
- With `data` set and no custom children, `GraphCanvas` defaults the node and edge cloud renderers to on, so the [Getting started](#getting-started-from-zero) example is the whole API surface for a basic render.
134
-
135
- ## Common pitfalls
75
+ ## The props you will actually use
136
76
 
137
- - **Bad data shape = silent blank canvas.** Missing `id` on edges, missing `properties: {}` on either, or naming the edge label `category` instead of `relationship` all produce a black canvas with toolbar visible and no rendered nodes. The store accepts the data; the render pipeline rejects it. See "Data shape" above.
138
- - **Captions are off by default.** If you want node labels, pass `caption={{ visible: true, property: "name", position: "bottom" }}` (or whichever property you populated in `properties`).
139
- - **CSS import is required.** Without `import "@kineviz/gl/dist/index.css"`, the toolbar overlaps content and node-selection rings disappear.
140
- - **`container` div must have non-zero size.** `GraphCanvas` fills the element you pass as `container`. If that element is `0×0` (no height, `display: inline`, or no sizing context), the canvas is `0×0` and stays blank. Size the host div explicitly (`style={{ width: "100%", height: 600 }}`) or wrap it in a sized parent.
141
- - **Bind the container with `useState`, not `useRef`.** A `ref` mutation doesn't re-render, so `<GraphCanvas>` never mounts and nothing draws. See [Getting started](#getting-started-from-zero) step 4.
142
- - **Map/geo examples need `forceLayout` (or another layout source).** Otherwise nodes pile at the origin.
143
- - **Three.js must be r121.x.** Newer versions silently break edge/arrow rendering due to internal API drift.
77
+ Every subsystem toggle takes `true` for defaults or an object to configure, so
78
+ you can start with the bare word and refine later.
144
79
 
145
- ## More on the `container` prop
80
+ | Prop | What it does |
81
+ | --- | --- |
82
+ | `data` | `{ nodes, edges }`. Sets the whole graph. |
83
+ | `forceLayout` | Force-directed simulation. `true`, or `{ charge, gravity, linkDistance, … }`. |
84
+ | `caption` | Node labels. `true`, or `{ property, position, maxLength, scale }`. |
85
+ | `edgeCaption` | Edge labels, same shape. |
86
+ | `node` / `edge` | Appearance: `{ shape, defaultSize, defaultColor, nodeScale }`, `{ lineWidth, … }`. |
87
+ | `is3D` | `true` (default) or `false` for a flat, rotation-locked view. |
88
+ | `theme` | `"dark"` (default), `"light"`, `"midnight"`, `"forest"`, `"warm"`, or a config object. |
89
+ | `map` | Put the graph on a tiled world map. `true`, or `{ provider, geoLayout, … }`. |
90
+ | `selection` / `onSelectionChange` | Controlled selection, or just observe it. |
91
+ | `apiRef` / `onReady` | Reach the imperative API (below). |
92
+ | `pixelRatio` | The single biggest frame-cost knob on high-DPI screens. |
146
93
 
147
- The [Getting started](#getting-started-from-zero) example shows the standard pattern: create a host `<div>`, capture its element with `useState`, and pass it as `container`. Notes:
94
+ Pass children and the default node/edge renderers switch off, so you can compose
95
+ your own layers. To keep both, opt in explicitly:
148
96
 
149
- - **Type:** `container?: HTMLElement | null`. Pass the resolved element, not a ref object.
150
- - **`style` / `className` are ignored when `container` is set.** Your container element owns its styling (the props emit a dev-mode `console.warn` if you pass them anyway). Style the host `<div>` directly instead.
151
- - **`useState`, not `useRef`** — a ref mutation doesn't trigger the parent re-render that mounts `<GraphCanvas>` once the host div is in the DOM.
152
- - **Non-React / custom shells:** because `container` takes any `HTMLElement`, you can hand it a node managed outside React (a custom layout, a different library's mount point) — render `<GraphCanvas container={el} … />` once that element exists.
97
+ ```tsx
98
+ <GraphCanvas data={data} forceLayout node edge>
99
+ <MyOverlayLayer />
100
+ </GraphCanvas>
101
+ ```
153
102
 
154
- ## Custom children (advanced)
103
+ ### Using your own container
155
104
 
156
- Passing children to `<GraphCanvas>` switches off the default node/edge cloud renderers (so you can compose your own `<TextLayer>`, custom decorations, etc.):
105
+ `container` takes any `HTMLElement`, which is how you mount into a node React
106
+ does not own. When you pass it, you own the styling too — `className` and
107
+ `style` are ignored. Bind it with `useState`, not `useRef`: a ref mutation does
108
+ not re-render, so the canvas would never mount.
157
109
 
158
110
  ```tsx
159
- <GraphCanvas data={{ nodes, edges }} forceLayout>
160
- <MyCustomDecorationLayer />
161
- </GraphCanvas>
111
+ const [host, setHost] = useState<HTMLDivElement | null>(null);
112
+
113
+ return (
114
+ <div ref={setHost} style={{ width: "100%", height: 600 }}>
115
+ {host && <GraphCanvas container={host} data={data} forceLayout />}
116
+ </div>
117
+ );
162
118
  ```
163
119
 
164
- To use children AND keep default rendering, opt in explicitly:
120
+ ## The imperative API
121
+
122
+ Everything the component does declaratively is also a method. One object, 30-odd
123
+ namespaces, same rule throughout: **reads are synchronous, writes return a
124
+ promise** that resolves once the change is on a frame.
165
125
 
166
126
  ```tsx
167
- <GraphCanvas data={{ nodes, edges }} forceLayout nodeCloud edgeCloud>
168
- <MyOverlay />
169
- </GraphCanvas>
127
+ import { GraphCanvas } from "@kineviz/gl";
128
+ import type { RenderEngineApi } from "@kineviz/gl";
129
+
130
+ function Graph() {
131
+ const api = useRef<RenderEngineApi | null>(null);
132
+
133
+ return (
134
+ <GraphCanvas
135
+ data={data}
136
+ forceLayout
137
+ apiRef={api}
138
+ onReady={({ api }) => {
139
+ api.events.on("selection:changed", ({ nodeIds, source }) => {
140
+ // `source` is "user" for a click, "api" for a programmatic change
141
+ });
142
+ }}
143
+ />
144
+ );
145
+ }
170
146
  ```
171
147
 
172
- ## Optional: ontology
148
+ ```ts
149
+ // read, synchronously
150
+ api.store.nodeCount;
151
+ api.nodes.get("a");
152
+ api.nodes.where((n) => n.category === "Person");
153
+
154
+ // write, awaited
155
+ await api.nodes.add([{ category: "Person", properties: { name: "Carol" } }]);
156
+ await api.style.setCategoryColor("Person", "#4363d8");
157
+ await api.style.sizeNodesByProperty("score", { minSize: 8, maxSize: 40 });
158
+ await api.layout.sphere();
159
+ await api.camera.flyToNodes(["a"]);
160
+ api.selection.selectNodes(["a", "b"]); // "replace" | "add" | "toggle"
161
+
162
+ // group writes
163
+ await api.history.transaction("import", async () => { /* one undo step */ });
164
+ api.store.batch(() => { /* one notification, one redraw */ });
165
+ await api.history.undo();
166
+ ```
173
167
 
174
- If your app uses Kineviz ontologies, also install `@kineviz/ontology`:
168
+ `id` is optional on `add` and generated when you leave it out. `api.events.on`
169
+ returns its own unsubscribe function, so the React idiom is a one-liner:
175
170
 
176
- ```bash
177
- npm install @kineviz/ontology
171
+ ```ts
172
+ useEffect(() => api.events.on("selection:changed", handler), [api]);
178
173
  ```
179
174
 
175
+ The engine core does not need React or a DOM at all — construct `GraphStore`
176
+ and `RenderEngineApi` directly to build, lay out and query a graph headlessly.
177
+ See the [headless quick start](https://gl.kineviz.com/dev/getting-started).
178
+
179
+ ## Force layout
180
+
181
+ Two backends. The default is the CPU one, deliberately:
182
+
180
183
  ```tsx
181
- import { GraphCanvas, useGraphStore } from "@kineviz/gl";
182
- import { OntologyRegistry } from "@kineviz/ontology";
183
- import medicalOntology from "./medical-ontology.json";
184
-
185
- function App() {
186
- const store = useGraphStore();
187
- useEffect(() => {
188
- const registry = new OntologyRegistry();
189
- registry.loadDeclared(medicalOntology);
190
- store.setOntologyRegistry(registry);
191
- }, [store]);
192
- return <GraphCanvas data={{ nodes, edges }} forceLayout />;
193
- }
184
+ <GraphCanvas data={data} forceLayout /> {/* d3-force-3d */}
185
+ <GraphCanvas data={data} forceLayout={{ engine: "webgpu" }} /> {/* WebGPU compute */}
186
+ <GraphCanvas data={data} forceLayout={{ engine: "auto" }} /> {/* WebGPU if available */}
194
187
  ```
195
188
 
196
- Without ontology, `store.ontology` returns `null` and the engine renders raw category/relationship strings.
189
+ `"d3"` is the default on every machine, including ones with WebGPU. The two
190
+ backends do not converge on the same layout, so a default that followed the
191
+ browser's capabilities made the same data settle into two different shapes —
192
+ a screenshot from one machine did not match another. Reach for `"webgpu"` when
193
+ the **node count** is the problem, somewhere north of 5 000 nodes; it is safe to
194
+ request unconditionally, falling back to `"d3"` with a dev-mode warning where
195
+ it is unavailable. The WebGPU code is fetched on demand, so asking for it costs
196
+ nothing until you do.
197
+
198
+ Tuning fields are shared across backends: `charge`, `gravity`, `linkDistance`,
199
+ `linkStrength`, `collision`, `alpha`, `alphaDecay`, `friction`.
200
+
201
+ ## Entry points
202
+
203
+ | Import | Contains |
204
+ | --- | --- |
205
+ | `@kineviz/gl` | the component, the API, the types, the layers |
206
+ | `@kineviz/gl/dist/index.css` | **required** stylesheet |
207
+ | `@kineviz/gl/schemas` | machine-readable schemas for every API method — for command palettes, tool bars and agent integrations |
208
+ | `@kineviz/gl/layout-gpu` | the GPU layout controller classes, for driving a simulation yourself |
209
+ | `dist/kineviz-gl.umd.js` | script-tag build; **bundles its own `three`**, so do not mix it with an app that loads `three` |
210
+
211
+ ESM-first with a CJS fallback, built for the browser. No Node builtins.
212
+
213
+ ## Peer dependencies
214
+
215
+ | Package | Range | Notes |
216
+ | --- | --- | --- |
217
+ | `three` | `~0.184.0` | Bounded on both sides. The engine calls r184 APIs. |
218
+ | `react` | `^18.0.0` | |
219
+ | `react-dom` | `^18.0.0` | |
220
+
221
+ ## Download size
222
+
223
+ | What | gzip |
224
+ | --- | --- |
225
+ | `@kineviz/gl`, everything needed to render | 385 KiB |
226
+ | the WebGPU layout chunk, fetched on demand | 28 KiB |
227
+ | `dist/index.css` | 5 KiB |
228
+
229
+ Tree-shaking buys around 14%, not 80% — `GraphCanvas` transitively needs the
230
+ projection, the layout engine, the picking layer and the built-in panels. Plan
231
+ for the full figure, and if first paint matters, load the engine behind a
232
+ dynamic `import()` after the page is interactive.
233
+
234
+ ## Browser support
235
+
236
+ A WebGL2 context is required. The WebGPU paths — the layout backend and the
237
+ experimental render path — additionally need `navigator.gpu`, and degrade to
238
+ WebGL rather than failing when it is absent.
239
+
240
+ ## Common pitfalls
241
+
242
+ - **Blank canvas, toolbar visible.** Almost always the data shape: a missing
243
+ `properties: {}`, an edge without an `id`, or `category` where
244
+ `relationship` belongs. The store accepts it; the render pipeline does not.
245
+ - **Blank canvas, nothing visible.** The parent has no height. `GraphCanvas`
246
+ fills its host, and a `0 × 0` host renders a `0 × 0` canvas.
247
+ - **No labels.** `caption` is off unless you pass it.
248
+ - **Unstyled toolbar, missing selection rings.** The CSS import is missing.
249
+ - **Nodes piled at the origin.** No layout source — pass `forceLayout`, or call
250
+ one of the `api.layout.*` presets.
251
+ - **Cached indices stop matching after a delete.** Deletes reorder the
252
+ collections, which is what makes them cheap. Re-resolve by `id`.
197
253
 
198
254
  ## Changelog
199
255
 
200
- Release notes for every version live in [`CHANGELOG.md`](./CHANGELOG.md) (shipped
201
- in the package tarball, so it's also at `node_modules/@kineviz/gl/CHANGELOG.md`).
256
+ `CHANGELOG.md` ships in the package, so the release notes for the version you
257
+ installed are always at `node_modules/@kineviz/gl/CHANGELOG.md`.
202
258
 
203
259
  ## License
204
260
 
205
- Commercial — see `LICENSE-COMMERCIAL.txt`.
261
+ Apache-2.0 — see `LICENSE`, and `NOTICE` for the third-party attributions the
262
+ bundles carry. The source repository is not published; the npm package is the
263
+ distribution. Licensing enquiries: licensing@kineviz.com