Merge pull request #946 from ambroseus/fix/edge-updater-handle-position

fix(wrapEdge): shift edge updater circles positions to not overlap node handles
This commit is contained in:
Moritz Klack
2021-03-01 10:26:22 +01:00
committed by GitHub
2 changed files with 51 additions and 14 deletions
+42
View File
@@ -0,0 +1,42 @@
import React from 'react';
import { Position } from '../../types';
const shiftX = (x: number, shift: number, position: Position) => {
if (position === Position.Left) return x - shift;
if (position === Position.Right) return x + shift;
return x;
}
const shiftY = (y: number, shift: number, position: Position) => {
if (position === Position.Top) return y - shift;
if (position === Position.Bottom) return y + shift;
return y;
}
export interface EdgeAnchorProps {
className?: string
position: Position
centerX: number
centerY: number
radius?: number
}
export const EdgeAnchor = ({
className = "react-flow__edgeupdater",
position,
centerX,
centerY,
radius = 10
}: EdgeAnchorProps): JSX.Element => {
return (
<circle
className={className}
cx={shiftX(centerX, radius, position)}
cy={shiftY(centerY, radius, position)}
r={radius}
stroke="transparent"
fill="transparent"
/>
);
}
+9 -14
View File
@@ -4,6 +4,7 @@ import cc from 'classcat';
import { useStoreActions, useStoreState } from '../../store/hooks';
import { Edge, EdgeProps, WrapEdgeProps } from '../../types';
import { onMouseDown } from '../../components/Handle/handler';
import { EdgeAnchor } from './EdgeAnchor';
export default (EdgeComponent: ComponentType<EdgeProps>) => {
const EdgeWrapper = ({
@@ -146,13 +147,10 @@ export default (EdgeComponent: ComponentType<EdgeProps>) => {
onMouseEnter={onEdgeUpdaterMouseEnter}
onMouseOut={onEdgeUpdaterMouseOut}
>
<circle
className="react-flow__edgeupdater"
cx={sourceX}
cy={sourceY}
r={10}
stroke="transparent"
fill="transparent"
<EdgeAnchor
position={sourcePosition}
centerX={sourceX}
centerY={sourceY}
/>
</g>
)}
@@ -187,13 +185,10 @@ export default (EdgeComponent: ComponentType<EdgeProps>) => {
onMouseEnter={onEdgeUpdaterMouseEnter}
onMouseOut={onEdgeUpdaterMouseOut}
>
<circle
className="react-flow__edgeupdater"
cx={targetX}
cy={targetY}
r={10}
stroke="transparent"
fill="transparent"
<EdgeAnchor
position={targetPosition}
centerX={targetX}
centerY={targetY}
/>
</g>
)}