@easyv/charts 1.6.13 → 1.6.14

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