@easyv/charts 1.4.22 → 1.4.24

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.
Files changed (90) hide show
  1. package/.babelrc +8 -8
  2. package/.husky/commit-msg +3 -3
  3. package/CHANGELOG.md +18 -18
  4. package/commitlint.config.js +1 -1
  5. package/lib/components/AnimateData.js +8 -16
  6. package/lib/components/Axis.js +106 -138
  7. package/lib/components/Background.js +18 -26
  8. package/lib/components/Band.js +105 -91
  9. package/lib/components/BaseLine.js +33 -46
  10. package/lib/components/Brush.js +29 -46
  11. package/lib/components/Carousel.js +13 -40
  12. package/lib/components/CartesianChart.js +291 -112
  13. package/lib/components/Chart.js +23 -36
  14. package/lib/components/ChartContainer.js +21 -29
  15. package/lib/components/ConicalGradient.js +56 -89
  16. package/lib/components/Control.js +65 -0
  17. package/lib/components/ExtentData.js +9 -17
  18. package/lib/components/FilterData.js +16 -27
  19. package/lib/components/Indicator.js +66 -12
  20. package/lib/components/Label.js +128 -118
  21. package/lib/components/Legend.js +41 -66
  22. package/lib/components/Lighter.js +21 -50
  23. package/lib/components/Line.js +39 -59
  24. package/lib/components/LinearGradient.js +16 -22
  25. package/lib/components/Mapping.js +9 -34
  26. package/lib/components/Marquee.js +14 -30
  27. package/lib/components/PieChart.js +311 -405
  28. package/lib/components/StackData.js +8 -18
  29. package/lib/components/StereoBar.js +65 -105
  30. package/lib/components/TextOverflow.js +8 -21
  31. package/lib/components/Tooltip.js +41 -55
  32. package/lib/components/index.js +7 -27
  33. package/lib/context/index.js +0 -2
  34. package/lib/css/index.module.css +42 -42
  35. package/lib/css/piechart.module.css +26 -26
  36. package/lib/element/ConicGradient.js +29 -35
  37. package/lib/element/Line.js +9 -13
  38. package/lib/element/index.js +0 -2
  39. package/lib/formatter/index.js +0 -2
  40. package/lib/formatter/legend.js +30 -41
  41. package/lib/hooks/index.js +0 -9
  42. package/lib/hooks/useAiData.js +12 -20
  43. package/lib/hooks/useAnimateData.js +8 -21
  44. package/lib/hooks/useAxes.js +69 -115
  45. package/lib/hooks/useCarouselAxisX.js +47 -68
  46. package/lib/hooks/useExtentData.js +14 -46
  47. package/lib/hooks/useFilterData.js +13 -34
  48. package/lib/hooks/useStackData.js +12 -35
  49. package/lib/hooks/useTooltip.js +37 -54
  50. package/lib/index.js +0 -15
  51. package/lib/utils/index.js +95 -247
  52. package/package.json +55 -55
  53. package/src/components/Axis.tsx +223 -183
  54. package/src/components/Background.tsx +61 -61
  55. package/src/components/Band.tsx +274 -239
  56. package/src/components/Brush.js +159 -159
  57. package/src/components/CartesianChart.js +319 -43
  58. package/src/components/Chart.js +99 -99
  59. package/src/components/ChartContainer.tsx +71 -64
  60. package/src/components/ConicalGradient.js +258 -258
  61. package/src/components/Control.jsx +51 -0
  62. package/src/components/ExtentData.js +17 -17
  63. package/src/components/Indicator.js +61 -13
  64. package/src/components/Label.js +275 -242
  65. package/src/components/Legend.js +165 -165
  66. package/src/components/Lighter.jsx +173 -173
  67. package/src/components/Line.js +150 -150
  68. package/src/components/LinearGradient.js +29 -29
  69. package/src/components/PieChart.js +7 -3
  70. package/src/components/StereoBar.tsx +307 -307
  71. package/src/components/index.js +57 -55
  72. package/src/context/index.js +2 -2
  73. package/src/css/index.module.css +42 -42
  74. package/src/css/piechart.module.css +26 -26
  75. package/src/element/ConicGradient.jsx +55 -55
  76. package/src/element/Line.tsx +33 -33
  77. package/src/element/index.ts +3 -3
  78. package/src/formatter/index.js +1 -1
  79. package/src/formatter/legend.js +92 -92
  80. package/src/hooks/index.js +20 -20
  81. package/src/hooks/useAnimateData.ts +67 -67
  82. package/src/hooks/useAxes.js +9 -2
  83. package/src/hooks/useCarouselAxisX.js +35 -18
  84. package/src/hooks/useFilterData.js +72 -72
  85. package/src/hooks/useStackData.js +101 -101
  86. package/src/hooks/useTooltip.ts +100 -100
  87. package/src/index.js +6 -6
  88. package/src/types/index.d.ts +67 -67
  89. package/src/utils/index.js +757 -757
  90. package/tsconfig.json +23 -23
