@easyv/charts 1.2.3 → 1.2.6

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 (92) hide show
  1. package/.babelrc +8 -8
  2. package/.husky/commit-msg +3 -3
  3. package/CHANGELOG.md +18 -18
  4. package/lib/components/AnimateData.js +11 -7
  5. package/lib/components/Axis.js +18 -14
  6. package/lib/components/Background.js +2 -2
  7. package/lib/components/Band.js +8 -4
  8. package/lib/components/BaseLine.js +76 -0
  9. package/lib/components/Brush.js +2 -2
  10. package/lib/components/Carousel.js +15 -8
  11. package/lib/components/CartesianChart.js +26 -7
  12. package/lib/components/Chart.js +9 -6
  13. package/lib/components/ChartContainer.js +8 -4
  14. package/lib/components/ConicalGradient.js +27 -23
  15. package/lib/components/ExtentData.js +7 -4
  16. package/lib/components/FilterData.js +7 -4
  17. package/lib/components/Indicator.js +2 -2
  18. package/lib/components/Label.js +2 -2
  19. package/lib/components/Legend.js +11 -5
  20. package/lib/components/Lighter.js +179 -179
  21. package/lib/components/Line.js +11 -5
  22. package/lib/components/LinearGradient.js +2 -2
  23. package/lib/components/Mapping.js +8 -5
  24. package/lib/components/Marquee.js +14 -14
  25. package/lib/components/PieChart.js +17 -8
  26. package/lib/components/StackData.js +7 -4
  27. package/lib/components/StereoBar.js +8 -4
  28. package/lib/components/TextOverflow.js +65 -0
  29. package/lib/components/Tooltip.js +2 -2
  30. package/lib/components/index.js +58 -50
  31. package/lib/css/index.module.css +41 -41
  32. package/lib/css/piechart.module.css +26 -26
  33. package/lib/element/ConicGradient.js +72 -72
  34. package/lib/formatter/legend.js +2 -2
  35. package/lib/hooks/index.js +14 -14
  36. package/lib/hooks/useAnimateData.js +7 -7
  37. package/lib/hooks/useAxes.js +7 -7
  38. package/lib/hooks/useCarouselAxisX.js +7 -7
  39. package/lib/hooks/useExtentData.js +8 -8
  40. package/lib/hooks/useFilterData.js +8 -8
  41. package/lib/hooks/useStackData.js +10 -8
  42. package/lib/hooks/useTooltip.js +10 -10
  43. package/lib/index.js +6 -2
  44. package/lib/utils/index.js +31 -8
  45. package/package.json +53 -51
  46. package/src/components/AnimateData.tsx +24 -24
  47. package/src/components/Axis.tsx +354 -354
  48. package/src/components/Background.tsx +45 -45
  49. package/src/components/Band.tsx +173 -173
  50. package/src/components/BaseLine.js +76 -0
  51. package/src/components/Brush.js +159 -159
  52. package/src/components/Carousel.tsx +144 -144
  53. package/src/components/CartesianChart.js +22 -5
  54. package/src/components/Chart.js +99 -99
  55. package/src/components/ChartContainer.tsx +63 -63
  56. package/src/components/ConicalGradient.js +258 -258
  57. package/src/components/ExtentData.js +17 -17
  58. package/src/components/FilterData.js +23 -23
  59. package/src/components/Indicator.js +13 -13
  60. package/src/components/Label.js +206 -206
  61. package/src/components/Legend.js +158 -158
  62. package/src/components/Lighter.jsx +173 -173
  63. package/src/components/Line.js +144 -144
  64. package/src/components/LinearGradient.js +29 -29
  65. package/src/components/Mapping.js +71 -71
  66. package/src/components/Marquee.js +93 -93
  67. package/src/components/PieChart.js +1288 -1288
  68. package/src/components/StackData.js +20 -20
  69. package/src/components/StereoBar.tsx +310 -310
  70. package/src/components/TextOverflow.js +51 -0
  71. package/src/components/Tooltip.js +169 -169
  72. package/src/components/index.js +55 -53
  73. package/src/context/index.js +2 -2
  74. package/src/css/index.module.css +41 -41
  75. package/src/css/piechart.module.css +26 -26
  76. package/src/element/ConicGradient.jsx +55 -55
  77. package/src/element/Line.tsx +33 -33
  78. package/src/element/index.ts +3 -3
  79. package/src/formatter/index.js +1 -1
  80. package/src/formatter/legend.js +90 -90
  81. package/src/hooks/index.js +17 -17
  82. package/src/hooks/useAnimateData.ts +67 -67
  83. package/src/hooks/useAxes.js +144 -144
  84. package/src/hooks/useCarouselAxisX.js +163 -163
  85. package/src/hooks/useExtentData.js +88 -88
  86. package/src/hooks/useFilterData.js +72 -72
  87. package/src/hooks/useStackData.js +100 -100
  88. package/src/hooks/useTooltip.ts +96 -96
  89. package/src/index.js +6 -6
  90. package/src/types/index.d.ts +67 -67
  91. package/src/utils/index.js +714 -696
  92. package/tsconfig.json +22 -22
