@opendata-ai/openchart-react 7.11.0 → 8.0.0-rc.2
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 +70 -5
- package/dist/index.js +293 -81
- package/dist/index.js.map +1 -1
- package/dist/styles.css +2 -1
- package/dist/styles.css.map +1 -0
- package/package.json +4 -4
- package/src/Chart.tsx +18 -0
- package/src/ChartStory.tsx +203 -0
- package/src/Map.tsx +131 -0
- package/src/Visualization.tsx +7 -0
- package/src/__tests__/ChartStory.test.tsx +92 -0
- package/src/index.ts +7 -0
package/dist/index.js
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
compileBarList,
|
|
14
14
|
compileChart,
|
|
15
15
|
compileGraph,
|
|
16
|
+
compileMap,
|
|
16
17
|
compileSankey,
|
|
17
18
|
compileTable,
|
|
18
19
|
compileTileMap,
|
|
@@ -132,12 +133,14 @@ function ChartInner({
|
|
|
132
133
|
onMarkHover,
|
|
133
134
|
onMarkLeave,
|
|
134
135
|
onLegendToggle,
|
|
136
|
+
onHighlightChange,
|
|
135
137
|
onAnnotationClick,
|
|
136
138
|
onAnnotationEdit,
|
|
137
139
|
onEdit,
|
|
138
140
|
onSelect,
|
|
139
141
|
onDeselect,
|
|
140
142
|
onTextEdit,
|
|
143
|
+
onReveal,
|
|
141
144
|
selectedElement: selectedElementProp,
|
|
142
145
|
highlight,
|
|
143
146
|
className,
|
|
@@ -157,12 +160,14 @@ function ChartInner({
|
|
|
157
160
|
onMarkHover,
|
|
158
161
|
onMarkLeave,
|
|
159
162
|
onLegendToggle,
|
|
163
|
+
onHighlightChange,
|
|
160
164
|
onAnnotationClick,
|
|
161
165
|
onAnnotationEdit,
|
|
162
166
|
onEdit,
|
|
163
167
|
onSelect,
|
|
164
168
|
onDeselect,
|
|
165
|
-
onTextEdit
|
|
169
|
+
onTextEdit,
|
|
170
|
+
onReveal
|
|
166
171
|
};
|
|
167
172
|
const stableOnDataPointClick = useCallback2(
|
|
168
173
|
(data) => handlersRef.current.onDataPointClick?.(data),
|
|
@@ -181,6 +186,10 @@ function ChartInner({
|
|
|
181
186
|
(series, visible) => handlersRef.current.onLegendToggle?.(series, visible),
|
|
182
187
|
[]
|
|
183
188
|
);
|
|
189
|
+
const stableOnHighlightChange = useCallback2(
|
|
190
|
+
(values) => handlersRef.current.onHighlightChange?.(values),
|
|
191
|
+
[]
|
|
192
|
+
);
|
|
184
193
|
const stableOnAnnotationClick = useCallback2(
|
|
185
194
|
(annotation, event) => handlersRef.current.onAnnotationClick?.(annotation, event),
|
|
186
195
|
[]
|
|
@@ -205,6 +214,10 @@ function ChartInner({
|
|
|
205
214
|
(element, oldText, newText) => handlersRef.current.onTextEdit?.(element, oldText, newText),
|
|
206
215
|
[]
|
|
207
216
|
);
|
|
217
|
+
const stableOnReveal = useCallback2(
|
|
218
|
+
(guess) => handlersRef.current.onReveal?.(guess),
|
|
219
|
+
[]
|
|
220
|
+
);
|
|
208
221
|
useImperativeHandle2(
|
|
209
222
|
ref,
|
|
210
223
|
() => ({
|
|
@@ -234,6 +247,7 @@ function ChartInner({
|
|
|
234
247
|
onMarkHover: stableOnMarkHover,
|
|
235
248
|
onMarkLeave: stableOnMarkLeave,
|
|
236
249
|
onLegendToggle: stableOnLegendToggle,
|
|
250
|
+
onHighlightChange: stableOnHighlightChange,
|
|
237
251
|
onAnnotationClick: stableOnAnnotationClick,
|
|
238
252
|
// Only include editing callbacks when the consumer provides them.
|
|
239
253
|
// The stable wrappers are always truthy, so gating on handlersRef
|
|
@@ -243,6 +257,7 @@ function ChartInner({
|
|
|
243
257
|
...handlersRef.current.onSelect ? { onSelect: stableOnSelect } : {},
|
|
244
258
|
...handlersRef.current.onDeselect ? { onDeselect: stableOnDeselect } : {},
|
|
245
259
|
...handlersRef.current.onTextEdit ? { onTextEdit: stableOnTextEdit } : {},
|
|
260
|
+
...handlersRef.current.onReveal ? { onReveal: stableOnReveal } : {},
|
|
246
261
|
...selectedElementProp ? { selectedElement: selectedElementProp } : {},
|
|
247
262
|
responsive: true
|
|
248
263
|
};
|
|
@@ -259,13 +274,15 @@ function ChartInner({
|
|
|
259
274
|
stableOnDataPointClick,
|
|
260
275
|
stableOnEdit,
|
|
261
276
|
stableOnLegendToggle,
|
|
277
|
+
stableOnHighlightChange,
|
|
262
278
|
stableOnMarkClick,
|
|
263
279
|
stableOnMarkHover,
|
|
264
280
|
stableOnMarkLeave,
|
|
265
281
|
stableOnAnnotationEdit,
|
|
266
282
|
stableOnSelect,
|
|
267
283
|
stableOnDeselect,
|
|
268
|
-
stableOnTextEdit
|
|
284
|
+
stableOnTextEdit,
|
|
285
|
+
stableOnReveal
|
|
269
286
|
]);
|
|
270
287
|
useEffect2(() => {
|
|
271
288
|
const chart = chartRef.current;
|
|
@@ -302,12 +319,125 @@ function ChartInner({
|
|
|
302
319
|
var Chart = forwardRef2(ChartInner);
|
|
303
320
|
Chart.displayName = "Chart";
|
|
304
321
|
|
|
322
|
+
// src/ChartStory.tsx
|
|
323
|
+
import {
|
|
324
|
+
createChartStory
|
|
325
|
+
} from "@opendata-ai/openchart-vanilla/story";
|
|
326
|
+
import { useEffect as useEffect3, useImperativeHandle as useImperativeHandle3, useRef as useRef3 } from "react";
|
|
327
|
+
import { jsx as jsx4, jsxs } from "react/jsx-runtime";
|
|
328
|
+
var sectionStyle = {
|
|
329
|
+
position: "relative",
|
|
330
|
+
display: "grid",
|
|
331
|
+
gridTemplateColumns: "minmax(0, 26rem) minmax(0, 1fr)",
|
|
332
|
+
gap: "3rem",
|
|
333
|
+
alignItems: "start"
|
|
334
|
+
};
|
|
335
|
+
var narrativeColumnStyle = {
|
|
336
|
+
position: "relative"
|
|
337
|
+
};
|
|
338
|
+
var stepStyle = {
|
|
339
|
+
minHeight: "80vh",
|
|
340
|
+
display: "flex",
|
|
341
|
+
alignItems: "center"
|
|
342
|
+
};
|
|
343
|
+
var panelStyle = {
|
|
344
|
+
position: "sticky",
|
|
345
|
+
top: "2rem",
|
|
346
|
+
height: "calc(100vh - 4rem)",
|
|
347
|
+
display: "flex",
|
|
348
|
+
alignItems: "center",
|
|
349
|
+
justifyContent: "center"
|
|
350
|
+
};
|
|
351
|
+
var chartMountStyle = {
|
|
352
|
+
width: "100%"
|
|
353
|
+
};
|
|
354
|
+
function ChartStory({
|
|
355
|
+
spec,
|
|
356
|
+
steps,
|
|
357
|
+
narrative,
|
|
358
|
+
step,
|
|
359
|
+
triggerPosition,
|
|
360
|
+
cameraMode,
|
|
361
|
+
mountOptions,
|
|
362
|
+
className,
|
|
363
|
+
style,
|
|
364
|
+
ref
|
|
365
|
+
}) {
|
|
366
|
+
const sectionRef = useRef3(null);
|
|
367
|
+
const chartMountRef = useRef3(null);
|
|
368
|
+
const stepRefs = useRef3([]);
|
|
369
|
+
const storyRef = useRef3(null);
|
|
370
|
+
if (narrative.length !== steps.length) {
|
|
371
|
+
console.warn(
|
|
372
|
+
`[openchart] ChartStory: narrative length (${narrative.length}) does not match steps length (${steps.length}). Each step should have a corresponding narrative element.`
|
|
373
|
+
);
|
|
374
|
+
}
|
|
375
|
+
const optionsRef = useRef3({ spec, steps, triggerPosition, cameraMode, mountOptions });
|
|
376
|
+
optionsRef.current = { spec, steps, triggerPosition, cameraMode, mountOptions };
|
|
377
|
+
useEffect3(() => {
|
|
378
|
+
const mount = chartMountRef.current;
|
|
379
|
+
const section = sectionRef.current;
|
|
380
|
+
if (!mount) return;
|
|
381
|
+
const opts = optionsRef.current;
|
|
382
|
+
const story = createChartStory(
|
|
383
|
+
mount,
|
|
384
|
+
{
|
|
385
|
+
spec: opts.spec,
|
|
386
|
+
steps: opts.steps,
|
|
387
|
+
triggerPosition: opts.triggerPosition,
|
|
388
|
+
cameraMode: opts.cameraMode
|
|
389
|
+
},
|
|
390
|
+
opts.mountOptions
|
|
391
|
+
);
|
|
392
|
+
storyRef.current = story;
|
|
393
|
+
if (section) story.setContainer(section);
|
|
394
|
+
stepRefs.current.forEach((el, i) => {
|
|
395
|
+
if (el) story.registerStep(i, el);
|
|
396
|
+
});
|
|
397
|
+
return () => {
|
|
398
|
+
story.destroy();
|
|
399
|
+
storyRef.current = null;
|
|
400
|
+
};
|
|
401
|
+
}, []);
|
|
402
|
+
useEffect3(() => {
|
|
403
|
+
if (step === void 0) return;
|
|
404
|
+
storyRef.current?.goTo(step);
|
|
405
|
+
}, [step]);
|
|
406
|
+
useImperativeHandle3(
|
|
407
|
+
ref,
|
|
408
|
+
() => ({
|
|
409
|
+
goTo(index) {
|
|
410
|
+
storyRef.current?.goTo(index);
|
|
411
|
+
},
|
|
412
|
+
get instance() {
|
|
413
|
+
return storyRef.current;
|
|
414
|
+
}
|
|
415
|
+
}),
|
|
416
|
+
[]
|
|
417
|
+
);
|
|
418
|
+
return /* @__PURE__ */ jsxs("section", { ref: sectionRef, className, style: { ...sectionStyle, ...style }, children: [
|
|
419
|
+
/* @__PURE__ */ jsx4("div", { style: narrativeColumnStyle, children: narrative.map((content, i) => /* @__PURE__ */ jsx4(
|
|
420
|
+
"div",
|
|
421
|
+
{
|
|
422
|
+
ref: (el) => {
|
|
423
|
+
stepRefs.current[i] = el;
|
|
424
|
+
},
|
|
425
|
+
"data-oc-story-step": i,
|
|
426
|
+
style: stepStyle,
|
|
427
|
+
children: /* @__PURE__ */ jsx4("div", { style: { maxWidth: "36rem" }, children: content })
|
|
428
|
+
},
|
|
429
|
+
i
|
|
430
|
+
)) }),
|
|
431
|
+
/* @__PURE__ */ jsx4("div", { style: panelStyle, children: /* @__PURE__ */ jsx4("div", { ref: chartMountRef, style: chartMountStyle }) })
|
|
432
|
+
] });
|
|
433
|
+
}
|
|
434
|
+
|
|
305
435
|
// src/DataTable.tsx
|
|
306
436
|
import {
|
|
307
437
|
createTable
|
|
308
438
|
} from "@opendata-ai/openchart-vanilla";
|
|
309
|
-
import { useCallback as useCallback3, useEffect as
|
|
310
|
-
import { jsx as
|
|
439
|
+
import { useCallback as useCallback3, useEffect as useEffect4, useRef as useRef4 } from "react";
|
|
440
|
+
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
311
441
|
function DataTable({
|
|
312
442
|
spec,
|
|
313
443
|
theme: themeProp,
|
|
@@ -326,9 +456,9 @@ function DataTable({
|
|
|
326
456
|
const contextDarkMode = useVizDarkMode();
|
|
327
457
|
const theme = themeProp ?? contextTheme;
|
|
328
458
|
const resolvedDarkMode = darkMode ?? contextDarkMode;
|
|
329
|
-
const containerRef =
|
|
330
|
-
const tableRef =
|
|
331
|
-
const handlersRef =
|
|
459
|
+
const containerRef = useRef4(null);
|
|
460
|
+
const tableRef = useRef4(null);
|
|
461
|
+
const handlersRef = useRef4({});
|
|
332
462
|
handlersRef.current = { onRowClick, onSortChange, onSearchChange, onPageChange };
|
|
333
463
|
const stableOnRowClick = useCallback3(
|
|
334
464
|
(row) => handlersRef.current.onRowClick?.(row),
|
|
@@ -342,9 +472,9 @@ function DataTable({
|
|
|
342
472
|
},
|
|
343
473
|
[]
|
|
344
474
|
);
|
|
345
|
-
const prevSpecRef =
|
|
475
|
+
const prevSpecRef = useRef4("");
|
|
346
476
|
const isControlled = sort !== void 0 || search !== void 0 || page !== void 0;
|
|
347
|
-
|
|
477
|
+
useEffect4(() => {
|
|
348
478
|
const container = containerRef.current;
|
|
349
479
|
if (!container) return;
|
|
350
480
|
const mountOptions = {
|
|
@@ -368,7 +498,7 @@ function DataTable({
|
|
|
368
498
|
tableRef.current = null;
|
|
369
499
|
};
|
|
370
500
|
}, [theme, resolvedDarkMode, isControlled, stableOnRowClick, stableOnStateChange]);
|
|
371
|
-
|
|
501
|
+
useEffect4(() => {
|
|
372
502
|
const table = tableRef.current;
|
|
373
503
|
if (!table || !isControlled) return;
|
|
374
504
|
table.setState({
|
|
@@ -377,7 +507,7 @@ function DataTable({
|
|
|
377
507
|
page: page ?? 0
|
|
378
508
|
});
|
|
379
509
|
}, [sort, search, page, isControlled]);
|
|
380
|
-
|
|
510
|
+
useEffect4(() => {
|
|
381
511
|
const table = tableRef.current;
|
|
382
512
|
if (!table) return;
|
|
383
513
|
const specString = JSON.stringify(spec);
|
|
@@ -386,7 +516,7 @@ function DataTable({
|
|
|
386
516
|
table.update(spec);
|
|
387
517
|
}
|
|
388
518
|
}, [spec]);
|
|
389
|
-
return /* @__PURE__ */
|
|
519
|
+
return /* @__PURE__ */ jsx5(
|
|
390
520
|
"div",
|
|
391
521
|
{
|
|
392
522
|
ref: containerRef,
|
|
@@ -403,11 +533,11 @@ import {
|
|
|
403
533
|
import {
|
|
404
534
|
forwardRef as forwardRef3,
|
|
405
535
|
useCallback as useCallback4,
|
|
406
|
-
useEffect as
|
|
407
|
-
useImperativeHandle as
|
|
408
|
-
useRef as
|
|
536
|
+
useEffect as useEffect5,
|
|
537
|
+
useImperativeHandle as useImperativeHandle4,
|
|
538
|
+
useRef as useRef5
|
|
409
539
|
} from "react";
|
|
410
|
-
import { jsx as
|
|
540
|
+
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
411
541
|
var Graph = forwardRef3(function Graph2({
|
|
412
542
|
spec,
|
|
413
543
|
theme: themeProp,
|
|
@@ -426,10 +556,10 @@ var Graph = forwardRef3(function Graph2({
|
|
|
426
556
|
const contextDarkMode = useVizDarkMode();
|
|
427
557
|
const theme = themeProp ?? contextTheme;
|
|
428
558
|
const resolvedDarkMode = darkMode ?? contextDarkMode;
|
|
429
|
-
const containerRef =
|
|
430
|
-
const graphRef =
|
|
431
|
-
const specRef =
|
|
432
|
-
const handlersRef =
|
|
559
|
+
const containerRef = useRef5(null);
|
|
560
|
+
const graphRef = useRef5(null);
|
|
561
|
+
const specRef = useRef5("");
|
|
562
|
+
const handlersRef = useRef5({});
|
|
433
563
|
handlersRef.current = {
|
|
434
564
|
onNodeClick,
|
|
435
565
|
onNodeDoubleClick,
|
|
@@ -457,7 +587,7 @@ var Graph = forwardRef3(function Graph2({
|
|
|
457
587
|
(nodeIds) => handlersRef.current.onSelectionChange?.(nodeIds),
|
|
458
588
|
[]
|
|
459
589
|
);
|
|
460
|
-
|
|
590
|
+
useImperativeHandle4(
|
|
461
591
|
ref,
|
|
462
592
|
() => ({
|
|
463
593
|
search(query) {
|
|
@@ -487,7 +617,7 @@ var Graph = forwardRef3(function Graph2({
|
|
|
487
617
|
}),
|
|
488
618
|
[]
|
|
489
619
|
);
|
|
490
|
-
|
|
620
|
+
useEffect5(() => {
|
|
491
621
|
const container = containerRef.current;
|
|
492
622
|
if (!container) return;
|
|
493
623
|
const options = {
|
|
@@ -519,7 +649,7 @@ var Graph = forwardRef3(function Graph2({
|
|
|
519
649
|
stableOnEdgeHover,
|
|
520
650
|
stableOnSelectionChange
|
|
521
651
|
]);
|
|
522
|
-
|
|
652
|
+
useEffect5(() => {
|
|
523
653
|
const graph = graphRef.current;
|
|
524
654
|
if (!graph) return;
|
|
525
655
|
const specString = JSON.stringify(spec);
|
|
@@ -543,7 +673,7 @@ var Graph = forwardRef3(function Graph2({
|
|
|
543
673
|
}
|
|
544
674
|
graph.update(spec);
|
|
545
675
|
}, [spec]);
|
|
546
|
-
return /* @__PURE__ */
|
|
676
|
+
return /* @__PURE__ */ jsx6(
|
|
547
677
|
"div",
|
|
548
678
|
{
|
|
549
679
|
ref: containerRef,
|
|
@@ -555,13 +685,13 @@ var Graph = forwardRef3(function Graph2({
|
|
|
555
685
|
|
|
556
686
|
// src/hooks.ts
|
|
557
687
|
import { createChart as createChart2 } from "@opendata-ai/openchart-vanilla";
|
|
558
|
-
import { useEffect as
|
|
688
|
+
import { useEffect as useEffect6, useRef as useRef6, useState } from "react";
|
|
559
689
|
function useChart(spec, options) {
|
|
560
|
-
const ref =
|
|
561
|
-
const chartRef =
|
|
690
|
+
const ref = useRef6(null);
|
|
691
|
+
const chartRef = useRef6(null);
|
|
562
692
|
const [layout, setLayout] = useState(null);
|
|
563
|
-
const specRef =
|
|
564
|
-
|
|
693
|
+
const specRef = useRef6("");
|
|
694
|
+
useEffect6(() => {
|
|
565
695
|
const container = ref.current;
|
|
566
696
|
if (!container) return;
|
|
567
697
|
const mountOpts = {
|
|
@@ -580,7 +710,7 @@ function useChart(spec, options) {
|
|
|
580
710
|
setLayout(null);
|
|
581
711
|
};
|
|
582
712
|
}, [options?.theme, options?.darkMode, options?.onDataPointClick, options?.responsive]);
|
|
583
|
-
|
|
713
|
+
useEffect6(() => {
|
|
584
714
|
const chart = chartRef.current;
|
|
585
715
|
if (!chart) return;
|
|
586
716
|
const specString = JSON.stringify(spec);
|
|
@@ -598,7 +728,7 @@ function useChart(spec, options) {
|
|
|
598
728
|
}
|
|
599
729
|
function useDarkMode(mode) {
|
|
600
730
|
const [isDark, setIsDark] = useState(() => resolveInitial(mode));
|
|
601
|
-
|
|
731
|
+
useEffect6(() => {
|
|
602
732
|
if (mode !== "auto") {
|
|
603
733
|
setIsDark(mode === "force");
|
|
604
734
|
return;
|
|
@@ -625,9 +755,9 @@ function resolveInitial(mode) {
|
|
|
625
755
|
}
|
|
626
756
|
|
|
627
757
|
// src/hooks/useGraph.ts
|
|
628
|
-
import { useCallback as useCallback5, useRef as
|
|
758
|
+
import { useCallback as useCallback5, useRef as useRef7 } from "react";
|
|
629
759
|
function useGraph() {
|
|
630
|
-
const ref =
|
|
760
|
+
const ref = useRef7(null);
|
|
631
761
|
const search = useCallback5((query) => {
|
|
632
762
|
ref.current?.search(query);
|
|
633
763
|
}, []);
|
|
@@ -661,10 +791,10 @@ function useGraph() {
|
|
|
661
791
|
import {
|
|
662
792
|
createTable as createTable2
|
|
663
793
|
} from "@opendata-ai/openchart-vanilla";
|
|
664
|
-
import { useCallback as useCallback6, useEffect as
|
|
794
|
+
import { useCallback as useCallback6, useEffect as useEffect7, useRef as useRef8, useState as useState2 } from "react";
|
|
665
795
|
function useTable(spec, options) {
|
|
666
|
-
const ref =
|
|
667
|
-
const tableRef =
|
|
796
|
+
const ref = useRef8(null);
|
|
797
|
+
const tableRef = useRef8(null);
|
|
668
798
|
const [state, setState] = useState2({
|
|
669
799
|
sort: null,
|
|
670
800
|
search: "",
|
|
@@ -678,7 +808,7 @@ function useTable(spec, options) {
|
|
|
678
808
|
},
|
|
679
809
|
[originalOnStateChange]
|
|
680
810
|
);
|
|
681
|
-
|
|
811
|
+
useEffect7(() => {
|
|
682
812
|
const container = ref.current;
|
|
683
813
|
if (!container) return;
|
|
684
814
|
const mountOpts = {
|
|
@@ -701,7 +831,7 @@ function useTable(spec, options) {
|
|
|
701
831
|
options,
|
|
702
832
|
spec
|
|
703
833
|
]);
|
|
704
|
-
|
|
834
|
+
useEffect7(() => {
|
|
705
835
|
const table = tableRef.current;
|
|
706
836
|
if (!table) return;
|
|
707
837
|
table.update(spec);
|
|
@@ -745,19 +875,94 @@ function useTableState(initialState) {
|
|
|
745
875
|
};
|
|
746
876
|
}
|
|
747
877
|
|
|
878
|
+
// src/Map.tsx
|
|
879
|
+
import { createMap } from "@opendata-ai/openchart-vanilla";
|
|
880
|
+
import {
|
|
881
|
+
forwardRef as forwardRef4,
|
|
882
|
+
useCallback as useCallback8,
|
|
883
|
+
useEffect as useEffect8,
|
|
884
|
+
useImperativeHandle as useImperativeHandle5,
|
|
885
|
+
useRef as useRef9
|
|
886
|
+
} from "react";
|
|
887
|
+
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
888
|
+
var GeoMap = forwardRef4(function GeoMap2({ spec, theme: themeProp, darkMode, onMarkClick, onMarkHover, className, style }, ref) {
|
|
889
|
+
const contextTheme = useVizTheme();
|
|
890
|
+
const contextDarkMode = useVizDarkMode();
|
|
891
|
+
const theme = themeProp ?? contextTheme;
|
|
892
|
+
const resolvedDarkMode = darkMode ?? contextDarkMode;
|
|
893
|
+
const containerRef = useRef9(null);
|
|
894
|
+
const instanceRef = useRef9(null);
|
|
895
|
+
const specRef = useRef9("");
|
|
896
|
+
const handlersRef = useRef9({});
|
|
897
|
+
handlersRef.current = {
|
|
898
|
+
onMarkClick,
|
|
899
|
+
onMarkHover
|
|
900
|
+
};
|
|
901
|
+
const stableOnMarkClick = useCallback8(
|
|
902
|
+
(feature) => handlersRef.current.onMarkClick?.(feature),
|
|
903
|
+
[]
|
|
904
|
+
);
|
|
905
|
+
const stableOnMarkHover = useCallback8(
|
|
906
|
+
(feature) => handlersRef.current.onMarkHover?.(feature),
|
|
907
|
+
[]
|
|
908
|
+
);
|
|
909
|
+
useImperativeHandle5(
|
|
910
|
+
ref,
|
|
911
|
+
() => ({
|
|
912
|
+
get instance() {
|
|
913
|
+
return instanceRef.current;
|
|
914
|
+
}
|
|
915
|
+
}),
|
|
916
|
+
[]
|
|
917
|
+
);
|
|
918
|
+
useEffect8(() => {
|
|
919
|
+
const container = containerRef.current;
|
|
920
|
+
if (!container) return;
|
|
921
|
+
const options = {
|
|
922
|
+
theme,
|
|
923
|
+
darkMode: resolvedDarkMode,
|
|
924
|
+
onMarkClick: stableOnMarkClick,
|
|
925
|
+
onMarkHover: stableOnMarkHover,
|
|
926
|
+
responsive: true
|
|
927
|
+
};
|
|
928
|
+
instanceRef.current = createMap(container, spec, options);
|
|
929
|
+
specRef.current = JSON.stringify(spec);
|
|
930
|
+
return () => {
|
|
931
|
+
instanceRef.current?.destroy();
|
|
932
|
+
instanceRef.current = null;
|
|
933
|
+
};
|
|
934
|
+
}, [theme, resolvedDarkMode, stableOnMarkClick, stableOnMarkHover]);
|
|
935
|
+
useEffect8(() => {
|
|
936
|
+
const instance = instanceRef.current;
|
|
937
|
+
if (!instance) return;
|
|
938
|
+
const specString = JSON.stringify(spec);
|
|
939
|
+
if (specString === specRef.current) return;
|
|
940
|
+
specRef.current = specString;
|
|
941
|
+
instance.update(spec);
|
|
942
|
+
}, [spec]);
|
|
943
|
+
return /* @__PURE__ */ jsx7(
|
|
944
|
+
"div",
|
|
945
|
+
{
|
|
946
|
+
ref: containerRef,
|
|
947
|
+
className: className ? `oc-map-root ${className}` : "oc-map-root",
|
|
948
|
+
style
|
|
949
|
+
}
|
|
950
|
+
);
|
|
951
|
+
});
|
|
952
|
+
|
|
748
953
|
// src/Sankey.tsx
|
|
749
954
|
import {
|
|
750
955
|
createSankey
|
|
751
956
|
} from "@opendata-ai/openchart-vanilla";
|
|
752
957
|
import {
|
|
753
|
-
forwardRef as
|
|
754
|
-
useCallback as
|
|
755
|
-
useEffect as
|
|
756
|
-
useImperativeHandle as
|
|
757
|
-
useRef as
|
|
958
|
+
forwardRef as forwardRef5,
|
|
959
|
+
useCallback as useCallback9,
|
|
960
|
+
useEffect as useEffect9,
|
|
961
|
+
useImperativeHandle as useImperativeHandle6,
|
|
962
|
+
useRef as useRef10
|
|
758
963
|
} from "react";
|
|
759
|
-
import { jsx as
|
|
760
|
-
var Sankey =
|
|
964
|
+
import { jsx as jsx8 } from "react/jsx-runtime";
|
|
965
|
+
var Sankey = forwardRef5(function Sankey2({
|
|
761
966
|
spec,
|
|
762
967
|
theme: themeProp,
|
|
763
968
|
darkMode,
|
|
@@ -772,33 +977,33 @@ var Sankey = forwardRef4(function Sankey2({
|
|
|
772
977
|
const contextDarkMode = useVizDarkMode();
|
|
773
978
|
const theme = themeProp ?? contextTheme;
|
|
774
979
|
const resolvedDarkMode = darkMode ?? contextDarkMode;
|
|
775
|
-
const containerRef =
|
|
776
|
-
const instanceRef =
|
|
777
|
-
const specRef =
|
|
778
|
-
const handlersRef =
|
|
980
|
+
const containerRef = useRef10(null);
|
|
981
|
+
const instanceRef = useRef10(null);
|
|
982
|
+
const specRef = useRef10("");
|
|
983
|
+
const handlersRef = useRef10({});
|
|
779
984
|
handlersRef.current = {
|
|
780
985
|
onNodeClick,
|
|
781
986
|
onLinkClick,
|
|
782
987
|
onNodeHover,
|
|
783
988
|
onLinkHover
|
|
784
989
|
};
|
|
785
|
-
const stableOnNodeClick =
|
|
990
|
+
const stableOnNodeClick = useCallback9(
|
|
786
991
|
(node) => handlersRef.current.onNodeClick?.(node),
|
|
787
992
|
[]
|
|
788
993
|
);
|
|
789
|
-
const stableOnLinkClick =
|
|
994
|
+
const stableOnLinkClick = useCallback9(
|
|
790
995
|
(link) => handlersRef.current.onLinkClick?.(link),
|
|
791
996
|
[]
|
|
792
997
|
);
|
|
793
|
-
const stableOnNodeHover =
|
|
998
|
+
const stableOnNodeHover = useCallback9(
|
|
794
999
|
(node) => handlersRef.current.onNodeHover?.(node),
|
|
795
1000
|
[]
|
|
796
1001
|
);
|
|
797
|
-
const stableOnLinkHover =
|
|
1002
|
+
const stableOnLinkHover = useCallback9(
|
|
798
1003
|
(link) => handlersRef.current.onLinkHover?.(link),
|
|
799
1004
|
[]
|
|
800
1005
|
);
|
|
801
|
-
|
|
1006
|
+
useImperativeHandle6(
|
|
802
1007
|
ref,
|
|
803
1008
|
() => ({
|
|
804
1009
|
get instance() {
|
|
@@ -807,7 +1012,7 @@ var Sankey = forwardRef4(function Sankey2({
|
|
|
807
1012
|
}),
|
|
808
1013
|
[]
|
|
809
1014
|
);
|
|
810
|
-
|
|
1015
|
+
useEffect9(() => {
|
|
811
1016
|
const container = containerRef.current;
|
|
812
1017
|
if (!container) return;
|
|
813
1018
|
const options = {
|
|
@@ -833,7 +1038,7 @@ var Sankey = forwardRef4(function Sankey2({
|
|
|
833
1038
|
stableOnNodeHover,
|
|
834
1039
|
stableOnLinkHover
|
|
835
1040
|
]);
|
|
836
|
-
|
|
1041
|
+
useEffect9(() => {
|
|
837
1042
|
const instance = instanceRef.current;
|
|
838
1043
|
if (!instance) return;
|
|
839
1044
|
const specString = JSON.stringify(spec);
|
|
@@ -841,7 +1046,7 @@ var Sankey = forwardRef4(function Sankey2({
|
|
|
841
1046
|
specRef.current = specString;
|
|
842
1047
|
instance.update(spec);
|
|
843
1048
|
}, [spec]);
|
|
844
|
-
return /* @__PURE__ */
|
|
1049
|
+
return /* @__PURE__ */ jsx8(
|
|
845
1050
|
"div",
|
|
846
1051
|
{
|
|
847
1052
|
ref: containerRef,
|
|
@@ -856,35 +1061,35 @@ import {
|
|
|
856
1061
|
createTileMap
|
|
857
1062
|
} from "@opendata-ai/openchart-vanilla";
|
|
858
1063
|
import {
|
|
859
|
-
forwardRef as
|
|
860
|
-
useCallback as
|
|
861
|
-
useEffect as
|
|
862
|
-
useImperativeHandle as
|
|
863
|
-
useRef as
|
|
1064
|
+
forwardRef as forwardRef6,
|
|
1065
|
+
useCallback as useCallback10,
|
|
1066
|
+
useEffect as useEffect10,
|
|
1067
|
+
useImperativeHandle as useImperativeHandle7,
|
|
1068
|
+
useRef as useRef11
|
|
864
1069
|
} from "react";
|
|
865
|
-
import { jsx as
|
|
866
|
-
var TileMap =
|
|
1070
|
+
import { jsx as jsx9 } from "react/jsx-runtime";
|
|
1071
|
+
var TileMap = forwardRef6(function TileMap2({ spec, theme: themeProp, darkMode, onTileClick, onTileHover, className, style }, ref) {
|
|
867
1072
|
const contextTheme = useVizTheme();
|
|
868
1073
|
const contextDarkMode = useVizDarkMode();
|
|
869
1074
|
const theme = themeProp ?? contextTheme;
|
|
870
1075
|
const resolvedDarkMode = darkMode ?? contextDarkMode;
|
|
871
|
-
const containerRef =
|
|
872
|
-
const instanceRef =
|
|
873
|
-
const specRef =
|
|
874
|
-
const handlersRef =
|
|
1076
|
+
const containerRef = useRef11(null);
|
|
1077
|
+
const instanceRef = useRef11(null);
|
|
1078
|
+
const specRef = useRef11("");
|
|
1079
|
+
const handlersRef = useRef11({});
|
|
875
1080
|
handlersRef.current = {
|
|
876
1081
|
onTileClick,
|
|
877
1082
|
onTileHover
|
|
878
1083
|
};
|
|
879
|
-
const stableOnTileClick =
|
|
1084
|
+
const stableOnTileClick = useCallback10(
|
|
880
1085
|
(tile) => handlersRef.current.onTileClick?.(tile),
|
|
881
1086
|
[]
|
|
882
1087
|
);
|
|
883
|
-
const stableOnTileHover =
|
|
1088
|
+
const stableOnTileHover = useCallback10(
|
|
884
1089
|
(tile) => handlersRef.current.onTileHover?.(tile),
|
|
885
1090
|
[]
|
|
886
1091
|
);
|
|
887
|
-
|
|
1092
|
+
useImperativeHandle7(
|
|
888
1093
|
ref,
|
|
889
1094
|
() => ({
|
|
890
1095
|
get instance() {
|
|
@@ -893,7 +1098,7 @@ var TileMap = forwardRef5(function TileMap2({ spec, theme: themeProp, darkMode,
|
|
|
893
1098
|
}),
|
|
894
1099
|
[]
|
|
895
1100
|
);
|
|
896
|
-
|
|
1101
|
+
useEffect10(() => {
|
|
897
1102
|
const container = containerRef.current;
|
|
898
1103
|
if (!container) return;
|
|
899
1104
|
const options = {
|
|
@@ -910,7 +1115,7 @@ var TileMap = forwardRef5(function TileMap2({ spec, theme: themeProp, darkMode,
|
|
|
910
1115
|
instanceRef.current = null;
|
|
911
1116
|
};
|
|
912
1117
|
}, [theme, resolvedDarkMode, stableOnTileClick, stableOnTileHover]);
|
|
913
|
-
|
|
1118
|
+
useEffect10(() => {
|
|
914
1119
|
const instance = instanceRef.current;
|
|
915
1120
|
if (!instance) return;
|
|
916
1121
|
const specString = JSON.stringify(spec);
|
|
@@ -918,7 +1123,7 @@ var TileMap = forwardRef5(function TileMap2({ spec, theme: themeProp, darkMode,
|
|
|
918
1123
|
specRef.current = specString;
|
|
919
1124
|
instance.update(spec);
|
|
920
1125
|
}, [spec]);
|
|
921
|
-
return /* @__PURE__ */
|
|
1126
|
+
return /* @__PURE__ */ jsx9(
|
|
922
1127
|
"div",
|
|
923
1128
|
{
|
|
924
1129
|
ref: containerRef,
|
|
@@ -932,14 +1137,15 @@ var TileMap = forwardRef5(function TileMap2({ spec, theme: themeProp, darkMode,
|
|
|
932
1137
|
import {
|
|
933
1138
|
isBarListSpec,
|
|
934
1139
|
isGraphSpec,
|
|
1140
|
+
isMapSpec,
|
|
935
1141
|
isSankeySpec,
|
|
936
1142
|
isTableSpec,
|
|
937
1143
|
isTileMapSpec
|
|
938
1144
|
} from "@opendata-ai/openchart-core";
|
|
939
|
-
import { jsx as
|
|
1145
|
+
import { jsx as jsx10 } from "react/jsx-runtime";
|
|
940
1146
|
function Visualization({ spec, theme, darkMode, className, style }) {
|
|
941
1147
|
if (isTableSpec(spec)) {
|
|
942
|
-
return /* @__PURE__ */
|
|
1148
|
+
return /* @__PURE__ */ jsx10(
|
|
943
1149
|
DataTable,
|
|
944
1150
|
{
|
|
945
1151
|
spec,
|
|
@@ -951,23 +1157,28 @@ function Visualization({ spec, theme, darkMode, className, style }) {
|
|
|
951
1157
|
);
|
|
952
1158
|
}
|
|
953
1159
|
if (isGraphSpec(spec)) {
|
|
954
|
-
return /* @__PURE__ */
|
|
1160
|
+
return /* @__PURE__ */ jsx10(Graph, { spec, theme, darkMode, className, style });
|
|
955
1161
|
}
|
|
956
1162
|
if (isSankeySpec(spec)) {
|
|
957
|
-
return /* @__PURE__ */
|
|
1163
|
+
return /* @__PURE__ */ jsx10(Sankey, { spec, theme, darkMode, className, style });
|
|
958
1164
|
}
|
|
959
1165
|
if (isTileMapSpec(spec)) {
|
|
960
|
-
return /* @__PURE__ */
|
|
1166
|
+
return /* @__PURE__ */ jsx10(TileMap, { spec, theme, darkMode, className, style });
|
|
961
1167
|
}
|
|
962
1168
|
if (isBarListSpec(spec)) {
|
|
963
|
-
return /* @__PURE__ */
|
|
1169
|
+
return /* @__PURE__ */ jsx10(BarList, { spec, theme, darkMode, className, style });
|
|
1170
|
+
}
|
|
1171
|
+
if (isMapSpec(spec)) {
|
|
1172
|
+
return /* @__PURE__ */ jsx10(GeoMap, { spec, theme, darkMode, className, style });
|
|
964
1173
|
}
|
|
965
|
-
return /* @__PURE__ */
|
|
1174
|
+
return /* @__PURE__ */ jsx10(Chart, { spec, theme, darkMode, className, style });
|
|
966
1175
|
}
|
|
967
1176
|
export {
|
|
968
1177
|
BarList,
|
|
969
1178
|
Chart,
|
|
1179
|
+
ChartStory,
|
|
970
1180
|
DataTable,
|
|
1181
|
+
GeoMap,
|
|
971
1182
|
Graph,
|
|
972
1183
|
Sankey,
|
|
973
1184
|
TileMap,
|
|
@@ -978,6 +1189,7 @@ export {
|
|
|
978
1189
|
compileBarList,
|
|
979
1190
|
compileChart,
|
|
980
1191
|
compileGraph,
|
|
1192
|
+
compileMap,
|
|
981
1193
|
compileSankey,
|
|
982
1194
|
compileTable,
|
|
983
1195
|
compileTileMap,
|