@opendata-ai/openchart-react 8.0.0-rc.8 → 8.0.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/dist/index.d.ts +149 -43
- package/dist/index.js +294 -157
- 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 -130
- 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.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";
|
|
@@ -12,8 +13,8 @@ import {
|
|
|
12
13
|
compile,
|
|
13
14
|
compileBarList,
|
|
14
15
|
compileChart,
|
|
16
|
+
compileGeoMap,
|
|
15
17
|
compileGraph,
|
|
16
|
-
compileMap,
|
|
17
18
|
compileSankey,
|
|
18
19
|
compileTable,
|
|
19
20
|
compileTileMap,
|
|
@@ -128,6 +129,7 @@ function ChartInner({
|
|
|
128
129
|
spec,
|
|
129
130
|
theme: themeProp,
|
|
130
131
|
darkMode,
|
|
132
|
+
renderer,
|
|
131
133
|
onDataPointClick,
|
|
132
134
|
onMarkClick,
|
|
133
135
|
onMarkHover,
|
|
@@ -141,6 +143,7 @@ function ChartInner({
|
|
|
141
143
|
onDeselect,
|
|
142
144
|
onTextEdit,
|
|
143
145
|
onReveal,
|
|
146
|
+
editable,
|
|
144
147
|
selectedElement: selectedElementProp,
|
|
145
148
|
highlight,
|
|
146
149
|
className,
|
|
@@ -242,6 +245,7 @@ function ChartInner({
|
|
|
242
245
|
const options = {
|
|
243
246
|
theme,
|
|
244
247
|
darkMode: resolvedDarkMode,
|
|
248
|
+
renderer,
|
|
245
249
|
onDataPointClick: stableOnDataPointClick,
|
|
246
250
|
onMarkClick: stableOnMarkClick,
|
|
247
251
|
onMarkHover: stableOnMarkHover,
|
|
@@ -258,6 +262,7 @@ function ChartInner({
|
|
|
258
262
|
...handlersRef.current.onDeselect ? { onDeselect: stableOnDeselect } : {},
|
|
259
263
|
...handlersRef.current.onTextEdit ? { onTextEdit: stableOnTextEdit } : {},
|
|
260
264
|
...handlersRef.current.onReveal ? { onReveal: stableOnReveal } : {},
|
|
265
|
+
...editable != null ? { editable } : {},
|
|
261
266
|
...selectedElementProp ? { selectedElement: selectedElementProp } : {},
|
|
262
267
|
responsive: true
|
|
263
268
|
};
|
|
@@ -270,6 +275,8 @@ function ChartInner({
|
|
|
270
275
|
}, [
|
|
271
276
|
theme,
|
|
272
277
|
resolvedDarkMode,
|
|
278
|
+
renderer,
|
|
279
|
+
editable,
|
|
273
280
|
stableOnAnnotationClick,
|
|
274
281
|
stableOnDataPointClick,
|
|
275
282
|
stableOnEdit,
|
|
@@ -526,9 +533,9 @@ function DataTable({
|
|
|
526
533
|
);
|
|
527
534
|
}
|
|
528
535
|
|
|
529
|
-
// src/
|
|
536
|
+
// src/GeoMap.tsx
|
|
530
537
|
import {
|
|
531
|
-
|
|
538
|
+
createGeoMap
|
|
532
539
|
} from "@opendata-ai/openchart-vanilla";
|
|
533
540
|
import {
|
|
534
541
|
forwardRef as forwardRef3,
|
|
@@ -538,7 +545,93 @@ import {
|
|
|
538
545
|
useRef as useRef5
|
|
539
546
|
} from "react";
|
|
540
547
|
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
541
|
-
var
|
|
548
|
+
var GeoMap = forwardRef3(function GeoMap2({ spec, theme: themeProp, darkMode, onMarkClick, onMarkHover, className, style }, ref) {
|
|
549
|
+
const contextTheme = useVizTheme();
|
|
550
|
+
const contextDarkMode = useVizDarkMode();
|
|
551
|
+
const theme = themeProp ?? contextTheme;
|
|
552
|
+
const resolvedDarkMode = darkMode ?? contextDarkMode;
|
|
553
|
+
const containerRef = useRef5(null);
|
|
554
|
+
const instanceRef = useRef5(null);
|
|
555
|
+
const specRef = useRef5("");
|
|
556
|
+
const handlersRef = useRef5({});
|
|
557
|
+
handlersRef.current = {
|
|
558
|
+
onMarkClick,
|
|
559
|
+
onMarkHover
|
|
560
|
+
};
|
|
561
|
+
const stableOnMarkClick = useCallback4(
|
|
562
|
+
(feature) => handlersRef.current.onMarkClick?.(feature),
|
|
563
|
+
[]
|
|
564
|
+
);
|
|
565
|
+
const stableOnMarkHover = useCallback4(
|
|
566
|
+
(feature) => handlersRef.current.onMarkHover?.(feature),
|
|
567
|
+
[]
|
|
568
|
+
);
|
|
569
|
+
useImperativeHandle4(
|
|
570
|
+
ref,
|
|
571
|
+
() => ({
|
|
572
|
+
get instance() {
|
|
573
|
+
return instanceRef.current;
|
|
574
|
+
}
|
|
575
|
+
}),
|
|
576
|
+
[]
|
|
577
|
+
);
|
|
578
|
+
useEffect5(() => {
|
|
579
|
+
const container = containerRef.current;
|
|
580
|
+
if (!container) return;
|
|
581
|
+
const options = {
|
|
582
|
+
theme,
|
|
583
|
+
darkMode: resolvedDarkMode,
|
|
584
|
+
onMarkClick: stableOnMarkClick,
|
|
585
|
+
onMarkHover: stableOnMarkHover,
|
|
586
|
+
responsive: true
|
|
587
|
+
};
|
|
588
|
+
instanceRef.current = createGeoMap(container, spec, options);
|
|
589
|
+
specRef.current = JSON.stringify(spec);
|
|
590
|
+
return () => {
|
|
591
|
+
instanceRef.current?.destroy();
|
|
592
|
+
instanceRef.current = null;
|
|
593
|
+
};
|
|
594
|
+
}, [theme, resolvedDarkMode, stableOnMarkClick, stableOnMarkHover]);
|
|
595
|
+
useEffect5(() => {
|
|
596
|
+
const instance = instanceRef.current;
|
|
597
|
+
if (!instance) return;
|
|
598
|
+
const specString = JSON.stringify(spec);
|
|
599
|
+
if (specString === specRef.current) return;
|
|
600
|
+
specRef.current = specString;
|
|
601
|
+
instance.update(spec);
|
|
602
|
+
}, [spec]);
|
|
603
|
+
return /* @__PURE__ */ jsx6(
|
|
604
|
+
"div",
|
|
605
|
+
{
|
|
606
|
+
ref: containerRef,
|
|
607
|
+
className: className ? `oc-map-root ${className}` : "oc-map-root",
|
|
608
|
+
style
|
|
609
|
+
}
|
|
610
|
+
);
|
|
611
|
+
});
|
|
612
|
+
|
|
613
|
+
// src/Graph.tsx
|
|
614
|
+
import {
|
|
615
|
+
createGraph
|
|
616
|
+
} from "@opendata-ai/openchart-vanilla";
|
|
617
|
+
import {
|
|
618
|
+
forwardRef as forwardRef4,
|
|
619
|
+
useCallback as useCallback5,
|
|
620
|
+
useEffect as useEffect6,
|
|
621
|
+
useImperativeHandle as useImperativeHandle5,
|
|
622
|
+
useRef as useRef6
|
|
623
|
+
} from "react";
|
|
624
|
+
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
625
|
+
function tooltipStructural(tooltip) {
|
|
626
|
+
if (tooltip === false) return false;
|
|
627
|
+
return true;
|
|
628
|
+
}
|
|
629
|
+
function legendStructural(legend) {
|
|
630
|
+
if (legend === false) return "false";
|
|
631
|
+
if (legend === true || legend === void 0) return "true";
|
|
632
|
+
return JSON.stringify({ interactive: legend.interactive, counts: legend.counts });
|
|
633
|
+
}
|
|
634
|
+
var Graph = forwardRef4(function Graph2({
|
|
542
635
|
spec,
|
|
543
636
|
theme: themeProp,
|
|
544
637
|
darkMode,
|
|
@@ -547,8 +640,13 @@ var Graph = forwardRef3(function Graph2({
|
|
|
547
640
|
onNodeHover,
|
|
548
641
|
onEdgeHover,
|
|
549
642
|
onSelectionChange,
|
|
643
|
+
onLegendHover,
|
|
644
|
+
onLegendToggle,
|
|
645
|
+
onHighlightChange,
|
|
646
|
+
onCameraChange,
|
|
550
647
|
tooltip,
|
|
551
648
|
legend,
|
|
649
|
+
fitOnLoad,
|
|
552
650
|
className,
|
|
553
651
|
style
|
|
554
652
|
}, ref) {
|
|
@@ -556,38 +654,64 @@ var Graph = forwardRef3(function Graph2({
|
|
|
556
654
|
const contextDarkMode = useVizDarkMode();
|
|
557
655
|
const theme = themeProp ?? contextTheme;
|
|
558
656
|
const resolvedDarkMode = darkMode ?? contextDarkMode;
|
|
559
|
-
const containerRef =
|
|
560
|
-
const graphRef =
|
|
561
|
-
const specRef =
|
|
562
|
-
const
|
|
657
|
+
const containerRef = useRef6(null);
|
|
658
|
+
const graphRef = useRef6(null);
|
|
659
|
+
const specRef = useRef6("");
|
|
660
|
+
const prevMountDepsRef = useRef6(null);
|
|
661
|
+
const handlersRef = useRef6({});
|
|
563
662
|
handlersRef.current = {
|
|
564
663
|
onNodeClick,
|
|
565
664
|
onNodeDoubleClick,
|
|
566
665
|
onNodeHover,
|
|
567
666
|
onEdgeHover,
|
|
568
|
-
onSelectionChange
|
|
667
|
+
onSelectionChange,
|
|
668
|
+
onLegendHover,
|
|
669
|
+
onLegendToggle,
|
|
670
|
+
onHighlightChange,
|
|
671
|
+
onCameraChange,
|
|
672
|
+
tooltipFormatter: typeof tooltip === "object" ? tooltip.formatter : void 0
|
|
569
673
|
};
|
|
570
|
-
const stableOnNodeClick =
|
|
674
|
+
const stableOnNodeClick = useCallback5(
|
|
571
675
|
(node) => handlersRef.current.onNodeClick?.(node),
|
|
572
676
|
[]
|
|
573
677
|
);
|
|
574
|
-
const stableOnNodeDoubleClick =
|
|
678
|
+
const stableOnNodeDoubleClick = useCallback5(
|
|
575
679
|
(node) => handlersRef.current.onNodeDoubleClick?.(node),
|
|
576
680
|
[]
|
|
577
681
|
);
|
|
578
|
-
const stableOnNodeHover =
|
|
682
|
+
const stableOnNodeHover = useCallback5(
|
|
579
683
|
(node) => handlersRef.current.onNodeHover?.(node),
|
|
580
684
|
[]
|
|
581
685
|
);
|
|
582
|
-
const stableOnEdgeHover =
|
|
686
|
+
const stableOnEdgeHover = useCallback5(
|
|
583
687
|
(edge) => handlersRef.current.onEdgeHover?.(edge),
|
|
584
688
|
[]
|
|
585
689
|
);
|
|
586
|
-
const stableOnSelectionChange =
|
|
690
|
+
const stableOnSelectionChange = useCallback5(
|
|
587
691
|
(nodeIds) => handlersRef.current.onSelectionChange?.(nodeIds),
|
|
588
692
|
[]
|
|
589
693
|
);
|
|
590
|
-
|
|
694
|
+
const stableOnLegendHover = useCallback5(
|
|
695
|
+
(entry) => handlersRef.current.onLegendHover?.(entry),
|
|
696
|
+
[]
|
|
697
|
+
);
|
|
698
|
+
const stableOnLegendToggle = useCallback5(
|
|
699
|
+
(activeValues) => handlersRef.current.onLegendToggle?.(activeValues),
|
|
700
|
+
[]
|
|
701
|
+
);
|
|
702
|
+
const stableOnHighlightChange = useCallback5(
|
|
703
|
+
(nodeIds) => handlersRef.current.onHighlightChange?.(nodeIds),
|
|
704
|
+
[]
|
|
705
|
+
);
|
|
706
|
+
const stableOnCameraChange = useCallback5(
|
|
707
|
+
(camera) => handlersRef.current.onCameraChange?.(camera),
|
|
708
|
+
[]
|
|
709
|
+
);
|
|
710
|
+
const stableTooltipFormatter = useCallback5(
|
|
711
|
+
(item, defaults) => handlersRef.current.tooltipFormatter?.(item, defaults) ?? defaults,
|
|
712
|
+
[]
|
|
713
|
+
);
|
|
714
|
+
useImperativeHandle5(
|
|
591
715
|
ref,
|
|
592
716
|
() => ({
|
|
593
717
|
search(query) {
|
|
@@ -596,18 +720,48 @@ var Graph = forwardRef3(function Graph2({
|
|
|
596
720
|
clearSearch() {
|
|
597
721
|
graphRef.current?.clearSearch();
|
|
598
722
|
},
|
|
599
|
-
|
|
600
|
-
graphRef.current?.
|
|
723
|
+
getSearchMatches() {
|
|
724
|
+
return graphRef.current?.getSearchMatches() ?? [];
|
|
725
|
+
},
|
|
726
|
+
zoomToFit(opts) {
|
|
727
|
+
graphRef.current?.zoomToFit(opts);
|
|
728
|
+
},
|
|
729
|
+
zoomToNode(nodeId, opts) {
|
|
730
|
+
graphRef.current?.zoomToNode(nodeId, opts);
|
|
731
|
+
},
|
|
732
|
+
flyTo(target, opts) {
|
|
733
|
+
graphRef.current?.flyTo(target, opts);
|
|
601
734
|
},
|
|
602
|
-
|
|
603
|
-
graphRef.current?.
|
|
735
|
+
centerAt(x, y, opts) {
|
|
736
|
+
graphRef.current?.centerAt(x, y, opts);
|
|
604
737
|
},
|
|
605
|
-
|
|
606
|
-
graphRef.current?.
|
|
738
|
+
getCamera() {
|
|
739
|
+
return graphRef.current?.getCamera() ?? { x: 0, y: 0, k: 1 };
|
|
740
|
+
},
|
|
741
|
+
selectNode(nodeId, opts) {
|
|
742
|
+
graphRef.current?.selectNode(nodeId, opts);
|
|
607
743
|
},
|
|
608
744
|
getSelectedNodes() {
|
|
609
745
|
return graphRef.current?.getSelectedNodes() ?? [];
|
|
610
746
|
},
|
|
747
|
+
highlight(target, opts) {
|
|
748
|
+
graphRef.current?.highlight(target, opts);
|
|
749
|
+
},
|
|
750
|
+
clearHighlight() {
|
|
751
|
+
graphRef.current?.clearHighlight();
|
|
752
|
+
},
|
|
753
|
+
getHighlight() {
|
|
754
|
+
return graphRef.current?.getHighlight() ?? null;
|
|
755
|
+
},
|
|
756
|
+
getLegend() {
|
|
757
|
+
return graphRef.current?.getLegend() ?? null;
|
|
758
|
+
},
|
|
759
|
+
setActiveCategories(values) {
|
|
760
|
+
graphRef.current?.setActiveCategories(values);
|
|
761
|
+
},
|
|
762
|
+
getActiveCategories() {
|
|
763
|
+
return graphRef.current?.getActiveCategories() ?? [];
|
|
764
|
+
},
|
|
611
765
|
updateVisuals(spec2) {
|
|
612
766
|
graphRef.current?.updateVisuals(spec2);
|
|
613
767
|
},
|
|
@@ -617,23 +771,36 @@ var Graph = forwardRef3(function Graph2({
|
|
|
617
771
|
}),
|
|
618
772
|
[]
|
|
619
773
|
);
|
|
620
|
-
|
|
774
|
+
const tooltipOn = tooltipStructural(tooltip);
|
|
775
|
+
const legendKey = legendStructural(legend);
|
|
776
|
+
useEffect6(() => {
|
|
621
777
|
const container = containerRef.current;
|
|
622
778
|
if (!container) return;
|
|
779
|
+
const tooltipOption = tooltipOn ? { formatter: stableTooltipFormatter } : false;
|
|
780
|
+
const mountDeps = [theme, resolvedDarkMode, tooltipOn, legendKey, fitOnLoad];
|
|
781
|
+
const prevDeps = prevMountDepsRef.current;
|
|
782
|
+
const suppressEntrance = prevDeps !== null && mountDeps.some((d, i) => !Object.is(d, prevDeps[i]));
|
|
623
783
|
const options = {
|
|
624
784
|
theme,
|
|
625
785
|
darkMode: resolvedDarkMode,
|
|
626
|
-
tooltip,
|
|
786
|
+
tooltip: tooltipOption,
|
|
627
787
|
legend,
|
|
788
|
+
fitOnLoad,
|
|
628
789
|
onNodeClick: stableOnNodeClick,
|
|
629
790
|
onNodeDoubleClick: stableOnNodeDoubleClick,
|
|
630
791
|
onNodeHover: stableOnNodeHover,
|
|
631
792
|
onEdgeHover: stableOnEdgeHover,
|
|
632
793
|
onSelectionChange: stableOnSelectionChange,
|
|
633
|
-
|
|
794
|
+
onLegendHover: stableOnLegendHover,
|
|
795
|
+
onLegendToggle: stableOnLegendToggle,
|
|
796
|
+
onHighlightChange: stableOnHighlightChange,
|
|
797
|
+
onCameraChange: stableOnCameraChange,
|
|
798
|
+
responsive: true,
|
|
799
|
+
suppressEntrance
|
|
634
800
|
};
|
|
635
801
|
graphRef.current = createGraph(container, spec, options);
|
|
636
802
|
specRef.current = JSON.stringify(spec);
|
|
803
|
+
prevMountDepsRef.current = mountDeps;
|
|
637
804
|
return () => {
|
|
638
805
|
graphRef.current?.destroy();
|
|
639
806
|
graphRef.current = null;
|
|
@@ -641,39 +808,29 @@ var Graph = forwardRef3(function Graph2({
|
|
|
641
808
|
}, [
|
|
642
809
|
theme,
|
|
643
810
|
resolvedDarkMode,
|
|
644
|
-
|
|
645
|
-
|
|
811
|
+
tooltipOn,
|
|
812
|
+
legendKey,
|
|
813
|
+
fitOnLoad,
|
|
646
814
|
stableOnNodeClick,
|
|
647
815
|
stableOnNodeDoubleClick,
|
|
648
816
|
stableOnNodeHover,
|
|
649
817
|
stableOnEdgeHover,
|
|
650
|
-
stableOnSelectionChange
|
|
818
|
+
stableOnSelectionChange,
|
|
819
|
+
stableOnLegendHover,
|
|
820
|
+
stableOnLegendToggle,
|
|
821
|
+
stableOnHighlightChange,
|
|
822
|
+
stableOnCameraChange,
|
|
823
|
+
stableTooltipFormatter
|
|
651
824
|
]);
|
|
652
|
-
|
|
825
|
+
useEffect6(() => {
|
|
653
826
|
const graph = graphRef.current;
|
|
654
827
|
if (!graph) return;
|
|
655
828
|
const specString = JSON.stringify(spec);
|
|
656
829
|
if (specString === specRef.current) return;
|
|
657
|
-
const prevSpec = specRef.current;
|
|
658
830
|
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
831
|
graph.update(spec);
|
|
675
832
|
}, [spec]);
|
|
676
|
-
return /* @__PURE__ */
|
|
833
|
+
return /* @__PURE__ */ jsx7(
|
|
677
834
|
"div",
|
|
678
835
|
{
|
|
679
836
|
ref: containerRef,
|
|
@@ -685,20 +842,21 @@ var Graph = forwardRef3(function Graph2({
|
|
|
685
842
|
|
|
686
843
|
// src/hooks.ts
|
|
687
844
|
import { createChart as createChart2 } from "@opendata-ai/openchart-vanilla";
|
|
688
|
-
import { useEffect as
|
|
845
|
+
import { useEffect as useEffect7, useRef as useRef7, useState } from "react";
|
|
689
846
|
function useChart(spec, options) {
|
|
690
|
-
const ref =
|
|
691
|
-
const chartRef =
|
|
847
|
+
const ref = useRef7(null);
|
|
848
|
+
const chartRef = useRef7(null);
|
|
692
849
|
const [layout, setLayout] = useState(null);
|
|
693
|
-
const specRef =
|
|
694
|
-
|
|
850
|
+
const specRef = useRef7("");
|
|
851
|
+
useEffect7(() => {
|
|
695
852
|
const container = ref.current;
|
|
696
853
|
if (!container) return;
|
|
697
854
|
const mountOpts = {
|
|
698
855
|
theme: options?.theme,
|
|
699
856
|
darkMode: options?.darkMode,
|
|
700
857
|
onDataPointClick: options?.onDataPointClick,
|
|
701
|
-
responsive: options?.responsive
|
|
858
|
+
responsive: options?.responsive,
|
|
859
|
+
renderer: options?.renderer
|
|
702
860
|
};
|
|
703
861
|
const chart = createChart2(container, spec, mountOpts);
|
|
704
862
|
chartRef.current = chart;
|
|
@@ -709,8 +867,14 @@ function useChart(spec, options) {
|
|
|
709
867
|
chartRef.current = null;
|
|
710
868
|
setLayout(null);
|
|
711
869
|
};
|
|
712
|
-
}, [
|
|
713
|
-
|
|
870
|
+
}, [
|
|
871
|
+
options?.theme,
|
|
872
|
+
options?.darkMode,
|
|
873
|
+
options?.onDataPointClick,
|
|
874
|
+
options?.responsive,
|
|
875
|
+
options?.renderer
|
|
876
|
+
]);
|
|
877
|
+
useEffect7(() => {
|
|
714
878
|
const chart = chartRef.current;
|
|
715
879
|
if (!chart) return;
|
|
716
880
|
const specString = JSON.stringify(spec);
|
|
@@ -728,7 +892,7 @@ function useChart(spec, options) {
|
|
|
728
892
|
}
|
|
729
893
|
function useDarkMode(mode) {
|
|
730
894
|
const [isDark, setIsDark] = useState(() => resolveInitial(mode));
|
|
731
|
-
|
|
895
|
+
useEffect7(() => {
|
|
732
896
|
if (mode !== "auto") {
|
|
733
897
|
setIsDark(mode === "force");
|
|
734
898
|
return;
|
|
@@ -755,35 +919,84 @@ function resolveInitial(mode) {
|
|
|
755
919
|
}
|
|
756
920
|
|
|
757
921
|
// src/hooks/useGraph.ts
|
|
758
|
-
import { useCallback as
|
|
922
|
+
import { useCallback as useCallback6, useRef as useRef8 } from "react";
|
|
759
923
|
function useGraph() {
|
|
760
|
-
const ref =
|
|
761
|
-
const search =
|
|
924
|
+
const ref = useRef8(null);
|
|
925
|
+
const search = useCallback6((query) => {
|
|
762
926
|
ref.current?.search(query);
|
|
763
927
|
}, []);
|
|
764
|
-
const clearSearch =
|
|
928
|
+
const clearSearch = useCallback6(() => {
|
|
765
929
|
ref.current?.clearSearch();
|
|
766
930
|
}, []);
|
|
767
|
-
const
|
|
768
|
-
ref.current?.
|
|
931
|
+
const getSearchMatches = useCallback6(() => {
|
|
932
|
+
return ref.current?.getSearchMatches() ?? [];
|
|
933
|
+
}, []);
|
|
934
|
+
const zoomToFit = useCallback6((opts) => {
|
|
935
|
+
ref.current?.zoomToFit(opts);
|
|
769
936
|
}, []);
|
|
770
|
-
const zoomToNode =
|
|
771
|
-
|
|
937
|
+
const zoomToNode = useCallback6(
|
|
938
|
+
(nodeId, opts) => {
|
|
939
|
+
ref.current?.zoomToNode(nodeId, opts);
|
|
940
|
+
},
|
|
941
|
+
[]
|
|
942
|
+
);
|
|
943
|
+
const flyTo = useCallback6(
|
|
944
|
+
(target, opts) => {
|
|
945
|
+
ref.current?.flyTo(target, opts);
|
|
946
|
+
},
|
|
947
|
+
[]
|
|
948
|
+
);
|
|
949
|
+
const centerAt = useCallback6((x, y, opts) => {
|
|
950
|
+
ref.current?.centerAt(x, y, opts);
|
|
772
951
|
}, []);
|
|
773
|
-
const
|
|
774
|
-
ref.current?.
|
|
952
|
+
const getCamera = useCallback6(() => {
|
|
953
|
+
return ref.current?.getCamera() ?? { x: 0, y: 0, k: 1 };
|
|
775
954
|
}, []);
|
|
776
|
-
const
|
|
955
|
+
const selectNode = useCallback6(
|
|
956
|
+
(nodeId, opts) => {
|
|
957
|
+
ref.current?.selectNode(nodeId, opts);
|
|
958
|
+
},
|
|
959
|
+
[]
|
|
960
|
+
);
|
|
961
|
+
const getSelectedNodes = useCallback6(() => {
|
|
777
962
|
return ref.current?.getSelectedNodes() ?? [];
|
|
778
963
|
}, []);
|
|
964
|
+
const highlight = useCallback6((target, opts) => {
|
|
965
|
+
ref.current?.highlight(target, opts);
|
|
966
|
+
}, []);
|
|
967
|
+
const clearHighlight = useCallback6(() => {
|
|
968
|
+
ref.current?.clearHighlight();
|
|
969
|
+
}, []);
|
|
970
|
+
const getHighlight = useCallback6(() => {
|
|
971
|
+
return ref.current?.getHighlight() ?? null;
|
|
972
|
+
}, []);
|
|
973
|
+
const getLegend = useCallback6(() => {
|
|
974
|
+
return ref.current?.getLegend() ?? null;
|
|
975
|
+
}, []);
|
|
976
|
+
const setActiveCategories = useCallback6((values) => {
|
|
977
|
+
ref.current?.setActiveCategories(values);
|
|
978
|
+
}, []);
|
|
979
|
+
const getActiveCategories = useCallback6(() => {
|
|
980
|
+
return ref.current?.getActiveCategories() ?? [];
|
|
981
|
+
}, []);
|
|
779
982
|
return {
|
|
780
983
|
ref,
|
|
781
984
|
search,
|
|
782
985
|
clearSearch,
|
|
986
|
+
getSearchMatches,
|
|
783
987
|
zoomToFit,
|
|
784
988
|
zoomToNode,
|
|
989
|
+
flyTo,
|
|
990
|
+
centerAt,
|
|
991
|
+
getCamera,
|
|
785
992
|
selectNode,
|
|
786
|
-
getSelectedNodes
|
|
993
|
+
getSelectedNodes,
|
|
994
|
+
highlight,
|
|
995
|
+
clearHighlight,
|
|
996
|
+
getHighlight,
|
|
997
|
+
getLegend,
|
|
998
|
+
setActiveCategories,
|
|
999
|
+
getActiveCategories
|
|
787
1000
|
};
|
|
788
1001
|
}
|
|
789
1002
|
|
|
@@ -791,24 +1004,24 @@ function useGraph() {
|
|
|
791
1004
|
import {
|
|
792
1005
|
createTable as createTable2
|
|
793
1006
|
} from "@opendata-ai/openchart-vanilla";
|
|
794
|
-
import { useCallback as
|
|
1007
|
+
import { useCallback as useCallback7, useEffect as useEffect8, useRef as useRef9, useState as useState2 } from "react";
|
|
795
1008
|
function useTable(spec, options) {
|
|
796
|
-
const ref =
|
|
797
|
-
const tableRef =
|
|
1009
|
+
const ref = useRef9(null);
|
|
1010
|
+
const tableRef = useRef9(null);
|
|
798
1011
|
const [state, setState] = useState2({
|
|
799
1012
|
sort: null,
|
|
800
1013
|
search: "",
|
|
801
1014
|
page: 0
|
|
802
1015
|
});
|
|
803
1016
|
const originalOnStateChange = options?.onStateChange;
|
|
804
|
-
const handleStateChange =
|
|
1017
|
+
const handleStateChange = useCallback7(
|
|
805
1018
|
(newState) => {
|
|
806
1019
|
setState(newState);
|
|
807
1020
|
originalOnStateChange?.(newState);
|
|
808
1021
|
},
|
|
809
1022
|
[originalOnStateChange]
|
|
810
1023
|
);
|
|
811
|
-
|
|
1024
|
+
useEffect8(() => {
|
|
812
1025
|
const container = ref.current;
|
|
813
1026
|
if (!container) return;
|
|
814
1027
|
const mountOpts = {
|
|
@@ -831,7 +1044,7 @@ function useTable(spec, options) {
|
|
|
831
1044
|
options,
|
|
832
1045
|
spec
|
|
833
1046
|
]);
|
|
834
|
-
|
|
1047
|
+
useEffect8(() => {
|
|
835
1048
|
const table = tableRef.current;
|
|
836
1049
|
if (!table) return;
|
|
837
1050
|
table.update(spec);
|
|
@@ -845,21 +1058,21 @@ function useTable(spec, options) {
|
|
|
845
1058
|
}
|
|
846
1059
|
|
|
847
1060
|
// src/hooks/useTableState.ts
|
|
848
|
-
import { useCallback as
|
|
1061
|
+
import { useCallback as useCallback8, useState as useState3 } from "react";
|
|
849
1062
|
function useTableState(initialState) {
|
|
850
1063
|
const [sort, setSortInternal] = useState3(initialState?.sort ?? null);
|
|
851
1064
|
const [search, setSearchInternal] = useState3(initialState?.search ?? "");
|
|
852
1065
|
const [page, setPageInternal] = useState3(initialState?.page ?? 0);
|
|
853
|
-
const setSort =
|
|
1066
|
+
const setSort = useCallback8((newSort) => {
|
|
854
1067
|
setSortInternal(newSort);
|
|
855
1068
|
}, []);
|
|
856
|
-
const setSearch =
|
|
1069
|
+
const setSearch = useCallback8((query) => {
|
|
857
1070
|
setSearchInternal(query);
|
|
858
1071
|
}, []);
|
|
859
|
-
const setPage =
|
|
1072
|
+
const setPage = useCallback8((newPage) => {
|
|
860
1073
|
setPageInternal(newPage);
|
|
861
1074
|
}, []);
|
|
862
|
-
const resetState =
|
|
1075
|
+
const resetState = useCallback8(() => {
|
|
863
1076
|
setSortInternal(initialState?.sort ?? null);
|
|
864
1077
|
setSearchInternal(initialState?.search ?? "");
|
|
865
1078
|
setPageInternal(initialState?.page ?? 0);
|
|
@@ -875,83 +1088,6 @@ function useTableState(initialState) {
|
|
|
875
1088
|
};
|
|
876
1089
|
}
|
|
877
1090
|
|
|
878
|
-
// src/Map.tsx
|
|
879
|
-
import {
|
|
880
|
-
createMap
|
|
881
|
-
} from "@opendata-ai/openchart-vanilla";
|
|
882
|
-
import {
|
|
883
|
-
forwardRef as forwardRef4,
|
|
884
|
-
useCallback as useCallback8,
|
|
885
|
-
useEffect as useEffect8,
|
|
886
|
-
useImperativeHandle as useImperativeHandle5,
|
|
887
|
-
useRef as useRef9
|
|
888
|
-
} from "react";
|
|
889
|
-
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
890
|
-
var GeoMap = forwardRef4(function GeoMap2({ spec, theme: themeProp, darkMode, onMarkClick, onMarkHover, className, style }, ref) {
|
|
891
|
-
const contextTheme = useVizTheme();
|
|
892
|
-
const contextDarkMode = useVizDarkMode();
|
|
893
|
-
const theme = themeProp ?? contextTheme;
|
|
894
|
-
const resolvedDarkMode = darkMode ?? contextDarkMode;
|
|
895
|
-
const containerRef = useRef9(null);
|
|
896
|
-
const instanceRef = useRef9(null);
|
|
897
|
-
const specRef = useRef9("");
|
|
898
|
-
const handlersRef = useRef9({});
|
|
899
|
-
handlersRef.current = {
|
|
900
|
-
onMarkClick,
|
|
901
|
-
onMarkHover
|
|
902
|
-
};
|
|
903
|
-
const stableOnMarkClick = useCallback8(
|
|
904
|
-
(feature) => handlersRef.current.onMarkClick?.(feature),
|
|
905
|
-
[]
|
|
906
|
-
);
|
|
907
|
-
const stableOnMarkHover = useCallback8(
|
|
908
|
-
(feature) => handlersRef.current.onMarkHover?.(feature),
|
|
909
|
-
[]
|
|
910
|
-
);
|
|
911
|
-
useImperativeHandle5(
|
|
912
|
-
ref,
|
|
913
|
-
() => ({
|
|
914
|
-
get instance() {
|
|
915
|
-
return instanceRef.current;
|
|
916
|
-
}
|
|
917
|
-
}),
|
|
918
|
-
[]
|
|
919
|
-
);
|
|
920
|
-
useEffect8(() => {
|
|
921
|
-
const container = containerRef.current;
|
|
922
|
-
if (!container) return;
|
|
923
|
-
const options = {
|
|
924
|
-
theme,
|
|
925
|
-
darkMode: resolvedDarkMode,
|
|
926
|
-
onMarkClick: stableOnMarkClick,
|
|
927
|
-
onMarkHover: stableOnMarkHover,
|
|
928
|
-
responsive: true
|
|
929
|
-
};
|
|
930
|
-
instanceRef.current = createMap(container, spec, options);
|
|
931
|
-
specRef.current = JSON.stringify(spec);
|
|
932
|
-
return () => {
|
|
933
|
-
instanceRef.current?.destroy();
|
|
934
|
-
instanceRef.current = null;
|
|
935
|
-
};
|
|
936
|
-
}, [theme, resolvedDarkMode, stableOnMarkClick, stableOnMarkHover]);
|
|
937
|
-
useEffect8(() => {
|
|
938
|
-
const instance = instanceRef.current;
|
|
939
|
-
if (!instance) return;
|
|
940
|
-
const specString = JSON.stringify(spec);
|
|
941
|
-
if (specString === specRef.current) return;
|
|
942
|
-
specRef.current = specString;
|
|
943
|
-
instance.update(spec);
|
|
944
|
-
}, [spec]);
|
|
945
|
-
return /* @__PURE__ */ jsx7(
|
|
946
|
-
"div",
|
|
947
|
-
{
|
|
948
|
-
ref: containerRef,
|
|
949
|
-
className: className ? `oc-map-root ${className}` : "oc-map-root",
|
|
950
|
-
style
|
|
951
|
-
}
|
|
952
|
-
);
|
|
953
|
-
});
|
|
954
|
-
|
|
955
1091
|
// src/Sankey.tsx
|
|
956
1092
|
import {
|
|
957
1093
|
createSankey
|
|
@@ -1138,8 +1274,8 @@ var TileMap = forwardRef6(function TileMap2({ spec, theme: themeProp, darkMode,
|
|
|
1138
1274
|
// src/Visualization.tsx
|
|
1139
1275
|
import {
|
|
1140
1276
|
isBarListSpec,
|
|
1277
|
+
isGeoMapSpec,
|
|
1141
1278
|
isGraphSpec,
|
|
1142
|
-
isMapSpec,
|
|
1143
1279
|
isSankeySpec,
|
|
1144
1280
|
isTableSpec,
|
|
1145
1281
|
isTileMapSpec
|
|
@@ -1170,7 +1306,7 @@ function Visualization({ spec, theme, darkMode, className, style }) {
|
|
|
1170
1306
|
if (isBarListSpec(spec)) {
|
|
1171
1307
|
return /* @__PURE__ */ jsx10(BarList, { spec, theme, darkMode, className, style });
|
|
1172
1308
|
}
|
|
1173
|
-
if (
|
|
1309
|
+
if (isGeoMapSpec(spec)) {
|
|
1174
1310
|
return /* @__PURE__ */ jsx10(GeoMap, { spec, theme, darkMode, className, style });
|
|
1175
1311
|
}
|
|
1176
1312
|
return /* @__PURE__ */ jsx10(Chart, { spec, theme, darkMode, className, style });
|
|
@@ -1190,8 +1326,8 @@ export {
|
|
|
1190
1326
|
compile,
|
|
1191
1327
|
compileBarList,
|
|
1192
1328
|
compileChart,
|
|
1329
|
+
compileGeoMap,
|
|
1193
1330
|
compileGraph,
|
|
1194
|
-
compileMap,
|
|
1195
1331
|
compileSankey,
|
|
1196
1332
|
compileTable,
|
|
1197
1333
|
compileTileMap,
|
|
@@ -1200,6 +1336,7 @@ export {
|
|
|
1200
1336
|
exportPNG,
|
|
1201
1337
|
exportSVG,
|
|
1202
1338
|
exportSVGWithFonts,
|
|
1339
|
+
exportSpecSequence,
|
|
1203
1340
|
getChartRenderer,
|
|
1204
1341
|
normalizeSpec,
|
|
1205
1342
|
registerChartRenderer,
|