Skip to content

Commit b0810b4

Browse files
wumailboyongjiong
authored andcommitted
fix(extension): optimize radius and variable name
1 parent a1e3bc3 commit b0810b4

File tree

1 file changed

+16
-16
lines changed
  • packages/extension/src/materials/curved-edge

1 file changed

+16
-16
lines changed

Diff for: packages/extension/src/materials/curved-edge/index.ts

+16-16
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import {
66
} from '@logicflow/core';
77

88
type DirectionType = 't' | 'b' | 'l' | 'r' | '';
9-
type ArcPositionType = 'tl' | 'tr' | 'bl' | 'br' | '-';
9+
type ArcQuadrantType = 'tl' | 'tr' | 'bl' | 'br' | '-';
1010

11-
const directionMap: any = {
11+
const directionMap: {
12+
[key: string]: ArcQuadrantType;
13+
} = {
1214
tr: 'tl',
1315
lb: 'tl',
1416
tl: 'tr',
@@ -38,7 +40,7 @@ function pointFilter(points: number[][]) {
3840
function getMidPoints(
3941
cur: PointTuple,
4042
key: string,
41-
orientation: ArcPositionType,
43+
orientation: ArcQuadrantType,
4244
radius: number,
4345
) {
4446
const mid1 = [cur[0], cur[1]];
@@ -85,7 +87,7 @@ function getMidPoints(
8587
return [mid1, mid2];
8688
}
8789
default:
88-
return null;
90+
return [];
8991
}
9092
}
9193

@@ -97,30 +99,33 @@ function getPartialPath(
9799
): string {
98100
let dir1: DirectionType = '';
99101
let dir2: DirectionType = '';
100-
let realRadius = radius;
101102

102103
if (prev[0] === cur[0]) {
103104
dir1 = prev[1] > cur[1] ? 't' : 'b';
104-
realRadius = Math.min(Math.abs(prev[0] - cur[0]), radius);
105105
} else if (prev[1] === cur[1]) {
106106
dir1 = prev[0] > cur[0] ? 'l' : 'r';
107-
realRadius = Math.min(Math.abs(prev[1] - cur[1]), radius);
108107
}
108+
109109
if (cur[0] === next[0]) {
110110
dir2 = cur[1] > next[1] ? 't' : 'b';
111-
realRadius = Math.min(Math.abs(prev[0] - cur[0]), radius);
112111
} else if (cur[1] === next[1]) {
113112
dir2 = cur[0] > next[0] ? 'l' : 'r';
114-
realRadius = Math.min(Math.abs(prev[1] - cur[1]), radius);
115113
}
116114

115+
const r = Math.min(
116+
Math.hypot(cur[0] - prev[0], cur[1] - prev[1]) / 2,
117+
Math.hypot(next[0] - cur[0], next[1] - cur[1]) / 2,
118+
radius,
119+
) || (1 / 5) * radius;
120+
117121
const key = `${dir1}${dir2}`;
118-
const orientation: ArcPositionType = directionMap[key] || '-';
122+
const orientation: ArcQuadrantType = directionMap[key] || '-';
119123
let path = `L ${prev[0]} ${prev[1]}`;
124+
120125
if (orientation === '-') {
121126
path += `L ${cur[0]} ${cur[1]} L ${next[0]} ${next[1]}`;
122127
} else {
123-
const [mid1, mid2] = getMidPoints(cur, key, orientation, realRadius) || [];
128+
const [mid1, mid2] = getMidPoints(cur, key, orientation, r);
124129
if (mid1 && mid2) {
125130
path += `L ${mid1[0]} ${mid1[1]} Q ${cur[0]} ${cur[1]} ${mid2[0]} ${mid2[1]}`;
126131
[cur[0], cur[1]] = mid2;
@@ -163,11 +168,6 @@ class CurvedEdge extends PolylineEdge {
163168
...arrowConfig,
164169
fill: 'none',
165170
};
166-
console.log(
167-
pointsStr,
168-
pointsStr.split(' ').map((p) => p.split(',').map((a) => +a)),
169-
d,
170-
);
171171
return h('path', {
172172
d,
173173
...attrs,

0 commit comments

Comments
 (0)