@easyv/charts 1.4.39 → 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.
@@ -54,14 +54,14 @@ var defaultFormatter = function defaultFormatter(d, _ref) {
54
54
  return d + suffix;
55
55
  };
56
56
 
57
- var getAxesPath = function getAxesPath(orientation, _ref2, cHeight) {
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":
@@ -123,7 +123,9 @@ var AxisLine = function AxisLine(_ref3) {
123
123
  _ref3$isClipAxis = _ref3.isClipAxis,
124
124
  isClipAxis = _ref3$isClipAxis === void 0 ? false : _ref3$isClipAxis,
125
125
  _ref3$clipAxisRange = _ref3.clipAxisRange,
126
- 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;
127
129
  if (!show) return null;
128
130
  var context = (0, _react.useContext)(_context.chartContext);
129
131
 
@@ -138,7 +140,7 @@ var AxisLine = function AxisLine(_ref3) {
138
140
  }));
139
141
  } else {
140
142
  return /*#__PURE__*/_react["default"].createElement("path", {
141
- d: getAxesPath(orientation, context, cHeight),
143
+ d: getAxesPath(orientation, context, cHeight, cPercent),
142
144
  stroke: color,
143
145
  strokeWidth: lineWidth
144
146
  });
@@ -278,7 +280,8 @@ var _default = /*#__PURE__*/(0, _react.memo)( /*#__PURE__*/(0, _react.forwardRef
278
280
  height = _useContext.height;
279
281
 
280
282
  var cHeight = controlInfo.cHeight,
281
- isC = controlInfo.isC;
283
+ isC = controlInfo.isC,
284
+ cPercent = controlInfo.cPercent;
282
285
  var x = orientation == "right" ? width : 0;
283
286
  var y = orientation == "bottom" ? height - cHeight : 0;
284
287
 
@@ -297,7 +300,7 @@ var _default = /*#__PURE__*/(0, _react.memo)( /*#__PURE__*/(0, _react.forwardRef
297
300
  });
298
301
  var x1 = gridCoord.x1;
299
302
  var y1 = gridCoord.y1;
300
- 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"])({
301
304
  className: "__easyv-tickLine",
302
305
  key: index,
303
306
  config: tickLine
@@ -313,6 +316,8 @@ var _default = /*#__PURE__*/(0, _react.memo)( /*#__PURE__*/(0, _react.forwardRef
313
316
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, ticks.map(function (ticks, index) {
314
317
  return draw(ticks, scaler[index]);
315
318
  }));
319
+ } else if (isC && orientation == "bottom") {
320
+ return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, draw(rawTicks, scaler));
316
321
  } else {
317
322
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, draw(ticks, scaler));
318
323
  }
@@ -363,7 +368,7 @@ var _default = /*#__PURE__*/(0, _react.memo)( /*#__PURE__*/(0, _react.forwardRef
363
368
  }
364
369
  }
365
370
 
366
- 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) {
367
372
  var x = _ref7.x,
368
373
  y = _ref7.y;
369
374
  return /*#__PURE__*/_react["default"].createElement("g", {
@@ -406,7 +411,8 @@ var _default = /*#__PURE__*/(0, _react.memo)( /*#__PURE__*/(0, _react.forwardRef
406
411
  cHeight: cHeight
407
412
  }),
408
413
  isClipAxis: isClipAxis,
409
- clipAxisRange: clipAxisRange
414
+ clipAxisRange: clipAxisRange,
415
+ cPercent: cPercent
410
416
  }), tickLine && drawAxisTickLine()))), /*#__PURE__*/_react["default"].createElement("svg", {
411
417
  width: width,
412
418
  style: {
@@ -416,7 +422,15 @@ var _default = /*#__PURE__*/(0, _react.memo)( /*#__PURE__*/(0, _react.forwardRef
416
422
  transform: "translate(" + x + ", " + y + ")"
417
423
  }, /*#__PURE__*/_react["default"].createElement("g", {
418
424
  ref: ref
419
- }, label && gridLine && drawLabel(), unit && /*#__PURE__*/_react["default"].createElement(Unit, {
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, {
420
434
  config: unit
421
435
  })))));
422
436
  }));
