From 76fe779f346a3fd9f2e725c0897f2bedd4a87d58 Mon Sep 17 00:00:00 2001 From: braks <78412429+bcakmakoglu@users.noreply.github.com> Date: Thu, 13 Jun 2024 22:27:07 +0200 Subject: [PATCH] docs: update nodes / edges pages --- docs/src/guide/edge.md | 364 ++++++++++++++++++++++++----------------- docs/src/guide/node.md | 273 +++++++++++++++++-------------- 2 files changed, 363 insertions(+), 274 deletions(-) diff --git a/docs/src/guide/edge.md b/docs/src/guide/edge.md index a40d81c2..aab31179 100644 --- a/docs/src/guide/edge.md +++ b/docs/src/guide/edge.md @@ -73,6 +73,10 @@ const straightEdge = ref([ target: '2', }, ]); + +function logEvent(name, data) { + console.log(name, data) +} # Introduction to Edges @@ -86,8 +90,7 @@ For the full list of options available for an edge, check out the [Edge Type](/t ## Adding Edges to the Graph -Edges are generally created by adding them to the `mode-value` (using `v-model`) or to the `edges` prop of the Vue Flow component. -This can be done dynamically at any point in your component's lifecycle. +Edges are rendered by passing them to the `edges` prop (or the deprecated `v-model` prop) of the Vue Flow component. :::code-group @@ -97,30 +100,30 @@ This can be done dynamically at any point in your component's lifecycle. import { ref, onMounted } from 'vue' import { VueFlow } from '@vue-flow/core' -const elements = ref([ +const nodes = ref([ { id: '1', position: { x: 50, y: 50 }, - label: 'Node 1', + data: { label: 'Node 1', }, }, { id: '2', position: { x: 50, y: 250 }, - label: 'Node 2', + data: { label: 'Node 2', }, } ]); -onMounted(() => { - elements.value.push({ - id: 'e1-2', +const edges = ref([ + { + id: 'e1->2', source: '1', target: '2', - }) -}) + } +]); ``` @@ -128,42 +131,42 @@ onMounted(() => { ``` ::: -If you are working with more complex graphs that necessitate extensive state access, the `useVueFlow` composable should -be employed. -The [`addEdges`](/typedocs/interfaces/Actions#addEdges) action is available -through [useVueFlow](/typedocs/functions/useVueFlow), allowing you to add edges straight to the state. +If you are working with more complex graphs or simply require access to the internal state, +the [useVueFlow](/typedocs/functions/useVueFlow) composable will come in handy. + +The [`addEdges`](/typedocs/interfaces/Actions#addEdges) action is available through [useVueFlow](/typedocs/functions/useVueFlow), allowing you to add edges straight to the state. What's more, this action isn't limited to the component rendering the graph; it can be utilized elsewhere, like in a Sidebar or Toolbar. @@ -176,31 +179,28 @@ const initialNodes = ref([ { id: '1', position: { x: 50, y: 50 }, - label: 'Node 1', + data: { label: 'Node 1', }, }, { id: '2', position: { x: 50, y: 250 }, - label: 'Node 2', + data: { label: 'Node 2', }, } ]) const { addEdges } = useVueFlow() -onMounted(() => { - // add an edge after mount - addEdges([ - { - source: '1', - target: '2', - - // if a node has multiple handles of the same type, - // you should specify which handle to use by id - sourceHandle: null, - targetHandle: null, - } - ]) -}) +addEdges([ + { + source: '1', + target: '2', + + // if a node has multiple handles of the same type, + // you should specify which handle to use by id + sourceHandle: null, + targetHandle: null, + } +])