From 75355b04e730d904da392b12ce1f6a8969032d6e Mon Sep 17 00:00:00 2001
From: braks <78412429+bcakmakoglu@users.noreply.github.com>
Date: Wed, 7 Feb 2024 22:22:15 +0100
Subject: [PATCH] feat(docs): add animation edge to layouting example
---
docs/examples/layout/AnimationEdge.vue | 103 +++++++++----------
docs/examples/layout/App.vue | 16 ++-
docs/examples/layout/ProcessNode.vue | 56 ++++++++--
docs/examples/layout/initial-elements.js | 46 ++++-----
docs/examples/layout/useRunProcess.js | 49 ++++-----
examples/vite/src/Layouting/useRunProcess.ts | 4 +-
6 files changed, 157 insertions(+), 117 deletions(-)
diff --git a/docs/examples/layout/AnimationEdge.vue b/docs/examples/layout/AnimationEdge.vue
index 0a2fee97..4bfb5aa9 100644
--- a/docs/examples/layout/AnimationEdge.vue
+++ b/docs/examples/layout/AnimationEdge.vue
@@ -1,6 +1,6 @@
@@ -148,14 +133,18 @@ export default {
-
+
-
+
+
+ 📦
+
+
diff --git a/docs/examples/layout/App.vue b/docs/examples/layout/App.vue
index 57ea3529..d2ad3e2c 100644
--- a/docs/examples/layout/App.vue
+++ b/docs/examples/layout/App.vue
@@ -4,6 +4,7 @@ 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 AnimationEdge from './AnimationEdge.vue'
import { initialEdges, initialNodes } from './initial-elements.js'
import { useRunProcess } from './useRunProcess'
@@ -62,11 +63,20 @@ function handleLayout(direction) {
-
+
-
-
+
+
diff --git a/docs/examples/layout/ProcessNode.vue b/docs/examples/layout/ProcessNode.vue
index d0f297cd..b9567ea9 100644
--- a/docs/examples/layout/ProcessNode.vue
+++ b/docs/examples/layout/ProcessNode.vue
@@ -1,6 +1,6 @@
-
-
+
+
-
❌
-
🚧
-
😎
-
🚫
-
📦
+
+ {{ processLabel }}
+
@@ -50,6 +88,7 @@ const bgColor = toRef(() => {
.process-node {
padding: 10px;
color: white;
+ border: 1px solid #4b5563;
border-radius: 99px;
font-size: 12px;
width: 18px;
@@ -57,7 +96,6 @@ const bgColor = toRef(() => {
display: flex;
align-items: center;
justify-content: center;
- box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
}
.spinner {
diff --git a/docs/examples/layout/initial-elements.js b/docs/examples/layout/initial-elements.js
index 80b104cd..b0619cf3 100644
--- a/docs/examples/layout/initial-elements.js
+++ b/docs/examples/layout/initial-elements.js
@@ -1,74 +1,74 @@
const position = { x: 0, y: 0 }
-const type = 'process'
+const nodeType = 'process'
+const edgeType = 'animation'
export const initialNodes = [
{
id: '1',
- label: 'Start',
position,
- type,
+ type: nodeType,
},
{
id: '2',
position,
- type,
+ type: nodeType,
},
{
id: '2a',
position,
- type,
+ type: nodeType,
},
{
id: '2b',
position,
- type,
+ type: nodeType,
},
{
id: '2c',
position,
- type,
+ type: nodeType,
},
{
id: '2d',
position,
- type,
+ type: nodeType,
},
{
id: '3',
position,
- type,
+ type: nodeType,
},
{
id: '4',
position,
- type,
+ type: nodeType,
},
{
id: '5',
position,
- type,
+ type: nodeType,
},
{
id: '6',
position,
- type,
+ type: nodeType,
},
{
id: '7',
position,
- type,
+ type: nodeType,
},
]
export const initialEdges = [
- { id: 'e1-2', source: '1', target: '2', type: 'smoothstep', animated: true },
- { id: 'e1-3', source: '1', target: '3', type: 'smoothstep', animated: true },
- { id: 'e2-2a', source: '2', target: '2a', type: 'smoothstep', animated: true },
- { id: 'e2-2b', source: '2', target: '2b', type: 'smoothstep', animated: true },
- { id: 'e2-2c', source: '2', target: '2c', type: 'smoothstep', animated: true },
- { id: 'e2c-2d', source: '2c', target: '2d', type: 'smoothstep', animated: true },
- { id: 'e3-7', source: '3', target: '4', type: 'smoothstep', animated: true },
- { id: 'e4-5', source: '4', target: '5', type: 'smoothstep', animated: true },
- { id: 'e5-6', source: '5', target: '6', type: 'smoothstep', animated: true },
- { id: 'e5-7', source: '5', target: '7', type: 'smoothstep', animated: true },
+ { id: 'e1-2', source: '1', target: '2', type: edgeType, animated: true },
+ { id: 'e1-3', source: '1', target: '3', type: edgeType, animated: true },
+ { id: 'e2-2a', source: '2', target: '2a', type: edgeType, animated: true },
+ { id: 'e2-2b', source: '2', target: '2b', type: edgeType, animated: true },
+ { id: 'e2-2c', source: '2', target: '2c', type: edgeType, animated: true },
+ { id: 'e2c-2d', source: '2c', target: '2d', type: edgeType, animated: true },
+ { id: 'e3-7', source: '3', target: '4', type: edgeType, animated: true },
+ { id: 'e4-5', source: '4', target: '5', type: edgeType, animated: true },
+ { id: 'e5-6', source: '5', target: '6', type: edgeType, animated: true },
+ { id: 'e5-7', source: '5', target: '7', type: edgeType, animated: true },
]
diff --git a/docs/examples/layout/useRunProcess.js b/docs/examples/layout/useRunProcess.js
index eb48410f..34a90f60 100644
--- a/docs/examples/layout/useRunProcess.js
+++ b/docs/examples/layout/useRunProcess.js
@@ -18,7 +18,7 @@ export function useRunProcess(dagreGraph) {
const executedNodes = new Set()
const runningTasks = new Map()
- async function runNode(node) {
+ async function runNode(node, isStart = false) {
if (executedNodes.has(node.id)) {
return
}
@@ -30,33 +30,36 @@ export function useRunProcess(dagreGraph) {
// Simulate an async process with a random timeout between 1 and 3 seconds
const delay = Math.floor(Math.random() * 2000) + 1000
return new Promise((resolve) => {
- const timeout = setTimeout(async () => {
- const children = graph.value.successors(node.id)
+ const timeout = setTimeout(
+ async () => {
+ const children = graph.value.successors(node.id)
- // Randomly decide whether the node will throw an error
- const willThrowError = Math.random() < 0.15
+ // Randomly decide whether the node will throw an error
+ const willThrowError = Math.random() < 0.15
- if (willThrowError) {
- updateNodeData(node.id, { isRunning: false, hasError: true })
+ if (willThrowError) {
+ updateNodeData(node.id, { isRunning: false, hasError: true })
+
+ await skipDescendants(node.id)
+ runningTasks.delete(node.id)
+
+ resolve()
+ return
+ }
+
+ updateNodeData(node.id, { isRunning: false, isFinished: true })
- await skipDescendants(node.id)
runningTasks.delete(node.id)
+ if (children.length > 0) {
+ // Run the process on the children in parallel
+ await Promise.all(children.map((id) => runNode({ id })))
+ }
+
resolve()
- return
- }
-
- updateNodeData(node.id, { isRunning: false, isFinished: true })
-
- runningTasks.delete(node.id)
-
- if (children.length > 0) {
- // Run the process on the children in parallel
- await Promise.all(children.map((id) => runNode({ id })))
- }
-
- resolve()
- }, delay)
+ },
+ isStart ? 0 : delay,
+ )
runningTasks.set(node.id, timeout)
})
@@ -75,7 +78,7 @@ export function useRunProcess(dagreGraph) {
const startingNodes = nodes.filter((node) => graph.value.predecessors(node.id)?.length === 0)
// Run the process on all starting nodes in parallel
- await Promise.all(startingNodes.map(runNode))
+ await Promise.all(startingNodes.map((node) => runNode(node, true)))
clear()
}
diff --git a/examples/vite/src/Layouting/useRunProcess.ts b/examples/vite/src/Layouting/useRunProcess.ts
index 22e37ac8..1dc245bd 100644
--- a/examples/vite/src/Layouting/useRunProcess.ts
+++ b/examples/vite/src/Layouting/useRunProcess.ts
@@ -20,7 +20,7 @@ export function useRunProcess(dagreGraph: MaybeRefOrGetter
const executedNodes = new Set()
const runningTasks = new Map()
- async function runNode(node: { id: string }, isStartingNode = false) {
+ async function runNode(node: { id: string }, isStart = false) {
if (executedNodes.has(node.id)) {
return
}
@@ -59,7 +59,7 @@ export function useRunProcess(dagreGraph: MaybeRefOrGetter
resolve()
},
- isStartingNode ? 0 : delay,
+ isStart ? 0 : delay,
)
runningTasks.set(node.id, timeout)