@kineviz/gl 0.3.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 +165 -0
- package/dist/index.css +1298 -0
- package/dist/index.css.map +1 -0
- package/dist/index.d.mts +17581 -0
- package/dist/index.d.ts +17581 -0
- package/dist/index.js +55769 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +55526 -0
- package/dist/index.mjs.map +1 -0
- package/dist/kineviz-gl.css +1297 -0
- package/dist/kineviz-gl.umd.js +91912 -0
- package/package.json +54 -0
package/README.md
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
# @kineviz/gl
|
|
2
|
+
|
|
3
|
+
WebGL 3D graph visualization engine for React.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Tarball delivery (P1):
|
|
9
|
+
npm install ./vendor/kineviz-gl-0.2.0.tgz
|
|
10
|
+
|
|
11
|
+
# Or pin in package.json:
|
|
12
|
+
{
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@kineviz/gl": "file:./vendor/kineviz-gl-0.2.0.tgz"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Peer dependencies
|
|
20
|
+
|
|
21
|
+
| Package | Required range | Notes |
|
|
22
|
+
| --- | --- | --- |
|
|
23
|
+
| `react` | `^18.0.0` | React 18 only. |
|
|
24
|
+
| `react-dom` | `^18.0.0` | |
|
|
25
|
+
| `three` | `~0.121.0` | **Strict.** r122+ breaks engine internals. |
|
|
26
|
+
|
|
27
|
+
Install three at exactly r121.x:
|
|
28
|
+
```bash
|
|
29
|
+
npm install three@~0.121.0
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Data shape (REQUIRED — read before writing your data)
|
|
33
|
+
|
|
34
|
+
`@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).
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
interface NodeData {
|
|
38
|
+
id: string;
|
|
39
|
+
category: string;
|
|
40
|
+
properties: Record<string, string | number | boolean | null>; // REQUIRED, even if empty
|
|
41
|
+
labels?: string[];
|
|
42
|
+
tags?: string[];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
interface EdgeData {
|
|
46
|
+
id: string; // REQUIRED — unique edge ID
|
|
47
|
+
source: string; // node id
|
|
48
|
+
target: string; // node id
|
|
49
|
+
relationship: string; // NOT `category` — edges use `relationship`
|
|
50
|
+
properties: Record<string, string | number | boolean | null>; // REQUIRED, even if empty
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Quick start
|
|
55
|
+
|
|
56
|
+
```tsx
|
|
57
|
+
import { GraphCanvas } from "@kineviz/gl";
|
|
58
|
+
import "@kineviz/gl/dist/index.css"; // required
|
|
59
|
+
|
|
60
|
+
const nodes = [
|
|
61
|
+
{ id: "a", category: "Person", properties: { name: "Alice" } },
|
|
62
|
+
{ id: "b", category: "Person", properties: { name: "Bob" } },
|
|
63
|
+
];
|
|
64
|
+
const edges = [
|
|
65
|
+
{ id: "e1", source: "a", target: "b", relationship: "KNOWS", properties: {} },
|
|
66
|
+
];
|
|
67
|
+
|
|
68
|
+
export default function App() {
|
|
69
|
+
return (
|
|
70
|
+
<GraphCanvas
|
|
71
|
+
data={{ nodes, edges }}
|
|
72
|
+
forceLayout
|
|
73
|
+
caption={{ visible: true, position: "bottom", property: "name", maxLength: 20 }}
|
|
74
|
+
style={{ width: "100%", height: 600 }}
|
|
75
|
+
/>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
That's it. `GraphCanvas` auto-creates its own host div, defaults the node and edge renderers to on, and forwards `style` / `className` to the host. The parent's sizing context determines the canvas size — use a fixed `style` (above), or wrap in a sized parent (`<div style={{ width: "100vw", height: "100vh" }}>`).
|
|
81
|
+
|
|
82
|
+
## Common pitfalls
|
|
83
|
+
|
|
84
|
+
- **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.
|
|
85
|
+
- **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`).
|
|
86
|
+
- **CSS import is required.** Without `import "@kineviz/gl/dist/index.css"`, the toolbar overlaps content and node-selection rings disappear.
|
|
87
|
+
- **Parent must have non-zero size.** GraphCanvas's auto-host div defaults to `width: 100%, height: 100%`. If the parent has `display: inline` or no sizing context, the canvas is 0×0. Pass `style` to size the host explicitly, or wrap in a sized parent.
|
|
88
|
+
- **Map/geo examples need `forceLayout` (or another layout source).** Otherwise nodes pile at the origin.
|
|
89
|
+
- **Three.js must be r121.x.** Newer versions silently break edge/arrow rendering due to internal API drift.
|
|
90
|
+
|
|
91
|
+
## Advanced: external container
|
|
92
|
+
|
|
93
|
+
If your app already manages the host DOM (custom layout, non-React shell, integration with another library), pass `container` and own the styling:
|
|
94
|
+
|
|
95
|
+
```tsx
|
|
96
|
+
import { useState } from "react";
|
|
97
|
+
import { GraphCanvas } from "@kineviz/gl";
|
|
98
|
+
import "@kineviz/gl/dist/index.css";
|
|
99
|
+
|
|
100
|
+
export default function App() {
|
|
101
|
+
const [container, setContainer] = useState<HTMLDivElement | null>(null);
|
|
102
|
+
|
|
103
|
+
return (
|
|
104
|
+
<div ref={setContainer} style={{ width: "100%", height: 600 }}>
|
|
105
|
+
{container && (
|
|
106
|
+
<GraphCanvas
|
|
107
|
+
container={container}
|
|
108
|
+
data={{ nodes, edges }}
|
|
109
|
+
forceLayout
|
|
110
|
+
/>
|
|
111
|
+
)}
|
|
112
|
+
</div>
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
When `container` is provided, `style` and `className` props on `<GraphCanvas>` are ignored (with a dev-mode `console.warn`). Use `useState`, not `useRef` — a ref doesn't trigger the parent re-render needed to mount `<GraphCanvas>` once the host div is in the DOM.
|
|
118
|
+
|
|
119
|
+
## Custom children (advanced)
|
|
120
|
+
|
|
121
|
+
Passing children to `<GraphCanvas>` switches off the default node/edge cloud renderers (so you can compose your own `<TextLayer>`, custom decorations, etc.):
|
|
122
|
+
|
|
123
|
+
```tsx
|
|
124
|
+
<GraphCanvas data={{ nodes, edges }} forceLayout>
|
|
125
|
+
<MyCustomDecorationLayer />
|
|
126
|
+
</GraphCanvas>
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
To use children AND keep default rendering, opt in explicitly:
|
|
130
|
+
|
|
131
|
+
```tsx
|
|
132
|
+
<GraphCanvas data={{ nodes, edges }} forceLayout nodeCloud edgeCloud>
|
|
133
|
+
<MyOverlay />
|
|
134
|
+
</GraphCanvas>
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Optional: ontology
|
|
138
|
+
|
|
139
|
+
If your app uses Kineviz ontologies, also install `@kineviz/ontology`:
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
npm install @kineviz/ontology
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
```tsx
|
|
146
|
+
import { GraphCanvas, useGraphStore } from "@kineviz/gl";
|
|
147
|
+
import { OntologyRegistry } from "@kineviz/ontology";
|
|
148
|
+
import medicalOntology from "./medical-ontology.json";
|
|
149
|
+
|
|
150
|
+
function App() {
|
|
151
|
+
const store = useGraphStore();
|
|
152
|
+
useEffect(() => {
|
|
153
|
+
const registry = new OntologyRegistry();
|
|
154
|
+
registry.loadDeclared(medicalOntology);
|
|
155
|
+
store.setOntologyRegistry(registry);
|
|
156
|
+
}, [store]);
|
|
157
|
+
return <GraphCanvas data={{ nodes, edges }} forceLayout />;
|
|
158
|
+
}
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Without ontology, `store.ontology` returns `null` and the engine renders raw category/relationship strings.
|
|
162
|
+
|
|
163
|
+
## License
|
|
164
|
+
|
|
165
|
+
Commercial — see `LICENSE-COMMERCIAL.txt`.
|