From 7bd29964a82f340510a698040ffd6c5fa0f326e1 Mon Sep 17 00:00:00 2001 From: braks <78412429+bcakmakoglu@users.noreply.github.com> Date: Tue, 6 Feb 2024 13:04:00 +0100 Subject: [PATCH] docs: add run process to layouting example --- docs/examples/index.ts | 4 +- docs/examples/layout/App.vue | 32 ++++++--- docs/examples/layout/ProcessNode.vue | 81 ++++++++++++++++++++++ docs/examples/layout/index.ts | 2 + docs/examples/layout/initial-elements.js | 30 ++++---- docs/examples/layout/useRunProcess.js | 88 ++++++++++++++++++++++++ 6 files changed, 213 insertions(+), 24 deletions(-) create mode 100644 docs/examples/layout/ProcessNode.vue create mode 100644 docs/examples/layout/useRunProcess.js diff --git a/docs/examples/index.ts b/docs/examples/index.ts index 46a468db..b8836d57 100644 --- a/docs/examples/index.ts +++ b/docs/examples/index.ts @@ -18,7 +18,7 @@ import { IntersectionApp, IntersectionCSS } from './intersection' import { SnapToHandleApp, SnappableConnectionLine } from './connection-radius' import { NodeResizerApp, ResizableNode } from './node-resizer' import { ToolbarApp, ToolbarNode } from './node-toolbar' -import { LayoutApp, LayoutElements } from './layout' +import { LayoutApp, LayoutElements, LayoutNode, LayoutScript } from './layout' export const exampleImports = { basic: { @@ -127,6 +127,8 @@ export const exampleImports = { layout: { 'App.vue': LayoutApp, 'initial-elements.js': LayoutElements, + 'ProcessNode.vue': LayoutNode, + 'useRunProcess.js': LayoutScript, 'additionalImports': { dagre: 'https://cdn.skypack.dev/pin/dagre@v0.8.5-NOlknF82nBdUHQKLJWRC/mode=imports,min/optimized/dagre.js', }, diff --git a/docs/examples/layout/App.vue b/docs/examples/layout/App.vue index b75bbe0b..3ff97031 100644 --- a/docs/examples/layout/App.vue +++ b/docs/examples/layout/App.vue @@ -3,40 +3,48 @@ import dagre from 'dagre' import { nextTick, ref } from 'vue' import { Panel, Position, VueFlow, useVueFlow } from '@vue-flow/core' import { Background } from '@vue-flow/background' +import ProcessNode from './ProcessNode.vue' import { initialEdges, initialNodes } from './initial-elements.js' +import { useRunProcess } from './useRunProcess' const nodes = ref(initialNodes) const edges = ref(initialEdges) +const dagreGraph = ref(new dagre.graphlib.Graph()) + +dagreGraph.value.setDefaultEdgeLabel(() => ({})) + +const { run } = useRunProcess() + const { findNode, fitView } = useVueFlow() function handleLayout(direction) { // we create a new graph instance, in case some nodes/edges were removed, otherwise dagre would act as if they were still there - const dagreGraph = new dagre.graphlib.Graph() + dagreGraph.value = new dagre.graphlib.Graph() - dagreGraph.setDefaultEdgeLabel(() => ({})) + dagreGraph.value.setDefaultEdgeLabel(() => ({})) const isHorizontal = direction === 'LR' - dagreGraph.setGraph({ rankdir: direction }) + dagreGraph.value.setGraph({ rankdir: direction }) for (const node of nodes.value) { // if you need width+height of nodes for your layout, you can use the dimensions property of the internal node (`GraphNode` type) const graphNode = findNode(node.id) - dagreGraph.setNode(node.id, { width: graphNode.dimensions.width || 150, height: graphNode.dimensions.height || 50 }) + dagreGraph.value.setNode(node.id, { width: graphNode.dimensions.width || 150, height: graphNode.dimensions.height || 50 }) } for (const edge of edges.value) { - dagreGraph.setEdge(edge.source, edge.target) + dagreGraph.value.setEdge(edge.source, edge.target) } - dagre.layout(dagreGraph) + dagre.layout(dagreGraph.value) // set nodes with updated positions nodes.value = nodes.value.map((node) => { - const nodeWithPosition = dagreGraph.node(node.id) + const nodeWithPosition = dagreGraph.value.node(node.id) return { ...node, @@ -55,11 +63,17 @@ function handleLayout(direction) {