Skip to content
Merged
5 changes: 5 additions & 0 deletions changelog.d/272-kit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
section: kit
---

- **Graph layouts report sibling blocks** (#272). `GraphLayout.blocks` lists each block's tray and its cards, and a frame's `blocks` lists the trays it draws. `GraphLayoutOptions.blocks` keeps the blocks from a reference layout, as transition steps do. Links into a tray carry `data-to-block`, and links out of a tray carry `data-from-block`. `edgeEnd` gives the box where a block's relationship ends.
5 changes: 5 additions & 0 deletions changelog.d/272.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
section: renderers
---

- **The graph renderer wraps wide fan-outs into blocks and lays out large graphs faster** (#272). When six or more cards share every relationship, such as a toolset's tools that all require one scope, they now form a block: the cards wrap into lines inside a captioned tray (for example, `11 tools +11`) instead of forming one row wider than the screen. Their relationships run as one route into the tray and one route out. Each relationship can still be selected and marked on its own. Routing large graphs is also faster: the GitHub MCP Server's 150 tools lay out in under a second instead of over a minute, and a graph of 320 modules lays out in about half the time. Graphs without these blocks lay out exactly as before.
21 changes: 20 additions & 1 deletion docs/guides/renderer-kit-graphs.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ the whole graph does not fit at the floor, the view opens on the changed region
at the floor so a content-sized frame still matches the content's height.

Hubs widen automatically to provide a separate port for each incoming
relationship (`fanInWidths`). A hovered, focused or selected relationship is
relationship (`fanInWidths`). Routes from a sibling block are counted once
rather than once for each card. A hovered, focused or selected relationship is
drawn over the others, and a selected or hovered card's relationships over the
rest, so each can be traced whole into a hub. Every relationship has an origin
dot where it leaves its source (`EdgeOrigins`, one dot per shared start), and
Expand Down Expand Up @@ -89,6 +90,24 @@ subgraphs share layers, and cards within a layer align along the edge where
their incoming relationships arrive (top or left) so each layer forms a clean
baseline.

**Sibling blocks.** When six or more cards (`blockMinimum`) share every
relationship, they wrap into a block instead of stretching their layer into one
long row. Sharing every relationship means having the same sources and targets,
of the same kinds, drawn the same way (`LayoutEdge.bundle`). ELK places the
block as a single node. Its cards fill lines in reading order inside an inset
tray about three times as broad as it is deep; in a top-to-bottom graph, the
cards sit on the column grid. One route runs from each source into the tray,
entering directly across from the source where possible, and one route runs from
the tray to each target. Each relationship keeps its own link on the shared
route so it can still be selected and marked. Links into or out of a tray carry
`data-to-block` or `data-from-block`. The canvas draws each tray under its cards
with a caption that counts the cards and, while changes are emphasized, shows
how many each change touches (`11 tools +11`). `GraphLayout.blocks` lists each
block's tray and cards. Within a frame, each block in `blocks` is as visible as
its most visible card. Each step of a transition keeps the union's blocks
(`GraphLayoutOptions.blocks`) so the same cards stay together through the
animation.

For flat graphs with relationships and 300 or fewer nodes, ELK first orders
cards to minimize crossings and then places them with one centered port per face
using the narrowest of the four Brandes–Köpf alignments rather than their
Expand Down
55 changes: 55 additions & 0 deletions docs/reference/renderer-kit.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,14 @@ Whether to draw it is the caller's policy, and drawing it should be reported.
| `crossed` | `"crossed": Array<number>` | The indices in `obstacles` of the cards `least` crosses. |
| `least` | `"least": BoxEdge` | The candidate route that overlaps the obstacles least. |

### `blockMinimum`

```ts
blockMinimum: 6
```

The fewest siblings wrapped into a block: fewer stand in their layer's row, as wide as a few cards.

### `BorderWidths`

```ts
Expand Down Expand Up @@ -1305,6 +1313,15 @@ edgeArrowHeadLength: 8.5

The arrowhead's length from tip to base (see `arrowHeadLength`); paths from `boxEdge` end this far short of the card.

### `edgeEnd`

```ts
edgeEnd(node: TransitionNode, block: TransitionBlock | undefined): TransitionNode
```

Where a relationship of a block's card ends (see `GraphLayout.blocks`): on the block's tray, which fades but never
scales as an arriving card does (`cardBox`); any other ends on its card.

### `edgeKind`

```ts
Expand Down Expand Up @@ -1734,6 +1751,7 @@ What a graph transition draws at one progress (see `GraphTransition`), in layout

| Member | Signature | Description |
|---|---|---|
| `blocks` | `"blocks": Array<TransitionBlock>` | Sibling blocks visible at this progress, drawn under their cards. |
| `edges` | `"edges": Array<TransitionEdge>` | Relationships visible at this progress; a rewired one may appear twice, its old and new routes crossfading. |
| `height` | `"height": number` | The drawing's height, interpolated between the layouts the frame moves between. |
| `junctions` | `"junctions": Array<Point>` | Join/split points of shared-prerequisite stages, when the frame is settled on a layout that has them. |
Expand All @@ -1751,6 +1769,7 @@ A laid-out graph from `layoutGraph`, in layout units (CSS px at a zoom of 1). Sh
| Member | Signature | Description |
|---|---|---|
| `alignment` | `"alignment": "BALANCED" \| "LEFTDOWN" \| "LEFTUP" \| "RIGHTDOWN" \| "RIGHTUP"` | How this layout placed its cards (see `GraphLayoutOptions.alignment`). |
| `blocks` | `"blocks": Map<string, LayoutBlock>` | Sibling blocks by block ID: many cards that share every relationship, wrapped into a grid of lines in one place in their layer (see `GraphLayoutOptions.blocks`). Their relationships' routes are the block's: one from each source into the block's in face, one from its out face to each target, shared by every card in it. |
| `groups` | `"groups": Map<string, Array<string>>` | Compound module boundaries and their direct members. |
| `height` | `"height": number` | The height of the drawing, everything in it, its padding included. |
| `junctions` | `"junctions": Array<Point>` | Join/split points of shared-prerequisite stages (see `GraphLayoutOptions.junctions`). |
Expand All @@ -1773,6 +1792,7 @@ How `layoutGraph` lays out a graph; every option has a default.
| Member | Signature | Description |
|---|---|---|
| `alignment` | `"alignment"?: "BALANCED" \| "LEFTDOWN" \| "LEFTUP" \| "RIGHTDOWN" \| "RIGHTUP"` | How to place the cards (see `GraphLayout.alignment`); chosen when absent. A transition passes its union's, so every step places its cards alike, in one ELK run. |
| `blocks` | `"blocks"?: ReadonlyMap<string, Array<string>>` | The blocks of a reference layout (`GraphLayout.blocks`, by block ID, their cards in order). Without it, a layout wraps every `blockMinimum` or more cards that share all their relationships (the same sources and targets, kinds and bundles) into a block; with it, only cards one of these held, two or more still alike, so a transition's steps keep their union's blocks. |
| `boundaries` | `"boundaries"?: ReadonlySet<string>` | Compound boundaries that stay boundaries even when nothing is left in them (see `moduleGroups`): a transition passes its union's, so no boundary turns into a card between steps. |
| `compound` | `"compound"?: Array<string> \| false \| true` | Group unambiguous containment-only entities into compound boundaries: `true` for `module`s (architecture), or the entity kinds that may become boundaries (infrastructure: modules, resource groups, parent resources). |
| `hints` | `"hints"?: ReadonlyMap<string, Point>` | Where cards were in a reference layout. ELK then keeps that order within each layer (semi-interactive crossing minimization) and still minimizes the crossings of long edges. Transitions pass their union layout, so cards keep their relative places from step to step. |
Expand Down Expand Up @@ -2041,6 +2061,22 @@ layerGap: number

Space between layers: room for a route's tail stub, two full turns (`routeRadius`) and its arrowhead's lead-in.

### `LayoutBlock`

```ts
interface LayoutBlock extends Point
```

A laid-out block: its centre and size, like a card's, and its cards in reading order.

| Member | Signature | Description |
|---|---|---|
| `height` | `"height": number` | The tray's height, its caption and padding included. |
| `members` | `"members": Array<string>` | Its cards' IDs, in reading order. |
| `width` | `"width": number` | The tray's width, its padding and any overhang into the columns' gaps included. |
| `x` | `"x": number` | Distance rightward. |
| `y` | `"y": number` | Distance downward. |

### `LayoutEdge`

```ts
Expand Down Expand Up @@ -3639,6 +3675,25 @@ trackSpacing: 10

Space between the crossing runs of S routes that share a gap and would otherwise lie on one another.

### `TransitionBlock`

```ts
interface TransitionBlock extends Point
```

A sibling block in a frame (see `GraphLayout.blocks`): the tray its cards sit in, its centre and size in layout units,
and how present it is: as present as its most present card, faded while a move goes to or from a layout without it.

| Member | Signature | Description |
|---|---|---|
| `height` | `"height": number` | The tray's height, interpolated between the layouts the frame moves between. |
| `key` | `"key": string` | The block's ID, the same in every layout that has it. |
| `members` | `"members": Array<string>` | Its cards' entity row IDs, in reading order. |
| `opacity` | `"opacity": number` | How present the tray is, 0 to 1: as present as its most present card. |
| `width` | `"width": number` | The tray's width, interpolated between the layouts the frame moves between. |
| `x` | `"x": number` | Distance rightward. |
| `y` | `"y": number` | Distance downward. |

### `TransitionEdge`

```ts
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/renderers.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Built-in Projections graph renderer: staged, identity-stable graph transitions (
- Handles: `graph`, `graph-horizontal`, `dag`, `architecture`, `infrastructure`, `dependencies`
- Comparison modes: `diff`, `side-by-side`, `animated`, `swipe`
- Package: `@githubnext/projections-renderer-graph`
- Example scenarios ([`scenarios.json`](../../packages/renderers/graph/scenarios.json)): Service platform; Service platform, payments first (custom order); Test timings with volatile durations; Class summaries, generated by a model; Source references, left to right; Declared rename; Feature flags; Feature flags, one revision; Single extraction; CI pipeline restructure; Release workflow; Platform gains a worker; Storage module split; Single extraction; Card icons; OpenRewrite: JUnit 4 to JUnit 5; Terraform: the database is replaced; Bicep: a private endpoint subnet; Terraform: one revision's plan; React 19.2 and clsx; Express 5 and React 19; npm workspace (one revision); NuGet package update; NuGet library with long package names; A layered module graph; A layered module graph (one revision); A wide module graph; A wide module graph (one revision); A hub-heavy module graph (one revision); An architecture of 42 components (one revision); Who may reach what: 6 callers, 16 owners, 74 relationships (graph); Who may reach what: 6 callers, 16 owners, 74 relationships (architecture)
- Example scenarios ([`scenarios.json`](../../packages/renderers/graph/scenarios.json)): Service platform; Service platform, payments first (custom order); Test timings with volatile durations; Class summaries, generated by a model; Source references, left to right; Declared rename; Feature flags; Feature flags, one revision; Single extraction; CI pipeline restructure; Release workflow; Platform gains a worker; Storage module split; Single extraction; Card icons; OpenRewrite: JUnit 4 to JUnit 5; Terraform: the database is replaced; Bicep: a private endpoint subnet; Terraform: one revision's plan; React 19.2 and clsx; Express 5 and React 19; npm workspace (one revision); NuGet package update; NuGet library with long package names; A layered module graph; A layered module graph (one revision); A wide module graph; A wide module graph (one revision); A hub-heavy module graph (one revision); MCP tools, toolsets and OAuth scopes; An architecture of 42 components (one revision); Who may reach what: 6 callers, 16 owners, 74 relationships (graph); Who may reach what: 6 callers, 16 owners, 74 relationships (architecture)

## `runtime-policy`

Expand Down
8 changes: 4 additions & 4 deletions eslint-suppressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -2307,7 +2307,7 @@
},
"packages/renderers/kit/src/graph-transition/crossing.ts": {
"@typescript-eslint/no-non-null-assertion": {
"count": 5
"count": 4
}
},
"packages/renderers/kit/src/graph-transition/diff-frame.ts": {
Expand Down Expand Up @@ -2413,12 +2413,12 @@
},
"packages/renderers/kit/src/layout/routing/bundles.ts": {
"@typescript-eslint/no-non-null-assertion": {
"count": 25
"count": 18
}
},
"packages/renderers/kit/src/layout/routing/context.ts": {
"@typescript-eslint/no-non-null-assertion": {
"count": 8
"count": 6
}
},
"packages/renderers/kit/src/layout/routing/corridor.ts": {
Expand Down Expand Up @@ -2534,7 +2534,7 @@
},
"packages/renderers/kit/src/react/graph-canvas/graph-link.tsx": {
"@typescript-eslint/no-non-null-assertion": {
"count": 5
"count": 4
}
},
"packages/renderers/kit/src/react/graph-canvas/laid-out-graph.tsx": {
Expand Down
6 changes: 5 additions & 1 deletion packages/renderers/graph/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ layer's cards share one top, or one left edge), with each card over the card it
links to wherever it can sit there, so that relationship runs straight, and
relationships that leave and enter the cards' faces along the layers (top to
bottom, or left to right for `graph-horizontal`), several into one card at
evenly spaced ports across its face. A graph's cards share the width its longest
evenly spaced ports across its face. Six or more cards that share every
relationship (such as a toolset's tools that all require one scope) wrap into a
block instead of one wide row: a captioned tray of cards in lines that ELK
places as a single node, with one route from each source and one to each target
(the kit's `GraphLayout.blocks`). A graph's cards share the width its longest
card text needs, from 112 to 216 units (longer text ends in an ellipsis and the
card's tooltip has it whole), and one revision's cards leave out the status
footer a comparison reserves, so typical graphs open fitted with their text at
Expand Down
61 changes: 59 additions & 2 deletions packages/renderers/graph/browser/graph.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import {expect, test} from '@playwright/test'
import {openRenderer} from '@githubnext/projections-renderer-harness/playwright'
import {featureFlags, fileReflow, layeredWaves} from '../../kit/browser/fixtures.js'
import {featureFlags, fileReflow, layeredWaves, wideFanOut} from '../../kit/browser/fixtures.js'
import {scrubSuite, selectionSuite} from '../../kit/browser/suite.js'
import {paneStatusSuite, statusSuite} from '../../kit/browser/status.js'

scrubSuite([fileReflow('graph'), fileReflow('graph-horizontal'), layeredWaves('graph'), featureFlags()])
scrubSuite([
fileReflow('graph'),
fileReflow('graph-horizontal'),
layeredWaves('graph'),
featureFlags(),
wideFanOut(),
wideFanOut('graph-horizontal'),
])
selectionSuite(fileReflow('graph'), 'file:src/api.ts')
statusSuite(fileReflow('graph'))
statusSuite(layeredWaves('graph'))
Expand Down Expand Up @@ -224,3 +231,53 @@ test('node names are monospace identifiers that stay inside their cards; kinds s
).toBe(false)
})
})

test('a wide fan-out wraps into a block whose relationships enter and leave its tray as one', async ({page}) => {
const {before, after} = wideFanOut()
for (const request of [{extraction: after}, {before, after, progress: 1}, {before, after, comparisonMode: 'diff' as const}]) {
const renderer = await openRenderer(page, {renderer: 'graph', ...request})
// In screen pixels: whether a card is in a tray is the same at any zoom.
const drawn = await renderer.frame.locator('svg.graph').evaluate(svg => {
const box = (element: Element | null) => {
const rect = element?.getBoundingClientRect() ?? new DOMRect(Number.NaN, Number.NaN)
return {left: rect.left, right: rect.right, top: rect.top, bottom: rect.bottom}
}
const blocks = [...svg.querySelectorAll<SVGGElement>('.graph-block')].map(block => ({
caption: block.querySelector('.graph-block-caption')?.textContent ?? '',
tray: box(block.querySelector('.graph-block-tray')),
}))
const cards = [...svg.querySelectorAll<SVGGElement>('.graph-node[data-entity-id]')].map(node => ({
id: node.dataset.entityId ?? '',
box: box(node.querySelector('.node-surface')),
}))
const links = [...svg.querySelectorAll<SVGGElement>('.graph-link[data-entity-id]')].map(link => ({
id: link.dataset.entityId ?? '',
toBlock: link.dataset.toBlock,
fromBlock: link.dataset.fromBlock,
d: link.querySelector('path.graph-edge')?.getAttribute('d'),
}))
return {blocks, cards, links}
})
// The arrivals and the six remaining issue tools: one block each.
expect(drawn.blocks.map(block => block.caption.replace(/ \+\d+$/u, '')).toSorted()).toEqual(['6 tools', '8 tools'])
const tray = drawn.blocks.find(block => block.caption.startsWith('8'))?.tray
const arrivals = drawn.cards.filter(card => card.id.startsWith('tool:') && card.id.includes('automation'))
expect(arrivals).toHaveLength(8)
for (const {id, box} of arrivals) {
expect(
tray && box.left >= tray.left && box.right <= tray.right && box.top >= tray.top && box.bottom <= tray.bottom,
`${id} in its tray`,
).toBe(true)
}
// Wrapped: in more than one line.
expect(new Set(arrivals.map(card => Math.round(card.box.top))).size).toBeGreaterThan(1)
// Every arrival's relationships share one route into the tray and one out of it.
const into = drawn.links.filter(link => link.id.startsWith('toolset:copilot_automations->'))
const out = drawn.links.filter(link => link.id.includes('automation') && link.id.endsWith('->scope:repo'))
expect(into).toHaveLength(8)
expect(out).toHaveLength(8)
expect(new Set(into.map(link => link.d)).size).toBe(1)
expect(new Set(out.map(link => link.d)).size).toBe(1)
expect(into.every(link => link.toBlock !== undefined) && out.every(link => link.fromBlock !== undefined)).toBe(true)
}
})
Loading