@@ -6,9 +6,11 @@ import {
6
6
} from '@logicflow/core' ;
7
7
8
8
type DirectionType = 't' | 'b' | 'l' | 'r' | '' ;
9
- type ArcPositionType = 'tl' | 'tr' | 'bl' | 'br' | '-' ;
9
+ type ArcQuadrantType = 'tl' | 'tr' | 'bl' | 'br' | '-' ;
10
10
11
- const directionMap : any = {
11
+ const directionMap : {
12
+ [ key : string ] : ArcQuadrantType ;
13
+ } = {
12
14
tr : 'tl' ,
13
15
lb : 'tl' ,
14
16
tl : 'tr' ,
@@ -38,7 +40,7 @@ function pointFilter(points: number[][]) {
38
40
function getMidPoints (
39
41
cur : PointTuple ,
40
42
key : string ,
41
- orientation : ArcPositionType ,
43
+ orientation : ArcQuadrantType ,
42
44
radius : number ,
43
45
) {
44
46
const mid1 = [ cur [ 0 ] , cur [ 1 ] ] ;
@@ -85,7 +87,7 @@ function getMidPoints(
85
87
return [ mid1 , mid2 ] ;
86
88
}
87
89
default :
88
- return null ;
90
+ return [ ] ;
89
91
}
90
92
}
91
93
@@ -97,30 +99,33 @@ function getPartialPath(
97
99
) : string {
98
100
let dir1 : DirectionType = '' ;
99
101
let dir2 : DirectionType = '' ;
100
- let realRadius = radius ;
101
102
102
103
if ( prev [ 0 ] === cur [ 0 ] ) {
103
104
dir1 = prev [ 1 ] > cur [ 1 ] ? 't' : 'b' ;
104
- realRadius = Math . min ( Math . abs ( prev [ 0 ] - cur [ 0 ] ) , radius ) ;
105
105
} else if ( prev [ 1 ] === cur [ 1 ] ) {
106
106
dir1 = prev [ 0 ] > cur [ 0 ] ? 'l' : 'r' ;
107
- realRadius = Math . min ( Math . abs ( prev [ 1 ] - cur [ 1 ] ) , radius ) ;
108
107
}
108
+
109
109
if ( cur [ 0 ] === next [ 0 ] ) {
110
110
dir2 = cur [ 1 ] > next [ 1 ] ? 't' : 'b' ;
111
- realRadius = Math . min ( Math . abs ( prev [ 0 ] - cur [ 0 ] ) , radius ) ;
112
111
} else if ( cur [ 1 ] === next [ 1 ] ) {
113
112
dir2 = cur [ 0 ] > next [ 0 ] ? 'l' : 'r' ;
114
- realRadius = Math . min ( Math . abs ( prev [ 1 ] - cur [ 1 ] ) , radius ) ;
115
113
}
116
114
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
+
117
121
const key = `${ dir1 } ${ dir2 } ` ;
118
- const orientation : ArcPositionType = directionMap [ key ] || '-' ;
122
+ const orientation : ArcQuadrantType = directionMap [ key ] || '-' ;
119
123
let path = `L ${ prev [ 0 ] } ${ prev [ 1 ] } ` ;
124
+
120
125
if ( orientation === '-' ) {
121
126
path += `L ${ cur [ 0 ] } ${ cur [ 1 ] } L ${ next [ 0 ] } ${ next [ 1 ] } ` ;
122
127
} else {
123
- const [ mid1 , mid2 ] = getMidPoints ( cur , key , orientation , realRadius ) || [ ] ;
128
+ const [ mid1 , mid2 ] = getMidPoints ( cur , key , orientation , r ) ;
124
129
if ( mid1 && mid2 ) {
125
130
path += `L ${ mid1 [ 0 ] } ${ mid1 [ 1 ] } Q ${ cur [ 0 ] } ${ cur [ 1 ] } ${ mid2 [ 0 ] } ${ mid2 [ 1 ] } ` ;
126
131
[ cur [ 0 ] , cur [ 1 ] ] = mid2 ;
@@ -163,11 +168,6 @@ class CurvedEdge extends PolylineEdge {
163
168
...arrowConfig ,
164
169
fill : 'none' ,
165
170
} ;
166
- console . log (
167
- pointsStr ,
168
- pointsStr . split ( ' ' ) . map ( ( p ) => p . split ( ',' ) . map ( ( a ) => + a ) ) ,
169
- d ,
170
- ) ;
171
171
return h ( 'path' , {
172
172
d,
173
173
...attrs ,
0 commit comments