@easyv/charts 1.4.16 → 1.4.17

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