@easyv/charts 1.3.27 → 1.3.29

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 (53) hide show
  1. package/.babelrc +8 -8
  2. package/.husky/commit-msg +3 -3
  3. package/CHANGELOG.md +18 -18
  4. package/lib/components/Background.js +2 -2
  5. package/lib/components/CartesianChart.js +15 -2
  6. package/lib/components/ConicalGradient.js +21 -21
  7. package/lib/components/Indicator.js +2 -2
  8. package/lib/components/Lighter.js +179 -179
  9. package/lib/components/LinearGradient.js +2 -2
  10. package/lib/components/PieChart.js +3 -40
  11. package/lib/css/index.module.css +41 -41
  12. package/lib/css/piechart.module.css +26 -26
  13. package/lib/element/ConicGradient.js +72 -72
  14. package/lib/hooks/useAnimateData.js +5 -5
  15. package/lib/hooks/useCarouselAxisX.js +14 -8
  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/package.json +1 -1
  20. package/src/components/Background.tsx +62 -62
  21. package/src/components/Band.tsx +192 -192
  22. package/src/components/Brush.js +159 -159
  23. package/src/components/CartesianChart.js +5 -2
  24. package/src/components/Chart.js +99 -99
  25. package/src/components/ChartContainer.tsx +63 -63
  26. package/src/components/ConicalGradient.js +258 -258
  27. package/src/components/ExtentData.js +17 -17
  28. package/src/components/Indicator.js +13 -13
  29. package/src/components/Label.js +225 -225
  30. package/src/components/Lighter.jsx +173 -173
  31. package/src/components/Line.js +150 -150
  32. package/src/components/LinearGradient.js +29 -29
  33. package/src/components/PieChart.js +6 -51
  34. package/src/components/StereoBar.tsx +307 -307
  35. package/src/components/index.js +55 -55
  36. package/src/context/index.js +2 -2
  37. package/src/css/index.module.css +41 -41
  38. package/src/css/piechart.module.css +26 -26
  39. package/src/element/ConicGradient.jsx +55 -55
  40. package/src/element/Line.tsx +33 -33
  41. package/src/element/index.ts +3 -3
  42. package/src/formatter/index.js +1 -1
  43. package/src/formatter/legend.js +90 -90
  44. package/src/hooks/index.js +17 -17
  45. package/src/hooks/useAnimateData.ts +67 -67
  46. package/src/hooks/useCarouselAxisX.js +11 -7
  47. package/src/hooks/useFilterData.js +72 -72
  48. package/src/hooks/useStackData.js +101 -101
  49. package/src/hooks/useTooltip.ts +96 -96
  50. package/src/index.js +6 -6
  51. package/src/types/index.d.ts +67 -67
  52. package/src/utils/index.js +757 -757
  53. package/tsconfig.json +23 -23
