@easyv/charts 1.4.40 → 1.5.1
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 +48 -15
- package/lib/components/Control.js +53 -4
- package/lib/components/Line.js +5 -1
- package/lib/utils/index.js +13 -2
- package/package.json +1 -1
- package/src/components/CartesianChart.js +38 -15
- package/src/components/Control.jsx +41 -9
- package/src/components/Line.js +3 -2
- package/src/utils/index.js +7 -0
|
@@ -15,6 +15,8 @@ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")
|
|
|
15
15
|
|
|
16
16
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
17
17
|
|
|
18
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
19
|
+
|
|
18
20
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
19
21
|
|
|
20
22
|
var _react = _interopRequireWildcard(require("react"));
|
|
@@ -32,6 +34,10 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
32
34
|
|
|
33
35
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
34
36
|
|
|
37
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
38
|
+
|
|
39
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
40
|
+
|
|
35
41
|
var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
|
|
36
42
|
var _ref$config = _ref.config,
|
|
37
43
|
axesConfig = _ref$config.axes,
|
|
@@ -114,7 +120,8 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
|
|
|
114
120
|
cWidth: controlWidth,
|
|
115
121
|
cHeight: controlHeight,
|
|
116
122
|
cBarWidth: controlBarWidth,
|
|
117
|
-
cPercent: dragPercent
|
|
123
|
+
cPercent: dragPercent,
|
|
124
|
+
cBarX: 0
|
|
118
125
|
}),
|
|
119
126
|
_useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
|
|
120
127
|
controlInfo = _useState4[0],
|
|
@@ -123,7 +130,8 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
|
|
|
123
130
|
var cWidth = controlInfo.cWidth,
|
|
124
131
|
cHeight = controlInfo.cHeight,
|
|
125
132
|
cBarWidth = controlInfo.cBarWidth,
|
|
126
|
-
cPercent = controlInfo.cPercent
|
|
133
|
+
cPercent = controlInfo.cPercent,
|
|
134
|
+
cBarX = controlInfo.cBarX;
|
|
127
135
|
yLineRange -= cHeight;
|
|
128
136
|
(0, _react.useEffect)(function () {
|
|
129
137
|
setControlInfo({
|
|
@@ -131,7 +139,8 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
|
|
|
131
139
|
cWidth: controlWidth,
|
|
132
140
|
cHeight: controlHeight,
|
|
133
141
|
cBarWidth: controlBarWidth,
|
|
134
|
-
cPercent: dragPercent
|
|
142
|
+
cPercent: dragPercent,
|
|
143
|
+
cBarX: 0
|
|
135
144
|
});
|
|
136
145
|
}, [JSON.stringify(control)]);
|
|
137
146
|
var svg = (0, _react.useRef)();
|
|
@@ -216,34 +225,58 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
|
|
|
216
225
|
|
|
217
226
|
var isWorking = (0, _react.useRef)(false); //控制条是否正在进行各种操作
|
|
218
227
|
|
|
219
|
-
var range = function range(num) {
|
|
228
|
+
var range = function range(num, ignoreMax) {
|
|
220
229
|
var _num = num;
|
|
221
230
|
var min = 0;
|
|
222
231
|
var max = cWidth - cBarWidth;
|
|
223
232
|
_num = Math.max(_num, min);
|
|
233
|
+
|
|
234
|
+
if (ignoreMax) {
|
|
235
|
+
return _num;
|
|
236
|
+
}
|
|
237
|
+
|
|
224
238
|
_num = Math.min(_num, max);
|
|
225
239
|
return _num;
|
|
226
240
|
}; //设置滑块和图表主体的偏移值
|
|
227
241
|
|
|
228
242
|
|
|
229
243
|
var setControlTranslate = function setControlTranslate(x, needSave) {
|
|
230
|
-
var controlEnd = axisX.controlEnd,
|
|
231
|
-
start = axisX.start;
|
|
232
244
|
var moveLen = range(x);
|
|
233
245
|
if (needSave) ctlBarX.current = moveLen;
|
|
234
|
-
|
|
246
|
+
setControlInfo(function (pre) {
|
|
247
|
+
return _objectSpread(_objectSpread({}, pre), {}, {
|
|
248
|
+
cBarX: moveLen
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
};
|
|
235
252
|
|
|
236
|
-
|
|
237
|
-
var
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
253
|
+
var setControlWidth = function setControlWidth(fn) {
|
|
254
|
+
var ignoreMax = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
255
|
+
setControlInfo(function (pre) {
|
|
256
|
+
var x = pre.cBarX;
|
|
257
|
+
var moveLen = range(x, ignoreMax);
|
|
258
|
+
ctlBarX.current = moveLen;
|
|
259
|
+
return fn(pre);
|
|
260
|
+
});
|
|
241
261
|
}; //设置控制条是否正在进行拖拽/缩放操作
|
|
242
262
|
|
|
243
263
|
|
|
244
264
|
var setWorking = function setWorking(bool) {
|
|
245
265
|
isWorking.current = bool;
|
|
246
|
-
};
|
|
266
|
+
}; //cBarX变化后,修改图表的偏移值
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
(0, _react.useLayoutEffect)(function () {
|
|
270
|
+
var controlEnd = axisX.controlEnd,
|
|
271
|
+
start = axisX.start;
|
|
272
|
+
controlEl.current.style.transform = "translate(".concat(cBarX, "px,0)"); //计算出当前位移的百分比
|
|
273
|
+
|
|
274
|
+
var percent = cBarX / (cWidth - cBarWidth);
|
|
275
|
+
var translateX = -(controlEnd + start / cPercent - chartWidth) * percent;
|
|
276
|
+
curControlPercent.current = percent;
|
|
277
|
+
seriesEl.current.style.transform = "translate(".concat(translateX, "px,").concat(marginTop, "px)");
|
|
278
|
+
axisElList.current[2].style.transform = "translate(".concat(translateX, "px,", 0, "px)");
|
|
279
|
+
}, [controlInfo]); //控制条轮播动画
|
|
247
280
|
|
|
248
281
|
(0, _react.useEffect)(function () {
|
|
249
282
|
if (controlEl.current && control) {
|
|
@@ -343,7 +376,7 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
|
|
|
343
376
|
cancelAnimationFrame(controlTimer.current);
|
|
344
377
|
};
|
|
345
378
|
}
|
|
346
|
-
}, [JSON.stringify(animation), control,
|
|
379
|
+
}, [JSON.stringify(animation), control, cWidth, cHeight, cBarWidth, cPercent]); //初始化控制图提示框状态的函数
|
|
347
380
|
|
|
348
381
|
var initCtlTip = function initCtlTip() {
|
|
349
382
|
return {
|
|
@@ -492,7 +525,7 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
|
|
|
492
525
|
actions: {
|
|
493
526
|
setX: setControlTranslate,
|
|
494
527
|
setWorking: setWorking,
|
|
495
|
-
|
|
528
|
+
setControlWidth: setControlWidth
|
|
496
529
|
},
|
|
497
530
|
props: {
|
|
498
531
|
control: control,
|
|
@@ -19,6 +19,8 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
19
19
|
|
|
20
20
|
var _d3Scale = require("d3-scale");
|
|
21
21
|
|
|
22
|
+
var _utils = require("../utils");
|
|
23
|
+
|
|
22
24
|
var _excluded = ["Component", "yOrZ"];
|
|
23
25
|
|
|
24
26
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
@@ -33,7 +35,7 @@ var _default = /*#__PURE__*/(0, _react.memo)( /*#__PURE__*/(0, _react.forwardRef
|
|
|
33
35
|
var _props$actions = props.actions,
|
|
34
36
|
setX = _props$actions.setX,
|
|
35
37
|
setWorking = _props$actions.setWorking,
|
|
36
|
-
|
|
38
|
+
setControlWidth = _props$actions.setControlWidth,
|
|
37
39
|
_props$props = props.props,
|
|
38
40
|
_props$props$control = _props$props.control,
|
|
39
41
|
height = _props$props$control.height,
|
|
@@ -71,8 +73,39 @@ var _default = /*#__PURE__*/(0, _react.memo)( /*#__PURE__*/(0, _react.forwardRef
|
|
|
71
73
|
cursor: "col-resize",
|
|
72
74
|
background: "rgb(2, 176, 249)",
|
|
73
75
|
WebkitBackgroundClip: "content-box"
|
|
76
|
+
}; //左手柄的鼠标按下逻辑
|
|
77
|
+
|
|
78
|
+
var leftDown = function leftDown() {
|
|
79
|
+
var transform = ref.current.style.transform;
|
|
80
|
+
var initX = 0;
|
|
81
|
+
var rawTranslateX = parseFloat(transform ? transform.match(/\d+\.*\d*/)[0] : 0);
|
|
82
|
+
var rightX = rawTranslateX + cBarWidth;
|
|
83
|
+
|
|
84
|
+
var move = function move(e) {
|
|
85
|
+
var movementX = e.movementX;
|
|
86
|
+
initX = (0, _utils.mathR)(initX + movementX, [-rawTranslateX, rightX - rawTranslateX]);
|
|
87
|
+
setControlWidth(function (pre) {
|
|
88
|
+
var cWidth = pre.cWidth,
|
|
89
|
+
cBarWidth = pre.cBarWidth;
|
|
90
|
+
var nextBarWidth = (0, _utils.mathR)(cBarWidth - movementX, [1, rightX]);
|
|
91
|
+
return _objectSpread(_objectSpread({}, pre), {}, {
|
|
92
|
+
cBarWidth: nextBarWidth,
|
|
93
|
+
cPercent: nextBarWidth / cWidth,
|
|
94
|
+
cBarX: initX + rawTranslateX
|
|
95
|
+
});
|
|
96
|
+
}, true);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
var up = function up() {
|
|
100
|
+
document.removeEventListener("mousemove", move);
|
|
101
|
+
document.removeEventListener("mouseup", up);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
document.addEventListener("mousemove", move);
|
|
105
|
+
document.addEventListener("mouseup", up);
|
|
74
106
|
}; //滑块的鼠标按下操作
|
|
75
107
|
|
|
108
|
+
|
|
76
109
|
var down = function down() {
|
|
77
110
|
var transform = ref.current.style.transform;
|
|
78
111
|
var movementX = 0;
|
|
@@ -97,13 +130,19 @@ var _default = /*#__PURE__*/(0, _react.memo)( /*#__PURE__*/(0, _react.forwardRef
|
|
|
97
130
|
|
|
98
131
|
|
|
99
132
|
var rightDown = function rightDown() {
|
|
133
|
+
var transform = ref.current.style.transform;
|
|
134
|
+
var rawTranslateX = parseFloat(transform ? transform.match(/\d+\.*\d*/)[0] : 0);
|
|
135
|
+
|
|
100
136
|
var move = function move(e) {
|
|
101
137
|
var movementX = e.movementX;
|
|
102
|
-
|
|
103
|
-
var
|
|
138
|
+
setControlWidth(function (pre) {
|
|
139
|
+
var cWidth = pre.cWidth,
|
|
140
|
+
cBarWidth = pre.cBarWidth;
|
|
141
|
+
var maxWidth = cWidth - rawTranslateX;
|
|
142
|
+
var nextBarWidth = (0, _utils.mathR)(cBarWidth + movementX, [1, maxWidth]);
|
|
104
143
|
return _objectSpread(_objectSpread({}, pre), {}, {
|
|
105
144
|
cBarWidth: nextBarWidth,
|
|
106
|
-
cPercent: nextBarWidth /
|
|
145
|
+
cPercent: nextBarWidth / cWidth
|
|
107
146
|
});
|
|
108
147
|
});
|
|
109
148
|
};
|
|
@@ -146,9 +185,19 @@ var _default = /*#__PURE__*/(0, _react.memo)( /*#__PURE__*/(0, _react.forwardRef
|
|
|
146
185
|
ref: ref,
|
|
147
186
|
style: barStyle
|
|
148
187
|
}, /*#__PURE__*/_react["default"].createElement("div", {
|
|
188
|
+
style: _objectSpread(_objectSpread({}, controllerStyle), {}, {
|
|
189
|
+
transform: "translateX(-6px)"
|
|
190
|
+
}),
|
|
191
|
+
onMouseDown: leftDown
|
|
192
|
+
}), /*#__PURE__*/_react["default"].createElement("div", {
|
|
149
193
|
style: dragStyle,
|
|
150
194
|
onMouseDown: down,
|
|
151
195
|
ref: barRef
|
|
196
|
+
}), /*#__PURE__*/_react["default"].createElement("div", {
|
|
197
|
+
style: _objectSpread(_objectSpread({}, controllerStyle), {}, {
|
|
198
|
+
transform: "translateX(6px)"
|
|
199
|
+
}),
|
|
200
|
+
onMouseDown: rightDown
|
|
152
201
|
})));
|
|
153
202
|
}));
|
|
154
203
|
|
package/lib/components/Line.js
CHANGED
|
@@ -93,6 +93,9 @@ var Area = function Area(_ref2) {
|
|
|
93
93
|
}, [xScaler, yScaler, curve, tension]);
|
|
94
94
|
return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("path", {
|
|
95
95
|
d: areaGen(data),
|
|
96
|
+
style: {
|
|
97
|
+
pointerEvents: "none"
|
|
98
|
+
},
|
|
96
99
|
stroke: "none",
|
|
97
100
|
fill: 'url(#' + id + ')'
|
|
98
101
|
}), /*#__PURE__*/_react["default"].createElement("defs", null, type && type == 'pattern' ? /*#__PURE__*/_react["default"].createElement("pattern", {
|
|
@@ -178,7 +181,8 @@ var _default = /*#__PURE__*/(0, _react.memo)(function (_ref6) {
|
|
|
178
181
|
d: path,
|
|
179
182
|
stroke: stroke,
|
|
180
183
|
style: {
|
|
181
|
-
filter: show ? "drop-shadow(".concat(shadow.hShadow, "px ").concat(shadow.vShadow, "px ").concat(shadow.blur, "px ").concat(shadow.color, ")") : "none"
|
|
184
|
+
filter: show ? "drop-shadow(".concat(shadow.hShadow, "px ").concat(shadow.vShadow, "px ").concat(shadow.blur, "px ").concat(shadow.color, ")") : "none",
|
|
185
|
+
pointerEvents: "none"
|
|
182
186
|
},
|
|
183
187
|
fill: "none",
|
|
184
188
|
strokeDasharray: lineType === 'dash' ? '3 3' : null,
|
package/lib/utils/index.js
CHANGED
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.band = band;
|
|
9
|
-
exports.sortPie = exports.seriesYOrZ = exports.resetStacks = exports.reduceConfig = exports.isValidHttpUrl = exports.identity = exports.getTranslate3d = exports.getTranslate2d = exports.getTicksOfAxis = exports.getTickCoord = exports.getStacks = exports.getSeriesInfo = 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.filterChildren = exports.dateFormat = exports.dataYOrZ = void 0;
|
|
9
|
+
exports.sortPie = exports.seriesYOrZ = exports.resetStacks = exports.reduceConfig = exports.mathR = exports.isValidHttpUrl = exports.identity = exports.getTranslate3d = exports.getTranslate2d = exports.getTicksOfAxis = exports.getTickCoord = exports.getStacks = exports.getSeriesInfo = 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.filterChildren = exports.dateFormat = exports.dataYOrZ = void 0;
|
|
10
10
|
|
|
11
11
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
12
12
|
|
|
@@ -900,6 +900,17 @@ var reduceConfig = function reduceConfig() {
|
|
|
900
900
|
}
|
|
901
901
|
|
|
902
902
|
return output;
|
|
903
|
+
}; //限制value的值在min和max之间
|
|
904
|
+
|
|
905
|
+
|
|
906
|
+
exports.reduceConfig = reduceConfig;
|
|
907
|
+
|
|
908
|
+
var mathR = function mathR(value, range) {
|
|
909
|
+
var _range = (0, _slicedToArray2["default"])(range, 2),
|
|
910
|
+
min = _range[0],
|
|
911
|
+
max = _range[1];
|
|
912
|
+
|
|
913
|
+
return Math.max(min, Math.min(value, max));
|
|
903
914
|
};
|
|
904
915
|
|
|
905
|
-
exports.
|
|
916
|
+
exports.mathR = mathR;
|
package/package.json
CHANGED
|
@@ -8,7 +8,8 @@ import React, {
|
|
|
8
8
|
useRef,
|
|
9
9
|
useContext,
|
|
10
10
|
useCallback,
|
|
11
|
-
useEffect
|
|
11
|
+
useEffect,
|
|
12
|
+
useLayoutEffect
|
|
12
13
|
} from "react";
|
|
13
14
|
import { useAxes, useTooltip, useCarouselAxisX, useAiData } from "../hooks";
|
|
14
15
|
import { chartContext } from "../context";
|
|
@@ -89,8 +90,8 @@ const Chart = memo(
|
|
|
89
90
|
dragPercent = dragWidth/100;
|
|
90
91
|
controlBarWidth = controlWidth*dragPercent;
|
|
91
92
|
}
|
|
92
|
-
const [controlInfo, setControlInfo] = useState({ isC:isControl, cWidth:controlWidth, cHeight:controlHeight, cBarWidth:controlBarWidth, cPercent:dragPercent });
|
|
93
|
-
const { cWidth, cHeight, cBarWidth, cPercent } = controlInfo;
|
|
93
|
+
const [controlInfo, setControlInfo] = useState({ isC:isControl, cWidth:controlWidth, cHeight:controlHeight, cBarWidth:controlBarWidth, cPercent:dragPercent, cBarX:0 });
|
|
94
|
+
const { cWidth, cHeight, cBarWidth, cPercent, cBarX } = controlInfo;
|
|
94
95
|
yLineRange -= cHeight;
|
|
95
96
|
useEffect(()=>{
|
|
96
97
|
setControlInfo({
|
|
@@ -98,7 +99,8 @@ const Chart = memo(
|
|
|
98
99
|
cWidth:controlWidth,
|
|
99
100
|
cHeight:controlHeight,
|
|
100
101
|
cBarWidth:controlBarWidth,
|
|
101
|
-
cPercent:dragPercent
|
|
102
|
+
cPercent:dragPercent,
|
|
103
|
+
cBarX:0
|
|
102
104
|
});
|
|
103
105
|
},[JSON.stringify(control)]);
|
|
104
106
|
|
|
@@ -193,31 +195,52 @@ const Chart = memo(
|
|
|
193
195
|
const ctlBarX = useRef(0); //控制条的滑块偏移值
|
|
194
196
|
const isWorking = useRef(false); //控制条是否正在进行各种操作
|
|
195
197
|
|
|
196
|
-
const range = (num) => {
|
|
198
|
+
const range = (num, ignoreMax) => {
|
|
197
199
|
let _num = num;
|
|
198
200
|
const min = 0;
|
|
199
201
|
const max = cWidth - cBarWidth;
|
|
200
202
|
_num = Math.max(_num, min);
|
|
203
|
+
if(ignoreMax){
|
|
204
|
+
return _num;
|
|
205
|
+
}
|
|
201
206
|
_num = Math.min(_num, max);
|
|
202
207
|
return _num;
|
|
203
208
|
};
|
|
204
209
|
//设置滑块和图表主体的偏移值
|
|
205
210
|
const setControlTranslate = (x, needSave) => {
|
|
206
|
-
const { controlEnd, start } = axisX;
|
|
207
211
|
const moveLen = range(x);
|
|
208
212
|
if(needSave) ctlBarX.current = moveLen;
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
axisElList.current[2].style.transform = `translate(${translateX}px,${0}px)`;
|
|
213
|
+
setControlInfo(pre=>{
|
|
214
|
+
return {
|
|
215
|
+
...pre,
|
|
216
|
+
cBarX:moveLen
|
|
217
|
+
}
|
|
218
|
+
});
|
|
216
219
|
};
|
|
220
|
+
const setControlWidth = (fn,ignoreMax=false)=>{
|
|
221
|
+
setControlInfo(pre=>{
|
|
222
|
+
const x = pre.cBarX;
|
|
223
|
+
const moveLen = range(x, ignoreMax);
|
|
224
|
+
ctlBarX.current = moveLen;
|
|
225
|
+
return fn(pre);
|
|
226
|
+
});
|
|
227
|
+
}
|
|
217
228
|
//设置控制条是否正在进行拖拽/缩放操作
|
|
218
229
|
const setWorking=(bool)=>{
|
|
219
230
|
isWorking.current = bool;
|
|
220
231
|
}
|
|
232
|
+
//cBarX变化后,修改图表的偏移值
|
|
233
|
+
useLayoutEffect(()=>{
|
|
234
|
+
const { controlEnd, start } = axisX;
|
|
235
|
+
controlEl.current.style.transform = `translate(${cBarX}px,0)`;
|
|
236
|
+
//计算出当前位移的百分比
|
|
237
|
+
const percent = cBarX / (cWidth - cBarWidth);
|
|
238
|
+
const translateX = -(controlEnd + start/cPercent - chartWidth) * percent;
|
|
239
|
+
curControlPercent.current = percent;
|
|
240
|
+
seriesEl.current.style.transform = `translate(${translateX}px,${marginTop}px)`;
|
|
241
|
+
axisElList.current[2].style.transform = `translate(${translateX}px,${0}px)`;
|
|
242
|
+
},[controlInfo]);
|
|
243
|
+
//控制条轮播动画
|
|
221
244
|
useEffect(() => {
|
|
222
245
|
if (controlEl.current && control) {
|
|
223
246
|
let isEnter = false; //控制条轮播动画是否处于暂停状态
|
|
@@ -294,7 +317,7 @@ const Chart = memo(
|
|
|
294
317
|
cancelAnimationFrame(controlTimer.current);
|
|
295
318
|
};
|
|
296
319
|
}
|
|
297
|
-
}, [JSON.stringify(animation), control,
|
|
320
|
+
}, [JSON.stringify(animation), control, cWidth, cHeight, cBarWidth, cPercent]);
|
|
298
321
|
//初始化控制图提示框状态的函数
|
|
299
322
|
const initCtlTip = ()=>{
|
|
300
323
|
return {
|
|
@@ -487,7 +510,7 @@ const Chart = memo(
|
|
|
487
510
|
actions={{
|
|
488
511
|
setX:setControlTranslate,
|
|
489
512
|
setWorking,
|
|
490
|
-
|
|
513
|
+
setControlWidth
|
|
491
514
|
}}
|
|
492
515
|
props={{
|
|
493
516
|
control,
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import React, { forwardRef, memo, useRef } from "react";
|
|
2
2
|
import { scaleLinear } from "d3-scale";
|
|
3
|
+
import { mathR } from "../utils";
|
|
3
4
|
|
|
4
5
|
export default memo(forwardRef((props, ref) => {
|
|
5
6
|
const {
|
|
6
|
-
actions:{ setX, setWorking,
|
|
7
|
+
actions:{ setX, setWorking, setControlWidth },
|
|
7
8
|
props: {
|
|
8
9
|
control:{ height, color, gap, drag:{ color:dragColor }, margin:{ left } },
|
|
9
|
-
controlInfo:{
|
|
10
|
+
controlInfo:{ cWidth, cBarWidth },
|
|
10
11
|
axes, series, top, bandLength
|
|
11
12
|
}
|
|
12
13
|
} = props;
|
|
@@ -35,6 +36,34 @@ export default memo(forwardRef((props, ref) => {
|
|
|
35
36
|
background:"rgb(2, 176, 249)",
|
|
36
37
|
WebkitBackgroundClip:"content-box",
|
|
37
38
|
}
|
|
39
|
+
|
|
40
|
+
//左手柄的鼠标按下逻辑
|
|
41
|
+
const leftDown=()=>{
|
|
42
|
+
const transform = ref.current.style.transform;
|
|
43
|
+
let initX = 0;
|
|
44
|
+
let rawTranslateX = parseFloat(transform?transform.match(/\d+\.*\d*/)[0]:0);
|
|
45
|
+
const rightX = rawTranslateX+cBarWidth;
|
|
46
|
+
const move=(e)=>{
|
|
47
|
+
const { movementX } = e;
|
|
48
|
+
initX = mathR(initX+movementX,[-rawTranslateX, rightX-rawTranslateX]);
|
|
49
|
+
setControlWidth((pre)=>{
|
|
50
|
+
const { cWidth, cBarWidth } = pre;
|
|
51
|
+
const nextBarWidth = mathR(cBarWidth-movementX,[1,rightX]);
|
|
52
|
+
return {
|
|
53
|
+
...pre,
|
|
54
|
+
cBarWidth:nextBarWidth,
|
|
55
|
+
cPercent:nextBarWidth/cWidth,
|
|
56
|
+
cBarX:initX+rawTranslateX
|
|
57
|
+
}
|
|
58
|
+
}, true);
|
|
59
|
+
}
|
|
60
|
+
const up=()=>{
|
|
61
|
+
document.removeEventListener("mousemove",move);
|
|
62
|
+
document.removeEventListener("mouseup",up);
|
|
63
|
+
}
|
|
64
|
+
document.addEventListener("mousemove",move);
|
|
65
|
+
document.addEventListener("mouseup",up);
|
|
66
|
+
}
|
|
38
67
|
//滑块的鼠标按下操作
|
|
39
68
|
const down=()=>{
|
|
40
69
|
const transform = ref.current.style.transform;
|
|
@@ -56,17 +85,20 @@ export default memo(forwardRef((props, ref) => {
|
|
|
56
85
|
}
|
|
57
86
|
// //右手柄的鼠标按下逻辑
|
|
58
87
|
const rightDown=()=>{
|
|
59
|
-
|
|
88
|
+
const transform = ref.current.style.transform;
|
|
89
|
+
let rawTranslateX = parseFloat(transform?transform.match(/\d+\.*\d*/)[0]:0);
|
|
60
90
|
const move=(e)=>{
|
|
61
91
|
const { movementX } = e;
|
|
62
|
-
|
|
63
|
-
const
|
|
92
|
+
setControlWidth((pre)=>{
|
|
93
|
+
const { cWidth, cBarWidth } = pre;
|
|
94
|
+
const maxWidth = cWidth-rawTranslateX;
|
|
95
|
+
const nextBarWidth = mathR(cBarWidth+movementX,[1,maxWidth]);
|
|
64
96
|
return {
|
|
65
97
|
...pre,
|
|
66
98
|
cBarWidth:nextBarWidth,
|
|
67
|
-
cPercent:nextBarWidth/
|
|
99
|
+
cPercent:nextBarWidth/cWidth
|
|
68
100
|
}
|
|
69
|
-
})
|
|
101
|
+
});
|
|
70
102
|
}
|
|
71
103
|
const up=()=>{
|
|
72
104
|
document.removeEventListener("mousemove",move);
|
|
@@ -108,9 +140,9 @@ export default memo(forwardRef((props, ref) => {
|
|
|
108
140
|
</svg>
|
|
109
141
|
{/* 控制条 */}
|
|
110
142
|
<div ref={ref} style={barStyle}>
|
|
111
|
-
|
|
143
|
+
<div style={{...controllerStyle,transform:"translateX(-6px)"}} onMouseDown={leftDown}></div>
|
|
112
144
|
<div style={dragStyle} onMouseDown={down} ref={barRef}></div>
|
|
113
|
-
|
|
145
|
+
<div style={{...controllerStyle,transform:`translateX(6px)`}} onMouseDown={rightDown}></div>
|
|
114
146
|
</div>
|
|
115
147
|
</div>
|
|
116
148
|
);
|
package/src/components/Line.js
CHANGED
|
@@ -48,7 +48,7 @@ const Area = ({
|
|
|
48
48
|
|
|
49
49
|
return (
|
|
50
50
|
<>
|
|
51
|
-
<path d={areaGen(data)} stroke='none' fill={'url(#' + id + ')'} />
|
|
51
|
+
<path d={areaGen(data)} style={{pointerEvents:"none"}} stroke='none' fill={'url(#' + id + ')'} />
|
|
52
52
|
<defs>
|
|
53
53
|
{type && type == 'pattern' ? (
|
|
54
54
|
<pattern id={id} patternUnits="userSpaceOnUse" width={patternW} height={patternH}>
|
|
@@ -129,7 +129,8 @@ export default memo(
|
|
|
129
129
|
d={path}
|
|
130
130
|
stroke={stroke}
|
|
131
131
|
style={{
|
|
132
|
-
filter:show?`drop-shadow(${shadow.hShadow}px ${shadow.vShadow}px ${shadow.blur}px ${shadow.color})`:"none"
|
|
132
|
+
filter:show?`drop-shadow(${shadow.hShadow}px ${shadow.vShadow}px ${shadow.blur}px ${shadow.color})`:"none",
|
|
133
|
+
pointerEvents:"none"
|
|
133
134
|
}}
|
|
134
135
|
fill='none'
|
|
135
136
|
strokeDasharray={lineType === 'dash' ? '3 3' : null}
|
package/src/utils/index.js
CHANGED
|
@@ -723,6 +723,12 @@ const reduceConfig = (config = []) => {
|
|
|
723
723
|
return output;
|
|
724
724
|
};
|
|
725
725
|
|
|
726
|
+
//限制value的值在min和max之间
|
|
727
|
+
const mathR=(value, range)=>{
|
|
728
|
+
const [min,max] = range;
|
|
729
|
+
return Math.max(min,Math.min(value,max));
|
|
730
|
+
}
|
|
731
|
+
|
|
726
732
|
export {
|
|
727
733
|
dateFormat,
|
|
728
734
|
getBreakWord,
|
|
@@ -754,4 +760,5 @@ export {
|
|
|
754
760
|
getDataWithPercent,
|
|
755
761
|
reduceConfig,
|
|
756
762
|
getSeriesInfo,
|
|
763
|
+
mathR
|
|
757
764
|
};
|