@easyv/charts 1.4.15 → 1.4.17
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/.husky/commit-msg +1 -1
- package/lib/components/Axis.js +139 -85
- package/lib/components/Band.js +50 -16
- package/lib/components/BaseLine.js +16 -5
- package/lib/components/CartesianChart.js +13 -13
- package/lib/components/Label.js +49 -33
- package/lib/components/TextOverflow.js +4 -1
- package/lib/hooks/useAxes.js +250 -61
- package/lib/hooks/useExtentData.js +44 -9
- package/package.json +55 -54
- package/src/components/Axis.tsx +246 -157
- package/src/components/Band.tsx +91 -56
- package/src/components/BaseLine.js +22 -5
- package/src/components/CartesianChart.js +7 -6
- package/src/components/Label.js +56 -46
- package/src/components/TextOverflow.tsx +4 -1
- package/src/hooks/useAxes.js +336 -117
- package/src/hooks/useExtentData.js +37 -10
package/package.json
CHANGED
|
@@ -1,54 +1,55 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@easyv/charts",
|
|
3
|
-
"version": "1.4.
|
|
4
|
-
"description": "",
|
|
5
|
-
"main": "lib/index.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"make": "babel src -d lib --extensions .ts,.tsx,.js,.jsx && cp -r src/css lib",
|
|
8
|
-
"prepare": "husky install"
|
|
9
|
-
},
|
|
10
|
-
"keywords": [],
|
|
11
|
-
"author": "",
|
|
12
|
-
"license": "ISC",
|
|
13
|
-
"devDependencies": {
|
|
14
|
-
"@babel/cli": "^7.17.10",
|
|
15
|
-
"@babel/core": "^7.17.10",
|
|
16
|
-
"@babel/plugin-proposal-class-properties": "^7.16.7",
|
|
17
|
-
"@babel/plugin-proposal-export-default-from": "^7.16.7",
|
|
18
|
-
"@babel/plugin-transform-runtime": "^7.17.10",
|
|
19
|
-
"@babel/preset-env": "^7.17.10",
|
|
20
|
-
"@babel/preset-react": "^7.16.7",
|
|
21
|
-
"@babel/preset-typescript": "^7.16.7",
|
|
22
|
-
"@commitlint/cli": "^17.
|
|
23
|
-
"@commitlint/config-conventional": "^16.2.4",
|
|
24
|
-
"@types/d3": "^7.0.0",
|
|
25
|
-
"@types/react": "^18.0.12",
|
|
26
|
-
"@types/react-dom": "^18.0.5",
|
|
27
|
-
"babel-plugin-transform-import-styles": "^0.0.11",
|
|
28
|
-
"babel-preset-env": "^1.7.0",
|
|
29
|
-
"cz-conventional-changelog": "^3.3.0",
|
|
30
|
-
"husky": "^7.0.4",
|
|
31
|
-
"load-styles": "^2.0.0",
|
|
32
|
-
"standard-version": "^9.3.2"
|
|
33
|
-
},
|
|
34
|
-
"dependencies": {
|
|
35
|
-
"@easyv/utils": "^0.0.45",
|
|
36
|
-
"d3v7": "npm:d3@^7.0.0",
|
|
37
|
-
"gitignore": "^0.7.0",
|
|
38
|
-
"mrm": "^4.0.0",
|
|
39
|
-
"popmotion": "^9.3.6",
|
|
40
|
-
"react": "^17.0.2",
|
|
41
|
-
"svg-path-properties": "^1.0.11",
|
|
42
|
-
"svg-points": "^6.0.1"
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@easyv/charts",
|
|
3
|
+
"version": "1.4.17",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"make": "babel src -d lib --extensions .ts,.tsx,.js,.jsx && cp -r src/css lib",
|
|
8
|
+
"prepare": "husky install"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [],
|
|
11
|
+
"author": "",
|
|
12
|
+
"license": "ISC",
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"@babel/cli": "^7.17.10",
|
|
15
|
+
"@babel/core": "^7.17.10",
|
|
16
|
+
"@babel/plugin-proposal-class-properties": "^7.16.7",
|
|
17
|
+
"@babel/plugin-proposal-export-default-from": "^7.16.7",
|
|
18
|
+
"@babel/plugin-transform-runtime": "^7.17.10",
|
|
19
|
+
"@babel/preset-env": "^7.17.10",
|
|
20
|
+
"@babel/preset-react": "^7.16.7",
|
|
21
|
+
"@babel/preset-typescript": "^7.16.7",
|
|
22
|
+
"@commitlint/cli": "^17.6.7",
|
|
23
|
+
"@commitlint/config-conventional": "^16.2.4",
|
|
24
|
+
"@types/d3": "^7.0.0",
|
|
25
|
+
"@types/react": "^18.0.12",
|
|
26
|
+
"@types/react-dom": "^18.0.5",
|
|
27
|
+
"babel-plugin-transform-import-styles": "^0.0.11",
|
|
28
|
+
"babel-preset-env": "^1.7.0",
|
|
29
|
+
"cz-conventional-changelog": "^3.3.0",
|
|
30
|
+
"husky": "^7.0.4",
|
|
31
|
+
"load-styles": "^2.0.0",
|
|
32
|
+
"standard-version": "^9.3.2"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@easyv/utils": "^0.0.45",
|
|
36
|
+
"d3v7": "npm:d3@^7.0.0",
|
|
37
|
+
"gitignore": "^0.7.0",
|
|
38
|
+
"mrm": "^4.0.0",
|
|
39
|
+
"popmotion": "^9.3.6",
|
|
40
|
+
"react": "^17.0.2",
|
|
41
|
+
"svg-path-properties": "^1.0.11",
|
|
42
|
+
"svg-points": "^6.0.1",
|
|
43
|
+
"yarn": "^1.22.19"
|
|
44
|
+
},
|
|
45
|
+
"config": {
|
|
46
|
+
"commitizen": {
|
|
47
|
+
"path": "./node_modules/cz-conventional-changelog"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"standard-version": {
|
|
51
|
+
"skip": {
|
|
52
|
+
"commit": true
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
package/src/components/Axis.tsx
CHANGED
|
@@ -8,24 +8,24 @@ import React, {
|
|
|
8
8
|
useContext,
|
|
9
9
|
CSSProperties,
|
|
10
10
|
MouseEventHandler,
|
|
11
|
-
} from
|
|
12
|
-
import { getTickCoord, getGridCoord, getFontStyle } from
|
|
13
|
-
import { chartContext } from
|
|
14
|
-
import { Line } from
|
|
15
|
-
import TextOverflow from
|
|
11
|
+
} from "react";
|
|
12
|
+
import { getTickCoord, getGridCoord, getFontStyle } from "../utils";
|
|
13
|
+
import { chartContext } from "../context";
|
|
14
|
+
import { Line } from "../element";
|
|
15
|
+
import TextOverflow from "./TextOverflow";
|
|
16
16
|
const defaultEvent = () => {};
|
|
17
17
|
const defaultAppearance = {
|
|
18
|
-
angle:0,
|
|
19
|
-
count:6,
|
|
20
|
-
speed:5,
|
|
21
|
-
width:"fit-content",
|
|
22
|
-
textOverflow:"ellipsis"
|
|
18
|
+
angle: 0,
|
|
19
|
+
count: 6,
|
|
20
|
+
speed: 5,
|
|
21
|
+
width: "fit-content",
|
|
22
|
+
textOverflow: "ellipsis",
|
|
23
23
|
};
|
|
24
24
|
const defaultAlign: Align = {
|
|
25
|
-
textAnchor:
|
|
26
|
-
dominantBaseline:
|
|
25
|
+
textAnchor: "middle",
|
|
26
|
+
dominantBaseline: "middle",
|
|
27
27
|
};
|
|
28
|
-
const defaultOrientation =
|
|
28
|
+
const defaultOrientation = "bottom";
|
|
29
29
|
const defaultTickSize = 6;
|
|
30
30
|
const defaultFormatter: (
|
|
31
31
|
d: string,
|
|
@@ -37,12 +37,12 @@ const getAxesPath: (
|
|
|
37
37
|
{ width, height }: Context
|
|
38
38
|
) => string = (orientation, { width, height }) => {
|
|
39
39
|
switch (orientation) {
|
|
40
|
-
case
|
|
41
|
-
case
|
|
42
|
-
return
|
|
43
|
-
case
|
|
44
|
-
case
|
|
45
|
-
return
|
|
40
|
+
case "top":
|
|
41
|
+
case "bottom":
|
|
42
|
+
return "M-0.5, 0H" + width;
|
|
43
|
+
case "left":
|
|
44
|
+
case "right":
|
|
45
|
+
return "M0, -0.5V" + (height + 0.5);
|
|
46
46
|
}
|
|
47
47
|
};
|
|
48
48
|
/**
|
|
@@ -59,32 +59,32 @@ const getLayout: (
|
|
|
59
59
|
orientation: Orientation,
|
|
60
60
|
rotate: number
|
|
61
61
|
) => {
|
|
62
|
-
transform:string
|
|
62
|
+
transform: string;
|
|
63
63
|
directionX: number;
|
|
64
64
|
directionY: number;
|
|
65
65
|
} = (orientation, rotate) => {
|
|
66
66
|
switch (orientation) {
|
|
67
|
-
case
|
|
67
|
+
case "top":
|
|
68
68
|
return {
|
|
69
|
-
transform
|
|
69
|
+
transform: `translate(-50%,-100%) rotate(${rotate}deg)`,
|
|
70
70
|
directionX: 1,
|
|
71
71
|
directionY: -1,
|
|
72
72
|
};
|
|
73
|
-
case
|
|
73
|
+
case "bottom":
|
|
74
74
|
return {
|
|
75
|
-
transform
|
|
75
|
+
transform: `translate(-50%,0) rotate(${rotate}deg)`,
|
|
76
76
|
directionX: 1,
|
|
77
77
|
directionY: 1,
|
|
78
78
|
};
|
|
79
|
-
case
|
|
79
|
+
case "left":
|
|
80
80
|
return {
|
|
81
|
-
transform
|
|
81
|
+
transform: `translate(-100%,-50%) rotate(${rotate}deg)`,
|
|
82
82
|
directionX: -1,
|
|
83
83
|
directionY: 1,
|
|
84
84
|
};
|
|
85
|
-
case
|
|
85
|
+
case "right":
|
|
86
86
|
return {
|
|
87
|
-
transform
|
|
87
|
+
transform: `translate(0,-50%) rotate(${rotate}deg)`,
|
|
88
88
|
directionX: 1,
|
|
89
89
|
directionY: 1,
|
|
90
90
|
};
|
|
@@ -93,29 +93,45 @@ const getLayout: (
|
|
|
93
93
|
const AxisLine: ({
|
|
94
94
|
orientation,
|
|
95
95
|
config,
|
|
96
|
+
isClipAxis,
|
|
97
|
+
clipAxisRange,
|
|
96
98
|
}: any) => ReactComponentElement<ComponentType> | null = ({
|
|
97
99
|
orientation = defaultOrientation,
|
|
98
100
|
config: { show, color, lineWidth },
|
|
101
|
+
isClipAxis = false,
|
|
102
|
+
clipAxisRange = [],
|
|
99
103
|
}) => {
|
|
100
104
|
if (!show) return null;
|
|
101
105
|
const context: Context = useContext(chartContext);
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
106
|
+
const { width, height } = context;
|
|
107
|
+
if (isClipAxis) {
|
|
108
|
+
return (
|
|
109
|
+
<>
|
|
110
|
+
{clipAxisRange.map((range: any, index: number) => {
|
|
111
|
+
return (
|
|
112
|
+
<path
|
|
113
|
+
key={index}
|
|
114
|
+
d={`M 0.5,${range[0]} L 0.5,${range[1]}`}
|
|
115
|
+
stroke={color}
|
|
116
|
+
strokeWidth={lineWidth}
|
|
117
|
+
/>
|
|
118
|
+
);
|
|
119
|
+
})}
|
|
120
|
+
</>
|
|
121
|
+
);
|
|
122
|
+
} else {
|
|
123
|
+
return (
|
|
124
|
+
<path
|
|
125
|
+
d={getAxesPath(orientation, context)}
|
|
126
|
+
stroke={color}
|
|
127
|
+
strokeWidth={lineWidth}
|
|
128
|
+
/>
|
|
129
|
+
);
|
|
130
|
+
}
|
|
109
131
|
};
|
|
110
132
|
|
|
111
133
|
const Unit: ({
|
|
112
|
-
config: {
|
|
113
|
-
show,
|
|
114
|
-
text,
|
|
115
|
-
font,
|
|
116
|
-
translate,
|
|
117
|
-
align,
|
|
118
|
-
},
|
|
134
|
+
config: { show, text, font, translate, align },
|
|
119
135
|
}: any) => ReactComponentElement<ComponentType> | null = ({
|
|
120
136
|
config: {
|
|
121
137
|
show,
|
|
@@ -128,13 +144,13 @@ const Unit: ({
|
|
|
128
144
|
if (!show) return null;
|
|
129
145
|
return (
|
|
130
146
|
<text
|
|
131
|
-
className=
|
|
132
|
-
transform={
|
|
147
|
+
className="__easyv-unit"
|
|
148
|
+
transform={"translate(" + translateX + ", " + translateY + ")"}
|
|
133
149
|
fontFamily={fontFamily}
|
|
134
150
|
fontSize={fontSize}
|
|
135
151
|
fill={color}
|
|
136
|
-
fontWeight={bold ?
|
|
137
|
-
fontStyle={italic ?
|
|
152
|
+
fontWeight={bold ? "bold" : "normal"}
|
|
153
|
+
fontStyle={italic ? "italic" : "normal"}
|
|
138
154
|
letterSpacing={letterSpacing}
|
|
139
155
|
textAnchor={textAnchor}
|
|
140
156
|
>
|
|
@@ -144,12 +160,12 @@ const Unit: ({
|
|
|
144
160
|
};
|
|
145
161
|
|
|
146
162
|
type appearance = {
|
|
147
|
-
angle:number
|
|
148
|
-
count:number
|
|
149
|
-
speed:number
|
|
150
|
-
width:number | string
|
|
151
|
-
textOverflow:string
|
|
152
|
-
}
|
|
163
|
+
angle: number;
|
|
164
|
+
count: number;
|
|
165
|
+
speed: number;
|
|
166
|
+
width: number | string;
|
|
167
|
+
textOverflow: string;
|
|
168
|
+
};
|
|
153
169
|
type LabelType = {
|
|
154
170
|
className: string;
|
|
155
171
|
orientation: Orientation;
|
|
@@ -164,7 +180,7 @@ type LabelType = {
|
|
|
164
180
|
translate: Translate;
|
|
165
181
|
font: Font;
|
|
166
182
|
style: CSSProperties | Function;
|
|
167
|
-
appearance?:appearance
|
|
183
|
+
appearance?: appearance;
|
|
168
184
|
};
|
|
169
185
|
};
|
|
170
186
|
|
|
@@ -185,37 +201,52 @@ const Label: (
|
|
|
185
201
|
style,
|
|
186
202
|
translate: { x: translateX, y: translateY },
|
|
187
203
|
font,
|
|
188
|
-
appearance
|
|
189
|
-
width,
|
|
190
|
-
speed,
|
|
191
|
-
textOverflow
|
|
192
|
-
} = defaultAppearance
|
|
204
|
+
appearance: { width, speed, textOverflow } = defaultAppearance,
|
|
193
205
|
},
|
|
194
206
|
}) => {
|
|
195
207
|
if (!show) return null;
|
|
196
208
|
const _label = formatter(label, config);
|
|
197
209
|
const { transform, directionX, directionY } = getLayout(orientation, rotate);
|
|
198
|
-
const isVertical = orientation ==
|
|
210
|
+
const isVertical = orientation == "left" || orientation == "right";
|
|
199
211
|
|
|
200
212
|
const x =
|
|
201
213
|
(isVertical ? tickSize * directionX : coordinate) + translateX * directionX;
|
|
202
214
|
const y =
|
|
203
215
|
(isVertical ? coordinate : tickSize * directionY) + translateY * directionY;
|
|
204
216
|
|
|
205
|
-
const _style = style && (typeof style ==
|
|
217
|
+
const _style = style && (typeof style == "object" ? style : style(_label));
|
|
206
218
|
|
|
207
|
-
return
|
|
208
|
-
<
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
+
return (
|
|
220
|
+
<foreignObject
|
|
221
|
+
width="1"
|
|
222
|
+
height="1"
|
|
223
|
+
x={x}
|
|
224
|
+
y={y}
|
|
225
|
+
style={{ overflow: "visible" }}
|
|
226
|
+
>
|
|
227
|
+
<div
|
|
228
|
+
className={className}
|
|
229
|
+
onClick={onClick}
|
|
230
|
+
data-data={JSON.stringify({ x: label })}
|
|
231
|
+
style={{
|
|
232
|
+
..._style,
|
|
233
|
+
...getFontStyle(font),
|
|
234
|
+
}}
|
|
235
|
+
>
|
|
236
|
+
<TextOverflow
|
|
237
|
+
type={textOverflow}
|
|
238
|
+
speed={speed}
|
|
239
|
+
value={_label}
|
|
240
|
+
style={{
|
|
241
|
+
width,
|
|
242
|
+
transform,
|
|
243
|
+
textAlign: "center",
|
|
244
|
+
justifyContent: "center",
|
|
245
|
+
}}
|
|
246
|
+
></TextOverflow>
|
|
247
|
+
</div>
|
|
248
|
+
</foreignObject>
|
|
249
|
+
);
|
|
219
250
|
};
|
|
220
251
|
|
|
221
252
|
export default memo(
|
|
@@ -228,23 +259,133 @@ export default memo(
|
|
|
228
259
|
rotate,
|
|
229
260
|
triggerClick,
|
|
230
261
|
config: { on, label, axisLine, tickLine, gridLine, unit },
|
|
262
|
+
config,
|
|
231
263
|
positions,
|
|
232
264
|
xLineRange,
|
|
233
|
-
|
|
265
|
+
//断轴图相关
|
|
266
|
+
isClipAxis = false,
|
|
267
|
+
yLineRange,
|
|
268
|
+
clipAxisRange,
|
|
234
269
|
}: any) => {
|
|
235
270
|
if (!(on && ticks.length > 0)) return null;
|
|
236
271
|
const { width, height } = useContext(chartContext);
|
|
237
|
-
const x = orientation ==
|
|
238
|
-
const y = orientation ==
|
|
272
|
+
const x = orientation == "right" ? width : 0;
|
|
273
|
+
const y = orientation == "bottom" ? height : 0;
|
|
274
|
+
|
|
275
|
+
function drawYAxisTickLine() {
|
|
276
|
+
const draw = (ticks: any, scaler: any) => {
|
|
277
|
+
return ticks.map((tick: string, index: number) => {
|
|
278
|
+
const coordinate = scaler(tick);
|
|
279
|
+
if (isNaN(coordinate)) return null;
|
|
280
|
+
const _tickSize = tickLine.tickSize || tickSize;
|
|
281
|
+
const gridCoord = getGridCoord({
|
|
282
|
+
orientation,
|
|
283
|
+
coordinate,
|
|
284
|
+
end:
|
|
285
|
+
orientation == "left" || orientation == "right" ? width : height,
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
const x1 = gridCoord.x1;
|
|
289
|
+
const y1 = gridCoord.y1;
|
|
290
|
+
return (
|
|
291
|
+
!(
|
|
292
|
+
(orientation == "bottom" && (x1 < 0 || x1 > xLineRange)) ||
|
|
293
|
+
y1 < 0 ||
|
|
294
|
+
y1 > yLineRange
|
|
295
|
+
) && (
|
|
296
|
+
<Line
|
|
297
|
+
className="__easyv-tickLine"
|
|
298
|
+
key={index}
|
|
299
|
+
config={tickLine}
|
|
300
|
+
{...getTickCoord({
|
|
301
|
+
orientation,
|
|
302
|
+
coordinate,
|
|
303
|
+
tickSize: _tickSize,
|
|
304
|
+
})}
|
|
305
|
+
/>
|
|
306
|
+
)
|
|
307
|
+
);
|
|
308
|
+
});
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
if (isClipAxis) {
|
|
312
|
+
return (
|
|
313
|
+
<>
|
|
314
|
+
{ticks.map((ticks: any, index: number) => {
|
|
315
|
+
return draw(ticks, scaler[index]);
|
|
316
|
+
})}
|
|
317
|
+
</>
|
|
318
|
+
);
|
|
319
|
+
} else {
|
|
320
|
+
return <>{draw(ticks, scaler)}</>;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
function drawLabel() {
|
|
325
|
+
const draw = (ticks: any, scaler: any) => {
|
|
326
|
+
return ticks.map((tick: string, index: number) => {
|
|
327
|
+
const coordinate = scaler(tick);
|
|
328
|
+
if (isNaN(coordinate)) return null;
|
|
329
|
+
const _tickSize = tickLine.tickSize || tickSize;
|
|
330
|
+
const gridCoord = getGridCoord({
|
|
331
|
+
orientation,
|
|
332
|
+
coordinate,
|
|
333
|
+
end:
|
|
334
|
+
orientation == 'left' || orientation == 'right'
|
|
335
|
+
? width
|
|
336
|
+
: height,
|
|
337
|
+
});
|
|
338
|
+
const x1 = gridCoord.x1;
|
|
339
|
+
const y1 = gridCoord.y1;
|
|
340
|
+
return (
|
|
341
|
+
!(orientation=="bottom" && (x1<0 || x1>xLineRange) || (y1<0 || y1>yLineRange)) && <g key={index}>
|
|
342
|
+
{label && (
|
|
343
|
+
<Label
|
|
344
|
+
className='__easyv-label'
|
|
345
|
+
orientation={orientation}
|
|
346
|
+
coordinate={coordinate}
|
|
347
|
+
config={label}
|
|
348
|
+
label={tick}
|
|
349
|
+
tickSize={_tickSize}
|
|
350
|
+
formatter={formatter}
|
|
351
|
+
rotate={rotate}
|
|
352
|
+
onClick={triggerClick}
|
|
353
|
+
/>
|
|
354
|
+
)}
|
|
355
|
+
{gridLine && (
|
|
356
|
+
<Line
|
|
357
|
+
className='__easyv-gridLine'
|
|
358
|
+
config={gridLine}
|
|
359
|
+
{...gridCoord}
|
|
360
|
+
/>
|
|
361
|
+
)}
|
|
362
|
+
</g>
|
|
363
|
+
);
|
|
364
|
+
})
|
|
365
|
+
}
|
|
366
|
+
if (isClipAxis) {
|
|
367
|
+
return (
|
|
368
|
+
<>
|
|
369
|
+
{ticks.map((ticks: any, index: number) => {
|
|
370
|
+
return draw(ticks, scaler[index]);
|
|
371
|
+
})}
|
|
372
|
+
</>
|
|
373
|
+
);
|
|
374
|
+
} else {
|
|
375
|
+
return <>{draw(ticks, scaler)}</>;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
239
378
|
|
|
240
379
|
return (
|
|
241
380
|
<>
|
|
381
|
+
{/* 绘制轴线和刻度 */}
|
|
242
382
|
{axisLine && tickLine && (
|
|
243
383
|
<>
|
|
244
384
|
{axisLine &&
|
|
385
|
+
// 依据positions来区分x轴y轴,有position为x轴
|
|
245
386
|
(positions && positions.length ? (
|
|
246
387
|
positions.map(({ x, y }: any, index: number) => (
|
|
247
|
-
<g key={index} transform={
|
|
388
|
+
<g key={index} transform={"translate(" + x + ", " + y + ")"}>
|
|
248
389
|
<AxisLine orientation={orientation} config={axisLine} />
|
|
249
390
|
{tickLine &&
|
|
250
391
|
ticks.map((tick: string, index: number) => {
|
|
@@ -255,104 +396,52 @@ export default memo(
|
|
|
255
396
|
orientation,
|
|
256
397
|
coordinate,
|
|
257
398
|
end:
|
|
258
|
-
orientation ==
|
|
399
|
+
orientation == "left" || orientation == "right"
|
|
259
400
|
? width
|
|
260
401
|
: height,
|
|
261
402
|
});
|
|
262
403
|
const x1 = gridCoord.x1;
|
|
263
404
|
const y1 = gridCoord.y1;
|
|
264
405
|
return (
|
|
265
|
-
!(
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
406
|
+
!(
|
|
407
|
+
(orientation == "bottom" &&
|
|
408
|
+
(x1 < 0 || x1 > xLineRange)) ||
|
|
409
|
+
y1 < 0 ||
|
|
410
|
+
y1 > yLineRange
|
|
411
|
+
) && (
|
|
412
|
+
<Line
|
|
413
|
+
className="__easyv-tickLine"
|
|
414
|
+
key={index}
|
|
415
|
+
config={tickLine}
|
|
416
|
+
{...getTickCoord({
|
|
417
|
+
orientation,
|
|
418
|
+
coordinate,
|
|
419
|
+
tickSize: _tickSize,
|
|
420
|
+
})}
|
|
421
|
+
/>
|
|
422
|
+
)
|
|
275
423
|
);
|
|
276
424
|
})}
|
|
277
425
|
</g>
|
|
278
426
|
))
|
|
279
427
|
) : (
|
|
280
|
-
<g transform={
|
|
281
|
-
<AxisLine
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
orientation,
|
|
289
|
-
coordinate,
|
|
290
|
-
end:
|
|
291
|
-
orientation == 'left' || orientation == 'right'
|
|
292
|
-
? width
|
|
293
|
-
: height,
|
|
294
|
-
});
|
|
295
|
-
const x1 = gridCoord.x1;
|
|
296
|
-
const y1 = gridCoord.y1;
|
|
297
|
-
return (
|
|
298
|
-
!(orientation=="bottom" && (x1<0 || x1>xLineRange) || (y1<0 || y1>yLineRange)) && <Line
|
|
299
|
-
className='__easyv-tickLine'
|
|
300
|
-
key={index}
|
|
301
|
-
config={tickLine}
|
|
302
|
-
{...getTickCoord({
|
|
303
|
-
orientation,
|
|
304
|
-
coordinate,
|
|
305
|
-
tickSize: _tickSize,
|
|
306
|
-
})}
|
|
307
|
-
/>
|
|
308
|
-
);
|
|
309
|
-
})}
|
|
428
|
+
<g transform={"translate(" + x + ", " + y + ")"}>
|
|
429
|
+
<AxisLine
|
|
430
|
+
orientation={orientation}
|
|
431
|
+
config={axisLine}
|
|
432
|
+
isClipAxis={isClipAxis}
|
|
433
|
+
clipAxisRange={clipAxisRange}
|
|
434
|
+
/>
|
|
435
|
+
{tickLine && drawYAxisTickLine()}
|
|
310
436
|
</g>
|
|
311
437
|
))}
|
|
312
438
|
</>
|
|
313
439
|
)}
|
|
440
|
+
{/* 绘制标签和网格线 */}
|
|
314
441
|
<g transform={'translate(' + x + ', ' + y + ')'}>
|
|
315
442
|
{label &&
|
|
316
|
-
gridLine &&
|
|
317
|
-
|
|
318
|
-
const coordinate = scaler(tick);
|
|
319
|
-
if (isNaN(coordinate)) return null;
|
|
320
|
-
const _tickSize = tickLine.tickSize || tickSize;
|
|
321
|
-
const gridCoord = getGridCoord({
|
|
322
|
-
orientation,
|
|
323
|
-
coordinate,
|
|
324
|
-
end:
|
|
325
|
-
orientation == 'left' || orientation == 'right'
|
|
326
|
-
? width
|
|
327
|
-
: height,
|
|
328
|
-
});
|
|
329
|
-
const x1 = gridCoord.x1;
|
|
330
|
-
const y1 = gridCoord.y1;
|
|
331
|
-
return (
|
|
332
|
-
!(orientation=="bottom" && (x1<0 || x1>xLineRange) || (y1<0 || y1>yLineRange)) && <g key={index}>
|
|
333
|
-
{label && (
|
|
334
|
-
<Label
|
|
335
|
-
className='__easyv-label'
|
|
336
|
-
orientation={orientation}
|
|
337
|
-
coordinate={coordinate}
|
|
338
|
-
config={label}
|
|
339
|
-
label={tick}
|
|
340
|
-
tickSize={_tickSize}
|
|
341
|
-
formatter={formatter}
|
|
342
|
-
rotate={rotate}
|
|
343
|
-
onClick={triggerClick}
|
|
344
|
-
/>
|
|
345
|
-
)}
|
|
346
|
-
{gridLine && (
|
|
347
|
-
<Line
|
|
348
|
-
className='__easyv-gridLine'
|
|
349
|
-
config={gridLine}
|
|
350
|
-
{...gridCoord}
|
|
351
|
-
/>
|
|
352
|
-
)}
|
|
353
|
-
</g>
|
|
354
|
-
);
|
|
355
|
-
})}
|
|
443
|
+
gridLine && drawLabel()
|
|
444
|
+
}
|
|
356
445
|
{unit && <Unit config={unit} />}
|
|
357
446
|
</g>
|
|
358
447
|
</>
|