@@ -1,225 +1,225 @@
1
- /**
2
- * 轴类图表标签
3
- */
4
- import { memo, useContext } from 'react';
5
- import { getTranslate2d, getSeriesInfo } from '../utils';
6
- import { chartContext } from '../context';
7
-
8
- export default memo(
9
- ({
10
- config: {
11
- seriesIntervalWidth: paddingInner = 0,
12
- paddingInner: paddingOuter = 0,
13
- label,
14
- icon,
15
- },
16
- config,
17
- bandLength = 0,
18
- data,
19
- xAxis: { scaler: xScaler, step, direction },
20
- yAxis: { scaler: yScaler },
21
- triggerClick,
22
- }) => {
23
- const lineType = config.hasOwnProperty('line'); // 堆叠处理
24
- const showIcon = icon && icon.show;
25
- const showLabel = label && label.show;
26
-
27
- if (!(data.length && (showIcon || showLabel))) return null;
28
- const { width, height } = useContext(chartContext);
29
-
30
- const { seriesStep, seriesWidth, seriesStart } = getSeriesInfo({
31
- step,
32
- bandLength,
33
- paddingInner,
34
- paddingOuter,
35
- });
36
- const isVertical = direction === 'vertical';
37
- const _position = label.position;
38
- return (
39
- <g className='__easyv-label'>
40
- {data.map(
41
- (
42
- { index, bound: [start, end], data, data: { x, y, showY, s } },
43
- i
44
- ) => {
45
- const y1 = yScaler(isVertical ? end : start);
46
-
47
- // 处理z型折线图和堆叠柱图的逻辑冲突
48
- const y2 = lineType
49
- ? start
50
- ? yScaler(isVertical ? start : end - start)
51
- : yScaler(isVertical ? start : end)
52
- : yScaler(isVertical ? start : end);
53
-
54
- // const y2 = yScaler(isVertical ? start : end);
55
- const positionX =
56
- xScaler(x) - step / 2 + seriesStart + index * seriesStep;
57
-
58
- if (isNaN(positionX)) return null;
59
- const position = positionX + (config.line?step:seriesWidth) / 2;
60
- const labelPosition = isVertical
61
- ? getVerticalLabel({
62
- position: _position,
63
- y,
64
- y1,
65
- y2,
66
- width,
67
- })
68
- : getHorizontalLabel({
69
- position: _position,
70
- y,
71
- y1,
72
- y2,
73
- height,
74
- });
75
- const attr = isVertical
76
- ? {
77
- ...labelPosition,
78
- y: position,
79
- dominantBaseline: 'middle',
80
- }
81
- : {
82
- ...labelPosition,
83
- x: position,
84
- textAnchor: 'middle',
85
- };
86
- return (
87
- <g
88
- key={i}
89
- onClick={triggerClick}
90
- data-data={JSON.stringify(data)}
91
- >
92
- {showIcon && !isNaN(attr.y) && (
93
- <Icon cx={attr.x} cy={attr.y} config={icon} />
94
- )}
95
- {showLabel && <Label value={showY} config={label} {...attr} />}
96
- </g>
97
- );
98
- }
99
- )}
100
- </g>
101
- );
102
- }
103
- );
104
-
105
- const Label = ({
106
- x,
107
- y,
108
- value,
109
- config: {
110
- font,
111
- translate: { x: translateX = 0, y: translateY = 0 },
112
- },
113
- textAnchor = 'middle',
114
- dominantBaseline = 'middle',
115
- }) => {
116
- return (
117
- <text
118
- x={x}
119
- y={y}
120
- transform={getTranslate2d({
121
- x: translateX,
122
- y: translateY * (value >= 0 ? 1 : -1),
123
- })}
124
- textAnchor={textAnchor}
125
- dominantBaseline={dominantBaseline}
126
- {...font}
127
- >
128
- {value}
129
- </text>
130
- );
131
- };
132
- const Icon = ({
133
- cx,
134
- cy,
135
- config: {
136
- mode,
137
- inner,
138
- outer,
139
- color,
140
- radius,
141
- image,
142
- size: { width, height },
143
- },
144
- }) =>
145
- mode == 'single' ? (
146
- <Circle cx={cx} cy={cy} color={color} radius={radius} />
147
- ) : mode == 'double' ? (
148
- <>
149
- <Circle cx={cx} cy={cy} {...inner} />
150
- <Circle cx={cx} cy={cy} {...outer} />
151
- </>
152
- ) : (
153
- <>
154
- <image
155
- width={width}
156
- height={height}
157
- x={cx - width / 2}
158
- y={cy - height / 2}
159
- xlinkHref={window.appConfig.ASSETS_URL + image}
160
- />
161
- </>
162
- );
163
-
164
- const Circle = ({ cx, cy, color, radius }) => (
165
- <circle cx={cx} cy={cy} fill={color} r={radius} stroke='none' />
166
- );
167
-
168
- const getVerticalLabel = ({ position = 'outerStart', width, y, y1, y2 }) => {
169
- switch (position) {
170
- case 'start':
171
- return {
172
- x: y > 0 ? y2 : y1,
173
- textAnchor: 'start',
174
- };
175
- case 'middle':
176
- return {
177
- x: (y1 + y2) / 2,
178
- textAnchor: 'middle',
179
- };
180
- case 'end':
181
- return {
182
- x: y > 0 ? y1 : y2,
183
- textAnchor: 'end',
184
- };
185
- case 'outerStart':
186
- return {
187
- x: y1,
188
- textAnchor: y > 0 ? 'start' : 'end',
189
- };
190
- case 'chartStart':
191
- return {
192
- x: y > 0 ? width : 0,
193
- textAnchor: y > 0 ? 'start' : 'end',
194
- };
195
- }
196
- };
197
- const getHorizontalLabel = ({ position = 'outerStart', height, y, y1, y2 }) => {
198
- switch (position) {
199
- case 'start':
200
- return {
201
- y: y > 0 ? y1 : y2,
202
- dominantBaseline: 'text-after-edge',
203
- };
204
- case 'middle':
205
- return {
206
- y: (y1 + y2) / 2,
207
- dominantBaseline: 'middle',
208
- };
209
- case 'end':
210
- return {
211
- y: y > 0 ? y2 : y1,
212
- dominantBaseline: 'text-before-edge',
213
- };
214
- case 'outerStart':
215
- return {
216
- y: y2,
217
- dominantBaseline: y >= 0 ? 'text-after-edge' : 'text-before-edge',
218
- };
219
- case 'chartStart':
220
- return {
221
- y: y > 0 ? 0 : height,
222
- dominantBaseline: y > 0 ? 'text-after-edge' : 'text-before-edge',
223
- };
224
- }
225
- };
1
+ /**
2
+ * 轴类图表标签
3
+ */
4
+ import { memo, useContext } from 'react';
5
+ import { getTranslate2d, getSeriesInfo } from '../utils';
6
+ import { chartContext } from '../context';
7
+
8
+ export default memo(
9
+ ({
10
+ config: {
11
+ seriesIntervalWidth: paddingInner = 0,
12
+ paddingInner: paddingOuter = 0,
13
+ label,
14
+ icon,
15
+ },
16
+ config,
17
+ bandLength = 0,
18
+ data,
19
+ xAxis: { scaler: xScaler, step, direction },
20
+ yAxis: { scaler: yScaler },
21
+ triggerClick,
22
+ }) => {
23
+ const lineType = config.hasOwnProperty('line'); // 堆叠处理
24
+ const showIcon = icon && icon.show;
25
+ const showLabel = label && label.show;
26
+
27
+ if (!(data.length && (showIcon || showLabel))) return null;
28
+ const { width, height } = useContext(chartContext);
29
+
30
+ const { seriesStep, seriesWidth, seriesStart } = getSeriesInfo({
31
+ step,
32
+ bandLength,
33
+ paddingInner,
34
+ paddingOuter,
35
+ });
36
+ const isVertical = direction === 'vertical';
37
+ const _position = label.position;
38
+ return (
39
+ <g className='__easyv-label'>
40
+ {data.map(
41
+ (
42
+ { index, bound: [start, end], data, data: { x, y, showY, s } },
43
+ i
44
+ ) => {
45
+ const y1 = yScaler(isVertical ? end : start);
46
+
47
+ // 处理z型折线图和堆叠柱图的逻辑冲突
48
+ const y2 = lineType
49
+ ? start
50
+ ? yScaler(isVertical ? start : end - start)
51
+ : yScaler(isVertical ? start : end)
52
+ : yScaler(isVertical ? start : end);
53
+
54
+ // const y2 = yScaler(isVertical ? start : end);
55
+ const positionX =
56
+ xScaler(x) - step / 2 + seriesStart + index * seriesStep;
57
+
58
+ if (isNaN(positionX)) return null;
59
+ const position = positionX + (config.line?step:seriesWidth) / 2;
60
+ const labelPosition = isVertical
61
+ ? getVerticalLabel({
62
+ position: _position,
63
+ y,
64
+ y1,
65
+ y2,
66
+ width,
67
+ })
68
+ : getHorizontalLabel({
69
+ position: _position,
70
+ y,
71
+ y1,
72
+ y2,
73
+ height,
74
+ });
75
+ const attr = isVertical
76
+ ? {
77
+ ...labelPosition,
78
+ y: position,
79
+ dominantBaseline: 'middle',
80
+ }
81
+ : {
82
+ ...labelPosition,
83
+ x: position,
84
+ textAnchor: 'middle',
85
+ };
86
+ return (
87
+ <g
88
+ key={i}
89
+ onClick={triggerClick}
90
+ data-data={JSON.stringify(data)}
91
+ >
92
+ {showIcon && !isNaN(attr.y) && (
93
+ <Icon cx={attr.x} cy={attr.y} config={icon} />
94
+ )}
95
+ {showLabel && <Label value={showY} config={label} {...attr} />}
96
+ </g>
97
+ );
98
+ }
99
+ )}
100
+ </g>
101
+ );
102
+ }
103
+ );
104
+
105
+ const Label = ({
106
+ x,
107
+ y,
108
+ value,
109
+ config: {
110
+ font,
111
+ translate: { x: translateX = 0, y: translateY = 0 },
112
+ },
113
+ textAnchor = 'middle',
114
+ dominantBaseline = 'middle',
115
+ }) => {
116
+ return (
117
+ <text
118
+ x={x}
119
+ y={y}
120
+ transform={getTranslate2d({
121
+ x: translateX,
122
+ y: translateY * (value >= 0 ? 1 : -1),
123
+ })}
124
+ textAnchor={textAnchor}
125
+ dominantBaseline={dominantBaseline}
126
+ {...font}
127
+ >
128
+ {value}
129
+ </text>
130
+ );
131
+ };
132
+ const Icon = ({
133
+ cx,
134
+ cy,
135
+ config: {
136
+ mode,
137
+ inner,
138
+ outer,
139
+ color,
140
+ radius,
141
+ image,
142
+ size: { width, height },
143
+ },
144
+ }) =>
145
+ mode == 'single' ? (
146
+ <Circle cx={cx} cy={cy} color={color} radius={radius} />
147
+ ) : mode == 'double' ? (
148
+ <>
149
+ <Circle cx={cx} cy={cy} {...inner} />
150
+ <Circle cx={cx} cy={cy} {...outer} />
151
+ </>
152
+ ) : (
153
+ <>
154
+ <image
155
+ width={width}
156
+ height={height}
157
+ x={cx - width / 2}
158
+ y={cy - height / 2}
159
+ xlinkHref={window.appConfig.ASSETS_URL + image}
160
+ />
161
+ </>
162
+ );
163
+
164
+ const Circle = ({ cx, cy, color, radius }) => (
165
+ <circle cx={cx} cy={cy} fill={color} r={radius} stroke='none' />
166
+ );
167
+
168
+ const getVerticalLabel = ({ position = 'outerStart', width, y, y1, y2 }) => {
169
+ switch (position) {
170
+ case 'start':
171
+ return {
172
+ x: y > 0 ? y2 : y1,
173
+ textAnchor: 'start',
174
+ };
175
+ case 'middle':
176
+ return {
177
+ x: (y1 + y2) / 2,
178
+ textAnchor: 'middle',
179
+ };
180
+ case 'end':
181
+ return {
182
+ x: y > 0 ? y1 : y2,
183
+ textAnchor: 'end',
184
+ };
185
+ case 'outerStart':
186
+ return {
187
+ x: y1,
188
+ textAnchor: y > 0 ? 'start' : 'end',
189
+ };
190
+ case 'chartStart':
191
+ return {
192
+ x: y > 0 ? width : 0,
193
+ textAnchor: y > 0 ? 'start' : 'end',
194
+ };
195
+ }
196
+ };
197
+ const getHorizontalLabel = ({ position = 'outerStart', height, y, y1, y2 }) => {
198
+ switch (position) {
199
+ case 'start':
200
+ return {
201
+ y: y > 0 ? y1 : y2,
202
+ dominantBaseline: 'text-after-edge',
203
+ };
204
+ case 'middle':
205
+ return {
206
+ y: (y1 + y2) / 2,
207
+ dominantBaseline: 'middle',
208
+ };
209
+ case 'end':
210
+ return {
211
+ y: y > 0 ? y2 : y1,
212
+ dominantBaseline: 'text-before-edge',
213
+ };
214
+ case 'outerStart':
215
+ return {
216
+ y: y2,
217
+ dominantBaseline: y >= 0 ? 'text-after-edge' : 'text-before-edge',
218
+ };
219
+ case 'chartStart':
220
+ return {
221
+ y: y > 0 ? 0 : height,
222
+ dominantBaseline: y > 0 ? 'text-after-edge' : 'text-before-edge',
223
+ };
224
+ }
225
+ };