@classic-homes/charts-react 0.1.35 → 0.1.37
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.cjs +22 -29
- package/dist/index.js +22 -29
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -316,13 +316,15 @@ function useChartResize(chartRef, containerRef) {
|
|
|
316
316
|
const resizeObserverRef = (0, import_react2.useRef)(null);
|
|
317
317
|
(0, import_react2.useEffect)(() => {
|
|
318
318
|
const container = containerRef.current;
|
|
319
|
-
|
|
320
|
-
if (!container || !chart) return;
|
|
319
|
+
if (!container) return;
|
|
321
320
|
let resizeTimeout;
|
|
322
321
|
resizeObserverRef.current = new ResizeObserver(() => {
|
|
323
322
|
clearTimeout(resizeTimeout);
|
|
324
323
|
resizeTimeout = setTimeout(() => {
|
|
325
|
-
chart.
|
|
324
|
+
const chart = chartRef.current;
|
|
325
|
+
if (chart && !chart.isDisposed()) {
|
|
326
|
+
chart.resize();
|
|
327
|
+
}
|
|
326
328
|
}, 100);
|
|
327
329
|
});
|
|
328
330
|
resizeObserverRef.current.observe(container);
|
|
@@ -352,6 +354,7 @@ function useReducedMotion() {
|
|
|
352
354
|
}
|
|
353
355
|
|
|
354
356
|
// src/hooks/useChart.ts
|
|
357
|
+
var SET_OPTION_OPTS = { notMerge: false, lazyUpdate: true };
|
|
355
358
|
function useChart({
|
|
356
359
|
option,
|
|
357
360
|
theme = "auto",
|
|
@@ -364,39 +367,29 @@ function useChart({
|
|
|
364
367
|
const reducedMotion = useReducedMotion();
|
|
365
368
|
const onReadyRef = (0, import_react4.useRef)(onReady);
|
|
366
369
|
onReadyRef.current = onReady;
|
|
370
|
+
const optionRef = (0, import_react4.useRef)(option);
|
|
371
|
+
optionRef.current = {
|
|
372
|
+
...option,
|
|
373
|
+
animation: animation ?? !reducedMotion
|
|
374
|
+
};
|
|
367
375
|
(0, import_react4.useEffect)(() => {
|
|
368
376
|
if (!containerRef.current) return;
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
if (onReadyRef.current && chartRef.current) {
|
|
374
|
-
onReadyRef.current(chartRef.current);
|
|
375
|
-
}
|
|
377
|
+
const chart = echarts2.init(containerRef.current, currentTheme);
|
|
378
|
+
chartRef.current = chart;
|
|
379
|
+
chart.setOption(optionRef.current, SET_OPTION_OPTS);
|
|
380
|
+
onReadyRef.current?.(chart);
|
|
376
381
|
return () => {
|
|
377
|
-
|
|
378
|
-
chartRef.current
|
|
382
|
+
chart.dispose();
|
|
383
|
+
if (chartRef.current === chart) {
|
|
384
|
+
chartRef.current = null;
|
|
385
|
+
}
|
|
379
386
|
};
|
|
380
387
|
}, [currentTheme]);
|
|
381
388
|
(0, import_react4.useEffect)(() => {
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
...option,
|
|
386
|
-
animation: shouldAnimate
|
|
387
|
-
};
|
|
388
|
-
chartRef.current.setOption(optionWithAnimation, {
|
|
389
|
-
notMerge: false,
|
|
390
|
-
lazyUpdate: true
|
|
391
|
-
});
|
|
389
|
+
const chart = chartRef.current;
|
|
390
|
+
if (!chart || chart.isDisposed()) return;
|
|
391
|
+
chart.setOption(optionRef.current, SET_OPTION_OPTS);
|
|
392
392
|
}, [option, animation, reducedMotion]);
|
|
393
|
-
(0, import_react4.useEffect)(() => {
|
|
394
|
-
if (!chartRef.current || !containerRef.current) return;
|
|
395
|
-
const currentOption = chartRef.current.getOption();
|
|
396
|
-
chartRef.current.dispose();
|
|
397
|
-
chartRef.current = echarts2.init(containerRef.current, currentTheme);
|
|
398
|
-
chartRef.current.setOption(currentOption);
|
|
399
|
-
}, [currentTheme]);
|
|
400
393
|
useChartResize(chartRef, containerRef);
|
|
401
394
|
return {
|
|
402
395
|
chartRef,
|
package/dist/index.js
CHANGED
|
@@ -263,13 +263,15 @@ function useChartResize(chartRef, containerRef) {
|
|
|
263
263
|
const resizeObserverRef = useRef(null);
|
|
264
264
|
useEffect2(() => {
|
|
265
265
|
const container = containerRef.current;
|
|
266
|
-
|
|
267
|
-
if (!container || !chart) return;
|
|
266
|
+
if (!container) return;
|
|
268
267
|
let resizeTimeout;
|
|
269
268
|
resizeObserverRef.current = new ResizeObserver(() => {
|
|
270
269
|
clearTimeout(resizeTimeout);
|
|
271
270
|
resizeTimeout = setTimeout(() => {
|
|
272
|
-
chart.
|
|
271
|
+
const chart = chartRef.current;
|
|
272
|
+
if (chart && !chart.isDisposed()) {
|
|
273
|
+
chart.resize();
|
|
274
|
+
}
|
|
273
275
|
}, 100);
|
|
274
276
|
});
|
|
275
277
|
resizeObserverRef.current.observe(container);
|
|
@@ -299,6 +301,7 @@ function useReducedMotion() {
|
|
|
299
301
|
}
|
|
300
302
|
|
|
301
303
|
// src/hooks/useChart.ts
|
|
304
|
+
var SET_OPTION_OPTS = { notMerge: false, lazyUpdate: true };
|
|
302
305
|
function useChart({
|
|
303
306
|
option,
|
|
304
307
|
theme = "auto",
|
|
@@ -311,39 +314,29 @@ function useChart({
|
|
|
311
314
|
const reducedMotion = useReducedMotion();
|
|
312
315
|
const onReadyRef = useRef2(onReady);
|
|
313
316
|
onReadyRef.current = onReady;
|
|
317
|
+
const optionRef = useRef2(option);
|
|
318
|
+
optionRef.current = {
|
|
319
|
+
...option,
|
|
320
|
+
animation: animation ?? !reducedMotion
|
|
321
|
+
};
|
|
314
322
|
useEffect4(() => {
|
|
315
323
|
if (!containerRef.current) return;
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
if (onReadyRef.current && chartRef.current) {
|
|
321
|
-
onReadyRef.current(chartRef.current);
|
|
322
|
-
}
|
|
324
|
+
const chart = echarts2.init(containerRef.current, currentTheme);
|
|
325
|
+
chartRef.current = chart;
|
|
326
|
+
chart.setOption(optionRef.current, SET_OPTION_OPTS);
|
|
327
|
+
onReadyRef.current?.(chart);
|
|
323
328
|
return () => {
|
|
324
|
-
|
|
325
|
-
chartRef.current
|
|
329
|
+
chart.dispose();
|
|
330
|
+
if (chartRef.current === chart) {
|
|
331
|
+
chartRef.current = null;
|
|
332
|
+
}
|
|
326
333
|
};
|
|
327
334
|
}, [currentTheme]);
|
|
328
335
|
useEffect4(() => {
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
...option,
|
|
333
|
-
animation: shouldAnimate
|
|
334
|
-
};
|
|
335
|
-
chartRef.current.setOption(optionWithAnimation, {
|
|
336
|
-
notMerge: false,
|
|
337
|
-
lazyUpdate: true
|
|
338
|
-
});
|
|
336
|
+
const chart = chartRef.current;
|
|
337
|
+
if (!chart || chart.isDisposed()) return;
|
|
338
|
+
chart.setOption(optionRef.current, SET_OPTION_OPTS);
|
|
339
339
|
}, [option, animation, reducedMotion]);
|
|
340
|
-
useEffect4(() => {
|
|
341
|
-
if (!chartRef.current || !containerRef.current) return;
|
|
342
|
-
const currentOption = chartRef.current.getOption();
|
|
343
|
-
chartRef.current.dispose();
|
|
344
|
-
chartRef.current = echarts2.init(containerRef.current, currentTheme);
|
|
345
|
-
chartRef.current.setOption(currentOption);
|
|
346
|
-
}, [currentTheme]);
|
|
347
340
|
useChartResize(chartRef, containerRef);
|
|
348
341
|
return {
|
|
349
342
|
chartRef,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@classic-homes/charts-react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.37",
|
|
4
4
|
"description": "React ECharts components for Classic Theme",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"scripts": {
|
|
21
21
|
"build": "tsup src/index.ts --format esm,cjs --dts --external react --external react-dom --external echarts",
|
|
22
22
|
"dev": "tsup src/index.ts --format esm,cjs --dts --external react --external react-dom --external echarts --watch",
|
|
23
|
-
"clean": "rm
|
|
23
|
+
"clean": "node ../../scripts/rm.mjs dist",
|
|
24
24
|
"typecheck": "tsc --noEmit"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|