@easyv/charts 1.4.24 → 1.4.25

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 (89) 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 +16 -8
  6. package/lib/components/Axis.js +133 -86
  7. package/lib/components/Background.js +26 -18
  8. package/lib/components/Band.js +98 -72
  9. package/lib/components/BaseLine.js +46 -33
  10. package/lib/components/Brush.js +46 -29
  11. package/lib/components/Carousel.js +40 -13
  12. package/lib/components/CartesianChart.js +146 -98
  13. package/lib/components/Chart.js +36 -23
  14. package/lib/components/ChartContainer.js +27 -18
  15. package/lib/components/ConicalGradient.js +89 -56
  16. package/lib/components/Control.js +28 -12
  17. package/lib/components/ExtentData.js +17 -9
  18. package/lib/components/FilterData.js +27 -16
  19. package/lib/components/Indicator.js +30 -23
  20. package/lib/components/Label.js +126 -96
  21. package/lib/components/Legend.js +66 -41
  22. package/lib/components/Lighter.js +50 -21
  23. package/lib/components/Line.js +59 -39
  24. package/lib/components/LinearGradient.js +22 -16
  25. package/lib/components/Mapping.js +34 -9
  26. package/lib/components/Marquee.js +31 -15
  27. package/lib/components/PieChart.js +405 -311
  28. package/lib/components/StackData.js +18 -8
  29. package/lib/components/StereoBar.js +105 -65
  30. package/lib/components/TextOverflow.js +21 -8
  31. package/lib/components/Tooltip.js +55 -41
  32. package/lib/components/index.js +28 -0
  33. package/lib/context/index.js +2 -0
  34. package/lib/css/index.module.css +42 -42
  35. package/lib/css/piechart.module.css +26 -26
  36. package/lib/element/ConicGradient.js +35 -29
  37. package/lib/element/Line.js +13 -9
  38. package/lib/element/index.js +2 -0
  39. package/lib/formatter/index.js +2 -0
  40. package/lib/formatter/legend.js +41 -30
  41. package/lib/hooks/index.js +9 -0
  42. package/lib/hooks/useAiData.js +20 -12
  43. package/lib/hooks/useAnimateData.js +21 -8
  44. package/lib/hooks/useAxes.js +117 -67
  45. package/lib/hooks/useCarouselAxisX.js +60 -27
  46. package/lib/hooks/useExtentData.js +46 -14
  47. package/lib/hooks/useFilterData.js +34 -13
  48. package/lib/hooks/useStackData.js +35 -12
  49. package/lib/hooks/useTooltip.js +53 -36
  50. package/lib/index.js +15 -0
  51. package/lib/utils/index.js +247 -95
  52. package/package.json +55 -55
  53. package/src/components/Background.tsx +61 -61
  54. package/src/components/Band.tsx +274 -274
  55. package/src/components/Brush.js +159 -159
  56. package/src/components/CartesianChart.js +1 -1
  57. package/src/components/Chart.js +99 -99
  58. package/src/components/ChartContainer.tsx +71 -71
  59. package/src/components/ConicalGradient.js +258 -258
  60. package/src/components/Control.jsx +51 -51
  61. package/src/components/ExtentData.js +17 -17
  62. package/src/components/Indicator.js +61 -61
  63. package/src/components/Label.js +275 -275
  64. package/src/components/Legend.js +165 -165
  65. package/src/components/Lighter.jsx +173 -173
  66. package/src/components/Line.js +150 -150
  67. package/src/components/LinearGradient.js +29 -29
  68. package/src/components/Marquee.tsx +1 -1
  69. package/src/components/PieChart.js +3 -7
  70. package/src/components/StereoBar.tsx +307 -307
  71. package/src/components/index.js +57 -57
  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/useCarouselAxisX.js +1 -1
  83. package/src/hooks/useFilterData.js +72 -72
  84. package/src/hooks/useStackData.js +101 -101
  85. package/src/hooks/useTooltip.ts +100 -100
  86. package/src/index.js +6 -6
  87. package/src/types/index.d.ts +67 -67
  88. package/src/utils/index.js +757 -757
  89. package/tsconfig.json +23 -23
@@ -1,54 +1,75 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
4
5
  Object.defineProperty(exports, "__esModule", {
5
6
  value: true
6
7
  });
