refactor(flow)!: properly nest components

Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
Braks
2021-12-20 19:29:52 +01:00
parent 6bdea72b20
commit c96f62f622
12 changed files with 121 additions and 149 deletions
+11 -8
View File
@@ -1,24 +1,24 @@
import { Elements } from '~/index'
import { Edge, Node } from '~/index'
export function getElements(xElements = 10, yElements = 10): Elements {
const initialElements = []
export function getElements(xElements = 10, yElements = 10) {
const initialNodes: Node[] = []
const initialEdges: Edge[] = []
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,
label: `Node ${nodeId}`,
position,
}
initialElements.push(node)
initialNodes.push(node)
if (recentNodeId && nodeId <= xElements * yElements) {
initialElements.push({ id: `${x}-${y}`, source: recentNodeId.toString(), target: nodeId.toString() })
initialEdges.push({ id: `${x}-${y}`, source: recentNodeId.toString(), target: nodeId.toString() })
}
recentNodeId = nodeId
@@ -26,5 +26,8 @@ export function getElements(xElements = 10, yElements = 10): Elements {
}
}
return initialElements
return {
nodes: initialNodes,
edges: initialEdges,
}
}