@easyv/charts 1.3.1 → 1.3.2

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 (70) 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/Chart.js +2 -1
  8. package/lib/components/ConicalGradient.js +21 -21
  9. package/lib/components/Indicator.js +2 -2
  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/package.json +54 -54
  25. package/src/components/AnimateData.tsx +24 -24
  26. package/src/components/Axis.tsx +354 -354
  27. package/src/components/Background.tsx +62 -62
  28. package/src/components/Band.tsx +169 -169
  29. package/src/components/BaseLine.js +82 -82
  30. package/src/components/Brush.js +159 -159
  31. package/src/components/Carousel.tsx +144 -144
  32. package/src/components/Chart.js +99 -99
  33. package/src/components/ChartContainer.tsx +63 -63
  34. package/src/components/ConicalGradient.js +258 -258
  35. package/src/components/ExtentData.js +17 -17
  36. package/src/components/FilterData.js +23 -23
  37. package/src/components/Indicator.js +13 -13
  38. package/src/components/Label.js +225 -225
  39. package/src/components/Legend.js +158 -158
  40. package/src/components/Lighter.jsx +173 -173
  41. package/src/components/Line.js +145 -145
  42. package/src/components/LinearGradient.js +29 -29
  43. package/src/components/Mapping.js +71 -71
  44. package/src/components/Marquee.js +88 -88
  45. package/src/components/PieChart.js +1278 -1278
  46. package/src/components/StackData.js +16 -16
  47. package/src/components/StereoBar.tsx +307 -307
  48. package/src/components/TextOverflow.js +51 -51
  49. package/src/components/Tooltip.js +169 -169
  50. package/src/components/index.js +55 -55
  51. package/src/context/index.js +2 -2
  52. package/src/css/index.module.css +41 -41
  53. package/src/css/piechart.module.css +26 -26
  54. package/src/element/ConicGradient.jsx +55 -55
  55. package/src/element/Line.tsx +33 -33
  56. package/src/element/index.ts +3 -3
  57. package/src/formatter/index.js +1 -1
  58. package/src/formatter/legend.js +90 -90
  59. package/src/hooks/index.js +17 -17
  60. package/src/hooks/useAnimateData.ts +67 -67
  61. package/src/hooks/useAxes.js +144 -144
  62. package/src/hooks/useCarouselAxisX.js +163 -163
  63. package/src/hooks/useExtentData.js +89 -89
  64. package/src/hooks/useFilterData.js +72 -72
  65. package/src/hooks/useStackData.js +101 -101
  66. package/src/hooks/useTooltip.ts +96 -96
  67. package/src/index.js +6 -6
  68. package/src/types/index.d.ts +67 -67
  69. package/src/utils/index.js +738 -738
  70. 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
- 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
+ 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
+ };