update(examples): correct examples
Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
+22
-20
@@ -1,42 +1,44 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { VueFlow, MiniMap, Controls, Background, useVueFlow, useNodesState, useEdgesState } from '~/index'
|
import { VueFlow, MiniMap, Controls, Background, isNode, useVueFlow, addEdge } from '~/index'
|
||||||
|
|
||||||
const initialNodes = [
|
const elements = ref([
|
||||||
{ id: '1', type: 'input', label: 'Node 1', position: { x: 250, y: 5 } },
|
{ id: '1', type: 'input', label: 'Node 1', position: { x: 250, y: 5 } },
|
||||||
{ id: '2', label: 'Node 2', position: { x: 100, y: 100 } },
|
{ id: '2', label: 'Node 2', position: { x: 100, y: 100 } },
|
||||||
{ id: '3', label: 'Node 3', position: { x: 400, y: 100 } },
|
{ id: '3', label: 'Node 3', position: { x: 400, y: 100 } },
|
||||||
{ id: '4', label: 'Node 4', position: { x: 400, y: 200 } },
|
{ id: '4', label: 'Node 4', position: { x: 400, y: 200 } },
|
||||||
]
|
|
||||||
const initialEdges = [
|
|
||||||
{ id: 'e1-2', source: '1', target: '2', animated: true },
|
{ id: 'e1-2', source: '1', target: '2', animated: true },
|
||||||
{ id: 'e1-3', source: '1', target: '3' },
|
{ id: 'e1-3', source: '1', target: '3' },
|
||||||
]
|
])
|
||||||
const { onPaneReady, onNodeDragStop, onConnect, instance } = useVueFlow()
|
const { onPaneReady, onNodeDragStop, onConnect, instance } = useVueFlow()
|
||||||
const { nodes } = useNodesState({ nodes: initialNodes, applyDefault: true })
|
|
||||||
const { edges, addEdges } = useEdgesState({ edges: initialEdges, applyDefault: true })
|
|
||||||
onPaneReady(({ fitView }) => {
|
onPaneReady(({ fitView }) => {
|
||||||
fitView({ padding: 0.1 })
|
fitView({ padding: 0.1 })
|
||||||
})
|
})
|
||||||
onNodeDragStop((e) => console.log('drag stop', e))
|
onNodeDragStop((e) => console.log('drag stop', e))
|
||||||
onConnect((params) => addEdges([params]))
|
onConnect((params) => addEdge(params, elements.value))
|
||||||
|
|
||||||
const updatePos = () => {
|
const updatePos = () =>
|
||||||
nodes.forEach((el) => {
|
elements.value.forEach((el) => {
|
||||||
el.position = {
|
if (isNode(el)) {
|
||||||
x: Math.random() * 400,
|
el.position = {
|
||||||
y: Math.random() * 400,
|
x: Math.random() * 400,
|
||||||
|
y: Math.random() * 400,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
|
||||||
|
|
||||||
const logToObject = () => console.log(instance.value?.toObject())
|
const logToObject = () => console.log(instance.value.toObject())
|
||||||
const resetTransform = () => instance.value?.setTransform({ x: 0, y: 0, zoom: 1 })
|
const resetTransform = () => elements.value.push({ id: '1234', position: { x: 50, y: 50 }, label: 'Foobar' })
|
||||||
const toggleclasss = () => {
|
const toggleclasss = () => elements.value.forEach((el) => (el.class = el.class === 'light' ? 'dark' : 'light'))
|
||||||
nodes.forEach((el) => (el.class = el.class === 'light' ? 'dark' : 'light'))
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<VueFlow class="vue-flow-basic-example" :default-zoom="1.5" :min-zoom="0.2" :max-zoom="4" :zoom-on-scroll="false">
|
<VueFlow
|
||||||
|
v-model="elements"
|
||||||
|
class="vue-flow-basic-example"
|
||||||
|
:default-zoom="1.5"
|
||||||
|
:min-zoom="0.2"
|
||||||
|
:max-zoom="4"
|
||||||
|
:zoom-on-scroll="false"
|
||||||
|
>
|
||||||
<Background />
|
<Background />
|
||||||
<MiniMap />
|
<MiniMap />
|
||||||
<Controls />
|
<Controls />
|
||||||
|
|||||||
@@ -5,13 +5,14 @@ import {
|
|||||||
Elements,
|
Elements,
|
||||||
FlowElement,
|
FlowElement,
|
||||||
isEdge,
|
isEdge,
|
||||||
MiniMap,
|
|
||||||
Node,
|
Node,
|
||||||
Position,
|
Position,
|
||||||
SnapGrid,
|
SnapGrid,
|
||||||
useNodesState,
|
useNodesState,
|
||||||
useVueFlow,
|
useVueFlow,
|
||||||
VueFlow,
|
VueFlow,
|
||||||
|
Controls,
|
||||||
|
MiniMap,
|
||||||
} from '~/index'
|
} from '~/index'
|
||||||
|
|
||||||
const elements = ref<Elements>([])
|
const elements = ref<Elements>([])
|
||||||
@@ -84,7 +85,7 @@ onPaneReady((flowInstance) => {
|
|||||||
<template>
|
<template>
|
||||||
<VueFlow
|
<VueFlow
|
||||||
v-model="elements"
|
v-model="elements"
|
||||||
:style="`background: ${bgColor}`"
|
:style="{ backgroundColor: bgColor }"
|
||||||
:connection-mode="ConnectionMode.Loose"
|
:connection-mode="ConnectionMode.Loose"
|
||||||
:connection-line-style="connectionLineStyle"
|
:connection-line-style="connectionLineStyle"
|
||||||
:snap-to-grid="true"
|
:snap-to-grid="true"
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { getBezierPath, getMarkerEnd, Position, EdgeProps } from '~/index'
|
import { getBezierPath, getMarkerId, Position, EdgeProps } from '~/index'
|
||||||
|
|
||||||
interface CustomEdgeProps<T = { text: string }> extends EdgeProps<T> {
|
interface CustomEdgeProps<T = { text: string }> extends EdgeProps<T> {
|
||||||
source: string
|
source: string
|
||||||
@@ -13,7 +13,7 @@ interface CustomEdgeProps<T = { text: string }> extends EdgeProps<T> {
|
|||||||
targetY: number
|
targetY: number
|
||||||
sourcePosition: Position
|
sourcePosition: Position
|
||||||
targetPosition: Position
|
targetPosition: Position
|
||||||
markerEndId?: string
|
markerEnd?: string
|
||||||
data?: T
|
data?: T
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,7 +28,9 @@ const edgePath = computed(() =>
|
|||||||
targetPosition: props.targetPosition,
|
targetPosition: props.targetPosition,
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
const markerEnd = computed(() => getMarkerEnd(props.markerEnd, props.markerEndId))
|
console.log(props)
|
||||||
|
const markerEnd = computed(() => getMarkerId(props.markerEnd))
|
||||||
|
console.log(markerEnd.value)
|
||||||
</script>
|
</script>
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
export default {
|
export default {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { getBezierPath, getMarkerEnd } from '~/components/Edges/utils'
|
import { getEdgeCenter, getBezierPath, getMarkerId, Position, EdgeProps, EdgeText } from '~/index'
|
||||||
import { getEdgeCenter, Position, EdgeText, EdgeProps } from '~/index'
|
|
||||||
|
|
||||||
interface CustomEdgeProps extends EdgeProps {
|
interface CustomEdgeProps extends EdgeProps {
|
||||||
source: string
|
source: string
|
||||||
@@ -32,7 +31,7 @@ const edgePath = computed(() =>
|
|||||||
targetPosition: props.targetPosition,
|
targetPosition: props.targetPosition,
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
const markerEnd = computed(() => getMarkerEnd(props.markerEnd, props.markerEndId))
|
const markerEnd = computed(() => getMarkerId(props.markerEnd))
|
||||||
const center = computed(() =>
|
const center = computed(() =>
|
||||||
getEdgeCenter({
|
getEdgeCenter({
|
||||||
sourceX: props.sourceX,
|
sourceX: props.sourceX,
|
||||||
|
|||||||
@@ -2,9 +2,9 @@
|
|||||||
import CustomEdge from './CustomEdge.vue'
|
import CustomEdge from './CustomEdge.vue'
|
||||||
import CustomEdge2 from './CustomEdge2.vue'
|
import CustomEdge2 from './CustomEdge2.vue'
|
||||||
import CustomLabel from './CustomLabel.vue'
|
import CustomLabel from './CustomLabel.vue'
|
||||||
import { VueFlow, MiniMap, Controls, Background, MarkerType, useVueFlow, useElementsState } from '~/index'
|
import { VueFlow, MiniMap, Controls, Background, MarkerType, useVueFlow, useElementsState, Edge, Node } from '~/index'
|
||||||
|
|
||||||
const initialNodes = [
|
const initialNodes: Node[] = [
|
||||||
{ id: '1', type: 'input', label: 'Input 1', position: { x: 250, y: 0 } },
|
{ id: '1', type: 'input', label: 'Input 1', position: { x: 250, y: 0 } },
|
||||||
{ id: '2', label: 'Node 2', position: { x: 150, y: 100 } },
|
{ id: '2', label: 'Node 2', position: { x: 150, y: 100 } },
|
||||||
{ id: '2a', label: 'Node 2a', position: { x: 0, y: 180 } },
|
{ id: '2a', label: 'Node 2a', position: { x: 0, y: 180 } },
|
||||||
@@ -18,7 +18,7 @@ const initialNodes = [
|
|||||||
{ id: '9', type: 'output', label: 'Output 9', position: { x: 675, y: 500 } },
|
{ id: '9', type: 'output', label: 'Output 9', position: { x: 675, y: 500 } },
|
||||||
]
|
]
|
||||||
|
|
||||||
const initialEdges = [
|
const initialEdges: Edge[] = [
|
||||||
{ id: 'e1-2', source: '1', target: '2', label: 'bezier edge (default)', class: 'normal-edge' },
|
{ id: 'e1-2', source: '1', target: '2', label: 'bezier edge (default)', class: 'normal-edge' },
|
||||||
{ id: 'e2-2a', source: '2', target: '2a', type: 'smoothstep', label: 'smoothstep edge' },
|
{ id: 'e2-2a', source: '2', target: '2a', type: 'smoothstep', label: 'smoothstep edge' },
|
||||||
{ id: 'e2-3', source: '2', target: '3', type: 'step', label: 'step edge' },
|
{ id: 'e2-3', source: '2', target: '3', type: 'step', label: 'step edge' },
|
||||||
@@ -36,7 +36,9 @@ const initialEdges = [
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
labelStyle: { fill: 'red', fontWeight: 700 },
|
labelStyle: { fill: 'red', fontWeight: 700 },
|
||||||
markerEnd: MarkerType.Arrow,
|
markerEnd: {
|
||||||
|
type: MarkerType.Arrow,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'e5-7',
|
id: 'e5-7',
|
||||||
@@ -46,7 +48,9 @@ const initialEdges = [
|
|||||||
labelBgPadding: [8, 4],
|
labelBgPadding: [8, 4],
|
||||||
labelBgBorderRadius: 4,
|
labelBgBorderRadius: 4,
|
||||||
labelBgStyle: { fill: '#FFCC00', color: '#fff', fillOpacity: 0.7 },
|
labelBgStyle: { fill: '#FFCC00', color: '#fff', fillOpacity: 0.7 },
|
||||||
markerEnd: MarkerType.ArrowClosed,
|
markerEnd: {
|
||||||
|
type: MarkerType.ArrowClosed,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'e5-8',
|
id: 'e5-8',
|
||||||
@@ -54,7 +58,9 @@ const initialEdges = [
|
|||||||
target: '8',
|
target: '8',
|
||||||
type: 'custom',
|
type: 'custom',
|
||||||
data: { text: 'custom edge' },
|
data: { text: 'custom edge' },
|
||||||
markerEnd: MarkerType.ArrowClosed,
|
markerEnd: {
|
||||||
|
type: MarkerType.ArrowClosed,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'e5-9',
|
id: 'e5-9',
|
||||||
|
|||||||
@@ -1,38 +1,84 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import GroupNode from './GroupNode.vue'
|
import { ConnectionMode, useElementsState, useVueFlow, VueFlow, MiniMap, Background, Controls } from '~/index'
|
||||||
import { VueFlow, Elements, Edge, Connection, addEdge } from '~/index'
|
|
||||||
|
|
||||||
const elements = ref<Elements<{ label: string; group?: string }>>([
|
const { onConnect } = useVueFlow({
|
||||||
{ id: 'node-2', label: 'node-2', position: { x: 50, y: 5 } },
|
fitViewOnInit: true,
|
||||||
{
|
connectionMode: ConnectionMode.Loose,
|
||||||
id: 'group-a',
|
})
|
||||||
type: 'group',
|
const { nodes, edges, addEdges } = useElementsState({
|
||||||
label: 'A',
|
nodes: [
|
||||||
position: { x: 50, y: 100 },
|
{ id: '1', type: 'input', label: 'Node 1', position: { x: 250, y: 5 }, class: 'light' },
|
||||||
children: [
|
{
|
||||||
{
|
id: '2',
|
||||||
id: 'node-1',
|
label: 'Node 2',
|
||||||
label: 'node-1',
|
position: { x: 100, y: 100 },
|
||||||
position: { x: 250, y: 5 },
|
class: 'light',
|
||||||
extent: 'parent',
|
style: { backgroundColor: 'rgba(255, 0, 0, 0.8)', width: '200px', height: '200px' },
|
||||||
},
|
children: [
|
||||||
],
|
{
|
||||||
},
|
id: '2a',
|
||||||
{
|
label: 'Node 2a',
|
||||||
id: 'group-b',
|
position: { x: 10, y: 50 },
|
||||||
style: { zIndex: 2 },
|
},
|
||||||
selectable: false,
|
],
|
||||||
label: 'B',
|
},
|
||||||
position: { x: 500, y: 100 },
|
{ id: '3', label: 'Node 3', position: { x: 320, y: 100 }, class: 'light' },
|
||||||
},
|
{
|
||||||
])
|
id: '4',
|
||||||
|
label: 'Node 4',
|
||||||
|
position: { x: 320, y: 200 },
|
||||||
|
class: 'light',
|
||||||
|
style: { backgroundColor: 'rgba(255, 0, 0, 0.7)', width: '300px', height: '300px' },
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
id: '4a',
|
||||||
|
label: 'Node 4a',
|
||||||
|
position: { x: 15, y: 65 },
|
||||||
|
class: 'light',
|
||||||
|
extent: 'parent',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: '4b',
|
||||||
|
label: 'Node 4b',
|
||||||
|
position: { x: 15, y: 120 },
|
||||||
|
class: 'light',
|
||||||
|
style: { backgroundColor: 'rgba(255, 0, 255, 0.7)', height: '150px', width: '270px' },
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
id: '4b1',
|
||||||
|
label: 'Node 4b1',
|
||||||
|
position: { x: 20, y: 40 },
|
||||||
|
class: 'light',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: '4b2',
|
||||||
|
label: 'Node 4b2',
|
||||||
|
position: { x: 100, y: 100 },
|
||||||
|
class: 'light',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
edges: [
|
||||||
|
{ id: 'e1-2', source: '1', target: '2', animated: true },
|
||||||
|
{ id: 'e1-3', source: '1', target: '3' },
|
||||||
|
{ id: 'e2a-4a', source: '2a', target: '4a' },
|
||||||
|
{ id: 'e3-4', source: '3', target: '4' },
|
||||||
|
{ id: 'e3-4b', source: '3', target: '4b' },
|
||||||
|
{ id: 'e4a-4b1', source: '4a', target: '4b1' },
|
||||||
|
{ id: 'e4a-4b2', source: '4a', target: '4b2' },
|
||||||
|
{ id: 'e4b1-4b2', source: '4b1', target: '4b2' },
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
const onConnect = (params: Edge | Connection) => addEdge(params, elements.value)
|
onConnect((params) => addEdges([params]))
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<VueFlow v-model="elements" @connect="onConnect">
|
<VueFlow>
|
||||||
<template #node-group="aProps">
|
<MiniMap />
|
||||||
<GroupNode v-bind="aProps" />
|
<Controls />
|
||||||
</template>
|
<Background />
|
||||||
</VueFlow>
|
</VueFlow>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -37,8 +37,9 @@ const elements = ref(initialElements)
|
|||||||
const onLoad = (flowInstance: FlowInstance) => flowInstance.fitView()
|
const onLoad = (flowInstance: FlowInstance) => flowInstance.fitView()
|
||||||
const onEdgeUpdateStart = (edge: Edge) => console.log('start update', edge)
|
const onEdgeUpdateStart = (edge: Edge) => console.log('start update', edge)
|
||||||
const onEdgeUpdateEnd = (edge: Edge) => console.log('end update', edge)
|
const onEdgeUpdateEnd = (edge: Edge) => console.log('end update', edge)
|
||||||
const onEdgeUpdate = ({ edge, connection }: FlowEvents['edgeUpdate']) =>
|
const onEdgeUpdate = ({ edge, connection }: FlowEvents['edgeUpdate']) => {
|
||||||
(elements.value = updateEdge(edge, connection, elements.value))
|
elements.value = updateEdge(edge, connection, elements.value)
|
||||||
|
}
|
||||||
const onConnect = (params: Connection | Edge) => (elements.value = addEdge(params, elements.value))
|
const onConnect = (params: Connection | Edge) => (elements.value = addEdge(params, elements.value))
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
|
|||||||
Reference in New Issue
Block a user