Horizontal Flow
A diagram can go from left to right or from top to bottom, but you can also create mixed ones.
For controlling the direction of a diagram you can adjust the handle positions of a node with the sourcePosition
and targetPosition
props.
<script lang="ts">
import { writable } from 'svelte/store';
import {
SvelteFlow,
Controls,
Background,
BackgroundVariant,
MiniMap,
type NodeTypes,
type Node,
type Edge
} from '@xyflow/svelte';
import { initialNodes, initialEdges } from './nodes-and-edges';
import '@xyflow/svelte/dist/style.css';
const nodes = writable<Node[]>(initialNodes);
const edges = writable<Edge[]>(initialEdges);
</script>
<main>
<SvelteFlow {nodes} {edges} fitView minZoom={0.1} maxZoom={2.5}>
<Controls />
<Background variant={BackgroundVariant.Dots} />
<MiniMap />
</SvelteFlow>
</main>
<style>
main {
height: 100vh;
}
:global(.svelte-flow .svelte-flow__node.parent) {
background-color: rgba(220, 220, 255, 0.4);
}
</style>