@@ -89,7 +89,7 @@ function getMidPoints(
8989 }
9090}
9191
92- function getPath (
92+ function getPartialPath (
9393 prev : PointTuple ,
9494 cur : PointTuple ,
9595 next : PointTuple ,
@@ -120,7 +120,7 @@ function getPath(
120120 if ( orientation === '-' ) {
121121 path += `L ${ cur [ 0 ] } ${ cur [ 1 ] } L ${ next [ 0 ] } ${ next [ 1 ] } ` ;
122122 } else {
123- const [ mid1 , mid2 ] = getMidPoints ( cur , key , orientation , ( realRadius ) ) || [ ] ;
123+ const [ mid1 , mid2 ] = getMidPoints ( cur , key , orientation , realRadius ) || [ ] ;
124124 if ( mid1 && mid2 ) {
125125 path += `L ${ mid1 [ 0 ] } ${ mid1 [ 1 ] } Q ${ cur [ 0 ] } ${ cur [ 1 ] } ${ mid2 [ 0 ] } ${ mid2 [ 1 ] } ` ;
126126 [ cur [ 0 ] , cur [ 1 ] ] = mid2 ;
@@ -129,6 +129,24 @@ function getPath(
129129 return path ;
130130}
131131
132+ function getCurvedEdgePath ( points : number [ ] [ ] , radius : number ) : string {
133+ let i = 0 ;
134+ let d = '' ;
135+ if ( points . length === 2 ) {
136+ d += `M${ points [ i ] [ 0 ] } ${ points [ i ++ ] [ 1 ] } L ${ points [ i ] [ 0 ] } ${ points [ i ] [ 1 ] } ` ;
137+ } else {
138+ d += `M${ points [ i ] [ 0 ] } ${ points [ i ++ ] [ 1 ] } ` ;
139+ for ( ; i + 1 < points . length ; ) {
140+ const prev = points [ i - 1 ] as PointTuple ;
141+ const cur = points [ i ] as PointTuple ;
142+ const next = points [ i ++ + 1 ] as PointTuple ;
143+ d += getPartialPath ( prev , cur , next , radius as number ) ;
144+ }
145+ d += `L ${ points [ i ] [ 0 ] } ${ points [ i ] [ 1 ] } ` ;
146+ }
147+ return d ;
148+ }
149+
132150class CurvedEdge extends PolylineEdge {
133151 getEdge ( ) {
134152 const { model } = this . props ;
@@ -138,30 +156,18 @@ class CurvedEdge extends PolylineEdge {
138156 const points = pointFilter (
139157 pointsStr . split ( ' ' ) . map ( ( p ) => p . split ( ',' ) . map ( ( a ) => + a ) ) ,
140158 ) ;
141- let i = 0 ;
142- let d = '' ;
143- if ( points . length === 2 ) {
144- d += `M${ points [ i ] [ 0 ] } ${ points [ i ++ ] [ 1 ] } L ${ points [ i ] [ 0 ] } ${
145- points [ i ] [ 1 ]
146- } `;
147- } else {
148- d += `M${ points [ i ] [ 0 ] } ${ points [ i ++ ] [ 1 ] } ` ;
149- for ( ; i + 1 < points . length ; ) {
150- const prev = points [ i - 1 ] as PointTuple ;
151- const cur = points [ i ] as PointTuple ;
152- const next = points [ i ++ + 1 ] as PointTuple ;
153- d += getPath ( prev , cur , next , radius as number ) ;
154- }
155- d += `L ${ points [ i ] [ 0 ] } ${ points [ i ] [ 1 ] } ` ;
156- }
157-
159+ const d = getCurvedEdgePath ( points , radius as number ) ;
158160 const attrs = {
159161 style : isAnimation ? animationStyle : { } ,
160162 ...style ,
161163 ...arrowConfig ,
162164 fill : 'none' ,
163165 } ;
164- console . log ( d ) ;
166+ console . log (
167+ pointsStr ,
168+ pointsStr . split ( ' ' ) . map ( ( p ) => p . split ( ',' ) . map ( ( a ) => + a ) ) ,
169+ d ,
170+ ) ;
165171 return h ( 'path' , {
166172 d,
167173 ...attrs ,
@@ -179,7 +185,4 @@ const defaultCurvedEdge = {
179185
180186export default defaultCurvedEdge ;
181187
182- export {
183- CurvedEdge ,
184- CurvedEdgeModel ,
185- } ;
188+ export { CurvedEdge , CurvedEdgeModel , getCurvedEdgePath } ;
0 commit comments