@hsu-react/ui 2.4.0 → 2.4.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.
Files changed (57) hide show
  1. package/es/components/Chart/Bar/index.js +21 -7
  2. package/es/components/Chart/Common/index.js +9 -2
  3. package/es/components/Chart/Gauge/index.js +9 -2
  4. package/es/components/Chart/Heatmap/index.js +21 -6
  5. package/es/components/Chart/Line/index.js +21 -6
  6. package/es/components/Chart/Pie/Pie3D/index.js +9 -2
  7. package/es/components/Chart/Pie/index.js +9 -2
  8. package/es/components/Chart/Polar/index.js +9 -2
  9. package/es/components/Chart/Radar/index.js +9 -2
  10. package/es/components/Chart/Sankey/index.js +9 -2
  11. package/es/components/Chart/Tree/index.js +9 -2
  12. package/es/components/Chart/_hooks/useContainerReady.d.ts +18 -0
  13. package/es/components/Chart/_hooks/useContainerReady.js +56 -0
  14. package/es/components/Chart/_utils/cartesian.d.ts +3 -2
  15. package/es/components/Chart/_utils/cartesian.js +9 -10
  16. package/es/components/Chart/_utils/chartTheme.d.ts +22 -0
  17. package/es/components/Chart/_utils/chartTheme.js +23 -0
  18. package/es/components/Chart/_utils/heatmap.d.ts +3 -2
  19. package/es/components/Chart/_utils/heatmap.js +7 -10
  20. package/es/components/Panel/ListPanel/ListModalPanel/index.module.scss +10 -0
  21. package/lib/components/Chart/Bar/index.js +19 -7
  22. package/lib/components/Chart/Common/index.js +9 -2
  23. package/lib/components/Chart/Gauge/index.js +9 -2
  24. package/lib/components/Chart/Heatmap/index.js +19 -6
  25. package/lib/components/Chart/Line/index.js +19 -6
  26. package/lib/components/Chart/Pie/Pie3D/index.js +9 -2
  27. package/lib/components/Chart/Pie/index.js +9 -2
  28. package/lib/components/Chart/Polar/index.js +9 -2
  29. package/lib/components/Chart/Radar/index.js +9 -2
  30. package/lib/components/Chart/Sankey/index.js +9 -2
  31. package/lib/components/Chart/Tree/index.js +9 -2
  32. package/lib/components/Chart/_hooks/useContainerReady.d.ts +18 -0
  33. package/lib/components/Chart/_hooks/useContainerReady.js +51 -0
  34. package/lib/components/Chart/_utils/cartesian.d.ts +3 -2
  35. package/lib/components/Chart/_utils/cartesian.js +9 -11
  36. package/lib/components/Chart/_utils/chartTheme.d.ts +22 -0
  37. package/lib/components/Chart/_utils/chartTheme.js +29 -0
  38. package/lib/components/Chart/_utils/heatmap.d.ts +3 -2
  39. package/lib/components/Chart/_utils/heatmap.js +7 -10
  40. package/lib/components/Panel/ListPanel/ListModalPanel/index.module.scss +10 -0
  41. package/package.json +1 -1
  42. package/src/components/Chart/Bar/index.tsx +20 -5
  43. package/src/components/Chart/Common/index.tsx +12 -2
  44. package/src/components/Chart/Gauge/index.tsx +12 -2
  45. package/src/components/Chart/Heatmap/index.tsx +22 -5
  46. package/src/components/Chart/Line/index.tsx +20 -4
  47. package/src/components/Chart/Pie/Pie3D/index.tsx +10 -1
  48. package/src/components/Chart/Pie/index.tsx +10 -1
  49. package/src/components/Chart/Polar/index.tsx +12 -2
  50. package/src/components/Chart/Radar/index.tsx +10 -1
  51. package/src/components/Chart/Sankey/index.tsx +12 -2
  52. package/src/components/Chart/Tree/index.tsx +12 -2
  53. package/src/components/Chart/_hooks/useContainerReady.ts +50 -0
  54. package/src/components/Chart/_utils/cartesian.ts +11 -10
  55. package/src/components/Chart/_utils/chartTheme.ts +34 -0
  56. package/src/components/Chart/_utils/heatmap.ts +10 -10
  57. package/src/components/Panel/ListPanel/ListModalPanel/index.module.scss +10 -0
@@ -8,11 +8,14 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
8
8
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
9
9
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
10
10
  import * as echarts from "echarts";
11
+ import useContainerReady from "../_hooks/useContainerReady";
11
12
  import React, { useCallback, useEffect, useMemo, useRef } from "react";
12
13
  import styles from "../index.module.scss";
13
14
  import { autoScrollLegend } from "../_utils/autoScrollLegend";
14
15
  import { autoScrollByItem } from "../_utils/autoSmooth";
15
16
  import { buildCartesianSeriesOptions, createDefaultCategoryXAxis, createDefaultValueYAxis, getSliderShow, percentWindowToIndexWindow, resolveScrollConfig } from "../_utils/cartesian";
17
+ import { resolveChartChrome } from "../_utils/chartTheme";
18
+ import useIsDark from "../../../hooks/useIsDark";
16
19
  import { jsx as _jsx } from "react/jsx-runtime";
