@@ -87,7 +87,6 @@ function getPoints({
87
87
if ( sourceDir [ dirAccessor ] * targetDir [ dirAccessor ] === - 1 ) {
88
88
centerX = center . x || defaultCenterX
89
89
centerY = center . y || defaultCenterY
90
-
91
90
// --->
92
91
// |
93
92
// >---
@@ -126,9 +125,9 @@ function getPoints({
126
125
if ( diff <= offset ) {
127
126
const gapOffset = Math . min ( offset - 1 , offset - diff )
128
127
if ( sourceDir [ dirAccessor ] === currDir ) {
129
- sourceGapOffset [ dirAccessor ] = gapOffset
128
+ sourceGapOffset [ dirAccessor ] = ( sourceGapped [ dirAccessor ] > source [ dirAccessor ] ? - 1 : 1 ) * gapOffset
130
129
} else {
131
- targetGapOffset [ dirAccessor ] = gapOffset
130
+ targetGapOffset [ dirAccessor ] = ( targetGapped [ dirAccessor ] > target [ dirAccessor ] ? - 1 : 1 ) * gapOffset
132
131
}
133
132
}
134
133
}
@@ -148,8 +147,8 @@ function getPoints({
148
147
}
149
148
}
150
149
151
- const sourceGapPoint = { x : sourceGapped . x - sourceGapOffset . x , y : sourceGapped . y - sourceGapOffset . y }
152
- const targetGapPoint = { x : targetGapped . x - targetGapOffset . x , y : targetGapped . y - targetGapOffset . y }
150
+ const sourceGapPoint = { x : sourceGapped . x + sourceGapOffset . x , y : sourceGapped . y + sourceGapOffset . y }
151
+ const targetGapPoint = { x : targetGapped . x + targetGapOffset . x , y : targetGapped . y + targetGapOffset . y }
153
152
const maxXDistance = Math . max ( Math . abs ( sourceGapPoint . x - points [ 0 ] . x ) , Math . abs ( targetGapPoint . x - points [ 0 ] . x ) )
154
153
const maxYDistance = Math . max ( Math . abs ( sourceGapPoint . y - points [ 0 ] . y ) , Math . abs ( targetGapPoint . y - points [ 0 ] . y ) )
155
154
@@ -165,16 +164,16 @@ function getPoints({
165
164
166
165
const pathPoints = [
167
166
source ,
168
- { x : sourceGapped . x - sourceGapOffset . x , y : sourceGapped . y - sourceGapOffset . y } ,
167
+ { x : sourceGapped . x + sourceGapOffset . x , y : sourceGapped . y + sourceGapOffset . y } ,
169
168
...points ,
170
- { x : targetGapped . x - targetGapOffset . x , y : targetGapped . y - targetGapOffset . y } ,
169
+ { x : targetGapped . x + targetGapOffset . x , y : targetGapped . y + targetGapOffset . y } ,
171
170
target ,
172
171
]
173
172
174
173
return [ pathPoints , centerX , centerY , defaultOffsetX , defaultOffsetY ]
175
174
}
176
175
177
- function getBend ( a : XYPosition , b : XYPosition , c : XYPosition , size : number ) {
176
+ function getBend ( a : XYPosition , b : XYPosition , c : XYPosition , size : number ) : string {
178
177
const bendSize = Math . min ( distance ( a , b ) / 2 , distance ( b , c ) / 2 , size )
179
178
const { x, y } = b
180
179
@@ -195,6 +194,17 @@ function getBend(a: XYPosition, b: XYPosition, c: XYPosition, size: number) {
195
194
return `L ${ x } ,${ y + bendSize * yDir } Q ${ x } ,${ y } ${ x + bendSize * xDir } ,${ y } `
196
195
}
197
196
197
+ /**
198
+ * Get a smooth step path from source to target handle
199
+ * @param params
200
+ * @param params.sourceX - The x position of the source handle
201
+ * @param params.sourceY - The y position of the source handle
202
+ * @param params.sourcePosition - The position of the source handle (default: Position.Bottom)
203
+ * @param params.targetX - The x position of the target handle
204
+ * @param params.targetY - The y position of the target handle
205
+ * @param params.targetPosition - The position of the target handle (default: Position.Top)
206
+ * @returns A path string you can use in an SVG, the labelX and labelY position (center of path) and offsetX, offsetY between source handle and label
207
+ */
198
208
export function getSmoothStepPath ( {
199
209
sourceX,
200
210
sourceY,
0 commit comments