@easyv/charts 1.10.28 → 1.10.30
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/lib/components/CartesianChart.js +26 -4
- package/lib/components/Control.js +7 -0
- package/lib/components/Legend.js +42 -21
- package/lib/components/PieChart.js +2 -2
- package/lib/utils/index.js +31 -1
- package/package.json +2 -2
- package/src/components/CartesianChart.js +35 -2
- package/src/components/Control.jsx +7 -1
- package/src/components/Legend.js +101 -84
- package/src/components/PieChart.js +1629 -1629
- package/src/utils/index.js +26 -0
|
@@ -14,6 +14,7 @@ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/sli
|
|
|
14
14
|
var _react = _interopRequireWildcard(require("react"));
|
|
15
15
|
var _hooks = require("../hooks");
|
|
16
16
|
var _context = require("../context");
|
|
17
|
+
var _utils = require("../utils");
|
|
17
18
|
var _ = require(".");
|
|
18
19
|
var _excluded = ["Component", "yOrZ"],
|
|
19
20
|
_excluded2 = ["Component", "yOrZ"];
|
|
@@ -327,7 +328,10 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
|
|
|
327
328
|
var controlTimer = (0, _react.useRef)(); //控制条的动画计时器
|
|
328
329
|
var ctlBarX = (0, _react.useRef)(0); //控制条的滑块偏移值
|
|
329
330
|
var isWorking = (0, _react.useRef)(false); //控制条是否正在进行各种操作
|
|
330
|
-
|
|
331
|
+
var controlInfoRef = (0, _react.useRef)(controlInfo);
|
|
332
|
+
var axisXRef = (0, _react.useRef)(axisX);
|
|
333
|
+
controlInfoRef.current = controlInfo;
|
|
334
|
+
axisXRef.current = axisX;
|
|
331
335
|
var range = function range(num, ignoreMax) {
|
|
332
336
|
var _num = num;
|
|
333
337
|
var min = 0;
|
|
@@ -344,9 +348,11 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
|
|
|
344
348
|
var moveLen = range(x);
|
|
345
349
|
if (needSave) ctlBarX.current = moveLen;
|
|
346
350
|
setControlInfo(function (pre) {
|
|
347
|
-
|
|
351
|
+
var next = _objectSpread(_objectSpread({}, pre), {}, {
|
|
348
352
|
cBarX: moveLen
|
|
349
353
|
});
|
|
354
|
+
controlInfoRef.current = next;
|
|
355
|
+
return next;
|
|
350
356
|
});
|
|
351
357
|
};
|
|
352
358
|
var setControlWidth = function setControlWidth(fn) {
|
|
@@ -355,9 +361,24 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
|
|
|
355
361
|
var x = pre.cBarX;
|
|
356
362
|
var moveLen = range(x, ignoreMax);
|
|
357
363
|
ctlBarX.current = moveLen;
|
|
358
|
-
|
|
364
|
+
var next = fn(pre);
|
|
365
|
+
controlInfoRef.current = next;
|
|
366
|
+
return next;
|
|
359
367
|
});
|
|
360
368
|
};
|
|
369
|
+
var emitControlRangeChange = (0, _react.useCallback)(function () {
|
|
370
|
+
if (!control) return;
|
|
371
|
+
var visibleData = (0, _utils.getControlVisibleData)(originData, axisXRef.current, controlInfoRef.current, chartWidth);
|
|
372
|
+
var eventData = {
|
|
373
|
+
data: visibleData
|
|
374
|
+
};
|
|
375
|
+
triggerOnRelative("dataChange", eventData);
|
|
376
|
+
onEmit("dataChange", eventData);
|
|
377
|
+
}, [control, originData, chartWidth, triggerOnRelative, onEmit]);
|
|
378
|
+
(0, _react.useEffect)(function () {
|
|
379
|
+
if (!control) return;
|
|
380
|
+
emitControlRangeChange();
|
|
381
|
+
}, [control, chartWidth, height, JSON.stringify(originData), JSON.stringify(control), emitControlRangeChange]);
|
|
361
382
|
//设置控制条是否正在进行拖拽/缩放操作
|
|
362
383
|
var setWorking = function setWorking(bool) {
|
|
363
384
|
isWorking.current = bool;
|
|
@@ -745,7 +766,8 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
|
|
|
745
766
|
actions: {
|
|
746
767
|
setX: setControlTranslate,
|
|
747
768
|
setWorking: setWorking,
|
|
748
|
-
setControlWidth: setControlWidth
|
|
769
|
+
setControlWidth: setControlWidth,
|
|
770
|
+
onControlChange: emitControlRangeChange
|
|
749
771
|
},
|
|
750
772
|
props: {
|
|
751
773
|
control: control,
|
|
@@ -23,6 +23,7 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(/*#__PURE__*/(
|
|
|
23
23
|
setX = _props$actions.setX,
|
|
24
24
|
setWorking = _props$actions.setWorking,
|
|
25
25
|
setControlWidth = _props$actions.setControlWidth,
|
|
26
|
+
onControlChange = _props$actions.onControlChange,
|
|
26
27
|
_props$props = props.props,
|
|
27
28
|
_props$props$control = _props$props.control,
|
|
28
29
|
thumbnail = _props$props$control.thumbnail,
|
|
@@ -92,6 +93,7 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(/*#__PURE__*/(
|
|
|
92
93
|
var _up = function up() {
|
|
93
94
|
document.removeEventListener("mousemove", move);
|
|
94
95
|
document.removeEventListener("mouseup", _up);
|
|
96
|
+
onControlChange === null || onControlChange === void 0 || onControlChange();
|
|
95
97
|
};
|
|
96
98
|
document.addEventListener("mousemove", move);
|
|
97
99
|
document.addEventListener("mouseup", _up);
|
|
@@ -126,6 +128,7 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(/*#__PURE__*/(
|
|
|
126
128
|
var _up2 = function up(e) {
|
|
127
129
|
document.removeEventListener("touchmove", move);
|
|
128
130
|
document.removeEventListener("touchend", _up2);
|
|
131
|
+
onControlChange === null || onControlChange === void 0 || onControlChange();
|
|
129
132
|
};
|
|
130
133
|
document.addEventListener("touchmove", move, {
|
|
131
134
|
passive: false
|
|
@@ -146,6 +149,7 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(/*#__PURE__*/(
|
|
|
146
149
|
setWorking(false);
|
|
147
150
|
document.removeEventListener("mousemove", mouseMoveHandle);
|
|
148
151
|
document.removeEventListener("mouseup", _mouseUpHandle);
|
|
152
|
+
onControlChange === null || onControlChange === void 0 || onControlChange();
|
|
149
153
|
};
|
|
150
154
|
document.addEventListener("mousemove", mouseMoveHandle);
|
|
151
155
|
document.addEventListener("mouseup", _mouseUpHandle);
|
|
@@ -169,6 +173,7 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(/*#__PURE__*/(
|
|
|
169
173
|
setWorking(false);
|
|
170
174
|
document.removeEventListener("touchmove", mouseMoveHandle);
|
|
171
175
|
document.removeEventListener("touchend", _mouseUpHandle2);
|
|
176
|
+
onControlChange === null || onControlChange === void 0 || onControlChange();
|
|
172
177
|
};
|
|
173
178
|
document.addEventListener("touchmove", mouseMoveHandle, {
|
|
174
179
|
passive: false
|
|
@@ -198,6 +203,7 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(/*#__PURE__*/(
|
|
|
198
203
|
var _up3 = function up() {
|
|
199
204
|
document.removeEventListener("mousemove", move);
|
|
200
205
|
document.removeEventListener("mouseup", _up3);
|
|
206
|
+
onControlChange === null || onControlChange === void 0 || onControlChange();
|
|
201
207
|
};
|
|
202
208
|
document.addEventListener("mousemove", move);
|
|
203
209
|
document.addEventListener("mouseup", _up3);
|
|
@@ -229,6 +235,7 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(/*#__PURE__*/(
|
|
|
229
235
|
var _up4 = function up(e) {
|
|
230
236
|
document.removeEventListener("touchmove", move);
|
|
231
237
|
document.removeEventListener("touchend", _up4);
|
|
238
|
+
onControlChange === null || onControlChange === void 0 || onControlChange();
|
|
232
239
|
};
|
|
233
240
|
document.addEventListener("touchmove", move, {
|
|
234
241
|
passive: false
|
package/lib/components/Legend.js
CHANGED
|
@@ -27,7 +27,7 @@ var defaultFont = {
|
|
|
27
27
|
fontWeight: "normal"
|
|
28
28
|
};
|
|
29
29
|
var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref) {
|
|
30
|
-
var _config$value, _config$percent, _config$value2, _config$value3, _config$name,
|
|
30
|
+
var _ref2, _config$value, _config$percent, _config$value2, _config$value3, _config$name, _ref4;
|
|
31
31
|
var series = _ref.series,
|
|
32
32
|
height = _ref.height,
|
|
33
33
|
data = _ref.data,
|
|
@@ -88,15 +88,30 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
|
|
|
88
88
|
var _useState = (0, _react.useState)(0),
|
|
89
89
|
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
|
90
90
|
scrollStep = _useState2[0],
|
|
91
|
-
setScrollStep = _useState2[1]; //
|
|
91
|
+
setScrollStep = _useState2[1]; // 每次滚动距离
|
|
92
|
+
var _useState3 = (0, _react.useState)(null),
|
|
93
|
+
_useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
|
|
94
|
+
loopContainerHeight = _useState4[0],
|
|
95
|
+
setLoopContainerHeight = _useState4[1]; // 按父高度推算的 loop 视口高度
|
|
92
96
|
|
|
93
|
-
//
|
|
97
|
+
// 根据父级 height 计算可见项数,视口高度 = N*行高 + (N-1)*间距(最后一项下方不留空)
|
|
94
98
|
(0, _react.useEffect)(function () {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
99
|
+
var _series$length;
|
|
100
|
+
if (!ref_container.current) return;
|
|
101
|
+
var li = ref_container.current.querySelector("li");
|
|
102
|
+
if (!li) return;
|
|
103
|
+
var itemHeight = li.offsetHeight;
|
|
104
|
+
var step = itemHeight + gridRowGap;
|
|
105
|
+
setScrollStep(step);
|
|
106
|
+
if (!loop.show || !height) {
|
|
107
|
+
setLoopContainerHeight(null);
|
|
108
|
+
return;
|
|
98
109
|
}
|
|
99
|
-
|
|
110
|
+
var totalItems = (_series$length = series === null || series === void 0 ? void 0 : series.length) !== null && _series$length !== void 0 ? _series$length : 0;
|
|
111
|
+
var visibleCount = Math.min(totalItems, Math.max(1, Math.floor((height + gridRowGap) / step)));
|
|
112
|
+
setLoopContainerHeight(visibleCount * itemHeight + Math.max(0, visibleCount - 1) * gridRowGap);
|
|
113
|
+
}, [gridRowGap, loop.show, series, height]);
|
|
114
|
+
var loopHeight = loop.show ? (_ref2 = loopContainerHeight !== null && loopContainerHeight !== void 0 ? loopContainerHeight : height) !== null && _ref2 !== void 0 ? _ref2 : "auto" : "auto";
|
|
100
115
|
|
|
101
116
|
// 启动自动滚动定时器
|
|
102
117
|
(0, _react.useEffect)(function () {
|
|
@@ -155,8 +170,8 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
|
|
|
155
170
|
var valueSuffix = ((_config$value2 = config.value) === null || _config$value2 === void 0 || (_config$value2 = _config$value2.suffix) === null || _config$value2 === void 0 ? void 0 : _config$value2.text) || "";
|
|
156
171
|
var valueSplitConfig = ((_config$value3 = config.value) === null || _config$value3 === void 0 ? void 0 : _config$value3.splitConfig) || {};
|
|
157
172
|
var getValueStr = function getValueStr(item) {
|
|
158
|
-
var
|
|
159
|
-
var valueStr = ((
|
|
173
|
+
var _ref3, _item$data$y, _item$data;
|
|
174
|
+
var valueStr = ((_ref3 = (_item$data$y = (_item$data = item.data) === null || _item$data === void 0 ? void 0 : _item$data.y) !== null && _item$data$y !== void 0 ? _item$data$y : item.value) !== null && _ref3 !== void 0 ? _ref3 : "") + (valueSuffix || "");
|
|
160
175
|
if (valueSplitConfig.show && valueSplitConfig.separator) {
|
|
161
176
|
valueStr = valueStr.toString().replace(/\B(?=(\d{3})+(?!\d))/g, valueSplitConfig.separator);
|
|
162
177
|
}
|
|
@@ -213,13 +228,15 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
|
|
|
213
228
|
var isFixedWidth = isPieChart ? isPieFixedWidthGrid : LegendType == "FixedWidth";
|
|
214
229
|
var isSideLegend = isPieAdaptive && isSidePlacement;
|
|
215
230
|
var isTopBottomAdaptive = isPieAdaptive && isCenterTopOrBottom;
|
|
216
|
-
var fullWidth = (
|
|
231
|
+
var fullWidth = (_ref4 = componentWidth !== null && componentWidth !== void 0 ? componentWidth : chartWidth) !== null && _ref4 !== void 0 ? _ref4 : 0;
|
|
217
232
|
// Adaptive+上下:组件总宽;Adaptive+左右:仅 maxWidth = 总宽 − 左右 chart.margin,宽度由内容撑开
|
|
218
233
|
var pieLegendFullWidth = Math.max(0, fullWidth);
|
|
219
234
|
var pieLegendInnerWidth = Math.max(0, fullWidth - marginLeft - marginRight);
|
|
220
235
|
var sideLegendMaxWidth = isSideLegend ? pieLegendInnerWidth : 0;
|
|
221
236
|
var fixedColumnsPerRow = Math.min(Math.max(1, Number(gridTemplateColumns) || 1), length);
|
|
222
237
|
var isPieTopBottomFixedMultiCol = isPieChart && isFixedWidth && isCenterTopOrBottom && fixedColumnsPerRow > 1;
|
|
238
|
+
var columnsPerRow = Math.max(1, Number(gridTemplateColumns) || 1);
|
|
239
|
+
var totalRows = Math.ceil(length / columnsPerRow);
|
|
223
240
|
var formatterExtra = _objectSpread(_objectSpread(_objectSpread({}, config), {}, {
|
|
224
241
|
valueMaxWidth: valueMaxWidth,
|
|
225
242
|
percentMaxWidth: percentMaxWidth,
|
|
@@ -284,13 +301,15 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
|
|
|
284
301
|
speed: speed
|
|
285
302
|
})));
|
|
286
303
|
};
|
|
304
|
+
var legendAlignContent = alignment.split(" ")[0] == "center" && (alignment.split(" ")[1] == "left" || alignment.split(" ")[1] == "right") ? alignment.split(" ")[1] == "left" ? "flex-start" : "flex-end" : alignment.split(" ")[0] == "left" ? "flex-start" : alignment.split(" ")[0] == "center" ? "center" : "flex-end";
|
|
287
305
|
var stylePieOrAxis = formatter ? _objectSpread(_objectSpread({
|
|
288
306
|
display: "flex",
|
|
289
|
-
alignContent:
|
|
307
|
+
alignContent: loop.show ? "flex-start" : legendAlignContent,
|
|
290
308
|
flexDirection: "column",
|
|
309
|
+
gap: loop.show ? "".concat(gridRowGap, "px") : undefined,
|
|
291
310
|
position: "absolute"
|
|
292
311
|
}, getPosition(position, _alignment, x, y)), {}, {
|
|
293
|
-
height:
|
|
312
|
+
height: loopHeight,
|
|
294
313
|
overflowY: loop.show ? "scroll" : "auto"
|
|
295
314
|
}) : _objectSpread(_objectSpread({
|
|
296
315
|
width: "100%",
|
|
@@ -298,20 +317,22 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
|
|
|
298
317
|
boxSizing: "border-box",
|
|
299
318
|
position: "absolute"
|
|
300
319
|
}, getPosition(position, _alignment, x, y)), {}, {
|
|
301
|
-
height:
|
|
320
|
+
height: loopHeight,
|
|
302
321
|
overflowY: loop.show ? "scroll" : "auto"
|
|
303
322
|
});
|
|
304
323
|
if (isPieAdaptive && isSideLegend) {
|
|
305
324
|
// 左右侧图例:水平方向始终左对齐,图标落在同一条纵线上(与九宫格水平分量无关)
|
|
306
|
-
var pieAdaptiveWrapperStyle = _objectSpread(_objectSpread({
|
|
325
|
+
var pieAdaptiveWrapperStyle = _objectSpread(_objectSpread(_objectSpread({
|
|
307
326
|
position: "absolute",
|
|
308
327
|
display: "flex",
|
|
309
328
|
flexDirection: "column",
|
|
310
329
|
width: "max-content",
|
|
311
330
|
maxWidth: sideLegendMaxWidth || undefined,
|
|
312
331
|
alignItems: "flex-start"
|
|
313
|
-
},
|
|
314
|
-
|
|
332
|
+
}, loop.show ? {
|
|
333
|
+
justifyContent: "flex-start"
|
|
334
|
+
} : {}), getPosition(position, _alignment, x, y)), {}, {
|
|
335
|
+
height: loopHeight,
|
|
315
336
|
overflowY: loop.show ? "scroll" : "auto"
|
|
316
337
|
});
|
|
317
338
|
var pieAdaptiveListStyle = {
|
|
@@ -342,7 +363,7 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
|
|
|
342
363
|
maxWidth: pieLegendFullWidth || "100%",
|
|
343
364
|
boxSizing: "border-box"
|
|
344
365
|
}, getPosition(position, _alignment, x, y)), {}, {
|
|
345
|
-
height:
|
|
366
|
+
height: loopHeight,
|
|
346
367
|
overflowY: loop.show ? "scroll" : "auto"
|
|
347
368
|
});
|
|
348
369
|
var topBottomListStyle = {
|
|
@@ -414,7 +435,7 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
|
|
|
414
435
|
position: "absolute",
|
|
415
436
|
display: "flex"
|
|
416
437
|
}, getPosition(position, _alignment, x, y)), {}, {
|
|
417
|
-
height:
|
|
438
|
+
height: loopHeight,
|
|
418
439
|
overflowY: loop.show ? "scroll" : "auto"
|
|
419
440
|
}),
|
|
420
441
|
ref: ref_container
|
|
@@ -473,7 +494,7 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
|
|
|
473
494
|
className: "__easyv-legend-wrapper",
|
|
474
495
|
style: stylePieOrAxis,
|
|
475
496
|
ref: ref_container
|
|
476
|
-
}, formatter ? (0, _toConsumableArray2["default"])(Array(
|
|
497
|
+
}, formatter ? (0, _toConsumableArray2["default"])(Array(totalRows)).map(function (_, indexs) {
|
|
477
498
|
return /*#__PURE__*/_react["default"].createElement("ul", {
|
|
478
499
|
key: indexs,
|
|
479
500
|
style: {
|
|
@@ -481,10 +502,10 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
|
|
|
481
502
|
width: "fit-content",
|
|
482
503
|
justifyContent: legendMainAlign,
|
|
483
504
|
gap: "".concat(gridRowGap, "px ").concat(gridColumnGap, "px"),
|
|
484
|
-
|
|
505
|
+
margin: 0
|
|
485
506
|
}
|
|
486
507
|
}, _series.map(function (series, i) {
|
|
487
|
-
if (Math.floor(i /
|
|
508
|
+
if (Math.floor(i / columnsPerRow) == indexs) {
|
|
488
509
|
var _series$config4;
|
|
489
510
|
var type = series.type,
|
|
490
511
|
name = series.name,
|
|
@@ -27,8 +27,8 @@ var _excluded = ["startAngle", "endAngle", "antiClockwise"],
|
|
|
27
27
|
_excluded2 = ["padAngle", "innerRadius", "outerRadius", "cornerRadius", "startAngle", "endAngle"],
|
|
28
28
|
_excluded3 = ["formatter"],
|
|
29
29
|
_excluded4 = ["startAngle", "endAngle"];
|
|
30
|
-
/**
|
|
31
|
-
* 饼环图
|
|
30
|
+
/**
|
|
31
|
+
* 饼环图
|
|
32
32
|
*/
|
|
33
33
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
34
34
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
|
package/lib/utils/index.js
CHANGED
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.SvgBackground = void 0;
|
|
8
8
|
exports.band = band;
|
|
9
|
-
exports.sortPie = exports.seriesYOrZ = exports.reverseGradientStops = exports.resetStacks = exports.renderCanvasBackground = exports.reduceConfig = exports.mathR = exports.isValidHttpUrl = exports.identity = exports.getTranslate3d = exports.getTranslate2d = exports.getTicksOfAxis = exports.getTickCoord = exports.getStacks = exports.getSeriesInfo = exports.getMultiColorStr = exports.getMousePos = exports.getMargin = exports.getIcon = exports.getGridCoord = exports.getFontStyle = exports.getDomPath = exports.getDataWithPercent = exports.getCurrentStack = exports.getColorList = exports.getChildren = exports.getBreakWord = exports.getBandwidth = exports.getBandSeriesStepAndWidth = exports.getBandBackground = exports.formatFont = exports.filterChildren = exports.dateFormat = exports.dataYOrZ = void 0;
|
|
9
|
+
exports.sortPie = exports.seriesYOrZ = exports.reverseGradientStops = exports.resetStacks = exports.renderCanvasBackground = exports.reduceConfig = exports.mathR = exports.isValidHttpUrl = exports.identity = exports.getTranslate3d = exports.getTranslate2d = exports.getTicksOfAxis = exports.getTickCoord = exports.getStacks = exports.getSeriesInfo = exports.getMultiColorStr = exports.getMousePos = exports.getMargin = exports.getIcon = exports.getGridCoord = exports.getFontStyle = exports.getDomPath = exports.getDataWithPercent = exports.getCurrentStack = exports.getControlVisibleData = exports.getColorList = exports.getChildren = exports.getBreakWord = exports.getBandwidth = exports.getBandSeriesStepAndWidth = exports.getBandBackground = exports.formatFont = exports.filterChildren = exports.dateFormat = exports.dataYOrZ = void 0;
|
|
10
10
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
11
11
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
12
12
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
@@ -910,4 +910,34 @@ var mathR = exports.mathR = function mathR(value, range) {
|
|
|
910
910
|
min = _range[0],
|
|
911
911
|
max = _range[1];
|
|
912
912
|
return Math.max(min, Math.min(value, max));
|
|
913
|
+
};
|
|
914
|
+
|
|
915
|
+
/**
|
|
916
|
+
* 根据控制条位置计算当前图表视口内可见的原始数据
|
|
917
|
+
*/
|
|
918
|
+
var getControlVisibleData = exports.getControlVisibleData = function getControlVisibleData(originData, axisX, controlInfo, chartWidth) {
|
|
919
|
+
if (!(originData !== null && originData !== void 0 && originData.length) || !axisX || !controlInfo) return [];
|
|
920
|
+
var cBarX = controlInfo.cBarX,
|
|
921
|
+
cBarWidth = controlInfo.cBarWidth,
|
|
922
|
+
cWidth = controlInfo.cWidth,
|
|
923
|
+
cPercent = controlInfo.cPercent;
|
|
924
|
+
var controlEnd = axisX.controlEnd,
|
|
925
|
+
start = axisX.start,
|
|
926
|
+
scaler = axisX.scaler,
|
|
927
|
+
_axisX$step = axisX.step,
|
|
928
|
+
step = _axisX$step === void 0 ? 0 : _axisX$step;
|
|
929
|
+
var slideRange = cWidth - cBarWidth;
|
|
930
|
+
var percent = slideRange > 0 ? cBarX / slideRange : 0;
|
|
931
|
+
var safeCPercent = cPercent > 0 && Number.isFinite(cPercent) ? cPercent : 1;
|
|
932
|
+
var span = controlEnd + start / safeCPercent - chartWidth;
|
|
933
|
+
var translateX = Number.isFinite(span) ? -span * percent : 0;
|
|
934
|
+
var clipLeft = Number.isFinite(-translateX) ? -translateX : 0;
|
|
935
|
+
var clipRight = clipLeft + chartWidth;
|
|
936
|
+
var halfStep = Number.isFinite(step) ? step / 2 : 0;
|
|
937
|
+
return originData.filter(function (d) {
|
|
938
|
+
if ((d === null || d === void 0 ? void 0 : d.x) === undefined) return false;
|
|
939
|
+
var pos = scaler(d.x);
|
|
940
|
+
if (!Number.isFinite(pos)) return false;
|
|
941
|
+
return pos + halfStep >= clipLeft && pos - halfStep <= clipRight;
|
|
942
|
+
});
|
|
913
943
|
};
|
package/package.json
CHANGED
|
@@ -13,6 +13,7 @@ import React, {
|
|
|
13
13
|
} from "react";
|
|
14
14
|
import { useAxes, useTooltip, useCarouselAxisX, useAiData } from "../hooks";
|
|
15
15
|
import { chartContext } from "../context";
|
|
16
|
+
import { getControlVisibleData } from "../utils";
|
|
16
17
|
import {
|
|
17
18
|
ChartContainer,
|
|
18
19
|
Legend,
|
|
@@ -313,6 +314,10 @@ const Chart = memo(
|
|
|
313
314
|
const controlTimer = useRef(); //控制条的动画计时器
|
|
314
315
|
const ctlBarX = useRef(0); //控制条的滑块偏移值
|
|
315
316
|
const isWorking = useRef(false); //控制条是否正在进行各种操作
|
|
317
|
+
const controlInfoRef = useRef(controlInfo);
|
|
318
|
+
const axisXRef = useRef(axisX);
|
|
319
|
+
controlInfoRef.current = controlInfo;
|
|
320
|
+
axisXRef.current = axisX;
|
|
316
321
|
|
|
317
322
|
const range = (num, ignoreMax) => {
|
|
318
323
|
let _num = num;
|
|
@@ -330,10 +335,12 @@ const Chart = memo(
|
|
|
330
335
|
const moveLen = range(x);
|
|
331
336
|
if (needSave) ctlBarX.current = moveLen;
|
|
332
337
|
setControlInfo((pre) => {
|
|
333
|
-
|
|
338
|
+
const next = {
|
|
334
339
|
...pre,
|
|
335
340
|
cBarX: moveLen,
|
|
336
341
|
};
|
|
342
|
+
controlInfoRef.current = next;
|
|
343
|
+
return next;
|
|
337
344
|
});
|
|
338
345
|
};
|
|
339
346
|
const setControlWidth = (fn, ignoreMax = false) => {
|
|
@@ -341,9 +348,34 @@ const Chart = memo(
|
|
|
341
348
|
const x = pre.cBarX;
|
|
342
349
|
const moveLen = range(x, ignoreMax);
|
|
343
350
|
ctlBarX.current = moveLen;
|
|
344
|
-
|
|
351
|
+
const next = fn(pre);
|
|
352
|
+
controlInfoRef.current = next;
|
|
353
|
+
return next;
|
|
345
354
|
});
|
|
346
355
|
};
|
|
356
|
+
const emitControlRangeChange = useCallback(() => {
|
|
357
|
+
if (!control) return;
|
|
358
|
+
const visibleData = getControlVisibleData(
|
|
359
|
+
originData,
|
|
360
|
+
axisXRef.current,
|
|
361
|
+
controlInfoRef.current,
|
|
362
|
+
chartWidth,
|
|
363
|
+
);
|
|
364
|
+
const eventData = { data: visibleData };
|
|
365
|
+
triggerOnRelative("dataChange", eventData);
|
|
366
|
+
onEmit("dataChange", eventData);
|
|
367
|
+
}, [control, originData, chartWidth, triggerOnRelative, onEmit]);
|
|
368
|
+
useEffect(() => {
|
|
369
|
+
if (!control) return;
|
|
370
|
+
emitControlRangeChange();
|
|
371
|
+
}, [
|
|
372
|
+
control,
|
|
373
|
+
chartWidth,
|
|
374
|
+
height,
|
|
375
|
+
JSON.stringify(originData),
|
|
376
|
+
JSON.stringify(control),
|
|
377
|
+
emitControlRangeChange,
|
|
378
|
+
]);
|
|
347
379
|
//设置控制条是否正在进行拖拽/缩放操作
|
|
348
380
|
const setWorking = (bool) => {
|
|
349
381
|
isWorking.current = bool;
|
|
@@ -805,6 +837,7 @@ const Chart = memo(
|
|
|
805
837
|
setX: setControlTranslate,
|
|
806
838
|
setWorking,
|
|
807
839
|
setControlWidth,
|
|
840
|
+
onControlChange: emitControlRangeChange,
|
|
808
841
|
}}
|
|
809
842
|
props={{
|
|
810
843
|
control,
|
|
@@ -6,7 +6,7 @@ import { mathR } from "../utils";
|
|
|
6
6
|
export default memo(
|
|
7
7
|
forwardRef((props, ref) => {
|
|
8
8
|
const {
|
|
9
|
-
actions: { setX, setWorking, setControlWidth },
|
|
9
|
+
actions: { setX, setWorking, setControlWidth, onControlChange },
|
|
10
10
|
props: {
|
|
11
11
|
control: {
|
|
12
12
|
thumbnail,
|
|
@@ -82,6 +82,7 @@ export default memo(
|
|
|
82
82
|
const up = () => {
|
|
83
83
|
document.removeEventListener("mousemove", move);
|
|
84
84
|
document.removeEventListener("mouseup", up);
|
|
85
|
+
onControlChange?.();
|
|
85
86
|
};
|
|
86
87
|
document.addEventListener("mousemove", move);
|
|
87
88
|
document.addEventListener("mouseup", up);
|
|
@@ -122,6 +123,7 @@ export default memo(
|
|
|
122
123
|
const up = (e) => {
|
|
123
124
|
document.removeEventListener("touchmove", move);
|
|
124
125
|
document.removeEventListener("touchend", up);
|
|
126
|
+
onControlChange?.();
|
|
125
127
|
};
|
|
126
128
|
document.addEventListener("touchmove", move, { passive: false });
|
|
127
129
|
document.addEventListener("touchend", up);
|
|
@@ -142,6 +144,7 @@ export default memo(
|
|
|
142
144
|
setWorking(false);
|
|
143
145
|
document.removeEventListener("mousemove", mouseMoveHandle);
|
|
144
146
|
document.removeEventListener("mouseup", mouseUpHandle);
|
|
147
|
+
onControlChange?.();
|
|
145
148
|
};
|
|
146
149
|
document.addEventListener("mousemove", mouseMoveHandle);
|
|
147
150
|
document.addEventListener("mouseup", mouseUpHandle);
|
|
@@ -167,6 +170,7 @@ export default memo(
|
|
|
167
170
|
setWorking(false);
|
|
168
171
|
document.removeEventListener("touchmove", mouseMoveHandle);
|
|
169
172
|
document.removeEventListener("touchend", mouseUpHandle);
|
|
173
|
+
onControlChange?.();
|
|
170
174
|
};
|
|
171
175
|
document.addEventListener("touchmove", mouseMoveHandle, {
|
|
172
176
|
passive: false,
|
|
@@ -199,6 +203,7 @@ export default memo(
|
|
|
199
203
|
const up = () => {
|
|
200
204
|
document.removeEventListener("mousemove", move);
|
|
201
205
|
document.removeEventListener("mouseup", up);
|
|
206
|
+
onControlChange?.();
|
|
202
207
|
};
|
|
203
208
|
document.addEventListener("mousemove", move);
|
|
204
209
|
document.addEventListener("mouseup", up);
|
|
@@ -233,6 +238,7 @@ export default memo(
|
|
|
233
238
|
const up = (e) => {
|
|
234
239
|
document.removeEventListener("touchmove", move);
|
|
235
240
|
document.removeEventListener("touchend", up);
|
|
241
|
+
onControlChange?.();
|
|
236
242
|
};
|
|
237
243
|
document.addEventListener("touchmove", move, { passive: false });
|
|
238
244
|
document.addEventListener("touchend", up);
|