@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,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,173 +1,173 @@
1
- /**
2
- * 区域图发光跟踪路径
3
- */
4
- import React, {
5
- useState,
6
- useEffect,
7
- useRef,
8
- useCallback,
9
- useMemo,
10
- } from 'react';
11
- import { scaleLinear } from 'd3v7';
12
- import { getColorList } from '../utils';
13
- import { svgPathProperties } from 'svg-path-properties';
14
-
15
- export default ({
16
- path: d,
17
- config,
18
- config: { length: curveLength, width, fill, unitStep },
19
- }) => {
20
- const pointIndexRef = useRef(0);
21
- const raf = useRef(null);
22
- const [points, setPoints] = useState([]);
23
- const [lighter, setLighter] = useState(null);
24
- const pointLength = points.length;
25
- const totalLength = getLength(pointLength, curveLength);
26
- const easingFunc = easing.linear;
27
-
28
- const interpolateList = useMemo(
29
- () => getColorsInterpolate(getColorList(fill)),
30
- [fill]
31
- );
32
-
33
- const drawLigher = useCallback(() => {
34
- const STEP = 2;
35
- const LOOP = false;
36
- if (lighter && lighter.children) {
37
- const currentPointLength = pointIndexRef.current;
38
- const pointIndex =
39
- currentPointLength >= totalLength
40
- ? LOOP
41
- ? curveLength
42
- : 0
43
- : currentPointLength +
44
- unitStep +
45
- Math.floor(easingFunc(pointIndexRef.current / totalLength) * STEP);
46
-
47
- const overstep = pointIndex - pointLength;
48
- const startIndex = getPointIndex(pointIndex, pointLength, curveLength);
49
- const endIndex = getPointIndex(
50
- pointIndex + curveLength,
51
- pointLength,
52
- curveLength
53
- );
54
- const overstepPoints =
55
- LOOP && overstep > 0 ? points.slice(0, overstep) : [];
56
- drawCircle(
57
- Array.from(lighter.children),
58
- [...points.slice(startIndex, endIndex), ...overstepPoints],
59
- interpolateList
60
- );
61
-
62
- pointIndexRef.current = pointIndex;
63
- }
64
-
65
- raf.current = requestAnimationFrame(drawLigher);
66
- }, [lighter, totalLength, curveLength, unitStep, points, interpolateList]);
67
- useEffect(() => {
68
- const path = new svgPathProperties(d);
69
- const totalLength = path.getTotalLength();
70
- const points = [];
71
- for (let i = 0; i < totalLength; i++) {
72
- const { x, y } = path.getPointAtLength(i);
73
- points.push({
74
- index: i,
75
- x,
76
- y,
77
- });
78
- }
79
- setPoints(points);
80
- }, [d, config]);
81
-
82
- useEffect(() => {
83
- raf.current = requestAnimationFrame(drawLigher);
84
- return () => {
85
- cancelAnimationFrame(raf.current);
86
- };
87
- }, [drawLigher]);
88
- return (
89
- <g ref={setLighter}>
90
- {points.map(({ x, y }, index) => (
91
- <circle cx={x} cy={y} key={index} r={width} fill='none' />
92
- ))}
93
- </g>
94
- );
95
- };
96
-
97
- const drawCircle = (children, points, interpolateList) => {
98
- const pointLength = points.length;
99
- // const [startPoint] = points;
100
- // const startIndex = startPoint ? startPoint.index : 0;
101
- children.forEach((child, index) => {
102
- const pointIndex = points.findIndex(({ index: i }) => i == index);
103
- child.setAttribute(
104
- 'fill',
105
- pointIndex > -1
106
- ? getColor(
107
- pointIndex / pointLength, //TODO: 颜色插值尚需完善
108
- interpolateList
109
- )
110
- : 'none'
111
- );
112
- });
113
- };
114
- const getColor = (x, interpolateList) => {
115
- return interpolateList(x);
116
- };
117
- const getLength = (pointLength, length) => {
118
- if (length > pointLength) {
119
- return pointLength * 2;
120
- }
121
-
122
- return pointLength + length;
123
- };
124
-
125
- const getColorsInterpolate = (colors) => {
126
- const length = colors.length;
127
- if (!!(length < 2))
128
- return scaleLinear()
129
- .domain([0, 1])
130
- .range([colors[0].color || '#000', colors[0].color || '#000']);
131
- const linear = scaleLinear()
132
- .domain(colors.map((d) => d.offset))
133
- .range(colors.map((d) => d.color));
134
- return linear;
135
- };
136
- const easing = {
137
- linear() {
138
- return 0;
139
- },
140
-
141
- easeIn(k) {
142
- return Math.pow(k, 3);
143
- },
144
-
145
- easeOut(k) {
146
- return 1 - easing.easeIn(1 - k);
147
- },
148
-
149
- easeInOut(k) {
150
- return k < 0.5
151
- ? easing.easeIn(k * 2) / 2
152
- : 1 - easing.easeIn(2 - 2 * k) / 2;
153
- },
154
-
155
- easeOutIn(k) {
156
- return k < 0.5
157
- ? 0.5 * (1 - easing.easeIn(1 - 2 * k))
158
- : 0.5 * easing.easeIn(k * 2 - 1) + 0.5;
159
- },
160
- };
161
- const getPointIndex = (pointIndex, pointLength, curveLength) => {
162
- let index = pointIndex - curveLength;
163
-
164
- if (index < 0) {
165
- return 0;
166
- }
167
-
168
- if (index >= pointLength) {
169
- return pointLength - 1;
170
- }
171
-
172
- return index;
173
- };
1
+ /**
2
+ * 区域图发光跟踪路径
3
+ */
4
+ import React, {
5
+ useState,
6
+ useEffect,
7
+ useRef,
8
+ useCallback,
9
+ useMemo,
10
+ } from 'react';
11
+ import { scaleLinear } from 'd3v7';
12
+ import { getColorList } from '../utils';
13
+ import { svgPathProperties } from 'svg-path-properties';
14
+
15
+ export default ({
16
+ path: d,
17
+ config,
18
+ config: { length: curveLength, width, fill, unitStep },
19
+ }) => {
20
+ const pointIndexRef = useRef(0);
21
+ const raf = useRef(null);
22
+ const [points, setPoints] = useState([]);
23
+ const [lighter, setLighter] = useState(null);
24
+ const pointLength = points.length;
25
+ const totalLength = getLength(pointLength, curveLength);
26
+ const easingFunc = easing.linear;
27
+
28
+ const interpolateList = useMemo(
29
+ () => getColorsInterpolate(getColorList(fill)),
30
+ [fill]
31
+ );
32
+
33
+ const drawLigher = useCallback(() => {
34
+ const STEP = 2;
35
+ const LOOP = false;
36
+ if (lighter && lighter.children) {
37
+ const currentPointLength = pointIndexRef.current;
38
+ const pointIndex =
39
+ currentPointLength >= totalLength
40
+ ? LOOP
41
+ ? curveLength
42
+ : 0
43
+ : currentPointLength +
44
+ unitStep +
45
+ Math.floor(easingFunc(pointIndexRef.current / totalLength) * STEP);
46
+
47
+ const overstep = pointIndex - pointLength;
48
+ const startIndex = getPointIndex(pointIndex, pointLength, curveLength);
49
+ const endIndex = getPointIndex(
50
+ pointIndex + curveLength,
51
+ pointLength,
52
+ curveLength
53
+ );
54
+ const overstepPoints =
55
+ LOOP && overstep > 0 ? points.slice(0, overstep) : [];
56
+ drawCircle(
57
+ Array.from(lighter.children),
58
+ [...points.slice(startIndex, endIndex), ...overstepPoints],
59
+ interpolateList
60
+ );
61
+
62
+ pointIndexRef.current = pointIndex;
63
+ }
64
+
65
+ raf.current = requestAnimationFrame(drawLigher);
66
+ }, [lighter, totalLength, curveLength, unitStep, points, interpolateList]);
67
+ useEffect(() => {
68
+ const path = new svgPathProperties(d);
69
+ const totalLength = path.getTotalLength();
70
+ const points = [];
71
+ for (let i = 0; i < totalLength; i++) {
72
+ const { x, y } = path.getPointAtLength(i);
73
+ points.push({
74
+ index: i,
75
+ x,
76
+ y,
77
+ });
78
+ }
79
+ setPoints(points);
80
+ }, [d, config]);
81
+
82
+ useEffect(() => {
83
+ raf.current = requestAnimationFrame(drawLigher);
84
+ return () => {
85
+ cancelAnimationFrame(raf.current);
86
+ };
87
+ }, [drawLigher]);
88
+ return (
89
+ <g ref={setLighter}>
90
+ {points.map(({ x, y }, index) => (
91
+ <circle cx={x} cy={y} key={index} r={width} fill='none' />
92
+ ))}
93
+ </g>
94
+ );
95
+ };
96
+
97
+ const drawCircle = (children, points, interpolateList) => {
98
+ const pointLength = points.length;
99
+ // const [startPoint] = points;
100
+ // const startIndex = startPoint ? startPoint.index : 0;
101
+ children.forEach((child, index) => {
102
+ const pointIndex = points.findIndex(({ index: i }) => i == index);
103
+ child.setAttribute(
104
+ 'fill',
105
+ pointIndex > -1
106
+ ? getColor(
107
+ pointIndex / pointLength, //TODO: 颜色插值尚需完善
108
+ interpolateList
109
+ )
110
+ : 'none'
111
+ );
112
+ });
113
+ };
114
+ const getColor = (x, interpolateList) => {
115
+ return interpolateList(x);
116
+ };
117
+ const getLength = (pointLength, length) => {
118
+ if (length > pointLength) {
119
+ return pointLength * 2;
120
+ }
121
+
122
+ return pointLength + length;
123
+ };
124
+
125
+ const getColorsInterpolate = (colors) => {
126
+ const length = colors.length;
127
+ if (!!(length < 2))
128
+ return scaleLinear()
129
+ .domain([0, 1])
130
+ .range([colors[0].color || '#000', colors[0].color || '#000']);
131
+ const linear = scaleLinear()
132
+ .domain(colors.map((d) => d.offset))
133
+ .range(colors.map((d) => d.color));
134
+ return linear;
135
+ };
136
+ const easing = {
137
+ linear() {
138
+ return 0;
139
+ },
140
+
141
+ easeIn(k) {
142
+ return Math.pow(k, 3);
143
+ },
144
+
145
+ easeOut(k) {
146
+ return 1 - easing.easeIn(1 - k);
147
+ },
148
+
149
+ easeInOut(k) {
150
+ return k < 0.5
151
+ ? easing.easeIn(k * 2) / 2
152
+ : 1 - easing.easeIn(2 - 2 * k) / 2;
153
+ },
154
+
155
+ easeOutIn(k) {
156
+ return k < 0.5
157
+ ? 0.5 * (1 - easing.easeIn(1 - 2 * k))
158
+ : 0.5 * easing.easeIn(k * 2 - 1) + 0.5;
159
+ },
160
+ };
161
+ const getPointIndex = (pointIndex, pointLength, curveLength) => {
162
+ let index = pointIndex - curveLength;
163
+
164
+ if (index < 0) {
165
+ return 0;
166
+ }
167
+
168
+ if (index >= pointLength) {
169
+ return pointLength - 1;
170
+ }
171
+
172
+ return index;
173
+ };