From 70121edcd880cbce5e87291bae07de606d8cb26d Mon Sep 17 00:00:00 2001 From: moklick Date: Tue, 21 Jul 2020 16:47:35 +0200 Subject: [PATCH] feat(smoothstepedge): add border radius param --- src/components/Edges/SmoothStepEdge.tsx | 12 ++++++++---- src/types/index.ts | 4 ++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/components/Edges/SmoothStepEdge.tsx b/src/components/Edges/SmoothStepEdge.tsx index dfc860c0..f0dc1996 100644 --- a/src/components/Edges/SmoothStepEdge.tsx +++ b/src/components/Edges/SmoothStepEdge.tsx @@ -2,7 +2,7 @@ import React, { memo } from 'react'; import EdgeText from './EdgeText'; import { getMarkerEnd } from './utils'; -import { EdgeBezierProps, Position } from '../../types'; +import { EdgeSmoothStepProps, Position } from '../../types'; // These are some helper methods for drawing the round corners // The name indicates the direction of the path. "bottomLeftCorner" goes @@ -44,6 +44,7 @@ interface GetSmoothStepPathParams { targetX: number; targetY: number; targetPosition?: Position; + borderRadius?: number; } export function getSmoothStepPath({ @@ -57,9 +58,10 @@ export function getSmoothStepPath({ targetX, targetY, targetPosition = Position.Top, + borderRadius = 5, }: GetSmoothStepPathParams): string { - const cornerWidth = Math.min(5, Math.abs(targetX - sourceX)); - const cornerHeight = Math.min(5, Math.abs(targetY - sourceY)); + const cornerWidth = Math.min(borderRadius, Math.abs(targetX - sourceX)); + const cornerHeight = Math.min(borderRadius, Math.abs(targetY - sourceY)); const cornerSize = Math.min(cornerWidth, cornerHeight, xOffset, yOffset); const leftAndRight = [Position.Left, Position.Right]; @@ -141,7 +143,8 @@ export default memo( targetPosition = Position.Top, arrowHeadType, markerEndId, - }: EdgeBezierProps) => { + borderRadius = 5, + }: EdgeSmoothStepProps) => { const yOffset = Math.abs(targetY - sourceY) / 2; const centerY = targetY < sourceY ? targetY + yOffset : targetY - yOffset; @@ -159,6 +162,7 @@ export default memo( targetX, targetY, targetPosition, + borderRadius, }); const markerEnd = getMarkerEnd(arrowHeadType, markerEndId); diff --git a/src/types/index.ts b/src/types/index.ts index 6bbf076d..8b9e3e83 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -99,6 +99,10 @@ export interface EdgeBezierProps extends EdgeProps { targetPosition: Position; } +export interface EdgeSmoothStepProps extends EdgeBezierProps { + borderRadius?: number; +} + export interface NodeProps { id: ElementId; type: string;