update(examples): move examples into src dir

This commit is contained in:
Braks
2022-04-04 21:42:48 +02:00
parent 9539d7f263
commit c1594b0071
53 changed files with 34 additions and 35 deletions
+16
View File
@@ -0,0 +1,16 @@
<script lang="ts" setup>
import { getElements } from './utils'
import { VueFlow, FlowInstance } from '@braks/vue-flow'
const instance = ref<FlowInstance>()
const onLoad = (flowInstance: FlowInstance) => {
flowInstance.fitView()
instance.value = flowInstance
console.log(flowInstance.getNodes())
}
const { nodes, edges } = getElements(10, 10)
</script>
<template>
<VueFlow :nodes="nodes" :edges="edges" @pane-ready="onLoad"> </VueFlow>
</template>
+33
View File
@@ -0,0 +1,33 @@
import { Edge, Node } from '@braks/vue-flow'
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 node = {
id: nodeId.toString(),
style: { width: 50, fontSize: 11 },
label: `Node ${nodeId}`,
position,
}
initialNodes.push(node)
if (recentNodeId && nodeId <= xElements * yElements) {
initialEdges.push({ id: `${x}-${y}`, source: recentNodeId.toString(), target: nodeId.toString() })
}
recentNodeId = nodeId
nodeId++
}
}
return {
nodes: initialNodes,
edges: initialEdges,
}
}