Merge pull request #536 from wbkd/develop

Develop
This commit is contained in:
Moritz
2020-09-27 22:22:43 +02:00
committed by GitHub
3 changed files with 29 additions and 19 deletions
+5 -1
View File
@@ -350,6 +350,8 @@ Returns the path of a bezier edge.
targetX, targetX,
targetY, targetY,
targetPosition = Position.Top, targetPosition = Position.Top,
centerX, // optional
centerY // optional
}: GetBezierPathParams): string` }: GetBezierPathParams): string`
### getSmoothStepPath ### getSmoothStepPath
@@ -364,11 +366,13 @@ Returns the path of a smooth step edge. You can set `borderRadius` = `0` to get
targetY, targetY,
targetPosition = Position.Top, targetPosition = Position.Top,
borderRadius = 5, borderRadius = 5,
centerX, // optional
centerY // optional
}: GetSmoothStepPathParams): string` }: GetSmoothStepPathParams): string`
### getEdgeCenter ### getEdgeCenter
Returns the center poostion `[centerX, centerY]` of the edge. Returns the center poostion `[centerX, centerY, offsetX, offsetY]` of the edge.
`getEdgeCenter({ sourceX, sourceY, targetX, targetY }: GetCenterParams): [number, number, number, number]` `getEdgeCenter({ sourceX, sourceY, targetX, targetY }: GetCenterParams): [number, number, number, number]`
+10 -3
View File
@@ -12,6 +12,8 @@ interface GetBezierPathParams {
targetX: number; targetX: number;
targetY: number; targetY: number;
targetPosition?: Position; targetPosition?: Position;
centerX?: number;
centerY?: number;
} }
export function getBezierPath({ export function getBezierPath({
@@ -21,14 +23,19 @@ export function getBezierPath({
targetX, targetX,
targetY, targetY,
targetPosition = Position.Top, targetPosition = Position.Top,
centerX,
centerY,
}: GetBezierPathParams): string { }: GetBezierPathParams): string {
const [centerX, centerY] = getCenter({ sourceX, sourceY, targetX, targetY }); const [_centerX, _centerY] = getCenter({ sourceX, sourceY, targetX, targetY });
const leftAndRight = [Position.Left, Position.Right]; const leftAndRight = [Position.Left, Position.Right];
let path = `M${sourceX},${sourceY} C${sourceX},${centerY} ${targetX},${centerY} ${targetX},${targetY}`; const cX = typeof centerX !== 'undefined' ? centerX : _centerX;
const cY = typeof centerY !== 'undefined' ? centerY : _centerY;
let path = `M${sourceX},${sourceY} C${sourceX},${cY} ${targetX},${cY} ${targetX},${targetY}`;
if (leftAndRight.includes(sourcePosition) && leftAndRight.includes(targetPosition)) { if (leftAndRight.includes(sourcePosition) && leftAndRight.includes(targetPosition)) {
path = `M${sourceX},${sourceY} C${centerX},${sourceY} ${centerX},${targetY} ${targetX},${targetY}`; path = `M${sourceX},${sourceY} C${cX},${sourceY} ${cX},${targetY} ${targetX},${targetY}`;
} else if (leftAndRight.includes(targetPosition)) { } else if (leftAndRight.includes(targetPosition)) {
path = `M${sourceX},${sourceY} C${sourceX},${targetY} ${sourceX},${targetY} ${targetX},${targetY}`; path = `M${sourceX},${sourceY} C${sourceX},${targetY} ${sourceX},${targetY} ${targetX},${targetY}`;
} else if (leftAndRight.includes(sourcePosition)) { } else if (leftAndRight.includes(sourcePosition)) {
+14 -15
View File
@@ -41,6 +41,8 @@ interface GetSmoothStepPathParams {
targetY: number; targetY: number;
targetPosition?: Position; targetPosition?: Position;
borderRadius?: number; borderRadius?: number;
centerX?: number;
centerY?: number;
} }
export function getSmoothStepPath({ export function getSmoothStepPath({
@@ -51,8 +53,10 @@ export function getSmoothStepPath({
targetY, targetY,
targetPosition = Position.Top, targetPosition = Position.Top,
borderRadius = 5, borderRadius = 5,
centerX,
centerY,
}: GetSmoothStepPathParams): string { }: GetSmoothStepPathParams): string {
const [centerX, centerY, offsetX, offsetY] = getCenter({ sourceX, sourceY, targetX, targetY }); const [_centerX, _centerY, offsetX, offsetY] = getCenter({ sourceX, sourceY, targetX, targetY });
const cornerWidth = Math.min(borderRadius, Math.abs(targetX - sourceX)); const cornerWidth = Math.min(borderRadius, Math.abs(targetX - sourceX));
const cornerHeight = Math.min(borderRadius, Math.abs(targetY - sourceY)); const cornerHeight = Math.min(borderRadius, Math.abs(targetY - sourceY));
const cornerSize = Math.min(cornerWidth, cornerHeight, offsetX, offsetY); const cornerSize = Math.min(cornerWidth, cornerHeight, offsetX, offsetY);
@@ -62,33 +66,28 @@ export function getSmoothStepPath({
let firstCornerPath = null; let firstCornerPath = null;
let secondCornerPath = null; let secondCornerPath = null;
const cX = typeof centerX !== 'undefined' ? centerX : _centerX;
const cY = typeof centerY !== 'undefined' ? centerY : _centerY;
// default case: source and target positions are top or bottom // default case: source and target positions are top or bottom
if (sourceX <= targetX) { if (sourceX <= targetX) {
firstCornerPath = firstCornerPath =
sourceY <= targetY ? bottomLeftCorner(sourceX, centerY, cornerSize) : topLeftCorner(sourceX, centerY, cornerSize); sourceY <= targetY ? bottomLeftCorner(sourceX, cY, cornerSize) : topLeftCorner(sourceX, cY, cornerSize);
secondCornerPath = secondCornerPath =
sourceY <= targetY sourceY <= targetY ? rightTopCorner(targetX, cY, cornerSize) : rightBottomCorner(targetX, cY, cornerSize);
? rightTopCorner(targetX, centerY, cornerSize)
: rightBottomCorner(targetX, centerY, cornerSize);
} else { } else {
firstCornerPath = firstCornerPath =
sourceY < targetY sourceY < targetY ? bottomRightCorner(sourceX, cY, cornerSize) : topRightCorner(sourceX, cY, cornerSize);
? bottomRightCorner(sourceX, centerY, cornerSize)
: topRightCorner(sourceX, centerY, cornerSize);
secondCornerPath = secondCornerPath =
sourceY < targetY ? leftTopCorner(targetX, centerY, cornerSize) : leftBottomCorner(targetX, centerY, cornerSize); sourceY < targetY ? leftTopCorner(targetX, cY, cornerSize) : leftBottomCorner(targetX, cY, cornerSize);
} }
if (leftAndRight.includes(sourcePosition) && leftAndRight.includes(targetPosition)) { if (leftAndRight.includes(sourcePosition) && leftAndRight.includes(targetPosition)) {
if (sourceX <= targetX) { if (sourceX <= targetX) {
firstCornerPath = firstCornerPath =
sourceY <= targetY sourceY <= targetY ? rightTopCorner(cX, sourceY, cornerSize) : rightBottomCorner(cX, sourceY, cornerSize);
? rightTopCorner(centerX, sourceY, cornerSize)
: rightBottomCorner(centerX, sourceY, cornerSize);
secondCornerPath = secondCornerPath =
sourceY <= targetY sourceY <= targetY ? bottomLeftCorner(cX, targetY, cornerSize) : topLeftCorner(cX, targetY, cornerSize);
? bottomLeftCorner(centerX, targetY, cornerSize)
: topLeftCorner(centerX, targetY, cornerSize);
} }
} else if (leftAndRight.includes(sourcePosition) && !leftAndRight.includes(targetPosition)) { } else if (leftAndRight.includes(sourcePosition) && !leftAndRight.includes(targetPosition)) {
if (sourceX <= targetX) { if (sourceX <= targetX) {