47 lines
1.1 KiB
TypeScript
47 lines
1.1 KiB
TypeScript
import React, { memo } from 'react';
|
|
|
|
import BaseEdge from './BaseEdge';
|
|
import { EdgeProps } from '../../types';
|
|
|
|
export default memo(
|
|
({
|
|
sourceX,
|
|
sourceY,
|
|
targetX,
|
|
targetY,
|
|
label,
|
|
labelStyle,
|
|
labelShowBg,
|
|
labelBgStyle,
|
|
labelBgPadding,
|
|
labelBgBorderRadius,
|
|
style,
|
|
markerEnd,
|
|
markerStart,
|
|
}: EdgeProps) => {
|
|
const yOffset = Math.abs(targetY - sourceY) / 2;
|
|
const centerY = targetY < sourceY ? targetY + yOffset : targetY - yOffset;
|
|
|
|
const xOffset = Math.abs(targetX - sourceX) / 2;
|
|
const centerX = targetX < sourceX ? targetX + xOffset : targetX - xOffset;
|
|
const path = `M ${sourceX},${sourceY}L ${targetX},${targetY}`;
|
|
|
|
return (
|
|
<BaseEdge
|
|
path={path}
|
|
centerX={centerX}
|
|
centerY={centerY}
|
|
label={label}
|
|
labelStyle={labelStyle}
|
|
labelShowBg={labelShowBg}
|
|
labelBgStyle={labelBgStyle}
|
|
labelBgPadding={labelBgPadding}
|
|
labelBgBorderRadius={labelBgBorderRadius}
|
|
style={style}
|
|
markerEnd={markerEnd}
|
|
markerStart={markerStart}
|
|
/>
|
|
);
|
|
}
|
|
);
|