@@ -1,159 +1,159 @@
1
- /**
2
- * 实现中
3
- */
4
- import { memo, useState, useCallback, useEffect, useRef } from 'react';
5
-
6
- const left = {
7
- position: 'relative',
8
- width: 5,
9
- height: '100%',
10
- cursor: 'col-resize',
11
- backgroundClip: 'content-box',
12
- };
13
- const center = {
14
- flex: '1 1 0%',
15
- height: '100%',
16
- cursor: 'move',
17
- };
18
- const right = {
19
- position: 'relative',
20
- width: 5,
21
- height: '100%',
22
- cursor: 'col-resize',
23
- backgroundClip: 'content-box',
24
- };
25
- const initialPosition = {
26
- start: 0,
27
- end: 0,
28
- status: '',
29
- };
30
- const getValue = (x, min, max) => Math.max(min, Math.min(x, max));
31
- export default ({
32
- width,
33
- config: {
34
- height,
35
- background,
36
- margin: { marginLeft, marginRight },
37
- detail: { width: blockWidth, color },
38
- },
39
- }) => {
40
- const [state, setState] = useState({ translateX: 0, width: blockWidth });
41
- const availableWidth = width - marginLeft - marginRight;
42
- const cache = useRef(state);
43
-
44
- const move = useCallback(
45
- ({ delta, status, name }) => {
46
- let { width, translateX } = cache.current;
47
- const minWidth = 40;
48
- const minX = 0;
49
- switch (name) {
50
- case 'center':
51
- translateX = getValue(
52
- translateX + delta,
53
- minX,
54
- availableWidth - width
55
- );
56
- break;
57
- case 'left':
58
- let tempWidth = width;
59
- width = getValue(width + delta * -1, minWidth, translateX + width);
60
- translateX = getValue(
61
- translateX + delta,
62
- minX,
63
- translateX + tempWidth - width
64
- );
65
- break;
66
- case 'right':
67
- width = getValue(
68
- width + delta,
69
- minWidth,
70
- availableWidth - translateX
71
- );
72
- break;
73
- }
74
-
75
- if (status === 'up') {
76
- cache.current = { width, translateX };
77
- }
78
-
79
- setState({ width, translateX });
80
- },
81
- [availableWidth]
82
- );
83
- useEffect(() => {}, [state]);
84
- return (
85
- <div
86
- style={{
87
- marginLeft,
88
- marginRight,
89
- height,
90
- background,
91
- position: 'absolute',
92
- bottom: 0,
93
- width: availableWidth,
94
- }}
95
- >
96
- <div
97
- style={{
98
- display: 'flex',
99
- justifyContent: 'space-between',
100
- position: 'absolute',
101
- top: 0,
102
- left: 0,
103
- transform: 'translate3d(' + state.translateX + 'px, 0, 0)',
104
- height: '100%',
105
- width: state.width + 'px',
106
- backgroundColor: color,
107
- }}
108
- >
109
- <Move style={left} move={move} name='left' />
110
- <Move style={center} move={move} name='center' />
111
- <Move style={right} move={move} name='right' />
112
- </div>
113
- </div>
114
- );
115
- };
116
- const Move = memo(({ style, move, name }) => {
117
- const [position, setPosition] = useState(initialPosition);
118
-
119
- const documentOnMouseMove = useCallback((e) => {
120
- // console.log('documentOnMouseMove');
121
- setPosition((position) => {
122
- return {
123
- ...position,
124
- end: e.clientX,
125
- status: 'move',
126
- };
127
- });
128
- }, []);
129
-
130
- const documentOnMouseUp = useCallback((e) => {
131
- // console.log('documentOnMouseUp');
132
- setPosition((position) => {
133
- return {
134
- ...position,
135
- end: e.clientX,
136
- status: 'up',
137
- };
138
- });
139
- document.removeEventListener('mousemove', documentOnMouseMove);
140
- document.removeEventListener('mouseup', documentOnMouseUp);
141
- }, []);
142
-
143
- const onMouseDown = useCallback((e) => {
144
- // console.log('onMouseDown');
145
- setPosition({
146
- end: e.clientX,
147
- start: e.clientX,
148
- status: 'down',
149
- });
150
- document.addEventListener('mousemove', documentOnMouseMove);
151
- document.addEventListener('mouseup', documentOnMouseUp);
152
- }, []);
153
-
154
- useEffect(() => {
155
- const { start, end, status } = position;
156
- move({ delta: end - start, status, name });
157
- }, [position, move, name]);
158
- return <div style={style} onMouseDown={onMouseDown} />;
159
- });
1
+ /**
2
+ * 实现中
3
+ */
4
+ import { memo, useState, useCallback, useEffect, useRef } from 'react';
5
+
6
+ const left = {
7
+ position: 'relative',
8
+ width: 5,
9
+ height: '100%',
10
+ cursor: 'col-resize',
11
+ backgroundClip: 'content-box',
12
+ };
13
+ const center = {
14
+ flex: '1 1 0%',
15
+ height: '100%',
16
+ cursor: 'move',
17
+ };
18
+ const right = {
19
+ position: 'relative',
20
+ width: 5,
21
+ height: '100%',
22
+ cursor: 'col-resize',
23
+ backgroundClip: 'content-box',
24
+ };
25
+ const initialPosition = {
26
+ start: 0,
27
+ end: 0,
28
+ status: '',
29
+ };
30
+ const getValue = (x, min, max) => Math.max(min, Math.min(x, max));
31
+ export default ({
32
+ width,
33
+ config: {
34
+ height,
35
+ background,
36
+ margin: { marginLeft, marginRight },
37
+ detail: { width: blockWidth, color },
38
+ },
39
+ }) => {
40
+ const [state, setState] = useState({ translateX: 0, width: blockWidth });
41
+ const availableWidth = width - marginLeft - marginRight;
42
+ const cache = useRef(state);
43
+
44
+ const move = useCallback(
45
+ ({ delta, status, name }) => {
46
+ let { width, translateX } = cache.current;
47
+ const minWidth = 40;
48
+ const minX = 0;
49
+ switch (name) {
50
+ case 'center':
51
+ translateX = getValue(
52
+ translateX + delta,
53
+ minX,
54
+ availableWidth - width
55
+ );
56
+ break;
57
+ case 'left':
58
+ let tempWidth = width;
59
+ width = getValue(width + delta * -1, minWidth, translateX + width);
60
+ translateX = getValue(
61
+ translateX + delta,
62
+ minX,
63
+ translateX + tempWidth - width
64
+ );
65
+ break;
66
+ case 'right':
67
+ width = getValue(
68
+ width + delta,
69
+ minWidth,
70
+ availableWidth - translateX
71
+ );
72
+ break;
73
+ }
74
+
75
+ if (status === 'up') {
76
+ cache.current = { width, translateX };
77
+ }
78
+
79
+ setState({ width, translateX });
80
+ },
81
+ [availableWidth]
82
+ );
83
+ useEffect(() => {}, [state]);
84
+ return (
85
+ <div
86
+ style={{
87
+ marginLeft,
88
+ marginRight,
89
+ height,
90
+ background,
91
+ position: 'absolute',
92
+ bottom: 0,
93
+ width: availableWidth,
94
+ }}
95
+ >
96
+ <div
97
+ style={{
98
+ display: 'flex',
99
+ justifyContent: 'space-between',
100
+ position: 'absolute',
101
+ top: 0,
102
+ left: 0,
103
+ transform: 'translate3d(' + state.translateX + 'px, 0, 0)',
104
+ height: '100%',
105
+ width: state.width + 'px',
106
+ backgroundColor: color,
107
+ }}
108
+ >
109
+ <Move style={left} move={move} name='left' />
110
+ <Move style={center} move={move} name='center' />
111
+ <Move style={right} move={move} name='right' />
112
+ </div>
113
+ </div>
114
+ );
115
+ };
116
+ const Move = memo(({ style, move, name }) => {
117
+ const [position, setPosition] = useState(initialPosition);
118
+
119
+ const documentOnMouseMove = useCallback((e) => {
120
+ // console.log('documentOnMouseMove');
121
+ setPosition((position) => {
122
+ return {
123
+ ...position,
124
+ end: e.clientX,
125
+ status: 'move',
126
+ };
127
+ });
128
+ }, []);
129
+
130
+ const documentOnMouseUp = useCallback((e) => {
131
+ // console.log('documentOnMouseUp');
132
+ setPosition((position) => {
133
+ return {
134
+ ...position,
135
+ end: e.clientX,
136
+ status: 'up',
137
+ };
138
+ });
139
+ document.removeEventListener('mousemove', documentOnMouseMove);
140
+ document.removeEventListener('mouseup', documentOnMouseUp);
141
+ }, []);
142
+
143
+ const onMouseDown = useCallback((e) => {
144
+ // console.log('onMouseDown');
145
+ setPosition({
146
+ end: e.clientX,
147
+ start: e.clientX,
148
+ status: 'down',
149
+ });
150
+ document.addEventListener('mousemove', documentOnMouseMove);
151
+ document.addEventListener('mouseup', documentOnMouseUp);
152
+ }, []);
153
+
154
+ useEffect(() => {
155
+ const { start, end, status } = position;
156
+ move({ delta: end - start, status, name });
157
+ }, [position, move, name]);
158
+ return <div style={style} onMouseDown={onMouseDown} />;
159
+ });
@@ -1,144 +1,144 @@
1
- import React, {
2
- ComponentType,
3
- memo,
4
- useEffect,
5
- useState,
6
- useCallback,
7
- useRef,
8
- } from 'react';
9
- import { interval as d3Interval, Timer } from 'd3v7';
10
- type State = {
11
- currentIndex: number | null;
12
- trigger: string;
13
- };
14
-
15
- const initialState = {
16
- currentIndex: null,
17
- trigger: '',
18
- };
19
-
20
- const carouselState = {
21
- currentIndex: 0,
22
- trigger: 'carousel',
23
- };
24
-
25
- const defaultAnimation = {
26
- on: false,
27
- interval: 0,
28
- interactive: '',
29
- current: { heighten: 0, opacity: 100 },
30
- };
31
- /**
32
- * 饼图类图表轮播逻辑,用来管理currentIndex,及回调逻辑(HOC)
33
- */
34
- export default (Component: ComponentType<any>) =>
35
- memo(
36
- ({
37
- config: { animation, ...config },
38
- data = [],
39
- ...rest
40
- }: {
41
- data: DataType[];
42
- config: { dataAnimation: boolean; [key: string]: any };
43
- [key: string]: any;
44
- }) => {
45
- const dataLength = data.length;
46
- const _animation = Object.assign({}, defaultAnimation, animation);
47
- const { on, interval, interactive } = _animation;
48
-
49
- const [state, setState] = useState<State>(
50
- on ? carouselState : initialState
51
- );
52
- const timer: { current: Timer | null } = useRef(null);
53
-
54
- const animationOn = on && interval && dataLength;
55
-
56
- const carousel = useCallback(() => {
57
- if (animationOn) {
58
- timer.current = d3Interval(() => {
59
- setState(({ currentIndex }) => {
60
- const tmp = (currentIndex == null ? 0 : +currentIndex) + 1;
61
- return {
62
- currentIndex: tmp >= dataLength ? 0 : tmp,
63
- trigger: 'carousel',
64
- };
65
- });
66
- }, interval * 1000);
67
- } else {
68
- timer.current = null;
69
- setState({
70
- currentIndex: null,
71
- trigger: '',
72
- });
73
- }
74
- }, [animationOn, interval, dataLength]);
75
-
76
- useEffect(() => {
77
- carousel && carousel();
78
- return () => {
79
- timer.current && timer.current.stop();
80
- };
81
- }, [carousel]);
82
-
83
- const onEvent = useCallback(
84
- ({ currentIndex, type }) => {
85
- switch (interactive) {
86
- case true:
87
- case 'click':
88
- if (type == 'onClick') {
89
- timer.current && timer.current.stop();
90
- animationOn && carousel();
91
- setState({
92
- trigger: type,
93
- currentIndex,
94
- });
95
- }
96
- break;
97
- case 'hover':
98
- if (type == 'onMouseEnter') {
99
- setState({
100
- trigger: type,
101
- currentIndex,
102
- });
103
- timer.current && timer.current.stop();
104
- } else if (type == 'onMouseLeave') {
105
- animationOn && carousel();
106
- }
107
- break;
108
- case false:
109
- case '':
110
- break;
111
- case 'carousel':
112
- default:
113
- setState({
114
- trigger: type,
115
- currentIndex,
116
- });
117
- break;
118
- }
119
- },
120
- [interactive, animationOn, carousel]
121
- );
122
-
123
- if (!animationOn) {
124
- return (
125
- <Component
126
- {...rest}
127
- state={state}
128
- onEvent={onEvent}
129
- config={{ ...config, animation: _animation }}
130
- data={data}
131
- />
132
- );
133
- }
134
- return (
135
- <Component
136
- {...rest}
137
- state={state}
138
- onEvent={onEvent}
139
- config={{ ...config, animation: _animation }}
140
- data={data}
141
- />
142
- );
143
- }
144
- );
1
+ import React, {
2
+ ComponentType,
3
+ memo,
4
+ useEffect,
5
+ useState,
6
+ useCallback,
7
+ useRef,
8
+ } from 'react';
9
+ import { interval as d3Interval, Timer } from 'd3v7';
10
+ type State = {
11
+ currentIndex: number | null;
12
+ trigger: string;
13
+ };
14
+
15
+ const initialState = {
16
+ currentIndex: null,
17
+ trigger: '',
18
+ };
19
+
20
+ const carouselState = {
21
+ currentIndex: 0,
22
+ trigger: 'carousel',
23
+ };
24
+
25
+ const defaultAnimation = {
26
+ on: false,
27
+ interval: 0,
28
+ interactive: '',
29
+ current: { heighten: 0, opacity: 100 },
30
+ };
31
+ /**
32
+ * 饼图类图表轮播逻辑,用来管理currentIndex,及回调逻辑(HOC)
33
+ */
34
+ export default (Component: ComponentType<any>) =>
35
+ memo(
36
+ ({
37
+ config: { animation, ...config },
38
+ data = [],
39
+ ...rest
40
+ }: {
41
+ data: DataType[];
42
+ config: { dataAnimation: boolean; [key: string]: any };
43
+ [key: string]: any;
44
+ }) => {
45
+ const dataLength = data.length;
46
+ const _animation = Object.assign({}, defaultAnimation, animation);
47
+ const { on, interval, interactive } = _animation;
48
+
49
+ const [state, setState] = useState<State>(
50
+ on ? carouselState : initialState
51
+ );
52
+ const timer: { current: Timer | null } = useRef(null);
53
+
54
+ const animationOn = on && interval && dataLength;
55
+
56
+ const carousel = useCallback(() => {
57
+ if (animationOn) {
58
+ timer.current = d3Interval(() => {
59
+ setState(({ currentIndex }) => {
60
+ const tmp = (currentIndex == null ? 0 : +currentIndex) + 1;
61
+ return {
62
+ currentIndex: tmp >= dataLength ? 0 : tmp,
63
+ trigger: 'carousel',
64
+ };
65
+ });
66
+ }, interval * 1000);
67
+ } else {
68
+ timer.current = null;
69
+ setState({
70
+ currentIndex: null,
71
+ trigger: '',
72
+ });
73
+ }
74
+ }, [animationOn, interval, dataLength]);
75
+
76
+ useEffect(() => {
77
+ carousel && carousel();
78
+ return () => {
79
+ timer.current && timer.current.stop();
80
+ };
81
+ }, [carousel]);
82
+
83
+ const onEvent = useCallback(
84
+ ({ currentIndex, type }) => {
85
+ switch (interactive) {
86
+ case true:
87
+ case 'click':
88
+ if (type == 'onClick') {
89
+ timer.current && timer.current.stop();
90
+ animationOn && carousel();
91
+ setState({
92
+ trigger: type,
93
+ currentIndex,
94
+ });
95
+ }
96
+ break;
97
+ case 'hover':
98
+ if (type == 'onMouseEnter') {
99
+ setState({
100
+ trigger: type,
101
+ currentIndex,
102
+ });
103
+ timer.current && timer.current.stop();
104
+ } else if (type == 'onMouseLeave') {
105
+ animationOn && carousel();
106
+ }
107
+ break;
108
+ case false:
109
+ case '':
110
+ break;
111
+ case 'carousel':
112
+ default:
113
+ setState({
114
+ trigger: type,
115
+ currentIndex,
116
+ });
117
+ break;
118
+ }
119
+ },
120
+ [interactive, animationOn, carousel]
121
+ );
122
+
123
+ if (!animationOn) {
124
+ return (
125
+ <Component
126
+ {...rest}
127
+ state={state}
128
+ onEvent={onEvent}
129
+ config={{ ...config, animation: _animation }}
130
+ data={data}
131
+ />
132
+ );
133
+ }
134
+ return (
135
+ <Component
136
+ {...rest}
137
+ state={state}
138
+ onEvent={onEvent}
139
+ config={{ ...config, animation: _animation }}
140
+ data={data}
141
+ />
142
+ );
143
+ }
144
+ );
@@ -24,6 +24,7 @@ import {
24
24
  Brush,
25
25
  Label,
26
26
  Mapping,
27
+ BaseLine
27
28
  } from '.';
