refactor(edge-types-example): cleanup

This commit is contained in:
moklick
2020-07-21 16:48:23 +02:00
parent 8cf5b3f137
commit 8a16727cf8
5 changed files with 15 additions and 29 deletions
+1
View File
@@ -542,6 +542,7 @@ You can find all examples in the [example](example) folder or check out the live
- [interaction](https://reactflow.dev/interaction) - [interaction](https://reactflow.dev/interaction)
- [provider](https://reactflow.dev/provider) - [provider](https://reactflow.dev/provider)
- [hidden](https://reactflow.dev/hidden) - [hidden](https://reactflow.dev/hidden)
- [edge types](https://reactflow.dev/edge-types)
# Development # Development
+1 -1
View File
@@ -70,7 +70,7 @@ const CustomNodeFlow = () => {
nodeTypes={{ nodeTypes={{
selectorNode: ColorSelectorNode, selectorNode: ColorSelectorNode,
}} }}
connectionLineStyle={{ stroke: '#ddd', strokeWidth: 2 }} connectionLineStyle={{ stroke: '#ddd' }}
snapToGrid={true} snapToGrid={true}
snapGrid={[16, 16]} snapGrid={[16, 16]}
> >
+5 -25
View File
@@ -1,39 +1,23 @@
/**
* Example for checking the different edge types and source and target positions
*/
import React, { useState } from 'react'; 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'; import { getElements } from './utils';
const onLoad = (reactFlowInstance) => { const onLoad = (reactFlowInstance) => {
reactFlowInstance.fitView(); reactFlowInstance.fitView();
console.log(reactFlowInstance.getElements()); console.log(reactFlowInstance.getElements());
}; };
const initialElements = getElements(10, 10); const initialElements = getElements();
const EdgeTypesFlow = () => { const EdgeTypesFlow = () => {
const [elements, setElements] = useState(initialElements); const [elements, setElements] = useState(initialElements);
const onElementsRemove = (elementsToRemove) => setElements((els) => removeElements(elementsToRemove, els)); const onElementsRemove = (elementsToRemove) => setElements((els) => removeElements(elementsToRemove, els));
const onConnect = (params) => setElements((els) => addEdge(params, 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 ( return (
<ReactFlow <ReactFlow
elements={elements} elements={elements}
@@ -45,10 +29,6 @@ const EdgeTypesFlow = () => {
<MiniMap /> <MiniMap />
<Controls /> <Controls />
<Background /> <Background />
<button onClick={updatePos} style={{ position: 'absolute', right: 10, top: 30, zIndex: 4 }}>
change pos
</button>
</ReactFlow> </ReactFlow>
); );
}; };
+1 -1
View File
@@ -128,7 +128,7 @@ const OverviewFlow = () => {
onSelectionChange={onSelectionChange} onSelectionChange={onSelectionChange}
style={{ width: '100%', height: '100%' }} style={{ width: '100%', height: '100%' }}
onLoad={onLoad} onLoad={onLoad}
connectionLineStyle={{ stroke: '#ddd', strokeWidth: 2 }} connectionLineStyle={{ stroke: '#ddd' }}
snapToGrid={true} snapToGrid={true}
snapGrid={[16, 16]} snapGrid={[16, 16]}
> >
+7 -2
View File
@@ -2,7 +2,6 @@ import React, { useEffect, useState, CSSProperties } from 'react';
import cc from 'classcat'; import cc from 'classcat';
import { getBezierPath } from '../Edges/BezierEdge'; import { getBezierPath } from '../Edges/BezierEdge';
import { getStepPath } from '../Edges/StepEdge';
import { getSmoothStepPath } from '../Edges/SmoothStepEdge'; import { getSmoothStepPath } from '../Edges/SmoothStepEdge';
import { ElementId, Node, Transform, HandleElement, Position, ConnectionLineType, HandleType } from '../../types'; import { ElementId, Node, Transform, HandleElement, Position, ConnectionLineType, HandleType } from '../../types';
@@ -80,12 +79,18 @@ export default ({
targetPosition, targetPosition,
}); });
} else if (connectionLineType === ConnectionLineType.Step) { } else if (connectionLineType === ConnectionLineType.Step) {
dAttr = getStepPath({ dAttr = getSmoothStepPath({
xOffset,
yOffset,
centerX,
centerY, centerY,
sourceX, sourceX,
sourceY, sourceY,
sourcePosition: sourceHandle?.position,
targetX, targetX,
targetY, targetY,
targetPosition,
borderRadius: 0,
}); });
} else if (connectionLineType === ConnectionLineType.SmoothStep) { } else if (connectionLineType === ConnectionLineType.SmoothStep) {
dAttr = getSmoothStepPath({ dAttr = getSmoothStepPath({