@opendata-ai/openchart-react 6.27.0 → 6.28.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 +26 -4
- package/dist/index.js +211 -125
- package/dist/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +4 -4
- package/src/BarList.tsx +126 -0
- package/src/Visualization.tsx +13 -1
- package/src/index.ts +4 -1
package/dist/index.js
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
import {
|
|
11
11
|
clearRenderers,
|
|
12
12
|
compile,
|
|
13
|
+
compileBarList,
|
|
13
14
|
compileChart,
|
|
14
15
|
compileGraph,
|
|
15
16
|
compileSankey,
|
|
@@ -21,8 +22,10 @@ import {
|
|
|
21
22
|
validateSpec
|
|
22
23
|
} from "@opendata-ai/openchart-engine";
|
|
23
24
|
|
|
24
|
-
// src/
|
|
25
|
-
import {
|
|
25
|
+
// src/BarList.tsx
|
|
26
|
+
import {
|
|
27
|
+
createBarList
|
|
28
|
+
} from "@opendata-ai/openchart-vanilla";
|
|
26
29
|
import {
|
|
27
30
|
forwardRef,
|
|
28
31
|
useCallback,
|
|
@@ -46,9 +49,81 @@ function VizThemeProvider({ theme, darkMode, children }) {
|
|
|
46
49
|
return /* @__PURE__ */ jsx(VizThemeContext.Provider, { value: theme, children: /* @__PURE__ */ jsx(VizDarkModeContext.Provider, { value: darkMode, children }) });
|
|
47
50
|
}
|
|
48
51
|
|
|
49
|
-
// src/
|
|
52
|
+
// src/BarList.tsx
|
|
50
53
|
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
51
|
-
var
|
|
54
|
+
var BarList = forwardRef(function BarList2({ spec, theme: themeProp, darkMode, onRowClick, onRowHover, className, style }, ref) {
|
|
55
|
+
const contextTheme = useVizTheme();
|
|
56
|
+
const contextDarkMode = useVizDarkMode();
|
|
57
|
+
const theme = themeProp ?? contextTheme;
|
|
58
|
+
const resolvedDarkMode = darkMode ?? contextDarkMode;
|
|
59
|
+
const containerRef = useRef(null);
|
|
60
|
+
const instanceRef = useRef(null);
|
|
61
|
+
const specRef = useRef("");
|
|
62
|
+
const handlersRef = useRef({});
|
|
63
|
+
handlersRef.current = { onRowClick, onRowHover };
|
|
64
|
+
const stableOnRowClick = useCallback(
|
|
65
|
+
(row) => handlersRef.current.onRowClick?.(row),
|
|
66
|
+
[]
|
|
67
|
+
);
|
|
68
|
+
const stableOnRowHover = useCallback(
|
|
69
|
+
(row) => handlersRef.current.onRowHover?.(row),
|
|
70
|
+
[]
|
|
71
|
+
);
|
|
72
|
+
useImperativeHandle(
|
|
73
|
+
ref,
|
|
74
|
+
() => ({
|
|
75
|
+
get instance() {
|
|
76
|
+
return instanceRef.current;
|
|
77
|
+
}
|
|
78
|
+
}),
|
|
79
|
+
[]
|
|
80
|
+
);
|
|
81
|
+
useEffect(() => {
|
|
82
|
+
const container = containerRef.current;
|
|
83
|
+
if (!container) return;
|
|
84
|
+
const options = {
|
|
85
|
+
theme,
|
|
86
|
+
darkMode: resolvedDarkMode,
|
|
87
|
+
onRowClick: stableOnRowClick,
|
|
88
|
+
onRowHover: stableOnRowHover,
|
|
89
|
+
responsive: true
|
|
90
|
+
};
|
|
91
|
+
instanceRef.current = createBarList(container, spec, options);
|
|
92
|
+
specRef.current = JSON.stringify(spec);
|
|
93
|
+
return () => {
|
|
94
|
+
instanceRef.current?.destroy();
|
|
95
|
+
instanceRef.current = null;
|
|
96
|
+
};
|
|
97
|
+
}, [theme, resolvedDarkMode, stableOnRowClick, stableOnRowHover]);
|
|
98
|
+
useEffect(() => {
|
|
99
|
+
const instance = instanceRef.current;
|
|
100
|
+
if (!instance) return;
|
|
101
|
+
const specString = JSON.stringify(spec);
|
|
102
|
+
if (specString === specRef.current) return;
|
|
103
|
+
specRef.current = specString;
|
|
104
|
+
instance.update(spec);
|
|
105
|
+
}, [spec]);
|
|
106
|
+
return /* @__PURE__ */ jsx2(
|
|
107
|
+
"div",
|
|
108
|
+
{
|
|
109
|
+
ref: containerRef,
|
|
110
|
+
className: className ? `oc-barlist-root ${className}` : "oc-barlist-root",
|
|
111
|
+
style
|
|
112
|
+
}
|
|
113
|
+
);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
// src/Chart.tsx
|
|
117
|
+
import { createChart } from "@opendata-ai/openchart-vanilla";
|
|
118
|
+
import {
|
|
119
|
+
forwardRef as forwardRef2,
|
|
120
|
+
useCallback as useCallback2,
|
|
121
|
+
useEffect as useEffect2,
|
|
122
|
+
useImperativeHandle as useImperativeHandle2,
|
|
123
|
+
useRef as useRef2
|
|
124
|
+
} from "react";
|
|
125
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
126
|
+
var Chart = forwardRef2(function Chart2({
|
|
52
127
|
spec,
|
|
53
128
|
theme: themeProp,
|
|
54
129
|
darkMode,
|
|
@@ -71,10 +146,10 @@ var Chart = forwardRef(function Chart2({
|
|
|
71
146
|
const contextDarkMode = useVizDarkMode();
|
|
72
147
|
const theme = themeProp ?? contextTheme;
|
|
73
148
|
const resolvedDarkMode = darkMode ?? contextDarkMode;
|
|
74
|
-
const containerRef =
|
|
75
|
-
const chartRef =
|
|
76
|
-
const specRef =
|
|
77
|
-
const handlersRef =
|
|
149
|
+
const containerRef = useRef2(null);
|
|
150
|
+
const chartRef = useRef2(null);
|
|
151
|
+
const specRef = useRef2("");
|
|
152
|
+
const handlersRef = useRef2({});
|
|
78
153
|
handlersRef.current = {
|
|
79
154
|
onDataPointClick,
|
|
80
155
|
onMarkClick,
|
|
@@ -88,48 +163,48 @@ var Chart = forwardRef(function Chart2({
|
|
|
88
163
|
onDeselect,
|
|
89
164
|
onTextEdit
|
|
90
165
|
};
|
|
91
|
-
const stableOnDataPointClick =
|
|
166
|
+
const stableOnDataPointClick = useCallback2(
|
|
92
167
|
(data) => handlersRef.current.onDataPointClick?.(data),
|
|
93
168
|
[]
|
|
94
169
|
);
|
|
95
|
-
const stableOnMarkClick =
|
|
170
|
+
const stableOnMarkClick = useCallback2(
|
|
96
171
|
(event) => handlersRef.current.onMarkClick?.(event),
|
|
97
172
|
[]
|
|
98
173
|
);
|
|
99
|
-
const stableOnMarkHover =
|
|
174
|
+
const stableOnMarkHover = useCallback2(
|
|
100
175
|
(event) => handlersRef.current.onMarkHover?.(event),
|
|
101
176
|
[]
|
|
102
177
|
);
|
|
103
|
-
const stableOnMarkLeave =
|
|
104
|
-
const stableOnLegendToggle =
|
|
178
|
+
const stableOnMarkLeave = useCallback2(() => handlersRef.current.onMarkLeave?.(), []);
|
|
179
|
+
const stableOnLegendToggle = useCallback2(
|
|
105
180
|
(series, visible) => handlersRef.current.onLegendToggle?.(series, visible),
|
|
106
181
|
[]
|
|
107
182
|
);
|
|
108
|
-
const stableOnAnnotationClick =
|
|
183
|
+
const stableOnAnnotationClick = useCallback2(
|
|
109
184
|
(annotation, event) => handlersRef.current.onAnnotationClick?.(annotation, event),
|
|
110
185
|
[]
|
|
111
186
|
);
|
|
112
|
-
const stableOnAnnotationEdit =
|
|
187
|
+
const stableOnAnnotationEdit = useCallback2(
|
|
113
188
|
(annotation, updatedOffset) => handlersRef.current.onAnnotationEdit?.(annotation, updatedOffset),
|
|
114
189
|
[]
|
|
115
190
|
);
|
|
116
|
-
const stableOnEdit =
|
|
191
|
+
const stableOnEdit = useCallback2(
|
|
117
192
|
(edit) => handlersRef.current.onEdit?.(edit),
|
|
118
193
|
[]
|
|
119
194
|
);
|
|
120
|
-
const stableOnSelect =
|
|
195
|
+
const stableOnSelect = useCallback2(
|
|
121
196
|
(element) => handlersRef.current.onSelect?.(element),
|
|
122
197
|
[]
|
|
123
198
|
);
|
|
124
|
-
const stableOnDeselect =
|
|
199
|
+
const stableOnDeselect = useCallback2(
|
|
125
200
|
(element) => handlersRef.current.onDeselect?.(element),
|
|
126
201
|
[]
|
|
127
202
|
);
|
|
128
|
-
const stableOnTextEdit =
|
|
203
|
+
const stableOnTextEdit = useCallback2(
|
|
129
204
|
(element, oldText, newText) => handlersRef.current.onTextEdit?.(element, oldText, newText),
|
|
130
205
|
[]
|
|
131
206
|
);
|
|
132
|
-
|
|
207
|
+
useImperativeHandle2(
|
|
133
208
|
ref,
|
|
134
209
|
() => ({
|
|
135
210
|
getSelectedElement() {
|
|
@@ -147,7 +222,7 @@ var Chart = forwardRef(function Chart2({
|
|
|
147
222
|
}),
|
|
148
223
|
[]
|
|
149
224
|
);
|
|
150
|
-
|
|
225
|
+
useEffect2(() => {
|
|
151
226
|
const container = containerRef.current;
|
|
152
227
|
if (!container) return;
|
|
153
228
|
const options = {
|
|
@@ -191,7 +266,7 @@ var Chart = forwardRef(function Chart2({
|
|
|
191
266
|
stableOnDeselect,
|
|
192
267
|
stableOnTextEdit
|
|
193
268
|
]);
|
|
194
|
-
|
|
269
|
+
useEffect2(() => {
|
|
195
270
|
const chart = chartRef.current;
|
|
196
271
|
if (!chart) return;
|
|
197
272
|
const specString = JSON.stringify(spec);
|
|
@@ -200,7 +275,7 @@ var Chart = forwardRef(function Chart2({
|
|
|
200
275
|
chart.update(spec);
|
|
201
276
|
}
|
|
202
277
|
}, [spec]);
|
|
203
|
-
|
|
278
|
+
useEffect2(() => {
|
|
204
279
|
const chart = chartRef.current;
|
|
205
280
|
if (!chart || !chart.select) return;
|
|
206
281
|
if (selectedElementProp) {
|
|
@@ -209,7 +284,7 @@ var Chart = forwardRef(function Chart2({
|
|
|
209
284
|
chart.deselect();
|
|
210
285
|
}
|
|
211
286
|
}, [selectedElementProp]);
|
|
212
|
-
return /* @__PURE__ */
|
|
287
|
+
return /* @__PURE__ */ jsx3(
|
|
213
288
|
"div",
|
|
214
289
|
{
|
|
215
290
|
ref: containerRef,
|
|
@@ -223,8 +298,8 @@ var Chart = forwardRef(function Chart2({
|
|
|
223
298
|
import {
|
|
224
299
|
createTable
|
|
225
300
|
} from "@opendata-ai/openchart-vanilla";
|
|
226
|
-
import { useCallback as
|
|
227
|
-
import { jsx as
|
|
301
|
+
import { useCallback as useCallback3, useEffect as useEffect3, useRef as useRef3 } from "react";
|
|
302
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
228
303
|
function DataTable({
|
|
229
304
|
spec,
|
|
230
305
|
theme: themeProp,
|
|
@@ -243,15 +318,15 @@ function DataTable({
|
|
|
243
318
|
const contextDarkMode = useVizDarkMode();
|
|
244
319
|
const theme = themeProp ?? contextTheme;
|
|
245
320
|
const resolvedDarkMode = darkMode ?? contextDarkMode;
|
|
246
|
-
const containerRef =
|
|
247
|
-
const tableRef =
|
|
248
|
-
const handlersRef =
|
|
321
|
+
const containerRef = useRef3(null);
|
|
322
|
+
const tableRef = useRef3(null);
|
|
323
|
+
const handlersRef = useRef3({});
|
|
249
324
|
handlersRef.current = { onRowClick, onSortChange, onSearchChange, onPageChange };
|
|
250
|
-
const stableOnRowClick =
|
|
325
|
+
const stableOnRowClick = useCallback3(
|
|
251
326
|
(row) => handlersRef.current.onRowClick?.(row),
|
|
252
327
|
[]
|
|
253
328
|
);
|
|
254
|
-
const stableOnStateChange =
|
|
329
|
+
const stableOnStateChange = useCallback3(
|
|
255
330
|
(state) => {
|
|
256
331
|
if (state.sort !== void 0) handlersRef.current.onSortChange?.(state.sort);
|
|
257
332
|
if (state.search !== void 0) handlersRef.current.onSearchChange?.(state.search);
|
|
@@ -259,9 +334,9 @@ function DataTable({
|
|
|
259
334
|
},
|
|
260
335
|
[]
|
|
261
336
|
);
|
|
262
|
-
const prevSpecRef =
|
|
337
|
+
const prevSpecRef = useRef3("");
|
|
263
338
|
const isControlled = sort !== void 0 || search !== void 0 || page !== void 0;
|
|
264
|
-
|
|
339
|
+
useEffect3(() => {
|
|
265
340
|
const container = containerRef.current;
|
|
266
341
|
if (!container) return;
|
|
267
342
|
const mountOptions = {
|
|
@@ -285,7 +360,7 @@ function DataTable({
|
|
|
285
360
|
tableRef.current = null;
|
|
286
361
|
};
|
|
287
362
|
}, [theme, resolvedDarkMode, isControlled, stableOnRowClick, stableOnStateChange]);
|
|
288
|
-
|
|
363
|
+
useEffect3(() => {
|
|
289
364
|
const table = tableRef.current;
|
|
290
365
|
if (!table || !isControlled) return;
|
|
291
366
|
table.setState({
|
|
@@ -294,7 +369,7 @@ function DataTable({
|
|
|
294
369
|
page: page ?? 0
|
|
295
370
|
});
|
|
296
371
|
}, [sort, search, page, isControlled]);
|
|
297
|
-
|
|
372
|
+
useEffect3(() => {
|
|
298
373
|
const table = tableRef.current;
|
|
299
374
|
if (!table) return;
|
|
300
375
|
const specString = JSON.stringify(spec);
|
|
@@ -303,7 +378,7 @@ function DataTable({
|
|
|
303
378
|
table.update(spec);
|
|
304
379
|
}
|
|
305
380
|
}, [spec]);
|
|
306
|
-
return /* @__PURE__ */
|
|
381
|
+
return /* @__PURE__ */ jsx4(
|
|
307
382
|
"div",
|
|
308
383
|
{
|
|
309
384
|
ref: containerRef,
|
|
@@ -318,14 +393,14 @@ import {
|
|
|
318
393
|
createGraph
|
|
319
394
|
} from "@opendata-ai/openchart-vanilla";
|
|
320
395
|
import {
|
|
321
|
-
forwardRef as
|
|
322
|
-
useCallback as
|
|
323
|
-
useEffect as
|
|
324
|
-
useImperativeHandle as
|
|
325
|
-
useRef as
|
|
396
|
+
forwardRef as forwardRef3,
|
|
397
|
+
useCallback as useCallback4,
|
|
398
|
+
useEffect as useEffect4,
|
|
399
|
+
useImperativeHandle as useImperativeHandle3,
|
|
400
|
+
useRef as useRef4
|
|
326
401
|
} from "react";
|
|
327
|
-
import { jsx as
|
|
328
|
-
var Graph =
|
|
402
|
+
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
403
|
+
var Graph = forwardRef3(function Graph2({
|
|
329
404
|
spec,
|
|
330
405
|
theme: themeProp,
|
|
331
406
|
darkMode,
|
|
@@ -343,10 +418,10 @@ var Graph = forwardRef2(function Graph2({
|
|
|
343
418
|
const contextDarkMode = useVizDarkMode();
|
|
344
419
|
const theme = themeProp ?? contextTheme;
|
|
345
420
|
const resolvedDarkMode = darkMode ?? contextDarkMode;
|
|
346
|
-
const containerRef =
|
|
347
|
-
const graphRef =
|
|
348
|
-
const specRef =
|
|
349
|
-
const handlersRef =
|
|
421
|
+
const containerRef = useRef4(null);
|
|
422
|
+
const graphRef = useRef4(null);
|
|
423
|
+
const specRef = useRef4("");
|
|
424
|
+
const handlersRef = useRef4({});
|
|
350
425
|
handlersRef.current = {
|
|
351
426
|
onNodeClick,
|
|
352
427
|
onNodeDoubleClick,
|
|
@@ -354,27 +429,27 @@ var Graph = forwardRef2(function Graph2({
|
|
|
354
429
|
onEdgeHover,
|
|
355
430
|
onSelectionChange
|
|
356
431
|
};
|
|
357
|
-
const stableOnNodeClick =
|
|
432
|
+
const stableOnNodeClick = useCallback4(
|
|
358
433
|
(node) => handlersRef.current.onNodeClick?.(node),
|
|
359
434
|
[]
|
|
360
435
|
);
|
|
361
|
-
const stableOnNodeDoubleClick =
|
|
436
|
+
const stableOnNodeDoubleClick = useCallback4(
|
|
362
437
|
(node) => handlersRef.current.onNodeDoubleClick?.(node),
|
|
363
438
|
[]
|
|
364
439
|
);
|
|
365
|
-
const stableOnNodeHover =
|
|
440
|
+
const stableOnNodeHover = useCallback4(
|
|
366
441
|
(node) => handlersRef.current.onNodeHover?.(node),
|
|
367
442
|
[]
|
|
368
443
|
);
|
|
369
|
-
const stableOnEdgeHover =
|
|
444
|
+
const stableOnEdgeHover = useCallback4(
|
|
370
445
|
(edge) => handlersRef.current.onEdgeHover?.(edge),
|
|
371
446
|
[]
|
|
372
447
|
);
|
|
373
|
-
const stableOnSelectionChange =
|
|
448
|
+
const stableOnSelectionChange = useCallback4(
|
|
374
449
|
(nodeIds) => handlersRef.current.onSelectionChange?.(nodeIds),
|
|
375
450
|
[]
|
|
376
451
|
);
|
|
377
|
-
|
|
452
|
+
useImperativeHandle3(
|
|
378
453
|
ref,
|
|
379
454
|
() => ({
|
|
380
455
|
search(query) {
|
|
@@ -404,7 +479,7 @@ var Graph = forwardRef2(function Graph2({
|
|
|
404
479
|
}),
|
|
405
480
|
[]
|
|
406
481
|
);
|
|
407
|
-
|
|
482
|
+
useEffect4(() => {
|
|
408
483
|
const container = containerRef.current;
|
|
409
484
|
if (!container) return;
|
|
410
485
|
const options = {
|
|
@@ -436,7 +511,7 @@ var Graph = forwardRef2(function Graph2({
|
|
|
436
511
|
stableOnEdgeHover,
|
|
437
512
|
stableOnSelectionChange
|
|
438
513
|
]);
|
|
439
|
-
|
|
514
|
+
useEffect4(() => {
|
|
440
515
|
const graph = graphRef.current;
|
|
441
516
|
if (!graph) return;
|
|
442
517
|
const specString = JSON.stringify(spec);
|
|
@@ -460,7 +535,7 @@ var Graph = forwardRef2(function Graph2({
|
|
|
460
535
|
}
|
|
461
536
|
graph.update(spec);
|
|
462
537
|
}, [spec]);
|
|
463
|
-
return /* @__PURE__ */
|
|
538
|
+
return /* @__PURE__ */ jsx5(
|
|
464
539
|
"div",
|
|
465
540
|
{
|
|
466
541
|
ref: containerRef,
|
|
@@ -472,13 +547,13 @@ var Graph = forwardRef2(function Graph2({
|
|
|
472
547
|
|
|
473
548
|
// src/hooks.ts
|
|
474
549
|
import { createChart as createChart2 } from "@opendata-ai/openchart-vanilla";
|
|
475
|
-
import { useEffect as
|
|
550
|
+
import { useEffect as useEffect5, useRef as useRef5, useState } from "react";
|
|
476
551
|
function useChart(spec, options) {
|
|
477
|
-
const ref =
|
|
478
|
-
const chartRef =
|
|
552
|
+
const ref = useRef5(null);
|
|
553
|
+
const chartRef = useRef5(null);
|
|
479
554
|
const [layout, setLayout] = useState(null);
|
|
480
|
-
const specRef =
|
|
481
|
-
|
|
555
|
+
const specRef = useRef5("");
|
|
556
|
+
useEffect5(() => {
|
|
482
557
|
const container = ref.current;
|
|
483
558
|
if (!container) return;
|
|
484
559
|
const mountOpts = {
|
|
@@ -497,7 +572,7 @@ function useChart(spec, options) {
|
|
|
497
572
|
setLayout(null);
|
|
498
573
|
};
|
|
499
574
|
}, [options?.theme, options?.darkMode, options?.onDataPointClick, options?.responsive]);
|
|
500
|
-
|
|
575
|
+
useEffect5(() => {
|
|
501
576
|
const chart = chartRef.current;
|
|
502
577
|
if (!chart) return;
|
|
503
578
|
const specString = JSON.stringify(spec);
|
|
@@ -515,7 +590,7 @@ function useChart(spec, options) {
|
|
|
515
590
|
}
|
|
516
591
|
function useDarkMode(mode) {
|
|
517
592
|
const [isDark, setIsDark] = useState(() => resolveInitial(mode));
|
|
518
|
-
|
|
593
|
+
useEffect5(() => {
|
|
519
594
|
if (mode !== "auto") {
|
|
520
595
|
setIsDark(mode === "force");
|
|
521
596
|
return;
|
|
@@ -542,25 +617,25 @@ function resolveInitial(mode) {
|
|
|
542
617
|
}
|
|
543
618
|
|
|
544
619
|
// src/hooks/useGraph.ts
|
|
545
|
-
import { useCallback as
|
|
620
|
+
import { useCallback as useCallback5, useRef as useRef6 } from "react";
|
|
546
621
|
function useGraph() {
|
|
547
|
-
const ref =
|
|
548
|
-
const search =
|
|
622
|
+
const ref = useRef6(null);
|
|
623
|
+
const search = useCallback5((query) => {
|
|
549
624
|
ref.current?.search(query);
|
|
550
625
|
}, []);
|
|
551
|
-
const clearSearch =
|
|
626
|
+
const clearSearch = useCallback5(() => {
|
|
552
627
|
ref.current?.clearSearch();
|
|
553
628
|
}, []);
|
|
554
|
-
const zoomToFit =
|
|
629
|
+
const zoomToFit = useCallback5(() => {
|
|
555
630
|
ref.current?.zoomToFit();
|
|
556
631
|
}, []);
|
|
557
|
-
const zoomToNode =
|
|
632
|
+
const zoomToNode = useCallback5((nodeId) => {
|
|
558
633
|
ref.current?.zoomToNode(nodeId);
|
|
559
634
|
}, []);
|
|
560
|
-
const selectNode =
|
|
635
|
+
const selectNode = useCallback5((nodeId) => {
|
|
561
636
|
ref.current?.selectNode(nodeId);
|
|
562
637
|
}, []);
|
|
563
|
-
const getSelectedNodes =
|
|
638
|
+
const getSelectedNodes = useCallback5(() => {
|
|
564
639
|
return ref.current?.getSelectedNodes() ?? [];
|
|
565
640
|
}, []);
|
|
566
641
|
return {
|
|
@@ -578,24 +653,24 @@ function useGraph() {
|
|
|
578
653
|
import {
|
|
579
654
|
createTable as createTable2
|
|
580
655
|
} from "@opendata-ai/openchart-vanilla";
|
|
581
|
-
import { useCallback as
|
|
656
|
+
import { useCallback as useCallback6, useEffect as useEffect6, useRef as useRef7, useState as useState2 } from "react";
|
|
582
657
|
function useTable(spec, options) {
|
|
583
|
-
const ref =
|
|
584
|
-
const tableRef =
|
|
658
|
+
const ref = useRef7(null);
|
|
659
|
+
const tableRef = useRef7(null);
|
|
585
660
|
const [state, setState] = useState2({
|
|
586
661
|
sort: null,
|
|
587
662
|
search: "",
|
|
588
663
|
page: 0
|
|
589
664
|
});
|
|
590
665
|
const originalOnStateChange = options?.onStateChange;
|
|
591
|
-
const handleStateChange =
|
|
666
|
+
const handleStateChange = useCallback6(
|
|
592
667
|
(newState) => {
|
|
593
668
|
setState(newState);
|
|
594
669
|
originalOnStateChange?.(newState);
|
|
595
670
|
},
|
|
596
671
|
[originalOnStateChange]
|
|
597
672
|
);
|
|
598
|
-
|
|
673
|
+
useEffect6(() => {
|
|
599
674
|
const container = ref.current;
|
|
600
675
|
if (!container) return;
|
|
601
676
|
const mountOpts = {
|
|
@@ -618,7 +693,7 @@ function useTable(spec, options) {
|
|
|
618
693
|
options,
|
|
619
694
|
spec
|
|
620
695
|
]);
|
|
621
|
-
|
|
696
|
+
useEffect6(() => {
|
|
622
697
|
const table = tableRef.current;
|
|
623
698
|
if (!table) return;
|
|
624
699
|
table.update(spec);
|
|
@@ -632,21 +707,21 @@ function useTable(spec, options) {
|
|
|
632
707
|
}
|
|
633
708
|
|
|
634
709
|
// src/hooks/useTableState.ts
|
|
635
|
-
import { useCallback as
|
|
710
|
+
import { useCallback as useCallback7, useState as useState3 } from "react";
|
|
636
711
|
function useTableState(initialState) {
|
|
637
712
|
const [sort, setSortInternal] = useState3(initialState?.sort ?? null);
|
|
638
713
|
const [search, setSearchInternal] = useState3(initialState?.search ?? "");
|
|
639
714
|
const [page, setPageInternal] = useState3(initialState?.page ?? 0);
|
|
640
|
-
const setSort =
|
|
715
|
+
const setSort = useCallback7((newSort) => {
|
|
641
716
|
setSortInternal(newSort);
|
|
642
717
|
}, []);
|
|
643
|
-
const setSearch =
|
|
718
|
+
const setSearch = useCallback7((query) => {
|
|
644
719
|
setSearchInternal(query);
|
|
645
720
|
}, []);
|
|
646
|
-
const setPage =
|
|
721
|
+
const setPage = useCallback7((newPage) => {
|
|
647
722
|
setPageInternal(newPage);
|
|
648
723
|
}, []);
|
|
649
|
-
const resetState =
|
|
724
|
+
const resetState = useCallback7(() => {
|
|
650
725
|
setSortInternal(initialState?.sort ?? null);
|
|
651
726
|
setSearchInternal(initialState?.search ?? "");
|
|
652
727
|
setPageInternal(initialState?.page ?? 0);
|
|
@@ -667,14 +742,14 @@ import {
|
|
|
667
742
|
createSankey
|
|
668
743
|
} from "@opendata-ai/openchart-vanilla";
|
|
669
744
|
import {
|
|
670
|
-
forwardRef as
|
|
671
|
-
useCallback as
|
|
672
|
-
useEffect as
|
|
673
|
-
useImperativeHandle as
|
|
674
|
-
useRef as
|
|
745
|
+
forwardRef as forwardRef4,
|
|
746
|
+
useCallback as useCallback8,
|
|
747
|
+
useEffect as useEffect7,
|
|
748
|
+
useImperativeHandle as useImperativeHandle4,
|
|
749
|
+
useRef as useRef8
|
|
675
750
|
} from "react";
|
|
676
|
-
import { jsx as
|
|
677
|
-
var Sankey =
|
|
751
|
+
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
752
|
+
var Sankey = forwardRef4(function Sankey2({
|
|
678
753
|
spec,
|
|
679
754
|
theme: themeProp,
|
|
680
755
|
darkMode,
|
|
@@ -689,33 +764,33 @@ var Sankey = forwardRef3(function Sankey2({
|
|
|
689
764
|
const contextDarkMode = useVizDarkMode();
|
|
690
765
|
const theme = themeProp ?? contextTheme;
|
|
691
766
|
const resolvedDarkMode = darkMode ?? contextDarkMode;
|
|
692
|
-
const containerRef =
|
|
693
|
-
const instanceRef =
|
|
694
|
-
const specRef =
|
|
695
|
-
const handlersRef =
|
|
767
|
+
const containerRef = useRef8(null);
|
|
768
|
+
const instanceRef = useRef8(null);
|
|
769
|
+
const specRef = useRef8("");
|
|
770
|
+
const handlersRef = useRef8({});
|
|
696
771
|
handlersRef.current = {
|
|
697
772
|
onNodeClick,
|
|
698
773
|
onLinkClick,
|
|
699
774
|
onNodeHover,
|
|
700
775
|
onLinkHover
|
|
701
776
|
};
|
|
702
|
-
const stableOnNodeClick =
|
|
777
|
+
const stableOnNodeClick = useCallback8(
|
|
703
778
|
(node) => handlersRef.current.onNodeClick?.(node),
|
|
704
779
|
[]
|
|
705
780
|
);
|
|
706
|
-
const stableOnLinkClick =
|
|
781
|
+
const stableOnLinkClick = useCallback8(
|
|
707
782
|
(link) => handlersRef.current.onLinkClick?.(link),
|
|
708
783
|
[]
|
|
709
784
|
);
|
|
710
|
-
const stableOnNodeHover =
|
|
785
|
+
const stableOnNodeHover = useCallback8(
|
|
711
786
|
(node) => handlersRef.current.onNodeHover?.(node),
|
|
712
787
|
[]
|
|
713
788
|
);
|
|
714
|
-
const stableOnLinkHover =
|
|
789
|
+
const stableOnLinkHover = useCallback8(
|
|
715
790
|
(link) => handlersRef.current.onLinkHover?.(link),
|
|
716
791
|
[]
|
|
717
792
|
);
|
|
718
|
-
|
|
793
|
+
useImperativeHandle4(
|
|
719
794
|
ref,
|
|
720
795
|
() => ({
|
|
721
796
|
get instance() {
|
|
@@ -724,7 +799,7 @@ var Sankey = forwardRef3(function Sankey2({
|
|
|
724
799
|
}),
|
|
725
800
|
[]
|
|
726
801
|
);
|
|
727
|
-
|
|
802
|
+
useEffect7(() => {
|
|
728
803
|
const container = containerRef.current;
|
|
729
804
|
if (!container) return;
|
|
730
805
|
const options = {
|
|
@@ -750,7 +825,7 @@ var Sankey = forwardRef3(function Sankey2({
|
|
|
750
825
|
stableOnNodeHover,
|
|
751
826
|
stableOnLinkHover
|
|
752
827
|
]);
|
|
753
|
-
|
|
828
|
+
useEffect7(() => {
|
|
754
829
|
const instance = instanceRef.current;
|
|
755
830
|
if (!instance) return;
|
|
756
831
|
const specString = JSON.stringify(spec);
|
|
@@ -758,7 +833,7 @@ var Sankey = forwardRef3(function Sankey2({
|
|
|
758
833
|
specRef.current = specString;
|
|
759
834
|
instance.update(spec);
|
|
760
835
|
}, [spec]);
|
|
761
|
-
return /* @__PURE__ */
|
|
836
|
+
return /* @__PURE__ */ jsx6(
|
|
762
837
|
"div",
|
|
763
838
|
{
|
|
764
839
|
ref: containerRef,
|
|
@@ -773,35 +848,35 @@ import {
|
|
|
773
848
|
createTileMap
|
|
774
849
|
} from "@opendata-ai/openchart-vanilla";
|
|
775
850
|
import {
|
|
776
|
-
forwardRef as
|
|
777
|
-
useCallback as
|
|
778
|
-
useEffect as
|
|
779
|
-
useImperativeHandle as
|
|
780
|
-
useRef as
|
|
851
|
+
forwardRef as forwardRef5,
|
|
852
|
+
useCallback as useCallback9,
|
|
853
|
+
useEffect as useEffect8,
|
|
854
|
+
useImperativeHandle as useImperativeHandle5,
|
|
855
|
+
useRef as useRef9
|
|
781
856
|
} from "react";
|
|
782
|
-
import { jsx as
|
|
783
|
-
var TileMap =
|
|
857
|
+
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
858
|
+
var TileMap = forwardRef5(function TileMap2({ spec, theme: themeProp, darkMode, onTileClick, onTileHover, className, style }, ref) {
|
|
784
859
|
const contextTheme = useVizTheme();
|
|
785
860
|
const contextDarkMode = useVizDarkMode();
|
|
786
861
|
const theme = themeProp ?? contextTheme;
|
|
787
862
|
const resolvedDarkMode = darkMode ?? contextDarkMode;
|
|
788
|
-
const containerRef =
|
|
789
|
-
const instanceRef =
|
|
790
|
-
const specRef =
|
|
791
|
-
const handlersRef =
|
|
863
|
+
const containerRef = useRef9(null);
|
|
864
|
+
const instanceRef = useRef9(null);
|
|
865
|
+
const specRef = useRef9("");
|
|
866
|
+
const handlersRef = useRef9({});
|
|
792
867
|
handlersRef.current = {
|
|
793
868
|
onTileClick,
|
|
794
869
|
onTileHover
|
|
795
870
|
};
|
|
796
|
-
const stableOnTileClick =
|
|
871
|
+
const stableOnTileClick = useCallback9(
|
|
797
872
|
(tile) => handlersRef.current.onTileClick?.(tile),
|
|
798
873
|
[]
|
|
799
874
|
);
|
|
800
|
-
const stableOnTileHover =
|
|
875
|
+
const stableOnTileHover = useCallback9(
|
|
801
876
|
(tile) => handlersRef.current.onTileHover?.(tile),
|
|
802
877
|
[]
|
|
803
878
|
);
|
|
804
|
-
|
|
879
|
+
useImperativeHandle5(
|
|
805
880
|
ref,
|
|
806
881
|
() => ({
|
|
807
882
|
get instance() {
|
|
@@ -810,7 +885,7 @@ var TileMap = forwardRef4(function TileMap2({ spec, theme: themeProp, darkMode,
|
|
|
810
885
|
}),
|
|
811
886
|
[]
|
|
812
887
|
);
|
|
813
|
-
|
|
888
|
+
useEffect8(() => {
|
|
814
889
|
const container = containerRef.current;
|
|
815
890
|
if (!container) return;
|
|
816
891
|
const options = {
|
|
@@ -827,7 +902,7 @@ var TileMap = forwardRef4(function TileMap2({ spec, theme: themeProp, darkMode,
|
|
|
827
902
|
instanceRef.current = null;
|
|
828
903
|
};
|
|
829
904
|
}, [theme, resolvedDarkMode, stableOnTileClick, stableOnTileHover]);
|
|
830
|
-
|
|
905
|
+
useEffect8(() => {
|
|
831
906
|
const instance = instanceRef.current;
|
|
832
907
|
if (!instance) return;
|
|
833
908
|
const specString = JSON.stringify(spec);
|
|
@@ -835,7 +910,7 @@ var TileMap = forwardRef4(function TileMap2({ spec, theme: themeProp, darkMode,
|
|
|
835
910
|
specRef.current = specString;
|
|
836
911
|
instance.update(spec);
|
|
837
912
|
}, [spec]);
|
|
838
|
-
return /* @__PURE__ */
|
|
913
|
+
return /* @__PURE__ */ jsx7(
|
|
839
914
|
"div",
|
|
840
915
|
{
|
|
841
916
|
ref: containerRef,
|
|
@@ -846,11 +921,17 @@ var TileMap = forwardRef4(function TileMap2({ spec, theme: themeProp, darkMode,
|
|
|
846
921
|
});
|
|
847
922
|
|
|
848
923
|
// src/Visualization.tsx
|
|
849
|
-
import {
|
|
850
|
-
|
|
924
|
+
import {
|
|
925
|
+
isBarListSpec,
|
|
926
|
+
isGraphSpec,
|
|
927
|
+
isSankeySpec,
|
|
928
|
+
isTableSpec,
|
|
929
|
+
isTileMapSpec
|
|
930
|
+
} from "@opendata-ai/openchart-core";
|
|
931
|
+
import { jsx as jsx8 } from "react/jsx-runtime";
|
|
851
932
|
function Visualization({ spec, theme, darkMode, className, style }) {
|
|
852
933
|
if (isTableSpec(spec)) {
|
|
853
|
-
return /* @__PURE__ */
|
|
934
|
+
return /* @__PURE__ */ jsx8(
|
|
854
935
|
DataTable,
|
|
855
936
|
{
|
|
856
937
|
spec,
|
|
@@ -862,17 +943,21 @@ function Visualization({ spec, theme, darkMode, className, style }) {
|
|
|
862
943
|
);
|
|
863
944
|
}
|
|
864
945
|
if (isGraphSpec(spec)) {
|
|
865
|
-
return /* @__PURE__ */
|
|
946
|
+
return /* @__PURE__ */ jsx8(Graph, { spec, theme, darkMode, className, style });
|
|
866
947
|
}
|
|
867
948
|
if (isSankeySpec(spec)) {
|
|
868
|
-
return /* @__PURE__ */
|
|
949
|
+
return /* @__PURE__ */ jsx8(Sankey, { spec, theme, darkMode, className, style });
|
|
869
950
|
}
|
|
870
951
|
if (isTileMapSpec(spec)) {
|
|
871
|
-
return /* @__PURE__ */
|
|
952
|
+
return /* @__PURE__ */ jsx8(TileMap, { spec, theme, darkMode, className, style });
|
|
953
|
+
}
|
|
954
|
+
if (isBarListSpec(spec)) {
|
|
955
|
+
return /* @__PURE__ */ jsx8(BarList, { spec, theme, darkMode, className, style });
|
|
872
956
|
}
|
|
873
|
-
return /* @__PURE__ */
|
|
957
|
+
return /* @__PURE__ */ jsx8(Chart, { spec, theme, darkMode, className, style });
|
|
874
958
|
}
|
|
875
959
|
export {
|
|
960
|
+
BarList,
|
|
876
961
|
Chart,
|
|
877
962
|
DataTable,
|
|
878
963
|
Graph,
|
|
@@ -882,6 +967,7 @@ export {
|
|
|
882
967
|
VizThemeProvider,
|
|
883
968
|
clearRenderers,
|
|
884
969
|
compile,
|
|
970
|
+
compileBarList,
|
|
885
971
|
compileChart,
|
|
886
972
|
compileGraph,
|
|
887
973
|
compileSankey,
|