@@ -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
  }
@@ -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
- _props$props$control$ = _props$props$control.drag,
36
- dragColor = _props$props$control$.color,
37
- dragWidth = _props$props$control$.width,
38
- _props$props$control$2 = _props$props$control.margin,
39
- left = _props$props$control$2.left,
40
- right = _props$props$control$2.right,
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: barWidth * dragWidth / 100,
56
+ width: cBarWidth,
53
57
  display: "flex",
54
58
  justifyContent: "space-between",
55
59
  background: dragColor
@@ -90,21 +94,35 @@ var _default = /*#__PURE__*/(0, _react.memo)( /*#__PURE__*/(0, _react.forwardRef
90
94
  document.addEventListener("mouseup", mouseUpHandle);
91
95
  setWorking(true);
92
96
  }; // //右手柄的鼠标按下逻辑
93
- // const rightDown=()=>{
94
- // const move=(e)=>{
95
- // }
96
- // const up=()=>{
97
- // }
98
- // document.addEventListener()
99
- // }
100
97
 
101
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);
118
+ };
119
+
102
120
  return /*#__PURE__*/_react["default"].createElement("div", {
103
121
  style: {
104
- width: barWidth,
122
+ width: cWidth,
105
123
  height: height,
106
124
  backgroundColor: color,
107
- transform: "translate(".concat(left, "px,").concat(top, "px)")
125
+ transform: "translate(".concat(left, "px,").concat(top - height + gap, "px)")
108
126
  }
109
127
  }, /*#__PURE__*/_react["default"].createElement("svg", {
110
128
  width: "100%",
@@ -429,7 +429,7 @@ var _default = function _default(_ref) {
429
429
  });
430
430
  tmp.get("x") && (tmp.get("x").positions = xAxisPositions);
431
431
  return tmp;
432
- }, [axes]);
432
+ }, [axes, controlInfo]);
433
433
 
434
434
  return _axes;
435
435
  };
