update(examples): Add stress example

This commit is contained in:
Braks
2021-10-22 10:00:21 +02:00
parent 89efc0b7e4
commit 5611f79ea8
3 changed files with 95 additions and 0 deletions
+30
View File
@@ -0,0 +1,30 @@
import { Elements } from '~/index'
export function getElements(xElements = 10, yElements = 10): Elements {
const initialElements = []
let nodeId = 1
let recentNodeId = null
for (let y = 0; y < yElements; y++) {
for (let x = 0; x < xElements; x++) {
const position = { x: x * 100, y: y * 50 }
const data = { label: `Node ${nodeId}` }
const node = {
id: nodeId.toString(),
style: { width: 50, fontSize: 11 },
data,
position,
}
initialElements.push(node)
if (recentNodeId && nodeId <= xElements * yElements) {
initialElements.push({ id: `${x}-${y}`, source: recentNodeId.toString(), target: nodeId.toString() })
}
recentNodeId = nodeId
nodeId++
}
}
return initialElements as Elements
}