Files
vue-flow/examples/Stress/StressExample.vue
T
Braks 0b2764028f update(nodes): watch nodes width for dimension update
* add force param to setElements, if set we clear the elements arr (default true)
* wait for store watcher until store is ready (i.e. a state has been set)
* move renderer css class to Renderer.vue

Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com>
2021-11-25 19:29:13 +01:00

83 lines
1.9 KiB
Vue

<script lang="ts" setup>
import { CSSProperties } from 'vue'
import { getElements } from './utils'
import {
VueFlow,
removeElements,
addEdge,
MiniMap,
isNode,
Controls,
Background,
FlowInstance,
Elements,
Connection,
Edge,
} from '~/index'
const buttonWrapperStyles: CSSProperties = { position: 'absolute', right: 10, top: 10, zIndex: 4 }
const instance = ref<FlowInstance>()
const onLoad = (flowInstance: FlowInstance) => {
flowInstance.fitView()
instance.value = flowInstance
console.log(flowInstance.getElements())
}
const initialElements: Elements = getElements(10, 10)
const elements = ref(initialElements)
const onConnect = (params: Connection | Edge) => (elements.value = addEdge(params, elements.value))
const onElementsRemove = (elementsToRemove: Elements) => (elements.value = removeElements(elementsToRemove, elements.value))
const updatePos = () => {
elements.value = elements.value.map((el) => {
if (isNode(el)) {
return {
...el,
position: {
x: Math.random() * window.innerWidth,
y: Math.random() * window.innerHeight,
},
}
}
return el
})
}
const updateElements = () => {
const grid = Math.ceil(Math.random() * 10)
elements.value = getElements(grid, grid)
setTimeout(() => instance.value.fitView({ padding: 0.5 }))
}
</script>
<template>
<VueFlow
v-model="elements"
:loading="{ label: 'Loading...', transition: { name: 'fade', mode: 'out-in' } }"
@load="onLoad"
@elementsRemove="onElementsRemove"
@connect="onConnect"
>
<MiniMap />
<Controls />
<Background />
<div :style="buttonWrapperStyles">
<button style="margin-right: 5px" @click="updatePos">change pos</button>
<button @click="updateElements">update elements</button>
</div>
</VueFlow>
</template>
<style>
.fade-enter-active,
.fade-leave-active {
transition: opacity 0.35s ease;
}
.fade-enter-from,
.fade-leave-active {
opacity: 0;
}
</style>