@easyv/charts 1.0.73 → 1.0.74

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 (63) hide show
  1. package/.babelrc +8 -8
  2. package/lib/components/AnimateData.js +2 -2
  3. package/lib/components/Axis.js +12 -12
  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/LinearGradient.js +2 -2
  10. package/lib/css/index.module.css +41 -41
  11. package/lib/css/piechart.module.css +26 -26
  12. package/lib/hooks/useAnimateData.js +5 -5
  13. package/lib/hooks/useAxes.js +5 -5
  14. package/lib/hooks/useCarouselAxisX.js +5 -5
  15. package/lib/hooks/useExtentData.js +6 -6
  16. package/lib/hooks/useFilterData.js +5 -5
  17. package/lib/hooks/useStackData.js +5 -5
  18. package/lib/hooks/useTooltip.js +10 -10
  19. package/lib/utils/index.js +3 -3
  20. package/package.json +34 -34
  21. package/src/components/AnimateData.tsx +24 -24
  22. package/src/components/Axis.tsx +336 -336
  23. package/src/components/Background.tsx +45 -45
  24. package/src/components/Band.tsx +171 -171
  25. package/src/components/Brush.js +159 -159
  26. package/src/components/Carousel.tsx +144 -144
  27. package/src/components/Chart.js +99 -99
  28. package/src/components/ChartContainer.tsx +63 -63
  29. package/src/components/ConicalGradient.js +258 -258
  30. package/src/components/ExtentData.js +17 -17
  31. package/src/components/FilterData.js +23 -23
  32. package/src/components/Indicator.js +13 -13
  33. package/src/components/Label.js +206 -206
  34. package/src/components/Legend.js +158 -158
  35. package/src/components/Lighter.jsx +162 -162
  36. package/src/components/Line.js +144 -144
  37. package/src/components/LinearGradient.js +29 -29
  38. package/src/components/Mapping.js +71 -71
  39. package/src/components/PieChart.js +1093 -1093
  40. package/src/components/StackData.js +20 -20
  41. package/src/components/StereoBar.tsx +298 -298
  42. package/src/components/Tooltip.js +133 -133
  43. package/src/components/index.js +49 -49
  44. package/src/context/index.js +2 -2
  45. package/src/css/index.module.css +41 -41
  46. package/src/css/piechart.module.css +26 -26
  47. package/src/element/ConicGradient.jsx +55 -55
  48. package/src/element/Line.tsx +33 -33
  49. package/src/element/index.ts +3 -3
  50. package/src/formatter/index.js +1 -1
  51. package/src/formatter/legend.js +90 -90
  52. package/src/hooks/index.js +17 -17
  53. package/src/hooks/useAnimateData.ts +62 -62
  54. package/src/hooks/useAxes.js +144 -144
  55. package/src/hooks/useCarouselAxisX.js +163 -163
  56. package/src/hooks/useExtentData.js +88 -88
  57. package/src/hooks/useFilterData.js +72 -72
  58. package/src/hooks/useStackData.js +100 -100
  59. package/src/hooks/useTooltip.ts +96 -96
  60. package/src/index.js +6 -6
  61. package/src/types/index.d.ts +59 -59
  62. package/src/utils/index.js +692 -692
  63. package/tsconfig.json +22 -22
