@easyv/charts 1.10.29 → 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/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/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
|
|
@@ -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);
|