---
title: "Workflow: Large Workflows"
description: "Workflows of 10,000 nodes and 100,000 connections: a worker draws the connections and far nodes into one canvas, at most 150 cards become HTML, a frame that costs too much draws fewer connections and says so, groups collapse whole stages."
slug: "workflow-large"
---

import { DocPage, PageHeader, SourceFiles, SourceNote, DocText, DocLink, H2 } from "../../lib/components/index";

<DocPage meta={meta}>

<PageHeader slug="workflow-large" title="Large Workflows" component="workflow">
  A workflow grows past what a page can hold as HTML long before it grows past what a reader can follow. The editor keeps the HTML bounded however big the graph gets: the connections and every node far from the view are pixels in one canvas, drawn by a worker; the cards you read and edit are the few near the view. The numbers below each example are the editor's own readouts of the last frame.
</PageHeader>

<H2 id="ten-thousand">10,000 nodes, 100,000 connections</H2>

<DocText><code>data-generate</code> builds a synthetic workflow - stages of nodes with four typed ports each, connections from a stage to one of the next three - the same one for the same <code>data-seed</code>. Zoomed out, the canvas draws the node boxes and as many connections as the frame allows; zoom in past 55 % and the nodes near the view become cards. The tree on the left is how a reader finds one node among them.</DocText>

<DocText><code>tree()</code> hands a <DocLink href="data-tree.html">Data Tree</DocLink> every group and node as records (10,010 here), the tree's filter searches all of them, and a pick reveals the node in the editor - with Follow pressed the view flies to it and the cards around it appear. A click on a card opens the one way to it in the tree. Neither side keeps more HTML than it shows: the tree windows its rows, the editor its cards. <DocLink href="workflow-editing.html">Editing & Structure</DocLink> shows the same navigator over groups and a subworkflow.</DocText>

```html example label="10,000 nodes" schema="none" hint="Type 'Decode 4321' in the filter on the left and pick it: with Follow pressed the view flies there and its cards appear; released, the pick only selects. Click a card: its group opens in the tree, every other one closes. Scroll or pinch to zoom, drag to pan - zoomed out the readout says how many connections the last frame drew and that they were sampled; never more than 150 cards." previewStyle="align-items:stretch;"
<div class="grid gap-2">
  <div class="toolbar flex-wrap" role="toolbar" aria-label="Navigate 10,000 nodes">
    <button class="toggle" id="big-follow" type="button" aria-pressed="true" data-size="sm">
      <svg
        aria-hidden="true"
        width="16"
        height="16"
        viewBox="0 0 24 24"
        fill="none"
        stroke="currentColor"
        stroke-width="2"
        stroke-linecap="round"
        stroke-linejoin="round"
      >
        <circle cx="12" cy="12" r="10" />
        <path d="M22 12h-4M6 12H2M12 6V2M12 22v-4" />
      </svg>
      Follow
    </button>
    <div class="separator" data-orientation="vertical" role="separator"></div>
    <button
      class="btn"
      data-variant="ghost"
      data-size="sm"
      type="button"
      data-workflow-for="big"
      data-workflow-action="fit"
      >Fit</button
    >
    <button
      class="btn"
      data-variant="ghost"
      data-size="sm"
      type="button"
      data-workflow-for="big"
      data-workflow-action="zoom-in"
      >Zoom in</button
    >
    <button
      class="btn"
      data-variant="ghost"
      data-size="sm"
      type="button"
      data-workflow-for="big"
      data-workflow-action="zoom-out"
      >Zoom out</button
    >
    <span class="text-sm text-muted-foreground">
      <span data-workflow-for="big" data-workflow-output="nodes"></span> nodes ·
      <span data-workflow-for="big" data-workflow-output="edges"></span> connections ·
      <span data-workflow-for="big" data-workflow-output="drawn"></span> ·
      <span data-workflow-for="big" data-workflow-output="cards"></span> ·
      <span data-workflow-for="big" data-workflow-output="frame"></span>
    </span>
  </div>
  <div class="grid gap-2" style="grid-template-columns: minmax(11rem, 15rem) minmax(0, 1fr)">
    <div class="grid gap-2 content-start">
      <input class="input" data-tree-filter="big-tree" aria-label="Find a node" placeholder="Find a node…" />
      <div
        class="data-tree"
        id="big-tree"
        aria-label="10,000 nodes in ten groups"
        data-label-field="title"
        data-exclusive
        data-persist="none"
        style="height: 25rem"
      ></div>
    </div>
    <div
      class="workflow"
      id="big"
      data-generate="10000"
      data-edges="100000"
      data-seed="7"
      data-stage="100"
      data-groups="10"
      aria-label="A synthetic workflow of 10,000 nodes in ten groups"
      style="--workflow-height: 27.75rem"
    ></div>
  </div>
</div>
<script>
  document.addEventListener('DOMContentLoaded', () => {
    const W = df$.shadcn.workflow;
    const T = df$.shadcn.dataTree;
    const wf = document.getElementById('big');
    const tree = document.getElementById('big-tree');
    const follow = document.getElementById('big-follow');
    // the tree's records: every group, node and subworkflow node of the document, each naming its parent row
    const load = () =>
      T.setSource(tree, W.tree(wf), {
        render: (label, row) => {
          const name = document.createElement('span');
          name.textContent = row.title;
          label.append(name);
          if (row.kind === 'node') return;
          const kind = document.createElement('span');
          kind.className = 'data-tree-meta';
          kind.textContent = row.kind;
          label.append(kind);
        },
      });
    load();
    let timer = 0;
    wf.addEventListener('workflow-change', () => {
      clearTimeout(timer);
      timer = setTimeout(load, 200);
    });
    // a pick in the tree selects the node - entering its subworkflow; Follow also moves the view to it
    let syncing = false;
    tree.addEventListener('data-tree-select', (e) => {
      const row = e.detail.record;
      if (row.kind === 'group') return;
      syncing = true;
      W.reveal(wf, row.path, { camera: follow.getAttribute('aria-pressed') === 'true' });
      syncing = false;
    });
    // a selection in the editor opens the one way to it in the tree (data-exclusive) and shows it there
    wf.addEventListener('workflow-select', (e) => {
      if (syncing || e.detail.selected.length !== 1) return;
      T.reveal(tree, [...e.detail.path, e.detail.selected[0]].join('/'));
    });
  });
</script>
```

