feat(examples): add node-toolbar example

Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
braks
2022-12-09 20:52:01 +01:00
committed by Braks
parent f6acbd8dc6
commit 196215d9e2
5 changed files with 130 additions and 10 deletions
+32 -9
View File
@@ -1,24 +1,47 @@
<script lang="ts" setup>
import { VueFlow, useVueFlow } from '@vue-flow/core'
<script setup>
import { Background, MiniMap, Panel, PanelPosition } from '@vue-flow/additional-components'
import { VueFlow, isNode, useVueFlow } from '@vue-flow/core'
import { nextTick, ref } from 'vue'
import { getElements } from './utils'
const { nodes, edges } = getElements(10, 10)
const { nodes, edges } = getElements(15, 15)
const elements = ref([...nodes, ...edges])
const { onPaneReady } = useVueFlow({
nodes,
edges,
})
const { onPaneReady, dimensions, onNodeClick, getEdges, fitView } = useVueFlow()
onPaneReady((i) => {
i.fitView({
padding: 0.2,
})
console.log(i.getEdges.value)
console.log(i.getElements.value)
})
const toggleClass = () => elements.value.forEach((el) => (el.class = el.class === 'light' ? 'dark' : 'light'))
const updatePos = () => {
elements.value.forEach((el) => {
if (isNode(el)) {
el.position = {
x: Math.random() * 10 * dimensions.value.width,
y: Math.random() * 10 * dimensions.value.height,
}
}
})
nextTick(() => {
fitView({ duration: 1000, padding: 0.5 })
})
}
</script>
<template>
<VueFlow />
<VueFlow v-model="elements" :min-zoom="0.1">
<Background />
<Panel :position="PanelPosition.TopRight">
<button style="margin-right: 5px" @click="updatePos">update positions</button>
<button @click="toggleClass">toggle class</button>
</Panel>
</VueFlow>
</template>