@easyv/charts 1.2.11 → 1.3.0

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 (77) hide show
  1. package/.babelrc +8 -8
  2. package/.husky/commit-msg +3 -3
  3. package/CHANGELOG.md +18 -18
  4. package/lib/components/Axis.js +10 -10
  5. package/lib/components/Background.js +13 -3
  6. package/lib/components/Band.js +8 -8
  7. package/lib/components/BaseLine.js +0 -1
  8. package/lib/components/Carousel.js +2 -2
  9. package/lib/components/CartesianChart.js +11 -6
  10. package/lib/components/ConicalGradient.js +21 -21
  11. package/lib/components/Indicator.js +2 -2
  12. package/lib/components/Label.js +11 -12
  13. package/lib/components/Lighter.js +179 -179
  14. package/lib/components/LinearGradient.js +2 -2
  15. package/lib/components/Marquee.js +23 -28
  16. package/lib/components/StackData.js +2 -4
  17. package/lib/components/StereoBar.js +14 -14
  18. package/lib/components/TextOverflow.js +3 -3
  19. package/lib/css/index.module.css +41 -41
  20. package/lib/css/piechart.module.css +26 -26
  21. package/lib/element/ConicGradient.js +72 -72
  22. package/lib/hooks/useAnimateData.js +5 -5
  23. package/lib/hooks/useAxes.js +5 -5
  24. package/lib/hooks/useCarouselAxisX.js +5 -5
  25. package/lib/hooks/useExtentData.js +10 -8
  26. package/lib/hooks/useFilterData.js +5 -5
  27. package/lib/hooks/useStackData.js +11 -10
  28. package/lib/hooks/useTooltip.js +10 -10
  29. package/lib/utils/index.js +62 -41
  30. package/package.json +54 -53
  31. package/src/components/AnimateData.tsx +24 -24
  32. package/src/components/Axis.tsx +354 -354
  33. package/src/components/Background.tsx +62 -45
  34. package/src/components/Band.tsx +169 -173
  35. package/src/components/BaseLine.js +82 -83
  36. package/src/components/Brush.js +159 -159
  37. package/src/components/Carousel.tsx +144 -144
  38. package/src/components/CartesianChart.js +33 -22
  39. package/src/components/Chart.js +99 -99
  40. package/src/components/ChartContainer.tsx +63 -63
  41. package/src/components/ConicalGradient.js +258 -258
  42. package/src/components/ExtentData.js +17 -17
  43. package/src/components/FilterData.js +23 -23
  44. package/src/components/Indicator.js +13 -13
  45. package/src/components/Label.js +225 -206
  46. package/src/components/Legend.js +158 -158
  47. package/src/components/Lighter.jsx +173 -173
  48. package/src/components/Line.js +145 -145
  49. package/src/components/LinearGradient.js +29 -29
  50. package/src/components/Mapping.js +71 -71
  51. package/src/components/Marquee.js +88 -93
  52. package/src/components/PieChart.js +1278 -1278
  53. package/src/components/StackData.js +16 -20
  54. package/src/components/StereoBar.tsx +307 -311
  55. package/src/components/TextOverflow.js +51 -51
  56. package/src/components/Tooltip.js +169 -169
  57. package/src/components/index.js +55 -55
  58. package/src/context/index.js +2 -2
  59. package/src/css/index.module.css +41 -41
  60. package/src/css/piechart.module.css +26 -26
  61. package/src/element/ConicGradient.jsx +55 -55
  62. package/src/element/Line.tsx +33 -33
  63. package/src/element/index.ts +3 -3
  64. package/src/formatter/index.js +1 -1
  65. package/src/formatter/legend.js +90 -90
  66. package/src/hooks/index.js +17 -17
  67. package/src/hooks/useAnimateData.ts +67 -67
  68. package/src/hooks/useAxes.js +144 -144
  69. package/src/hooks/useCarouselAxisX.js +163 -163
  70. package/src/hooks/useExtentData.js +89 -88
  71. package/src/hooks/useFilterData.js +72 -72
  72. package/src/hooks/useStackData.js +101 -100
  73. package/src/hooks/useTooltip.ts +96 -96
  74. package/src/index.js +6 -6
  75. package/src/types/index.d.ts +67 -67
  76. package/src/utils/index.js +731 -714
  77. package/tsconfig.json +23 -23
@@ -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
+ );