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