refactor: Change Position into enum (#48)

This commit is contained in:
AndyLnd
2019-10-22 16:37:47 +02:00
committed by Moritz
parent 59caff6505
commit 8ca5c0f84b
7 changed files with 84 additions and 125 deletions
+6 -11
View File
@@ -1,6 +1,6 @@
import React, { memo } from 'react';
import { EdgeBezierProps } from '../../types';
import { EdgeBezierProps, Position } from '../../types';
export default memo(
({
@@ -8,8 +8,8 @@ export default memo(
sourceY,
targetX,
targetY,
sourcePosition = 'bottom',
targetPosition = 'top',
sourcePosition = Position.Bottom,
targetPosition = Position.Top,
style = {},
}: EdgeBezierProps) => {
const yOffset = Math.abs(targetY - sourceY) / 2;
@@ -17,18 +17,13 @@ export default memo(
let dAttr = `M${sourceX},${sourceY} C${sourceX},${centerY} ${targetX},${centerY} ${targetX},${targetY}`;
if (
['left', 'right'].includes(sourcePosition) &&
['left', 'right'].includes(targetPosition)
) {
const leftAndRight = [Position.Left, Position.Right];
if (leftAndRight.includes(sourcePosition) && leftAndRight.includes(targetPosition)) {
const xOffset = Math.abs(targetX - sourceX) / 2;
const centerX = targetX < sourceX ? targetX + xOffset : targetX - xOffset;
dAttr = `M${sourceX},${sourceY} C${centerX},${sourceY} ${centerX},${targetY} ${targetX},${targetY}`;
} else if (
['left', 'right'].includes(sourcePosition) ||
['left', 'right'].includes(targetPosition)
) {
} else if (leftAndRight.includes(sourcePosition) || leftAndRight.includes(targetPosition)) {
dAttr = `M${sourceX},${sourceY} C${sourceX},${targetY} ${sourceX},${targetY} ${targetX},${targetY}`;
}