@easyv/charts 1.5.28 → 1.5.30

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