@easyv/charts 1.3.3 → 1.3.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 (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 +10 -11
  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 +228 -225
  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 +88 -88
  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,225 +1,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
- const { seriesStep, seriesWidth, seriesStart } = getSeriesInfo({
30
- step,
31
- bandLength,
32
- paddingInner,
33
- paddingOuter,
34
- });
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 + 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
+
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
+ };