17
20
  var ChartBar = function ChartBar(props) {
18
21
  var className = props.className,
@@ -44,18 +47,26 @@ var ChartBar = function ChartBar(props) {
44
47
  coreOption = _objectWithoutProperties(props, _excluded);
45
48
  var chartRef = useRef(null);
46
49
  var chartInstanceRef = useRef(null);
50
+ // Defers `echarts.init` until the container has a box — see the hook for why
51
+ var containerReady = useContainerReady(chartRef);
47
52
  var resizeObserverRef = useRef(null);
48
53
  var prevXAxisKeyRef = useRef(null);
49
54
  var legendScrollRef = useRef(null);
50
55
  var normalizedScroll = useMemo(function () {
51
56
  return resolveScrollConfig(scrollConfig);
52
57
  }, [scrollConfig]);
58
+ // echarts options are plain JS and cannot read the `--vita-*` variables, so the axis and
59
+ // legend colours have to be resolved against the active appearance here
60
+ var isDark = useIsDark();
61
+ var chrome = useMemo(function () {
62
+ return resolveChartChrome(isDark);
63
+ }, [isDark]);
53
64
 
54
65
  // Cache the chart option with useMemo
55
66
  var chartOption = useMemo(function () {
56
67
  var _xAxisData$length, _ref, _ref2;
57
- var def_xAxis = createDefaultCategoryXAxis(xAxisData);
58
- var def_yAxis = createDefaultValueYAxis("bar");
68
+ var def_xAxis = createDefaultCategoryXAxis(xAxisData, chrome);
69
+ var def_yAxis = createDefaultValueYAxis("bar", chrome);
59
70
 
60
71
  // Process xAxis config
61
72
  var processedXAxis = Array.isArray(xAxis) ? xAxis === null || xAxis === void 0 ? void 0 : xAxis.map(function (item) {
@@ -150,8 +161,7 @@ var ChartBar = function ChartBar(props) {
150
161
  data: legendData,
151
162
  icon: "circle",
152
163
  textStyle: {
153
- color: "#373D48",
154
- fontSize: 16
164
+ color: chrome.text
155
165
  },
156
166
  itemWidth: 8,
157
167
  itemHeight: 8
@@ -175,18 +185,22 @@ var ChartBar = function ChartBar(props) {
175
185
  series: buildCartesianSeriesOptions("bar", seriesData, series)
176
186
  }, coreOption);
177
187
  return option;
178
- }, [xAxisData, xAxis, yAxis, grid, chartTitle, dataZoom, normalizedScroll, insideDataZoom, sliderDataZoom, title, tooltip, legendData, legend, seriesData, series, enableLegendAutoScroll, coreOption]);
188
+ }, [xAxisData, xAxis, yAxis, grid, chartTitle, dataZoom, normalizedScroll, insideDataZoom, sliderDataZoom, title, tooltip, legendData, legend, seriesData, series, enableLegendAutoScroll, coreOption, chrome]);
179
189
 
180
190
  // Callback for handling chart resize
181
191
  var handleResize = useCallback(function () {
182
192
  var _chartInstanceRef$cur;
193
+ // A keep-alive tab losing focus fires the observer with a 0×0 box; resizing to that throws
194
+ // the laid-out canvas away and it has to be rebuilt when the tab comes back
195
+ var el = chartRef.current;
196
+ if (!el || el.clientWidth === 0 || el.clientHeight === 0) return;
183
197
  (_chartInstanceRef$cur = chartInstanceRef.current) === null || _chartInstanceRef$cur === void 0 || _chartInstanceRef$cur.resize();
184
198
  }, []);
185
199
 
186
200
  // Initialize the chart
187
201
  useEffect(function () {
188
202
  var _xAxisData$join, _chart$getOption, _chart$getOption2, _opt$legend$, _opt$legend, _ref3;
189
- if (!chartRef.current) return;
203
+ if (!chartRef.current || !containerReady) return;
190
204
 
191
205
  // Initialize or reuse the existing instance
192
206
  var chart = chartInstanceRef.current;
@@ -327,7 +341,7 @@ var ChartBar = function ChartBar(props) {
327
341
  };
328
342
  }, [chartOption, handleResize, onClick, onLegendSelectChanged, onDataZoomWindowChanged, xAxisData, enableLegendAutoScroll, legendVisibleCount, legendScrollInterval,
329
343
  // 图例是否接管滚轮由它推导,漏了会拿到过期的滚动配置
330
- normalizedScroll]);
344
+ normalizedScroll, containerReady]);
331
345
 
332
346
  // Handle auto play