@@ -1,158 +1,158 @@
1
- /**
2
- * 图例
3
- */
4
- import React, { memo, useCallback } from 'react';
5
- import { getIcon, sortPie } from '../utils';
6
-
7
- const defaultFont = {
8
- fontStyle: 'normal',
9
- fontWeight: 'normal',
10
- };
11
-
12
- export default memo(
13
- ({
14
- series,
15
- config,
16
- config: {
17
- show,
18
- order = '',
19
- interactive,
20
- layout: {
21
- alignment = 'right center',
22
- gridTemplateColumns,
23
- gridGap: { gridColumnGap, gridRowGap },
24
- translate: { x, y },
25
- },
26
- font: { italic, bold, ...font } = defaultFont,
27
- unselect: { opacity = 1 } = {},
28
- },
29
- filterData,
30
- formatter,
31
- }) => {
32
- if (!show) return null;
33
-
34
- const _series = sortPie(series, order);
35
-
36
- const [_alignment, position] = alignment.split(' ');
37
- const length = _series.length;
38
-
39
- const onClick = useCallback(
40
- (e) => {
41
- const { dataset } = e.currentTarget;
42
- const { name } = dataset;
43
- filterData && interactive && filterData(name);
44
- },
45
- [interactive, filterData]
46
- );
47
-
48
- return (
49
- <div
50
- className='__easyv-legend-wrapper'
51
- style={{
52
- position: 'absolute',
53
- height: 'auto',
54
- display: 'flex',
55
- transform: 'translate3d(' + x + 'px, ' + y + 'px, 0px)',
56
- ...getPosition(position, _alignment),
57
- }}
58
- >
59
- <ul
60
- style={{
61
- display: 'grid',
62
- gridGap: gridRowGap + 'px ' + gridColumnGap + 'px',
63
- gridTemplateColumns:
64
- 'repeat(' + Math.min(gridTemplateColumns, length) + ', 1fr)',
65
- }}
66
- >
67
- {_series.map((series, index) => {
68
- const { type, name, displayName, icon, selected } = series;
69
- const _icon = getIcon(type, icon);
70
- return (
71
- <li
72
- key={index}
73
- onClick={onClick}
74
- data-name={name}
75
- style={{
76
- display: 'flex',
77
- opacity: selected === false ? opacity / 100 : 1,
78
- alignItems: 'center',
79
- gap: _icon.gap,
80
- }}
81
- >
82
- {formatter ? (
83
- formatter(series, config)
84
- ) : (
85
- <>
86
- <span style={_icon} />
87
- <span
88
- style={{
89
- ...font,
90
- fontStyle: italic ? 'italic' : 'normal',
91
- fontWeight: bold ? 'bold' : 'normal',
92
- }}
93
- >
94
- {displayName || name}
95
- </span>
96
- </>
97
- )}
98
- </li>
99
- );
100
- })}
101
- </ul>
102
- </div>
103
- );
104
- }
105
- );
106
-
107
- const getPosition = (position, alignment) => {
108
- switch (position) {
109
- case 'top':
110
- return {
111
- left: 0,
112
- right: 0,
113
- top: 5,
114
- justifyContent:
115
- alignment === 'center'
116
- ? 'center'
117
- : alignment === 'left'
118
- ? 'flex-start'
119
- : 'flex-end',
120
- };
121
- case 'right':
122
- return {
123
- top: 0,
124
- bottom: 0,
125
- right: 10,
126
- alignItems:
127
- alignment === 'center'
128
- ? 'center'
129
- : alignment === 'left'
130
- ? 'flex-start'
131
- : 'flex-end',
132
- };
133
- case 'left':
134
- return {
135
- top: 0,
136
- bottom: 0,
137
- left: 10,
138
- alignItems:
139
- alignment === 'center'
140
- ? 'center'
141
- : alignment === 'left'
142
- ? 'flex-start'
143
- : 'flex-end',
144
- };
145
- default:
146
- return {
147
- left: 0,
148
- right: 0,
149
- bottom: 5,
150
- justifyContent:
151
- alignment === 'center'
152
- ? 'center'
153
- : alignment === 'left'
154
- ? 'flex-start'
155
- : 'flex-end',
156
- };
157
- }
158
- };
1
+ /**
2
+ * 图例
3
+ */
4
+ import React, { memo, useCallback } from 'react';
5
+ import { getIcon, sortPie } from '../utils';
6
+
7
+ const defaultFont = {
8
+ fontStyle: 'normal',
9
+ fontWeight: 'normal',
10
+ };
11
+
12
+ export default memo(
13
+ ({
14
+ series,
15
+ config,
16
+ config: {
17
+ show,
18
+ order = '',
19
+ interactive,
20
+ layout: {
21
+ alignment = 'right center',
22
+ gridTemplateColumns,
23
+ gridGap: { gridColumnGap, gridRowGap },
24
+ translate: { x, y },
25
+ },
26
+ font: { italic, bold, ...font } = defaultFont,
27
+ unselect: { opacity = 1 } = {},
28
+ },
29
+ filterData,
30
+ formatter,
31
+ }) => {
32
+ if (!show) return null;
33
+
34
+ const _series = sortPie(series, order);
35
+
36
+ const [_alignment, position] = alignment.split(' ');
37
+ const length = _series.length;
38
+
39
+ const onClick = useCallback(
40
+ (e) => {
41
+ const { dataset } = e.currentTarget;
42
+ const { name } = dataset;
43
+ filterData && interactive && filterData(name);
44
+ },
45
+ [interactive, filterData]
46
+ );
47
+
48
+ return (
49
+ <div
50
+ className='__easyv-legend-wrapper'
51
+ style={{
52
+ position: 'absolute',
53
+ height: 'auto',
54
+ display: 'flex',
55
+ transform: 'translate3d(' + x + 'px, ' + y + 'px, 0px)',
56
+ ...getPosition(position, _alignment),
57
+ }}
58
+ >
59
+ <ul
60
+ style={{
61
+ display: 'grid',
62
+ gridGap: gridRowGap + 'px ' + gridColumnGap + 'px',
63
+ gridTemplateColumns:
64
+ 'repeat(' + Math.min(gridTemplateColumns, length) + ', 1fr)',
65
+ }}
66
+ >
67
+ {_series.map((series, index) => {
68
+ const { type, name, displayName, icon, selected } = series;
69
+ const _icon = getIcon(type, icon);
70
+ return (
71
+ <li
72
+ key={index}
73
+ onClick={onClick}
74
+ data-name={name}
75
+ style={{
76
+ display: 'flex',
77
+ opacity: selected === false ? opacity / 100 : 1,
78
+ alignItems: 'center',
79
+ gap: _icon.gap,
80
+ }}
81
+ >
82
+ {formatter ? (
83
+ formatter(series, config)
84
+ ) : (
85
+ <>
86
+ <span style={_icon} />
87
+ <span
88
+ style={{
89
+ ...font,
90
+ fontStyle: italic ? 'italic' : 'normal',
91
+ fontWeight: bold ? 'bold' : 'normal',
92
+ }}
93
+ >
94
+ {displayName || name}
95
+ </span>
96
+ </>
97
+ )}
98
+ </li>
99
+ );
100
+ })}
101
+ </ul>
102
+ </div>
103
+ );
104
+ }
105
+ );
106
+
107
+ const getPosition = (position, alignment) => {
108
+ switch (position) {
109
+ case 'top':
110
+ return {
111
+ left: 0,
112
+ right: 0,
113
+ top: 5,
114
+ justifyContent:
115
+ alignment === 'center'
116
+ ? 'center'
117
+ : alignment === 'left'
118
+ ? 'flex-start'
119
+ : 'flex-end',
120
+ };
121
+ case 'right':
122
+ return {
123
+ top: 0,
124
+ bottom: 0,
125
+ right: 10,
126
+ alignItems:
127
+ alignment === 'center'
128
+ ? 'center'
129
+ : alignment === 'left'
130
+ ? 'flex-start'
131
+ : 'flex-end',
132
+ };
133
+ case 'left':
134
+ return {
135
+ top: 0,
136
+ bottom: 0,
137
+ left: 10,
138
+ alignItems:
139
+ alignment === 'center'
140
+ ? 'center'
141
+ : alignment === 'left'
142
+ ? 'flex-start'
143
+ : 'flex-end',
144
+ };
145
+ default:
146
+ return {
147
+ left: 0,
148
+ right: 0,
149
+ bottom: 5,
150
+ justifyContent:
151
+ alignment === 'center'
152
+ ? 'center'
153
+ : alignment === 'left'
154
+ ? 'flex-start'
155
+ : 'flex-end',
156
+ };
157
+ }
158
+ };
@@ -1,162 +1,162 @@
1
- /**
2
- * 区域图发光跟踪路径
3
- */
4
- import React, { useState, useEffect, useRef } from 'react';
5
- import { scaleLinear } from 'd3v7';
6
- import { getColorList } from '../utils';
7
-
8
- const accelerateStep = 2;
9
- const loop = false;
10
-
11
- export default ({
12
- path: d,
13
- config: { length: curveLength, width, fill, unitStep },
14
- }) => {
15
- const pointIndexRef = useRef(0);
16
- const raf = useRef(null);
17
- const [points, setPoints] = useState([]);
18
- const [lighter, setLighter] = useState(null);
19
- const [path, setPath] = useState(null);
20
- const pointLength = points.length;
21
- const totalLength = getLength(pointLength, curveLength);
22
- const easingFunc = easing.linear;
23
- const interpolateList = getColorsInterpolate(getColorList(fill));
24
-
25
- const drawLigher = () => {
26
- const currentPointLength = pointIndexRef.current;
27
- const pointIndex =
28
- currentPointLength >= totalLength
29
- ? loop
30
- ? curveLength
31
- : 0
32
- : currentPointLength +
33
- unitStep +
34
- Math.floor(
35
- easingFunc(pointIndexRef.current / totalLength) * accelerateStep
36
- );
37
-
38
- const overstep = pointIndex - pointLength;
39
- const startIndex = getPointIndex(pointIndex, pointLength, curveLength);
40
- const endIndex = getPointIndex(
41
- pointIndex + curveLength,
42
- pointLength,
43
- curveLength
44
- );
45
- const overstepPoints =
46
- loop && overstep > 0 ? points.slice(0, overstep) : [];
47
-
48
- drawCircle(
49
- Array.from(lighter.children),
50
- [...points.slice(startIndex, endIndex), ...overstepPoints],
51
- interpolateList
52
- );
53
-
54
- pointIndexRef.current = pointIndex;
55
- raf.current = requestAnimationFrame(drawLigher);
56
- };
57
-
58
- useEffect(() => {
59
- if (path) {
60
- const totalLength = path.getTotalLength();
61
- const points = [];
62
- for (let i = 0; i < totalLength; i++) {
63
- const { x, y } = path.getPointAtLength(i);
64
- points.push({
65
- x,
66
- y,
67
- });
68
- }
69
- setPoints(points);
70
- }
71
- }, [d, path]);
72
-
73
- useEffect(() => {
74
- raf.current = requestAnimationFrame(drawLigher);
75
- return () => {
76
- cancelAnimationFrame(raf.current);
77
- };
78
- }, [drawLigher]);
79
-
80
- return (
81
- <>
82
- <path ref={setPath} d={d} fill='none' stroke='none' />
83
- <g ref={setLighter}>
84
- {points.map((item, index) => (
85
- <circle key={index} r={width} fill='none' />
86
- ))}
87
- </g>
88
- </>
89
- );
90
- };
91
-
92
- const drawCircle = (children, points, interpolateList) => {
93
- const pointLength = points.length;
94
- points.forEach(({ x, y }, index) => {
95
- children[index].setAttribute('cx', x);
96
- children[index].setAttribute('cy', y);
97
- children[index].setAttribute(
98
- 'fill',
99
- getColor(index / pointLength, interpolateList)
100
- );
101
- });
102
- };
103
- const getColor = (x, interpolateList) => {
104
- return interpolateList(x);
105
- };
106
- const getLength = (pointLength, length) => {
107
- if (length > pointLength) {
108
- return pointLength * 2;
109
- }
110
-
111
- return pointLength + length;
112
- };
113
-
114
- const getColorsInterpolate = (colors) => {
115
- const length = colors.length;
116
- if (!!(length < 2))
117
- return scaleLinear()
118
- .domain([0, 1])
119
- .range([colors[0].color || '#000', colors[0].color || '#000']);
120
- const linear = scaleLinear()
121
- .domain(colors.map((d) => d.offset))
122
- .range(colors.map((d) => d.color));
123
- return linear;
124
- };
125
- const easing = {
126
- linear() {
127
- return 0;
128
- },
129
-
130
- easeIn(k) {
131
- return Math.pow(k, 3);
132
- },
133
-
134
- easeOut(k) {
135
- return 1 - easing.easeIn(1 - k);
136
- },
137
-
138
- easeInOut(k) {
139
- return k < 0.5
140
- ? easing.easeIn(k * 2) / 2
141
- : 1 - easing.easeIn(2 - 2 * k) / 2;
142
- },
143
-
144
- easeOutIn(k) {
145
- return k < 0.5
146
- ? 0.5 * (1 - easing.easeIn(1 - 2 * k))
147
- : 0.5 * easing.easeIn(k * 2 - 1) + 0.5;
148
- },
149
- };
150
- const getPointIndex = (pointIndex, pointLength, curveLength) => {
151
- let index = pointIndex - curveLength;
152
-
153
- if (index < 0) {
154
- return 0;
155
- }
156
-
157
- if (index >= pointLength) {
158
- return pointLength - 1;
159
- }
160
-
161
- return index;
162
- };
1
+ /**
2
+ * 区域图发光跟踪路径
3
+ */
4
+ import React, { useState, useEffect, useRef } from 'react';
5
+ import { scaleLinear } from 'd3v7';
6
+ import { getColorList } from '../utils';
7
+
8
+ const accelerateStep = 2;
9
+ const loop = false;
10
+
11
+ export default ({
12
+ path: d,
13
+ config: { length: curveLength, width, fill, unitStep },
14
+ }) => {
15
+ const pointIndexRef = useRef(0);
16
+ const raf = useRef(null);
17
+ const [points, setPoints] = useState([]);
18
+ const [lighter, setLighter] = useState(null);
19
+ const [path, setPath] = useState(null);
20
+ const pointLength = points.length;
21
+ const totalLength = getLength(pointLength, curveLength);
22
+ const easingFunc = easing.linear;
23
+ const interpolateList = getColorsInterpolate(getColorList(fill));
24
+
25
+ const drawLigher = () => {
26
+ const currentPointLength = pointIndexRef.current;
27
+ const pointIndex =
28
+ currentPointLength >= totalLength
29
+ ? loop
30
+ ? curveLength
31
+ : 0
32
+ : currentPointLength +
33
+ unitStep +
34
+ Math.floor(
35
+ easingFunc(pointIndexRef.current / totalLength) * accelerateStep
36
+ );
37
+
38
+ const overstep = pointIndex - pointLength;
39
+ const startIndex = getPointIndex(pointIndex, pointLength, curveLength);
40
+ const endIndex = getPointIndex(
41
+ pointIndex + curveLength,
42
+ pointLength,
43
+ curveLength
44
+ );
45
+ const overstepPoints =
46
+ loop && overstep > 0 ? points.slice(0, overstep) : [];
47
+
48
+ drawCircle(
49
+ Array.from(lighter.children),
50
+ [...points.slice(startIndex, endIndex), ...overstepPoints],
51
+ interpolateList
52
+ );
53
+
54
+ pointIndexRef.current = pointIndex;
55
+ raf.current = requestAnimationFrame(drawLigher);
56
+ };
57
+
58
+ useEffect(() => {
59
+ if (path) {
60
+ const totalLength = path.getTotalLength();
61
+ const points = [];
62
+ for (let i = 0; i < totalLength; i++) {
63
+ const { x, y } = path.getPointAtLength(i);
64
+ points.push({
65
+ x,
66
+ y,
67
+ });
68
+ }
69
+ setPoints(points);
70
+ }
71
+ }, [d, path]);
72
+
73
+ useEffect(() => {
74
+ raf.current = requestAnimationFrame(drawLigher);
75
+ return () => {
76
+ cancelAnimationFrame(raf.current);
77
+ };
78
+ }, [drawLigher]);
79
+
80
+ return (
81
+ <>
82
+ <path ref={setPath} d={d} fill='none' stroke='none' />
83
+ <g ref={setLighter}>
84
+ {points.map((item, index) => (
85
+ <circle key={index} r={width} fill='none' />
86
+ ))}
87
+ </g>
88
+ </>
89
+ );
90
+ };
91
+
92
+ const drawCircle = (children, points, interpolateList) => {
93
+ const pointLength = points.length;
94
+ points.forEach(({ x, y }, index) => {
95
+ children[index].setAttribute('cx', x);
96
+ children[index].setAttribute('cy', y);
97
+ children[index].setAttribute(
98
+ 'fill',
99
+ getColor(index / pointLength, interpolateList)
100
+ );
101
+ });
102
+ };
103
+ const getColor = (x, interpolateList) => {
104
+ return interpolateList(x);
105
+ };
106
+ const getLength = (pointLength, length) => {
107
+ if (length > pointLength) {
108
+ return pointLength * 2;
109
+ }
110
+
111
+ return pointLength + length;
112
+ };
113
+
114
+ const getColorsInterpolate = (colors) => {
115
+ const length = colors.length;
116
+ if (!!(length < 2))
117
+ return scaleLinear()
118
+ .domain([0, 1])
119
+ .range([colors[0].color || '#000', colors[0].color || '#000']);
120
+ const linear = scaleLinear()
121
+ .domain(colors.map((d) => d.offset))
122
+ .range(colors.map((d) => d.color));
123
+ return linear;
124
+ };
125
+ const easing = {
126
+ linear() {
127
+ return 0;
128
+ },
129
+
130
+ easeIn(k) {
131
+ return Math.pow(k, 3);
132
+ },
133
+
134
+ easeOut(k) {
135
+ return 1 - easing.easeIn(1 - k);
136
+ },
137
+
138
+ easeInOut(k) {
139
+ return k < 0.5
140
+ ? easing.easeIn(k * 2) / 2
141
+ : 1 - easing.easeIn(2 - 2 * k) / 2;
142
+ },
143
+
144
+ easeOutIn(k) {
145
+ return k < 0.5
146
+ ? 0.5 * (1 - easing.easeIn(1 - 2 * k))
147
+ : 0.5 * easing.easeIn(k * 2 - 1) + 0.5;
148
+ },
149
+ };
150
+ const getPointIndex = (pointIndex, pointLength, curveLength) => {
151
+ let index = pointIndex - curveLength;
152
+
153
+ if (index < 0) {
154
+ return 0;
155
+ }
156
+
157
+ if (index >= pointLength) {
158
+ return pointLength - 1;
159
+ }
160
+
161
+ return index;
162
+ };