@easyv/charts 1.7.35 → 1.7.37

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