@opendata-ai/openchart-react 8.4.1 → 8.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 +65 -0
- package/dist/graph-3d.d.ts +1 -0
- package/dist/graph-3d.js +3 -0
- package/dist/graph-3d.js.map +1 -0
- package/dist/index.d.ts +4 -22
- package/dist/index.js +6 -7
- package/dist/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/styles.css.map +1 -1
- package/package.json +8 -4
package/README.md
CHANGED
|
@@ -55,6 +55,71 @@ function RenderSpec({ spec }: { spec: VizSpec }) {
|
|
|
55
55
|
|
|
56
56
|
If you need event handlers or component-specific props, use the specific component directly instead.
|
|
57
57
|
|
|
58
|
+
## 3D graphs
|
|
59
|
+
|
|
60
|
+
`dimensions: 3` on a graph spec renders with WebGL instead of canvas. The 3D
|
|
61
|
+
renderer ships on its own subpath so three.js never lands in the default bundle,
|
|
62
|
+
and its libraries are optional peers you install yourself:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
npm install three 3d-force-graph three-spritetext
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
The subpath registers the renderer as an import side effect, so it has to be
|
|
69
|
+
imported before the graph mounts. Every framework package ships its own mirror
|
|
70
|
+
of it (`@opendata-ai/openchart-vue/graph-3d`,
|
|
71
|
+
`@opendata-ai/openchart-svelte/graph-3d`), so you never reach past the package
|
|
72
|
+
you depend on; everything else is identical.
|
|
73
|
+
|
|
74
|
+
```tsx
|
|
75
|
+
import { Graph } from '@opendata-ai/openchart-react';
|
|
76
|
+
|
|
77
|
+
function Graph3D({ spec }) {
|
|
78
|
+
const [ready, setReady] = useState(false);
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
import('@opendata-ai/openchart-react/graph-3d').then(() => setReady(true));
|
|
81
|
+
}, []);
|
|
82
|
+
|
|
83
|
+
if (!ready) return <Spinner />;
|
|
84
|
+
return <Graph spec={{ ...spec, dimensions: 3 }} />;
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
The subpath import is required only when compilation actually resolves to 3D.
|
|
89
|
+
A spec above the 2000-node gate warns and falls back to 2D, so it renders
|
|
90
|
+
without the import; a `dimensions: 3` spec that stays 3D throws without it.
|
|
91
|
+
|
|
92
|
+
Notes:
|
|
93
|
+
|
|
94
|
+
- **SSR**: `3d-force-graph` touches `window` at import time. Import the subpath
|
|
95
|
+
client-side only (inside `useEffect`, a dynamic `import()`, or a browser-only
|
|
96
|
+
module) and render your own placeholder until it resolves.
|
|
97
|
+
- **One copy of three**: run `npm ls three` (or `bun pm ls three`) and confirm a
|
|
98
|
+
single copy. Two copies fail at runtime with `Cannot read properties of
|
|
99
|
+
undefined (reading 'VERTEX')` (vasturiano/react-force-graph#595).
|
|
100
|
+
|
|
101
|
+
Differences from 2D:
|
|
102
|
+
|
|
103
|
+
- Labels use a fixed budget re-ranked by camera distance, so distant labels drop
|
|
104
|
+
out instead of being decluttered by priority.
|
|
105
|
+
- The force simulation runs on the main thread. Above 2000 nodes the spec warns
|
|
106
|
+
and renders in 2D.
|
|
107
|
+
- Keyboard navigation, SVG export, `interaction.cursorRepulsion`, and
|
|
108
|
+
`interaction.springyDrag` are unsupported. Each warns and is ignored.
|
|
109
|
+
(`layout.type` of `radial` or `hierarchical` is rejected by spec validation in
|
|
110
|
+
both dimensions, so it never reaches either renderer.)
|
|
111
|
+
- `getCamera()` returns a pose, not a zoom transform: `x`/`y` are the look-at
|
|
112
|
+
point in world units, alongside `position` and `target`. In 2D they are the
|
|
113
|
+
zoom transform's translate in pixels. `onCameraChange` carries the same
|
|
114
|
+
payload, so persisted camera state has to be keyed on the dimension it came
|
|
115
|
+
from. Both are typed `GraphCamera`, whose `position`/`target` are optional
|
|
116
|
+
because only 3D sets them; `flyTo` accepts them back, and 2D ignores them.
|
|
117
|
+
- A structural `update()` reheats the whole layout, so settled nodes drift. 2D
|
|
118
|
+
applies a local impulse instead.
|
|
119
|
+
- `nodeOverrides[*].stroke` and `strokeWidth` are ignored (no ring).
|
|
120
|
+
- A dimension change is a remount, not an `update()`. The framework wrappers do
|
|
121
|
+
this for you; `update()` with a changed `dimensions` warns and no-ops.
|
|
122
|
+
|
|
58
123
|
## Dark mode and theming
|
|
59
124
|
|
|
60
125
|
Wrap your app (or a subtree) with `VizThemeProvider` to set theme and dark mode for all child visualizations. All `Chart`, `DataTable`, and `Graph` components inside the provider inherit its values.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@opendata-ai/openchart-vanilla/graph-3d';
|
package/dist/graph-3d.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/graph-3d.ts"],"sourcesContent":["/**\n * React subpath for the 3D graph renderer.\n *\n * Importing this module registers the WebGL renderer with the vanilla graph\n * registry, so a `<Graph />` whose spec sets `dimensions: 3` can mount. It is a\n * side-effect import: there is nothing React-specific here beyond the\n * re-export, and it exists so React hosts never have to reach past\n * `@opendata-ai/openchart-react` for a peer.\n *\n * Import it client-side only (three.js touches `window` at module scope):\n *\n * ```ts\n * useEffect(() => {\n * import('@opendata-ai/openchart-react/graph-3d');\n * }, []);\n * ```\n */\n\nexport * from '@opendata-ai/openchart-vanilla/graph-3d';\n"],"mappings":";AAkBA,cAAc;","names":[]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BarListSpec, ThemeConfig, DarkMode, DataRow, ChartEventHandlers, ChartSpec, LayerSpec, GraphSpec, ElementRef, GeoMapSpec, TableSpec, SortState, ChartLayout, SankeySpec, TileMapSpec, VizSpec } from '@opendata-ai/openchart-core';
|
|
2
2
|
export * from '@opendata-ai/openchart-core';
|
|
3
|
-
import { BarListInstance, ChartInstance, MountOptions, GeoMapMarkEvent, GeoMapInstance, CameraFlightOptions, GraphHighlightTarget, GraphLegendData, GraphInstance, GraphTooltipFormatter, TableInstance, TableState, TableMountOptions, SankeyInstance, TileMapInstance } from '@opendata-ai/openchart-vanilla';
|
|
3
|
+
import { BarListInstance, ChartInstance, MountOptions, GeoMapMarkEvent, GeoMapInstance, CameraFlightOptions, GraphFlyTarget, GraphCamera, GraphHighlightTarget, GraphLegendData, GraphInstance, GraphTooltipFormatter, TableInstance, TableState, TableMountOptions, SankeyInstance, TileMapInstance } from '@opendata-ai/openchart-vanilla';
|
|
4
4
|
export { JPGExportOptions, PNGExportOptions, SVGExportOptions, SpecSequenceOptions, exportCSV, exportJPG, exportPNG, exportSVG, exportSVGWithFonts, exportSpecSequence } from '@opendata-ai/openchart-vanilla';
|
|
5
5
|
export { ChartRenderer, CompileResult, CompiledGraphEdge, CompiledGraphNode, GraphCompilation, NormalizedBarListSpec, NormalizedChartSpec, NormalizedChrome, NormalizedGeoMapSpec, NormalizedGraphSpec, NormalizedSankeySpec, NormalizedSpec, NormalizedTableSpec, NormalizedTileMapSpec, SimulationConfig, ValidationError, ValidationErrorCode, ValidationResult, clearRenderers, compile, compileBarList, compileChart, compileGeoMap, compileGraph, compileSankey, compileTable, compileTileMap, getChartRenderer, normalizeSpec, registerChartRenderer, validateSpec } from '@opendata-ai/openchart-engine';
|
|
6
6
|
import * as react from 'react';
|
|
@@ -187,12 +187,6 @@ declare const GeoMap: react.ForwardRefExoticComponent<GeoMapProps & react.RefAtt
|
|
|
187
187
|
* graph instance. The full vanilla GraphInstance API is threaded through.
|
|
188
188
|
*/
|
|
189
189
|
|
|
190
|
-
/** Camera transform components (graph-space). */
|
|
191
|
-
type GraphCamera = {
|
|
192
|
-
x: number;
|
|
193
|
-
y: number;
|
|
194
|
-
k: number;
|
|
195
|
-
};
|
|
196
190
|
interface UseGraphReturn {
|
|
197
191
|
/** Ref to pass to <Graph ref={ref} />. */
|
|
198
192
|
ref: React.RefObject<GraphHandle | null>;
|
|
@@ -211,11 +205,7 @@ interface UseGraphReturn {
|
|
|
211
205
|
scale?: number;
|
|
212
206
|
}) => void;
|
|
213
207
|
/** Fly the camera to a graph-space target. */
|
|
214
|
-
flyTo: (target:
|
|
215
|
-
x: number;
|
|
216
|
-
y: number;
|
|
217
|
-
k?: number;
|
|
218
|
-
}, opts?: CameraFlightOptions) => void;
|
|
208
|
+
flyTo: (target: GraphFlyTarget, opts?: CameraFlightOptions) => void;
|
|
219
209
|
/** Center the camera on a graph-space point (keeps current zoom). */
|
|
220
210
|
centerAt: (x: number, y: number, opts?: CameraFlightOptions) => void;
|
|
221
211
|
/** Current camera transform. */
|
|
@@ -258,11 +248,7 @@ interface GraphHandle {
|
|
|
258
248
|
zoomToNode: (nodeId: string, opts?: CameraFlightOptions & {
|
|
259
249
|
scale?: number;
|
|
260
250
|
}) => void;
|
|
261
|
-
flyTo: (target:
|
|
262
|
-
x: number;
|
|
263
|
-
y: number;
|
|
264
|
-
k?: number;
|
|
265
|
-
}, opts?: CameraFlightOptions) => void;
|
|
251
|
+
flyTo: (target: GraphFlyTarget, opts?: CameraFlightOptions) => void;
|
|
266
252
|
centerAt: (x: number, y: number, opts?: CameraFlightOptions) => void;
|
|
267
253
|
getCamera: () => GraphCamera;
|
|
268
254
|
selectNode: (nodeId: string, opts?: {
|
|
@@ -329,11 +315,7 @@ interface GraphProps {
|
|
|
329
315
|
/** Fired whenever the highlight set changes (programmatic or legend), null when cleared. */
|
|
330
316
|
onHighlightChange?: (nodeIds: string[] | null) => void;
|
|
331
317
|
/** Camera change callback, rAF-coalesced (fires at most once per rendered frame). */
|
|
332
|
-
onCameraChange?: (camera:
|
|
333
|
-
x: number;
|
|
334
|
-
y: number;
|
|
335
|
-
k: number;
|
|
336
|
-
}) => void;
|
|
318
|
+
onCameraChange?: (camera: GraphCamera) => void;
|
|
337
319
|
/**
|
|
338
320
|
* Show built-in tooltip on node/edge hover. Defaults to true. Pass an object
|
|
339
321
|
* with a `formatter` to customize content.
|
package/dist/index.js
CHANGED
|
@@ -773,6 +773,7 @@ var Graph = forwardRef4(function Graph2({
|
|
|
773
773
|
);
|
|
774
774
|
const tooltipOn = tooltipStructural(tooltip);
|
|
775
775
|
const legendKey = legendStructural(legend);
|
|
776
|
+
const dimensions = spec.dimensions ?? 2;
|
|
776
777
|
useEffect6(() => {
|
|
777
778
|
const container = containerRef.current;
|
|
778
779
|
if (!container) return;
|
|
@@ -820,7 +821,8 @@ var Graph = forwardRef4(function Graph2({
|
|
|
820
821
|
stableOnLegendToggle,
|
|
821
822
|
stableOnHighlightChange,
|
|
822
823
|
stableOnCameraChange,
|
|
823
|
-
stableTooltipFormatter
|
|
824
|
+
stableTooltipFormatter,
|
|
825
|
+
dimensions
|
|
824
826
|
]);
|
|
825
827
|
useEffect6(() => {
|
|
826
828
|
const graph = graphRef.current;
|
|
@@ -940,12 +942,9 @@ function useGraph() {
|
|
|
940
942
|
},
|
|
941
943
|
[]
|
|
942
944
|
);
|
|
943
|
-
const flyTo = useCallback6(
|
|
944
|
-
(target, opts)
|
|
945
|
-
|
|
946
|
-
},
|
|
947
|
-
[]
|
|
948
|
-
);
|
|
945
|
+
const flyTo = useCallback6((target, opts) => {
|
|
946
|
+
ref.current?.flyTo(target, opts);
|
|
947
|
+
}, []);
|
|
949
948
|
const centerAt = useCallback6((x, y, opts) => {
|
|
950
949
|
ref.current?.centerAt(x, y, opts);
|
|
951
950
|
}, []);
|