@easyv/charts 1.4.22 → 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.
@@ -23,9 +23,11 @@ import CartesianChart from './CartesianChart';
23
23
  import PieChart from './PieChart';
24
24
  import TextOverflow from './TextOverflow';
25
25
  import BaseLine from './BaseLine';
26
+ import Control from './Control';
26
27
 
27
28
  const Area = Line;
28
29
  export {
30
+ Control,
29
31
  Mapping,
30
32
  AnimateData,
31
33
  FilterData,
@@ -58,7 +58,12 @@ const scales = {
58
58
  * @returns {Map} 返回所有轴
59
59
  */
60
60
 
61
- export default ({ axes, context: { width, height } }) => {
61
+ export default ({
62
+ axes,
63
+ context: { width, height }, //是否为控制图
64
+ isControlChart,
65
+ control: controlConfig,
66
+ }) => {
62
67
  const _axes = useMemo(() => {
63
68
  const tmp = new Map();
64
69
  const xAxisPositions = [];
@@ -321,7 +326,7 @@ export default ({ axes, context: { width, height } }) => {
321
326
  const { start, end, direction, _paddingOuter, length } =
322
327
  getChartsConfig(orientation, width, height, paddingOuter);
323
328
 
324
- const range =
329
+ let range =
325
330
  direction === "horizontal"
326
331
  ? [start, end]
327
332
  : direction === "vertical"
@@ -380,7 +385,9 @@ export default ({ axes, context: { width, height } }) => {
380
385
  ...item,
381
386
  count: _count,
382
387
  isClipAxis: _isClipAxis,
388
+ range,
383
389
  scaler,
390
+ domain,
384
391
  length,
385
392
  direction,
386
393
  start,
@@ -1,9 +1,9 @@
1
- import { useEffect, useState } from 'react';
2
- import { animate, linear } from 'popmotion';
1
+ import { useEffect, useState } from "react";
2
+ import { animate, linear } from "popmotion";
3
3
 
4
4
  const initialState = {
5
5
  currentIndex: null,
6
- flag: false, //表示是否为首次加载,true表示首次加载,不需要立刻执行动画,false表示可以执行轮播动画
6
+ flag: false, //表示是否为首次加载,true表示首次加载,不需要立刻执行动画,false表示可以执行轮播动画
7
7
  };
8
8
 
9
9
  /**
@@ -13,7 +13,13 @@ const initialState = {
13
13
  * @returns {Map} 返回经过改变后的x轴,主要是ticks和scaler的range发生了改变
14
14
  */
15
15
 
16
- export default (axis, config, isHover) => {
16
+ export default (
17
+ axis,
18
+ config,
19
+ isHover,
20
+ isControlChart = false,
21
+ controlConfig = null
22
+ ) => {
17
23
  const { show, interval, duration, hover } = config;
18
24
  const time = duration + interval;
19
25
 
@@ -29,6 +35,12 @@ export default (axis, config, isHover) => {
29
35
  } = axis;
30
36
  const tickLength = ticks.length;
31
37
 
38
+ const _end =
39
+ isControlChart && controlConfig
40
+ ? end * (1 / (controlConfig.drag.width / 100))
41
+ : end;
42
+ const controlDragScaler = scaler.copy().range([start, end]);
43
+
32
44
  const [state, setState] = useState({
33
45
  scaler,
34
46
  step,
@@ -46,9 +58,9 @@ export default (axis, config, isHover) => {
46
58
  setStatus(initialState);
47
59
  }
48
60
  }, [show, time, tickCount, tickLength]);
49
- useEffect(()=>{
61
+ useEffect(() => {
50
62
  let handler;
51
- if(!(hover && isHover) && show && time && tickLength > tickCount){
63
+ if (!(hover && isHover) && show && time && tickLength > tickCount) {
52
64
  handler = setInterval(() => {
53
65
  setStatus(({ currentIndex }) => {
54
66
  const tmp = +currentIndex + 1;
@@ -62,7 +74,7 @@ export default (axis, config, isHover) => {
62
74
  return () => {
63
75
  handler && clearInterval(handler);
64
76
  };
65
- },[show, time, tickCount, tickLength, hover, isHover])
77
+ }, [show, time, tickCount, tickLength, hover, isHover]);
66
78
 
67
79
  useEffect(() => {
68
80
  let animation;
@@ -74,7 +86,7 @@ export default (axis, config, isHover) => {
74
86
  setState({
75
87
  step,
76
88
  ticks: _ticks,
77
- scaler: scaler.copy().domain(_ticks).range([start, end]),
89
+ scaler: scaler.copy().domain(_ticks).range([start, _end]),
78
90
  });
79
91
  } else {
80
92
  animation = animate({
@@ -95,7 +107,7 @@ export default (axis, config, isHover) => {
95
107
  ticks: _ticks,
96
108
  scaler: scaler
97
109
  .copy()
98
- .range([start, end + step])
110
+ .range([start, _end + step])
99
111
  .domain(_ticks),
100
112
  };
101
113
  });
@@ -107,7 +119,7 @@ export default (axis, config, isHover) => {
107
119
  ...axis,
108
120
  scaler: scaler
109
121
  .copy()
110
- .range([start + step * v, end + step + step * v]),
122
+ .range([start + step * v, _end + step + step * v]),
111
123
  };
112
124
  });
113
125
  },
@@ -118,17 +130,17 @@ export default (axis, config, isHover) => {
118
130
  return {
119
131
  ...axis,
120
132
  ticks: _ticks,
121
- scaler: scaler.copy().range([start, end]).domain(_ticks),
133
+ scaler: scaler.copy().range([start, _end]).domain(_ticks),
122
134
  };
123
135
  });
124
136
  },
125
137
  });
126
138
  }
127
139
  } else {
128
- const _ticks = scaler.type == 'linear' ? scaler.domain() : allTicks;
140
+ const _ticks = scaler.type == "linear" ? scaler.domain() : allTicks;
129
141
  setState({
130
142
  step,
131
- scaler: scaler.copy().domain(_ticks).range([start, end]),
143
+ scaler: scaler.copy().domain(_ticks).range([start, _end]),
132
144
  ticks,
133
145
  });
134
146
  }
@@ -140,16 +152,21 @@ export default (axis, config, isHover) => {
140
152
  allTicks,
141
153
  scaler,
142
154
  start,
143
- end,
155
+ _end,
144
156
  step,
145
157
  ticks,
146
158
  lengthWithoutPaddingOuter,
147
159
  status,
148
160
  duration,
149
161
  ]);
162
+
150
163
  return {
151
164
  ...axis,
152
165
  ...state,
166
+ rawTicks: axis.ticks,
167
+ controlDragScaler,
168
+ controlEnd: _end,
169
+ isControlChart,
153
170
  };
154
171
  };
155
172
 
@@ -157,11 +174,11 @@ const getTicks = (ticks, currentIndex, length) => {
157
174
  const _currentIndex = +currentIndex;
158
175
  const ticksLength = ticks.length;
159
176
  if (ticksLength <= length) return ticks;
160
- const end = _currentIndex + length;
161
- if (ticksLength < end) {
177
+ const _end = _currentIndex + length;
178
+ if (ticksLength < _end) {
162
179
  const prev = ticks.slice(_currentIndex, ticksLength);
163
- const next = ticks.slice(0, end - ticksLength);
180
+ const next = ticks.slice(0, _end - ticksLength);
164
181
  return [...prev, ...next];
165
182
  }
166
- return ticks.slice(_currentIndex, end);
183
+ return ticks.slice(_currentIndex, _end);
167
184
  };
@@ -1,6 +1,6 @@
1
- import { useCallback, useState, useEffect } from 'react';
2
- import { getMousePos } from '../utils';
3
- const callback = () => { };
1
+ import { useCallback, useState, useEffect } from "react";
2
+ import { getMousePos } from "../utils";
3
+ const callback = () => {};
4
4
 
5
5
  /**
6
6
  * 主要用于轴类图表,返回当前选中的是哪一个x
@@ -19,8 +19,8 @@ type Props = {
19
19
  marginTop: number;
20
20
  width: number;
21
21
  height: number;
22
- axisX: AxisX;
23
- isHover:boolean,
22
+ axisX: any;
23
+ isHover: boolean;
24
24
  config: { auto?: boolean; interval?: number; manual?: boolean };
25
25
  };
26
26
 
@@ -37,7 +37,7 @@ export default ({
37
37
  const [currentIndex, setCurrentIndex] = useState<number | null>(null);
38
38
  const tickLength = axisX.allTicks.length;
39
39
  const setIndex = useCallback(
40
- (e) => {
40
+ (e: any) => {
41
41
  if (svg) {
42
42
  const {
43
43
  x: mouseX,
@@ -54,17 +54,17 @@ export default ({
54
54
  const x = resetX - marginLeft;
55
55
  const y = resetY - marginTop;
56
56
  if (x > 0 && x < width && y > 0 && y < height && _ticks.length) {
57
- const position = direction === 'vertical' ? y : x;
57
+ const position = direction === "vertical" ? y : x;
58
58
  const name = _ticks.reduce((prev: string, current: string) =>
59
59
  Math.abs(scaler(prev) - position) >
60
- Math.abs(scaler(current) - position)
60
+ Math.abs(scaler(current) - position)
61
61
  ? current
62
62
  : prev
63
63
  );
64
64
  setCurrentIndex(allTicks.findIndex((tick: string) => tick == name));
65
65
  } else {
66
66
  // 鼠标划出后,如果开启了自动轮播,就不需要让提示框消失了
67
- if(!auto){
67
+ if (!auto) {
68
68
  setCurrentIndex(null);
69
69
  }
70
70
  }
@@ -77,15 +77,15 @@ export default ({
77
77
  // if (!!on) setCurrentIndex(0);
78
78
  const intervalHandler = on
79
79
  ? setInterval(() => {
80
- setCurrentIndex((index) => {
81
- const tmp = index == null ? 0 : index;
82
- const currentIndex = tmp + 1;
83
- if (currentIndex >= tickLength) {
84
- return 0;
85
- }
86
- return currentIndex;
87
- });
88
- }, interval * 1000)
80
+ setCurrentIndex((index) => {
81
+ const tmp = index == null ? 0 : index;
82
+ const currentIndex = tmp + 1;
83
+ if (currentIndex >= tickLength) {
84
+ return 0;
85
+ }
86
+ return currentIndex;
87
+ });
88
+ }, interval * 1000)
89
89
  : null;
90
90
  return () => {
91
91
  intervalHandler && clearInterval(intervalHandler);