@opendata-ai/openchart-react 8.0.0-rc.2 → 8.0.0-rc.20
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/dist/index.d.ts +118 -24
- package/dist/index.js +165 -36
- package/dist/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/styles.css.map +1 -1
- package/package.json +5 -6
- package/src/BarList.tsx +0 -126
- package/src/Chart.tsx +0 -341
- package/src/ChartStory.tsx +0 -203
- package/src/DataTable.tsx +0 -165
- package/src/Graph.tsx +0 -253
- package/src/Map.tsx +0 -131
- package/src/Sankey.tsx +0 -176
- package/src/ThemeContext.tsx +0 -40
- package/src/TileMap.tsx +0 -165
- package/src/Visualization.tsx +0 -85
- package/src/__tests__/Chart.test.tsx +0 -134
- package/src/__tests__/ChartStory.test.tsx +0 -92
- package/src/__tests__/DataTable.test.tsx +0 -126
- package/src/__tests__/Graph.test.tsx +0 -130
- package/src/__tests__/ThemeContext.test.tsx +0 -238
- package/src/__tests__/hooks.test.tsx +0 -160
- package/src/__tests__/update-vs-remount.test.tsx +0 -133
- package/src/__tests__/useTableState.test.tsx +0 -218
- package/src/hooks/useGraph.ts +0 -87
- package/src/hooks/useTable.ts +0 -98
- package/src/hooks/useTableState.ts +0 -76
- package/src/hooks.ts +0 -154
- package/src/index.ts +0 -104
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import * as _opendata_ai_openchart_core from '@opendata-ai/openchart-core';
|
|
2
1
|
import { BarListSpec, ThemeConfig, DarkMode, DataRow, ChartEventHandlers, ChartSpec, LayerSpec, GraphSpec, ElementRef, MapSpec, TableSpec, SortState, ChartLayout, SankeySpec, TileMapSpec, VizSpec } from '@opendata-ai/openchart-core';
|
|
3
2
|
export * from '@opendata-ai/openchart-core';
|
|
4
|
-
import { BarListInstance, ChartInstance, MountOptions, GraphInstance, TableInstance, TableState, TableMountOptions, MapInstance, SankeyInstance, TileMapInstance } from '@opendata-ai/openchart-vanilla';
|
|
5
|
-
export { JPGExportOptions, PNGExportOptions, SVGExportOptions, exportCSV, exportJPG, exportPNG, exportSVG, exportSVGWithFonts } from '@opendata-ai/openchart-vanilla';
|
|
3
|
+
import { BarListInstance, ChartInstance, MountOptions, CameraFlightOptions, GraphHighlightTarget, GraphLegendData, GraphInstance, GraphTooltipFormatter, TableInstance, TableState, TableMountOptions, MapMarkEvent, MapInstance, SankeyInstance, TileMapInstance } from '@opendata-ai/openchart-vanilla';
|
|
4
|
+
export { JPGExportOptions, PNGExportOptions, SVGExportOptions, SpecSequenceOptions, exportCSV, exportJPG, exportPNG, exportSVG, exportSVGWithFonts, exportSpecSequence } from '@opendata-ai/openchart-vanilla';
|
|
6
5
|
export { ChartRenderer, CompileResult, CompiledGraphEdge, CompiledGraphNode, GraphCompilation, NormalizedBarListSpec, NormalizedChartSpec, NormalizedChrome, NormalizedGraphSpec, NormalizedMapSpec, NormalizedSankeySpec, NormalizedSpec, NormalizedTableSpec, NormalizedTileMapSpec, SimulationConfig, ValidationError, ValidationErrorCode, ValidationResult, clearRenderers, compile, compileBarList, compileChart, compileGraph, compileMap, compileSankey, compileTable, compileTileMap, getChartRenderer, normalizeSpec, registerChartRenderer, validateSpec } from '@opendata-ai/openchart-engine';
|
|
7
6
|
import * as react from 'react';
|
|
8
7
|
import { CSSProperties, ReactNode, Ref } from 'react';
|
|
@@ -153,6 +152,20 @@ interface DataTableProps {
|
|
|
153
152
|
*/
|
|
154
153
|
declare function DataTable({ spec, theme: themeProp, darkMode, onRowClick, onSortChange, onSearchChange, onPageChange, className, style, sort, search, page, }: DataTableProps): react_jsx_runtime.JSX.Element;
|
|
155
154
|
|
|
155
|
+
/**
|
|
156
|
+
* useGraph: hook for imperative graph control.
|
|
157
|
+
*
|
|
158
|
+
* Provides a ref to pass to <Graph /> and exposes graph methods
|
|
159
|
+
* (search, zoom, select, fly, highlight) for programmatic control of the
|
|
160
|
+
* graph instance. The full vanilla GraphInstance API is threaded through.
|
|
161
|
+
*/
|
|
162
|
+
|
|
163
|
+
/** Camera transform components (graph-space). */
|
|
164
|
+
type GraphCamera = {
|
|
165
|
+
x: number;
|
|
166
|
+
y: number;
|
|
167
|
+
k: number;
|
|
168
|
+
};
|
|
156
169
|
interface UseGraphReturn {
|
|
157
170
|
/** Ref to pass to <Graph ref={ref} />. */
|
|
158
171
|
ref: React.RefObject<GraphHandle | null>;
|
|
@@ -160,25 +173,79 @@ interface UseGraphReturn {
|
|
|
160
173
|
search: (query: string) => void;
|
|
161
174
|
/** Clear the current search. */
|
|
162
175
|
clearSearch: () => void;
|
|
163
|
-
/**
|
|
164
|
-
|
|
165
|
-
/** Zoom
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
176
|
+
/** Node ids currently matching the active search query. */
|
|
177
|
+
getSearchMatches: () => string[];
|
|
178
|
+
/** Zoom to fit all nodes in view. Animated by default; `{ duration: 0 }` snaps. */
|
|
179
|
+
zoomToFit: (opts?: CameraFlightOptions & {
|
|
180
|
+
padding?: number;
|
|
181
|
+
}) => void;
|
|
182
|
+
/** Fly to a node and zoom in (default scale 2). */
|
|
183
|
+
zoomToNode: (nodeId: string, opts?: CameraFlightOptions & {
|
|
184
|
+
scale?: number;
|
|
185
|
+
}) => void;
|
|
186
|
+
/** Fly the camera to a graph-space target. */
|
|
187
|
+
flyTo: (target: {
|
|
188
|
+
x: number;
|
|
189
|
+
y: number;
|
|
190
|
+
k?: number;
|
|
191
|
+
}, opts?: CameraFlightOptions) => void;
|
|
192
|
+
/** Center the camera on a graph-space point (keeps current zoom). */
|
|
193
|
+
centerAt: (x: number, y: number, opts?: CameraFlightOptions) => void;
|
|
194
|
+
/** Current camera transform. */
|
|
195
|
+
getCamera: () => GraphCamera;
|
|
196
|
+
/** Select a node by id; `{ fly: true }` also flies to it. */
|
|
197
|
+
selectNode: (nodeId: string, opts?: {
|
|
198
|
+
fly?: boolean;
|
|
199
|
+
} & CameraFlightOptions) => void;
|
|
169
200
|
/** Get the currently selected node ids. */
|
|
170
201
|
getSelectedNodes: () => string[];
|
|
202
|
+
/** Emphasize a set of nodes; eased via the focus model. */
|
|
203
|
+
highlight: (target: GraphHighlightTarget, opts?: {
|
|
204
|
+
dimOpacity?: number;
|
|
205
|
+
}) => void;
|
|
206
|
+
/** Clear any programmatic highlight (and legend toggles). */
|
|
207
|
+
clearHighlight: () => void;
|
|
208
|
+
/** The currently highlighted node ids, or null when nothing is highlighted. */
|
|
209
|
+
getHighlight: () => string[] | null;
|
|
210
|
+
/** Headless snapshot of the legend. */
|
|
211
|
+
getLegend: () => GraphLegendData | null;
|
|
212
|
+
/** Set the active category filter declaratively (replaces legend toggle state). */
|
|
213
|
+
setActiveCategories: (values: string[]) => void;
|
|
214
|
+
/** Current active category values (empty = all active, no filter). */
|
|
215
|
+
getActiveCategories: () => string[];
|
|
171
216
|
}
|
|
172
217
|
/** Handle exposed by Graph component via forwardRef. */
|
|
173
218
|
interface GraphHandle {
|
|
174
219
|
search: (query: string) => void;
|
|
175
220
|
clearSearch: () => void;
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
221
|
+
getSearchMatches: () => string[];
|
|
222
|
+
zoomToFit: (opts?: CameraFlightOptions & {
|
|
223
|
+
padding?: number;
|
|
224
|
+
}) => void;
|
|
225
|
+
zoomToNode: (nodeId: string, opts?: CameraFlightOptions & {
|
|
226
|
+
scale?: number;
|
|
227
|
+
}) => void;
|
|
228
|
+
flyTo: (target: {
|
|
229
|
+
x: number;
|
|
230
|
+
y: number;
|
|
231
|
+
k?: number;
|
|
232
|
+
}, opts?: CameraFlightOptions) => void;
|
|
233
|
+
centerAt: (x: number, y: number, opts?: CameraFlightOptions) => void;
|
|
234
|
+
getCamera: () => GraphCamera;
|
|
235
|
+
selectNode: (nodeId: string, opts?: {
|
|
236
|
+
fly?: boolean;
|
|
237
|
+
} & CameraFlightOptions) => void;
|
|
179
238
|
getSelectedNodes: () => string[];
|
|
239
|
+
highlight: (target: GraphHighlightTarget, opts?: {
|
|
240
|
+
dimOpacity?: number;
|
|
241
|
+
}) => void;
|
|
242
|
+
clearHighlight: () => void;
|
|
243
|
+
getHighlight: () => string[] | null;
|
|
244
|
+
getLegend: () => GraphLegendData | null;
|
|
245
|
+
setActiveCategories: (values: string[]) => void;
|
|
246
|
+
getActiveCategories: () => string[];
|
|
180
247
|
/** Re-compile encoding/legend/chrome without restarting the simulation. */
|
|
181
|
-
updateVisuals: (spec:
|
|
248
|
+
updateVisuals: (spec: GraphSpec) => void;
|
|
182
249
|
/** The underlying GraphInstance from the vanilla adapter. */
|
|
183
250
|
instance: GraphInstance | null;
|
|
184
251
|
}
|
|
@@ -193,6 +260,15 @@ interface GraphHandle {
|
|
|
193
260
|
*/
|
|
194
261
|
declare function useGraph(): UseGraphReturn;
|
|
195
262
|
|
|
263
|
+
/** Tooltip prop: `false` off, `true` default, or an object with a formatter. */
|
|
264
|
+
type GraphTooltipProp = boolean | {
|
|
265
|
+
formatter?: GraphTooltipFormatter;
|
|
266
|
+
};
|
|
267
|
+
/** Legend prop: `false` off, `true` default, or an object toggling interactivity/counts. */
|
|
268
|
+
type GraphLegendProp = boolean | {
|
|
269
|
+
interactive?: boolean;
|
|
270
|
+
counts?: boolean;
|
|
271
|
+
};
|
|
196
272
|
interface GraphProps {
|
|
197
273
|
/** The graph spec to render. */
|
|
198
274
|
spec: GraphSpec;
|
|
@@ -210,10 +286,33 @@ interface GraphProps {
|
|
|
210
286
|
onEdgeHover?: (edge: Record<string, unknown> | null) => void;
|
|
211
287
|
/** Callback when selection changes. */
|
|
212
288
|
onSelectionChange?: (nodeIds: string[]) => void;
|
|
213
|
-
/**
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
289
|
+
/** Fired when the user hovers a legend entry (null on leave). */
|
|
290
|
+
onLegendHover?: (entry: {
|
|
291
|
+
field: string;
|
|
292
|
+
value: string;
|
|
293
|
+
} | null) => void;
|
|
294
|
+
/** Fired when legend toggle state changes; `activeValues` is the active set (empty = all). */
|
|
295
|
+
onLegendToggle?: (activeValues: string[]) => void;
|
|
296
|
+
/** Fired whenever the highlight set changes (programmatic or legend), null when cleared. */
|
|
297
|
+
onHighlightChange?: (nodeIds: string[] | null) => void;
|
|
298
|
+
/** Camera change callback, rAF-coalesced (fires at most once per rendered frame). */
|
|
299
|
+
onCameraChange?: (camera: {
|
|
300
|
+
x: number;
|
|
301
|
+
y: number;
|
|
302
|
+
k: number;
|
|
303
|
+
}) => void;
|
|
304
|
+
/**
|
|
305
|
+
* Show built-in tooltip on node/edge hover. Defaults to true. Pass an object
|
|
306
|
+
* with a `formatter` to customize content.
|
|
307
|
+
*/
|
|
308
|
+
tooltip?: GraphTooltipProp;
|
|
309
|
+
/**
|
|
310
|
+
* Show built-in legend. Defaults to true. Pass `false` if you render your own,
|
|
311
|
+
* or an object to toggle interactivity/counts.
|
|
312
|
+
*/
|
|
313
|
+
legend?: GraphLegendProp;
|
|
314
|
+
/** Fit the graph to the viewport on the first tick. Default true. */
|
|
315
|
+
fitOnLoad?: boolean;
|
|
217
316
|
/** CSS class name for the wrapper div. */
|
|
218
317
|
className?: string;
|
|
219
318
|
/** Inline styles for the wrapper div. */
|
|
@@ -349,11 +448,6 @@ interface UseTableStateOptions {
|
|
|
349
448
|
*/
|
|
350
449
|
declare function useTableState(initialState?: UseTableStateOptions): UseTableStateReturn;
|
|
351
450
|
|
|
352
|
-
type MapFeatureEvent = {
|
|
353
|
-
id: string | number;
|
|
354
|
-
name?: string;
|
|
355
|
-
data: Record<string, unknown> | null;
|
|
356
|
-
};
|
|
357
451
|
interface MapProps {
|
|
358
452
|
/** The map spec to render. */
|
|
359
453
|
spec: MapSpec;
|
|
@@ -362,9 +456,9 @@ interface MapProps {
|
|
|
362
456
|
/** Dark mode: "auto", "force", or "off". */
|
|
363
457
|
darkMode?: DarkMode;
|
|
364
458
|
/** Callback when a map feature is clicked. */
|
|
365
|
-
onMarkClick?: (feature:
|
|
459
|
+
onMarkClick?: (feature: MapMarkEvent) => void;
|
|
366
460
|
/** Callback when a map feature is hovered (null when hover ends). */
|
|
367
|
-
onMarkHover?: (feature:
|
|
461
|
+
onMarkHover?: (feature: MapMarkEvent | null) => void;
|
|
368
462
|
/** CSS class name for the wrapper div. */
|
|
369
463
|
className?: string;
|
|
370
464
|
/** Inline styles for the wrapper div. */
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
exportCSV,
|
|
5
5
|
exportJPG,
|
|
6
6
|
exportPNG,
|
|
7
|
+
exportSpecSequence,
|
|
7
8
|
exportSVG,
|
|
8
9
|
exportSVGWithFonts
|
|
9
10
|
} from "@opendata-ai/openchart-vanilla";
|
|
@@ -141,6 +142,7 @@ function ChartInner({
|
|
|
141
142
|
onDeselect,
|
|
142
143
|
onTextEdit,
|
|
143
144
|
onReveal,
|
|
145
|
+
editable,
|
|
144
146
|
selectedElement: selectedElementProp,
|
|
145
147
|
highlight,
|
|
146
148
|
className,
|
|
@@ -258,6 +260,7 @@ function ChartInner({
|
|
|
258
260
|
...handlersRef.current.onDeselect ? { onDeselect: stableOnDeselect } : {},
|
|
259
261
|
...handlersRef.current.onTextEdit ? { onTextEdit: stableOnTextEdit } : {},
|
|
260
262
|
...handlersRef.current.onReveal ? { onReveal: stableOnReveal } : {},
|
|
263
|
+
...editable != null ? { editable } : {},
|
|
261
264
|
...selectedElementProp ? { selectedElement: selectedElementProp } : {},
|
|
262
265
|
responsive: true
|
|
263
266
|
};
|
|
@@ -270,6 +273,7 @@ function ChartInner({
|
|
|
270
273
|
}, [
|
|
271
274
|
theme,
|
|
272
275
|
resolvedDarkMode,
|
|
276
|
+
editable,
|
|
273
277
|
stableOnAnnotationClick,
|
|
274
278
|
stableOnDataPointClick,
|
|
275
279
|
stableOnEdit,
|
|
@@ -538,6 +542,15 @@ import {
|
|
|
538
542
|
useRef as useRef5
|
|
539
543
|
} from "react";
|
|
540
544
|
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
545
|
+
function tooltipStructural(tooltip) {
|
|
546
|
+
if (tooltip === false) return false;
|
|
547
|
+
return true;
|
|
548
|
+
}
|
|
549
|
+
function legendStructural(legend) {
|
|
550
|
+
if (legend === false) return "false";
|
|
551
|
+
if (legend === true || legend === void 0) return "true";
|
|
552
|
+
return JSON.stringify({ interactive: legend.interactive, counts: legend.counts });
|
|
553
|
+
}
|
|
541
554
|
var Graph = forwardRef3(function Graph2({
|
|
542
555
|
spec,
|
|
543
556
|
theme: themeProp,
|
|
@@ -547,8 +560,13 @@ var Graph = forwardRef3(function Graph2({
|
|
|
547
560
|
onNodeHover,
|
|
548
561
|
onEdgeHover,
|
|
549
562
|
onSelectionChange,
|
|
563
|
+
onLegendHover,
|
|
564
|
+
onLegendToggle,
|
|
565
|
+
onHighlightChange,
|
|
566
|
+
onCameraChange,
|
|
550
567
|
tooltip,
|
|
551
568
|
legend,
|
|
569
|
+
fitOnLoad,
|
|
552
570
|
className,
|
|
553
571
|
style
|
|
554
572
|
}, ref) {
|
|
@@ -559,13 +577,19 @@ var Graph = forwardRef3(function Graph2({
|
|
|
559
577
|
const containerRef = useRef5(null);
|
|
560
578
|
const graphRef = useRef5(null);
|
|
561
579
|
const specRef = useRef5("");
|
|
580
|
+
const prevMountDepsRef = useRef5(null);
|
|
562
581
|
const handlersRef = useRef5({});
|
|
563
582
|
handlersRef.current = {
|
|
564
583
|
onNodeClick,
|
|
565
584
|
onNodeDoubleClick,
|
|
566
585
|
onNodeHover,
|
|
567
586
|
onEdgeHover,
|
|
568
|
-
onSelectionChange
|
|
587
|
+
onSelectionChange,
|
|
588
|
+
onLegendHover,
|
|
589
|
+
onLegendToggle,
|
|
590
|
+
onHighlightChange,
|
|
591
|
+
onCameraChange,
|
|
592
|
+
tooltipFormatter: typeof tooltip === "object" ? tooltip.formatter : void 0
|
|
569
593
|
};
|
|
570
594
|
const stableOnNodeClick = useCallback4(
|
|
571
595
|
(node) => handlersRef.current.onNodeClick?.(node),
|
|
@@ -587,6 +611,26 @@ var Graph = forwardRef3(function Graph2({
|
|
|
587
611
|
(nodeIds) => handlersRef.current.onSelectionChange?.(nodeIds),
|
|
588
612
|
[]
|
|
589
613
|
);
|
|
614
|
+
const stableOnLegendHover = useCallback4(
|
|
615
|
+
(entry) => handlersRef.current.onLegendHover?.(entry),
|
|
616
|
+
[]
|
|
617
|
+
);
|
|
618
|
+
const stableOnLegendToggle = useCallback4(
|
|
619
|
+
(activeValues) => handlersRef.current.onLegendToggle?.(activeValues),
|
|
620
|
+
[]
|
|
621
|
+
);
|
|
622
|
+
const stableOnHighlightChange = useCallback4(
|
|
623
|
+
(nodeIds) => handlersRef.current.onHighlightChange?.(nodeIds),
|
|
624
|
+
[]
|
|
625
|
+
);
|
|
626
|
+
const stableOnCameraChange = useCallback4(
|
|
627
|
+
(camera) => handlersRef.current.onCameraChange?.(camera),
|
|
628
|
+
[]
|
|
629
|
+
);
|
|
630
|
+
const stableTooltipFormatter = useCallback4(
|
|
631
|
+
(item, defaults) => handlersRef.current.tooltipFormatter?.(item, defaults) ?? defaults,
|
|
632
|
+
[]
|
|
633
|
+
);
|
|
590
634
|
useImperativeHandle4(
|
|
591
635
|
ref,
|
|
592
636
|
() => ({
|
|
@@ -596,18 +640,48 @@ var Graph = forwardRef3(function Graph2({
|
|
|
596
640
|
clearSearch() {
|
|
597
641
|
graphRef.current?.clearSearch();
|
|
598
642
|
},
|
|
599
|
-
|
|
600
|
-
graphRef.current?.
|
|
643
|
+
getSearchMatches() {
|
|
644
|
+
return graphRef.current?.getSearchMatches() ?? [];
|
|
645
|
+
},
|
|
646
|
+
zoomToFit(opts) {
|
|
647
|
+
graphRef.current?.zoomToFit(opts);
|
|
648
|
+
},
|
|
649
|
+
zoomToNode(nodeId, opts) {
|
|
650
|
+
graphRef.current?.zoomToNode(nodeId, opts);
|
|
651
|
+
},
|
|
652
|
+
flyTo(target, opts) {
|
|
653
|
+
graphRef.current?.flyTo(target, opts);
|
|
654
|
+
},
|
|
655
|
+
centerAt(x, y, opts) {
|
|
656
|
+
graphRef.current?.centerAt(x, y, opts);
|
|
601
657
|
},
|
|
602
|
-
|
|
603
|
-
graphRef.current?.
|
|
658
|
+
getCamera() {
|
|
659
|
+
return graphRef.current?.getCamera() ?? { x: 0, y: 0, k: 1 };
|
|
604
660
|
},
|
|
605
|
-
selectNode(nodeId) {
|
|
606
|
-
graphRef.current?.selectNode(nodeId);
|
|
661
|
+
selectNode(nodeId, opts) {
|
|
662
|
+
graphRef.current?.selectNode(nodeId, opts);
|
|
607
663
|
},
|
|
608
664
|
getSelectedNodes() {
|
|
609
665
|
return graphRef.current?.getSelectedNodes() ?? [];
|
|
610
666
|
},
|
|
667
|
+
highlight(target, opts) {
|
|
668
|
+
graphRef.current?.highlight(target, opts);
|
|
669
|
+
},
|
|
670
|
+
clearHighlight() {
|
|
671
|
+
graphRef.current?.clearHighlight();
|
|
672
|
+
},
|
|
673
|
+
getHighlight() {
|
|
674
|
+
return graphRef.current?.getHighlight() ?? null;
|
|
675
|
+
},
|
|
676
|
+
getLegend() {
|
|
677
|
+
return graphRef.current?.getLegend() ?? null;
|
|
678
|
+
},
|
|
679
|
+
setActiveCategories(values) {
|
|
680
|
+
graphRef.current?.setActiveCategories(values);
|
|
681
|
+
},
|
|
682
|
+
getActiveCategories() {
|
|
683
|
+
return graphRef.current?.getActiveCategories() ?? [];
|
|
684
|
+
},
|
|
611
685
|
updateVisuals(spec2) {
|
|
612
686
|
graphRef.current?.updateVisuals(spec2);
|
|
613
687
|
},
|
|
@@ -617,23 +691,36 @@ var Graph = forwardRef3(function Graph2({
|
|
|
617
691
|
}),
|
|
618
692
|
[]
|
|
619
693
|
);
|
|
694
|
+
const tooltipOn = tooltipStructural(tooltip);
|
|
695
|
+
const legendKey = legendStructural(legend);
|
|
620
696
|
useEffect5(() => {
|
|
621
697
|
const container = containerRef.current;
|
|
622
698
|
if (!container) return;
|
|
699
|
+
const tooltipOption = tooltipOn ? { formatter: stableTooltipFormatter } : false;
|
|
700
|
+
const mountDeps = [theme, resolvedDarkMode, tooltipOn, legendKey, fitOnLoad];
|
|
701
|
+
const prevDeps = prevMountDepsRef.current;
|
|
702
|
+
const suppressEntrance = prevDeps !== null && mountDeps.some((d, i) => !Object.is(d, prevDeps[i]));
|
|
623
703
|
const options = {
|
|
624
704
|
theme,
|
|
625
705
|
darkMode: resolvedDarkMode,
|
|
626
|
-
tooltip,
|
|
706
|
+
tooltip: tooltipOption,
|
|
627
707
|
legend,
|
|
708
|
+
fitOnLoad,
|
|
628
709
|
onNodeClick: stableOnNodeClick,
|
|
629
710
|
onNodeDoubleClick: stableOnNodeDoubleClick,
|
|
630
711
|
onNodeHover: stableOnNodeHover,
|
|
631
712
|
onEdgeHover: stableOnEdgeHover,
|
|
632
713
|
onSelectionChange: stableOnSelectionChange,
|
|
633
|
-
|
|
714
|
+
onLegendHover: stableOnLegendHover,
|
|
715
|
+
onLegendToggle: stableOnLegendToggle,
|
|
716
|
+
onHighlightChange: stableOnHighlightChange,
|
|
717
|
+
onCameraChange: stableOnCameraChange,
|
|
718
|
+
responsive: true,
|
|
719
|
+
suppressEntrance
|
|
634
720
|
};
|
|
635
721
|
graphRef.current = createGraph(container, spec, options);
|
|
636
722
|
specRef.current = JSON.stringify(spec);
|
|
723
|
+
prevMountDepsRef.current = mountDeps;
|
|
637
724
|
return () => {
|
|
638
725
|
graphRef.current?.destroy();
|
|
639
726
|
graphRef.current = null;
|
|
@@ -641,36 +728,26 @@ var Graph = forwardRef3(function Graph2({
|
|
|
641
728
|
}, [
|
|
642
729
|
theme,
|
|
643
730
|
resolvedDarkMode,
|
|
644
|
-
|
|
645
|
-
|
|
731
|
+
tooltipOn,
|
|
732
|
+
legendKey,
|
|
733
|
+
fitOnLoad,
|
|
646
734
|
stableOnNodeClick,
|
|
647
735
|
stableOnNodeDoubleClick,
|
|
648
736
|
stableOnNodeHover,
|
|
649
737
|
stableOnEdgeHover,
|
|
650
|
-
stableOnSelectionChange
|
|
738
|
+
stableOnSelectionChange,
|
|
739
|
+
stableOnLegendHover,
|
|
740
|
+
stableOnLegendToggle,
|
|
741
|
+
stableOnHighlightChange,
|
|
742
|
+
stableOnCameraChange,
|
|
743
|
+
stableTooltipFormatter
|
|
651
744
|
]);
|
|
652
745
|
useEffect5(() => {
|
|
653
746
|
const graph = graphRef.current;
|
|
654
747
|
if (!graph) return;
|
|
655
748
|
const specString = JSON.stringify(spec);
|
|
656
749
|
if (specString === specRef.current) return;
|
|
657
|
-
const prevSpec = specRef.current;
|
|
658
750
|
specRef.current = specString;
|
|
659
|
-
if (prevSpec) {
|
|
660
|
-
try {
|
|
661
|
-
const prev = JSON.parse(prevSpec);
|
|
662
|
-
const sameNodes = prev.nodes.length === spec.nodes.length && prev.nodes.every((n, i) => n.id === spec.nodes[i].id);
|
|
663
|
-
const sameEdges = prev.edges.length === spec.edges.length && prev.edges.every(
|
|
664
|
-
(e, i) => e.source === spec.edges[i].source && e.target === spec.edges[i].target
|
|
665
|
-
);
|
|
666
|
-
const sameLayout = prev.layout?.clustering?.field === spec.layout?.clustering?.field;
|
|
667
|
-
if (sameNodes && sameEdges && sameLayout) {
|
|
668
|
-
graph.updateVisuals(spec);
|
|
669
|
-
return;
|
|
670
|
-
}
|
|
671
|
-
} catch {
|
|
672
|
-
}
|
|
673
|
-
}
|
|
674
751
|
graph.update(spec);
|
|
675
752
|
}, [spec]);
|
|
676
753
|
return /* @__PURE__ */ jsx6(
|
|
@@ -764,26 +841,75 @@ function useGraph() {
|
|
|
764
841
|
const clearSearch = useCallback5(() => {
|
|
765
842
|
ref.current?.clearSearch();
|
|
766
843
|
}, []);
|
|
767
|
-
const
|
|
768
|
-
ref.current?.
|
|
844
|
+
const getSearchMatches = useCallback5(() => {
|
|
845
|
+
return ref.current?.getSearchMatches() ?? [];
|
|
846
|
+
}, []);
|
|
847
|
+
const zoomToFit = useCallback5((opts) => {
|
|
848
|
+
ref.current?.zoomToFit(opts);
|
|
769
849
|
}, []);
|
|
770
|
-
const zoomToNode = useCallback5(
|
|
771
|
-
|
|
850
|
+
const zoomToNode = useCallback5(
|
|
851
|
+
(nodeId, opts) => {
|
|
852
|
+
ref.current?.zoomToNode(nodeId, opts);
|
|
853
|
+
},
|
|
854
|
+
[]
|
|
855
|
+
);
|
|
856
|
+
const flyTo = useCallback5(
|
|
857
|
+
(target, opts) => {
|
|
858
|
+
ref.current?.flyTo(target, opts);
|
|
859
|
+
},
|
|
860
|
+
[]
|
|
861
|
+
);
|
|
862
|
+
const centerAt = useCallback5((x, y, opts) => {
|
|
863
|
+
ref.current?.centerAt(x, y, opts);
|
|
772
864
|
}, []);
|
|
773
|
-
const
|
|
774
|
-
ref.current?.
|
|
865
|
+
const getCamera = useCallback5(() => {
|
|
866
|
+
return ref.current?.getCamera() ?? { x: 0, y: 0, k: 1 };
|
|
775
867
|
}, []);
|
|
868
|
+
const selectNode = useCallback5(
|
|
869
|
+
(nodeId, opts) => {
|
|
870
|
+
ref.current?.selectNode(nodeId, opts);
|
|
871
|
+
},
|
|
872
|
+
[]
|
|
873
|
+
);
|
|
776
874
|
const getSelectedNodes = useCallback5(() => {
|
|
777
875
|
return ref.current?.getSelectedNodes() ?? [];
|
|
778
876
|
}, []);
|
|
877
|
+
const highlight = useCallback5((target, opts) => {
|
|
878
|
+
ref.current?.highlight(target, opts);
|
|
879
|
+
}, []);
|
|
880
|
+
const clearHighlight = useCallback5(() => {
|
|
881
|
+
ref.current?.clearHighlight();
|
|
882
|
+
}, []);
|
|
883
|
+
const getHighlight = useCallback5(() => {
|
|
884
|
+
return ref.current?.getHighlight() ?? null;
|
|
885
|
+
}, []);
|
|
886
|
+
const getLegend = useCallback5(() => {
|
|
887
|
+
return ref.current?.getLegend() ?? null;
|
|
888
|
+
}, []);
|
|
889
|
+
const setActiveCategories = useCallback5((values) => {
|
|
890
|
+
ref.current?.setActiveCategories(values);
|
|
891
|
+
}, []);
|
|
892
|
+
const getActiveCategories = useCallback5(() => {
|
|
893
|
+
return ref.current?.getActiveCategories() ?? [];
|
|
894
|
+
}, []);
|
|
779
895
|
return {
|
|
780
896
|
ref,
|
|
781
897
|
search,
|
|
782
898
|
clearSearch,
|
|
899
|
+
getSearchMatches,
|
|
783
900
|
zoomToFit,
|
|
784
901
|
zoomToNode,
|
|
902
|
+
flyTo,
|
|
903
|
+
centerAt,
|
|
904
|
+
getCamera,
|
|
785
905
|
selectNode,
|
|
786
|
-
getSelectedNodes
|
|
906
|
+
getSelectedNodes,
|
|
907
|
+
highlight,
|
|
908
|
+
clearHighlight,
|
|
909
|
+
getHighlight,
|
|
910
|
+
getLegend,
|
|
911
|
+
setActiveCategories,
|
|
912
|
+
getActiveCategories
|
|
787
913
|
};
|
|
788
914
|
}
|
|
789
915
|
|
|
@@ -876,7 +1002,9 @@ function useTableState(initialState) {
|
|
|
876
1002
|
}
|
|
877
1003
|
|
|
878
1004
|
// src/Map.tsx
|
|
879
|
-
import {
|
|
1005
|
+
import {
|
|
1006
|
+
createMap
|
|
1007
|
+
} from "@opendata-ai/openchart-vanilla";
|
|
880
1008
|
import {
|
|
881
1009
|
forwardRef as forwardRef4,
|
|
882
1010
|
useCallback as useCallback8,
|
|
@@ -1198,6 +1326,7 @@ export {
|
|
|
1198
1326
|
exportPNG,
|
|
1199
1327
|
exportSVG,
|
|
1200
1328
|
exportSVGWithFonts,
|
|
1329
|
+
exportSpecSequence,
|
|
1201
1330
|
getChartRenderer,
|
|
1202
1331
|
normalizeSpec,
|
|
1203
1332
|
registerChartRenderer,
|