@@ -1,37 +1,23 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  var _typeof = require("@babel/runtime/helpers/typeof");
6
-
7
5
  Object.defineProperty(exports, "__esModule", {
8
6
  value: true
9
7
  });
10
8
  exports["default"] = void 0;
11
-
12
9
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
13
-
14
10
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
15
-
16
11
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
17
-
18
12
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
19
-
20
13
  var _react = _interopRequireWildcard(require("react"));
21
-
22
14
  var _d3v = require("d3v7");
23
-
24
15
  var _excluded = ["animation"],
25
- _excluded2 = ["config", "data"];
26
-
16
+ _excluded2 = ["config", "data"];
27
17
  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); }
28
-
29
18
  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; }
30
-
31
19
  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; }
32
-
33
20
  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; }
34
-
35
21
  var initialState = {
36
22
  currentIndex: null,
37
23
  trigger: ''
@@ -52,29 +38,24 @@ var defaultAnimation = {
52
38
  /**
53
39
  * 饼图类图表轮播逻辑,用来管理currentIndex,及回调逻辑(HOC)
54
40
  */
55
-
56
41
  var _default = function _default(Component) {
57
42
  return /*#__PURE__*/(0, _react.memo)(function (_ref) {
58
43
  var _ref$config = _ref.config,
59
- animation = _ref$config.animation,
60
- config = (0, _objectWithoutProperties2["default"])(_ref$config, _excluded),
61
- _ref$data = _ref.data,
62
- data = _ref$data === void 0 ? [] : _ref$data,
63
- rest = (0, _objectWithoutProperties2["default"])(_ref, _excluded2);
44
+ animation = _ref$config.animation,
45
+ config = (0, _objectWithoutProperties2["default"])(_ref$config, _excluded),
46
+ _ref$data = _ref.data,
47
+ data = _ref$data === void 0 ? [] : _ref$data,
48
+ rest = (0, _objectWithoutProperties2["default"])(_ref, _excluded2);
64
49
  var dataLength = data.length;
65
-
66
50
  var _animation = Object.assign({}, defaultAnimation, animation);
67
-
68
51
  var on = _animation.on,
69
- interval = _animation.interval,
70
- interactive = _animation.interactive,
71
- hoverStop = _animation.hoverStop;
72
-
52
+ interval = _animation.interval,
53
+ interactive = _animation.interactive,
54
+ hoverStop = _animation.hoverStop;
73
55
  var _useState = (0, _react.useState)(on ? carouselState : initialState),
74
- _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
75
- state = _useState2[0],
76
- setState = _useState2[1];
77
-
56
+ _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
57
+ state = _useState2[0],
58
+ setState = _useState2[1];
78
59
  var timer = (0, _react.useRef)(null);
79
60
  var hoverState = (0, _react.useRef)(false);
80
61
  var animationOn = on && interval && dataLength;
@@ -110,8 +91,7 @@ var _default = function _default(Component) {
110
91
  }, [carousel]);
111
92
  var onEvent = (0, _react.useCallback)(function (_ref3) {
112
93
  var currentIndex = _ref3.currentIndex,
113
- type = _ref3.type;
114
-
94
+ type = _ref3.type;
115
95
  switch (interactive) {
116
96
  case true:
117
97
  case 'click':
@@ -123,9 +103,7 @@ var _default = function _default(Component) {
123
103
  currentIndex: currentIndex
124
104
  });
125
105
  }
126
-
127
106
  break;
128
-
129
107
  case 'hover':
130
108
  if (type == 'onMouseEnter') {
131
109
  setState({
@@ -136,13 +114,10 @@ var _default = function _default(Component) {
136
114
  } else if (type == 'onMouseLeave') {
137
115
  !hoverState.current && animationOn && carousel();
138
116
  }
139
-
140
117
  break;
141
-
142
118
  case false:
143
119
  case '':
144
120
  break;
145
-
146
121
  case 'carousel':
147
122
  default:
148
123
  setState({
@@ -159,7 +134,6 @@ var _default = function _default(Component) {
159
134
  timer.current && timer.current.stop();
160
135
  } else {
161
136
  hoverState.current = false;
162
-
163
137
  if (animationOn) {
164
138
  timer.current = (0, _d3v.interval)(function () {
165
139
  setState(function (_ref4) {
@@ -186,5 +160,4 @@ var _default = function _default(Component) {
186
160
  }));
187
161
  });
188
162
  };
189
-
190
163
  exports["default"] = _default;
@@ -1,98 +1,91 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  var _typeof = require("@babel/runtime/helpers/typeof");
6
-
7
5
  Object.defineProperty(exports, "__esModule", {
8
6
  value: true
9
7
  });
10
8
  exports["default"] = void 0;
11
-
12
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
13
-
14
9
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
15
-
16
10
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
17
-
11
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
18
12
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
19
-
20
13
  var _react = _interopRequireWildcard(require("react"));
21
-
22
14
  var _hooks = require("../hooks");
23
-
24
15
  var _context = require("../context");
25
-
26
16
  var _ = require(".");
27
-
17
+ var _utils = require("../utils");
28
18
  var _excluded = ["Component", "yOrZ"],
29
- _excluded2 = ["Component", "yOrZ"];
30
-
19
+ _excluded2 = ["Component", "yOrZ"];
20
+ /**
21
+ * 轴类图表
22
+ */
31
23
  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); }
32
-
33
24
  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
-
35
25
  var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
36
26
  var _ref$config = _ref.config,
37
- axesConfig = _ref$config.axes,
38
- background = _ref$config.background,
39
- _ref$config$chart = _ref$config.chart,
40
- _ref$config$chart$dim = _ref$config$chart.dimension.chartDimension,
41
- height = _ref$config$chart$dim.height,
42
- width = _ref$config$chart$dim.width,
43
- _ref$config$chart$mar = _ref$config$chart.margin,
44
- marginLeft = _ref$config$chart$mar.marginLeft,
45
- marginTop = _ref$config$chart$mar.marginTop,
46
- marginRight = _ref$config$chart$mar.marginRight,
47
- marginBottom = _ref$config$chart$mar.marginBottom,
48
- animation = _ref$config$chart.animation,
49
- legend = _ref$config$chart.legend,
50
- series = _ref$config.series,
51
- bandLength = _ref$config.bandLength,
52
- tooltip = _ref$config.tooltip,
53
- _ref$config$baseLine = _ref$config.baseLine,
54
- _ref$config$baseLine$ = _ref$config$baseLine.orientation,
55
- baseLineOri = _ref$config$baseLine$ === void 0 ? '' : _ref$config$baseLine$,
56
- _ref$config$baseLine$2 = _ref$config$baseLine.config,
57
- baseLineConfig = _ref$config$baseLine$2 === void 0 ? {} : _ref$config$baseLine$2,
58
- _ref$config$baseLine$3 = _ref$config$baseLine.data,
59
- baseLineData = _ref$config$baseLine$3 === void 0 ? [] : _ref$config$baseLine$3,
60
- _ref$config$tooltip = _ref$config.tooltip;
61
- _ref$config$tooltip = _ref$config$tooltip === void 0 ? {} : _ref$config$tooltip;
62
- var _ref$config$tooltip$c = _ref$config$tooltip.config,
63
- tooltipConfig = _ref$config$tooltip$c === void 0 ? {} : _ref$config$tooltip$c,
64
- _ref$config$tooltip$c2 = _ref$config$tooltip.config;
65
- _ref$config$tooltip$c2 = _ref$config$tooltip$c2 === void 0 ? {} : _ref$config$tooltip$c2;
66
- var auto = _ref$config$tooltip$c2.auto,
67
- manual = _ref$config$tooltip$c2.manual,
68
- _ref$config$tooltip$c3 = _ref$config$tooltip$c2.indicator,
69
- indicator = _ref$config$tooltip$c3 === void 0 ? {} : _ref$config$tooltip$c3,
70
- brush = _ref$config.brush,
71
- style = _ref.style,
72
- originData = _ref.originData,
73
- filterData = _ref.filterData,
74
- aiFormatter = _ref.aiFormatter,
75
- id = _ref.id;
27
+ axesConfig = _ref$config.axes,
28
+ background = _ref$config.background,
29
+ _ref$config$chart = _ref$config.chart,
30
+ _ref$config$chart$dim = _ref$config$chart.dimension.chartDimension,
31
+ height = _ref$config$chart$dim.height,
32
+ width = _ref$config$chart$dim.width,
33
+ _ref$config$chart$mar = _ref$config$chart.margin,
34
+ marginLeft = _ref$config$chart$mar.marginLeft,
35
+ marginTop = _ref$config$chart$mar.marginTop,
36
+ marginRight = _ref$config$chart$mar.marginRight,
37
+ marginBottom = _ref$config$chart$mar.marginBottom,
38
+ animation = _ref$config$chart.animation,
39
+ legend = _ref$config$chart.legend,
40
+ series = _ref$config.series,
41
+ bandLength = _ref$config.bandLength,
42
+ tooltip = _ref$config.tooltip,
43
+ _ref$config$baseLine = _ref$config.baseLine,
44
+ _ref$config$baseLine$ = _ref$config$baseLine.orientation,
45
+ baseLineOri = _ref$config$baseLine$ === void 0 ? "" : _ref$config$baseLine$,
46
+ _ref$config$baseLine$2 = _ref$config$baseLine.config,
47
+ baseLineConfig = _ref$config$baseLine$2 === void 0 ? {} : _ref$config$baseLine$2,
48
+ _ref$config$baseLine$3 = _ref$config$baseLine.data,
49
+ baseLineData = _ref$config$baseLine$3 === void 0 ? [] : _ref$config$baseLine$3,
50
+ _ref$config$tooltip = _ref$config.tooltip,
51
+ _ref$config$tooltip2 = _ref$config$tooltip === void 0 ? {} : _ref$config$tooltip,
52
+ _ref$config$tooltip2$ = _ref$config$tooltip2.config,
53
+ tooltipConfig = _ref$config$tooltip2$ === void 0 ? {} : _ref$config$tooltip2$,
54
+ _ref$config$tooltip2$2 = _ref$config$tooltip2.config,
55
+ _ref$config$tooltip2$3 = _ref$config$tooltip2$2 === void 0 ? {} : _ref$config$tooltip2$2,
56
+ auto = _ref$config$tooltip2$3.auto,
57
+ manual = _ref$config$tooltip2$3.manual,
58
+ _ref$config$tooltip2$4 = _ref$config$tooltip2$3.indicator,
59
+ indicator = _ref$config$tooltip2$4 === void 0 ? {} : _ref$config$tooltip2$4,
60
+ brush = _ref$config.brush,
61
+ _ref$config$isControl = _ref$config.isControlChart,
62
+ isControlChart = _ref$config$isControl === void 0 ? false : _ref$config$isControl,
63
+ _ref$config$control = _ref$config.control,
64
+ control = _ref$config$control === void 0 ? null : _ref$config$control,
65
+ style = _ref.style,
66
+ originData = _ref.originData,
67
+ filterData = _ref.filterData,
68
+ aiFormatter = _ref.aiFormatter,
69
+ id = _ref.id;
76
70
  var context = (0, _react.useContext)(_context.chartContext);
77
-
78
71
  var _useState = (0, _react.useState)(false),
79
- _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
80
- isHover = _useState2[0],
81
- setIsHover = _useState2[1];
82
-
72
+ _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
73
+ isHover = _useState2[0],
74
+ setIsHover = _useState2[1];
83
75
  var _useContext = (0, _react.useContext)(_context.chartContext),
84
- chartWidth = _useContext.width,
85
- chartHeight = _useContext.height,
86
- triggerOnRelative = _useContext.triggerOnRelative,
87
- onEmit = _useContext.onEmit;
88
-
76
+ chartWidth = _useContext.width,
77
+ chartHeight = _useContext.height,
78
+ triggerOnRelative = _useContext.triggerOnRelative,
79
+ onEmit = _useContext.onEmit;
89
80
  var svg = (0, _react.useRef)();
90
81
  var axes = (0, _hooks.useAxes)({
91
82
  axes: axesConfig,
92
- context: context
83
+ context: context,
84
+ isControlChart: isControlChart,
85
+ control: control
93
86
  });
94
87
  var aiData = aiFormatter ? aiFormatter(originData, axes, series) : (0, _hooks.useAiData)(originData, axes, series);
95
- var axisX = (0, _hooks.useCarouselAxisX)(axes.get('x'), animation, isHover);
88
+ var axisX = (0, _hooks.useCarouselAxisX)(axes.get("x"), animation, isHover, isControlChart, control);
96
89
  var xLineRange = width - marginLeft - marginRight;
97
90
  var yLineRange = height - marginTop - marginBottom;
98
91
  (0, _react.useEffect)(function () {
@@ -100,40 +93,36 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
100
93
  if (!window.aiData) {
101
94
  window.aiData = {};
102
95
  }
103
-
104
96
  window.aiData[id] = {
105
97
  getAI: function getAI() {
106
98
  return aiData;
107
99
  }
108
100
  };
109
101
  }
110
-
111
102
  return function () {
112
103
  window.aiData && window.aiData[id] && delete window.aiData[id];
113
104
  };
114
105
  }, [JSON.stringify(aiData), id]);
115
-
116
106
  var _useTooltip = (0, _hooks.useTooltip)({
117
- svg: svg,
118
- marginLeft: marginLeft,
119
- marginTop: marginTop,
120
- width: chartWidth,
121
- height: chartHeight,
122
- axisX: axisX,
123
- isHover: isHover,
124
- config: tooltipConfig
125
- }),
126
- tooltipX = _useTooltip.x,
127
- tickName = _useTooltip.name,
128
- setIndex = _useTooltip.setIndex;
129
-
107
+ svg: svg,
108
+ marginLeft: marginLeft,
109
+ marginTop: marginTop,
110
+ width: chartWidth,
111
+ height: chartHeight,
112
+ axisX: axisX,
113
+ isHover: isHover,
114
+ config: tooltipConfig
115
+ }),
116
+ tooltipX = _useTooltip.x,
117
+ tickName = _useTooltip.name,
118
+ setIndex = _useTooltip.setIndex;
130
119
  var tooltipData = (0, _react.useMemo)(function () {
131
120
  return tickName !== undefined && originData.filter(function (d) {
132
121
  return d.x === tickName;
133
122
  });
134
123
  }, [tickName, originData]);
135
124
  var showTooltip = !!(tooltipData && tooltipData.length && (auto || manual));
136
- var isVertical = axisX.direction === 'vertical';
125
+ var isVertical = axisX.direction === "vertical";
137
126
  var indicatorWidth = indicator.width * axisX.step / 100;
138
127
  var position = axisX.scaler(tickName) - indicatorWidth / 2;
139
128
  var indicatorAttr = isVertical ? {
@@ -148,12 +137,154 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
148
137
  var onInteraction = (0, _react.useCallback)(function (e) {
149
138
  e.stopPropagation();
150
139
  var data = e.currentTarget.dataset.data;
151
-
152
140
  var _data = JSON.parse(data);
153
-
154
141
  triggerOnRelative(_data);
155
- onEmit('click', _data);
142
+ onEmit("click", _data);
156
143
  }, [triggerOnRelative, onEmit]);
144
+
145
+ /**
146
+ * 控制图相关
147
+ */
148
+ var controlEl = (0, _react.useRef)();
149
+ var seriesEl = (0, _react.useRef)(null);
150
+ var axisElList = (0, _react.useRef)([]);
151
+ var curControlPercent = (0, _react.useRef)(0);
152
+ (0, _react.useEffect)(function () {
153
+ if (controlEl.current && isControlChart) {
154
+ var isDragging = false;
155
+ var movementX = 0;
156
+ var rawTranslateX = 0;
157
+ var percent = 0;
158
+ var controlWidth = xLineRange * control.drag.width / 100;
159
+ var range = function range(num) {
160
+ var _num = num;
161
+ var min = 0;
162
+ var max = xLineRange - controlWidth;
163
+ _num = Math.max(_num, min);
164
+ _num = Math.min(_num, max);
165
+ return _num;
166
+ };
167
+ var setControlTranslate = function setControlTranslate(x) {
168
+ var moveLen = range(x);
169
+ controlEl.current.style.transform = "translateX(".concat(moveLen, "px)");
170
+ //计算出当前位移的百分比
171
+ percent = moveLen / (xLineRange - controlWidth);
172
+ curControlPercent.current = percent;
173
+ seriesEl.current.style.transform = "translate(".concat(-(axisX.controlEnd - axisX.end) * percent, "px,").concat(marginTop, "px)");
174
+ axisElList.current[2].style.transform = "translate(".concat(-(axisX.controlEnd - axisX.end) * percent, "px,", 0, "px)");
175
+ };
176
+ var mouseDownHandle = function mouseDownHandle(e) {
177
+ var mouseMoveHandle = function mouseMoveHandle(e) {
178
+ //当前位移的距离
179
+ if (isDragging) {
180
+ movementX += e.movementX;
181
+ setControlTranslate(movementX + rawTranslateX);
182
+ }
183
+ };
184
+ var mouseUpHandle = function mouseUpHandle(e) {
185
+ rawTranslateX = range(movementX + rawTranslateX);
186
+ movementX = 0;
187
+ isDragging = false;
188
+ document.removeEventListener("mousemove", mouseMoveHandle);
189
+ document.removeEventListener("mouseup", mouseUpHandle);
190
+ };
191
+ document.addEventListener("mousemove", mouseMoveHandle);
192
+ document.addEventListener("mouseup", mouseUpHandle);
193
+ isDragging = true;
194
+ };
195
+ var animationHoverStop;
196
+ var setAnimationHoverStopTrue = function setAnimationHoverStopTrue() {
197
+ animationHoverStop = true;
198
+ };
199
+ var setAnimationHoverStopFalse = function setAnimationHoverStopFalse() {
200
+ animationHoverStop = false;
201
+ };
202
+ svg.current.addEventListener("mouseenter", setAnimationHoverStopTrue);
203
+ svg.current.addEventListener("mouseleave", setAnimationHoverStopFalse);
204
+
205
+ //控制图轮播动画逻辑
206
+ var show = animation.show,
207
+ duration = animation.duration,
208
+ interval = animation.interval,
209
+ hover = animation.hover;
210
+ var times = Math.floor(xLineRange / controlWidth);
211
+ var animatePos = [];
212
+ for (var i = 0; i <= times; i++) {
213
+ if (i * controlWidth <= xLineRange) {
214
+ animatePos.push(i * controlWidth);
215
+ } else {
216
+ animatePos.push(xLineRange - controlWidth);
217
+ }
218
+ }
219
+ var index = 0;
220
+ var animationId;
221
+ if (animation.show) {
222
+ var initTime, timeGap;
223
+ var _animation = function _animation(timestamp) {
224
+ if (!initTime) {
225
+ initTime = timestamp;
226
+ }
227
+ if (animationHoverStop && hover) {
228
+ initTime = timestamp - timeGap;
229
+ }
230
+ timeGap = timestamp - initTime;
231
+ if (timeGap < (interval + duration) * 1000) {
232
+ if (timeGap < duration * 1000) {
233
+ var p = timeGap / (duration * 1000);
234
+ var nextIndex = index + 1;
235
+ var v;
236
+ if (nextIndex < animatePos.length) {
237
+ v = p * (animatePos[nextIndex] - animatePos[index]) + animatePos[index];
238
+ } else {
239
+ nextIndex = 0;
240
+ v = (1 - p) * animatePos[index];
241
+ }
242
+ setControlTranslate(v);
243
+ }
244
+ animationId = window.requestAnimationFrame(_animation);
245
+ } else {
246
+ index = index < times ? index + 1 : 0;
247
+ initTime = 0;
248
+ animationId = window.requestAnimationFrame(_animation);
249
+ }
250
+ };
251
+ animationId = window.requestAnimationFrame(_animation);
252
+ }
253
+ controlEl.current.addEventListener("mousedown", mouseDownHandle);
254
+ return function () {
255
+ controlEl.current.removeEventListener("mousedown", mouseDownHandle);
256
+ svg.current.removeEventListener("mouseenter", setAnimationHoverStopTrue);
257
+ svg.current.removeEventListener("mouseleave", setAnimationHoverStopFalse);
258
+ window.cancelAnimationFrame(animationId);
259
+ };
260
+ }
261
+ }, [JSON.stringify(animation), control]);
262
+ var _useState3 = (0, _react.useState)(false),
263
+ _useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
264
+ controlChartTooltipShow = _useState4[0],
265
+ setControlChartTooltipShow = _useState4[1];
266
+ var _useState5 = (0, _react.useState)(undefined),
267
+ _useState6 = (0, _slicedToArray2["default"])(_useState5, 2),
268
+ controlChartTooltipXName = _useState6[0],
269
+ setControlChartTooltipXName = _useState6[1];
270
+ var _useState7 = (0, _react.useState)(undefined),
271
+ _useState8 = (0, _slicedToArray2["default"])(_useState7, 2),
272
+ controlChartTooltipX = _useState8[0],
273
+ setControlChartTooltipX = _useState8[1];
274
+ var controlChartTooltipData = (0, _react.useMemo)(function () {
275
+ return controlChartTooltipXName !== undefined && originData.filter(function (d) {
276
+ return d.x === controlChartTooltipXName;
277
+ });
278
+ }, [controlChartTooltipXName, originData]);
279
+ var _useState9 = (0, _react.useState)(axisX.ticks.map(function (tick) {
280
+ return {
281
+ tick: tick,
282
+ isShow: false
283
+ };
284
+ })),
285
+ _useState10 = (0, _slicedToArray2["default"])(_useState9, 2),
286
+ controlChartIndicatorList = _useState10[0],
287
+ setControlChartIndicatorList = _useState10[1];
157
288
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_.ChartContainer, {
158
289
  style: style,
159
290
  width: width,
@@ -163,7 +294,6 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
163
294
  onMouseEnter: function onMouseEnter() {
164
295
  setIsHover(true);
165
296
  },
166
- onMouseMove: setIndex,
167
297
  onMouseLeave: function onMouseLeave(e) {
168
298
  setIsHover(false);
169
299
  setIndex(e);
@@ -182,7 +312,33 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
182
312
  axis: axisX,
183
313
  config: background,
184
314
  bandLength: bandLength
185
- }))), showTooltip && /*#__PURE__*/_react["default"].createElement(_.Indicator, (0, _extends2["default"])({}, indicator, indicatorAttr)), /*#__PURE__*/_react["default"].createElement("foreignObject", {
315
+ }))), (0, _toConsumableArray2["default"])(axes.values()).reverse().map(function (item, index) {
316
+ var config = item.axisType == "x" ? axisX : item;
317
+ return /*#__PURE__*/_react["default"].createElement(_.Axis, (0, _extends2["default"])({
318
+ ref: function ref(d) {
319
+ axisElList.current[index] = d;
320
+ },
321
+ triggerClick: onInteraction,
322
+ xLineRange: xLineRange,
323
+ yLineRange: yLineRange,
324
+ isControlChart: isControlChart,
325
+ controlConfig: control
326
+ }, config, {
327
+ key: index
328
+ }));
329
+ }), isControlChart && control && /*#__PURE__*/_react["default"].createElement(_.Control, {
330
+ ref: controlEl,
331
+ props: {
332
+ control: control,
333
+ axes: axes,
334
+ series: series,
335
+ xLineRange: xLineRange,
336
+ yLineRange: yLineRange,
337
+ marginTop: marginTop,
338
+ axisX: axisX,
339
+ bandLength: bandLength
340
+ }
341
+ }), showTooltip && !isControlChart && /*#__PURE__*/_react["default"].createElement(_.Indicator, (0, _extends2["default"])({}, indicator, indicatorAttr)), /*#__PURE__*/_react["default"].createElement("foreignObject", {
186
342
  style: isVertical ? {
187
343
  width: xLineRange + marginRight + marginLeft,
188
344
  height: yLineRange,
@@ -190,34 +346,57 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
190
346
  } : {
191
347
  width: xLineRange,
192
348
  height: yLineRange + marginTop + marginBottom,
193
- transform: "translateY(".concat(-marginTop, "px)") // overflow:'visible'
194
- // paddingTop:marginTop
195
-
349
+ transform: "translateY(".concat(-marginTop, "px)")
196
350
  }
197
351
  }, /*#__PURE__*/_react["default"].createElement("svg", {
198
352
  width: "100%",
199
353
  height: "100%",
354
+ ref: seriesEl,
200
355
  style: {
201
356
  overflow: "visible",
202
357
  transform: isVertical ? "translateX(".concat(marginRight, "px)") : "translateY(".concat(marginTop, "px)")
203
358
  }
204
- }, series.map(function (_ref2, index) {
359
+ }, /*#__PURE__*/_react["default"].createElement("g", null, isControlChart && controlChartIndicatorList.map(function (item, index) {
360
+ var x = axisX.scaler(item.tick);
361
+ return /*#__PURE__*/_react["default"].createElement(_.Indicator, (0, _extends2["default"])({
362
+ key: index
363
+ }, indicator, {
364
+ height: chartHeight,
365
+ width: indicatorWidth,
366
+ x: x - indicatorWidth / 2,
367
+ isControlChart: isControlChart,
368
+ xName: item.tick,
369
+ setControlChartTooltipXName: setControlChartTooltipXName,
370
+ setControlChartTooltipX: setControlChartTooltipX,
371
+ setControlChartTooltipShow: setControlChartTooltipShow,
372
+ controlChartIndicatorList: controlChartIndicatorList,
373
+ setControlChartIndicatorList: setControlChartIndicatorList
374
+ }));
375
+ })), series.map(function (_ref2, index) {
205
376
  var Component = _ref2.Component,
206
- yOrZ = _ref2.yOrZ,
207
- config = (0, _objectWithoutProperties2["default"])(_ref2, _excluded);
377
+ yOrZ = _ref2.yOrZ,
378
+ config = (0, _objectWithoutProperties2["default"])(_ref2, _excluded);
208
379
  var yAxis = axes.get(yOrZ);
209
380
  return yAxis && Component && /*#__PURE__*/_react["default"].createElement(Component, (0, _extends2["default"])({
210
381
  key: index
211
382
  }, config, {
212
383
  bandLength: bandLength,
213
384
  xAxis: axisX,
214
- yAxis: yAxis,
215
- triggerClick: onInteraction
385
+ yAxis: yAxis
386
+ // 控制图部分,主要是为了,当鼠标悬浮在指示器上时,显示对应的tooltip
387
+ ,
388
+ isControlChart: isControlChart,
389
+ setControlChartTooltipXName: setControlChartTooltipXName,
390
+ setControlChartTooltipX: setControlChartTooltipX,
391
+ setControlChartTooltipShow: setControlChartTooltipShow,
392
+ indicatorWidth: indicatorWidth,
393
+ triggerClick: onInteraction,
394
+ setControlChartIndicatorList: setControlChartIndicatorList
216
395
  }));
217
396
  }), series.map(function (_ref3, index) {
218
397
  var Component = _ref3.Component,
219
- yOrZ = _ref3.yOrZ,
220
- config = (0, _objectWithoutProperties2["default"])(_ref3, _excluded2);
398
+ yOrZ = _ref3.yOrZ,
399
+ config = (0, _objectWithoutProperties2["default"])(_ref3, _excluded2);
221
400
  var yAxis = axes.get(yOrZ);
222
401
  return yAxis && /*#__PURE__*/_react["default"].createElement(_.Label, (0, _extends2["default"])({
223
402
  key: index
@@ -227,16 +406,7 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
227
406
  yAxis: yAxis,
228
407
  triggerClick: onInteraction
229
408
  }));
230
- }))), (0, _toConsumableArray2["default"])(axes.values()).reverse().map(function (item, index) {
231
- var config = item.axisType == 'x' ? axisX : item;
232
- return /*#__PURE__*/_react["default"].createElement(_.Axis, (0, _extends2["default"])({
233
- triggerClick: onInteraction,
234
- xLineRange: xLineRange,
235
- yLineRange: yLineRange
236
- }, config, {
237
- key: index
238
- }));
239
- }), baseLineData && baseLineData.length > 0 && baseLineData.map(function (item, index) {
409
+ }))), baseLineData && baseLineData.length > 0 && baseLineData.map(function (item, index) {
240
410
  var yOrZ = baseLineConfig[index].line.yOrZ;
241
411
  var yAxis = axes.get(yOrZ);
242
412
  return yAxis && /*#__PURE__*/_react["default"].createElement(_.BaseLine, {
@@ -253,7 +423,7 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
253
423
  })), /*#__PURE__*/_react["default"].createElement(_.Legend, (0, _extends2["default"])({}, legend, {
254
424
  filterData: filterData,
255
425
  series: series
256
- })), showTooltip && /*#__PURE__*/_react["default"].createElement(_.Tooltip, (0, _extends2["default"])({
426
+ })), showTooltip && !isControlChart && /*#__PURE__*/_react["default"].createElement(_.Tooltip, (0, _extends2["default"])({
257
427
  isVertical: isVertical
258
428
  }, tooltip, {
259
429
  data: tooltipData,
@@ -264,12 +434,21 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
264
434
  series: series,
265
435
  width: width,
266
436
  height: height
437
+ })), controlChartTooltipShow && isControlChart && /*#__PURE__*/_react["default"].createElement(_.Tooltip, (0, _extends2["default"])({
438
+ isVertical: isVertical
439
+ }, tooltip, {
440
+ data: controlChartTooltipData,
441
+ x: controlChartTooltipX - (axisX.controlEnd - axisX.end) * curControlPercent.current,
442
+ marginLeft: marginLeft,
443
+ marginTop: marginTop,
444
+ tickName: controlChartTooltipXName,
445
+ series: series,
446
+ width: width,
447
+ height: height
267
448
  })), brush && /*#__PURE__*/_react["default"].createElement(_.Brush, {
268
449
  config: brush,
269
450
  width: width
270
451
  }));
271
452
  });
272
-
273
453
  var _default = (0, _.Mapping)((0, _.FilterData)((0, _.ExtentData)((0, _.AnimateData)((0, _.StackData)(Chart)))));
274
-
275
454
  exports["default"] = _default;