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