# Diagram

Read and edit organizations and strategy maps with shared relationships.

## Preview

diagram-preview-1.jsx

```jsx
import { useState } from "react";
import { Diagram, applyGraphChange } from "@/components/ui/diagram";
import { Avatar } from "@/components/ui/avatar";

export default function Example() {
  const initial = compactPeople;
  const [value, setValue] = useState(initial);
  const [reject, setReject] = useState(false);
  return (
    <div
      className={`diagram-demo${""}`}
      inert={undefined}
      aria-hidden={undefined}
    >
      <Diagram
        value={value}
        viewport={undefined}
        connector={"elbow"}
        editable={false}
        aria-label="Product organization"
        nodeWidth={184}
        onChange={async (change) => {
          if (reject) {
            setReject(false);
            throw new Error("Could not save this change. Try again.");
          }
          setValue((current) => applyGraphChange(current, change));
        }}
        createNode={({ id, label, formData }) => ({
          id,
          label,
          data: {
            role: String(formData?.get("role") || "Product team"),
            avatarSeed: String(formData?.get("avatarSeed") || id),
          },
        })}
        renderNode={(node) => <PersonCard node={node} />}
        relationshipTypes={[
          {
            value: "reporting",
            label: "Reporting line",
          },
          {
            value: "taskforce",
            label: "Taskforce",
          },
          {
            value: "paired",
            label: "Human\u2013agent pairing",
          },
        ]}
      />
    </div>
  );
}

function normalizeColor(value) {
  return value.replace(/^#+/, "");
}

function diceAvatarUrl(style, seedOrOptions, maybeOptions) {
  const base =
    typeof seedOrOptions === "string"
      ? {
          ...maybeOptions,
          seed: seedOrOptions,
        }
      : {
          ...seedOrOptions,
        };
  const seed = base.seed ?? "ghost";
  const params = new URLSearchParams();
  params.set("seed", seed);
  if (base.backgroundColor !== undefined) {
    const colors = Array.isArray(base.backgroundColor)
      ? base.backgroundColor
      : [base.backgroundColor];
    const csv = colors.map(normalizeColor).filter(Boolean).join(",");
    if (csv) params.set("backgroundColor", csv);
  }
  if (base.size !== undefined) params.set("size", String(base.size));
  if (base.skinColor) params.set("skinColor", normalizeColor(base.skinColor));
  return `https://api.dicebear.com/${"10.x"}/${style}/svg?${params.toString()}`;
}

var people = {
  nodes: [
    {
      id: "maya",
      label: "Maya Chen",
      data: {
        role: "CEO",
        skinColor: "f3c6a5",
      },
    },
    {
      id: "sam",
      label: "Sam Rivera",
      data: {
        role: "CPO",
        skinColor: "c58b62",
      },
    },
    {
      id: "alex",
      label: "Alex Morgan",
      data: {
        role: "CTO",
        skinColor: "895235",
      },
    },
    {
      id: "robin",
      label: "Robin Park",
      data: {
        role: "Head of Design",
        skinColor: "f9d8c4",
      },
    },
    {
      id: "taylor",
      label: "Taylor Kim",
      data: {
        role: "Head of Research",
        skinColor: "dfab81",
      },
    },
    {
      id: "jordan",
      label: "Jordan Lee",
      data: {
        role: "Platform manager",
        skinColor: "f3c6a5",
      },
    },
    {
      id: "casey",
      label: "Casey Allen",
      data: {
        role: "Product designer",
        skinColor: "a86d4f",
      },
    },
    {
      id: "avery",
      label: "Avery Singh",
      data: {
        role: "User researcher",
        skinColor: "c58b62",
      },
    },
    {
      id: "morgan",
      label: "Morgan Diaz",
      data: {
        role: "Product engineer",
        skinColor: "dfab81",
      },
    },
  ],
  edges: [
    {
      id: "maya-sam",
      source: "maya",
      target: "sam",
      role: "reporting",
    },
    {
      id: "maya-alex",
      source: "maya",
      target: "alex",
      role: "reporting",
    },
    {
      id: "sam-robin",
      source: "sam",
      target: "robin",
      role: "reporting",
    },
    {
      id: "sam-taylor",
      source: "sam",
      target: "taylor",
      role: "reporting",
    },
    {
      id: "alex-jordan",
      source: "alex",
      target: "jordan",
      role: "reporting",
    },
    {
      id: "robin-casey",
      source: "robin",
      target: "casey",
      role: "reporting",
    },
    {
      id: "taylor-avery",
      source: "taylor",
      target: "avery",
      role: "reporting",
    },
    {
      id: "jordan-morgan",
      source: "jordan",
      target: "morgan",
      role: "reporting",
    },
  ],
};

var compactPeople = {
  nodes: people.nodes.slice(0, 3),
  edges: people.edges.slice(0, 2),
};

function PersonCard({ node, layout = "inline" }) {
  const seed = node.data?.avatarSeed ?? node.id;
  const skinColor = node.data?.skinColor;
  return (
    <div className="diagram-demo-person" data-layout={layout}>
      <div className="diagram-demo-person-identity">
        <Avatar
          name={node.label}
          seed={seed}
          src={
            skinColor &&
            diceAvatarUrl("dylan", {
              seed,
              skinColor,
            })
          }
          kind={node.data?.agent ? "agent" : "human"}
          className={layout === "compact" ? "ui-avatar-small" : undefined}
          aria-hidden="true"
        />
        <div className="diagram-demo-person-copy">
          <span className="diagram-demo-name">{node.label}</span>
          <span>{node.data?.role}</span>
        </div>
      </div>
      {node.data?.note && (
        <small className="diagram-demo-person-meta">{node.data.note}</small>
      )}
    </div>
  );
}

var paired = {
  nodes: [
    ...people.nodes.slice(0, 6),
    {
      id: "research-agent",
      label: "Research agent",
      data: {
        role: "AI agent",
        agent: true,
        note: "Paired with Taylor Kim",
      },
    },
    {
      id: "code-agent",
      label: "Code agent",
      data: {
        role: "AI agent",
        agent: true,
        note: "Paired with Jordan Lee",
      },
    },
    {
      id: "partner",
      label: "Priya Shah",
      data: {
        role: "External researcher",
        note: "Northstar \xB7 Contractor",
        skinColor: "a86d4f",
      },
    },
  ],
  edges: [
    ...people.edges.slice(0, 5),
    {
      id: "taylor-agent",
      source: "taylor",
      target: "research-agent",
      role: "reporting",
    },
    {
      id: "jordan-agent",
      source: "jordan",
      target: "code-agent",
      role: "reporting",
    },
    {
      id: "shared-partner",
      source: "taylor",
      target: "partner",
      role: "reporting",
    },
    {
      id: "partner-taskforce",
      source: "jordan",
      target: "partner",
      role: "taskforce",
      line: "dashed",
      label: "Launch taskforce",
    },
    {
      id: "agent-pair",
      source: "robin",
      target: "research-agent",
      role: "paired",
      line: "dotted",
      label: "Design review",
    },
  ],
};

var shared = {
  nodes: people.nodes.slice(0, 6),
  edges: [
    ...people.edges.slice(0, 5),
    {
      id: "shared-research",
      source: "alex",
      target: "taylor",
      role: "reporting",
    },
    {
      id: "skip-level",
      source: "maya",
      target: "jordan",
      role: "advisory",
      line: "dashed",
      label: "Architecture review",
    },
  ],
};

