@easyv/charts 1.2.14 → 1.3.0
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/lib/components/Axis.js +10 -10
- package/lib/components/Background.js +13 -3
- package/lib/components/Band.js +8 -8
- package/lib/components/Carousel.js +2 -2
- package/lib/components/CartesianChart.js +5 -1
- package/lib/components/ConicalGradient.js +21 -21
- package/lib/components/Indicator.js +2 -2
- package/lib/components/Label.js +11 -12
- package/lib/components/Lighter.js +179 -179
- package/lib/components/LinearGradient.js +2 -2
- package/lib/components/Marquee.js +3 -3
- package/lib/components/StackData.js +2 -4
- package/lib/components/StereoBar.js +14 -14
- package/lib/components/TextOverflow.js +3 -3
- package/lib/css/index.module.css +41 -41
- package/lib/css/piechart.module.css +26 -26
- package/lib/element/ConicGradient.js +72 -72
- package/lib/hooks/useAnimateData.js +5 -5
- package/lib/hooks/useAxes.js +5 -5
- package/lib/hooks/useCarouselAxisX.js +5 -5
- package/lib/hooks/useExtentData.js +10 -8
- package/lib/hooks/useFilterData.js +5 -5
- package/lib/hooks/useStackData.js +11 -10
- package/lib/hooks/useTooltip.js +10 -10
- package/lib/utils/index.js +62 -41
- package/package.json +54 -53
- package/src/components/AnimateData.tsx +24 -24
- package/src/components/Axis.tsx +354 -354
- package/src/components/Background.tsx +62 -45
- package/src/components/Band.tsx +169 -173
- package/src/components/BaseLine.js +82 -82
- package/src/components/Brush.js +159 -159
- package/src/components/Carousel.tsx +144 -144
- package/src/components/CartesianChart.js +33 -22
- package/src/components/Chart.js +99 -99
- package/src/components/ChartContainer.tsx +63 -63
- package/src/components/ConicalGradient.js +258 -258
- package/src/components/ExtentData.js +17 -17
- package/src/components/FilterData.js +23 -23
- package/src/components/Indicator.js +13 -13
- package/src/components/Label.js +225 -206
- package/src/components/Legend.js +158 -158
- package/src/components/Lighter.jsx +173 -173
- package/src/components/Line.js +145 -145
- package/src/components/LinearGradient.js +29 -29
- package/src/components/Mapping.js +71 -71
- package/src/components/Marquee.js +88 -88
- package/src/components/PieChart.js +1278 -1278
- package/src/components/StackData.js +16 -20
- package/src/components/StereoBar.tsx +307 -311
- package/src/components/TextOverflow.js +51 -51
- package/src/components/Tooltip.js +169 -169
- package/src/components/index.js +55 -55
- package/src/context/index.js +2 -2
- package/src/css/index.module.css +41 -41
- 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 +90 -90
- package/src/hooks/index.js +17 -17
- package/src/hooks/useAnimateData.ts +67 -67
- package/src/hooks/useAxes.js +144 -144
- package/src/hooks/useCarouselAxisX.js +163 -163
- package/src/hooks/useExtentData.js +89 -88
- package/src/hooks/useFilterData.js +72 -72
- package/src/hooks/useStackData.js +101 -100
- package/src/hooks/useTooltip.ts +96 -96
- package/src/index.js +6 -6
- package/src/types/index.d.ts +67 -67
- package/src/utils/index.js +731 -714
- package/tsconfig.json +23 -23
package/src/components/Label.js
CHANGED
|
@@ -1,206 +1,225 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 轴类图表标签
|
|
3
|
-
*/
|
|
4
|
-
import { memo, useContext } from 'react';
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
},
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
);
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
{
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
)
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
case '
|
|
181
|
-
return {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
};
|
|
185
|
-
case '
|
|
186
|
-
return {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
};
|
|
190
|
-
case '
|
|
191
|
-
return {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
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
|
+
};
|