@easyv/charts 1.0.65 → 1.0.69

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 (65) hide show
  1. package/.babelrc +8 -8
  2. package/lib/components/AnimateData.js +2 -2
  3. package/lib/components/Axis.js +13 -13
  4. package/lib/components/Background.js +2 -2
  5. package/lib/components/Carousel.js +2 -2
  6. package/lib/components/Chart.js +2 -2
  7. package/lib/components/ConicalGradient.js +21 -21
  8. package/lib/components/Indicator.js +2 -2
  9. package/lib/components/Line.js +2 -0
  10. package/lib/components/LinearGradient.js +2 -2
  11. package/lib/css/index.module.css +41 -41
  12. package/lib/css/piechart.module.css +26 -26
  13. package/lib/formatter/legend.js +7 -2
  14. package/lib/hooks/useAnimateData.js +5 -5
  15. package/lib/hooks/useAxes.js +5 -5
  16. package/lib/hooks/useCarouselAxisX.js +5 -5
  17. package/lib/hooks/useExtentData.js +6 -6
  18. package/lib/hooks/useFilterData.js +5 -5
  19. package/lib/hooks/useStackData.js +5 -5
  20. package/lib/hooks/useTooltip.js +10 -10
  21. package/lib/utils/index.js +36 -7
  22. package/package.json +34 -34
  23. package/src/components/AnimateData.tsx +24 -24
  24. package/src/components/Axis.tsx +333 -333
  25. package/src/components/Background.tsx +45 -45
  26. package/src/components/Band.tsx +160 -160
  27. package/src/components/Brush.js +159 -159
  28. package/src/components/Carousel.tsx +144 -144
  29. package/src/components/Chart.js +99 -99
  30. package/src/components/ChartContainer.tsx +63 -63
  31. package/src/components/ConicalGradient.js +258 -258
  32. package/src/components/ExtentData.js +17 -17
  33. package/src/components/FilterData.js +23 -23
  34. package/src/components/Indicator.js +13 -13
  35. package/src/components/Label.js +196 -196
  36. package/src/components/Legend.js +158 -158
  37. package/src/components/Lighter.jsx +162 -162
  38. package/src/components/Line.js +128 -126
  39. package/src/components/LinearGradient.js +29 -29
  40. package/src/components/Mapping.js +71 -71
  41. package/src/components/PieChart.js +1093 -1093
  42. package/src/components/StackData.js +20 -20
  43. package/src/components/StereoBar.tsx +298 -298
  44. package/src/components/Tooltip.js +133 -133
  45. package/src/components/index.js +49 -49
  46. package/src/context/index.js +2 -2
  47. package/src/css/index.module.css +41 -41
  48. package/src/css/piechart.module.css +26 -26
  49. package/src/element/ConicGradient.jsx +55 -55
  50. package/src/element/Line.tsx +33 -33
  51. package/src/element/index.ts +3 -3
  52. package/src/formatter/index.js +1 -1
  53. package/src/formatter/legend.js +90 -87
  54. package/src/hooks/index.js +17 -17
  55. package/src/hooks/useAnimateData.ts +62 -62
  56. package/src/hooks/useAxes.js +143 -143
  57. package/src/hooks/useCarouselAxisX.js +163 -163
  58. package/src/hooks/useExtentData.js +88 -88
  59. package/src/hooks/useFilterData.js +72 -72
  60. package/src/hooks/useStackData.js +100 -100
  61. package/src/hooks/useTooltip.ts +96 -96
  62. package/src/index.js +6 -6
  63. package/src/types/index.d.ts +59 -59
  64. package/src/utils/index.js +672 -640
  65. 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
+ );