7
8
  exports["default"] = void 0;
9
+
8
10
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+
9
12
  var _react = require("react");
13
+
10
14
  var _d3Scale = require("d3-scale");
15
+
11
16
  var _utils = require("../utils");
17
+
12
18
  var _utils2 = require("@easyv/utils/lib/common/utils");
19
+
13
20
  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; }
21
+
14
22
  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; }
23
+
15
24
  var getCount = function getCount(num) {
16
25
  var i = 0,
17
- num_ = Math.abs(num);
26
+ num_ = Math.abs(num);
18
27
  if (num_ < 1) return i;
28
+
19
29
  while (num_ > 10) {
20
30
  i++;
21
31
  num_ = Math.floor(num_ / 10);
22
32
  }
33
+
23
34
  return i;
24
35
  };
36
+
25
37
  var getNewDomain = function getNewDomain(domain, mode, step) {
26
38
  var newDomain = [];
27
39
  var min = domain[0],
28
- max = domain[1];
40
+ max = domain[1];
29
41
  var minCount = Math.pow(10, getCount(min)),
30
- maxCount = Math.pow(10, getCount(max));
42
+ maxCount = Math.pow(10, getCount(max));
43
+
31
44
  switch (mode) {
32
45
  case "count":
33
46
  newDomain[0] = Math.floor(domain[0] / minCount) * minCount;
34
47
  newDomain[1] = Math.ceil(domain[1] / maxCount) * maxCount;
35
48
  break;
49
+
36
50
  case "step":
37
51
  newDomain = [domain[0], domain[0]];
52
+
38
53
  while (newDomain[1] < domain[1]) {
39
54
  newDomain[1] += step;
40
55
  }
56
+
41
57
  }
58
+
42
59
  return newDomain;
43
60
  };
61
+
44
62
  var getTickCount = function getTickCount(domain, count, decimal) {
45
63
  var multiple = Math.pow(10, decimal);
46
64
  var gap = domain[1] * multiple - domain[0] * multiple;
65
+
47
66
  if (gap < count) {
48
67
  return Math.max(2, 1 + gap);
49
68
  }
69
+
50
70
  return count;
51
71
  };