@@ -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,
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easyv/charts",
3
- "version": "1.4.39",
3
+ "version": "1.4.40",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -37,12 +37,13 @@ const defaultFormatter: (
37
37
  const getAxesPath: (
38
38
  orientation: Orientation,
39
39
  { width, height }: Context,
40
- cHeight:number
41
- ) => string = (orientation, { width, height }, cHeight) => {
40
+ cHeight:number,
41
+ cPercent:number
42
+ ) => string = (orientation, { width, height }, cHeight, cPercent) => {
42
43
  switch (orientation) {
43
44
  case "top":
44
45
  case "bottom":
45
- return "M-0.5, 0H" + width;
46
+ return "M-0.5, 0H" + width/cPercent;
46
47
  case "left":
47
48
  case "right":
48
49
  return "M0, -0.5V" + (height + 0.5 - cHeight);
@@ -98,11 +99,13 @@ const AxisLine: ({
98
99
  config,
99
100
  isClipAxis,
100
101
  clipAxisRange,
102
+ cPercent
101
103
  }: any) => ReactComponentElement<ComponentType> | null = ({
102
104
  orientation = defaultOrientation,
103
105
  config: { show, color, lineWidth, cHeight },
104
106
  isClipAxis = false,
105
107
  clipAxisRange = [],
108
+ cPercent = 1
106
109
  }) => {
107
110
  if (!show) return null;
108
111
  const context: Context = useContext(chartContext);
@@ -124,7 +127,7 @@ const AxisLine: ({
124
127
  } else {
125
128
  return (
126
129
  <path
127
- d={getAxesPath(orientation, context, cHeight)}
130
+ d={getAxesPath(orientation, context, cHeight, cPercent)}
128
131
  stroke={color}
129
132
  strokeWidth={lineWidth}
130
133
  />
@@ -279,7 +282,7 @@ export default memo(
279
282
  ) => {
280
283
  if (!(on && ticks.length > 0)) return null;
281
284
  const { width, height } = useContext(chartContext);
282
- const { cHeight, isC } = controlInfo;
285
+ const { cHeight, isC, cPercent } = controlInfo;
283
286
  const x = orientation == "right" ? width : 0;
284
287
  const y = orientation == "bottom" ? height-cHeight : 0;
285
288
 
@@ -302,7 +305,7 @@ export default memo(
302
305
  const y1 = gridCoord.y1;
303
306
  return (
304
307
  !(
305
- (orientation == "bottom" && (x1 < 0 || x1 > xLineRange)) ||
308
+ (orientation == "bottom" && !isC && (x1 < 0 || x1 > xLineRange)) ||
306
309
  y1 < 0 ||
307
310
  y1 > yLineRange
308
311
  ) && (
@@ -320,7 +323,7 @@ export default memo(
320
323
  );
321
324
  });
322
325
  };
323
-
326
+
324
327
  if (isClipAxis) {
325
328
  return (
326
329
  <>
@@ -329,11 +332,12 @@ export default memo(
329
332
  })}
330
333
  </>
331
334
  );
332
- } else {
335
+ } else if (isC && orientation == "bottom") {
336
+ return <>{draw(rawTicks, scaler)}</>;
337
+ }else {
333
338
  return <>{draw(ticks, scaler)}</>;
334
339
  }
335
340
  }
336
-
337
341
  function drawLabel() {
338
342
  const draw = (ticks: any, scaler: any) => {
339
343
  return ticks.map((tick: string, index: number) => {
@@ -400,7 +404,7 @@ export default memo(
400
404
  return (
401
405
  <g>
402
406
  {/* 绘制轴线和刻度 */}
403
- {axisLine && tickLine && (
407
+ {axisLine && tickLine && !isC && (
404
408
  <g>
405
409
  {axisLine &&
406
410
  (positions && positions.length ? (
@@ -458,6 +462,7 @@ export default memo(
458
462
  config={{...axisLine,cHeight}}
459
463
  isClipAxis={isClipAxis}
460
464
  clipAxisRange={clipAxisRange}
465
+ cPercent={cPercent}
461
466
  />
462
467
  {tickLine && drawAxisTickLine()}
463
468
  </g>
@@ -476,6 +481,14 @@ export default memo(
476
481
  {/* 用于控制图 */}
477
482
  <g ref={ref as any}>
478
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()}
479
492
  {unit && <Unit config={unit} />}
480
493
  </g>
481
494
  </g>
@@ -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
  }}
@@ -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, width:dragWidth }, margin:{ left, right } }, axes, series, width, top, bandLength
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:barWidth*dragWidth/100,
19
+ width:cBarWidth,
19
20
  display:"flex",
20
21
  justifyContent:"space-between",
21
22
  background:dragColor
@@ -54,23 +55,33 @@ export default memo(forwardRef((props, ref) => {
54
55
  setWorking(true);
55
56
  }
56
57
  // //右手柄的鼠标按下逻辑
57
- // const rightDown=()=>{
58
+ const rightDown=()=>{
58
59
 
59
- // const move=(e)=>{
60
-
61
- // }
62
- // const up=()=>{
63
-
64
- // }
65
- // document.addEventListener()
66
- // }
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
+ }
67
78
  return (
68
79
  <div
69
80
  style={{
70
- width: barWidth,
81
+ width:cWidth,
71
82
  height: height,
72
83
  backgroundColor: color,
73
- transform: `translate(${left}px,${top}px)`,
84
+ transform: `translate(${left}px,${top-height+gap}px)`,
74
85
  }}
75
86
  >
76
87
  <svg width="100%" height="100%">
@@ -430,6 +430,6 @@ export default ({
430
430
  });
431
431
  tmp.get("x") && (tmp.get("x").positions = xAxisPositions);
432
432
  return tmp;
433
- }, [axes]);
433
+ }, [axes, controlInfo]);
434
434
  return _axes;
435
435
  };
@@ -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;
@@ -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,