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