@@ -14,12 +14,13 @@ const elements = ref<Elements>([
14
14
{ id: ' e1-2' , source: ' 1' , target: ' 2' , animated: true },
15
15
{ id: ' e1-3' , source: ' 1' , target: ' 3' },
16
16
])
17
- const { onNodeDragStop, onEdgeClick, onConnect, addEdges, setTransform, toObject } = useVueFlow ({
18
- minZoom: 0.2 ,
19
- maxZoom: 4 ,
20
- connectOnClick: true ,
21
- fitViewOnInit: false ,
22
- })
17
+ const { onNodeDragStop, onEdgeClick, onConnect, addEdges, setTransform, toObject, fitView, onPaneReady, setNodes, setEdges } =
18
+ useVueFlow ({
19
+ minZoom: 0.2 ,
20
+ maxZoom: 4 ,
21
+ connectOnClick: true ,
22
+ fitViewOnInit: false ,
23
+ })
23
24
24
25
onNodeDragStop ((e ) => console .log (' drag stop' , e .event ))
25
26
onEdgeClick (console .log )
@@ -35,13 +36,29 @@ const updatePos = () =>
35
36
}
36
37
})
37
38
39
+ onPaneReady ((instance ) => {
40
+ setNodes ([
41
+ { id: ' 1' , type: ' input' , label: ' Node 1' , position: { x: 250 , y: 5 }, class: ' light' },
42
+ { id: ' 2' , label: ' Node 2' , position: { x: 100 , y: 100 }, class: ' light' },
43
+ { id: ' 3' , label: ' Node 3' , position: { x: 400 , y: 100 }, class: ' light' },
44
+ { id: ' 4' , label: ' Node 4' , position: { x: 400 , y: 200 }, class: ' light' },
45
+ ])
46
+
47
+ setEdges ([
48
+ { id: ' e1-2' , source: ' 1' , target: ' 2' , animated: true },
49
+ { id: ' e1-3' , source: ' 1' , target: ' 3' },
50
+ ])
51
+
52
+ instance .fitView ()
53
+ })
54
+
38
55
const logToObject = () => console .log (toObject ())
39
56
const resetTransform = () => setTransform ({ x: 0 , y: 0 , zoom: 1 })
40
57
const toggleclass = () => elements .value .forEach ((el ) => (el .class = el .class === ' light' ? ' dark' : ' light' ))
41
58
</script >
42
59
43
60
<template >
44
- <VueFlow v-model =" elements" fit-view-on-init connection-mode =" strict" class =" vue-flow-basic-example" >
61
+ <VueFlow v-model =" elements" connection-mode =" strict" class =" vue-flow-basic-example" >
45
62
<Background />
46
63
<MiniMap />
47
64
<Controls />
0 commit comments