72
+
52
73
  var scales = {
53
74
  linear: _d3Scale.scaleLinear,
54
75
  log: _d3Scale.scaleLog,
@@ -56,54 +77,54 @@ var scales = {
56
77
  utc: _d3Scale.scaleUtc,
57
78
  ordinal: _utils.band
58
79
  };
59
-
60
80
  /**
61
81
  * x/y/z轴
62
82
  * @param {Array} axes 轴列表数组
63
83
  * @param {Object} context 其中需要包括
64
84
  * @returns {Map} 返回所有轴
65
85
  */
86
+
66
87
  var _default = function _default(_ref) {
67
88
  var axes = _ref.axes,
68
- _ref$context = _ref.context,
69
- width = _ref$context.width,
70
- height = _ref$context.height,
71
- isControlChart = _ref.isControlChart,
72
- controlConfig = _ref.control;
89
+ _ref$context = _ref.context,
90
+ width = _ref$context.width,
91
+ height = _ref$context.height,
92
+ isControlChart = _ref.isControlChart,
93
+ controlConfig = _ref.control;
94
+
73
95
  var _axes = (0, _react.useMemo)(function () {
74
96
  var tmp = new Map();
75
97
  var xAxisPositions = [];
76
98
  axes.forEach(function (item) {
77
99
  var _item$config$label = item.config.label,
78
- _item$config$label$sh = _item$config$label.showLast,
79
- showLast = _item$config$label$sh === void 0 ? false : _item$config$label$sh,
80
- _item$config$label$de = _item$config$label.decimal,
81
- decimal = _item$config$label$de === void 0 ? 0 : _item$config$label$de,
82
- type = item.type,
83
- orientation = item.orientation,
84
- ticks = item.ticks,
85
- _item$tickCount = item.tickCount,
86
- count = _item$tickCount === void 0 ? 1 : _item$tickCount,
87
- _item$step = item.step,
88
- step = _item$step === void 0 ? 1 : _item$step,
89
- domain = item.domain,
90
- axisType = item.axisType,
91
- _item$paddingOuter = item.paddingOuter,
92
- paddingOuter = _item$paddingOuter === void 0 ? 0 : _item$paddingOuter,
93
- auto = item.auto,
94
- mode = item.mode,
95
- carousel = item.carousel,
96
- config = item.config,
97
- isClipAxis = item.isClipAxis,
98
- bottomClipAxisCount = item.bottomClipAxisCount,
99
- topClipAxisCount = item.topClipAxisCount,
100
- bottomClipAxisStep = item.bottomClipAxisStep,
101
- topClipAxisStep = item.topClipAxisStep,
102
- clipValue = item.clipValue,
103
- clipPosition = item.clipPosition,
104
- clipDifferenceValue = item.clipDifferenceValue,
105
- clipAxisMode = item.clipAxisMode;
106
- //如果是断轴类型,输出一套完全不同的values
100
+ _item$config$label$sh = _item$config$label.showLast,
101
+ showLast = _item$config$label$sh === void 0 ? false : _item$config$label$sh,
102
+ _item$config$label$de = _item$config$label.decimal,
103
+ decimal = _item$config$label$de === void 0 ? 0 : _item$config$label$de,
104
+ type = item.type,
105
+ orientation = item.orientation,
106
+ ticks = item.ticks,
107
+ _item$tickCount = item.tickCount,
108
+ count = _item$tickCount === void 0 ? 1 : _item$tickCount,
109
+ _item$step = item.step,
110
+ step = _item$step === void 0 ? 1 : _item$step,
111
+ domain = item.domain,
112
+ axisType = item.axisType,
113
+ _item$paddingOuter = item.paddingOuter,
114
+ paddingOuter = _item$paddingOuter === void 0 ? 0 : _item$paddingOuter,
115
+ auto = item.auto,
116
+ mode = item.mode,
117
+ carousel = item.carousel,
118
+ config = item.config,
119
+ isClipAxis = item.isClipAxis,
120
+ bottomClipAxisCount = item.bottomClipAxisCount,
121
+ topClipAxisCount = item.topClipAxisCount,
122
+ bottomClipAxisStep = item.bottomClipAxisStep,
123
+ topClipAxisStep = item.topClipAxisStep,
124
+ clipValue = item.clipValue,
125
+ clipPosition = item.clipPosition,
126
+ clipDifferenceValue = item.clipDifferenceValue,
127
+ clipAxisMode = item.clipAxisMode; //如果是断轴类型,输出一套完全不同的values
107
128
 
108
129
  /**
109
130
  * 获取轴的:朝向direction,起点位置start,终点位置end
@@ -113,10 +134,13 @@ var _default = function _default(_ref) {
113
134
  * @param {*} paddingOuter
114
135
  * @returns {start,end,direction}
115
136
  */
137
+
116
138
  function getChartsConfig(orientation, width, height, paddingOuter) {
117
139
  var direction = orientation === "top" || orientation === "bottom" ? "horizontal" : orientation === "left" || orientation === "right" ? "vertical" : "";
118
140
  var length = direction === "horizontal" ? width : direction === "vertical" ? height : 0;
141
+
119
142
  var _paddingOuter = paddingOuter * length;
143
+
120
144
  var start = _paddingOuter / 2;
121
145
  var end = length - start;
122
146
  return {
@@ -127,7 +151,6 @@ var _default = function _default(_ref) {
127
151
  _paddingOuter: _paddingOuter
128
152
  };
129
153
  }
130
-
131
154
  /**
132
155
  * 设置scaler
133
156
  * @param {*} scales
@@ -136,14 +159,16 @@ var _default = function _default(_ref) {
136
159
  * @param {*} range 屏幕坐标的范围
137
160
  * @returns
138
161
  */
162
+
163
+
139
164
  function setScaler(scales, type, domain, range) {
140
165
  //比例将抽象数据的维度映射到可视表示形式。虽然最常用于将数据编码为位置,例如将时间和温度映射到散点图中的水平和垂直位置
141
166
  var scaler = scales[type]().domain(domain).range(range);
142
167
  scaler.type = type;
143
168
  if (type !== "ordinal") scaler.clamp(true); //scaler.nice().clamp(true)
169
+
144
170
  return scaler;
145
171
  }
146
-
147
172
  /**
148
173
  * 获取所有标签数据
149
174
  * @param {*} scaler
@@ -151,10 +176,11 @@ var _default = function _default(_ref) {
151
176
  * @param {*} tickCount
152
177
  * @returns
153
178
  */
179
+
180
+
154
181
  function getAllTicks(scaler, ticks, tickCount) {
155
182
  return ticks ? ticks : scaler.ticks ? scaler.ticks(tickCount) : scaler.domain();
156
183
  }
157
-
158
184
  /**
159
185
  * 计算非自动模式下的标签集合
160
186
  * @param {*} allTicks
@@ -168,8 +194,11 @@ var _default = function _default(_ref) {
168
194
  * @param {*} step
169
195
  * @returns
170
196
  */
197
+
198
+
171
199
  function getTicks(allTicks, type, carousel, showLast, auto, mode, newDomain, tickCount, step) {
172
200
  var _ticks = allTicks;
201
+
173
202
  if (type === "ordinal") {
174
203
  if (carousel === false) {
175
204
  _ticks = (0, _utils.getTicksOfAxis)(_ticks, +tickCount, showLast);
@@ -180,23 +209,26 @@ var _default = function _default(_ref) {
180
209
  case "count":
181
210
  _ticks = (0, _utils2.getYTicks)(newDomain[1], newDomain[0], +tickCount);
182
211
  break;
212
+
183
213
  case "step":
184
214
  _ticks = (0, _utils2.getYTicksByStep)(newDomain[1], newDomain[0], +step);
185
215
  break;
186
216
  }
187
217
  }
188
218
  }
219
+
189
220
  return _ticks;
190
- }
191
- //断轴相关
221
+ } //断轴相关
222
+
223
+
192
224
  var _isClipAxis = isClipAxis,
193
- clipAxisDomain = [],
194
- clipAxisCount = [],
195
- clipAxisTickCount = [],
196
- clipAxisStep = [];
225
+ clipAxisDomain = [],
226
+ clipAxisCount = [],
227
+ clipAxisTickCount = [],
228
+ clipAxisStep = [];
197
229
  var _count = count,
198
- _step = step;
199
- //计算topDomain,bottomDomain,当断轴值为设置不合理的时候,不开启断轴
230
+ _step = step; //计算topDomain,bottomDomain,当断轴值为设置不合理的时候,不开启断轴
231
+
200
232
  if (isClipAxis && (clipValue > domain[1] || clipValue < domain[0])) {
201
233
  _isClipAxis = false;
202
234
  _count = topClipAxisCount;
@@ -206,25 +238,30 @@ var _default = function _default(_ref) {
206
238
  clipAxisCount = [topClipAxisCount, bottomClipAxisCount];
207
239
  clipAxisStep = [topClipAxisStep, bottomClipAxisStep];
208
240
  }
241
+
209
242
  if (_isClipAxis) {
210
243
  var getClipAxisRange = function getClipAxisRange(start, end, clipPosition, clipMargin) {
211
244
  var topRange = [(end - start) * (clipPosition / 100) - clipMargin / 2, start];
212
245
  var bottomRange = [end, (end - start) * (clipPosition / 100) + clipMargin / 2];
213
246
  return [topRange, bottomRange];
214
247
  }; //计算range填入scaler参数
248
+
249
+
215
250
  clipAxisDomain.forEach(function (domain, index) {
216
251
  clipAxisTickCount.push(getTickCount(domain, clipAxisCount[index], decimal));
217
252
  });
253
+
218
254
  var _getChartsConfig = getChartsConfig(orientation, width, height, paddingOuter),
219
- start = _getChartsConfig.start,
220
- end = _getChartsConfig.end,
221
- direction = _getChartsConfig.direction,
222
- _paddingOuter = _getChartsConfig._paddingOuter,
223
- length = _getChartsConfig.length;
255
+ start = _getChartsConfig.start,
256
+ end = _getChartsConfig.end,
257
+ direction = _getChartsConfig.direction,
258
+ _paddingOuter = _getChartsConfig._paddingOuter,
259
+ length = _getChartsConfig.length;
260
+
224
261
  var clipMargin = 10;
225
262
  var clipAxisRange = getClipAxisRange(start, end, clipPosition, clipMargin);
226
- var newClipAxisDomain = [];
227
- //如果非自适应模式,计算新的domain,传入scaler,适配强制步长或者数量强制
263
+ var newClipAxisDomain = []; //如果非自适应模式,计算新的domain,传入scaler,适配强制步长或者数量强制
264
+
228
265
  if (!isNaN(domain[1]) && !auto) {
229
266
  clipAxisDomain.forEach(function (domain, index) {
230
267
  newClipAxisDomain.push(getNewDomain(domain, mode, clipAxisStep[index]));
@@ -232,13 +269,14 @@ var _default = function _default(_ref) {
232
269
  } else {
233
270
  //如果为刻度自适应,使用原先domain直接传入scaler,使用scaler.ticks来计算出标签集合
234
271
  newClipAxisDomain = clipAxisDomain;
235
- }
236
- //设置scaler,scaler会将数值映射真实的坐标(svg坐标)
272
+ } //设置scaler,scaler会将数值映射真实的坐标(svg坐标)
273
+
274
+
237
275
  var clipAxisScaler = [];
238
276
  newClipAxisDomain.forEach(function (domain, index) {
239
277
  clipAxisScaler.push(setScaler(scales, type, domain, clipAxisRange[index]));
240
- });
241
- //clipAxisAllTicks作用是使用scaler.ticks方法,来计算标签集合
278
+ }); //clipAxisAllTicks作用是使用scaler.ticks方法,来计算标签集合
279
+
242
280
  var clipAxisAllTicks = [];
243
281
  clipAxisScaler.forEach(function (scaler, index) {
244
282
  clipAxisAllTicks.push(getAllTicks(scaler, ticks, clipAxisTickCount[index]));
@@ -265,23 +303,28 @@ var _default = function _default(_ref) {
265
303
  } else {
266
304
  //计算真正需要的tickCount,如果domain区间太小,不能完全按照count来,需要减少count数
267
305
  var tickCount = type == "ordinal" ? _count : getTickCount(domain, _count, decimal);
306
+
268
307
  var _getChartsConfig2 = getChartsConfig(orientation, width, height, paddingOuter),
269
- _start = _getChartsConfig2.start,
270
- _end = _getChartsConfig2.end,
271
- _direction = _getChartsConfig2.direction,
272
- _paddingOuter2 = _getChartsConfig2._paddingOuter,
273
- _length = _getChartsConfig2.length;
308
+ _start = _getChartsConfig2.start,
309
+ _end = _getChartsConfig2.end,
310
+ _direction = _getChartsConfig2.direction,
311
+ _paddingOuter2 = _getChartsConfig2._paddingOuter,
312
+ _length = _getChartsConfig2.length;
313
+
274
314
  var range = _direction === "horizontal" ? [_start, _end] : _direction === "vertical" ? [_end, _start] : [0, 0];
275
315
  var newDomain = domain;
316
+
276
317
  if (type !== "ordinal" && !isNaN(domain[1]) && !auto) {
277
318
  newDomain = getNewDomain(domain, mode, _step);
278
319
  }
320
+
279
321
  var scaler = scales[type]().domain(newDomain).range(range);
280
322
  scaler.type = type;
281
323
  if (type !== "ordinal") scaler.clamp(true); //scaler.nice().clamp(true)
324
+
282
325
  var allTicks = ticks ? ticks : scaler.ticks ? scaler.ticks(tickCount) : scaler.domain();
283
- var _ticks = allTicks;
284
- //
326
+ var _ticks = allTicks; //
327
+
285
328
  if (type === "ordinal") {
286
329
  if (carousel === false) {
287
330
  _ticks = (0, _utils.getTicksOfAxis)(_ticks, +tickCount, showLast);
@@ -292,15 +335,19 @@ var _default = function _default(_ref) {
292
335
  case "count":
293
336
  _ticks = (0, _utils2.getYTicks)(newDomain[1], newDomain[0], +tickCount);
294
337
  break;
338
+
295
339
  case "step":
296
340
  _ticks = (0, _utils2.getYTicksByStep)(newDomain[1], newDomain[0], +_step);
297
341
  break;
298
342
  }
299
343
  }
300
344
  }
345
+
301
346
  var _lengthWithoutPaddingOuter = _length - _paddingOuter2;
347
+
302
348
  if (type == "linear" && config.on) {
303
349
  var zeroPosition = scaler(0);
350
+
304
351
  if (zeroPosition !== range[0] && !isNaN(zeroPosition)) {
305
352
  if (_direction === "horizontal") {
306
353
  xAxisPositions.push({
@@ -315,6 +362,7 @@ var _default = function _default(_ref) {
315
362
  }
316
363
  }
317
364
  }
365
+
318
366
  tmp.set(axisType, _objectSpread(_objectSpread({}, item), {}, {
319
367
  count: _count,
320
368
  isClipAxis: _isClipAxis,
@@ -335,6 +383,8 @@ var _default = function _default(_ref) {
335
383
  tmp.get("x") && (tmp.get("x").positions = xAxisPositions);
336
384
  return tmp;
337
385
  }, [axes]);
386
+
338
387
  return _axes;
339
388
  };
389
+
340
390
  exports["default"] = _default;
@@ -1,59 +1,74 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
4
5
  Object.defineProperty(exports, "__esModule", {
5
6
  value: true
6
7
  });
7
8
  exports["default"] = void 0;
9
+
8
10
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+
9
12
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
13
+
10
14
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
15
+
11
16
  var _react = require("react");
17
+
12
18
  var _popmotion = require("popmotion");
19
+
13
20
  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; }
21
+
14
22
  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; }
23
+
15
24
  var initialState = {
16
25
  currentIndex: null,
17
26
  flag: false //表示是否为首次加载,true表示首次加载,不需要立刻执行动画,false表示可以执行轮播动画
18
- };
19
27
 
28
+ };
20
29
  /**
21
30
  * x轴滚动逻辑
22
31
  * @param {Object} axis x轴配置项
23
32
  * @param {Object} config x轴轮播动画的配置项
24
33
  * @returns {Map} 返回经过改变后的x轴,主要是ticks和scaler的range发生了改变
25
34
  */
35
+
26
36
  var _default = function _default(axis, config, isHover) {
27
37
  var isControlChart = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
28
38
  var controlConfig = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null;
29
39
  var show = config.show,
30
- interval = config.interval,
31
- duration = config.duration,
32
- hover = config.hover;
40
+ interval = config.interval,
41
+ duration = config.duration,
42
+ hover = config.hover;
33
43
  var time = duration + interval;
34
44
  var tickCount = axis.tickCount,
35
- allTicks = axis.allTicks,
36
- scaler = axis.scaler,
37
- start = axis.start,
38
- end = axis.end,
39
- step = axis.step,
40
- ticks = axis.ticks,
41
- lengthWithoutPaddingOuter = axis.lengthWithoutPaddingOuter;
45
+ allTicks = axis.allTicks,
46
+ scaler = axis.scaler,
47
+ start = axis.start,
48
+ end = axis.end,
49
+ step = axis.step,
50
+ ticks = axis.ticks,
51
+ lengthWithoutPaddingOuter = axis.lengthWithoutPaddingOuter;
42
52
  var tickLength = ticks.length;
43
- var _end = isControlChart && controlConfig ? end / (controlConfig.drag.width / 100) : end;
53
+
54
+ var _end = isControlChart && controlConfig ? end * (1 / (controlConfig.drag.width / 100)) : end;
55
+
44
56
  var controlDragScaler = scaler.copy().range([start, end]);
57
+
45
58
  var _useState = (0, _react.useState)({
46
- scaler: scaler,
47
- step: step,
48
- ticks: ticks
49
- }),
50
- _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
51
- state = _useState2[0],
52
- setState = _useState2[1];
59
+ scaler: scaler,
60
+ step: step,
61
+ ticks: ticks
62
+ }),
63
+ _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
64
+ state = _useState2[0],
65
+ setState = _useState2[1];
66
+
53
67
  var _useState3 = (0, _react.useState)(initialState),
54
- _useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
55
- status = _useState4[0],
56
- setStatus = _useState4[1];
68
+ _useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
69
+ status = _useState4[0],
70
+ setStatus = _useState4[1];
71
+
57
72
  (0, _react.useEffect)(function () {
58
73
  if (show && time && tickLength > tickCount) {
59
74
  setStatus({
@@ -66,6 +81,7 @@ var _default = function _default(axis, config, isHover) {
66
81
  }, [show, time, tickCount, tickLength]);
67
82
  (0, _react.useEffect)(function () {
68
83
  var handler;
84
+
69
85
  if (!(hover && isHover) && show && time && tickLength > tickCount) {
70
86
  handler = setInterval(function () {
71
87
  setStatus(function (_ref) {
@@ -78,6 +94,7 @@ var _default = function _default(axis, config, isHover) {
78
94
  });
79
95
  }, time * 1000);
80
96
  }
97
+
81
98
  return function () {
82
99
  handler && clearInterval(handler);
83
100
  };
@@ -85,11 +102,14 @@ var _default = function _default(axis, config, isHover) {
85
102
  (0, _react.useEffect)(function () {
86
103
  var animation;
87
104
  var currentIndex = status.currentIndex,
88
- flag = status.flag;
105
+ flag = status.flag;
106
+
89
107
  if (currentIndex !== null) {
90
108
  var _step = lengthWithoutPaddingOuter / tickCount;
109
+
91
110
  if (flag) {
92
111
  var _ticks = allTicks.slice(currentIndex, tickCount);
112
+
93
113
  setState({
94
114
  step: _step,
95
115
  ticks: _ticks,
@@ -104,10 +124,13 @@ var _default = function _default(axis, config, isHover) {
104
124
  onPlay: function onPlay() {
105
125
  setState(function (axis) {
106
126
  var ticks = axis.ticks,
107
- scaler = axis.scaler;
127
+ scaler = axis.scaler;
128
+
108
129
  var _ticks2 = (0, _slicedToArray2["default"])(ticks, 1),
109
- tick = _ticks2[0];
130
+ tick = _ticks2[0];
131
+
110
132
  var _ticks = [tick].concat((0, _toConsumableArray2["default"])(getTicks(allTicks, currentIndex, tickCount)));
133
+
111
134
  return _objectSpread(_objectSpread({}, axis), {}, {
112
135
  ticks: _ticks,
113
136
  scaler: scaler.copy().range([start, _end + _step]).domain(_ticks)
@@ -117,7 +140,7 @@ var _default = function _default(axis, config, isHover) {
117
140
  onUpdate: function onUpdate(v) {
118
141
  setState(function (axis) {
119
142
  var scaler = axis.scaler,
120
- step = axis.step;
143
+ step = axis.step;
121
144
  return _objectSpread(_objectSpread({}, axis), {}, {
122
145
  scaler: scaler.copy().range([start + step * v, _end + step + step * v])
123
146
  });
@@ -126,8 +149,10 @@ var _default = function _default(axis, config, isHover) {
126
149
  onComplete: function onComplete() {
127
150
  setState(function (axis) {
128
151
  var scaler = axis.scaler,
129
- ticks = axis.ticks;
152
+ ticks = axis.ticks;
153
+
130
154
  var _ticks = ticks.slice(1, ticks.length);
155
+
131
156
  return _objectSpread(_objectSpread({}, axis), {}, {
132
157
  ticks: _ticks,
133
158
  scaler: scaler.copy().range([start, _end]).domain(_ticks)
@@ -138,12 +163,14 @@ var _default = function _default(axis, config, isHover) {
138
163
  }
139
164
  } else {
140
165
  var _ticks3 = scaler.type == "linear" ? scaler.domain() : allTicks;
166
+
141
167
  setState({
142
168
  step: step,
143
169
  scaler: scaler.copy().domain(_ticks3).range([start, _end]),
144
170
  ticks: ticks
145
171
  });
146
172
  }
173
+
147
174
  return function () {
148
175
  animation && animation.stop();
149
176
  };
@@ -155,16 +182,22 @@ var _default = function _default(axis, config, isHover) {
155
182
  isControlChart: isControlChart
156
183
  });
157
184
  };
185
+
158
186
  exports["default"] = _default;
187
+
159
188
  var getTicks = function getTicks(ticks, currentIndex, length) {
160
189
  var _currentIndex = +currentIndex;
190
+
161
191
  var ticksLength = ticks.length;
162
192
  if (ticksLength <= length) return ticks;
193
+
163
194
  var _end = _currentIndex + length;
195
+
164
196
  if (ticksLength < _end) {
165
197
  var prev = ticks.slice(_currentIndex, ticksLength);
166
198
  var next = ticks.slice(0, _end - ticksLength);
167
199
  return [].concat((0, _toConsumableArray2["default"])(prev), (0, _toConsumableArray2["default"])(next));
168
200
  }
201
+
169
202
  return ticks.slice(_currentIndex, _end);
170
203
  };