@easyv/charts 1.4.38 → 1.4.40
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/Axis.js +31 -15
- package/lib/components/Band.js +32 -29
- package/lib/components/CartesianChart.js +6 -4
- package/lib/components/Chart.js +24 -2
- package/lib/components/Control.js +38 -12
- package/lib/hooks/useAxes.js +1 -1
- package/lib/hooks/useCarouselAxisX.js +3 -3
- package/lib/hooks/useTooltip.js +5 -3
- package/package.json +1 -1
- package/src/components/Axis.tsx +28 -17
- package/src/components/Band.tsx +24 -21
- package/src/components/CartesianChart.js +6 -3
- package/src/components/Chart.js +18 -2
- package/src/components/Control.jsx +29 -6
- package/src/hooks/useAxes.js +1 -1
- package/src/hooks/useCarouselAxisX.js +4 -3
- package/src/hooks/useTooltip.ts +5 -2
package/lib/components/Axis.js
CHANGED
|
@@ -54,18 +54,18 @@ var defaultFormatter = function defaultFormatter(d, _ref) {
|
|
|
54
54
|
return d + suffix;
|
|
55
55
|
};
|
|
56
56
|
|
|
57
|
-
var getAxesPath = function getAxesPath(orientation, _ref2) {
|
|
57
|
+
var getAxesPath = function getAxesPath(orientation, _ref2, cHeight, cPercent) {
|
|
58
58
|
var width = _ref2.width,
|
|
59
59
|
height = _ref2.height;
|
|
60
60
|
|
|
61
61
|
switch (orientation) {
|
|
62
62
|
case "top":
|
|
63
63
|
case "bottom":
|
|
64
|
-
return "M-0.5, 0H" + width;
|
|
64
|
+
return "M-0.5, 0H" + width / cPercent;
|
|
65
65
|
|
|
66
66
|
case "left":
|
|
67
67
|
case "right":
|
|
68
|
-
return "M0, -0.5V" + (height + 0.5);
|
|
68
|
+
return "M0, -0.5V" + (height + 0.5 - cHeight);
|
|
69
69
|
}
|
|
70
70
|
};
|
|
71
71
|
/**
|
|
@@ -119,14 +119,15 @@ var AxisLine = function AxisLine(_ref3) {
|
|
|
119
119
|
show = _ref3$config.show,
|
|
120
120
|
color = _ref3$config.color,
|
|
121
121
|
lineWidth = _ref3$config.lineWidth,
|
|
122
|
+
cHeight = _ref3$config.cHeight,
|
|
122
123
|
_ref3$isClipAxis = _ref3.isClipAxis,
|
|
123
124
|
isClipAxis = _ref3$isClipAxis === void 0 ? false : _ref3$isClipAxis,
|
|
124
125
|
_ref3$clipAxisRange = _ref3.clipAxisRange,
|
|
125
|
-
clipAxisRange = _ref3$clipAxisRange === void 0 ? [] : _ref3$clipAxisRange
|
|
126
|
+
clipAxisRange = _ref3$clipAxisRange === void 0 ? [] : _ref3$clipAxisRange,
|
|
127
|
+
_ref3$cPercent = _ref3.cPercent,
|
|
128
|
+
cPercent = _ref3$cPercent === void 0 ? 1 : _ref3$cPercent;
|
|
126
129
|
if (!show) return null;
|
|
127
130
|
var context = (0, _react.useContext)(_context.chartContext);
|
|
128
|
-
var width = context.width,
|
|
129
|
-
height = context.height;
|
|
130
131
|
|
|
131
132
|
if (isClipAxis) {
|
|
132
133
|
return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, clipAxisRange.map(function (range, index) {
|
|
@@ -139,7 +140,7 @@ var AxisLine = function AxisLine(_ref3) {
|
|
|
139
140
|
}));
|
|
140
141
|
} else {
|
|
141
142
|
return /*#__PURE__*/_react["default"].createElement("path", {
|
|
142
|
-
d: getAxesPath(orientation, context),
|
|
143
|
+
d: getAxesPath(orientation, context, cHeight, cPercent),
|
|
143
144
|
stroke: color,
|
|
144
145
|
strokeWidth: lineWidth
|
|
145
146
|
});
|
|
@@ -262,7 +263,6 @@ var _default = /*#__PURE__*/(0, _react.memo)( /*#__PURE__*/(0, _react.forwardRef
|
|
|
262
263
|
tickLine = _ref6$config.tickLine,
|
|
263
264
|
gridLine = _ref6$config.gridLine,
|
|
264
265
|
unit = _ref6$config.unit,
|
|
265
|
-
config = _ref6.config,
|
|
266
266
|
positions = _ref6.positions,
|
|
267
267
|
xLineRange = _ref6.xLineRange,
|
|
268
268
|
range = _ref6.range,
|
|
@@ -280,7 +280,8 @@ var _default = /*#__PURE__*/(0, _react.memo)( /*#__PURE__*/(0, _react.forwardRef
|
|
|
280
280
|
height = _useContext.height;
|
|
281
281
|
|
|
282
282
|
var cHeight = controlInfo.cHeight,
|
|
283
|
-
isC = controlInfo.isC
|
|
283
|
+
isC = controlInfo.isC,
|
|
284
|
+
cPercent = controlInfo.cPercent;
|
|
284
285
|
var x = orientation == "right" ? width : 0;
|
|
285
286
|
var y = orientation == "bottom" ? height - cHeight : 0;
|
|
286
287
|
|
|
@@ -299,7 +300,7 @@ var _default = /*#__PURE__*/(0, _react.memo)( /*#__PURE__*/(0, _react.forwardRef
|
|
|
299
300
|
});
|
|
300
301
|
var x1 = gridCoord.x1;
|
|
301
302
|
var y1 = gridCoord.y1;
|
|
302
|
-
return !(orientation == "bottom" && (x1 < 0 || x1 > xLineRange) || y1 < 0 || y1 > yLineRange) && /*#__PURE__*/_react["default"].createElement(_element.Line, (0, _extends2["default"])({
|
|
303
|
+
return !(orientation == "bottom" && !isC && (x1 < 0 || x1 > xLineRange) || y1 < 0 || y1 > yLineRange) && /*#__PURE__*/_react["default"].createElement(_element.Line, (0, _extends2["default"])({
|
|
303
304
|
className: "__easyv-tickLine",
|
|
304
305
|
key: index,
|
|
305
306
|
config: tickLine
|
|
@@ -315,6 +316,8 @@ var _default = /*#__PURE__*/(0, _react.memo)( /*#__PURE__*/(0, _react.forwardRef
|
|
|
315
316
|
return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, ticks.map(function (ticks, index) {
|
|
316
317
|
return draw(ticks, scaler[index]);
|
|
317
318
|
}));
|
|
319
|
+
} else if (isC && orientation == "bottom") {
|
|
320
|
+
return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, draw(rawTicks, scaler));
|
|
318
321
|
} else {
|
|
319
322
|
return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, draw(ticks, scaler));
|
|
320
323
|
}
|
|
@@ -365,7 +368,7 @@ var _default = /*#__PURE__*/(0, _react.memo)( /*#__PURE__*/(0, _react.forwardRef
|
|
|
365
368
|
}
|
|
366
369
|
}
|
|
367
370
|
|
|
368
|
-
return /*#__PURE__*/_react["default"].createElement("g", null, axisLine && tickLine && /*#__PURE__*/_react["default"].createElement("g", null, axisLine && (positions && positions.length ? positions.map(function (_ref7, index) {
|
|
371
|
+
return /*#__PURE__*/_react["default"].createElement("g", null, axisLine && tickLine && !isC && /*#__PURE__*/_react["default"].createElement("g", null, axisLine && (positions && positions.length ? positions.map(function (_ref7, index) {
|
|
369
372
|
var x = _ref7.x,
|
|
370
373
|
y = _ref7.y;
|
|
371
374
|
return /*#__PURE__*/_react["default"].createElement("g", {
|
|
@@ -373,7 +376,9 @@ var _default = /*#__PURE__*/(0, _react.memo)( /*#__PURE__*/(0, _react.forwardRef
|
|
|
373
376
|
transform: "translate(" + x + ", " + y + ")"
|
|
374
377
|
}, /*#__PURE__*/_react["default"].createElement(AxisLine, {
|
|
375
378
|
orientation: orientation,
|
|
376
|
-
config: axisLine,
|
|
379
|
+
config: _objectSpread(_objectSpread({}, axisLine), {}, {
|
|
380
|
+
cHeight: cHeight
|
|
381
|
+
}),
|
|
377
382
|
range: range
|
|
378
383
|
}), tickLine && ticks.map(function (tick, index) {
|
|
379
384
|
var coordinate = scaler(tick);
|
|
@@ -402,9 +407,12 @@ var _default = /*#__PURE__*/(0, _react.memo)( /*#__PURE__*/(0, _react.forwardRef
|
|
|
402
407
|
transform: "translate(" + x + ", " + y + ")"
|
|
403
408
|
}, /*#__PURE__*/_react["default"].createElement(AxisLine, {
|
|
404
409
|
orientation: orientation,
|
|
405
|
-
config: axisLine,
|
|
410
|
+
config: _objectSpread(_objectSpread({}, axisLine), {}, {
|
|
411
|
+
cHeight: cHeight
|
|
412
|
+
}),
|
|
406
413
|
isClipAxis: isClipAxis,
|
|
407
|
-
clipAxisRange: clipAxisRange
|
|
414
|
+
clipAxisRange: clipAxisRange,
|
|
415
|
+
cPercent: cPercent
|
|
408
416
|
}), tickLine && drawAxisTickLine()))), /*#__PURE__*/_react["default"].createElement("svg", {
|
|
409
417
|
width: width,
|
|
410
418
|
style: {
|
|
@@ -414,7 +422,15 @@ var _default = /*#__PURE__*/(0, _react.memo)( /*#__PURE__*/(0, _react.forwardRef
|
|
|
414
422
|
transform: "translate(" + x + ", " + y + ")"
|
|
415
423
|
}, /*#__PURE__*/_react["default"].createElement("g", {
|
|
416
424
|
ref: ref
|
|
417
|
-
}, label && gridLine && drawLabel(),
|
|
425
|
+
}, label && gridLine && drawLabel(), isC && /*#__PURE__*/_react["default"].createElement(AxisLine, {
|
|
426
|
+
orientation: orientation,
|
|
427
|
+
config: _objectSpread(_objectSpread({}, axisLine), {}, {
|
|
428
|
+
cHeight: cHeight
|
|
429
|
+
}),
|
|
430
|
+
isClipAxis: isClipAxis,
|
|
431
|
+
clipAxisRange: clipAxisRange,
|
|
432
|
+
cPercent: cPercent
|
|
433
|
+
}), isC && tickLine && drawAxisTickLine(), unit && /*#__PURE__*/_react["default"].createElement(Unit, {
|
|
418
434
|
config: unit
|
|
419
435
|
})))));
|
|
420
436
|
}));
|
package/lib/components/Band.js
CHANGED
|
@@ -205,43 +205,46 @@ var _default = /*#__PURE__*/(0, _react.memo)(function (_ref3) {
|
|
|
205
205
|
style: {
|
|
206
206
|
overflow: "visible",
|
|
207
207
|
position: "relative",
|
|
208
|
-
pointerEvents: isControlChart ? "auto" : "none",
|
|
209
208
|
cursor: "pointer"
|
|
210
209
|
}
|
|
211
210
|
}, attr, {
|
|
212
211
|
onClick: triggerClick //enter和leave事件,用于控制图的提示框
|
|
213
212
|
,
|
|
214
213
|
onMouseEnter: function onMouseEnter() {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
214
|
+
if (isControlChart) {
|
|
215
|
+
setCtlTip(function (pre) {
|
|
216
|
+
return {
|
|
217
|
+
show: true,
|
|
218
|
+
x: xScaler(x),
|
|
219
|
+
xName: data.x,
|
|
220
|
+
indicatorList: pre.indicatorList.map(function (item) {
|
|
221
|
+
if (item.tick === data.x) {
|
|
222
|
+
return _objectSpread(_objectSpread({}, item), {}, {
|
|
223
|
+
isShow: true
|
|
224
|
+
});
|
|
225
|
+
} else {
|
|
226
|
+
return item;
|
|
227
|
+
}
|
|
228
|
+
})
|
|
229
|
+
};
|
|
230
|
+
});
|
|
231
|
+
}
|
|
231
232
|
},
|
|
232
233
|
onMouseLeave: function onMouseLeave() {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
234
|
+
if (isControlChart) {
|
|
235
|
+
setCtlTip(function (pre) {
|
|
236
|
+
return {
|
|
237
|
+
show: false,
|
|
238
|
+
x: undefined,
|
|
239
|
+
xName: undefined,
|
|
240
|
+
indicatorList: pre.indicatorList.map(function (item) {
|
|
241
|
+
return _objectSpread(_objectSpread({}, item), {}, {
|
|
242
|
+
isShow: false
|
|
243
|
+
});
|
|
244
|
+
})
|
|
245
|
+
};
|
|
246
|
+
});
|
|
247
|
+
}
|
|
245
248
|
},
|
|
246
249
|
"data-data": JSON.stringify(data)
|
|
247
250
|
}), headUrl && showHead && /*#__PURE__*/_react["default"].createElement("div", {
|
|
@@ -70,6 +70,7 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
|
|
|
70
70
|
brush = _ref$config.brush,
|
|
71
71
|
_ref$config$control = _ref$config.control,
|
|
72
72
|
control = _ref$config$control === void 0 ? null : _ref$config$control,
|
|
73
|
+
active = _ref.active,
|
|
73
74
|
style = _ref.style,
|
|
74
75
|
originData = _ref.originData,
|
|
75
76
|
filterData = _ref.filterData,
|
|
@@ -140,7 +141,7 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
|
|
|
140
141
|
controlInfo: controlInfo
|
|
141
142
|
});
|
|
142
143
|
var aiData = aiFormatter ? aiFormatter(originData, axes, series) : (0, _hooks.useAiData)(originData, axes, series);
|
|
143
|
-
var axisX = (0, _hooks.useCarouselAxisX)(axes.get("x"), animation, isHover, controlInfo);
|
|
144
|
+
var axisX = (0, _hooks.useCarouselAxisX)(axes.get("x"), animation, isHover, controlInfo, active);
|
|
144
145
|
(0, _react.useEffect)(function () {
|
|
145
146
|
if (aiData.length) {
|
|
146
147
|
if (!window.aiData) {
|
|
@@ -167,7 +168,8 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
|
|
|
167
168
|
height: yLineRange,
|
|
168
169
|
axisX: axisX,
|
|
169
170
|
isHover: isHover,
|
|
170
|
-
config: tooltipConfig
|
|
171
|
+
config: tooltipConfig,
|
|
172
|
+
active: active
|
|
171
173
|
}),
|
|
172
174
|
tooltipX = _useTooltip.x,
|
|
173
175
|
tickName = _useTooltip.name,
|
|
@@ -341,7 +343,7 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
|
|
|
341
343
|
cancelAnimationFrame(controlTimer.current);
|
|
342
344
|
};
|
|
343
345
|
}
|
|
344
|
-
}, [JSON.stringify(animation), control]); //初始化控制图提示框状态的函数
|
|
346
|
+
}, [JSON.stringify(animation), control, controlInfo]); //初始化控制图提示框状态的函数
|
|
345
347
|
|
|
346
348
|
var initCtlTip = function initCtlTip() {
|
|
347
349
|
return {
|
|
@@ -494,9 +496,9 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
|
|
|
494
496
|
},
|
|
495
497
|
props: {
|
|
496
498
|
control: control,
|
|
499
|
+
controlInfo: controlInfo,
|
|
497
500
|
axes: axes,
|
|
498
501
|
series: series,
|
|
499
|
-
width: width,
|
|
500
502
|
top: chartHeight + marginTop,
|
|
501
503
|
bandLength: bandLength
|
|
502
504
|
}
|
package/lib/components/Chart.js
CHANGED
|
@@ -13,6 +13,8 @@ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")
|
|
|
13
13
|
|
|
14
14
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
15
15
|
|
|
16
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
17
|
+
|
|
16
18
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
17
19
|
|
|
18
20
|
var _react = _interopRequireWildcard(require("react"));
|
|
@@ -71,6 +73,12 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref2) {
|
|
|
71
73
|
var svg = /*#__PURE__*/(0, _react.createRef)();
|
|
72
74
|
var chartWidth = width - marginLeft - marginRight;
|
|
73
75
|
var chartHeight = height - marginTop - marginBottom;
|
|
76
|
+
|
|
77
|
+
var _useState = (0, _react.useState)(true),
|
|
78
|
+
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
|
79
|
+
active = _useState2[0],
|
|
80
|
+
setActive = _useState2[1];
|
|
81
|
+
|
|
74
82
|
var triggerOnRelative = (0, _react.useCallback)(function (action, data) {
|
|
75
83
|
if (!interaction) return;
|
|
76
84
|
var callbacks = interaction.callbacks,
|
|
@@ -106,7 +114,20 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref2) {
|
|
|
106
114
|
svg: svg,
|
|
107
115
|
onEmit: onEmit
|
|
108
116
|
};
|
|
109
|
-
}, [id, chartWidth, chartHeight, triggerOnRelative, svg, onEmit]);
|
|
117
|
+
}, [id, chartWidth, chartHeight, triggerOnRelative, svg, onEmit]);
|
|
118
|
+
(0, _react.useEffect)(function () {
|
|
119
|
+
var activeHandler = function activeHandler(e) {
|
|
120
|
+
var _e$dynamicData = e.dynamicData,
|
|
121
|
+
dynamicData = _e$dynamicData === void 0 ? true : _e$dynamicData; // console.log("当前组件(id="+id+")状态:",dynamicData?"唤醒":"休眠");
|
|
122
|
+
|
|
123
|
+
setActive(dynamicData);
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
document.addEventListener("switchActive_".concat(id), activeHandler);
|
|
127
|
+
return function () {
|
|
128
|
+
document.removeEventListener("switchActive_".concat(id), activeHandler);
|
|
129
|
+
};
|
|
130
|
+
}, []); //对轴类图表进行
|
|
110
131
|
|
|
111
132
|
var data = originData;
|
|
112
133
|
|
|
@@ -142,7 +163,8 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref2) {
|
|
|
142
163
|
}, props)) : /*#__PURE__*/_react["default"].createElement(_.CartesianChart, (0, _extends2["default"])({
|
|
143
164
|
id: id,
|
|
144
165
|
config: config,
|
|
145
|
-
data: data
|
|
166
|
+
data: data,
|
|
167
|
+
active: active
|
|
146
168
|
}, props)));
|
|
147
169
|
});
|
|
148
170
|
var _default = Chart;
|
|
@@ -13,6 +13,8 @@ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")
|
|
|
13
13
|
|
|
14
14
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
15
15
|
|
|
16
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
17
|
+
|
|
16
18
|
var _react = _interopRequireWildcard(require("react"));
|
|
17
19
|
|
|
18
20
|
var _d3Scale = require("d3-scale");
|
|
@@ -23,6 +25,10 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
23
25
|
|
|
24
26
|
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; }
|
|
25
27
|
|
|
28
|
+
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; }
|
|
29
|
+
|
|
30
|
+
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; }
|
|
31
|
+
|
|
26
32
|
var _default = /*#__PURE__*/(0, _react.memo)( /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
27
33
|
var _props$actions = props.actions,
|
|
28
34
|
setX = _props$actions.setX,
|
|
@@ -32,24 +38,22 @@ var _default = /*#__PURE__*/(0, _react.memo)( /*#__PURE__*/(0, _react.forwardRef
|
|
|
32
38
|
_props$props$control = _props$props.control,
|
|
33
39
|
height = _props$props$control.height,
|
|
34
40
|
color = _props$props$control.color,
|
|
35
|
-
|
|
36
|
-
dragColor = _props$props$control
|
|
37
|
-
|
|
38
|
-
_props$props$
|
|
39
|
-
|
|
40
|
-
|
|
41
|
+
gap = _props$props$control.gap,
|
|
42
|
+
dragColor = _props$props$control.drag.color,
|
|
43
|
+
left = _props$props$control.margin.left,
|
|
44
|
+
_props$props$controlI = _props$props.controlInfo,
|
|
45
|
+
cWidth = _props$props$controlI.cWidth,
|
|
46
|
+
cBarWidth = _props$props$controlI.cBarWidth,
|
|
41
47
|
axes = _props$props.axes,
|
|
42
48
|
series = _props$props.series,
|
|
43
|
-
width = _props$props.width,
|
|
44
49
|
top = _props$props.top,
|
|
45
50
|
bandLength = _props$props.bandLength;
|
|
46
|
-
var barWidth = width - left - right;
|
|
47
51
|
var xAxis = axes.get("x");
|
|
48
52
|
var barRef = (0, _react.useRef)();
|
|
49
53
|
var barStyle = {
|
|
50
54
|
position: "absolute",
|
|
51
55
|
top: 0,
|
|
52
|
-
width:
|
|
56
|
+
width: cBarWidth,
|
|
53
57
|
display: "flex",
|
|
54
58
|
justifyContent: "space-between",
|
|
55
59
|
background: dragColor
|
|
@@ -67,7 +71,7 @@ var _default = /*#__PURE__*/(0, _react.memo)( /*#__PURE__*/(0, _react.forwardRef
|
|
|
67
71
|
cursor: "col-resize",
|
|
68
72
|
background: "rgb(2, 176, 249)",
|
|
69
73
|
WebkitBackgroundClip: "content-box"
|
|
70
|
-
};
|
|
74
|
+
}; //滑块的鼠标按下操作
|
|
71
75
|
|
|
72
76
|
var down = function down() {
|
|
73
77
|
var transform = ref.current.style.transform;
|
|
@@ -89,14 +93,36 @@ var _default = /*#__PURE__*/(0, _react.memo)( /*#__PURE__*/(0, _react.forwardRef
|
|
|
89
93
|
document.addEventListener("mousemove", mouseMoveHandle);
|
|
90
94
|
document.addEventListener("mouseup", mouseUpHandle);
|
|
91
95
|
setWorking(true);
|
|
96
|
+
}; // //右手柄的鼠标按下逻辑
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
var rightDown = function rightDown() {
|
|
100
|
+
var move = function move(e) {
|
|
101
|
+
var movementX = e.movementX;
|
|
102
|
+
setControlInfo(function (pre) {
|
|
103
|
+
var nextBarWidth = pre.cBarWidth + movementX;
|
|
104
|
+
return _objectSpread(_objectSpread({}, pre), {}, {
|
|
105
|
+
cBarWidth: nextBarWidth,
|
|
106
|
+
cPercent: nextBarWidth / pre.cWidth
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
var up = function up() {
|
|
112
|
+
document.removeEventListener("mousemove", move);
|
|
113
|
+
document.removeEventListener("mouseup", up);
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
document.addEventListener("mousemove", move);
|
|
117
|
+
document.addEventListener("mouseup", up);
|
|
92
118
|
};
|
|
93
119
|
|
|
94
120
|
return /*#__PURE__*/_react["default"].createElement("div", {
|
|
95
121
|
style: {
|
|
96
|
-
width:
|
|
122
|
+
width: cWidth,
|
|
97
123
|
height: height,
|
|
98
124
|
backgroundColor: color,
|
|
99
|
-
transform: "translate(".concat(left, "px,").concat(top, "px)")
|
|
125
|
+
transform: "translate(".concat(left, "px,").concat(top - height + gap, "px)")
|
|
100
126
|
}
|
|
101
127
|
}, /*#__PURE__*/_react["default"].createElement("svg", {
|
|
102
128
|
width: "100%",
|
package/lib/hooks/useAxes.js
CHANGED
|
@@ -33,7 +33,7 @@ var initialState = {
|
|
|
33
33
|
* @returns {Map} 返回经过改变后的x轴,主要是ticks和scaler的range发生了改变
|
|
34
34
|
*/
|
|
35
35
|
|
|
36
|
-
var _default = function _default(axis, config, isHover, controlInfo) {
|
|
36
|
+
var _default = function _default(axis, config, isHover, controlInfo, active) {
|
|
37
37
|
var show = config.show,
|
|
38
38
|
interval = config.interval,
|
|
39
39
|
duration = config.duration,
|
|
@@ -84,7 +84,7 @@ var _default = function _default(axis, config, isHover, controlInfo) {
|
|
|
84
84
|
(0, _react.useEffect)(function () {
|
|
85
85
|
var handler;
|
|
86
86
|
|
|
87
|
-
if (!(hover && isHover) && show && time && tickLength > tickCount) {
|
|
87
|
+
if (!(hover && isHover) && show && time && tickLength > tickCount && active) {
|
|
88
88
|
handler = setInterval(function () {
|
|
89
89
|
setStatus(function (_ref) {
|
|
90
90
|
var currentIndex = _ref.currentIndex;
|
|
@@ -100,7 +100,7 @@ var _default = function _default(axis, config, isHover, controlInfo) {
|
|
|
100
100
|
return function () {
|
|
101
101
|
handler && clearInterval(handler);
|
|
102
102
|
};
|
|
103
|
-
}, [show, time, tickCount, tickLength, hover, isHover]);
|
|
103
|
+
}, [show, time, tickCount, tickLength, hover, isHover, active]);
|
|
104
104
|
(0, _react.useEffect)(function () {
|
|
105
105
|
var animation;
|
|
106
106
|
var currentIndex = status.currentIndex,
|
package/lib/hooks/useTooltip.js
CHANGED
|
@@ -23,6 +23,7 @@ var callback = function callback() {};
|
|
|
23
23
|
* @param {Number} height 高
|
|
24
24
|
* @param {Number} axisX 类目轴
|
|
25
25
|
* @param {Object} config 轮播动画参数
|
|
26
|
+
* @param {Boolean} active 组件是否处于活跃状态
|
|
26
27
|
* @returns {Object} 返回被选中的名称,坐标,选中方法
|
|
27
28
|
*/
|
|
28
29
|
|
|
@@ -40,7 +41,8 @@ var _default = function _default(_ref) {
|
|
|
40
41
|
var auto = _ref$config.auto,
|
|
41
42
|
_ref$config$interval = _ref$config.interval,
|
|
42
43
|
interval = _ref$config$interval === void 0 ? 0 : _ref$config$interval,
|
|
43
|
-
manual = _ref$config.manual
|
|
44
|
+
manual = _ref$config.manual,
|
|
45
|
+
active = _ref.active;
|
|
44
46
|
|
|
45
47
|
var _useState = (0, _react.useState)(null),
|
|
46
48
|
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
|
@@ -90,7 +92,7 @@ var _default = function _default(_ref) {
|
|
|
90
92
|
}
|
|
91
93
|
}, [svg, marginLeft, axisX, auto]);
|
|
92
94
|
(0, _react.useEffect)(function () {
|
|
93
|
-
var on = auto && tickLength && !isHover; // if (!!on) setCurrentIndex(0);
|
|
95
|
+
var on = auto && tickLength && !isHover && active; // if (!!on) setCurrentIndex(0);
|
|
94
96
|
|
|
95
97
|
var intervalHandler = on ? setInterval(function () {
|
|
96
98
|
setCurrentIndex(function (index) {
|
|
@@ -107,7 +109,7 @@ var _default = function _default(_ref) {
|
|
|
107
109
|
return function () {
|
|
108
110
|
intervalHandler && clearInterval(intervalHandler);
|
|
109
111
|
};
|
|
110
|
-
}, [auto, tickLength, interval, isHover]);
|
|
112
|
+
}, [auto, tickLength, interval, isHover, active]);
|
|
111
113
|
var name = currentIndex === null ? null : axisX.allTicks[currentIndex];
|
|
112
114
|
return {
|
|
113
115
|
name: name,
|
package/package.json
CHANGED
package/src/components/Axis.tsx
CHANGED
|
@@ -36,15 +36,17 @@ const defaultFormatter: (
|
|
|
36
36
|
|
|
37
37
|
const getAxesPath: (
|
|
38
38
|
orientation: Orientation,
|
|
39
|
-
{ width, height }: Context
|
|
40
|
-
|
|
39
|
+
{ width, height }: Context,
|
|
40
|
+
cHeight:number,
|
|
41
|
+
cPercent:number
|
|
42
|
+
) => string = (orientation, { width, height }, cHeight, cPercent) => {
|
|
41
43
|
switch (orientation) {
|
|
42
44
|
case "top":
|
|
43
45
|
case "bottom":
|
|
44
|
-
return "M-0.5, 0H" + width;
|
|
46
|
+
return "M-0.5, 0H" + width/cPercent;
|
|
45
47
|
case "left":
|
|
46
48
|
case "right":
|
|
47
|
-
return "M0, -0.5V" + (height + 0.5);
|
|
49
|
+
return "M0, -0.5V" + (height + 0.5 - cHeight);
|
|
48
50
|
}
|
|
49
51
|
};
|
|
50
52
|
/**
|
|
@@ -97,15 +99,16 @@ const AxisLine: ({
|
|
|
97
99
|
config,
|
|
98
100
|
isClipAxis,
|
|
99
101
|
clipAxisRange,
|
|
102
|
+
cPercent
|
|
100
103
|
}: any) => ReactComponentElement<ComponentType> | null = ({
|
|
101
104
|
orientation = defaultOrientation,
|
|
102
|
-
config: { show, color, lineWidth },
|
|
105
|
+
config: { show, color, lineWidth, cHeight },
|
|
103
106
|
isClipAxis = false,
|
|
104
107
|
clipAxisRange = [],
|
|
108
|
+
cPercent = 1
|
|
105
109
|
}) => {
|
|
106
110
|
if (!show) return null;
|
|
107
111
|
const context: Context = useContext(chartContext);
|
|
108
|
-
const { width, height } = context;
|
|
109
112
|
if (isClipAxis) {
|
|
110
113
|
return (
|
|
111
114
|
<>
|
|
@@ -124,7 +127,7 @@ const AxisLine: ({
|
|
|
124
127
|
} else {
|
|
125
128
|
return (
|
|
126
129
|
<path
|
|
127
|
-
d={getAxesPath(orientation, context)}
|
|
130
|
+
d={getAxesPath(orientation, context, cHeight, cPercent)}
|
|
128
131
|
stroke={color}
|
|
129
132
|
strokeWidth={lineWidth}
|
|
130
133
|
/>
|
|
@@ -263,7 +266,6 @@ export default memo(
|
|
|
263
266
|
rotate,
|
|
264
267
|
triggerClick,
|
|
265
268
|
config: { on, label, axisLine, tickLine, gridLine, unit },
|
|
266
|
-
config,
|
|
267
269
|
positions,
|
|
268
270
|
xLineRange,
|
|
269
271
|
range,
|
|
@@ -280,7 +282,7 @@ export default memo(
|
|
|
280
282
|
) => {
|
|
281
283
|
if (!(on && ticks.length > 0)) return null;
|
|
282
284
|
const { width, height } = useContext(chartContext);
|
|
283
|
-
const { cHeight, isC } = controlInfo;
|
|
285
|
+
const { cHeight, isC, cPercent } = controlInfo;
|
|
284
286
|
const x = orientation == "right" ? width : 0;
|
|
285
287
|
const y = orientation == "bottom" ? height-cHeight : 0;
|
|
286
288
|
|
|
@@ -303,7 +305,7 @@ export default memo(
|
|
|
303
305
|
const y1 = gridCoord.y1;
|
|
304
306
|
return (
|
|
305
307
|
!(
|
|
306
|
-
(orientation == "bottom" && (x1 < 0 || x1 > xLineRange)) ||
|
|
308
|
+
(orientation == "bottom" && !isC && (x1 < 0 || x1 > xLineRange)) ||
|
|
307
309
|
y1 < 0 ||
|
|
308
310
|
y1 > yLineRange
|
|
309
311
|
) && (
|
|
@@ -321,7 +323,7 @@ export default memo(
|
|
|
321
323
|
);
|
|
322
324
|
});
|
|
323
325
|
};
|
|
324
|
-
|
|
326
|
+
|
|
325
327
|
if (isClipAxis) {
|
|
326
328
|
return (
|
|
327
329
|
<>
|
|
@@ -330,11 +332,12 @@ export default memo(
|
|
|
330
332
|
})}
|
|
331
333
|
</>
|
|
332
334
|
);
|
|
333
|
-
} else {
|
|
335
|
+
} else if (isC && orientation == "bottom") {
|
|
336
|
+
return <>{draw(rawTicks, scaler)}</>;
|
|
337
|
+
}else {
|
|
334
338
|
return <>{draw(ticks, scaler)}</>;
|
|
335
339
|
}
|
|
336
340
|
}
|
|
337
|
-
|
|
338
341
|
function drawLabel() {
|
|
339
342
|
const draw = (ticks: any, scaler: any) => {
|
|
340
343
|
return ticks.map((tick: string, index: number) => {
|
|
@@ -398,11 +401,10 @@ export default memo(
|
|
|
398
401
|
return <>{draw(ticks, scaler)}</>;
|
|
399
402
|
}
|
|
400
403
|
}
|
|
401
|
-
|
|
402
404
|
return (
|
|
403
405
|
<g>
|
|
404
406
|
{/* 绘制轴线和刻度 */}
|
|
405
|
-
{axisLine && tickLine && (
|
|
407
|
+
{axisLine && tickLine && !isC && (
|
|
406
408
|
<g>
|
|
407
409
|
{axisLine &&
|
|
408
410
|
(positions && positions.length ? (
|
|
@@ -413,7 +415,7 @@ export default memo(
|
|
|
413
415
|
>
|
|
414
416
|
<AxisLine
|
|
415
417
|
orientation={orientation}
|
|
416
|
-
config={axisLine}
|
|
418
|
+
config={{...axisLine,cHeight}}
|
|
417
419
|
range={range}
|
|
418
420
|
/>
|
|
419
421
|
{tickLine &&
|
|
@@ -457,9 +459,10 @@ export default memo(
|
|
|
457
459
|
<g transform={"translate(" + x + ", " + y + ")"}>
|
|
458
460
|
<AxisLine
|
|
459
461
|
orientation={orientation}
|
|
460
|
-
config={axisLine}
|
|
462
|
+
config={{...axisLine,cHeight}}
|
|
461
463
|
isClipAxis={isClipAxis}
|
|
462
464
|
clipAxisRange={clipAxisRange}
|
|
465
|
+
cPercent={cPercent}
|
|
463
466
|
/>
|
|
464
467
|
{tickLine && drawAxisTickLine()}
|
|
465
468
|
</g>
|
|
@@ -478,6 +481,14 @@ export default memo(
|
|
|
478
481
|
{/* 用于控制图 */}
|
|
479
482
|
<g ref={ref as any}>
|
|
480
483
|
{label && gridLine && drawLabel()}
|
|
484
|
+
{isC && <AxisLine
|
|
485
|
+
orientation={orientation}
|
|
486
|
+
config={{...axisLine,cHeight}}
|
|
487
|
+
isClipAxis={isClipAxis}
|
|
488
|
+
clipAxisRange={clipAxisRange}
|
|
489
|
+
cPercent={cPercent}
|
|
490
|
+
/>}
|
|
491
|
+
{isC && tickLine && drawAxisTickLine()}
|
|
481
492
|
{unit && <Unit config={unit} />}
|
|
482
493
|
</g>
|
|
483
494
|
</g>
|
package/src/components/Band.tsx
CHANGED
|
@@ -169,35 +169,38 @@ export default memo(
|
|
|
169
169
|
style={{
|
|
170
170
|
overflow: "visible",
|
|
171
171
|
position: "relative",
|
|
172
|
-
pointerEvents:isControlChart?"auto":"none",
|
|
173
172
|
cursor: "pointer",
|
|
174
173
|
}}
|
|
175
174
|
{...attr}
|
|
176
175
|
onClick={triggerClick}
|
|
177
176
|
//enter和leave事件,用于控制图的提示框
|
|
178
177
|
onMouseEnter={() => {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
178
|
+
if(isControlChart){
|
|
179
|
+
setCtlTip((pre:any)=>({
|
|
180
|
+
show:true,
|
|
181
|
+
x:xScaler(x),
|
|
182
|
+
xName:data.x,
|
|
183
|
+
indicatorList:pre.indicatorList.map((item:any)=>{
|
|
184
|
+
if (item.tick === data.x) {
|
|
185
|
+
return { ...item, isShow: true };
|
|
186
|
+
} else {
|
|
187
|
+
return item;
|
|
188
|
+
}
|
|
189
|
+
})
|
|
190
|
+
}))
|
|
191
|
+
}
|
|
191
192
|
}}
|
|
192
193
|
onMouseLeave={() => {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
194
|
+
if(isControlChart){
|
|
195
|
+
setCtlTip((pre:any)=>({
|
|
196
|
+
show:false,
|
|
197
|
+
x:undefined,
|
|
198
|
+
xName:undefined,
|
|
199
|
+
indicatorList:pre.indicatorList.map((item:any)=>{
|
|
200
|
+
return { ...item, isShow:false }
|
|
201
|
+
})
|
|
202
|
+
}))
|
|
203
|
+
}
|
|
201
204
|
}}
|
|
202
205
|
data-data={JSON.stringify(data)}
|
|
203
206
|
>
|
|
@@ -58,6 +58,7 @@ const Chart = memo(
|
|
|
58
58
|
brush,
|
|
59
59
|
control = null,
|
|
60
60
|
},
|
|
61
|
+
active,
|
|
61
62
|
style,
|
|
62
63
|
originData,
|
|
63
64
|
filterData,
|
|
@@ -112,7 +113,8 @@ const Chart = memo(
|
|
|
112
113
|
axes.get("x"),
|
|
113
114
|
animation,
|
|
114
115
|
isHover,
|
|
115
|
-
controlInfo
|
|
116
|
+
controlInfo,
|
|
117
|
+
active
|
|
116
118
|
);
|
|
117
119
|
useEffect(()=>{
|
|
118
120
|
if(aiData.length){
|
|
@@ -143,6 +145,7 @@ const Chart = memo(
|
|
|
143
145
|
axisX,
|
|
144
146
|
isHover,
|
|
145
147
|
config: tooltipConfig,
|
|
148
|
+
active
|
|
146
149
|
});
|
|
147
150
|
const tooltipData = useMemo(
|
|
148
151
|
() =>
|
|
@@ -291,7 +294,7 @@ const Chart = memo(
|
|
|
291
294
|
cancelAnimationFrame(controlTimer.current);
|
|
292
295
|
};
|
|
293
296
|
}
|
|
294
|
-
}, [JSON.stringify(animation), control]);
|
|
297
|
+
}, [JSON.stringify(animation), control, controlInfo]);
|
|
295
298
|
//初始化控制图提示框状态的函数
|
|
296
299
|
const initCtlTip = ()=>{
|
|
297
300
|
return {
|
|
@@ -488,9 +491,9 @@ const Chart = memo(
|
|
|
488
491
|
}}
|
|
489
492
|
props={{
|
|
490
493
|
control,
|
|
494
|
+
controlInfo,
|
|
491
495
|
axes,
|
|
492
496
|
series,
|
|
493
|
-
width,
|
|
494
497
|
top:chartHeight+marginTop,
|
|
495
498
|
bandLength,
|
|
496
499
|
}}
|
package/src/components/Chart.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 总入口,通过外面传进来的type来确定渲染哪种图表,饼环图表为“pie”,否则为轴类图表
|
|
3
3
|
*/
|
|
4
|
-
import React, { memo, useMemo, createRef, useCallback } from 'react';
|
|
4
|
+
import React, { memo, useMemo, createRef, useState, useEffect, useCallback } from 'react';
|
|
5
5
|
import { chartContext } from '../context';
|
|
6
6
|
import { PieChart, CartesianChart } from '.';
|
|
7
7
|
import { group } from 'd3v7';
|
|
@@ -43,6 +43,8 @@ const Chart = memo(
|
|
|
43
43
|
const chartWidth = width - marginLeft - marginRight;
|
|
44
44
|
const chartHeight = height - marginTop - marginBottom;
|
|
45
45
|
|
|
46
|
+
const [active, setActive] = useState(true);
|
|
47
|
+
|
|
46
48
|
const triggerOnRelative = useCallback(
|
|
47
49
|
(action,data) => {
|
|
48
50
|
if (!interaction) return;
|
|
@@ -87,6 +89,20 @@ const Chart = memo(
|
|
|
87
89
|
}),
|
|
88
90
|
[id, chartWidth, chartHeight, triggerOnRelative, svg, onEmit]
|
|
89
91
|
);
|
|
92
|
+
|
|
93
|
+
useEffect(()=>{
|
|
94
|
+
const activeHandler=(e)=>{
|
|
95
|
+
const { dynamicData = true } = e;
|
|
96
|
+
// console.log("当前组件(id="+id+")状态:",dynamicData?"唤醒":"休眠");
|
|
97
|
+
setActive(dynamicData);
|
|
98
|
+
}
|
|
99
|
+
document.addEventListener(`switchActive_${id}`,activeHandler);
|
|
100
|
+
return ()=>{
|
|
101
|
+
document.removeEventListener(`switchActive_${id}`,activeHandler);
|
|
102
|
+
}
|
|
103
|
+
},[]);
|
|
104
|
+
|
|
105
|
+
|
|
90
106
|
//对轴类图表进行
|
|
91
107
|
let data = originData;
|
|
92
108
|
if(axes){
|
|
@@ -107,7 +123,7 @@ const Chart = memo(
|
|
|
107
123
|
{type == 'pie' ? (
|
|
108
124
|
<PieChart id={id} config={config} data={data} {...props} />
|
|
109
125
|
) : (
|
|
110
|
-
<CartesianChart id={id} config={config} data={data} {...props} />
|
|
126
|
+
<CartesianChart id={id} config={config} data={data} active={active} {...props} />
|
|
111
127
|
)}
|
|
112
128
|
</chartContext.Provider>
|
|
113
129
|
);
|
|
@@ -5,17 +5,18 @@ export default memo(forwardRef((props, ref) => {
|
|
|
5
5
|
const {
|
|
6
6
|
actions:{ setX, setWorking, setControlInfo },
|
|
7
7
|
props: {
|
|
8
|
-
control:{ height, color, drag:{ color:dragColor
|
|
8
|
+
control:{ height, color, gap, drag:{ color:dragColor }, margin:{ left } },
|
|
9
|
+
controlInfo:{ cWidth, cBarWidth },
|
|
10
|
+
axes, series, top, bandLength
|
|
9
11
|
}
|
|
10
12
|
} = props;
|
|
11
|
-
const barWidth = width-left-right;
|
|
12
13
|
const xAxis = axes.get("x");
|
|
13
14
|
const barRef = useRef();
|
|
14
15
|
|
|
15
16
|
const barStyle={
|
|
16
17
|
position:"absolute",
|
|
17
18
|
top:0,
|
|
18
|
-
width:
|
|
19
|
+
width:cBarWidth,
|
|
19
20
|
display:"flex",
|
|
20
21
|
justifyContent:"space-between",
|
|
21
22
|
background:dragColor
|
|
@@ -34,6 +35,7 @@ export default memo(forwardRef((props, ref) => {
|
|
|
34
35
|
background:"rgb(2, 176, 249)",
|
|
35
36
|
WebkitBackgroundClip:"content-box",
|
|
36
37
|
}
|
|
38
|
+
//滑块的鼠标按下操作
|
|
37
39
|
const down=()=>{
|
|
38
40
|
const transform = ref.current.style.transform;
|
|
39
41
|
let movementX = 0;
|
|
@@ -52,13 +54,34 @@ export default memo(forwardRef((props, ref) => {
|
|
|
52
54
|
document.addEventListener("mouseup", mouseUpHandle);
|
|
53
55
|
setWorking(true);
|
|
54
56
|
}
|
|
57
|
+
// //右手柄的鼠标按下逻辑
|
|
58
|
+
const rightDown=()=>{
|
|
59
|
+
|
|
60
|
+
const move=(e)=>{
|
|
61
|
+
const { movementX } = e;
|
|
62
|
+
setControlInfo(pre=>{
|
|
63
|
+
const nextBarWidth = pre.cBarWidth+movementX;
|
|
64
|
+
return {
|
|
65
|
+
...pre,
|
|
66
|
+
cBarWidth:nextBarWidth,
|
|
67
|
+
cPercent:nextBarWidth/pre.cWidth
|
|
68
|
+
}
|
|
69
|
+
})
|
|
70
|
+
}
|
|
71
|
+
const up=()=>{
|
|
72
|
+
document.removeEventListener("mousemove",move);
|
|
73
|
+
document.removeEventListener("mouseup",up);
|
|
74
|
+
}
|
|
75
|
+
document.addEventListener("mousemove",move);
|
|
76
|
+
document.addEventListener("mouseup",up);
|
|
77
|
+
}
|
|
55
78
|
return (
|
|
56
79
|
<div
|
|
57
80
|
style={{
|
|
58
|
-
width:
|
|
81
|
+
width:cWidth,
|
|
59
82
|
height: height,
|
|
60
83
|
backgroundColor: color,
|
|
61
|
-
transform: `translate(${left}px,${top}px)`,
|
|
84
|
+
transform: `translate(${left}px,${top-height+gap}px)`,
|
|
62
85
|
}}
|
|
63
86
|
>
|
|
64
87
|
<svg width="100%" height="100%">
|
|
@@ -87,7 +110,7 @@ export default memo(forwardRef((props, ref) => {
|
|
|
87
110
|
<div ref={ref} style={barStyle}>
|
|
88
111
|
{/* <div style={{...controllerStyle,transform:"translateX(-6px)"}}></div> */}
|
|
89
112
|
<div style={dragStyle} onMouseDown={down} ref={barRef}></div>
|
|
90
|
-
{/* <div style={{...controllerStyle,transform:`translateX(6px)`}}></div> */}
|
|
113
|
+
{/* <div style={{...controllerStyle,transform:`translateX(6px)`}} onMouseDown={rightDown}></div> */}
|
|
91
114
|
</div>
|
|
92
115
|
</div>
|
|
93
116
|
);
|
package/src/hooks/useAxes.js
CHANGED
|
@@ -17,7 +17,8 @@ export default (
|
|
|
17
17
|
axis,
|
|
18
18
|
config,
|
|
19
19
|
isHover,
|
|
20
|
-
controlInfo
|
|
20
|
+
controlInfo,
|
|
21
|
+
active
|
|
21
22
|
) => {
|
|
22
23
|
const { show, interval, duration, hover } = config;
|
|
23
24
|
const { isC, cPercent } = controlInfo;
|
|
@@ -59,7 +60,7 @@ export default (
|
|
|
59
60
|
}, [show, time, tickCount, tickLength]);
|
|
60
61
|
useEffect(() => {
|
|
61
62
|
let handler;
|
|
62
|
-
if (!(hover && isHover) && show && time && tickLength > tickCount) {
|
|
63
|
+
if (!(hover && isHover) && show && time && tickLength > tickCount && active) {
|
|
63
64
|
handler = setInterval(() => {
|
|
64
65
|
setStatus(({ currentIndex }) => {
|
|
65
66
|
const tmp = +currentIndex + 1;
|
|
@@ -73,7 +74,7 @@ export default (
|
|
|
73
74
|
return () => {
|
|
74
75
|
handler && clearInterval(handler);
|
|
75
76
|
};
|
|
76
|
-
}, [show, time, tickCount, tickLength, hover, isHover]);
|
|
77
|
+
}, [show, time, tickCount, tickLength, hover, isHover, active]);
|
|
77
78
|
|
|
78
79
|
useEffect(() => {
|
|
79
80
|
let animation;
|
package/src/hooks/useTooltip.ts
CHANGED
|
@@ -11,6 +11,7 @@ const callback = () => {};
|
|
|
11
11
|
* @param {Number} height 高
|
|
12
12
|
* @param {Number} axisX 类目轴
|
|
13
13
|
* @param {Object} config 轮播动画参数
|
|
14
|
+
* @param {Boolean} active 组件是否处于活跃状态
|
|
14
15
|
* @returns {Object} 返回被选中的名称,坐标,选中方法
|
|
15
16
|
*/
|
|
16
17
|
type Props = {
|
|
@@ -22,6 +23,7 @@ type Props = {
|
|
|
22
23
|
axisX: any;
|
|
23
24
|
isHover: boolean;
|
|
24
25
|
config: { auto?: boolean; interval?: number; manual?: boolean };
|
|
26
|
+
active:boolean
|
|
25
27
|
};
|
|
26
28
|
|
|
27
29
|
export default ({
|
|
@@ -33,6 +35,7 @@ export default ({
|
|
|
33
35
|
axisX,
|
|
34
36
|
isHover,
|
|
35
37
|
config: { auto, interval = 0, manual } = {},
|
|
38
|
+
active
|
|
36
39
|
}: Props) => {
|
|
37
40
|
const [currentIndex, setCurrentIndex] = useState<number | null>(null);
|
|
38
41
|
const tickLength = axisX.allTicks.length;
|
|
@@ -73,7 +76,7 @@ export default ({
|
|
|
73
76
|
[svg, marginLeft, axisX, auto]
|
|
74
77
|
);
|
|
75
78
|
useEffect(() => {
|
|
76
|
-
const on = auto && tickLength && !isHover;
|
|
79
|
+
const on = auto && tickLength && !isHover && active;
|
|
77
80
|
// if (!!on) setCurrentIndex(0);
|
|
78
81
|
const intervalHandler = on
|
|
79
82
|
? setInterval(() => {
|
|
@@ -90,7 +93,7 @@ export default ({
|
|
|
90
93
|
return () => {
|
|
91
94
|
intervalHandler && clearInterval(intervalHandler);
|
|
92
95
|
};
|
|
93
|
-
}, [auto, tickLength, interval, isHover]);
|
|
96
|
+
}, [auto, tickLength, interval, isHover, active]);
|
|
94
97
|
const name = currentIndex === null ? null : axisX.allTicks[currentIndex];
|
|
95
98
|
return {
|
|
96
99
|
name,
|