@zgfe/modules-interval 1.0.23-zhongyuan.7 → 1.0.23-zhongyuan.8

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.
@@ -112,6 +112,7 @@ var SearchPanel = function SearchPanel(props) {
112
112
  includeToday: true,
113
113
  selectRange: envs && envs.timeRangeOpen ? envs.timeRangeOpen : 36,
114
114
  timeRangeOpen: envs && envs.timeRangeOpen ? envs.timeRangeOpen : 36,
115
+ selectRangeUnit: envs && envs.timeRangeOpen ? 'months' : 'days',
115
116
  onChange: onChangeTime
116
117
  }), /*#__PURE__*/React.createElement(BizSelect, {
117
118
  multiple: true,
@@ -3,6 +3,8 @@ import "./index.less";
3
3
  var CustomTooltip = function CustomTooltip(_ref) {
4
4
  var payload = _ref.payload,
5
5
  series = _ref.series;
6
+ console.log(payload, series, 'payload, series');
7
+
6
8
  // 初始化,判断showList是否有值,如果没值,取结果的前10条
7
9
  useEffect(function () {}, []);
8
10
  function convertToHMS(seconds) {
@@ -13,7 +15,7 @@ var CustomTooltip = function CustomTooltip(_ref) {
13
15
  }
14
16
  // 根据payload中的数据定义弹窗内容
15
17
  var marker = payload === null || payload === void 0 ? void 0 : payload.marker;
16
- var value = payload === null || payload === void 0 ? void 0 : payload.value;
18
+ var value = payload === null || payload === void 0 ? void 0 : payload.data;
17
19
  return /*#__PURE__*/React.createElement("div", {
18
20
  className: "custom-tooltip-chart"
19
21
  }, /*#__PURE__*/React.createElement("div", {
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ import { eventChartProps } from './types';
3
+ declare const IntervalChart: React.FC<eventChartProps.Props>;
4
+ export default IntervalChart;
@@ -0,0 +1,299 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
6
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
+ import React, { useEffect, useRef, useState } from 'react';
8
+ import ReactECharts from 'echarts-for-react';
9
+ import * as echarts from 'echarts';
10
+ import { renderToString } from 'react-dom/server';
11
+ import CustomTooltip from "./customTooltip";
12
+ import { chartColors } from "../../constants";
13
+ import { getRandomColor } from "../../constants/color";
14
+ import { convertDateArray } from "../../utils/formData";
15
+ var _currentAxisBreaks = [{
16
+ start: 5000,
17
+ end: 100000,
18
+ gap: '1.5%'
19
+ }, {
20
+ start: 105000,
21
+ end: 3100000,
22
+ gap: '1.5%'
23
+ }];
24
+ var IntervalChart = function IntervalChart(props) {
25
+ var _useState = useState({}),
26
+ _useState2 = _slicedToArray(_useState, 2),
27
+ option = _useState2[0],
28
+ setOption = _useState2[1];
29
+ var chartRef = useRef(null);
30
+ useEffect(function () {
31
+ var _props$showList, _seriesData$series;
32
+ chartRef && chartRef.current.getEchartsInstance().clear();
33
+ var seriesData = props === null || props === void 0 ? void 0 : (_props$showList = props.showList) === null || _props$showList === void 0 ? void 0 : _props$showList.appData;
34
+ var params = props === null || props === void 0 ? void 0 : props.params;
35
+ var eCharts = {
36
+ tooltip: {
37
+ trigger: 'item',
38
+ // tooltip 跟随鼠标
39
+ position: function position(point, params, dom, rect, size) {
40
+ return [point[0] + 10, point[1] - 10];
41
+ },
42
+ axisPointer: {
43
+ type: 'line'
44
+ }
45
+ // formatter: (params: any) => {
46
+ // let tooltipString = ``;
47
+ // tooltipString += params.map((k) => {
48
+ // const item = seriesData?.series.find((it: any) => it.names[0] === k.name);
49
+ // return renderToString(<CustomTooltip series={item} payload={k} />);
50
+ // });
51
+ // return tooltipString;
52
+ // },
53
+ // formatter: (params: any) => {
54
+ // return renderToString(<CustomTooltip1 series={seriesData?.series} payload={params} />);
55
+ // },
56
+ },
57
+
58
+ legend: {
59
+ bottom: 0,
60
+ icon: 'circle',
61
+ type: 'scroll',
62
+ itemWidth: 10,
63
+ // 设置图例的宽度为10px
64
+ itemHeight: 10 // 设置图例的高度为10px
65
+ },
66
+
67
+ grid: {
68
+ top: '10',
69
+ left: '0',
70
+ right: '0',
71
+ bottom: props.onlyChart ? '0' : '68px',
72
+ containLabel: true
73
+ },
74
+ xAxis: {
75
+ type: 'category',
76
+ boundaryGap: true,
77
+ nameGap: 30,
78
+ data: convertDateArray(params, seriesData === null || seriesData === void 0 ? void 0 : seriesData.xAxis),
79
+ splitArea: {
80
+ show: false
81
+ },
82
+ splitLine: {
83
+ show: false
84
+ },
85
+ axisLine: {
86
+ lineStyle: {
87
+ color: '#E6E7EA' // 设置线条颜色
88
+ }
89
+ },
90
+
91
+ axisLabel: {
92
+ color: '#67727F' // 设置文字颜色
93
+ },
94
+
95
+ axisPointer: {
96
+ type: 'shadow'
97
+ }
98
+ },
99
+ yAxis: {
100
+ type: 'value',
101
+ splitLine: {
102
+ show: true,
103
+ lineStyle: {
104
+ type: 'dashed' // 设置线条类型为虚线
105
+ }
106
+ },
107
+
108
+ axisLabel: {
109
+ color: '#67727F' // 设置文字颜色
110
+ },
111
+
112
+ breaks: _currentAxisBreaks,
113
+ breakArea: {
114
+ itemStyle: {
115
+ opacity: 1
116
+ },
117
+ zigzagZ: 200
118
+ }
119
+ },
120
+ dataZoom: [{
121
+ type: 'inside',
122
+ start: 0,
123
+ end: 20,
124
+ right: 3,
125
+ height: 20 // 设置内置的dataZoom的高度
126
+ }, {
127
+ show: props.onlyChart ? false : true,
128
+ type: 'slider',
129
+ bottom: '38px',
130
+ xAxisIndex: [0],
131
+ start: 0,
132
+ end: 20,
133
+ right: 3,
134
+ height: 20 // 设置滑动条的高度
135
+ }],
136
+
137
+ series: seriesData === null || seriesData === void 0 ? void 0 : (_seriesData$series = seriesData.series) === null || _seriesData$series === void 0 ? void 0 : _seriesData$series.map(function (item, i) {
138
+ var _seriesData$series$i, _seriesData$series$i2;
139
+ // 生成随机颜色
140
+ var color = i < chartColors.length ? chartColors[i] : getRandomColor();
141
+ return {
142
+ type: 'boxplot',
143
+ datasetIndex: i,
144
+ name: seriesData === null || seriesData === void 0 ? void 0 : (_seriesData$series$i = seriesData.series[i]) === null || _seriesData$series$i === void 0 ? void 0 : _seriesData$series$i.names[0],
145
+ data: seriesData === null || seriesData === void 0 ? void 0 : (_seriesData$series$i2 = seriesData.series[i]) === null || _seriesData$series$i2 === void 0 ? void 0 : _seriesData$series$i2.values,
146
+ showBackground: true,
147
+ // 关键修改:背景改为透明
148
+ backgroundStyle: {
149
+ color: 'transparent'
150
+ },
151
+ emphasis: {
152
+ itemStyle: {
153
+ borderColor: item.type ? 'rgba(0,0,0,0.2)' : color // 设置盒子的颜色
154
+ },
155
+
156
+ tooltip: {
157
+ show: true,
158
+ // 单独配置series中的tooltip为显示
159
+ extraCssText: 'border: none;padding:0;border-radius:10px;background: rgba(250, 251, 253, 0.8)',
160
+ // 添加自定义的CSS样式,去掉边框
161
+ formatter: function formatter(params) {
162
+ var tooltipString = renderToString( /*#__PURE__*/React.createElement(CustomTooltip, {
163
+ series: seriesData === null || seriesData === void 0 ? void 0 : seriesData.series[i],
164
+ payload: params
165
+ }));
166
+ return tooltipString;
167
+ }
168
+ }
169
+ },
170
+ itemStyle: {
171
+ borderColor: item.type ? 'rgba(0,0,0,0.2)' : color
172
+ }
173
+ };
174
+ })
175
+ };
176
+ setOption(eCharts);
177
+ }, [props === null || props === void 0 ? void 0 : props.showList]);
178
+ var updateCollapseButton = function updateCollapseButton(params) {
179
+ // If there is any axis break expanded, we need to show the collapse button.
180
+ var needReset = false;
181
+ for (var i = 0; i < params.breaks.length; i++) {
182
+ var changedBreakItem = params.breaks[i];
183
+ if (changedBreakItem.isExpanded) {
184
+ needReset = true;
185
+ break;
186
+ }
187
+ }
188
+ setOption({
189
+ // Draw the collapse button.
190
+ graphic: [{
191
+ elements: [{
192
+ type: 'rect',
193
+ ignore: !needReset,
194
+ name: 'collapseAxisBreakBtn',
195
+ top: 5,
196
+ left: 5,
197
+ shape: {
198
+ r: 3,
199
+ width: 140,
200
+ height: 24
201
+ },
202
+ style: {
203
+ fill: '#eee',
204
+ stroke: '#999',
205
+ lineWidth: 1
206
+ },
207
+ textContent: {
208
+ type: 'text',
209
+ style: {
210
+ text: 'Collapse Axis Breaks',
211
+ fontSize: 13,
212
+ fontWeight: 'bold'
213
+ }
214
+ },
215
+ textConfig: {
216
+ position: 'inside'
217
+ }
218
+ }]
219
+ }]
220
+ });
221
+ };
222
+
223
+ // 获取实例
224
+ var _useState3 = useState(null),
225
+ _useState4 = _slicedToArray(_useState3, 2),
226
+ echartsInstance = _useState4[0],
227
+ setEchartsInstance = _useState4[1];
228
+ useEffect(function () {
229
+ console.log(chartRef.current.getEchartsInstance(), 'chartRef.current.getEchartsInstance()');
230
+ setEchartsInstance(chartRef.current.getEchartsInstance());
231
+ }, []);
232
+ return /*#__PURE__*/React.createElement(ReactECharts, {
233
+ ref: chartRef,
234
+ style: {
235
+ height: '431px',
236
+ padding: 24
237
+ },
238
+ option: option,
239
+ onEvents: {
240
+ axisbreakchanged: function axisbreakchanged(params) {
241
+ return updateCollapseButton(params);
242
+ },
243
+ mousemove: function mousemove(params) {
244
+ console.log('鼠标进入');
245
+ var pointInPixel = [params.offsetX, params.offsetY];
246
+ console.log(echartsInstance, 'echartsInstanceechartsInstance');
247
+
248
+ // 检查是否在网格区域内
249
+ if (echartsInstance && echartsInstance.containPixel('grid', pointInPixel)) {
250
+ var pointInGrid = echartsInstance && echartsInstance.convertFromPixel({
251
+ seriesIndex: 0
252
+ }, pointInPixel);
253
+ if (pointInGrid) {
254
+ var xIndex = Math.round(pointInGrid[0]);
255
+ var option = echartsInstance && echartsInstance.getOption();
256
+ var series = option.series;
257
+ var seriesCount = series.length;
258
+
259
+ // 获取网格区域信息
260
+ var grid = echartsInstance && echartsInstance.getModel().getComponent('grid', 0);
261
+ var gridRect = grid.coordinateSystem.getRect();
262
+
263
+ // 计算每个类目的宽度
264
+ var categoryCount = option.xAxis[0].data.length;
265
+ var categoryWidth = gridRect.width / categoryCount;
266
+
267
+ // 计算当前类目内的相对位置
268
+ var categoryStartX = gridRect.x + xIndex * categoryWidth;
269
+ var relativeX = params.offsetX - categoryStartX;
270
+
271
+ // 计算每个柱子的宽度(考虑柱子间距)
272
+ var barWidth = categoryWidth / seriesCount;
273
+
274
+ // 计算鼠标悬停在哪个系列的柱子上
275
+ var seriesIndex = Math.floor(relativeX / barWidth);
276
+
277
+ // 确保索引有效
278
+ if (seriesIndex >= 0 && seriesIndex < seriesCount && xIndex >= 0 && xIndex < categoryCount) {
279
+ // 显示跟随鼠标的 tooltip
280
+ echartsInstance && echartsInstance.dispatchAction({
281
+ type: 'showTip',
282
+ seriesIndex: seriesIndex,
283
+ dataIndex: xIndex,
284
+ position: [params.offsetX + 10, params.offsetY - 10]
285
+ });
286
+ }
287
+ }
288
+ }
289
+ },
290
+ mouseout: function mouseout() {
291
+ echartsInstance && echartsInstance.dispatchAction({
292
+ type: 'hideTip'
293
+ });
294
+ }
295
+ },
296
+ echarts: echarts
297
+ });
298
+ };
299
+ export default IntervalChart;
@@ -5,45 +5,105 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
5
5
  function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
6
6
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
7
  import React, { useEffect, useRef, useState } from 'react';
8
- import ReactECharts from 'echarts-for-react';
9
8
  import * as echarts from 'echarts';
10
9
  import { renderToString } from 'react-dom/server';
11
- import CustomTooltip1 from "./customTooltip1";
10
+ import CustomTooltip from "./customTooltip";
12
11
  import { chartColors } from "../../constants";
13
12
  import { getRandomColor } from "../../constants/color";
14
13
  import { convertDateArray } from "../../utils/formData";
14
+ var _currentAxisBreaks = [{
15
+ start: 5000,
16
+ end: 100000,
17
+ gap: '1.5%'
18
+ }, {
19
+ start: 105000,
20
+ end: 3100000,
21
+ gap: '1.5%'
22
+ }];
15
23
  var IntervalChart = function IntervalChart(props) {
16
24
  var _useState = useState({}),
17
25
  _useState2 = _slicedToArray(_useState, 2),
18
- option = _useState2[0],
19
- setOption = _useState2[1];
26
+ optionECharts = _useState2[0],
27
+ setOptionECharts = _useState2[1];
28
+ // 获取实例
20
29
  var chartRef = useRef(null);
30
+ var _useState3 = useState(null),
31
+ _useState4 = _slicedToArray(_useState3, 2),
32
+ chartInstance = _useState4[0],
33
+ setChartInstance = _useState4[1]; // echart实列
34
+ useEffect(function () {
35
+ var aDom = echarts.init(chartRef.current);
36
+ setChartInstance(aDom);
37
+ }, []);
21
38
  useEffect(function () {
22
39
  var _props$showList, _seriesData$series;
23
- chartRef && chartRef.current.getEchartsInstance().clear();
40
+ // chartRef && chartRef.current.getEchartsInstance().clear();
24
41
  var seriesData = props === null || props === void 0 ? void 0 : (_props$showList = props.showList) === null || _props$showList === void 0 ? void 0 : _props$showList.appData;
25
42
  var params = props === null || props === void 0 ? void 0 : props.params;
26
43
  var eCharts = {
27
44
  tooltip: {
28
- trigger: 'axis',
45
+ trigger: 'item',
46
+ // tooltip 跟随鼠标
47
+ // position: function (point, params, dom, rect, size) {
48
+ // return [point[0] + 10, point[1] - 10];
49
+ // },
50
+ // ========== 核心:重写position函数,防止tooltip溢出屏幕 ==========
51
+ position: function position(point, params, dom, rect, size) {
52
+ // 获取tooltip DOM元素的实际宽高(自定义HTML的尺寸)
53
+ var tooltipWidth = dom.offsetWidth || 200; // 默认宽度200px
54
+ var tooltipHeight = dom.offsetHeight || 150; // 默认高度150px
55
+
56
+ // 获取屏幕可视区域的宽高
57
+ var screenWidth = document.documentElement.clientWidth;
58
+ var screenHeight = document.documentElement.clientHeight;
59
+
60
+ // 鼠标当前坐标
61
+ var mouseX = point[0];
62
+ var mouseY = point[1];
63
+
64
+ // 计算tooltip的候选位置(初始:鼠标右侧+10px,鼠标上方-10px)
65
+ var targetX = mouseX + 10;
66
+ var targetY = mouseY - 10;
67
+
68
+ // 1. 右边界检测:如果tooltip超出屏幕右侧,显示在鼠标左侧
69
+ if (targetX + tooltipWidth > screenWidth) {
70
+ targetX = mouseX - tooltipWidth - 10;
71
+ }
72
+
73
+ // 2. 左边界检测:如果tooltip超出屏幕左侧,强制显示在屏幕左侧
74
+ if (targetX < 0) {
75
+ targetX = 10;
76
+ }
77
+
78
+ // 3. 下边界检测:如果tooltip超出屏幕下方,显示在鼠标下方
79
+ if (targetY + tooltipHeight > screenHeight) {
80
+ targetY = mouseY + 10;
81
+ }
82
+
83
+ // 4. 上边界检测:如果tooltip超出屏幕上方,强制显示在屏幕上方
84
+ if (targetY < 0) {
85
+ targetY = 10;
86
+ }
87
+
88
+ // 返回最终调整后的位置
89
+ return [targetX, targetY];
90
+ },
29
91
  axisPointer: {
30
92
  type: 'shadow'
31
93
  },
32
- // formatter: (params: any) => {
33
- // let tooltipString = ``;
34
- // tooltipString += params.map((k) => {
35
- // const item = seriesData?.series.find((it: any) => it.names[0] === k.name);
36
- // return renderToString(<CustomTooltip series={item} payload={k} />);
37
- // });
38
- // return tooltipString;
39
- // },
94
+ confine: true,
95
+ // 开启边界限制(ECharts内置,配合自定义position双重保障)
40
96
  formatter: function formatter(params) {
41
- return renderToString( /*#__PURE__*/React.createElement(CustomTooltip1, {
42
- series: seriesData === null || seriesData === void 0 ? void 0 : seriesData.series,
97
+ return renderToString( /*#__PURE__*/React.createElement(CustomTooltip, {
98
+ series: undefined,
43
99
  payload: params
44
100
  }));
45
101
  }
102
+ // formatter: (params: any) => {
103
+ // return renderToString(<CustomTooltip1 series={seriesData?.series} payload={params} />);
104
+ // },
46
105
  },
106
+
47
107
  legend: {
48
108
  bottom: 0,
49
109
  icon: 'circle',
@@ -79,23 +139,40 @@ var IntervalChart = function IntervalChart(props) {
79
139
 
80
140
  axisLabel: {
81
141
  color: '#67727F' // 设置文字颜色
142
+ },
143
+
144
+ axisPointer: {
145
+ type: 'shadow'
82
146
  }
83
147
  },
84
-
85
148
  yAxis: {
86
- type: 'value',
87
- splitLine: {
88
- show: true,
89
- lineStyle: {
90
- type: 'dashed' // 设置线条类型为虚线
91
- }
92
- },
149
+ // type: 'value',
150
+ // splitLine: {
151
+ // show: true,
152
+ // lineStyle: {
153
+ // type: 'dashed', // 设置线条类型为虚线
154
+ // },
155
+ // },
156
+ // axisLabel: {
157
+ // color: '#67727F', // 设置文字颜色
158
+ // },
159
+ // breaks: _currentAxisBreaks,
160
+ // breakArea: {
161
+ // itemStyle: {
162
+ // opacity: 1,
163
+ // },
164
+ // zigzagZ: 200,
165
+ // },
93
166
 
94
- axisLabel: {
95
- color: '#67727F' // 设置文字颜色
167
+ type: 'value',
168
+ breaks: _currentAxisBreaks,
169
+ breakArea: {
170
+ itemStyle: {
171
+ opacity: 1
172
+ },
173
+ zigzagZ: 200
96
174
  }
97
175
  },
98
-
99
176
  dataZoom: [{
100
177
  type: 'inside',
101
178
  start: 0,
@@ -122,10 +199,29 @@ var IntervalChart = function IntervalChart(props) {
122
199
  datasetIndex: 1,
123
200
  name: seriesData === null || seriesData === void 0 ? void 0 : (_seriesData$series$i = seriesData.series[i]) === null || _seriesData$series$i === void 0 ? void 0 : _seriesData$series$i.names[0],
124
201
  data: seriesData === null || seriesData === void 0 ? void 0 : (_seriesData$series$i2 = seriesData.series[i]) === null || _seriesData$series$i2 === void 0 ? void 0 : _seriesData$series$i2.values,
202
+ showBackground: true,
203
+ // 关键修改:背景改为透明
204
+ backgroundStyle: {
205
+ color: 'rgba(0,0,0,0.2)'
206
+ },
125
207
  emphasis: {
208
+ focus: 'series',
209
+ blurScope: 'coordinateSystem',
126
210
  itemStyle: {
127
211
  borderColor: color // 设置盒子的颜色
128
212
  }
213
+
214
+ // tooltip: {
215
+ // show: true, // 单独配置series中的tooltip为显示
216
+ // extraCssText:
217
+ // 'border: none;padding:0;border-radius:10px;background: rgba(250, 251, 253, 0.8)', // 添加自定义的CSS样式,去掉边框
218
+ // formatter: (params: any) => {
219
+ // const tooltipString = renderToString(
220
+ // <CustomTooltip series={seriesData?.series[i]} payload={params} />,
221
+ // );
222
+ // return tooltipString;
223
+ // },
224
+ // },
129
225
  },
130
226
 
131
227
  itemStyle: {
@@ -134,16 +230,202 @@ var IntervalChart = function IntervalChart(props) {
134
230
  };
135
231
  })
136
232
  };
137
- setOption(eCharts);
233
+ setOptionECharts(eCharts);
138
234
  }, [props === null || props === void 0 ? void 0 : props.showList]);
139
- return /*#__PURE__*/React.createElement(ReactECharts, {
235
+ useEffect(function () {
236
+ chartInstance && chartInstance.setOption(optionECharts);
237
+ }, [optionECharts]);
238
+ useEffect(function () {
239
+ setTimeout(function () {
240
+ chartInstance && chartInstance.on('axisbreakchanged', function (params) {
241
+ updateCollapseButton(params);
242
+ });
243
+ // =========================
244
+ // 关键修改:结合 dataZoom 的可见索引范围
245
+ // =========================
246
+
247
+ // 当前 x 轴可见的起止 dataIndex(受 dataZoom 控制)
248
+ var baseOption = chartInstance && chartInstance.getOption();
249
+ var totalCategoryCount = baseOption && baseOption.xAxis[0].data.length;
250
+ var visibleStartIndex = 0;
251
+ var visibleEndIndex = totalCategoryCount - 1;
252
+
253
+ // 根据 dataZoom 的 start / end 百分比更新可见索引范围[web:28]
254
+ function updateVisibleRangeFromDataZoom(params) {
255
+ var startPercent;
256
+ var endPercent;
257
+ if (params && params.batch && params.batch.length) {
258
+ // 事件中 batch 数组形式
259
+ startPercent = params.batch[0].start;
260
+ endPercent = params.batch[0].end;
261
+ } else if (params) {
262
+ startPercent = params.start;
263
+ endPercent = params.end;
264
+ }
265
+ if (startPercent == null || endPercent == null) {
266
+ return;
267
+ }
268
+ var optionNow = chartInstance && chartInstance.getOption();
269
+ var axisData = optionNow.xAxis[0].data || [];
270
+ var total = axisData.length || 1;
271
+ visibleStartIndex = Math.round(startPercent / 100 * (total - 1));
272
+ visibleEndIndex = Math.round(endPercent / 100 * (total - 1));
273
+ if (visibleStartIndex < 0) visibleStartIndex = 0;
274
+ if (visibleEndIndex > total - 1) visibleEndIndex = total - 1;
275
+ }
276
+
277
+ // 初始化一次可见范围(用当前 option 中 dataZoom 的配置)
278
+ if (baseOption && baseOption.dataZoom && baseOption && baseOption.dataZoom.length) {
279
+ updateVisibleRangeFromDataZoom(baseOption.dataZoom[0]);
280
+ }
281
+
282
+ // 监听 dataZoom 事件,更新可见范围
283
+ chartInstance && chartInstance.on('dataZoom', function (params) {
284
+ updateVisibleRangeFromDataZoom(params);
285
+ });
286
+
287
+ // 封装鼠标移动时的计算逻辑
288
+ function handleMouseMove(params) {
289
+ var pointInPixel = [params.offsetX, params.offsetY];
290
+
291
+ // 检查是否在网格区域内
292
+ if (!chartInstance && chartInstance.containPixel('grid', pointInPixel)) {
293
+ chartInstance && chartInstance.dispatchAction({
294
+ type: 'hideTip'
295
+ });
296
+ return;
297
+ }
298
+
299
+ // 使用当前坐标系(考虑 dataZoom / axisBreak)将像素坐标转为数据坐标[web:19]
300
+ var pointInGrid = chartInstance && chartInstance.convertFromPixel({
301
+ xAxisIndex: 0,
302
+ yAxisIndex: 0
303
+ }, pointInPixel);
304
+ if (!pointInGrid) {
305
+ chartInstance && chartInstance.dispatchAction({
306
+ type: 'hideTip'
307
+ });
308
+ return;
309
+ }
310
+ var xIndex = Math.round(pointInGrid[0]);
311
+ var optionNow = chartInstance && chartInstance.getOption();
312
+ var series = optionNow.series || [];
313
+ var seriesCount = series.length;
314
+
315
+ // 如果当前 xIndex 不在 dataZoom 可见范围内,直接不显示 tooltip
316
+ if (xIndex < visibleStartIndex || xIndex > visibleEndIndex) {
317
+ chartInstance && chartInstance.dispatchAction({
318
+ type: 'hideTip'
319
+ });
320
+ return;
321
+ }
322
+
323
+ // 获取当前网格区域信息(会随 dataZoom / resize 变化)
324
+ var gridModel = chartInstance && chartInstance.getModel().getComponent('grid', 0);
325
+ var gridRect = gridModel.coordinateSystem.getRect();
326
+
327
+ // 当前可见类目数量(只按 dataZoom 可见区计算宽度)
328
+ var visibleCategoryCount = visibleEndIndex - visibleStartIndex + 1;
329
+ if (visibleCategoryCount <= 0) {
330
+ chartInstance && chartInstance.dispatchAction({
331
+ type: 'hideTip'
332
+ });
333
+ return;
334
+ }
335
+
336
+ // 每个可见类目在当前网格中的宽度
337
+ var categoryWidth = gridRect.width / visibleCategoryCount;
338
+
339
+ // 当前类目的起点 = grid 起点 + (xIndex - visibleStartIndex) * 每类宽度
340
+ var categoryStartX = gridRect.x + (xIndex - visibleStartIndex) * categoryWidth;
341
+
342
+ // 鼠标在当前类目内的相对 X 位置
343
+ var relativeX = params.offsetX - categoryStartX;
344
+
345
+ // 计算每个 series 对应的“柱子”宽度(背景区域同样分配)
346
+ var barWidth = categoryWidth / seriesCount;
347
+
348
+ // 鼠标当前所在的系列下标(按背景区域来划分)
349
+ var seriesIndex = Math.floor(relativeX / barWidth);
350
+
351
+ // 索引有效性判断
352
+ var categoryTotal = optionNow.xAxis[0].data.length;
353
+ if (seriesIndex >= 0 && seriesIndex < seriesCount && xIndex >= 0 && xIndex < categoryTotal) {
354
+ // 显示跟随鼠标的 tooltip(包括柱子上方的背景区域)
355
+ chartInstance && chartInstance.dispatchAction({
356
+ type: 'showTip',
357
+ seriesIndex: seriesIndex,
358
+ dataIndex: xIndex,
359
+ position: [params.offsetX + 10, params.offsetY - 10]
360
+ });
361
+ } else {
362
+ chartInstance && chartInstance.dispatchAction({
363
+ type: 'hideTip'
364
+ });
365
+ }
366
+ }
367
+
368
+ // 添加鼠标移动监听,计算鼠标位置对应的具体柱子(考虑 dataZoom 后的新显示)
369
+ chartInstance && chartInstance.getZr().on('mousemove', function (params) {
370
+ handleMouseMove(params);
371
+ });
372
+ chartInstance && chartInstance.getZr().on('mouseout', function () {
373
+ chartInstance && chartInstance.dispatchAction({
374
+ type: 'hideTip'
375
+ });
376
+ });
377
+ }, 0);
378
+ }, [chartInstance]);
379
+ function updateCollapseButton(params) {
380
+ // If there is any axis break expanded, we need to show the collapse button.
381
+ var needReset = false;
382
+ for (var i = 0; i < params.breaks.length; i++) {
383
+ var changedBreakItem = params.breaks[i];
384
+ if (changedBreakItem.isExpanded) {
385
+ needReset = true;
386
+ break;
387
+ }
388
+ }
389
+ setOptionECharts({
390
+ // Draw the collapse button.
391
+ graphic: [{
392
+ elements: [{
393
+ type: 'rect',
394
+ ignore: !needReset,
395
+ name: 'collapseAxisBreakBtn',
396
+ top: 5,
397
+ left: 5,
398
+ shape: {
399
+ r: 3,
400
+ width: 140,
401
+ height: 24
402
+ },
403
+ style: {
404
+ fill: '#eee',
405
+ stroke: '#999',
406
+ lineWidth: 1
407
+ },
408
+ textContent: {
409
+ type: 'text',
410
+ style: {
411
+ text: 'Collapse Axis Breaks',
412
+ fontSize: 13,
413
+ fontWeight: 'bold'
414
+ }
415
+ },
416
+ textConfig: {
417
+ position: 'inside'
418
+ }
419
+ }]
420
+ }]
421
+ });
422
+ }
423
+ return /*#__PURE__*/React.createElement("div", {
140
424
  ref: chartRef,
141
425
  style: {
142
- height: '431px',
143
- padding: 24
144
- },
145
- option: option,
146
- echarts: echarts
426
+ width: '100%',
427
+ height: '400px'
428
+ }
147
429
  });
148
430
  };
149
431
  export default IntervalChart;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zgfe/modules-interval",
3
- "version": "1.0.23-zhongyuan.7",
3
+ "version": "1.0.23-zhongyuan.8",
4
4
  "private": false,
5
5
  "module": "dist/esm/index.js",
6
6
  "typings": "dist/esm/index.d.ts",
@@ -42,7 +42,7 @@
42
42
  "@types/uuid": "^9.0.2",
43
43
  "@umijs/fabric": "^2.8.1",
44
44
  "@umijs/test": "^3.0.5",
45
- "@zgfe/business-lib": "1.2.70-hxd.31",
45
+ "@zgfe/business-lib": "1.2.70-hxd.1",
46
46
  "antd": "^4.22.6",
47
47
  "dumi": "^1.1.0",
48
48
  "echarts": "^5.3.2",
@@ -59,7 +59,7 @@
59
59
  "publishConfig": {
60
60
  "access": "public"
61
61
  },
62
- "gitHead": "a87d5d2364b644df413e5fc3aa2092302252be5a",
62
+ "gitHead": "780c85ab01f850993b44a85e7714ed33224040ac",
63
63
  "gitHooks": {
64
64
  "pre-commit": "lint-staged"
65
65
  }