28
29
 
29
30
  const Chart = memo(
@@ -41,6 +42,10 @@ const Chart = memo(
41
42
  },
42
43
  series,
43
44
  tooltip,
45
+ baseLine: {
46
+ config: baseLineConfig = {},
47
+ data: baseLineData = []
48
+ },
44
49
  tooltip: {
45
50
  config: tooltipConfig = {},
46
51
  config: { auto, manual, indicator = {} } = {},
@@ -49,7 +54,7 @@ const Chart = memo(
49
54
  },
50
55
  style,
51
56
  data,
52
- filterData,
57
+ filterData
53
58
  }) => {
54
59
  const context = useContext(chartContext);
55
60
  const {
@@ -95,10 +100,10 @@ const Chart = memo(
95
100
  const indicatorAttr = isVertical
96
101
  ? { width: chartWidth, height: indicatorWidth, y: position }
97
102
  : {
98
- height: chartHeight,
99
- width: indicatorWidth,
100
- x: position,
101
- };
103
+ height: chartHeight,
104
+ width: indicatorWidth,
105
+ x: position,
106
+ };
102
107
 
103
108
  const onInteraction = useCallback(
104
109
  (e) => {
@@ -167,6 +172,18 @@ const Chart = memo(
167
172
  )
168
173
  );
169
174
  })}
175
+ {baseLineData && baseLineData.length > 0 && baseLineData.map((item, index) => {
176
+ const { line: { yOrZ } } = baseLineConfig[index];
177
+ const yAxis = axes.get(yOrZ);
178
+ return (
179
+ yAxis && (<BaseLine
180
+ width={width}
181
+ key={index}
182
+ config={baseLineConfig[index]}
183
+ yAxis={yAxis}
184
+ data={item} />)
185
+ )
186
+ })}
170
187
  </ChartContainer>
171
188
  <Legend {...legend} filterData={filterData} series={series} />
172
189
  {showTooltip && (