333
347
  useEffect(function () {
@@ -8,6 +8,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
8
8
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
9
9
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
10
10
  import React, { useCallback, useEffect, useMemo, useRef } from "react";
11
+ import useContainerReady from "../_hooks/useContainerReady";
11
12
  import styles from "../index.module.scss";
12
13
  import * as echarts from "echarts";
13
14
  import { jsx as _jsx } from "react/jsx-runtime";
@@ -18,6 +19,8 @@ var Common = function Common(props) {
18
19
  coreOption = _objectWithoutProperties(props, _excluded);
19
20
  var chartRef = useRef(null);
20
21
  var chartInstanceRef = useRef(null);
22
+ // Defers `echarts.init` until the container has a box — see the hook for why
23
+ var containerReady = useContainerReady(chartRef);
21
24
  var resizeObserverRef = useRef(null);
22
25
 
23
26
  // Cache the chart configuration with useMemo
@@ -29,12 +32,16 @@ var Common = function Common(props) {
29
32
  // Callback that handles chart resize
30
33
  var handleResize = useCallback(function () {
31
34
  var _chartInstanceRef$cur;
35
+ // A keep-alive tab losing focus fires the observer with a 0×0 box; resizing to that throws
36
+ // the laid-out canvas away and it has to be rebuilt when the tab comes back
37
+ var el = chartRef.current;
38
+ if (!el || el.clientWidth === 0 || el.clientHeight === 0) return;
32
39
  (_chartInstanceRef$cur = chartInstanceRef.current) === null || _chartInstanceRef$cur === void 0 || _chartInstanceRef$cur.resize();
33
40
  }, []);
34
41
 
35
42
  // Initialize the chart
36
43
  useEffect(function () {
37
- if (!chartRef.current) return;
44
+ if (!chartRef.current || !containerReady) return;
38
45
 
39
46
  // Initialize or reuse an existing instance
40
47
  var chart = chartInstanceRef.current;
@@ -62,7 +69,7 @@ var Common = function Common(props) {
62
69
  return function () {
63
70
  window.removeEventListener("resize", handleResize);
64
71
  };
65
- }, [chartOption, handleResize, onChart]);
72
+ }, [chartOption, handleResize, onChart, containerReady]);
66
73
 
67
74
  // Clean up resources on component unmount
68
75
  useEffect(function () {
@@ -8,6 +8,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
8
8
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
9
9
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
10
10
  import * as echarts from "echarts";
11
+ import useContainerReady from "../_hooks/useContainerReady";
11
12
  import React, { useCallback, useEffect, useMemo, useRef } from "react";
12
13
  import styles from "../index.module.scss";
13
14
  import { jsx as _jsx } from "react/jsx-runtime";
@@ -31,6 +32,8 @@ var Gauge = function Gauge(props) {
31
32
  coreSeries = _objectWithoutProperties(_ref, _excluded);
32
33
  var chartRef = useRef(null);
33
34
  var chartInstanceRef = useRef(null);
35
+ // Defers `echarts.init` until the container has a box — see the hook for why
36
+ var containerReady = useContainerReady(chartRef);
34
37
  var resizeObserverRef = useRef(null);
35
38
 
36
39
  // Cache the chart option with useMemo
@@ -83,12 +86,16 @@ var Gauge = function Gauge(props) {
83
86
  // Callback for handling chart resize
84
87
  var handleResize = useCallback(function () {
85
88
  var _chartInstanceRef$cur;
89
+ // A keep-alive tab losing focus fires the observer with a 0×0 box; resizing to that throws
90
+ // the laid-out canvas away and it has to be rebuilt when the tab comes back
91
+ var el = chartRef.current;
92
+ if (!el || el.clientWidth === 0 || el.clientHeight === 0) return;
86
93
  (_chartInstanceRef$cur = chartInstanceRef.current) === null || _chartInstanceRef$cur === void 0 || _chartInstanceRef$cur.resize();
87
94
  }, []);
88
95
 
89
96
  // Initialize the chart
90
97
  useEffect(function () {
91
- if (!chartRef.current) return;
98
+ if (!chartRef.current || !containerReady) return;
92
99
 
93
100
  // Initialize or reuse the existing instance
94
101
  var chart = chartInstanceRef.current;
@@ -113,7 +120,7 @@ var Gauge = function Gauge(props) {
113
120
  return function () {
114
121
  window.removeEventListener("resize", handleResize);
115
122
  };
116
- }, [chartOption, handleResize]);
123
+ }, [chartOption, handleResize, containerReady]);
117
124
 
118
125
  // Clean up resources when the component unmounts
119
126
  useEffect(function () {
@@ -14,9 +14,12 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
14
14
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
15
15
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
16
16
  import React, { useCallback, useEffect, useMemo, useRef } from "react";
17
+ import useContainerReady from "../_hooks/useContainerReady";
17
18
  import styles from "../index.module.scss";
18
19
  import * as echarts from "echarts";
19
20
  import { createDefaultHeatmapXAxis, createDefaultHeatmapYAxis } from "../_utils/heatmap";
21
+ import { resolveChartChrome } from "../_utils/chartTheme";
22
+ import useIsDark from "../../../hooks/useIsDark";
20
23
  import { jsx as _jsx } from "react/jsx-runtime";
21
24
  var Heatmap = function Heatmap(props) {
22
25
  var className = props.className,
@@ -40,7 +43,15 @@ var Heatmap = function Heatmap(props) {
40
43
  coreOption = _objectWithoutProperties(props, _excluded);
41
44
  var chartRef = useRef(null);
42
45
  var chartInstanceRef = useRef(null);
46
+ // Defers `echarts.init` until the container has a box — see the hook for why
47
+ var containerReady = useContainerReady(chartRef);
43
48
  var resizeObserverRef = useRef(null);
49
+ // echarts options are plain JS and cannot read the `--vita-*` variables, so the axis and legend
50
+ // colours have to be resolved against the active appearance here
51
+ var isDark = useIsDark();
52
+ var chrome = useMemo(function () {
53
+ return resolveChartChrome(isDark);
54
+ }, [isDark]);
44
55
 
45
56
  // Process the data and generate the chart option
46
57
  var chartOption = useMemo(function () {
@@ -85,7 +96,7 @@ var Heatmap = function Heatmap(props) {
85
96
  left: "right",
86
97
  top: "center",
87
98
  textStyle: {
88
- color: "#373D48"
99
+ color: chrome.text
89
100
  },
90
101
  inRange: {
91
102
  color: inRangeColor
@@ -93,7 +104,7 @@ var Heatmap = function Heatmap(props) {
93
104
  };
94
105
 
95
106
  // Process xAxis config
96
- var def_xAxis = createDefaultHeatmapXAxis(xAxisData);
107
+ var def_xAxis = createDefaultHeatmapXAxis(xAxisData, chrome);
97
108
  var processedXAxis = Array.isArray(xAxis) ? xAxis === null || xAxis === void 0 ? void 0 : xAxis.map(function (item) {
98
109
  return _objectSpread(_objectSpread({}, def_xAxis), {}, {
99
110
  data: (item === null || item === void 0 ? void 0 : item.type) === "value" ? undefined : xAxisData
@@ -103,7 +114,7 @@ var Heatmap = function Heatmap(props) {
103
114
  }, xAxis);
104
115
 
105
116
  // Process yAxis config
106
- var def_yAxis = createDefaultHeatmapYAxis(yAxisData);
117
+ var def_yAxis = createDefaultHeatmapYAxis(yAxisData, chrome);
107
118
  var processedYAxis = Array.isArray(yAxis) ? yAxis === null || yAxis === void 0 ? void 0 : yAxis.map(function (item) {
108
119
  return _objectSpread(_objectSpread({}, def_yAxis), {}, {
109
120
  data: (item === null || item === void 0 ? void 0 : item.type) === "value" ? undefined : yAxisData
@@ -170,17 +181,21 @@ var Heatmap = function Heatmap(props) {
170
181
  }, series)]
171
182
  }, coreOption);
172
183
  return option;
173
- }, [data, inRangeColor, xAxisData, xAxis, yAxisData, yAxis, propVisualMap, grid, chartTitle, title, tooltip, series, coreOption, zeroColor]);
184
+ }, [data, inRangeColor, xAxisData, xAxis, yAxisData, yAxis, propVisualMap, grid, chartTitle, title, tooltip, series, coreOption, zeroColor, chrome]);
174
185
 
175
186
  // Callback for handling chart resize
176
187
  var handleResize = useCallback(function () {
177
188
  var _chartInstanceRef$cur;
189
+ // A keep-alive tab losing focus fires the observer with a 0×0 box; resizing to that throws
190
+ // the laid-out canvas away and it has to be rebuilt when the tab comes back
191
+ var el = chartRef.current;
192
+ if (!el || el.clientWidth === 0 || el.clientHeight === 0) return;
178
193
  (_chartInstanceRef$cur = chartInstanceRef.current) === null || _chartInstanceRef$cur === void 0 || _chartInstanceRef$cur.resize();
179
194
  }, []);
180
195
 
181
196
  // Initialize the chart
182
197
  useEffect(function () {
183
- if (!chartRef.current) return;
198
+ if (!chartRef.current || !containerReady) return;
184
199
 
185
200
  // Initialize or reuse the existing instance
186
201
  var chart = chartInstanceRef.current;
@@ -217,7 +232,7 @@ var Heatmap = function Heatmap(props) {
217
232
  (_chartInstanceRef$cur3 = chartInstanceRef.current) === null || _chartInstanceRef$cur3 === void 0 || _chartInstanceRef$cur3.off("click", onClick);
218
233
  }
219
234
  };
220
- }, [chartOption, handleResize, onChart, onClick]);
235
+ }, [chartOption, handleResize, onChart, onClick, containerReady]);
221
236
 
222
237
  // Clean up resources when the component unmounts
223
238
  useEffect(function () {
@@ -8,11 +8,14 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
8
8
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
9
9
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
10
10
  import * as echarts from "echarts";
11
+ import useContainerReady from "../_hooks/useContainerReady";
11
12
  import React, { useCallback, useEffect, useMemo, useRef } from "react";
12
13
  import styles from "../index.module.scss";
13
14
  import { autoScrollLegend } from "../_utils/autoScrollLegend";
14
15
  import { autoScrollByItem } from "../_utils/autoSmooth";
15
16
  import { buildCartesianSeriesOptions, createDefaultCategoryXAxis, createDefaultValueYAxis, getSliderShow, percentWindowToIndexWindow, resolveScrollConfig } from "../_utils/cartesian";
17
+ import { resolveChartChrome } from "../_utils/chartTheme";
18
+ import useIsDark from "../../../hooks/useIsDark";
16
19
  import { jsx as _jsx } from "react/jsx-runtime";
17
20
  var ChartLine = function ChartLine(props) {
18
21
  var className = props.className,
@@ -44,18 +47,26 @@ var ChartLine = function ChartLine(props) {
44
47
  coreOption = _objectWithoutProperties(props, _excluded);
45
48
  var chartRef = useRef(null);
46
49
  var chartInstanceRef = useRef(null);
50
+ // Defers `echarts.init` until the container has a box — see the hook for why
51
+ var containerReady = useContainerReady(chartRef);
47
52
  var resizeObserverRef = useRef(null);
48
53
  var prevXAxisKeyRef = useRef(null);
49
54
  var legendScrollRef = useRef(null);
50
55
  var normalizedScroll = useMemo(function () {
51
56
  return resolveScrollConfig(scrollConfig);
52
57
  }, [scrollConfig]);
58
+ // echarts options are plain JS and cannot read the `--vita-*` variables, so the axis and
59
+ // legend colours have to be resolved against the active appearance here
60
+ var isDark = useIsDark();
61
+ var chrome = useMemo(function () {
62
+ return resolveChartChrome(isDark);
63
+ }, [isDark]);
53
64
 
54
65
  // Cache the chart option with useMemo
55
66
  var chartOption = useMemo(function () {
56
67
  var _xAxisData$length, _ref, _ref2;
57
- var def_xAxis = createDefaultCategoryXAxis(xAxisData);
58
- var def_yAxis = createDefaultValueYAxis("line");
68
+ var def_xAxis = createDefaultCategoryXAxis(xAxisData, chrome);
69
+ var def_yAxis = createDefaultValueYAxis("line", chrome);
59
70
 
60
71
  // Process xAxis config
61
72
  var processedXAxis = Array.isArray(xAxis) ? xAxis === null || xAxis === void 0 ? void 0 : xAxis.map(function (item) {
@@ -144,7 +155,7 @@ var ChartLine = function ChartLine(props) {
144
155
  top: "5%",
145
156
  icon: "circle",
146
157
  textStyle: {
147
- color: "#373D48"
158
+ color: chrome.text
148
159
  },
149
160
  itemWidth: 8,
150
161
  itemHeight: 8
@@ -171,18 +182,22 @@ var ChartLine = function ChartLine(props) {
171
182
  series: buildCartesianSeriesOptions("line", seriesData, series)
172
183
  }, coreOption);
173
184
  return option;
174
- }, [xAxisData, xAxis, yAxis, grid, chartTitle, dataZoom, normalizedScroll, insideDataZoom, sliderDataZoom, title, legendData, legend, tooltip, seriesData, series, enableLegendAutoScroll, coreOption]);
185
+ }, [xAxisData, xAxis, yAxis, grid, chartTitle, dataZoom, normalizedScroll, insideDataZoom, sliderDataZoom, title, legendData, legend, tooltip, seriesData, series, enableLegendAutoScroll, coreOption, chrome]);
175
186
 
176
187
  // Callback for handling chart resize
177
188
  var handleResize = useCallback(function () {
178
189
  var _chartInstanceRef$cur;
190
+ // A keep-alive tab losing focus fires the observer with a 0×0 box; resizing to that throws
191
+ // the laid-out canvas away and it has to be rebuilt when the tab comes back
192
+ var el = chartRef.current;
193
+ if (!el || el.clientWidth === 0 || el.clientHeight === 0) return;
179
194
  (_chartInstanceRef$cur = chartInstanceRef.current) === null || _chartInstanceRef$cur === void 0 || _chartInstanceRef$cur.resize();
180
195
  }, []);
181
196
 
182
197
  // Initialize the chart
183
198
  useEffect(function () {
184
199
  var _xAxisData$join, _chart$getOption, _chart$getOption2, _opt$legend$, _opt$legend, _ref3;
185
- if (!chartRef.current) return;
200
+ if (!chartRef.current || !containerReady) return;
186
201
 
187
202
  // Initialize or reuse the existing instance
188
203
  var chart = chartInstanceRef.current;
@@ -323,7 +338,7 @@ var ChartLine = function ChartLine(props) {
323
338
  };
324
339
  }, [chartOption, handleResize, onClick, onLegendSelectChanged, onDataZoomWindowChanged, xAxisData, enableLegendAutoScroll, legendVisibleCount, legendScrollInterval,
325
340
  // 图例是否接管滚轮由它推导,漏了会拿到过期的滚动配置
326
- normalizedScroll]);
341
+ normalizedScroll, containerReady]);
327
342
 
328
343
  // Handle auto play
329
344
  useEffect(function () {
@@ -2,6 +2,7 @@ var _excluded = ["className", "style", "pieData", "internalDiameterRatio", "auto
2
2
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
3
3
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
4
4
  import * as echarts from "echarts";
5
+ import useContainerReady from "../../_hooks/useContainerReady";
5
6
  import "echarts-gl";
6
7
  import React, { useCallback, useEffect, useMemo, useRef } from "react";
7
8
  import { useMouseOverHandler, useGlobalOutHandler } from "./_hooks";
@@ -45,6 +46,8 @@ var ChartPie3D = function ChartPie3D(props) {
45
46
  coreOption = _objectWithoutProperties(props, _excluded);
46
47
  var chartRef = useRef(null);
47
48
  var chartInstanceRef = useRef(null);
49
+ // Defers `echarts.init` until the container has a box — see the hook for why
50
+ var containerReady = useContainerReady(chartRef);
48
51
  var resizeObserverRef = useRef(null);
49
52
  var hoveredIndexRef = useRef("");
50
53
  var optionRef = useRef(null);
@@ -67,6 +70,10 @@ var ChartPie3D = function ChartPie3D(props) {
67
70
  }, [pieData, internalDiameterRatio, tooltip, alpha, beta, autoRotate, distance, coreOption, minHeight, maxHeight, yOffset, label, enableMouseControl]);
68
71
  var handleResize = useCallback(function () {
69
72
  var _chartInstanceRef$cur;
73
+ // A keep-alive tab losing focus fires the observer with a 0×0 box; resizing to that throws
74
+ // the laid-out canvas away and it has to be rebuilt when the tab comes back
75
+ var el = chartRef.current;
76
+ if (!el || el.clientWidth === 0 || el.clientHeight === 0) return;
70
77
  (_chartInstanceRef$cur = chartInstanceRef.current) === null || _chartInstanceRef$cur === void 0 || _chartInstanceRef$cur.resize();
71
78
  }, []);
72
79
  var handleMouseOver = useMouseOverHandler(optionRef, chartInstanceRef, hoveredIndexRef, {
@@ -83,7 +90,7 @@ var ChartPie3D = function ChartPie3D(props) {
83
90
  autoRotate: autoRotate
84
91
  });
85
92
  useEffect(function () {
86
- if (!chartRef.current) return;
93
+ if (!chartRef.current || !containerReady) return;
87
94
  var chart = chartInstanceRef.current;
88
95
  if (!chart) {
89
96
  chart = echarts.init(chartRef.current);
@@ -112,7 +119,7 @@ var ChartPie3D = function ChartPie3D(props) {
112
119
  }
113
120
  }
114
121
  };
115
- }, [chartOption, handleResize, handleMouseOver, handleGlobalOut, onChart, onClick]);
122
+ }, [chartOption, handleResize, handleMouseOver, handleGlobalOut, onChart, onClick, containerReady]);
116
123
  useEffect(function () {
117
124
  return function () {
118
125
  if (resizeObserverRef.current) {
@@ -14,6 +14,7 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
14
14
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
15
15
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
16
16
  import * as echarts from "echarts";
17
+ import useContainerReady from "../_hooks/useContainerReady";
17
18
  import React, { useCallback, useEffect, useMemo, useRef } from "react";
18
19
  import { autoScrollLegend } from "../chartUtils";
19
20
  import styles from "../index.module.scss";
@@ -49,6 +50,8 @@ var ChartPie = function ChartPie(props) {
49
50
  coreOption = _objectWithoutProperties(props, _excluded);
50
51
  var chartRef = useRef(null);
51
52
  var chartInstanceRef = useRef(null);
53
+ // Defers `echarts.init` until the container has a box — see the hook for why
54
+ var containerReady = useContainerReady(chartRef);
52
55
  var resizeObserverRef = useRef(null);
53
56
  var legendScrollRef = useRef(null);
54
57
 
@@ -198,12 +201,16 @@ var ChartPie = function ChartPie(props) {
198
201
  // Callback for handling chart resize
199
202
  var handleResize = useCallback(function () {
200
203
  var _chartInstanceRef$cur;
204
+ // A keep-alive tab losing focus fires the observer with a 0×0 box; resizing to that throws
205
+ // the laid-out canvas away and it has to be rebuilt when the tab comes back
206
+ var el = chartRef.current;
207
+ if (!el || el.clientWidth === 0 || el.clientHeight === 0) return;
201
208
  (_chartInstanceRef$cur = chartInstanceRef.current) === null || _chartInstanceRef$cur === void 0 || _chartInstanceRef$cur.resize();
202
209
  }, []);
203
210
 
204
211
  // Initialize the chart
205
212
  useEffect(function () {
206
- if (!chartRef.current) return;
213
+ if (!chartRef.current || !containerReady) return;
207
214
 
208
215
  // Initialize or reuse the existing instance
209
216
  var chart = chartInstanceRef.current;
@@ -261,7 +268,7 @@ var ChartPie = function ChartPie(props) {
261
268
  legendScrollRef.current = null;
262
269
  }
263
270
  };
264
- }, [chartOption, handleResize, onChart, onClick, enableLegendAutoScroll, seriesData, legendVisibleCount, legendScrollInterval]);
271
+ }, [chartOption, handleResize, onChart, onClick, enableLegendAutoScroll, seriesData, legendVisibleCount, legendScrollInterval, containerReady]);
265
272
 
266
273
  // Clean up resources when the component unmounts
267
274
  useEffect(function () {
@@ -8,6 +8,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
8
8
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
9
9
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
10
10
  import * as echarts from "echarts";
11
+ import useContainerReady from "../_hooks/useContainerReady";
11
12
  import React, { useCallback, useEffect, useMemo, useRef } from "react";
12
13
  import styles from "../index.module.scss";
13
14
  import { jsx as _jsx } from "react/jsx-runtime";
@@ -29,6 +30,8 @@ var Polar = function Polar(props) {
29
30
  coreOption = _objectWithoutProperties(props, _excluded);
30
31
  var chartRef = useRef(null);
31
32
  var chartInstanceRef = useRef(null);
33
+ // Defers `echarts.init` until the container has a box — see the hook for why
34
+ var containerReady = useContainerReady(chartRef);
32
35
  var resizeObserverRef = useRef(null);
33
36
 
34
37
  // Cache the chart option with useMemo
@@ -135,12 +138,16 @@ var Polar = function Polar(props) {
135
138
  // Callback handling chart resize
136
139
  var handleResize = useCallback(function () {
137
140
  var _chartInstanceRef$cur;
141
+ // A keep-alive tab losing focus fires the observer with a 0×0 box; resizing to that throws
142
+ // the laid-out canvas away and it has to be rebuilt when the tab comes back
143
+ var el = chartRef.current;
144
+ if (!el || el.clientWidth === 0 || el.clientHeight === 0) return;
138
145
  (_chartInstanceRef$cur = chartInstanceRef.current) === null || _chartInstanceRef$cur === void 0 || _chartInstanceRef$cur.resize();
139
146
  }, []);
140
147
 
141
148
  // Initialize the chart
142
149
  useEffect(function () {
143
- if (!chartRef.current) return;
150
+ if (!chartRef.current || !containerReady) return;
144
151
 
145
152
  // Initialize a new instance or reuse the existing one
146
153
  var chart = chartInstanceRef.current;
@@ -165,7 +172,7 @@ var Polar = function Polar(props) {
165
172
  return function () {
166
173
  window.removeEventListener("resize", handleResize);
167
174
  };
168
- }, [chartOption, handleResize]);
175
+ }, [chartOption, handleResize, containerReady]);
169
176
 
170
177
  // Clean up resources on unmount
171
178
  useEffect(function () {
@@ -14,6 +14,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
14
14
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
15
15
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
16
16
  import * as echarts from "echarts";
17
+ import useContainerReady from "../_hooks/useContainerReady";
17
18
  import React, { useCallback, useEffect, useMemo, useRef } from "react";
18
19
  import styles from "../index.module.scss";
19
20
 
@@ -40,6 +41,8 @@ var Radar = function Radar(props) {
40
41
  coreOption = _objectWithoutProperties(props, _excluded);
41
42
  var chartRef = useRef(null);
42
43
  var chartInstanceRef = useRef(null);
44
+ // Defers `echarts.init` until the container has a box — see the hook for why
45
+ var containerReady = useContainerReady(chartRef);
43
46
  var resizeObserverRef = useRef(null);
44
47
  var hoveredIndicatorRef = useRef(-1);
45
48
  var singleIndicatorEnabled = Boolean(singleIndicatorTooltipProp) && singleIndicatorMode !== undefined;
@@ -154,10 +157,14 @@ var Radar = function Radar(props) {
154
157
  }, [indicators, data, color, name, radar, series, coreOption, singleIndicatorEnabled, singleIndicatorFormatter, singleIndicatorRegion]);
155
158
  var handleResize = useCallback(function () {
156
159
  var _chartInstanceRef$cur;
160
+ // A keep-alive tab losing focus fires the observer with a 0×0 box; resizing to that throws
161
+ // the laid-out canvas away and it has to be rebuilt when the tab comes back
162
+ var el = chartRef.current;
163
+ if (!el || el.clientWidth === 0 || el.clientHeight === 0) return;
157
164
  (_chartInstanceRef$cur = chartInstanceRef.current) === null || _chartInstanceRef$cur === void 0 || _chartInstanceRef$cur.resize();
158
165
  }, []);
159
166
  useEffect(function () {
160
- if (!chartRef.current) return;
167
+ if (!chartRef.current || !containerReady) return;
161
168
  var chart = chartInstanceRef.current;
162
169
  if (!chart) {
163
170
  chart = echarts.init(chartRef.current);
@@ -281,7 +288,7 @@ var Radar = function Radar(props) {
281
288
  }
282
289
  }
283
290
  };
284
- }, [chartOption, handleResize, singleIndicatorEnabled, singleIndicatorRegion, singleIndicatorHighlight, singleIndicatorHoverFill, color]);
291
+ }, [chartOption, handleResize, singleIndicatorEnabled, singleIndicatorRegion, singleIndicatorHighlight, singleIndicatorHoverFill, color, containerReady]);
285
292
  useEffect(function () {
286
293
  return function () {
287
294
  if (resizeObserverRef.current) {
@@ -11,6 +11,7 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
11
11
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
12
12
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
13
13
  import React, { useCallback, useEffect, useMemo, useRef } from "react";
14
+ import useContainerReady from "../_hooks/useContainerReady";
14
15
  import styles from "../index.module.scss";
15
16
  import * as echarts from "echarts";
16
17
  import { jsx as _jsx } from "react/jsx-runtime";
@@ -23,6 +24,8 @@ var Sankey = function Sankey(props) {
23
24
  getImage = props.getImage;
24
25
  var chartRef = useRef(null);
25
26
  var chartInstanceRef = useRef(null);
27
+ // Defers `echarts.init` until the container has a box — see the hook for why
28
+ var containerReady = useContainerReady(chartRef);
26
29
  var resizeObserverRef = useRef(null);
27
30
 
28
31
  // Cache the chart option with useMemo
@@ -103,12 +106,16 @@ var Sankey = function Sankey(props) {
103
106
  // Callback handling chart resize
104
107
  var handleResize = useCallback(function () {
105
108
  var _chartInstanceRef$cur;
109
+ // A keep-alive tab losing focus fires the observer with a 0×0 box; resizing to that throws
110
+ // the laid-out canvas away and it has to be rebuilt when the tab comes back
111
+ var el = chartRef.current;
112
+ if (!el || el.clientWidth === 0 || el.clientHeight === 0) return;
106
113
  (_chartInstanceRef$cur = chartInstanceRef.current) === null || _chartInstanceRef$cur === void 0 || _chartInstanceRef$cur.resize();
107
114
  }, []);
108
115
 
109
116
  // Initialize the chart
110
117
  useEffect(function () {
111
- if (!chartRef.current) return;
118
+ if (!chartRef.current || !containerReady) return;
112
119
 
113
120
  // Initialize a new instance or reuse the existing one
114
121
  var chart = chartInstanceRef.current;
@@ -142,7 +149,7 @@ var Sankey = function Sankey(props) {
142
149
  return function () {
143
150
  window.removeEventListener("resize", handleResize);
144
151
  };
145
- }, [chartOption, handleResize, getImage]);
152
+ }, [chartOption, handleResize, getImage, containerReady]);
146
153
 
147
154
  // Clean up resources on unmount
148
155
  useEffect(function () {
@@ -5,6 +5,7 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
5
5
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
6
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
7
  import React, { useCallback, useEffect, useMemo, useRef } from "react";
8
+ import useContainerReady from "../_hooks/useContainerReady";
8
9
  import styles from "../index.module.scss";
9
10
  import * as echarts from "echarts";
10
11
  import { deepCopy } from "hsu-utils";
@@ -18,6 +19,8 @@ var Tree = function Tree(props) {
18
19
  getImage = props.getImage;
19
20
  var chartRef = useRef(null);
20
21
  var chartInstanceRef = useRef(null);
22
+ // Defers `echarts.init` until the container has a box — see the hook for why
23
+ var containerReady = useContainerReady(chartRef);
21
24
  var resizeObserverRef = useRef(null);
22
25
 
23
26
  // Cache the chart option with useMemo
@@ -38,12 +41,16 @@ var Tree = function Tree(props) {
38
41
  // Callback handling chart resize
39
42
  var handleResize = useCallback(function () {
40
43
  var _chartInstanceRef$cur;
44
+ // A keep-alive tab losing focus fires the observer with a 0×0 box; resizing to that throws
45
+ // the laid-out canvas away and it has to be rebuilt when the tab comes back
46
+ var el = chartRef.current;
47
+ if (!el || el.clientWidth === 0 || el.clientHeight === 0) return;
41
48
  (_chartInstanceRef$cur = chartInstanceRef.current) === null || _chartInstanceRef$cur === void 0 || _chartInstanceRef$cur.resize();
42
49
  }, []);
43
50
 
44
51
  // Initialize the chart
45
52
  useEffect(function () {
46
- if (!chartRef.current) return;
53
+ if (!chartRef.current || !containerReady) return;
47
54
 
48
55
  // Initialize a new instance or reuse the existing one
49
56
  var chart = chartInstanceRef.current;
@@ -77,7 +84,7 @@ var Tree = function Tree(props) {
77
84
  return function () {
78
85
  window.removeEventListener("resize", handleResize);
79
86
  };
80
- }, [chartOption, handleResize, getImage]);
87
+ }, [chartOption, handleResize, getImage, containerReady]);
81
88
 
82
89
  // Clean up resources on unmount
83
90
  useEffect(function () {
@@ -0,0 +1,18 @@
1
+ import { RefObject } from "react";
2
+ /**
3
+ * Whether the referenced element has a non-zero box yet.
4
+ *
5
+ * `echarts.init` on a 0×0 element logs `Can't get DOM width or height` and builds a canvas with no
6
+ * size, recovering only on the next `resize()`. A chart hits that path whenever it mounts before
7
+ * layout has given it space — inside a keep-alive tab that is not the active one, a collapsed
8
+ * panel, a modal that has not opened yet — so consuming apps see the warning for charts that end
9
+ * up rendering perfectly well.
10
+ *
11
+ * Gating `init` on this flag defers it to the first frame the element actually occupies space.
12
+ *
13
+ * It **latches**: once measured, the element going back to 0×0 (a keep-alive tab losing focus)
14
+ * must not read as "not ready" again, or the init effect would tear the chart down and re-create
15
+ * it on every tab switch.
16
+ */
17
+ declare const useContainerReady: (ref: RefObject<HTMLElement | null>) => boolean;
18
+ export default useContainerReady;