@easyv/charts 1.3.8 → 1.3.9

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