@easyv/charts 1.2.3 → 1.2.4

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