```

diagram-preview-1.css

```css
/* apps/web/src/demos/library/diagram-demo.css */
.diagram-demo {
  position: relative;
  width: 1040px;
  max-width: 100%;
  min-width: 0;
  background: var(--background);
  color: var(--foreground);
  font-weight: 400;
}
.diagram-demo-person {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}
.diagram-demo-person-identity {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  min-width: 0;
}
.diagram-demo-person-copy {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.diagram-demo-person .diagram-demo-name {
  font-size: 13px;
  font-weight: 400;
  line-height: 18px;
  color: var(--foreground);
  overflow-wrap: anywhere;
  padding-inline-end: 16px;
}
.diagram-demo-person-copy > span,
.diagram-demo-person-meta {
  font-size: 12px;
  line-height: 18px;
  color: var(--muted-foreground);
  overflow-wrap: anywhere;
}
.diagram-demo-person-meta {
  align-self: stretch;
}
.diagram-demo-person[data-layout=compact] .diagram-demo-person-identity {
  gap: 8px;
}
.diagram-demo-person:is([data-layout=stacked], [data-layout=centered]) .diagram-demo-person-identity {
  flex-direction: column;
  gap: 8px;
}
.diagram-demo-person[data-layout=centered] {
  align-items: center;
  text-align: center;
}
.diagram-demo-person[data-layout=centered] .diagram-demo-person-identity,
.diagram-demo-person[data-layout=centered] .diagram-demo-person-copy {
  align-items: center;
}
.diagram-demo-person[data-layout=centered] .diagram-demo-name {
  padding-inline-end: 0;
}
.diagram-demo-goal {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.diagram-demo-goal .diagram-demo-name {
  font-size: 14px;
  font-weight: 400;
  line-height: 21px;
  color: var(--foreground);
}
.diagram-demo-goal > small,
.diagram-demo-goal > span {
  font-size: 12px;
  color: var(--muted-foreground);
}
.diagram-demo--viewport > .ui-graph-surface {
  height: 620px;
}
.diagram-demo--thumbnail {
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  pointer-events: none;
}
.diagram-demo--thumbnail > .ui-graph-surface {
  max-width: 100%;
}
.diagram-demo-node-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  width: 100%;
  padding: 24px;
}
.diagram-demo-card-example {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}
.diagram-demo-card-example > .ui-graph-node {
  flex: 1;
}
.diagram-demo-card-label {
  font-size: 12px;
  line-height: 18px;
  color: var(--muted-foreground);
  text-transform: capitalize;
}
.diagram-demo-connectors {
  display: grid;
  gap: 24px;
  width: 100%;
}
.diagram-demo-connector-name {
  display: block;
  padding-inline: 24px;
  color: var(--muted-foreground);
  font-size: 12px;
  text-transform: capitalize;
}

```

## Design guidance

Use Diagram for organizations, reporting relationships, strategy and request branches inside an ordinary page, profile or dashboard. Its embedded view measures and fits the graph width while preserving readable text and contained scrolling for large branches. Set align="start" for a top-left tree: the first card starts at the left, and descendants follow in indented rows. Pass the GraphViewport renderer as viewport when a large map needs pan, zoom or drag-to-reparent. The base item ships no canvas engine. Use [Node canvas](/components/node-canvas) when users own spatial placement and typed workflow ports. Use [Tree view](/components/tree-view) for compact hierarchical navigation.

Both views accept caller-owned nodes and explicit edges. Stable IDs identify a person, goal or agent even when several parents connect to it. Edge role distinguishes reporting, alignment and taskforce relationships. Reporting and alignment edges point from parent to child; connection forms let you choose both endpoints. Geometry, disclosure and selection remain separate view state.

Enable editing with both editable and onChange. Apply accepted proposals to the latest application value with applyGraphChange. A rejected promise keeps the draft and reports the error; persistence, undo and business permissions belong to your application. getChangePermission returns { allowed: false, reason } to deny an otherwise valid change.

## Installation

```sh
npx shadcn@latest add https://ghost-ui.com/r/diagram.json
```

Install the optional canvas renderer only for viewport:

```sh
npx shadcn@latest add https://ghost-ui.com/r/graph-viewport.json
```

Examples compose real Ghost owners; install Avatar, Progress or Button when the copied example imports them.

Package consumers import views from @collectivecreation/ghost-ui/graphs, or the individual @collectivecreation/ghost-ui/components/diagram entry. Load @collectivecreation/ghost-ui/styles.css, @collectivecreation/ghost-ui/components.css and @collectivecreation/ghost-ui/graphs.css. The optional graph entry uses @xyflow/react@12.12.1; Diagram's default layout also uses @dagrejs/dagre@3.1.3. The pure @collectivecreation/ghost-ui/graph-model entry needs neither engine nor React.

## Basic usage

```tsx
import { useState } from "react";
import { Diagram, applyGraphChange, type GraphValue } from "@/components/ui/diagram";

export function Example() {
  const [value, setValue] = useState<GraphValue>({
    nodes: [{ id: "lead", label: "Product lead" }, { id: "research", label: "Research agent" }],
    edges: [{ id: "delegation", source: "lead", target: "research", role: "reporting" }],
  });
  return <Diagram aria-label="Product team" value={value} editable
    onChange={change => setValue(current => applyGraphChange(current, change))} />;
}
```

## Structures

For standalone card examples, NodeCard.Root contains NodeCard.Content and an optional NodeCard.Footer; NodeCard.Title belongs in NodeCard.Header. Within Diagram.renderNode, compose these content parts without another root, because Diagram supplies the card shell.

- Diagram
  - Caller content from renderNode or default label
  - Relationships from value.edges
  - Disclosure from collapsedIds or local state

The slot labels describe inputs; they are not additional exports.

renderNode supplies content inside Diagram’s canonical card shell; compose NodeCard.Header, Title, Description, Content, Footer and Actions there. Do not add another Root inside the renderer. The default view supplies selection, menus, responsive editors, ports and disclosure. Empty data uses the shared EmptyState with a first-position action when editing is enabled. Never use a spatial container ID as a reporting parent.

Search temporarily reveals matching ancestor paths without overwriting stored collapse state. collapsedIds controls disclosure; omit it for local disclosure. Pair controlled disclosure with onCollapsedIdsChange; local creation expands its parent automatically. Supply layout to replace default geometry while keeping graph facts and editing intact. The default measured layout preserves ordinary sibling input order. A shared node cannot occupy contradictory positions under several parents at once.

## Examples

### Node cards

Compose the same Card-backed parts with an inline avatar, a smaller avatar, a separate avatar row or centered content. Keep the name and role together. Contractor details and human pairing belong in a full-width metadata row below the identity.

diagram-node-cards-2.jsx

```jsx
import { NodeCard } from "@/components/ui/diagram";
import { Avatar } from "@/components/ui/avatar";

export default function Example() {
  const examples = [
    {
      layout: "inline",
      label: "Inline",
      node: {
        id: "priya",
        label: "Priya Shah",
        data: {
          role: "External researcher",
          note: "Northstar \xB7 Contractor",
          skinColor: "a86d4f",
        },
      },
    },
    {
      layout: "compact",
      label: "Smaller avatar",
      node: {
        id: "sam",
        label: "Sam Rivera",
        data: {
          role: "CPO",
          note: "Product organization",
          skinColor: "c58b62",
        },
      },
    },
    {
      layout: "stacked",
      label: "Avatar row",
      node: {
        id: "research",
        label: "Research agent",
        data: {
          role: "AI research",
          agent: true,
          note: "Paired with Taylor Kim",
        },
      },
    },
    {
      layout: "centered",
      label: "Centered",
      node: {
        id: "code",
        label: "Code agent",
        data: {
          role: "AI engineering",
          agent: true,
          note: "Paired with Jordan Lee",
        },
      },
    },
  ];
  return (
    <div className="diagram-demo-node-cards">
      {examples.map(({ layout, label, node }) => (
        <div className="diagram-demo-card-example" key={layout}>
          <span className="diagram-demo-card-label">{label}</span>
          <NodeCard.Root tabIndex={0} aria-label={`${label} node card`}>
            <NodeCard.Content>
              <PersonCard node={node} layout={layout} />
            </NodeCard.Content>
          </NodeCard.Root>
        </div>
      ))}
    </div>
  );
}

function normalizeColor(value) {
  return value.replace(/^#+/, "");
}

function diceAvatarUrl(style, seedOrOptions, maybeOptions) {
  const base =
    typeof seedOrOptions === "string"
      ? {
          ...maybeOptions,
          seed: seedOrOptions,
        }
      : {
          ...seedOrOptions,
        };
  const seed = base.seed ?? "ghost";
  const params = new URLSearchParams();
  params.set("seed", seed);
  if (base.backgroundColor !== undefined) {
    const colors = Array.isArray(base.backgroundColor)
      ? base.backgroundColor
      : [base.backgroundColor];
    const csv = colors.map(normalizeColor).filter(Boolean).join(",");
    if (csv) params.set("backgroundColor", csv);
  }
  if (base.size !== undefined) params.set("size", String(base.size));
  if (base.skinColor) params.set("skinColor", normalizeColor(base.skinColor));
  return `https://api.dicebear.com/${"10.x"}/${style}/svg?${params.toString()}`;
}

var people = {
  nodes: [
    {
      id: "maya",
      label: "Maya Chen",
      data: {
        role: "CEO",
        skinColor: "f3c6a5",
      },
    },
    {
      id: "sam",
      label: "Sam Rivera",
      data: {
        role: "CPO",
        skinColor: "c58b62",
      },
    },
    {
      id: "alex",
      label: "Alex Morgan",
      data: {
        role: "CTO",
        skinColor: "895235",
      },
    },
    {
      id: "robin",
      label: "Robin Park",
      data: {
        role: "Head of Design",
        skinColor: "f9d8c4",
      },
    },
    {
      id: "taylor",
      label: "Taylor Kim",
      data: {
        role: "Head of Research",
        skinColor: "dfab81",
      },
    },
    {
      id: "jordan",
      label: "Jordan Lee",
      data: {
        role: "Platform manager",
        skinColor: "f3c6a5",
      },
    },
    {
      id: "casey",
      label: "Casey Allen",
      data: {
        role: "Product designer",
        skinColor: "a86d4f",
      },
    },
    {
      id: "avery",
      label: "Avery Singh",
      data: {
        role: "User researcher",
        skinColor: "c58b62",
      },
    },
    {
      id: "morgan",
      label: "Morgan Diaz",
      data: {
        role: "Product engineer",
        skinColor: "dfab81",
      },
    },
  ],
  edges: [
    {
      id: "maya-sam",
      source: "maya",
      target: "sam",
      role: "reporting",
    },
    {
      id: "maya-alex",
      source: "maya",
      target: "alex",
      role: "reporting",
    },
    {
      id: "sam-robin",
      source: "sam",
      target: "robin",
      role: "reporting",
    },
    {
      id: "sam-taylor",
      source: "sam",
      target: "taylor",
      role: "reporting",
    },
    {
      id: "alex-jordan",
      source: "alex",
      target: "jordan",
      role: "reporting",
    },
    {
      id: "robin-casey",
      source: "robin",
      target: "casey",
      role: "reporting",
    },
    {
      id: "taylor-avery",
      source: "taylor",
      target: "avery",
      role: "reporting",
    },
    {
      id: "jordan-morgan",
      source: "jordan",
      target: "morgan",
      role: "reporting",
    },
  ],
};

var compactPeople = {
  nodes: people.nodes.slice(0, 3),
  edges: people.edges.slice(0, 2),
};

function PersonCard({ node, layout = "inline" }) {
  const seed = node.data?.avatarSeed ?? node.id;
  const skinColor = node.data?.skinColor;
  return (
    <div className="diagram-demo-person" data-layout={layout}>
      <div className="diagram-demo-person-identity">
        <Avatar
          name={node.label}
          seed={seed}
          src={
            skinColor &&
            diceAvatarUrl("dylan", {
              seed,
              skinColor,
            })
          }
          kind={node.data?.agent ? "agent" : "human"}
          className={layout === "compact" ? "ui-avatar-small" : undefined}
          aria-hidden="true"
        />
        <div className="diagram-demo-person-copy">
          <span className="diagram-demo-name">{node.label}</span>
          <span>{node.data?.role}</span>
        </div>
      </div>
      {node.data?.note && (
        <small className="diagram-demo-person-meta">{node.data.note}</small>
      )}
    </div>
  );
}

var paired = {
  nodes: [
    ...people.nodes.slice(0, 6),
    {
      id: "research-agent",
      label: "Research agent",
      data: {
        role: "AI agent",
        agent: true,
        note: "Paired with Taylor Kim",
      },
    },
    {
      id: "code-agent",
      label: "Code agent",
      data: {
        role: "AI agent",
        agent: true,
        note: "Paired with Jordan Lee",
      },
    },
    {
      id: "partner",
      label: "Priya Shah",
      data: {
        role: "External researcher",
        note: "Northstar \xB7 Contractor",
        skinColor: "a86d4f",
      },
    },
  ],
  edges: [
    ...people.edges.slice(0, 5),
    {
      id: "taylor-agent",
      source: "taylor",
      target: "research-agent",
      role: "reporting",
    },
    {
      id: "jordan-agent",
      source: "jordan",
      target: "code-agent",
      role: "reporting",
    },
    {
      id: "shared-partner",
      source: "taylor",
      target: "partner",
      role: "reporting",
    },
    {
      id: "partner-taskforce",
      source: "jordan",
      target: "partner",
      role: "taskforce",
      line: "dashed",
      label: "Launch taskforce",
    },
    {
      id: "agent-pair",
      source: "robin",
      target: "research-agent",
      role: "paired",
      line: "dotted",
      label: "Design review",
    },
  ],
};

var shared = {
  nodes: people.nodes.slice(0, 6),
  edges: [
    ...people.edges.slice(0, 5),
    {
      id: "shared-research",
      source: "alex",
      target: "taylor",
      role: "reporting",
    },
    {
      id: "skip-level",
      source: "maya",
      target: "jordan",
      role: "advisory",
      line: "dashed",
      label: "Architecture review",
    },
  ],
};

```

diagram-node-cards-2.css

```css
/* apps/web/src/demos/library/diagram-demo.css */
.diagram-demo {
  position: relative;
  width: 1040px;
  max-width: 100%;
  min-width: 0;
  background: var(--background);
  color: var(--foreground);
  font-weight: 400;
}
.diagram-demo-person {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}
.diagram-demo-person-identity {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  min-width: 0;
}
.diagram-demo-person-copy {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.diagram-demo-person .diagram-demo-name {
  font-size: 13px;
  font-weight: 400;
  line-height: 18px;
  color: var(--foreground);
  overflow-wrap: anywhere;
  padding-inline-end: 16px;
}
.diagram-demo-person-copy > span,
.diagram-demo-person-meta {
  font-size: 12px;
  line-height: 18px;
  color: var(--muted-foreground);
  overflow-wrap: anywhere;
}
.diagram-demo-person-meta {
  align-self: stretch;
}
.diagram-demo-person[data-layout=compact] .diagram-demo-person-identity {
  gap: 8px;
}
.diagram-demo-person:is([data-layout=stacked], [data-layout=centered]) .diagram-demo-person-identity {
  flex-direction: column;
  gap: 8px;
}
.diagram-demo-person[data-layout=centered] {
  align-items: center;
  text-align: center;
}
.diagram-demo-person[data-layout=centered] .diagram-demo-person-identity,
.diagram-demo-person[data-layout=centered] .diagram-demo-person-copy {
  align-items: center;
}
.diagram-demo-person[data-layout=centered] .diagram-demo-name {
  padding-inline-end: 0;
}
.diagram-demo-node-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  width: 100%;
  padding: 24px;
}
.diagram-demo-card-example {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}
.diagram-demo-card-example > .ui-graph-node {
  flex: 1;
}
.diagram-demo-card-label {
  font-size: 12px;
  line-height: 18px;
  color: var(--muted-foreground);
  text-transform: capitalize;
}

```

### Node card surfaces

Outline, subtle and ghost reuse Card's variants. Subtle has no border at rest; hover and focus darken its existing border. Layout and surface style are independent choices; keep the corner clear for the view's contextual actions.

diagram-node-card-surfaces-3.jsx

```jsx
import { NodeCard } from "@/components/ui/diagram";
import { Avatar } from "@/components/ui/avatar";

export default function Example() {
  const node = {
    id: "research",
    label: "Research agent",
    data: {
      role: "AI research",
      agent: true,
      note: "Paired with Taylor Kim",
    },
  };
  return (
    <div className="diagram-demo-node-cards">
      {["outline", "subtle", "ghost"].map((variant, index) => (
        <div className="diagram-demo-card-example" key={variant}>
          <span className="diagram-demo-card-label">{variant}</span>
          <NodeCard.Root
            variant={variant}
            tabIndex={0}
            aria-label={`${variant} node card`}
          >
            <NodeCard.Content>
              <PersonCard node={node} />
            </NodeCard.Content>
            <NodeCard.Footer>
              {["Ready", "Reviewing sources", "Waiting for review"][index]}
            </NodeCard.Footer>
          </NodeCard.Root>
        </div>
      ))}
    </div>
  );
}

function normalizeColor(value) {
  return value.replace(/^#+/, "");
}

function diceAvatarUrl(style, seedOrOptions, maybeOptions) {
  const base =
    typeof seedOrOptions === "string"
      ? {
          ...maybeOptions,
          seed: seedOrOptions,
        }
      : {
          ...seedOrOptions,
        };
  const seed = base.seed ?? "ghost";
  const params = new URLSearchParams();
  params.set("seed", seed);
  if (base.backgroundColor !== undefined) {
    const colors = Array.isArray(base.backgroundColor)
      ? base.backgroundColor
      : [base.backgroundColor];
    const csv = colors.map(normalizeColor).filter(Boolean).join(",");
    if (csv) params.set("backgroundColor", csv);
  }
  if (base.size !== undefined) params.set("size", String(base.size));
  if (base.skinColor) params.set("skinColor", normalizeColor(base.skinColor));
  return `https://api.dicebear.com/${"10.x"}/${style}/svg?${params.toString()}`;
}

var people = {
  nodes: [
    {
      id: "maya",
      label: "Maya Chen",
      data: {
        role: "CEO",
        skinColor: "f3c6a5",
      },
    },
    {
      id: "sam",
      label: "Sam Rivera",
      data: {
        role: "CPO",
        skinColor: "c58b62",
      },
    },
    {
      id: "alex",
      label: "Alex Morgan",
      data: {
        role: "CTO",
        skinColor: "895235",
      },
    },
    {
      id: "robin",
      label: "Robin Park",
      data: {
        role: "Head of Design",
        skinColor: "f9d8c4",
      },
    },
    {
      id: "taylor",
      label: "Taylor Kim",
      data: {
        role: "Head of Research",
        skinColor: "dfab81",
      },
    },
    {
      id: "jordan",
      label: "Jordan Lee",
      data: {
        role: "Platform manager",
        skinColor: "f3c6a5",
      },
    },
    {
      id: "casey",
      label: "Casey Allen",
      data: {
        role: "Product designer",
        skinColor: "a86d4f",
      },
    },
    {
      id: "avery",
      label: "Avery Singh",
      data: {
        role: "User researcher",
        skinColor: "c58b62",
      },
    },
    {
      id: "morgan",
      label: "Morgan Diaz",
      data: {
        role: "Product engineer",
        skinColor: "dfab81",
      },
    },
  ],
  edges: [
    {
      id: "maya-sam",
      source: "maya",
      target: "sam",
      role: "reporting",
    },
    {
      id: "maya-alex",
      source: "maya",
      target: "alex",
      role: "reporting",
    },
    {
      id: "sam-robin",
      source: "sam",
      target: "robin",
      role: "reporting",
    },
    {
      id: "sam-taylor",
      source: "sam",
      target: "taylor",
      role: "reporting",
    },
    {
      id: "alex-jordan",
      source: "alex",
      target: "jordan",
      role: "reporting",
    },
    {
      id: "robin-casey",
      source: "robin",
      target: "casey",
      role: "reporting",
    },
    {
      id: "taylor-avery",
      source: "taylor",
      target: "avery",
      role: "reporting",
    },
    {
      id: "jordan-morgan",
      source: "jordan",
      target: "morgan",
      role: "reporting",
    },
  ],
};

var compactPeople = {
  nodes: people.nodes.slice(0, 3),
  edges: people.edges.slice(0, 2),
};

function PersonCard({ node, layout = "inline" }) {
  const seed = node.data?.avatarSeed ?? node.id;
  const skinColor = node.data?.skinColor;
  return (
    <div className="diagram-demo-person" data-layout={layout}>
      <div className="diagram-demo-person-identity">
        <Avatar
          name={node.label}
          seed={seed}
          src={
            skinColor &&
            diceAvatarUrl("dylan", {
              seed,
              skinColor,
            })
          }
          kind={node.data?.agent ? "agent" : "human"}
          className={layout === "compact" ? "ui-avatar-small" : undefined}
          aria-hidden="true"
        />
        <div className="diagram-demo-person-copy">
          <span className="diagram-demo-name">{node.label}</span>
          <span>{node.data?.role}</span>
        </div>
      </div>
      {node.data?.note && (
        <small className="diagram-demo-person-meta">{node.data.note}</small>
      )}
    </div>
  );
}

var paired = {
  nodes: [
    ...people.nodes.slice(0, 6),
    {
      id: "research-agent",
      label: "Research agent",
      data: {
        role: "AI agent",
        agent: true,
        note: "Paired with Taylor Kim",
      },
    },
    {
      id: "code-agent",
      label: "Code agent",
      data: {
        role: "AI agent",
        agent: true,
        note: "Paired with Jordan Lee",
      },
    },
    {
      id: "partner",
      label: "Priya Shah",
      data: {
        role: "External researcher",
        note: "Northstar \xB7 Contractor",
        skinColor: "a86d4f",
      },
    },
  ],
  edges: [
    ...people.edges.slice(0, 5),
    {
      id: "taylor-agent",
      source: "taylor",
      target: "research-agent",
      role: "reporting",
    },
    {
      id: "jordan-agent",
      source: "jordan",
      target: "code-agent",
      role: "reporting",
    },
    {
      id: "shared-partner",
      source: "taylor",
      target: "partner",
      role: "reporting",
    },
    {
      id: "partner-taskforce",
      source: "jordan",
      target: "partner",
      role: "taskforce",
      line: "dashed",
      label: "Launch taskforce",
    },
    {
      id: "agent-pair",
      source: "robin",
      target: "research-agent",
      role: "paired",
      line: "dotted",
      label: "Design review",
    },
  ],
};

var shared = {
  nodes: people.nodes.slice(0, 6),
  edges: [
    ...people.edges.slice(0, 5),
    {
      id: "shared-research",
      source: "alex",
      target: "taylor",
      role: "reporting",
    },
    {
      id: "skip-level",
      source: "maya",
      target: "jordan",
      role: "advisory",
      line: "dashed",
      label: "Architecture review",
    },
  ],
};

```

diagram-node-card-surfaces-3.css

```css
/* apps/web/src/demos/library/diagram-demo.css */
.diagram-demo {
  position: relative;
  width: 1040px;
  max-width: 100%;
  min-width: 0;
  background: var(--background);
  color: var(--foreground);
  font-weight: 400;
}
.diagram-demo-person {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}
.diagram-demo-person-identity {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  min-width: 0;
}
.diagram-demo-person-copy {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.diagram-demo-person .diagram-demo-name {
  font-size: 13px;
  font-weight: 400;
  line-height: 18px;
  color: var(--foreground);
  overflow-wrap: anywhere;
  padding-inline-end: 16px;
}
.diagram-demo-person-copy > span,
.diagram-demo-person-meta {
  font-size: 12px;
  line-height: 18px;
  color: var(--muted-foreground);
  overflow-wrap: anywhere;
}
.diagram-demo-person-meta {
  align-self: stretch;
}
.diagram-demo-person[data-layout=compact] .diagram-demo-person-identity {
  gap: 8px;
}
.diagram-demo-person:is([data-layout=stacked], [data-layout=centered]) .diagram-demo-person-identity {
  flex-direction: column;
  gap: 8px;
}
.diagram-demo-person[data-layout=centered] {
  align-items: center;
  text-align: center;
}
.diagram-demo-person[data-layout=centered] .diagram-demo-person-identity,
.diagram-demo-person[data-layout=centered] .diagram-demo-person-copy {
  align-items: center;
}
.diagram-demo-person[data-layout=centered] .diagram-demo-name {
  padding-inline-end: 0;
}
.diagram-demo-node-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  width: 100%;
  padding: 24px;
}
.diagram-demo-card-example {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}
.diagram-demo-card-example > .ui-graph-node {
  flex: 1;
}
.diagram-demo-card-label {
  font-size: 12px;
  line-height: 18px;
  color: var(--muted-foreground);
  text-transform: capitalize;
}

```

### Edit an organization

Hover or focus a card edge to reveal its attached add/connect actions. Node and connection editors use a Popover on desktop and a bottom Drawer with a grip below 640px. Edit details includes the name, role, avatar seed and parent. Shared children keep their other parents and descendants. Collapse counts show all descendants; the tooltip also gives the direct-child count.

diagram-edit-an-organization-4.jsx

```jsx
import { useState } from "react";
import { Diagram, applyGraphChange } from "@/components/ui/diagram";
import { Avatar } from "@/components/ui/avatar";

export default function Example() {
  const initial = compactPeople;
  const [value, setValue] = useState(initial);
  const [reject, setReject] = useState(false);
  return (
    <div
      className={`diagram-demo${""}`}
      inert={undefined}
      aria-hidden={undefined}
    >
      <Diagram
        value={value}
        viewport={undefined}
        connector={"elbow"}
        editable={true}
        aria-label="Product organization"
        nodeWidth={184}
        onChange={async (change) => {
          if (reject) {
            setReject(false);
            throw new Error("Could not save this change. Try again.");
          }
          setValue((current) => applyGraphChange(current, change));
        }}
        createNode={({ id, label, formData }) => ({
          id,
          label,
          data: {
            role: String(formData?.get("role") || "Product team"),
            avatarSeed: String(formData?.get("avatarSeed") || id),
          },
        })}
        renderNode={(node) => <PersonCard node={node} />}
        relationshipTypes={[
          {
            value: "reporting",
            label: "Reporting line",
          },
          {
            value: "taskforce",
            label: "Taskforce",
          },
          {
            value: "paired",
            label: "Human\u2013agent pairing",
          },
        ]}
      />
    </div>
  );
}

function normalizeColor(value) {
  return value.replace(/^#+/, "");
}

function diceAvatarUrl(style, seedOrOptions, maybeOptions) {
  const base =
    typeof seedOrOptions === "string"
      ? {
          ...maybeOptions,
          seed: seedOrOptions,
        }
      : {
          ...seedOrOptions,
        };
  const seed = base.seed ?? "ghost";
  const params = new URLSearchParams();
  params.set("seed", seed);
  if (base.backgroundColor !== undefined) {
    const colors = Array.isArray(base.backgroundColor)
      ? base.backgroundColor
      : [base.backgroundColor];
    const csv = colors.map(normalizeColor).filter(Boolean).join(",");
    if (csv) params.set("backgroundColor", csv);
  }
  if (base.size !== undefined) params.set("size", String(base.size));
  if (base.skinColor) params.set("skinColor", normalizeColor(base.skinColor));
  return `https://api.dicebear.com/${"10.x"}/${style}/svg?${params.toString()}`;
}

var people = {
  nodes: [
    {
      id: "maya",
      label: "Maya Chen",
      data: {
        role: "CEO",
        skinColor: "f3c6a5",
      },
    },
    {
      id: "sam",
      label: "Sam Rivera",
      data: {
        role: "CPO",
        skinColor: "c58b62",
      },
    },
    {
      id: "alex",
      label: "Alex Morgan",
      data: {
        role: "CTO",
        skinColor: "895235",
      },
    },
    {
      id: "robin",
      label: "Robin Park",
      data: {
        role: "Head of Design",
        skinColor: "f9d8c4",
      },
    },
    {
      id: "taylor",
      label: "Taylor Kim",
      data: {
        role: "Head of Research",
        skinColor: "dfab81",
      },
    },
    {
      id: "jordan",
      label: "Jordan Lee",
      data: {
        role: "Platform manager",
        skinColor: "f3c6a5",
      },
    },
    {
      id: "casey",
      label: "Casey Allen",
      data: {
        role: "Product designer",
        skinColor: "a86d4f",
      },
    },
    {
      id: "avery",
      label: "Avery Singh",
      data: {
        role: "User researcher",
        skinColor: "c58b62",
      },
    },
    {
      id: "morgan",
      label: "Morgan Diaz",
      data: {
        role: "Product engineer",
        skinColor: "dfab81",
      },
    },
  ],
  edges: [
    {
      id: "maya-sam",
      source: "maya",
      target: "sam",
      role: "reporting",
    },
    {
      id: "maya-alex",
      source: "maya",
      target: "alex",
      role: "reporting",
    },
    {
      id: "sam-robin",
      source: "sam",
      target: "robin",
      role: "reporting",
    },
    {
      id: "sam-taylor",
      source: "sam",
      target: "taylor",
      role: "reporting",
    },
    {
      id: "alex-jordan",
      source: "alex",
      target: "jordan",
      role: "reporting",
    },
    {
      id: "robin-casey",
      source: "robin",
      target: "casey",
      role: "reporting",
    },
    {
      id: "taylor-avery",
      source: "taylor",
      target: "avery",
      role: "reporting",
    },
    {
      id: "jordan-morgan",
      source: "jordan",
      target: "morgan",
      role: "reporting",
    },
  ],
};

var compactPeople = {
  nodes: people.nodes.slice(0, 3),
  edges: people.edges.slice(0, 2),
};

function PersonCard({ node, layout = "inline" }) {
  const seed = node.data?.avatarSeed ?? node.id;
  const skinColor = node.data?.skinColor;
  return (
    <div className="diagram-demo-person" data-layout={layout}>
      <div className="diagram-demo-person-identity">
        <Avatar
          name={node.label}
          seed={seed}
          src={
            skinColor &&
            diceAvatarUrl("dylan", {
              seed,
              skinColor,
            })
          }
          kind={node.data?.agent ? "agent" : "human"}
          className={layout === "compact" ? "ui-avatar-small" : undefined}
          aria-hidden="true"
        />
        <div className="diagram-demo-person-copy">
          <span className="diagram-demo-name">{node.label}</span>
          <span>{node.data?.role}</span>
        </div>
      </div>
      {node.data?.note && (
        <small className="diagram-demo-person-meta">{node.data.note}</small>
      )}
    </div>
  );
}

var paired = {
  nodes: [
    ...people.nodes.slice(0, 6),
    {
      id: "research-agent",
      label: "Research agent",
      data: {
        role: "AI agent",
        agent: true,
        note: "Paired with Taylor Kim",
      },
    },
    {
      id: "code-agent",
      label: "Code agent",
      data: {
        role: "AI agent",
        agent: true,
        note: "Paired with Jordan Lee",
      },
    },
    {
      id: "partner",
      label: "Priya Shah",
      data: {
        role: "External researcher",
        note: "Northstar \xB7 Contractor",
        skinColor: "a86d4f",
      },
    },
  ],
  edges: [
    ...people.edges.slice(0, 5),
    {
      id: "taylor-agent",
      source: "taylor",
      target: "research-agent",
      role: "reporting",
    },
    {
      id: "jordan-agent",
      source: "jordan",
      target: "code-agent",
      role: "reporting",
    },
    {
      id: "shared-partner",
      source: "taylor",
      target: "partner",
      role: "reporting",
    },
    {
      id: "partner-taskforce",
      source: "jordan",
      target: "partner",
      role: "taskforce",
      line: "dashed",
      label: "Launch taskforce",
    },
    {
      id: "agent-pair",
      source: "robin",
      target: "research-agent",
      role: "paired",
      line: "dotted",
      label: "Design review",
    },
  ],
};

var shared = {
  nodes: people.nodes.slice(0, 6),
  edges: [
    ...people.edges.slice(0, 5),
    {
      id: "shared-research",
      source: "alex",
      target: "taylor",
      role: "reporting",
    },
    {
      id: "skip-level",
      source: "maya",
      target: "jordan",
      role: "advisory",
      line: "dashed",
      label: "Architecture review",
    },
  ],
};

```

diagram-edit-an-organization-4.css

```css
/* apps/web/src/demos/library/diagram-demo.css */
.diagram-demo {
  position: relative;
  width: 1040px;
  max-width: 100%;
  min-width: 0;
  background: var(--background);
  color: var(--foreground);
  font-weight: 400;
}
.diagram-demo-person {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}
.diagram-demo-person-identity {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  min-width: 0;
}
.diagram-demo-person-copy {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.diagram-demo-person .diagram-demo-name {
  font-size: 13px;
  font-weight: 400;
  line-height: 18px;
  color: var(--foreground);
  overflow-wrap: anywhere;
  padding-inline-end: 16px;
}
.diagram-demo-person-copy > span,
.diagram-demo-person-meta {
  font-size: 12px;
  line-height: 18px;
  color: var(--muted-foreground);
  overflow-wrap: anywhere;
}
.diagram-demo-person-meta {
  align-self: stretch;
}
.diagram-demo-person[data-layout=compact] .diagram-demo-person-identity {
  gap: 8px;
}
.diagram-demo-person:is([data-layout=stacked], [data-layout=centered]) .diagram-demo-person-identity {
  flex-direction: column;
  gap: 8px;
}
.diagram-demo-person[data-layout=centered] {
  align-items: center;
  text-align: center;
}
.diagram-demo-person[data-layout=centered] .diagram-demo-person-identity,
.diagram-demo-person[data-layout=centered] .diagram-demo-person-copy {
  align-items: center;
}
.diagram-demo-person[data-layout=centered] .diagram-demo-name {
  padding-inline-end: 0;
}
.diagram-demo-goal {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.diagram-demo-goal .diagram-demo-name {
  font-size: 14px;
  font-weight: 400;
  line-height: 21px;
  color: var(--foreground);
}
.diagram-demo-goal > small,
.diagram-demo-goal > span {
  font-size: 12px;
  color: var(--muted-foreground);
}
.diagram-demo--viewport > .ui-graph-surface {
  height: 620px;
}
.diagram-demo--thumbnail {
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  pointer-events: none;
}
.diagram-demo--thumbnail > .ui-graph-surface {
  max-width: 100%;
}
.diagram-demo-node-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  width: 100%;
  padding: 24px;
}
.diagram-demo-card-example {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}
.diagram-demo-card-example > .ui-graph-node {
  flex: 1;
}
.diagram-demo-card-label {
  font-size: 12px;
  line-height: 18px;
  color: var(--muted-foreground);
  text-transform: capitalize;
}
.diagram-demo-connectors {
  display: grid;
  gap: 24px;
  width: 100%;
}
.diagram-demo-connector-name {
  display: block;
  padding-inline: 24px;
  color: var(--muted-foreground);
  font-size: 12px;
  text-transform: capitalize;
}

```

### OKR strategy

Use an alignment role for ancestry. Progress, ownership and objective type are caller content.

diagram-okr-strategy-5.jsx

```jsx
import { useState } from "react";
import { Diagram, applyGraphChange } from "@/components/ui/diagram";
import { Progress } from "@/components/ui/progress";

export default function Example() {
  const [value, setValue] = useState(goals);
  return (
    <div className="diagram-demo">
      <Diagram
        value={value}
        hierarchyRole="alignment"
        connectionRole="alignment"
        editable
        nodeWidth={248}
        aria-label="Q4 strategy map"
        onChange={(change) =>
          setValue((current) =>
            applyGraphChange(current, change, {
              hierarchyRole: "alignment",
            }),
          )
        }
        renderNode={(node) => (
          <div className="diagram-demo-goal">
            <small>{node.data?.kind}</small>
            <span className="diagram-demo-name">{node.label}</span>
            <span>{node.data?.owner}</span>
          </div>
        )}
        renderNodeFooter={(node) => (
          <Progress.Root
            className="diagram-demo-goal-progress"
            value={node.data?.progress ?? 0}
          >
            <Progress.Label>Progress</Progress.Label>
            <Progress.Value />
            <Progress.Track>
              <Progress.Indicator />
            </Progress.Track>
          </Progress.Root>
        )}
        createNode={({ id, label }) => ({
          id,
          label,
          data: {
            owner: "Unassigned",
            progress: 0,
            kind: "Initiative",
          },
        })}
      />
    </div>
  );
}

var people = {
  nodes: [
    {
      id: "maya",
      label: "Maya Chen",
      data: {
        role: "CEO",
        skinColor: "f3c6a5",
      },
    },
    {
      id: "sam",
      label: "Sam Rivera",
      data: {
        role: "CPO",
        skinColor: "c58b62",
      },
    },
    {
      id: "alex",
      label: "Alex Morgan",
      data: {
        role: "CTO",
        skinColor: "895235",
      },
    },
    {
      id: "robin",
      label: "Robin Park",
      data: {
        role: "Head of Design",
        skinColor: "f9d8c4",
      },
    },
    {
      id: "taylor",
      label: "Taylor Kim",
      data: {
        role: "Head of Research",
        skinColor: "dfab81",
      },
    },
    {
      id: "jordan",
      label: "Jordan Lee",
      data: {
        role: "Platform manager",
        skinColor: "f3c6a5",
      },
    },
    {
      id: "casey",
      label: "Casey Allen",
      data: {
        role: "Product designer",
        skinColor: "a86d4f",
      },
    },
    {
      id: "avery",
      label: "Avery Singh",
      data: {
        role: "User researcher",
        skinColor: "c58b62",
      },
    },
    {
      id: "morgan",
      label: "Morgan Diaz",
      data: {
        role: "Product engineer",
        skinColor: "dfab81",
      },
    },
  ],
  edges: [
    {
      id: "maya-sam",
      source: "maya",
      target: "sam",
      role: "reporting",
    },
    {
      id: "maya-alex",
      source: "maya",
      target: "alex",
      role: "reporting",
    },
    {
      id: "sam-robin",
      source: "sam",
      target: "robin",
      role: "reporting",
    },
    {
      id: "sam-taylor",
      source: "sam",
      target: "taylor",
      role: "reporting",
    },
    {
      id: "alex-jordan",
      source: "alex",
      target: "jordan",
      role: "reporting",
    },
    {
      id: "robin-casey",
      source: "robin",
      target: "casey",
      role: "reporting",
    },
    {
      id: "taylor-avery",
      source: "taylor",
      target: "avery",
      role: "reporting",
    },
    {
      id: "jordan-morgan",
      source: "jordan",
      target: "morgan",
      role: "reporting",
    },
  ],
};

var compactPeople = {
  nodes: people.nodes.slice(0, 3),
  edges: people.edges.slice(0, 2),
};

var paired = {
  nodes: [
    ...people.nodes.slice(0, 6),
    {
      id: "research-agent",
      label: "Research agent",
      data: {
        role: "AI agent",
        agent: true,
        note: "Paired with Taylor Kim",
      },
    },
    {
      id: "code-agent",
      label: "Code agent",
      data: {
        role: "AI agent",
        agent: true,
        note: "Paired with Jordan Lee",
      },
    },
    {
      id: "partner",
      label: "Priya Shah",
      data: {
        role: "External researcher",
        note: "Northstar \xB7 Contractor",
        skinColor: "a86d4f",
      },
    },
  ],
  edges: [
    ...people.edges.slice(0, 5),
    {
      id: "taylor-agent",
      source: "taylor",
      target: "research-agent",
      role: "reporting",
    },
    {
      id: "jordan-agent",
      source: "jordan",
      target: "code-agent",
      role: "reporting",
    },
    {
      id: "shared-partner",
      source: "taylor",
      target: "partner",
      role: "reporting",
    },
    {
      id: "partner-taskforce",
      source: "jordan",
      target: "partner",
      role: "taskforce",
      line: "dashed",
      label: "Launch taskforce",
    },
    {
      id: "agent-pair",
      source: "robin",
      target: "research-agent",
      role: "paired",
      line: "dotted",
      label: "Design review",
    },
  ],
};

var shared = {
  nodes: people.nodes.slice(0, 6),
  edges: [
    ...people.edges.slice(0, 5),
    {
      id: "shared-research",
      source: "alex",
      target: "taylor",
      role: "reporting",
    },
    {
      id: "skip-level",
      source: "maya",
      target: "jordan",
      role: "advisory",
      line: "dashed",
      label: "Architecture review",
    },
  ],
};

var goals = {
  nodes: [
    {
      id: "trusted",
      label: "Make AI answers trustworthy",
      data: {
        owner: "Maya Chen",
        progress: 68,
        kind: "Company objective",
      },
    },
    {
      id: "citations",
      label: "Citations in every grounded answer",
      data: {
        owner: "Sam Rivera",
        progress: 82,
        kind: "Key result",
      },
    },
    {
      id: "quality",
      label: "Raise answer quality to 90%",
      data: {
        owner: "Taylor Kim",
        progress: 64,
        kind: "Key result",
      },
    },
    {
      id: "grounding",
      label: "Ship source verification",
      data: {
        owner: "Jordan Lee",
        progress: 75,
        kind: "Initiative",
      },
    },
    {
      id: "evals",
      label: "Evaluate 1,000 real questions",
      data: {
        owner: "Avery Singh",
        progress: 48,
        kind: "Initiative",
      },
    },
  ],
  edges: [
    {
      id: "trusted-citations",
      source: "trusted",
      target: "citations",
      role: "alignment",
    },
    {
      id: "trusted-quality",
      source: "trusted",
      target: "quality",
      role: "alignment",
    },
    {
      id: "citations-grounding",
      source: "citations",
      target: "grounding",
      role: "alignment",
    },
    {
      id: "quality-evals",
      source: "quality",
      target: "evals",
      role: "alignment",
    },
  ],
};

```

diagram-okr-strategy-5.css

```css
/* apps/web/src/demos/library/diagram-demo.css */
.diagram-demo {
  position: relative;
  width: 1040px;
  max-width: 100%;
  min-width: 0;
  background: var(--background);
  color: var(--foreground);
  font-weight: 400;
}
.diagram-demo-goal {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.diagram-demo-goal .diagram-demo-name {
  font-size: 14px;
  font-weight: 400;
  line-height: 21px;
  color: var(--foreground);
}
.diagram-demo-goal > small,
.diagram-demo-goal > span {
  font-size: 12px;
  color: var(--muted-foreground);
}

```

### People and agents

Keep agents explicit and pair them with humans through a named relationship. A dotted taskforce link does not create reporting ancestry.

diagram-people-and-agents-6.jsx

```jsx
import { useState } from "react";
import { Diagram, applyGraphChange } from "@/components/ui/diagram";
import { Avatar } from "@/components/ui/avatar";

export default function Example() {
  return <Organization initial={paired} editable />;
}

function normalizeColor(value) {
  return value.replace(/^#+/, "");
}

function diceAvatarUrl(style, seedOrOptions, maybeOptions) {
  const base =
    typeof seedOrOptions === "string"
      ? {
          ...maybeOptions,
          seed: seedOrOptions,
        }
      : {
          ...seedOrOptions,
        };
  const seed = base.seed ?? "ghost";
  const params = new URLSearchParams();
  params.set("seed", seed);
  if (base.backgroundColor !== undefined) {
    const colors = Array.isArray(base.backgroundColor)
      ? base.backgroundColor
      : [base.backgroundColor];
    const csv = colors.map(normalizeColor).filter(Boolean).join(",");
    if (csv) params.set("backgroundColor", csv);
  }
  if (base.size !== undefined) params.set("size", String(base.size));
  if (base.skinColor) params.set("skinColor", normalizeColor(base.skinColor));
  return `https://api.dicebear.com/${"10.x"}/${style}/svg?${params.toString()}`;
}

var people = {
  nodes: [
    {
      id: "maya",
      label: "Maya Chen",
      data: {
        role: "CEO",
        skinColor: "f3c6a5",
      },
    },
    {
      id: "sam",
      label: "Sam Rivera",
      data: {
        role: "CPO",
        skinColor: "c58b62",
      },
    },
    {
      id: "alex",
      label: "Alex Morgan",
      data: {
        role: "CTO",
        skinColor: "895235",
      },
    },
    {
      id: "robin",
      label: "Robin Park",
      data: {
        role: "Head of Design",
        skinColor: "f9d8c4",
      },
    },
    {
      id: "taylor",
      label: "Taylor Kim",
      data: {
        role: "Head of Research",
        skinColor: "dfab81",
      },
    },
    {
      id: "jordan",
      label: "Jordan Lee",
      data: {
        role: "Platform manager",
        skinColor: "f3c6a5",
      },
    },
    {
      id: "casey",
      label: "Casey Allen",
      data: {
        role: "Product designer",
        skinColor: "a86d4f",
      },
    },
    {
      id: "avery",
      label: "Avery Singh",
      data: {
        role: "User researcher",
        skinColor: "c58b62",
      },
    },
    {
      id: "morgan",
      label: "Morgan Diaz",
      data: {
        role: "Product engineer",
        skinColor: "dfab81",
      },
    },
  ],
  edges: [
    {
      id: "maya-sam",
      source: "maya",
      target: "sam",
      role: "reporting",
    },
    {
      id: "maya-alex",
      source: "maya",
      target: "alex",
      role: "reporting",
    },
    {
      id: "sam-robin",
      source: "sam",
      target: "robin",
      role: "reporting",
    },
    {
      id: "sam-taylor",
      source: "sam",
      target: "taylor",
      role: "reporting",
    },
    {
      id: "alex-jordan",
      source: "alex",
      target: "jordan",
      role: "reporting",
    },
    {
      id: "robin-casey",
      source: "robin",
      target: "casey",
      role: "reporting",
    },
    {
      id: "taylor-avery",
      source: "taylor",
      target: "avery",
      role: "reporting",
    },
    {
      id: "jordan-morgan",
      source: "jordan",
      target: "morgan",
      role: "reporting",
    },
  ],
};

var compactPeople = {
  nodes: people.nodes.slice(0, 3),
  edges: people.edges.slice(0, 2),
};

function PersonCard({ node, layout = "inline" }) {
  const seed = node.data?.avatarSeed ?? node.id;
  const skinColor = node.data?.skinColor;
  return (
    <div className="diagram-demo-person" data-layout={layout}>
      <div className="diagram-demo-person-identity">
        <Avatar
          name={node.label}
          seed={seed}
          src={
            skinColor &&
            diceAvatarUrl("dylan", {
              seed,
              skinColor,
            })
          }
          kind={node.data?.agent ? "agent" : "human"}
          className={layout === "compact" ? "ui-avatar-small" : undefined}
          aria-hidden="true"
        />
        <div className="diagram-demo-person-copy">
          <span className="diagram-demo-name">{node.label}</span>
          <span>{node.data?.role}</span>
        </div>
      </div>
      {node.data?.note && (
        <small className="diagram-demo-person-meta">{node.data.note}</small>
      )}
    </div>
  );
}

function Organization({
  initial = compactPeople,
  editable = false,
  compact = false,
  fail = false,
  viewport = false,
  connector = "elbow",
}) {
  const [value, setValue] = useState(initial);
  const [reject, setReject] = useState(false);
  return (
    <div
      className={`diagram-demo${""}`}
      inert={undefined}
      aria-hidden={undefined}
    >
      <Diagram
        value={value}
        viewport={undefined}
        connector={"elbow"}
        editable={true}
        aria-label="Product organization"
        nodeWidth={184}
        onChange={async (change) => {
          if (reject) {
            setReject(false);
            throw new Error("Could not save this change. Try again.");
          }
          setValue((current) => applyGraphChange(current, change));
        }}
        createNode={({ id, label, formData }) => ({
          id,
          label,
          data: {
            role: String(formData?.get("role") || "Product team"),
            avatarSeed: String(formData?.get("avatarSeed") || id),
          },
        })}
        renderNode={(node) => <PersonCard node={node} />}
        relationshipTypes={[
          {
            value: "reporting",
            label: "Reporting line",
          },
          {
            value: "taskforce",
            label: "Taskforce",
          },
          {
            value: "paired",
            label: "Human\u2013agent pairing",
          },
        ]}
      />
    </div>
  );
}

var paired = {
  nodes: [
    ...people.nodes.slice(0, 6),
    {
      id: "research-agent",
      label: "Research agent",
      data: {
        role: "AI agent",
        agent: true,
        note: "Paired with Taylor Kim",
      },
    },
    {
      id: "code-agent",
      label: "Code agent",
      data: {
        role: "AI agent",
        agent: true,
        note: "Paired with Jordan Lee",
      },
    },
    {
      id: "partner",
      label: "Priya Shah",
      data: {
        role: "External researcher",
        note: "Northstar \xB7 Contractor",
        skinColor: "a86d4f",
      },
    },
  ],
  edges: [
    ...people.edges.slice(0, 5),
    {
      id: "taylor-agent",
      source: "taylor",
      target: "research-agent",
      role: "reporting",
    },
    {
      id: "jordan-agent",
      source: "jordan",
      target: "code-agent",
      role: "reporting",
    },
    {
      id: "shared-partner",
      source: "taylor",
      target: "partner",
      role: "reporting",
    },
    {
      id: "partner-taskforce",
      source: "jordan",
      target: "partner",
      role: "taskforce",
      line: "dashed",
      label: "Launch taskforce",
    },
    {
      id: "agent-pair",
      source: "robin",
      target: "research-agent",
      role: "paired",
      line: "dotted",
      label: "Design review",
    },
  ],
};

var shared = {
  nodes: people.nodes.slice(0, 6),
  edges: [
    ...people.edges.slice(0, 5),
    {
      id: "shared-research",
      source: "alex",
      target: "taylor",
      role: "reporting",
    },
    {
      id: "skip-level",
      source: "maya",
      target: "jordan",
      role: "advisory",
      line: "dashed",
      label: "Architecture review",
    },
  ],
};

```

diagram-people-and-agents-6.css

```css
/* apps/web/src/demos/library/diagram-demo.css */
.diagram-demo {
  position: relative;
  width: 1040px;
  max-width: 100%;
  min-width: 0;
  background: var(--background);
  color: var(--foreground);
  font-weight: 400;
}
.diagram-demo-person {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}
.diagram-demo-person-identity {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  min-width: 0;
}
.diagram-demo-person-copy {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.diagram-demo-person .diagram-demo-name {
  font-size: 13px;
  font-weight: 400;
  line-height: 18px;
  color: var(--foreground);
  overflow-wrap: anywhere;
  padding-inline-end: 16px;
}
.diagram-demo-person-copy > span,
.diagram-demo-person-meta {
  font-size: 12px;
  line-height: 18px;
  color: var(--muted-foreground);
  overflow-wrap: anywhere;
}
.diagram-demo-person-meta {
  align-self: stretch;
}
.diagram-demo-person[data-layout=compact] .diagram-demo-person-identity {
  gap: 8px;
}
.diagram-demo-person:is([data-layout=stacked], [data-layout=centered]) .diagram-demo-person-identity {
  flex-direction: column;
  gap: 8px;
}
.diagram-demo-person[data-layout=centered] {
  align-items: center;
  text-align: center;
}
.diagram-demo-person[data-layout=centered] .diagram-demo-person-identity,
.diagram-demo-person[data-layout=centered] .diagram-demo-person-copy {
  align-items: center;
}
.diagram-demo-person[data-layout=centered] .diagram-demo-name {
  padding-inline-end: 0;
}
.diagram-demo-goal {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.diagram-demo-goal .diagram-demo-name {
  font-size: 14px;
  font-weight: 400;
  line-height: 21px;
  color: var(--foreground);
}
.diagram-demo-goal > small,
.diagram-demo-goal > span {
  font-size: 12px;
  color: var(--muted-foreground);
}
.diagram-demo--viewport > .ui-graph-surface {
  height: 620px;
}
.diagram-demo--thumbnail {
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  pointer-events: none;
}
.diagram-demo--thumbnail > .ui-graph-surface {
  max-width: 100%;
}
.diagram-demo-node-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  width: 100%;
  padding: 24px;
}
.diagram-demo-card-example {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}
.diagram-demo-card-example > .ui-graph-node {
  flex: 1;
}
.diagram-demo-card-label {
  font-size: 12px;
  line-height: 18px;
  color: var(--muted-foreground);
  text-transform: capitalize;
}
.diagram-demo-connectors {
  display: grid;
  gap: 24px;
  width: 100%;
}
.diagram-demo-connector-name {
  display: block;
  padding-inline: 24px;
  color: var(--muted-foreground);
  font-size: 12px;
  text-transform: capitalize;
}

```

### Shared parents and skip levels

The same node can have two reporting parents. Collapsing one route preserves a shared descendant reached through another expanded route.

diagram-shared-parents-and-skip-levels-7.jsx

```jsx
import { useState } from "react";
import { Diagram, applyGraphChange } from "@/components/ui/diagram";
import { Avatar } from "@/components/ui/avatar";

export default function Example() {
  return <Organization initial={shared} editable />;
}

function normalizeColor(value) {
  return value.replace(/^#+/, "");
}

function diceAvatarUrl(style, seedOrOptions, maybeOptions) {
  const base =
    typeof seedOrOptions === "string"
      ? {
          ...maybeOptions,
          seed: seedOrOptions,
        }
      : {
          ...seedOrOptions,
        };
  const seed = base.seed ?? "ghost";
  const params = new URLSearchParams();
  params.set("seed", seed);
  if (base.backgroundColor !== undefined) {
    const colors = Array.isArray(base.backgroundColor)
      ? base.backgroundColor
      : [base.backgroundColor];
    const csv = colors.map(normalizeColor).filter(Boolean).join(",");
    if (csv) params.set("backgroundColor", csv);
  }
  if (base.size !== undefined) params.set("size", String(base.size));
  if (base.skinColor) params.set("skinColor", normalizeColor(base.skinColor));
  return `https://api.dicebear.com/${"10.x"}/${style}/svg?${params.toString()}`;
}

var people = {
  nodes: [
    {
      id: "maya",
      label: "Maya Chen",
      data: {
        role: "CEO",
        skinColor: "f3c6a5",
      },
    },
    {
      id: "sam",
      label: "Sam Rivera",
      data: {
        role: "CPO",
        skinColor: "c58b62",
      },
    },
    {
      id: "alex",
      label: "Alex Morgan",
      data: {
        role: "CTO",
        skinColor: "895235",
      },
    },
    {
      id: "robin",
      label: "Robin Park",
      data: {
        role: "Head of Design",
        skinColor: "f9d8c4",
      },
    },
    {
      id: "taylor",
      label: "Taylor Kim",
      data: {
        role: "Head of Research",
        skinColor: "dfab81",
      },
    },
    {
      id: "jordan",
      label: "Jordan Lee",
      data: {
        role: "Platform manager",
        skinColor: "f3c6a5",
      },
    },
    {
      id: "casey",
      label: "Casey Allen",
      data: {
        role: "Product designer",
        skinColor: "a86d4f",
      },
    },
    {
      id: "avery",
      label: "Avery Singh",
      data: {
        role: "User researcher",
        skinColor: "c58b62",
      },
    },
    {
      id: "morgan",
      label: "Morgan Diaz",
      data: {
        role: "Product engineer",
        skinColor: "dfab81",
      },
    },
  ],
  edges: [
    {
      id: "maya-sam",
      source: "maya",
      target: "sam",
      role: "reporting",
    },
    {
      id: "maya-alex",
      source: "maya",
      target: "alex",
      role: "reporting",
    },
    {
      id: "sam-robin",
      source: "sam",
      target: "robin",
      role: "reporting",
    },
    {
      id: "sam-taylor",
      source: "sam",
      target: "taylor",
      role: "reporting",
    },
    {
      id: "alex-jordan",
      source: "alex",
      target: "jordan",
      role: "reporting",
    },
    {
      id: "robin-casey",
      source: "robin",
      target: "casey",
      role: "reporting",
    },
    {
      id: "taylor-avery",
      source: "taylor",
      target: "avery",
      role: "reporting",
    },
    {
      id: "jordan-morgan",
      source: "jordan",
      target: "morgan",
      role: "reporting",
    },
  ],
};

var compactPeople = {
  nodes: people.nodes.slice(0, 3),
  edges: people.edges.slice(0, 2),
};

function PersonCard({ node, layout = "inline" }) {
  const seed = node.data?.avatarSeed ?? node.id;
  const skinColor = node.data?.skinColor;
  return (
    <div className="diagram-demo-person" data-layout={layout}>
      <div className="diagram-demo-person-identity">
        <Avatar
          name={node.label}
          seed={seed}
          src={
            skinColor &&
            diceAvatarUrl("dylan", {
              seed,
              skinColor,
            })
          }
          kind={node.data?.agent ? "agent" : "human"}
          className={layout === "compact" ? "ui-avatar-small" : undefined}
          aria-hidden="true"
        />
        <div className="diagram-demo-person-copy">
          <span className="diagram-demo-name">{node.label}</span>
          <span>{node.data?.role}</span>
        </div>
      </div>
      {node.data?.note && (
        <small className="diagram-demo-person-meta">{node.data.note}</small>
      )}
    </div>
  );
}

function Organization({
  initial = compactPeople,
  editable = false,
  compact = false,
  fail = false,
  viewport = false,
  connector = "elbow",
}) {
  const [value, setValue] = useState(initial);
  const [reject, setReject] = useState(false);
  return (
    <div
      className={`diagram-demo${""}`}
      inert={undefined}
      aria-hidden={undefined}
    >
      <Diagram
        value={value}
        viewport={undefined}
        connector={"elbow"}
        editable={true}
        aria-label="Product organization"
        nodeWidth={184}
        onChange={async (change) => {
          if (reject) {
            setReject(false);
            throw new Error("Could not save this change. Try again.");
          }
          setValue((current) => applyGraphChange(current, change));
        }}
        createNode={({ id, label, formData }) => ({
          id,
          label,
          data: {
            role: String(formData?.get("role") || "Product team"),
            avatarSeed: String(formData?.get("avatarSeed") || id),
          },
        })}
        renderNode={(node) => <PersonCard node={node} />}
        relationshipTypes={[
          {
            value: "reporting",
            label: "Reporting line",
          },
          {
            value: "taskforce",
            label: "Taskforce",
          },
          {
            value: "paired",
            label: "Human\u2013agent pairing",
          },
        ]}
      />
    </div>
  );
}

var paired = {
  nodes: [
    ...people.nodes.slice(0, 6),
    {
      id: "research-agent",
      label: "Research agent",
      data: {
        role: "AI agent",
        agent: true,
        note: "Paired with Taylor Kim",
      },
    },
    {
      id: "code-agent",
      label: "Code agent",
      data: {
        role: "AI agent",
        agent: true,
        note: "Paired with Jordan Lee",
      },
    },
    {
      id: "partner",
      label: "Priya Shah",
      data: {
        role: "External researcher",
        note: "Northstar \xB7 Contractor",
        skinColor: "a86d4f",
      },
    },
  ],
  edges: [
    ...people.edges.slice(0, 5),
    {
      id: "taylor-agent",
      source: "taylor",
      target: "research-agent",
      role: "reporting",
    },
    {
      id: "jordan-agent",
      source: "jordan",
      target: "code-agent",
      role: "reporting",
    },
    {
      id: "shared-partner",
      source: "taylor",
      target: "partner",
      role: "reporting",
    },
    {
      id: "partner-taskforce",
      source: "jordan",
      target: "partner",
      role: "taskforce",
      line: "dashed",
      label: "Launch taskforce",
    },
    {
      id: "agent-pair",
      source: "robin",
      target: "research-agent",
      role: "paired",
      line: "dotted",
      label: "Design review",
    },
  ],
};

var shared = {
  nodes: people.nodes.slice(0, 6),
  edges: [
    ...people.edges.slice(0, 5),
    {
      id: "shared-research",
      source: "alex",
      target: "taylor",
      role: "reporting",
    },
    {
      id: "skip-level",
      source: "maya",
      target: "jordan",
      role: "advisory",
      line: "dashed",
      label: "Architecture review",
    },
  ],
};

```

diagram-shared-parents-and-skip-levels-7.css

```css
/* apps/web/src/demos/library/diagram-demo.css */
.diagram-demo {
  position: relative;
  width: 1040px;
  max-width: 100%;
  min-width: 0;
  background: var(--background);
  color: var(--foreground);
  font-weight: 400;
}
.diagram-demo-person {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}
.diagram-demo-person-identity {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  min-width: 0;
}
.diagram-demo-person-copy {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.diagram-demo-person .diagram-demo-name {
  font-size: 13px;
  font-weight: 400;
  line-height: 18px;
  color: var(--foreground);
  overflow-wrap: anywhere;
  padding-inline-end: 16px;
}
.diagram-demo-person-copy > span,
.diagram-demo-person-meta {
  font-size: 12px;
  line-height: 18px;
  color: var(--muted-foreground);
  overflow-wrap: anywhere;
}
.diagram-demo-person-meta {
  align-self: stretch;
}
.diagram-demo-person[data-layout=compact] .diagram-demo-person-identity {
  gap: 8px;
}
.diagram-demo-person:is([data-layout=stacked], [data-layout=centered]) .diagram-demo-person-identity {
  flex-direction: column;
  gap: 8px;
}
.diagram-demo-person[data-layout=centered] {
  align-items: center;
  text-align: center;
}
.diagram-demo-person[data-layout=centered] .diagram-demo-person-identity,
.diagram-demo-person[data-layout=centered] .diagram-demo-person-copy {
  align-items: center;
}
.diagram-demo-person[data-layout=centered] .diagram-demo-name {
  padding-inline-end: 0;
}
.diagram-demo-goal {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.diagram-demo-goal .diagram-demo-name {
  font-size: 14px;
  font-weight: 400;
  line-height: 21px;
  color: var(--foreground);
}
.diagram-demo-goal > small,
.diagram-demo-goal > span {
  font-size: 12px;
  color: var(--muted-foreground);
}
.diagram-demo--viewport > .ui-graph-surface {
  height: 620px;
}
.diagram-demo--thumbnail {
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  pointer-events: none;
}
.diagram-demo--thumbnail > .ui-graph-surface {
  max-width: 100%;
}
.diagram-demo-node-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  width: 100%;
  padding: 24px;
}
.diagram-demo-card-example {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}
.diagram-demo-card-example > .ui-graph-node {
  flex: 1;
}
.diagram-demo-card-label {
  font-size: 12px;
  line-height: 18px;
  color: var(--muted-foreground);
  text-transform: capitalize;
}
.diagram-demo-connectors {
  display: grid;
  gap: 24px;
  width: 100%;
}
.diagram-demo-connector-name {
  display: block;
  padding-inline: 24px;
  color: var(--muted-foreground);
  font-size: 12px;
  text-transform: capitalize;
}

```

### Diagram viewport

Choose a viewport for spatial navigation and drag-to-reparent. Embedded content remains the default. Set its height through native styles or a host class.

diagram-diagram-viewport-8.jsx

```jsx
import { useState } from "react";
import { Diagram, applyGraphChange } from "@/components/ui/diagram";
import { GraphViewport } from "@/components/ui/graph-viewport";
import { Avatar } from "@/components/ui/avatar";

export default function Example() {
  const initial = compactPeople;
  const [value, setValue] = useState(initial);
  const [reject, setReject] = useState(false);
  return (
    <div
      className={`diagram-demo${" diagram-demo--viewport"}`}
      inert={undefined}
      aria-hidden={undefined}
    >
      <Diagram
        value={value}
        viewport={GraphViewport}
        connector={"elbow"}
        editable={true}
        aria-label="Product organization"
        nodeWidth={184}
        onChange={async (change) => {
          if (reject) {
            setReject(false);
            throw new Error("Could not save this change. Try again.");
          }
          setValue((current) => applyGraphChange(current, change));
        }}
        createNode={({ id, label, formData }) => ({
          id,
          label,
          data: {
            role: String(formData?.get("role") || "Product team"),
            avatarSeed: String(formData?.get("avatarSeed") || id),
          },
        })}
        renderNode={(node) => <PersonCard node={node} />}
        relationshipTypes={[
          {
            value: "reporting",
            label: "Reporting line",
          },
          {
            value: "taskforce",
            label: "Taskforce",
          },
          {
            value: "paired",
            label: "Human\u2013agent pairing",
          },
        ]}
      />
    </div>
  );
}

function normalizeColor(value) {
  return value.replace(/^#+/, "");
}

function diceAvatarUrl(style, seedOrOptions, maybeOptions) {
  const base =
    typeof seedOrOptions === "string"
      ? {
          ...maybeOptions,
          seed: seedOrOptions,
        }
      : {
          ...seedOrOptions,
        };
  const seed = base.seed ?? "ghost";
  const params = new URLSearchParams();
  params.set("seed", seed);
  if (base.backgroundColor !== undefined) {
    const colors = Array.isArray(base.backgroundColor)
      ? base.backgroundColor
      : [base.backgroundColor];
    const csv = colors.map(normalizeColor).filter(Boolean).join(",");
    if (csv) params.set("backgroundColor", csv);
  }
  if (base.size !== undefined) params.set("size", String(base.size));
  if (base.skinColor) params.set("skinColor", normalizeColor(base.skinColor));
  return `https://api.dicebear.com/${"10.x"}/${style}/svg?${params.toString()}`;
}

var people = {
  nodes: [
    {
      id: "maya",
      label: "Maya Chen",
      data: {
        role: "CEO",
        skinColor: "f3c6a5",
      },
    },
    {
      id: "sam",
      label: "Sam Rivera",
      data: {
        role: "CPO",
        skinColor: "c58b62",
      },
    },
    {
      id: "alex",
      label: "Alex Morgan",
      data: {
        role: "CTO",
        skinColor: "895235",
      },
    },
    {
      id: "robin",
      label: "Robin Park",
      data: {
        role: "Head of Design",
        skinColor: "f9d8c4",
      },
    },
    {
      id: "taylor",
      label: "Taylor Kim",
      data: {
        role: "Head of Research",
        skinColor: "dfab81",
      },
    },
    {
      id: "jordan",
      label: "Jordan Lee",
      data: {
        role: "Platform manager",
        skinColor: "f3c6a5",
      },
    },
    {
      id: "casey",
      label: "Casey Allen",
      data: {
        role: "Product designer",
        skinColor: "a86d4f",
      },
    },
    {
      id: "avery",
      label: "Avery Singh",
      data: {
        role: "User researcher",
        skinColor: "c58b62",
      },
    },
    {
      id: "morgan",
      label: "Morgan Diaz",
      data: {
        role: "Product engineer",
        skinColor: "dfab81",
      },
    },
  ],
  edges: [
    {
      id: "maya-sam",
      source: "maya",
      target: "sam",
      role: "reporting",
    },
    {
      id: "maya-alex",
      source: "maya",
      target: "alex",
      role: "reporting",
    },
    {
      id: "sam-robin",
      source: "sam",
      target: "robin",
      role: "reporting",
    },
    {
      id: "sam-taylor",
      source: "sam",
      target: "taylor",
      role: "reporting",
    },
    {
      id: "alex-jordan",
      source: "alex",
      target: "jordan",
      role: "reporting",
    },
    {
      id: "robin-casey",
      source: "robin",
      target: "casey",
      role: "reporting",
    },
    {
      id: "taylor-avery",
      source: "taylor",
      target: "avery",
      role: "reporting",
    },
    {
      id: "jordan-morgan",
      source: "jordan",
      target: "morgan",
      role: "reporting",
    },
  ],
};

var compactPeople = {
  nodes: people.nodes.slice(0, 3),
  edges: people.edges.slice(0, 2),
};

function PersonCard({ node, layout = "inline" }) {
  const seed = node.data?.avatarSeed ?? node.id;
  const skinColor = node.data?.skinColor;
  return (
    <div className="diagram-demo-person" data-layout={layout}>
      <div className="diagram-demo-person-identity">
        <Avatar
          name={node.label}
          seed={seed}
          src={
            skinColor &&
            diceAvatarUrl("dylan", {
              seed,
              skinColor,
            })
          }
          kind={node.data?.agent ? "agent" : "human"}
          className={layout === "compact" ? "ui-avatar-small" : undefined}
          aria-hidden="true"
        />
        <div className="diagram-demo-person-copy">
          <span className="diagram-demo-name">{node.label}</span>
          <span>{node.data?.role}</span>
        </div>
      </div>
      {node.data?.note && (
        <small className="diagram-demo-person-meta">{node.data.note}</small>
      )}
    </div>
  );
}

var paired = {
  nodes: [
    ...people.nodes.slice(0, 6),
    {
      id: "research-agent",
      label: "Research agent",
      data: {
        role: "AI agent",
        agent: true,
        note: "Paired with Taylor Kim",
      },
    },
    {
      id: "code-agent",
      label: "Code agent",
      data: {
        role: "AI agent",
        agent: true,
        note: "Paired with Jordan Lee",
      },
    },
    {
      id: "partner",
      label: "Priya Shah",
      data: {
        role: "External researcher",
        note: "Northstar \xB7 Contractor",
        skinColor: "a86d4f",
      },
    },
  ],
  edges: [
    ...people.edges.slice(0, 5),
    {
      id: "taylor-agent",
      source: "taylor",
      target: "research-agent",
      role: "reporting",
    },
    {
      id: "jordan-agent",
      source: "jordan",
      target: "code-agent",
      role: "reporting",
    },
    {
      id: "shared-partner",
      source: "taylor",
      target: "partner",
      role: "reporting",
    },
    {
      id: "partner-taskforce",
      source: "jordan",
      target: "partner",
      role: "taskforce",
      line: "dashed",
      label: "Launch taskforce",
    },
    {
      id: "agent-pair",
      source: "robin",
      target: "research-agent",
      role: "paired",
      line: "dotted",
      label: "Design review",
    },
  ],
};

var shared = {
  nodes: people.nodes.slice(0, 6),
  edges: [
    ...people.edges.slice(0, 5),
    {
      id: "shared-research",
      source: "alex",
      target: "taylor",
      role: "reporting",
    },
    {
      id: "skip-level",
      source: "maya",
      target: "jordan",
      role: "advisory",
      line: "dashed",
      label: "Architecture review",
    },
  ],
};

```

diagram-diagram-viewport-8.css

```css
/* apps/web/src/demos/library/diagram-demo.css */
.diagram-demo {
  position: relative;
  width: 1040px;
  max-width: 100%;
  min-width: 0;
  background: var(--background);
  color: var(--foreground);
  font-weight: 400;
}
.diagram-demo-person {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}
.diagram-demo-person-identity {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  min-width: 0;
}
.diagram-demo-person-copy {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.diagram-demo-person .diagram-demo-name {
  font-size: 13px;
  font-weight: 400;
  line-height: 18px;
  color: var(--foreground);
  overflow-wrap: anywhere;
  padding-inline-end: 16px;
}
.diagram-demo-person-copy > span,
.diagram-demo-person-meta {
  font-size: 12px;
  line-height: 18px;
  color: var(--muted-foreground);
  overflow-wrap: anywhere;
}
.diagram-demo-person-meta {
  align-self: stretch;
}
.diagram-demo-person[data-layout=compact] .diagram-demo-person-identity {
  gap: 8px;
}
.diagram-demo-person:is([data-layout=stacked], [data-layout=centered]) .diagram-demo-person-identity {
  flex-direction: column;
  gap: 8px;
}
.diagram-demo-person[data-layout=centered] {
  align-items: center;
  text-align: center;
}
.diagram-demo-person[data-layout=centered] .diagram-demo-person-identity,
.diagram-demo-person[data-layout=centered] .diagram-demo-person-copy {
  align-items: center;
}
.diagram-demo-person[data-layout=centered] .diagram-demo-name {
  padding-inline-end: 0;
}
.diagram-demo-goal {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.diagram-demo-goal .diagram-demo-name {
  font-size: 14px;
  font-weight: 400;
  line-height: 21px;
  color: var(--foreground);
}
.diagram-demo-goal > small,
.diagram-demo-goal > span {
  font-size: 12px;
  color: var(--muted-foreground);
}
.diagram-demo--viewport > .ui-graph-surface {
  height: 620px;
}
.diagram-demo--thumbnail {
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  pointer-events: none;
}
.diagram-demo--thumbnail > .ui-graph-surface {
  max-width: 100%;
}
.diagram-demo-node-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  width: 100%;
  padding: 24px;
}
.diagram-demo-card-example {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}
.diagram-demo-card-example > .ui-graph-node {
  flex: 1;
}
.diagram-demo-card-label {
  font-size: 12px;
  line-height: 18px;
  color: var(--muted-foreground);
  text-transform: capitalize;
}
.diagram-demo-connectors {
  display: grid;
  gap: 24px;
  width: 100%;
}
.diagram-demo-connector-name {
  display: block;
  padding-inline: 24px;
  color: var(--muted-foreground);
  font-size: 12px;
  text-transform: capitalize;
}

```

### Diagram connectors

Elbow is the default. Choose straight or bezier for a different reading pattern. Line style (solid, dashed, dotted) belongs to each relationship independently.

diagram-diagram-connectors-9.jsx

```jsx
import { useState } from "react";
import { Diagram } from "@/components/ui/diagram";
import { Avatar } from "@/components/ui/avatar";
import { Toggle } from "@/components/ui/toggle";
import { ToggleGroup } from "@/components/ui/toggle-group";

export default function Example() {
  const [connector, setConnector] = useState("elbow");
  return (
    <div className="diagram-demo diagram-alignment-demo">
      <ToggleGroup
        content="text"
        aria-label="Connector shape"
        value={[connector]}
        onValueChange={(value) => value[0] && setConnector(value[0])}
      >
        {["elbow", "straight", "bezier"].map((shape) => (
          <Toggle key={shape} value={shape}>
            {shape === "elbow"
              ? "Elbow"
              : shape === "straight"
                ? "Straight"
                : "Bezier"}
          </Toggle>
        ))}
      </ToggleGroup>
      <Diagram
        value={compactPeople}
        connector={connector}
        aria-label="Product team connectors"
        renderNode={(node) => <PersonCard node={node} />}
        nodeWidth={184}
      />
    </div>
  );
}

function normalizeColor(value) {
  return value.replace(/^#+/, "");
}

function diceAvatarUrl(style, seedOrOptions, maybeOptions) {
  const base =
    typeof seedOrOptions === "string"
      ? {
          ...maybeOptions,
          seed: seedOrOptions,
        }
      : {
          ...seedOrOptions,
        };
  const seed = base.seed ?? "ghost";
  const params = new URLSearchParams();
  params.set("seed", seed);
  if (base.backgroundColor !== undefined) {
    const colors = Array.isArray(base.backgroundColor)
      ? base.backgroundColor
      : [base.backgroundColor];
    const csv = colors.map(normalizeColor).filter(Boolean).join(",");
    if (csv) params.set("backgroundColor", csv);
  }
  if (base.size !== undefined) params.set("size", String(base.size));
  if (base.skinColor) params.set("skinColor", normalizeColor(base.skinColor));
  return `https://api.dicebear.com/${"10.x"}/${style}/svg?${params.toString()}`;
}

var people = {
  nodes: [
    {
      id: "maya",
      label: "Maya Chen",
      data: {
        role: "CEO",
        skinColor: "f3c6a5",
      },
    },
    {
      id: "sam",
      label: "Sam Rivera",
      data: {
        role: "CPO",
        skinColor: "c58b62",
      },
    },
    {
      id: "alex",
      label: "Alex Morgan",
      data: {
        role: "CTO",
        skinColor: "895235",
      },
    },
    {
      id: "robin",
      label: "Robin Park",
      data: {
        role: "Head of Design",
        skinColor: "f9d8c4",
      },
    },
    {
      id: "taylor",
      label: "Taylor Kim",
      data: {
        role: "Head of Research",
        skinColor: "dfab81",
      },
    },
    {
      id: "jordan",
      label: "Jordan Lee",
      data: {
        role: "Platform manager",
        skinColor: "f3c6a5",
      },
    },
    {
      id: "casey",
      label: "Casey Allen",
      data: {
        role: "Product designer",
        skinColor: "a86d4f",
      },
    },
    {
      id: "avery",
      label: "Avery Singh",
      data: {
        role: "User researcher",
        skinColor: "c58b62",
      },
    },
    {
      id: "morgan",
      label: "Morgan Diaz",
      data: {
        role: "Product engineer",
        skinColor: "dfab81",
      },
    },
  ],
  edges: [
    {
      id: "maya-sam",
      source: "maya",
      target: "sam",
      role: "reporting",
    },
    {
      id: "maya-alex",
      source: "maya",
      target: "alex",
      role: "reporting",
    },
    {
      id: "sam-robin",
      source: "sam",
      target: "robin",
      role: "reporting",
    },
    {
      id: "sam-taylor",
      source: "sam",
      target: "taylor",
      role: "reporting",
    },
    {
      id: "alex-jordan",
      source: "alex",
      target: "jordan",
      role: "reporting",
    },
    {
      id: "robin-casey",
      source: "robin",
      target: "casey",
      role: "reporting",
    },
    {
      id: "taylor-avery",
      source: "taylor",
      target: "avery",
      role: "reporting",
    },
    {
      id: "jordan-morgan",
      source: "jordan",
      target: "morgan",
      role: "reporting",
    },
  ],
};

var compactPeople = {
  nodes: people.nodes.slice(0, 3),
  edges: people.edges.slice(0, 2),
};

function PersonCard({ node, layout = "inline" }) {
  const seed = node.data?.avatarSeed ?? node.id;
  const skinColor = node.data?.skinColor;
  return (
    <div className="diagram-demo-person" data-layout={layout}>
      <div className="diagram-demo-person-identity">
        <Avatar
          name={node.label}
          seed={seed}
          src={
            skinColor &&
            diceAvatarUrl("dylan", {
              seed,
              skinColor,
            })
          }
          kind={node.data?.agent ? "agent" : "human"}
          className={layout === "compact" ? "ui-avatar-small" : undefined}
          aria-hidden="true"
        />
        <div className="diagram-demo-person-copy">
          <span className="diagram-demo-name">{node.label}</span>
          <span>{node.data?.role}</span>
        </div>
      </div>
      {node.data?.note && (
        <small className="diagram-demo-person-meta">{node.data.note}</small>
      )}
    </div>
  );
}

var paired = {
  nodes: [
    ...people.nodes.slice(0, 6),
    {
      id: "research-agent",
      label: "Research agent",
      data: {
        role: "AI agent",
        agent: true,
        note: "Paired with Taylor Kim",
      },
    },
    {
      id: "code-agent",
      label: "Code agent",
      data: {
        role: "AI agent",
        agent: true,
        note: "Paired with Jordan Lee",
      },
    },
    {
      id: "partner",
      label: "Priya Shah",
      data: {
        role: "External researcher",
        note: "Northstar \xB7 Contractor",
        skinColor: "a86d4f",
      },
    },
  ],
  edges: [
    ...people.edges.slice(0, 5),
    {
      id: "taylor-agent",
      source: "taylor",
      target: "research-agent",
      role: "reporting",
    },
    {
      id: "jordan-agent",
      source: "jordan",
      target: "code-agent",
      role: "reporting",
    },
    {
      id: "shared-partner",
      source: "taylor",
      target: "partner",
      role: "reporting",
    },
    {
      id: "partner-taskforce",
      source: "jordan",
      target: "partner",
      role: "taskforce",
      line: "dashed",
      label: "Launch taskforce",
    },
    {
      id: "agent-pair",
      source: "robin",
      target: "research-agent",
      role: "paired",
      line: "dotted",
      label: "Design review",
    },
  ],
};

var shared = {
  nodes: people.nodes.slice(0, 6),
  edges: [
    ...people.edges.slice(0, 5),
    {
      id: "shared-research",
      source: "alex",
      target: "taylor",
      role: "reporting",
    },
    {
      id: "skip-level",
      source: "maya",
      target: "jordan",
      role: "advisory",
      line: "dashed",
      label: "Architecture review",
    },
  ],
};

```

diagram-diagram-connectors-9.css

```css
/* apps/web/src/demos/library/diagram-demo.css */
.diagram-demo {
  position: relative;
  width: 1040px;
  max-width: 100%;
  min-width: 0;
  background: var(--background);
  color: var(--foreground);
  font-weight: 400;
}
.diagram-demo-person {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}
.diagram-demo-person-identity {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  min-width: 0;
}
.diagram-demo-person-copy {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.diagram-demo-person .diagram-demo-name {
  font-size: 13px;
  font-weight: 400;
  line-height: 18px;
  color: var(--foreground);
  overflow-wrap: anywhere;
  padding-inline-end: 16px;
}
.diagram-demo-person-copy > span,
.diagram-demo-person-meta {
  font-size: 12px;
  line-height: 18px;
  color: var(--muted-foreground);
  overflow-wrap: anywhere;
}
.diagram-demo-person-meta {
  align-self: stretch;
}
.diagram-demo-person[data-layout=compact] .diagram-demo-person-identity {
  gap: 8px;
}
.diagram-demo-person:is([data-layout=stacked], [data-layout=centered]) .diagram-demo-person-identity {
  flex-direction: column;
  gap: 8px;
}
.diagram-demo-person[data-layout=centered] {
  align-items: center;
  text-align: center;
}
.diagram-demo-person[data-layout=centered] .diagram-demo-person-identity,
.diagram-demo-person[data-layout=centered] .diagram-demo-person-copy {
  align-items: center;
}
.diagram-demo-person[data-layout=centered] .diagram-demo-name {
  padding-inline-end: 0;
}
.diagram-alignment-demo {
  display: grid;
  gap: 12px;
  padding: 16px;
}
.diagram-alignment-demo > .ui-toggle-group {
  justify-self: start;
}
.diagram-alignment-demo > .ui-graph-surface {
  margin: 0;
}

```

### Save failure

The first edit rejects locally. The retained draft can be submitted again.

diagram-save-failure-10.jsx

```jsx
import { useState } from "react";
import { Diagram, applyGraphChange } from "@/components/ui/diagram";
import { Avatar } from "@/components/ui/avatar";

export default function Example() {
  const initial = compactPeople;
  const [value, setValue] = useState(initial);
  const [reject, setReject] = useState(true);
  return (
    <div
      className={`diagram-demo${""}`}
      inert={undefined}
      aria-hidden={undefined}
    >
      <Diagram
        value={value}
        viewport={undefined}
        connector={"elbow"}
        editable={true}
        aria-label="Product organization"
        nodeWidth={184}
        onChange={async (change) => {
          if (reject) {
            setReject(false);
            throw new Error("Could not save this change. Try again.");
          }
          setValue((current) => applyGraphChange(current, change));
        }}
        createNode={({ id, label, formData }) => ({
          id,
          label,
          data: {
            role: String(formData?.get("role") || "Product team"),
            avatarSeed: String(formData?.get("avatarSeed") || id),
          },
        })}
        renderNode={(node) => <PersonCard node={node} />}
        relationshipTypes={[
          {
            value: "reporting",
            label: "Reporting line",
          },
          {
            value: "taskforce",
            label: "Taskforce",
          },
          {
            value: "paired",
            label: "Human\u2013agent pairing",
          },
        ]}
      />
    </div>
  );
}

function normalizeColor(value) {
  return value.replace(/^#+/, "");
}

function diceAvatarUrl(style, seedOrOptions, maybeOptions) {
  const base =
    typeof seedOrOptions === "string"
      ? {
          ...maybeOptions,
          seed: seedOrOptions,
        }
      : {
          ...seedOrOptions,
        };
  const seed = base.seed ?? "ghost";
  const params = new URLSearchParams();
  params.set("seed", seed);
  if (base.backgroundColor !== undefined) {
    const colors = Array.isArray(base.backgroundColor)
      ? base.backgroundColor
      : [base.backgroundColor];
    const csv = colors.map(normalizeColor).filter(Boolean).join(",");
    if (csv) params.set("backgroundColor", csv);
  }
  if (base.size !== undefined) params.set("size", String(base.size));
  if (base.skinColor) params.set("skinColor", normalizeColor(base.skinColor));
  return `https://api.dicebear.com/${"10.x"}/${style}/svg?${params.toString()}`;
}

var people = {
  nodes: [
    {
      id: "maya",
      label: "Maya Chen",
      data: {
        role: "CEO",
        skinColor: "f3c6a5",
      },
    },
    {
      id: "sam",
      label: "Sam Rivera",
      data: {
        role: "CPO",
        skinColor: "c58b62",
      },
    },
    {
      id: "alex",
      label: "Alex Morgan",
      data: {
        role: "CTO",
        skinColor: "895235",
      },
    },
    {
      id: "robin",
      label: "Robin Park",
      data: {
        role: "Head of Design",
        skinColor: "f9d8c4",
      },
    },
    {
      id: "taylor",
      label: "Taylor Kim",
      data: {
        role: "Head of Research",
        skinColor: "dfab81",
      },
    },
    {
      id: "jordan",
      label: "Jordan Lee",
      data: {
        role: "Platform manager",
        skinColor: "f3c6a5",
      },
    },
    {
      id: "casey",
      label: "Casey Allen",
      data: {
        role: "Product designer",
        skinColor: "a86d4f",
      },
    },
    {
      id: "avery",
      label: "Avery Singh",
      data: {
        role: "User researcher",
        skinColor: "c58b62",
      },
    },
    {
      id: "morgan",
      label: "Morgan Diaz",
      data: {
        role: "Product engineer",
        skinColor: "dfab81",
      },
    },
  ],
  edges: [
    {
      id: "maya-sam",
      source: "maya",
      target: "sam",
      role: "reporting",
    },
    {
      id: "maya-alex",
      source: "maya",
      target: "alex",
      role: "reporting",
    },
    {
      id: "sam-robin",
      source: "sam",
      target: "robin",
      role: "reporting",
    },
    {
      id: "sam-taylor",
      source: "sam",
      target: "taylor",
      role: "reporting",
    },
    {
      id: "alex-jordan",
      source: "alex",
      target: "jordan",
      role: "reporting",
    },
    {
      id: "robin-casey",
      source: "robin",
      target: "casey",
      role: "reporting",
    },
    {
      id: "taylor-avery",
      source: "taylor",
      target: "avery",
      role: "reporting",
    },
    {
      id: "jordan-morgan",
      source: "jordan",
      target: "morgan",
      role: "reporting",
    },
  ],
};

var compactPeople = {
  nodes: people.nodes.slice(0, 3),
  edges: people.edges.slice(0, 2),
};

function PersonCard({ node, layout = "inline" }) {
  const seed = node.data?.avatarSeed ?? node.id;
  const skinColor = node.data?.skinColor;
  return (
    <div className="diagram-demo-person" data-layout={layout}>
      <div className="diagram-demo-person-identity">
        <Avatar
          name={node.label}
          seed={seed}
          src={
            skinColor &&
            diceAvatarUrl("dylan", {
              seed,
              skinColor,
            })
          }
          kind={node.data?.agent ? "agent" : "human"}
          className={layout === "compact" ? "ui-avatar-small" : undefined}
          aria-hidden="true"
        />
        <div className="diagram-demo-person-copy">
          <span className="diagram-demo-name">{node.label}</span>
          <span>{node.data?.role}</span>
        </div>
      </div>
      {node.data?.note && (
        <small className="diagram-demo-person-meta">{node.data.note}</small>
      )}
    </div>
  );
}

var paired = {
  nodes: [
    ...people.nodes.slice(0, 6),
    {
      id: "research-agent",
      label: "Research agent",
      data: {
        role: "AI agent",
        agent: true,
        note: "Paired with Taylor Kim",
      },
    },
    {
      id: "code-agent",
      label: "Code agent",
      data: {
        role: "AI agent",
        agent: true,
        note: "Paired with Jordan Lee",
      },
    },
    {
      id: "partner",
      label: "Priya Shah",
      data: {
        role: "External researcher",
        note: "Northstar \xB7 Contractor",
        skinColor: "a86d4f",
      },
    },
  ],
  edges: [
    ...people.edges.slice(0, 5),
    {
      id: "taylor-agent",
      source: "taylor",
      target: "research-agent",
      role: "reporting",
    },
    {
      id: "jordan-agent",
      source: "jordan",
      target: "code-agent",
      role: "reporting",
    },
    {
      id: "shared-partner",
      source: "taylor",
      target: "partner",
      role: "reporting",
    },
    {
      id: "partner-taskforce",
      source: "jordan",
      target: "partner",
      role: "taskforce",
      line: "dashed",
      label: "Launch taskforce",
    },
    {
      id: "agent-pair",
      source: "robin",
      target: "research-agent",
      role: "paired",
      line: "dotted",
      label: "Design review",
    },
  ],
};

var shared = {
  nodes: people.nodes.slice(0, 6),
  edges: [
    ...people.edges.slice(0, 5),
    {
      id: "shared-research",
      source: "alex",
      target: "taylor",
      role: "reporting",
    },
    {
      id: "skip-level",
      source: "maya",
      target: "jordan",
      role: "advisory",
      line: "dashed",
      label: "Architecture review",
    },
  ],
};

```

diagram-save-failure-10.css

```css
/* apps/web/src/demos/library/diagram-demo.css */
.diagram-demo {
  position: relative;
  width: 1040px;
  max-width: 100%;
  min-width: 0;
  background: var(--background);
  color: var(--foreground);
  font-weight: 400;
}
.diagram-demo-person {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}
.diagram-demo-person-identity {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  min-width: 0;
}
.diagram-demo-person-copy {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.diagram-demo-person .diagram-demo-name {
  font-size: 13px;
  font-weight: 400;
  line-height: 18px;
  color: var(--foreground);
  overflow-wrap: anywhere;
  padding-inline-end: 16px;
}
.diagram-demo-person-copy > span,
.diagram-demo-person-meta {
  font-size: 12px;
  line-height: 18px;
  color: var(--muted-foreground);
  overflow-wrap: anywhere;
}
.diagram-demo-person-meta {
  align-self: stretch;
}
.diagram-demo-person[data-layout=compact] .diagram-demo-person-identity {
  gap: 8px;
}
.diagram-demo-person:is([data-layout=stacked], [data-layout=centered]) .diagram-demo-person-identity {
  flex-direction: column;
  gap: 8px;
}
.diagram-demo-person[data-layout=centered] {
  align-items: center;
  text-align: center;
}
.diagram-demo-person[data-layout=centered] .diagram-demo-person-identity,
.diagram-demo-person[data-layout=centered] .diagram-demo-person-copy {
  align-items: center;
}
.diagram-demo-person[data-layout=centered] .diagram-demo-name {
  padding-inline-end: 0;
}
.diagram-demo-goal {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.diagram-demo-goal .diagram-demo-name {
  font-size: 14px;
  font-weight: 400;
  line-height: 21px;
  color: var(--foreground);
}
.diagram-demo-goal > small,
.diagram-demo-goal > span {
  font-size: 12px;
  color: var(--muted-foreground);
}
.diagram-demo--viewport > .ui-graph-surface {
  height: 620px;
}
.diagram-demo--thumbnail {
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  pointer-events: none;
}
.diagram-demo--thumbnail > .ui-graph-surface {
  max-width: 100%;
}
.diagram-demo-node-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  width: 100%;
  padding: 24px;
}
.diagram-demo-card-example {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}
.diagram-demo-card-example > .ui-graph-node {
  flex: 1;
}
.diagram-demo-card-label {
  font-size: 12px;
  line-height: 18px;
  color: var(--muted-foreground);
  text-transform: capitalize;
}
.diagram-demo-connectors {
  display: grid;
  gap: 24px;
  width: 100%;
}
.diagram-demo-connector-name {
  display: block;
  padding-inline: 24px;
  color: var(--muted-foreground);
  font-size: 12px;
  text-transform: capitalize;
}

```

### Start empty

Create the first root before growing its branch.

diagram-start-empty-11.jsx

```jsx
import { useState } from "react";
import { Diagram, applyGraphChange } from "@/components/ui/diagram";
import { Avatar } from "@/components/ui/avatar";

export default function Example() {
  const initial = {
    nodes: [],
    edges: [],
  };
  const [value, setValue] = useState(initial);
  const [reject, setReject] = useState(false);
  return (
    <div
      className={`diagram-demo${""}`}
      inert={undefined}
      aria-hidden={undefined}
    >
      <Diagram
        value={value}
        viewport={undefined}
        connector={"elbow"}
        editable={true}
        aria-label="Product organization"
        nodeWidth={184}
        onChange={async (change) => {
          if (reject) {
            setReject(false);
            throw new Error("Could not save this change. Try again.");
          }
          setValue((current) => applyGraphChange(current, change));
        }}
        createNode={({ id, label, formData }) => ({
          id,
          label,
          data: {
            role: String(formData?.get("role") || "Product team"),
            avatarSeed: String(formData?.get("avatarSeed") || id),
          },
        })}
        renderNode={(node) => <PersonCard node={node} />}
        relationshipTypes={[
          {
            value: "reporting",
            label: "Reporting line",
          },
          {
            value: "taskforce",
            label: "Taskforce",
          },
          {
            value: "paired",
            label: "Human\u2013agent pairing",
          },
        ]}
      />
    </div>
  );
}

function normalizeColor(value) {
  return value.replace(/^#+/, "");
}

function diceAvatarUrl(style, seedOrOptions, maybeOptions) {
  const base =
    typeof seedOrOptions === "string"
      ? {
          ...maybeOptions,
          seed: seedOrOptions,
        }
      : {
          ...seedOrOptions,
        };
  const seed = base.seed ?? "ghost";
  const params = new URLSearchParams();
  params.set("seed", seed);
  if (base.backgroundColor !== undefined) {
    const colors = Array.isArray(base.backgroundColor)
      ? base.backgroundColor
      : [base.backgroundColor];
    const csv = colors.map(normalizeColor).filter(Boolean).join(",");
    if (csv) params.set("backgroundColor", csv);
  }
  if (base.size !== undefined) params.set("size", String(base.size));
  if (base.skinColor) params.set("skinColor", normalizeColor(base.skinColor));
  return `https://api.dicebear.com/${"10.x"}/${style}/svg?${params.toString()}`;
}

var people = {
  nodes: [
    {
      id: "maya",
      label: "Maya Chen",
      data: {
        role: "CEO",
        skinColor: "f3c6a5",
      },
    },
    {
      id: "sam",
      label: "Sam Rivera",
      data: {
        role: "CPO",
        skinColor: "c58b62",
      },
    },
    {
      id: "alex",
      label: "Alex Morgan",
      data: {
        role: "CTO",
        skinColor: "895235",
      },
    },
    {
      id: "robin",
      label: "Robin Park",
      data: {
        role: "Head of Design",
        skinColor: "f9d8c4",
      },
    },
    {
      id: "taylor",
      label: "Taylor Kim",
      data: {
        role: "Head of Research",
        skinColor: "dfab81",
      },
    },
    {
      id: "jordan",
      label: "Jordan Lee",
      data: {
        role: "Platform manager",
        skinColor: "f3c6a5",
      },
    },
    {
      id: "casey",
      label: "Casey Allen",
      data: {
        role: "Product designer",
        skinColor: "a86d4f",
      },
    },
    {
      id: "avery",
      label: "Avery Singh",
      data: {
        role: "User researcher",
        skinColor: "c58b62",
      },
    },
    {
      id: "morgan",
      label: "Morgan Diaz",
      data: {
        role: "Product engineer",
        skinColor: "dfab81",
      },
    },
  ],
  edges: [
    {
      id: "maya-sam",
      source: "maya",
      target: "sam",
      role: "reporting",
    },
    {
      id: "maya-alex",
      source: "maya",
      target: "alex",
      role: "reporting",
    },
    {
      id: "sam-robin",
      source: "sam",
      target: "robin",
      role: "reporting",
    },
    {
      id: "sam-taylor",
      source: "sam",
      target: "taylor",
      role: "reporting",
    },
    {
      id: "alex-jordan",
      source: "alex",
      target: "jordan",
      role: "reporting",
    },
    {
      id: "robin-casey",
      source: "robin",
      target: "casey",
      role: "reporting",
    },
    {
      id: "taylor-avery",
      source: "taylor",
      target: "avery",
      role: "reporting",
    },
    {
      id: "jordan-morgan",
      source: "jordan",
      target: "morgan",
      role: "reporting",
    },
  ],
};

var compactPeople = {
  nodes: people.nodes.slice(0, 3),
  edges: people.edges.slice(0, 2),
};

function PersonCard({ node, layout = "inline" }) {
  const seed = node.data?.avatarSeed ?? node.id;
  const skinColor = node.data?.skinColor;
  return (
    <div className="diagram-demo-person" data-layout={layout}>
      <div className="diagram-demo-person-identity">
        <Avatar
          name={node.label}
          seed={seed}
          src={
            skinColor &&
            diceAvatarUrl("dylan", {
              seed,
              skinColor,
            })
          }
          kind={node.data?.agent ? "agent" : "human"}
          className={layout === "compact" ? "ui-avatar-small" : undefined}
          aria-hidden="true"
        />
        <div className="diagram-demo-person-copy">
          <span className="diagram-demo-name">{node.label}</span>
          <span>{node.data?.role}</span>
        </div>
      </div>
      {node.data?.note && (
        <small className="diagram-demo-person-meta">{node.data.note}</small>
      )}
    </div>
  );
}

var paired = {
  nodes: [
    ...people.nodes.slice(0, 6),
    {
      id: "research-agent",
      label: "Research agent",
      data: {
        role: "AI agent",
        agent: true,
        note: "Paired with Taylor Kim",
      },
    },
    {
      id: "code-agent",
      label: "Code agent",
      data: {
        role: "AI agent",
        agent: true,
        note: "Paired with Jordan Lee",
      },
    },
    {
      id: "partner",
      label: "Priya Shah",
      data: {
        role: "External researcher",
        note: "Northstar \xB7 Contractor",
        skinColor: "a86d4f",
      },
    },
  ],
  edges: [
    ...people.edges.slice(0, 5),
    {
      id: "taylor-agent",
      source: "taylor",
      target: "research-agent",
      role: "reporting",
    },
    {
      id: "jordan-agent",
      source: "jordan",
      target: "code-agent",
      role: "reporting",
    },
    {
      id: "shared-partner",
      source: "taylor",
      target: "partner",
      role: "reporting",
    },
    {
      id: "partner-taskforce",
      source: "jordan",
      target: "partner",
      role: "taskforce",
      line: "dashed",
      label: "Launch taskforce",
    },
    {
      id: "agent-pair",
      source: "robin",
      target: "research-agent",
      role: "paired",
      line: "dotted",
      label: "Design review",
    },
  ],
};

var shared = {
  nodes: people.nodes.slice(0, 6),
  edges: [
    ...people.edges.slice(0, 5),
    {
      id: "shared-research",
      source: "alex",
      target: "taylor",
      role: "reporting",
    },
    {
      id: "skip-level",
      source: "maya",
      target: "jordan",
      role: "advisory",
      line: "dashed",
      label: "Architecture review",
    },
  ],
};

```

diagram-start-empty-11.css

```css
/* apps/web/src/demos/library/diagram-demo.css */
.diagram-demo {
  position: relative;
  width: 1040px;
  max-width: 100%;
  min-width: 0;
  background: var(--background);
  color: var(--foreground);
  font-weight: 400;
}
.diagram-demo-person {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}
.diagram-demo-person-identity {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  min-width: 0;
}
.diagram-demo-person-copy {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.diagram-demo-person .diagram-demo-name {
  font-size: 13px;
  font-weight: 400;
  line-height: 18px;
  color: var(--foreground);
  overflow-wrap: anywhere;
  padding-inline-end: 16px;
}
.diagram-demo-person-copy > span,
.diagram-demo-person-meta {
  font-size: 12px;
  line-height: 18px;
  color: var(--muted-foreground);
  overflow-wrap: anywhere;
}
.diagram-demo-person-meta {
  align-self: stretch;
}
.diagram-demo-person[data-layout=compact] .diagram-demo-person-identity {
  gap: 8px;
}
.diagram-demo-person:is([data-layout=stacked], [data-layout=centered]) .diagram-demo-person-identity {
  flex-direction: column;
  gap: 8px;
}
.diagram-demo-person[data-layout=centered] {
  align-items: center;
  text-align: center;
}
.diagram-demo-person[data-layout=centered] .diagram-demo-person-identity,
.diagram-demo-person[data-layout=centered] .diagram-demo-person-copy {
  align-items: center;
}
.diagram-demo-person[data-layout=centered] .diagram-demo-name {
  padding-inline-end: 0;
}
.diagram-demo-goal {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.diagram-demo-goal .diagram-demo-name {
  font-size: 14px;
  font-weight: 400;
  line-height: 21px;
  color: var(--foreground);
}
.diagram-demo-goal > small,
.diagram-demo-goal > span {
  font-size: 12px;
  color: var(--muted-foreground);
}
.diagram-demo--viewport > .ui-graph-surface {
  height: 620px;
}
.diagram-demo--thumbnail {
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  pointer-events: none;
}
.diagram-demo--thumbnail > .ui-graph-surface {
  max-width: 100%;
}
.diagram-demo-node-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  width: 100%;
  padding: 24px;
}
.diagram-demo-card-example {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}
.diagram-demo-card-example > .ui-graph-node {
  flex: 1;
}
.diagram-demo-card-label {
  font-size: 12px;
  line-height: 18px;
  color: var(--muted-foreground);
  text-transform: capitalize;
}
.diagram-demo-connectors {
  display: grid;
  gap: 24px;
  width: 100%;
}
.diagram-demo-connector-name {
  display: block;
  padding-inline: 24px;
  color: var(--muted-foreground);
  font-size: 12px;
  text-transform: capitalize;
}

```

### Hierarchy alignment

Top center uses an organization chart. Top left places the first card at the top left and shows descendants in indented, depth-first rows. The caller-owned ToggleGroup changes align; node identities and relationships stay the same.

diagram-hierarchy-alignment-12.jsx

```jsx
import { useState } from "react";
import { Diagram } from "@/components/ui/diagram";
import { Avatar } from "@/components/ui/avatar";
import { Toggle } from "@/components/ui/toggle";
import { ToggleGroup } from "@/components/ui/toggle-group";

export default function Example() {
  const [align, setAlign] = useState("center");
  return (
    <div className="diagram-demo diagram-alignment-demo">
      <ToggleGroup
        content="text"
        aria-label="Hierarchy alignment"
        value={[align]}
        onValueChange={(value) => value[0] && setAlign(value[0])}
      >
        <Toggle value="center">Top center</Toggle>
        <Toggle value="start">Top left</Toggle>
      </ToggleGroup>
      <Diagram
        value={compactPeople}
        align={align}
        aria-label="Product team hierarchy"
        renderNode={(node) => <PersonCard node={node} />}
        nodeWidth={184}
      />
    </div>
  );
}

function normalizeColor(value) {
  return value.replace(/^#+/, "");
}

function diceAvatarUrl(style, seedOrOptions, maybeOptions) {
  const base =
    typeof seedOrOptions === "string"
      ? {
          ...maybeOptions,
          seed: seedOrOptions,
        }
      : {
          ...seedOrOptions,
        };
  const seed = base.seed ?? "ghost";
  const params = new URLSearchParams();
  params.set("seed", seed);
  if (base.backgroundColor !== undefined) {
    const colors = Array.isArray(base.backgroundColor)
      ? base.backgroundColor
      : [base.backgroundColor];
    const csv = colors.map(normalizeColor).filter(Boolean).join(",");
    if (csv) params.set("backgroundColor", csv);
  }
  if (base.size !== undefined) params.set("size", String(base.size));
  if (base.skinColor) params.set("skinColor", normalizeColor(base.skinColor));
  return `https://api.dicebear.com/${"10.x"}/${style}/svg?${params.toString()}`;
}

var people = {
  nodes: [
    {
      id: "maya",
      label: "Maya Chen",
      data: {
        role: "CEO",
        skinColor: "f3c6a5",
      },
    },
    {
      id: "sam",
      label: "Sam Rivera",
      data: {
        role: "CPO",
        skinColor: "c58b62",
      },
    },
    {
      id: "alex",
      label: "Alex Morgan",
      data: {
        role: "CTO",
        skinColor: "895235",
      },
    },
    {
      id: "robin",
      label: "Robin Park",
      data: {
        role: "Head of Design",
        skinColor: "f9d8c4",
      },
    },
    {
      id: "taylor",
      label: "Taylor Kim",
      data: {
        role: "Head of Research",
        skinColor: "dfab81",
      },
    },
    {
      id: "jordan",
      label: "Jordan Lee",
      data: {
        role: "Platform manager",
        skinColor: "f3c6a5",
      },
    },
    {
      id: "casey",
      label: "Casey Allen",
      data: {
        role: "Product designer",
        skinColor: "a86d4f",
      },
    },
    {
      id: "avery",
      label: "Avery Singh",
      data: {
        role: "User researcher",
        skinColor: "c58b62",
      },
    },
    {
      id: "morgan",
      label: "Morgan Diaz",
      data: {
        role: "Product engineer",
        skinColor: "dfab81",
      },
    },
  ],
  edges: [
    {
      id: "maya-sam",
      source: "maya",
      target: "sam",
      role: "reporting",
    },
    {
      id: "maya-alex",
      source: "maya",
      target: "alex",
      role: "reporting",
    },
    {
      id: "sam-robin",
      source: "sam",
      target: "robin",
      role: "reporting",
    },
    {
      id: "sam-taylor",
      source: "sam",
      target: "taylor",
      role: "reporting",
    },
    {
      id: "alex-jordan",
      source: "alex",
      target: "jordan",
      role: "reporting",
    },
    {
      id: "robin-casey",
      source: "robin",
      target: "casey",
      role: "reporting",
    },
    {
      id: "taylor-avery",
      source: "taylor",
      target: "avery",
      role: "reporting",
    },
    {
      id: "jordan-morgan",
      source: "jordan",
      target: "morgan",
      role: "reporting",
    },
  ],
};

var compactPeople = {
  nodes: people.nodes.slice(0, 3),
  edges: people.edges.slice(0, 2),
};

function PersonCard({ node, layout = "inline" }) {
  const seed = node.data?.avatarSeed ?? node.id;
  const skinColor = node.data?.skinColor;
  return (
    <div className="diagram-demo-person" data-layout={layout}>
      <div className="diagram-demo-person-identity">
        <Avatar
          name={node.label}
          seed={seed}
          src={
            skinColor &&
            diceAvatarUrl("dylan", {
              seed,
              skinColor,
            })
          }
          kind={node.data?.agent ? "agent" : "human"}
          className={layout === "compact" ? "ui-avatar-small" : undefined}
          aria-hidden="true"
        />
        <div className="diagram-demo-person-copy">
          <span className="diagram-demo-name">{node.label}</span>
          <span>{node.data?.role}</span>
        </div>
      </div>
      {node.data?.note && (
        <small className="diagram-demo-person-meta">{node.data.note}</small>
      )}
    </div>
  );
}

var paired = {
  nodes: [
    ...people.nodes.slice(0, 6),
    {
      id: "research-agent",
      label: "Research agent",
      data: {
        role: "AI agent",
        agent: true,
        note: "Paired with Taylor Kim",
      },
    },
    {
      id: "code-agent",
      label: "Code agent",
      data: {
        role: "AI agent",
        agent: true,
        note: "Paired with Jordan Lee",
      },
    },
    {
      id: "partner",
      label: "Priya Shah",
      data: {
        role: "External researcher",
        note: "Northstar \xB7 Contractor",
        skinColor: "a86d4f",
      },
    },
  ],
  edges: [
    ...people.edges.slice(0, 5),
    {
      id: "taylor-agent",
      source: "taylor",
      target: "research-agent",
      role: "reporting",
    },
    {
      id: "jordan-agent",
      source: "jordan",
      target: "code-agent",
      role: "reporting",
    },
    {
      id: "shared-partner",
      source: "taylor",
      target: "partner",
      role: "reporting",
    },
    {
      id: "partner-taskforce",
      source: "jordan",
      target: "partner",
      role: "taskforce",
      line: "dashed",
      label: "Launch taskforce",
    },
    {
      id: "agent-pair",
      source: "robin",
      target: "research-agent",
      role: "paired",
      line: "dotted",
      label: "Design review",
    },
  ],
};

var shared = {
  nodes: people.nodes.slice(0, 6),
  edges: [
    ...people.edges.slice(0, 5),
    {
      id: "shared-research",
      source: "alex",
      target: "taylor",
      role: "reporting",
    },
    {
      id: "skip-level",
      source: "maya",
      target: "jordan",
      role: "advisory",
      line: "dashed",
      label: "Architecture review",
    },
  ],
};

```

diagram-hierarchy-alignment-12.css

```css
/* apps/web/src/demos/library/diagram-demo.css */
.diagram-demo {
  position: relative;
  width: 1040px;
  max-width: 100%;
  min-width: 0;
  background: var(--background);
  color: var(--foreground);
  font-weight: 400;
}
.diagram-demo-person {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}
.diagram-demo-person-identity {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  min-width: 0;
}
.diagram-demo-person-copy {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.diagram-demo-person .diagram-demo-name {
  font-size: 13px;
  font-weight: 400;
  line-height: 18px;
  color: var(--foreground);
  overflow-wrap: anywhere;
  padding-inline-end: 16px;
}
.diagram-demo-person-copy > span,
.diagram-demo-person-meta {
  font-size: 12px;
  line-height: 18px;
  color: var(--muted-foreground);
  overflow-wrap: anywhere;
}
.diagram-demo-person-meta {
  align-self: stretch;
}
.diagram-demo-person[data-layout=compact] .diagram-demo-person-identity {
  gap: 8px;
}
.diagram-demo-person:is([data-layout=stacked], [data-layout=centered]) .diagram-demo-person-identity {
  flex-direction: column;
  gap: 8px;
}
.diagram-demo-person[data-layout=centered] {
  align-items: center;
  text-align: center;
}
.diagram-demo-person[data-layout=centered] .diagram-demo-person-identity,
.diagram-demo-person[data-layout=centered] .diagram-demo-person-copy {
  align-items: center;
}
.diagram-demo-person[data-layout=centered] .diagram-demo-name {
  padding-inline-end: 0;
}
.diagram-alignment-demo {
  display: grid;
  gap: 12px;
  padding: 16px;
}
.diagram-alignment-demo > .ui-toggle-group {
  justify-self: start;
}
.diagram-alignment-demo > .ui-graph-surface {
  margin: 0;
}

```

### Conditional workflow

Use embedded Diagram when a rule and its outcomes need to be read inline. Configure rule opens a caller-owned Popover and Field; Save updates the displayed condition and branch labels. collapsible={false} removes disclosure controls and collapsed projection. This example edits presentation data only; it does not execute a workflow.

diagram-conditional-workflow-13.jsx

```jsx
import { useState } from "react";
import { Diagram, NodeCard } from "@/components/ui/diagram";
import { Field } from "@/components/ui/field";
import { Input } from "@/components/ui/input";
import { Button } from "@/components/ui/button";
import { Popover } from "@/components/ui/popover";

export default function Example() {
  const [rule, setRule] = useState("Contains a product image");
  const [draft, setDraft] = useState(rule);
  const [open, setOpen] = useState(false);
  const usesImage = rule === "Contains a product image";
  const value = {
    nodes: [
      {
        id: "request",
        label: "New request",
        data: {
          description: "Creative intake",
        },
      },
      {
        id: "rule",
        label: "Request type",
        data: {
          description: rule,
        },
      },
      {
        id: "image",
        label: "Generate image",
        data: {
          description: usesImage ? "Image request" : "Otherwise",
        },
      },
      {
        id: "copy",
        label: "Draft copy",
        data: {
          description: usesImage ? "Otherwise" : "Copy request",
        },
      },
    ],
    edges: [
      {
        id: "request-rule",
        source: "request",
        target: "rule",
        role: "condition",
      },
      {
        id: "image",
        source: "rule",
        target: "image",
        role: "condition",
        label: "Image",
      },
      {
        id: "copy",
        source: "rule",
        target: "copy",
        role: "condition",
        label: "Copy",
      },
    ],
  };
  return (
    <div className="diagram-demo diagram-conditional">
      <div className="diagram-conditional-actions">
        <Popover.Root open={open} onOpenChange={setOpen}>
          <Popover.Trigger render={<Button variant="outline" size="sm" />}>
            Configure rule
          </Popover.Trigger>
          <Popover.Portal>
            <Popover.Positioner>
              <Popover.Popup>
                <Popover.Arrow />
                <Popover.Header>
                  <Popover.Title>Configure branch</Popover.Title>
                  <Popover.Close aria-label="Close rule editor" />
                </Popover.Header>
                <Popover.Core>
                  <Field.Root>
                    <Field.Label>Request type</Field.Label>
                    <Input value={draft} onValueChange={setDraft} />
                  </Field.Root>
                </Popover.Core>
                <Popover.Footer>
                  <Button
                    variant="ghost"
                    onClick={() => {
                      setDraft(rule);
                      setOpen(false);
                    }}
                  >
                    Cancel
                  </Button>
                  <Button
                    onClick={() => {
                      setRule(draft.trim() || rule);
                      setOpen(false);
                    }}
                  >
                    Save rule
                  </Button>
                </Popover.Footer>
              </Popover.Popup>
            </Popover.Positioner>
          </Popover.Portal>
        </Popover.Root>
      </div>
      <Diagram
        value={value}
        hierarchyRole="condition"
        collapsible={false}
        aria-label="Request type branches"
        nodeWidth={184}
        renderNode={(node) => (
          <>
            <NodeCard.Header>
              <NodeCard.Title>{node.label}</NodeCard.Title>
            </NodeCard.Header>
            <NodeCard.Content>{node.data?.description}</NodeCard.Content>
          </>
        )}
      />
    </div>
  );
}

var people = {
  nodes: [
    {
      id: "maya",
      label: "Maya Chen",
      data: {
        role: "CEO",
        skinColor: "f3c6a5",
      },
    },
    {
      id: "sam",
      label: "Sam Rivera",
      data: {
        role: "CPO",
        skinColor: "c58b62",
      },
    },
    {
      id: "alex",
      label: "Alex Morgan",
      data: {
        role: "CTO",
        skinColor: "895235",
      },
    },
    {
      id: "robin",
      label: "Robin Park",
      data: {
        role: "Head of Design",
        skinColor: "f9d8c4",
      },
    },
    {
      id: "taylor",
      label: "Taylor Kim",
      data: {
        role: "Head of Research",
        skinColor: "dfab81",
      },
    },
    {
      id: "jordan",
      label: "Jordan Lee",
      data: {
        role: "Platform manager",
        skinColor: "f3c6a5",
      },
    },
    {
      id: "casey",
      label: "Casey Allen",
      data: {
        role: "Product designer",
        skinColor: "a86d4f",
      },
    },
    {
      id: "avery",
      label: "Avery Singh",
      data: {
        role: "User researcher",
        skinColor: "c58b62",
      },
    },
    {
      id: "morgan",
      label: "Morgan Diaz",
      data: {
        role: "Product engineer",
        skinColor: "dfab81",
      },
    },
  ],
  edges: [
    {
      id: "maya-sam",
      source: "maya",
      target: "sam",
      role: "reporting",
    },
    {
      id: "maya-alex",
      source: "maya",
      target: "alex",
      role: "reporting",
    },
    {
      id: "sam-robin",
      source: "sam",
      target: "robin",
      role: "reporting",
    },
    {
      id: "sam-taylor",
      source: "sam",
      target: "taylor",
      role: "reporting",
    },
    {
      id: "alex-jordan",
      source: "alex",
      target: "jordan",
      role: "reporting",
    },
    {
      id: "robin-casey",
      source: "robin",
      target: "casey",
      role: "reporting",
    },
    {
      id: "taylor-avery",
      source: "taylor",
      target: "avery",
      role: "reporting",
    },
    {
      id: "jordan-morgan",
      source: "jordan",
      target: "morgan",
      role: "reporting",
    },
  ],
};

var compactPeople = {
  nodes: people.nodes.slice(0, 3),
  edges: people.edges.slice(0, 2),
};

var paired = {
  nodes: [
    ...people.nodes.slice(0, 6),
    {
      id: "research-agent",
      label: "Research agent",
      data: {
        role: "AI agent",
        agent: true,
        note: "Paired with Taylor Kim",
      },
    },
    {
      id: "code-agent",
      label: "Code agent",
      data: {
        role: "AI agent",
        agent: true,
        note: "Paired with Jordan Lee",
      },
    },
    {
      id: "partner",
      label: "Priya Shah",
      data: {
        role: "External researcher",
        note: "Northstar \xB7 Contractor",
        skinColor: "a86d4f",
      },
    },
  ],
  edges: [
    ...people.edges.slice(0, 5),
    {
      id: "taylor-agent",
      source: "taylor",
      target: "research-agent",
      role: "reporting",
    },
    {
      id: "jordan-agent",
      source: "jordan",
      target: "code-agent",
      role: "reporting",
    },
    {
      id: "shared-partner",
      source: "taylor",
      target: "partner",
      role: "reporting",
    },
    {
      id: "partner-taskforce",
      source: "jordan",
      target: "partner",
      role: "taskforce",
      line: "dashed",
      label: "Launch taskforce",
    },
    {
      id: "agent-pair",
      source: "robin",
      target: "research-agent",
      role: "paired",
      line: "dotted",
      label: "Design review",
    },
  ],
};

var shared = {
  nodes: people.nodes.slice(0, 6),
  edges: [
    ...people.edges.slice(0, 5),
    {
      id: "shared-research",
      source: "alex",
      target: "taylor",
      role: "reporting",
    },
    {
      id: "skip-level",
      source: "maya",
      target: "jordan",
      role: "advisory",
      line: "dashed",
      label: "Architecture review",
    },
  ],
};

```

diagram-conditional-workflow-13.css

```css
/* apps/web/src/demos/library/diagram-demo.css */
.diagram-demo {
  position: relative;
  width: 1040px;
  max-width: 100%;
  min-width: 0;
  background: var(--background);
  color: var(--foreground);
  font-weight: 400;
}
.diagram-conditional {
  display: grid;
  gap: 16px;
  padding: 20px 24px;
}
.diagram-conditional-actions {
  justify-self: end;
}
.diagram-conditional .ui-graph-node {
  min-width: 180px;
}

```

## API reference

Diagram properties

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| align | 'center' \| 'start' | center | Center uses an organization chart; start uses indented, depth-first tree rows. A custom layout receives align and owns its geometry. |
| fit | 'width' \| 'none' | width | Width scales the measured embedded scene down to fit, with a 0.65 floor and contained scrolling below it. None preserves intrinsic size. |
| collapsible | boolean | true | When false, removes disclosure controls/counts and collapsed projection. |
| viewport | ComponentType<GraphViewportProps> | — | Injected canvas renderer. Pass GraphViewport from the graph-viewport item for a bounded pan/zoom surface with drag-to-reparent. When omitted, Diagram renders measured embedded content with native overflow. The injected renderer owns its viewport; embedded fit/alignment settings do not control its zoom. |
| connector | 'elbow' \| 'straight' \| 'bezier' | elbow | Connector geometry, independent of each edge line style. |
| routes | Readonly<Record<string, readonly GraphPoint[]>> | — | Optional interior waypoints keyed by public edge ID. Geometry stays outside graph facts; update routes when spatial positions change. Elbow routes remain orthogonal. Dense obstacle avoidance belongs to the supplied layout/routes. |
| value | GraphValue<N,E> | — | Required readonly node and edge arrays. Nodes have id, label, optional data and ports. Edges have id, source, target and role; label, ports, line and data are optional. |
| editable / onChange | boolean; (change: GraphChange<N,E>) => void \| Promise<void> | false | Both are required for mutation. Changes are proposals; the caller accepts and persists them. A pending callback prevents duplicate mutation. |
| getChangePermission | (change) => GraphPermission | — | Returns allowed true, or allowed false with a reason. Receives neutral public IDs. |
| renderNode / nodeWidth | (node, {selected}) => ReactNode; number \| (node) => number | 224 | Custom card content and width. Measured heights follow the content. |
| createNode / createEdge | (context) => GraphNode<N>; (connection & {id}) => GraphEdge<E> | — | Factories preserve caller metadata when creating nodes and relationships. |
| nodeTemplates / relationshipTypes | readonly GraphNodeTemplate<N>[]; readonly {value,label}[] | — | Creation choices and named relation roles. Templates may constrain compatible output types. |
| selectedNodeId / onSelectedNodeIdChange | string \| null; (id: string \| undefined) => void | — | Optional controlled node selection; null clears selection. |
| onEditNode | (node: GraphNode<N>) => void | — | Replaces the default responsive node editor for richer domain details. |
| Native attributes and ref | div attributes; HTMLDivElement ref | — | Set a meaningful accessible name. Embedded height follows content; set a height when viewport is enabled. |
| hierarchyRole / connectionRole | string | reporting | Role used for hierarchy projection and new structural relationships. |
| collapsedIds / defaultCollapsedIds / onCollapsedIdsChange | readonly string[]; (ids) => void | — | Controlled or initial branch disclosure. Shared descendants survive through expanded alternate paths. |
| search / onSearchChange | string; (query: string) => void | — | Filters to matches and their ancestor paths. A viewport supplies a search field; embedded hosts can supply their own. |
| direction / nodeGap / levelGap | 'down' \| 'right'; number; number | 'down'; 56; 64 | Org chart defaults: down, 56px sibling gap, 64px level gap. Start tree defaults: 32px indentation and 24px row gap. |
| layout | GraphLayoutFunction<N,E> | layoutDiagram | Receives graph, measured sizes and layout options. Returns positions and optional routed edge points. |

GraphChange includes insert, rename, update-node, connect, reconnect, move, reorder, reorder-root, update-edge, disconnect, remove and position. Insert can place a sibling before a stable edge ID. applyGraphChange returns the original value for invalid, stale or unchanged proposals; an invalid original graph throws. Reconnect preserves ID, metadata and edge order. Remove deletes only the node and incident edges, retaining its descendants. getGraphChangeError, assertGraphValue, getGraphProjection, getGraphDescendants and applyGraphPositions are also exported.

Use card and edge menus as alternatives to dragging. F2 edits the selected node; Shift+F10 opens its actions; Escape cancels the current draft. Keep domain loading, fetching, execution, undo and authorization in the caller. The examples use local state; Generate demonstrates local feedback rather than a model service.

NodeCard.Root accepts Card's variant (outline, subtle, ghost) and density (default, compact; default compact), plus selected, interactive and stagedParent visual states. Parts retain the canonical Card native props, render composition and refs. The graph view supplies focus and selection semantics; standalone integrations own theirs.

Embedded diagrams measure the host and complete scene. fit="width" scales down only, to a minimum of 0.65, then keeps horizontal overflow inside the diagram; fit="none" keeps intrinsic size. align="start" selects indented rows in the default layout and keeps the scene at its left scroll origin. Shared descendants appear once; use a custom layout and routes for dense cross-links. Optional viewports own their fit controls and zoom. The renderer installs @xyflow/react; pass GraphViewport only where the app needs it. getGraphConnectorPath is also exported for custom SVG renderers; it returns a path and label position without a canvas engine.