<H2 id="budget">The budget</H2>

<DocText>Three numbers bound a frame: 150 HTML cards, 3,000 nodes drawn on the canvas and 5,000 connections. Below 12 % zoom a node is only a box in its color, one path per color, and 30,000 of them fit - enough for all 10,000 above. The spatial hash answers "what is in view" without looking at every node, and a query stops at its budget and says so. When drawing a frame takes more than 20 ms the next frame draws fewer connections; a run of fast frames earns them back. Nothing is removed from the graph - the readout says <em>sampled</em>, the selected connection and the connections of the selected nodes are always drawn, and the outline and the inspector reach every node.</DocText>

```mermaid label="A frame under budget" caption="Fig 1. The camera asks the spatial hash for what is in view; each answer is cut at its budget, and a slow frame lowers the connection budget for the next one."
flowchart LR
    Camera["camera:<br/>pan, zoom"] --> Hash["spatial hash:<br/>what is in view"]
    Hash -->|"at most 150"| Cards["HTML cards"]
    Hash -->|"at most 3,000 (30,000 boxes below 12 %)"| Boxes["canvas nodes"]
    Hash -->|"at most the budget"| Lines["canvas connections"]
    Lines --> Cost{"over 20 ms?"}
    Cost -->|"yes: fewer"| Hash
```

<DocText>Cards and groups move with the live camera in the same frame as your pointer; the worker's last bitmap is moved and scaled by a transform until the next one arrives. A drag previews without committing - one transaction on release - so a 10,000-node graph is not copied while you move.</DocText>

<H2 id="stages">Stages in groups</H2>

<DocText><code>data-groups</code> wraps every few stages in a group; <code>data-collapsed</code> collapses every other one. A collapsed group is one small header: its nodes leave the canvas and the connections that crossed its border end at the header, so a big workflow reads as a few blocks. Click a header's button to open or close it.</DocText>

```html example label="Collapsed stages" schema="none" hint="Four groups of three stages, every other one collapsed. Open one with its + button, close it with −; drag a group by its header to move all its nodes. This one draws on the main thread (data-worker=&quot;none&quot;) - the fallback where no worker can start." previewStyle="align-items:stretch;"
<div
  class="workflow"
  id="stages"
  data-generate="48"
  data-edges="80"
  data-seed="3"
  data-stage="4"
  data-groups="3"
  data-collapsed
  data-worker="none"
  aria-label="Stages in groups"
  style="--workflow-height: 26rem"
></div>
```

<DocText>The limits a document may reach are 100,000 nodes, 1,000,000 connections and 10,000 groups; past them an import is refused before anything changes. See <DocLink href="workflow-formats.html">Formats & Import</DocLink>.</DocText>

<SourceFiles component="workflow" section="css">
  <SourceNote for="css">The stylesheet and the script are the Workflow's.</SourceNote>
</SourceFiles>

<SourceFiles component="workflow" section="js" jsTitle="JS" />

</DocPage>
