ExamplesInteraction

Contextual Zoom

This example shows how the current zoom level can be used by a node to decide which content to show. We can access the zoom inside the viewport writable via the useSvelteStore hook to update our custom node whenever the zoom changes.

<script lang="ts">
  import { writable } from 'svelte/store';
  import { SvelteFlow, Background, type Node, type Edge } from '@xyflow/svelte';
 
  import '@xyflow/svelte/dist/style.css';
 
  import { initialNodes, initialEdges } from './nodes-and-edges';
  import ZoomNode from './ZoomNode.svelte';
 
  const nodes = writable<Node[]>(initialNodes);
  const edges = writable<Edge[]>(initialEdges);
 
  const nodeTypes = {
    zoom: ZoomNode
  };
</script>
 
<div style="height:100vh;">
  <SvelteFlow {nodes} {nodeTypes} {edges} fitView>
    <Background />
  </SvelteFlow>
</div>
⚠️
To surpress unknown prop warnings in the browser console, please refer to the guide.