@easyv/charts 1.2.14 → 1.3.2
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/lib/components/Background.js +11 -1
- package/lib/components/Band.js +8 -8
- package/lib/components/CartesianChart.js +5 -1
- package/lib/components/Chart.js +2 -1
- package/lib/components/Label.js +11 -12
- package/lib/components/StackData.js +2 -4
- package/lib/components/StereoBar.js +14 -14
- package/lib/hooks/useExtentData.js +4 -2
- package/lib/hooks/useStackData.js +6 -5
- package/lib/utils/index.js +68 -41
- package/package.json +3 -2
- package/src/components/Background.tsx +21 -4
- package/src/components/Band.tsx +10 -14
- package/src/components/CartesianChart.js +33 -22
- package/src/components/Chart.js +1 -1
- package/src/components/Label.js +59 -40
- package/src/components/StackData.js +2 -6
- package/src/components/StereoBar.tsx +304 -308
- package/src/hooks/useExtentData.js +4 -3
- package/src/hooks/useStackData.js +5 -4
- package/src/utils/index.js +32 -8
- package/tsconfig.json +2 -2
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
Brush,
|
|
25
25
|
Label,
|
|
26
26
|
Mapping,
|
|
27
|
-
BaseLine
|
|
27
|
+
BaseLine,
|
|
28
28
|
} from '.';
|
|
29
29
|
|
|
30
30
|
const Chart = memo(
|
|
@@ -41,11 +41,12 @@ const Chart = memo(
|
|
|
41
41
|
legend,
|
|
42
42
|
},
|
|
43
43
|
series,
|
|
44
|
+
bandLength,
|
|
44
45
|
tooltip,
|
|
45
46
|
baseLine: {
|
|
46
|
-
orientation:baseLineOri='',
|
|
47
|
+
orientation: baseLineOri = '',
|
|
47
48
|
config: baseLineConfig = {},
|
|
48
|
-
data: baseLineData = []
|
|
49
|
+
data: baseLineData = [],
|
|
49
50
|
},
|
|
50
51
|
tooltip: {
|
|
51
52
|
config: tooltipConfig = {},
|
|
@@ -55,7 +56,7 @@ const Chart = memo(
|
|
|
55
56
|
},
|
|
56
57
|
style,
|
|
57
58
|
data,
|
|
58
|
-
filterData
|
|
59
|
+
filterData,
|
|
59
60
|
}) => {
|
|
60
61
|
const context = useContext(chartContext);
|
|
61
62
|
const {
|
|
@@ -101,10 +102,10 @@ const Chart = memo(
|
|
|
101
102
|
const indicatorAttr = isVertical
|
|
102
103
|
? { width: chartWidth, height: indicatorWidth, y: position }
|
|
103
104
|
: {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
105
|
+
height: chartHeight,
|
|
106
|
+
width: indicatorWidth,
|
|
107
|
+
x: position,
|
|
108
|
+
};
|
|
108
109
|
|
|
109
110
|
const onInteraction = useCallback(
|
|
110
111
|
(e) => {
|
|
@@ -134,6 +135,7 @@ const Chart = memo(
|
|
|
134
135
|
length={isVertical ? chartWidth : chartHeight}
|
|
135
136
|
axis={axisX}
|
|
136
137
|
config={background}
|
|
138
|
+
bandLength={bandLength}
|
|
137
139
|
/>
|
|
138
140
|
)}
|
|
139
141
|
{[...axes.values()].map((item, index) => {
|
|
@@ -152,6 +154,7 @@ const Chart = memo(
|
|
|
152
154
|
<Component
|
|
153
155
|
key={index}
|
|
154
156
|
{...config}
|
|
157
|
+
bandLength={bandLength}
|
|
155
158
|
xAxis={axisX}
|
|
156
159
|
yAxis={yAxis}
|
|
157
160
|
triggerClick={onInteraction}
|
|
@@ -166,6 +169,7 @@ const Chart = memo(
|
|
|
166
169
|
<Label
|
|
167
170
|
key={index}
|
|
168
171
|
{...config}
|
|
172
|
+
bandLength={bandLength}
|
|
169
173
|
xAxis={axisX}
|
|
170
174
|
yAxis={yAxis}
|
|
171
175
|
triggerClick={onInteraction}
|
|
@@ -173,20 +177,27 @@ const Chart = memo(
|
|
|
173
177
|
)
|
|
174
178
|
);
|
|
175
179
|
})}
|
|
176
|
-
{baseLineData &&
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
180
|
+
{baseLineData &&
|
|
181
|
+
baseLineData.length > 0 &&
|
|
182
|
+
baseLineData.map((item, index) => {
|
|
183
|
+
const {
|
|
184
|
+
line: { yOrZ },
|
|
185
|
+
} = baseLineConfig[index];
|
|
186
|
+
const yAxis = axes.get(yOrZ);
|
|
187
|
+
return (
|
|
188
|
+
yAxis && (
|
|
189
|
+
<BaseLine
|
|
190
|
+
height={height}
|
|
191
|
+
width={width}
|
|
192
|
+
key={index}
|
|
193
|
+
config={baseLineConfig[index]}
|
|
194
|
+
baseLineOri={baseLineOri}
|
|
195
|
+
yAxis={yAxis}
|
|
196
|
+
data={item}
|
|
197
|
+
/>
|
|
198
|
+
)
|
|
199
|
+
);
|
|
200
|
+
})}
|
|
190
201
|
</ChartContainer>
|
|
191
202
|
<Legend {...legend} filterData={filterData} series={series} />
|
|
192
203
|
{showTooltip && (
|
package/src/components/Chart.js
CHANGED
package/src/components/Label.js
CHANGED
|
@@ -2,11 +2,7 @@
|
|
|
2
2
|
* 轴类图表标签
|
|
3
3
|
*/
|
|
4
4
|
import { memo, useContext } from 'react';
|
|
5
|
-
import {
|
|
6
|
-
getTranslate2d,
|
|
7
|
-
getBandwidth,
|
|
8
|
-
getBandSeriesStepAndWidth,
|
|
9
|
-
} from '../utils';
|
|
5
|
+
import { getTranslate2d, getSeriesInfo } from '../utils';
|
|
10
6
|
import { chartContext } from '../context';
|
|
11
7
|
|
|
12
8
|
export default memo(
|
|
@@ -24,68 +20,78 @@ export default memo(
|
|
|
24
20
|
yAxis: { scaler: yScaler },
|
|
25
21
|
triggerClick,
|
|
26
22
|
}) => {
|
|
27
|
-
const lineType = config.hasOwnProperty('line')
|
|
23
|
+
const lineType = config.hasOwnProperty('line'); // 堆叠处理
|
|
28
24
|
const showIcon = icon && icon.show;
|
|
29
25
|
const showLabel = label && label.show;
|
|
30
26
|
|
|
31
27
|
if (!(data.length && (showIcon || showLabel))) return null;
|
|
32
28
|
const { width, height } = useContext(chartContext);
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
width: bandwidth,
|
|
36
|
-
paddingInner,
|
|
29
|
+
const { seriesStep, seriesWidth, seriesStart } = getSeriesInfo({
|
|
30
|
+
step,
|
|
37
31
|
bandLength,
|
|
32
|
+
paddingInner,
|
|
33
|
+
paddingOuter,
|
|
38
34
|
});
|
|
39
35
|
|
|
40
|
-
const offset =
|
|
41
|
-
(seriesWidth + paddingInner * seriesStep) * bandLength -
|
|
42
|
-
paddingInner * seriesStep;
|
|
43
36
|
const isVertical = direction === 'vertical';
|
|
44
37
|
const _position = label.position;
|
|
45
38
|
return (
|
|
46
39
|
<g className='__easyv-label'>
|
|
47
40
|
{data.map(
|
|
48
|
-
(
|
|
41
|
+
(
|
|
42
|
+
{ index, bound: [start, end], data, data: { x, y, showY, s } },
|
|
43
|
+
i
|
|
44
|
+
) => {
|
|
49
45
|
const y1 = yScaler(isVertical ? end : start);
|
|
50
|
-
|
|
51
|
-
|
|
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
|
+
|
|
52
54
|
// const y2 = yScaler(isVertical ? start : end);
|
|
53
|
-
const positionX =
|
|
55
|
+
const positionX =
|
|
56
|
+
xScaler(x) - step / 2 + seriesStart + index * seriesStep;
|
|
57
|
+
|
|
54
58
|
if (isNaN(positionX)) return null;
|
|
55
59
|
const position = positionX + seriesWidth / 2;
|
|
56
60
|
const labelPosition = isVertical
|
|
57
61
|
? getVerticalLabel({
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
position: _position,
|
|
63
|
+
y,
|
|
64
|
+
y1,
|
|
65
|
+
y2,
|
|
66
|
+
width,
|
|
67
|
+
})
|
|
64
68
|
: getHorizontalLabel({
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
position: _position,
|
|
70
|
+
y,
|
|
71
|
+
y1,
|
|
72
|
+
y2,
|
|
73
|
+
height,
|
|
74
|
+
});
|
|
71
75
|
const attr = isVertical
|
|
72
76
|
? {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
+
...labelPosition,
|
|
78
|
+
y: position,
|
|
79
|
+
dominantBaseline: 'middle',
|
|
80
|
+
}
|
|
77
81
|
: {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
+
...labelPosition,
|
|
83
|
+
x: position,
|
|
84
|
+
textAnchor: 'middle',
|
|
85
|
+
};
|
|
82
86
|
return (
|
|
83
87
|
<g
|
|
84
88
|
key={i}
|
|
85
89
|
onClick={triggerClick}
|
|
86
90
|
data-data={JSON.stringify(data)}
|
|
87
91
|
>
|
|
88
|
-
{showIcon &&
|
|
92
|
+
{showIcon && !isNaN(attr.y) && (
|
|
93
|
+
<Icon cx={attr.x} cy={attr.y} config={icon} />
|
|
94
|
+
)}
|
|
89
95
|
{showLabel && <Label value={showY} config={label} {...attr} />}
|
|
90
96
|
</g>
|
|
91
97
|
);
|
|
@@ -123,7 +129,19 @@ const Label = ({
|
|
|
123
129
|
</text>
|
|
124
130
|
);
|
|
125
131
|
};
|
|
126
|
-
const Icon = ({
|
|
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
|
+
}) =>
|
|
127
145
|
mode == 'single' ? (
|
|
128
146
|
<Circle cx={cx} cy={cy} color={color} radius={radius} />
|
|
129
147
|
) : mode == 'double' ? (
|
|
@@ -138,7 +156,8 @@ const Icon = ({ cx, cy, config: { mode, inner, outer, color, radius, image, size
|
|
|
138
156
|
height={height}
|
|
139
157
|
x={cx - width / 2}
|
|
140
158
|
y={cy - height / 2}
|
|
141
|
-
xlinkHref={window.appConfig.ASSETS_URL + image}
|
|
159
|
+
xlinkHref={window.appConfig.ASSETS_URL + image}
|
|
160
|
+
/>
|
|
142
161
|
</>
|
|
143
162
|
);
|
|
144
163
|
|
|
@@ -5,16 +5,12 @@ import { memo } from 'react';
|
|
|
5
5
|
import { useStackData } from '../hooks';
|
|
6
6
|
export default (Component) => {
|
|
7
7
|
return memo(({ config: { series, ...config }, data, ...props }) => {
|
|
8
|
-
const
|
|
8
|
+
const _config = useStackData({
|
|
9
9
|
series,
|
|
10
10
|
data,
|
|
11
11
|
});
|
|
12
12
|
return (
|
|
13
|
-
<Component
|
|
14
|
-
{...props}
|
|
15
|
-
config={{ ...config, series: _series }}
|
|
16
|
-
data={data}
|
|
17
|
-
/>
|
|
13
|
+
<Component {...props} config={{ ...config, ..._config }} data={data} />
|
|
18
14
|
);
|
|
19
15
|
});
|
|
20
16
|
};
|