chore(example): add switch

This commit is contained in:
moklick
2021-01-11 17:05:58 +01:00
parent 7791d1d2c3
commit e426bd0a08
4 changed files with 71 additions and 4 deletions
+11 -3
View File
@@ -33,15 +33,23 @@ const StressFlow = () => {
});
};
const updateElements = () => {
const grid = Math.ceil(Math.random() * 10);
setElements(getElements(grid, grid));
};
return (
<ReactFlow elements={elements} onLoad={onLoad} onElementsRemove={onElementsRemove} onConnect={onConnect}>
<MiniMap />
<Controls />
<Background />
<button onClick={updatePos} style={{ position: 'absolute', right: 10, top: 30, zIndex: 4 }}>
change pos
</button>
<div style={{ position: 'absolute', right: 10, top: 10, zIndex: 4 }}>
<button onClick={updatePos} style={{ marginRight: 5 }}>
change pos
</button>
<button onClick={updateElements}>update elements</button>
</div>
</ReactFlow>
);
};
+1 -1
View File
@@ -15,7 +15,7 @@ export function getElements(xElements = 10, yElements = 10) {
};
initialElements.push(node);
if (recentNodeId && nodeId <= (xElements * yElements)) {
if (recentNodeId && nodeId <= xElements * yElements) {
initialElements.push({ id: `${x}-${y}`, source: recentNodeId.toString(), target: nodeId.toString() });
}