diff --git a/README.md b/README.md index e87a9af2..3f9e9347 100644 --- a/README.md +++ b/README.md @@ -542,6 +542,7 @@ You can find all examples in the [example](example) folder or check out the live - [interaction](https://reactflow.dev/interaction) - [provider](https://reactflow.dev/provider) - [hidden](https://reactflow.dev/hidden) +- [edge types](https://reactflow.dev/edge-types) # Development diff --git a/example/src/CustomNode/index.js b/example/src/CustomNode/index.js index c346808f..9dc682c3 100644 --- a/example/src/CustomNode/index.js +++ b/example/src/CustomNode/index.js @@ -70,7 +70,7 @@ const CustomNodeFlow = () => { nodeTypes={{ selectorNode: ColorSelectorNode, }} - connectionLineStyle={{ stroke: '#ddd', strokeWidth: 2 }} + connectionLineStyle={{ stroke: '#ddd' }} snapToGrid={true} snapGrid={[16, 16]} > diff --git a/example/src/EdgeTypes/index.js b/example/src/EdgeTypes/index.js index 7fef539d..c6bae629 100644 --- a/example/src/EdgeTypes/index.js +++ b/example/src/EdgeTypes/index.js @@ -1,39 +1,23 @@ +/** + * Example for checking the different edge types and source and target positions + */ import React, { useState } from 'react'; -import ReactFlow, { removeElements, addEdge, MiniMap, isNode, Controls, Background } from 'react-flow-renderer'; +import ReactFlow, { removeElements, addEdge, MiniMap, Controls, Background } from 'react-flow-renderer'; import { getElements } from './utils'; const onLoad = (reactFlowInstance) => { reactFlowInstance.fitView(); - console.log(reactFlowInstance.getElements()); }; -const initialElements = getElements(10, 10); +const initialElements = getElements(); const EdgeTypesFlow = () => { const [elements, setElements] = useState(initialElements); const onElementsRemove = (elementsToRemove) => setElements((els) => removeElements(elementsToRemove, els)); const onConnect = (params) => setElements((els) => addEdge(params, els)); - const updatePos = () => { - setElements((elms) => { - return elms.map((el) => { - if (isNode(el)) { - return { - ...el, - position: { - x: Math.random() * window.innerWidth, - y: Math.random() * window.innerHeight, - }, - }; - } - - return el; - }); - }); - }; - return ( { - - ); }; diff --git a/example/src/Overview/index.js b/example/src/Overview/index.js index 4e822101..9eb7ddc2 100644 --- a/example/src/Overview/index.js +++ b/example/src/Overview/index.js @@ -128,7 +128,7 @@ const OverviewFlow = () => { onSelectionChange={onSelectionChange} style={{ width: '100%', height: '100%' }} onLoad={onLoad} - connectionLineStyle={{ stroke: '#ddd', strokeWidth: 2 }} + connectionLineStyle={{ stroke: '#ddd' }} snapToGrid={true} snapGrid={[16, 16]} > diff --git a/src/components/ConnectionLine/index.tsx b/src/components/ConnectionLine/index.tsx index 6daba9cb..00cc037b 100644 --- a/src/components/ConnectionLine/index.tsx +++ b/src/components/ConnectionLine/index.tsx @@ -2,7 +2,6 @@ import React, { useEffect, useState, CSSProperties } from 'react'; import cc from 'classcat'; import { getBezierPath } from '../Edges/BezierEdge'; -import { getStepPath } from '../Edges/StepEdge'; import { getSmoothStepPath } from '../Edges/SmoothStepEdge'; import { ElementId, Node, Transform, HandleElement, Position, ConnectionLineType, HandleType } from '../../types'; @@ -80,12 +79,18 @@ export default ({ targetPosition, }); } else if (connectionLineType === ConnectionLineType.Step) { - dAttr = getStepPath({ + dAttr = getSmoothStepPath({ + xOffset, + yOffset, + centerX, centerY, sourceX, sourceY, + sourcePosition: sourceHandle?.position, targetX, targetY, + targetPosition, + borderRadius: 0, }); } else if (connectionLineType === ConnectionLineType.SmoothStep) { dAttr = getSmoothStepPath({