@easyv/charts 1.0.75 → 1.1.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 (72) hide show
  1. package/.babelrc +8 -8
  2. package/.husky/commit-msg +4 -0
  3. package/CHANGELOG.md +16 -0
  4. package/commitlint.config.js +1 -0
  5. package/lib/components/AnimateData.js +2 -2
  6. package/lib/components/Axis.js +36 -17
  7. package/lib/components/Background.js +2 -2
  8. package/lib/components/Band.js +4 -1
  9. package/lib/components/Carousel.js +2 -2
  10. package/lib/components/CartesianChart.js +8 -2
  11. package/lib/components/Chart.js +2 -2
  12. package/lib/components/ConicalGradient.js +21 -21
  13. package/lib/components/Indicator.js +2 -2
  14. package/lib/components/Lighter.js +180 -0
  15. package/lib/components/LinearGradient.js +2 -2
  16. package/lib/components/Tooltip.js +30 -12
  17. package/lib/components/index.js +8 -0
  18. package/lib/css/index.module.css +41 -41
  19. package/lib/css/piechart.module.css +26 -26
  20. package/lib/element/ConicGradient.js +73 -0
  21. package/lib/hooks/useAnimateData.js +5 -5
  22. package/lib/hooks/useAxes.js +5 -5
  23. package/lib/hooks/useCarouselAxisX.js +5 -5
  24. package/lib/hooks/useExtentData.js +6 -6
  25. package/lib/hooks/useFilterData.js +5 -5
  26. package/lib/hooks/useStackData.js +5 -5
  27. package/lib/hooks/useTooltip.js +10 -10
  28. package/package.json +47 -34
  29. package/src/components/AnimateData.tsx +24 -24
  30. package/src/components/Axis.tsx +354 -336
  31. package/src/components/Background.tsx +45 -45
  32. package/src/components/Band.tsx +173 -171
  33. package/src/components/Brush.js +159 -159
  34. package/src/components/Carousel.tsx +144 -144
  35. package/src/components/CartesianChart.js +7 -1
  36. package/src/components/Chart.js +99 -99
  37. package/src/components/ChartContainer.tsx +63 -63
  38. package/src/components/ConicalGradient.js +258 -258
  39. package/src/components/ExtentData.js +17 -17
  40. package/src/components/FilterData.js +23 -23
  41. package/src/components/Indicator.js +13 -13
  42. package/src/components/Label.js +206 -206
  43. package/src/components/Legend.js +158 -158
  44. package/src/components/Lighter.jsx +173 -162
  45. package/src/components/Line.js +144 -144
  46. package/src/components/LinearGradient.js +29 -29
  47. package/src/components/Mapping.js +71 -71
  48. package/src/components/PieChart.js +1097 -1097
  49. package/src/components/StackData.js +20 -20
  50. package/src/components/StereoBar.tsx +298 -298
  51. package/src/components/Tooltip.js +168 -133
  52. package/src/components/index.js +51 -49
  53. package/src/context/index.js +2 -2
  54. package/src/css/index.module.css +41 -41
  55. package/src/css/piechart.module.css +26 -26
  56. package/src/element/ConicGradient.jsx +55 -55
  57. package/src/element/Line.tsx +33 -33
  58. package/src/element/index.ts +3 -3
  59. package/src/formatter/index.js +1 -1
  60. package/src/formatter/legend.js +90 -90
  61. package/src/hooks/index.js +17 -17
  62. package/src/hooks/useAnimateData.ts +62 -62
  63. package/src/hooks/useAxes.js +144 -144
  64. package/src/hooks/useCarouselAxisX.js +163 -163
  65. package/src/hooks/useExtentData.js +88 -88
  66. package/src/hooks/useFilterData.js +72 -72
  67. package/src/hooks/useStackData.js +100 -100
  68. package/src/hooks/useTooltip.ts +96 -96
  69. package/src/index.js +6 -6
  70. package/src/types/index.d.ts +62 -59
  71. package/src/utils/index.js +692 -692
  72. 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
+ );
@@ -132,7 +132,9 @@ const Chart = memo(
132
132
  )}
133
133
  {[...axes.values()].map((item, index) => {
134
134
  const config = item.axisType == 'x' ? axisX : item;
135
- return <Axis {...config} key={index} />;
135
+ return (
136
+ <Axis triggerClick={onInteraction} {...config} key={index} />
137
+ );
136
138
  })}
137
139
 
138
140
  {showTooltip && <Indicator {...indicator} {...indicatorAttr} />}
@@ -173,8 +175,12 @@ const Chart = memo(
173
175
  {...tooltip}
174
176
  data={tooltipData}
175
177
  x={tooltipX}
178
+ marginLeft={marginLeft}
179
+ marginTop={marginTop}
176
180
  tickName={tickName}
177
181
  series={series}
182
+ width={width}
183
+ height={height}
178
184
  />
179
185
  )}
180
186
  {brush && <Brush config={brush} width={width} />}