# Git-graph visualizer — implementation plan Status: planned (not yet built). Scope: add graph visualizations on top of the existing capture/storage/query foundation. ## Goals - A **GitKraken/gitamine-style** graph (straight branches, one column per branch) for "show me everything," ordered globally by time. - A **file-tree-style** graph (subtrees contiguous) for the folder/collapse metaphor. - **Collapse a fork** like a folder: hide all but one child branch. - **Solo a tab**: filter the graph to a single tab; cross-tab "open tab" links become buttons that re-scope the view. Reference for the lane algorithm: ## Key data insight Every `Visit` already carries `parentId` (the edge) and `tabId` (the tab). So: - A **fork** = a node with ≥2 children. - A **cross-tab edge** (`parent.tabId !== child.tabId`) = a link that opened a new tab. This is the basis for both solo-scoping and the tab-open buttons. Our visits form a **tree** (one parent each), not a general DAG — so there are no true merges. "Merge commit" in the original ask = a fork (multiple children). This makes layout simpler than git's. ## Architecture: shared renderer, swappable layouts ``` getForest(range) → full forest (all tabs) │ viewModel(forest, viewState) → visible forest + per-node annotations │ viewState = { mode, soloTab, collapsed: Set } │ annotation = { isFork, hiddenBranchCount, opensTabs[], openedFromTab } │ layout strategy → positions: Map, edges, laneColors ├─ chronologicalLayout() GitKraken-style: row = time rank └─ treeLayout() file-tree: row = DFS pre-order, col = depth │ GraphCanvas → SVG lane/edge gutter + positioned rows (favicon, title, collapse toggle, tab buttons) ``` - `src/viewer/graph/layout.ts` — two **pure** functions returning the same `GraphLayout` shape. The testable core; no DOM/framework dependency. - `src/viewer/graph/viewModel.ts` — applies solo + collapse and computes annotations from the full forest. - `GraphCanvas` — one renderer used by both layouts. SVG draws dots at `(col,row)` + edges; rows are positioned at a fixed `rowHeight` and carry the HTML (favicon/title/links/buttons). Hybrid: SVG for crisp diagonal edges, HTML for styling + `content-visibility` perf. ## Layout details **Chronological (straight branches).** Rows = visits sorted by `ts`. Columns via the active-lanes greedy from the reference: a node inherits its parent's column if it is the parent's **mainline** child; otherwise it claims the lowest free lane that is not a *forbidden column* (one that would force its edge to cross an occupied lane between parent-row and child-row). Ended lanes are set to `nil` (not removed) so branches stay vertically straight. **Tree-grouped.** Row = DFS pre-order index (subtrees contiguous); col = depth. Same `GraphCanvas`, different positions. **Mainline = most-recently-active child** (chosen): for each fork, the continued child is the one whose subtree contains the latest `ts`. One post-order max-ts pass; used for BOTH lane continuation and collapse so they agree. ## Collapse (folder twist) `collapsed: Set` in view state. Collapsible = ≥2 visible children. Collapsing prunes the non-mainline child subtrees before layout, so the graph re-lays-out smaller. Node shows a folder toggle + `+N branches` badge. State is keyed by visit id and survives filter/range changes. ## Solo a tab + tab-open buttons - Header **scope chip**: `All tabs ▾` / `Tab: "" ✕`. - Solo filters visible nodes to `tabId === soloTab`. A node whose parent is in another tab becomes a root, annotated `openedFromTab` → renders a `↩ opened from <page>` button that re-scopes to the opener's tab. - A node that opened other tabs renders `↗ open tab` per spawned tab → re-scopes to that child's tab. These buttons are the links between per-tab graphs. - Navigation is **in place** (re-scope the same viewer), not a split panel. - Collapse composes within the soloed set. ## UI wiring - View switcher: `Git graph | Tree | List` (keeps `IndentedTreeView`, showcases the `GraphView` seam). - `GraphView` interface widens to `render(ctx, container)` where `ctx = { roots, annotations, actions }`; `IndentedTreeView` ignores extras. - `main` owns `viewState` and re-derives the view model on any change. ## Testing - Pure layout unit tests (`tests/`, `npm test`): unique `(row,col)` per node, parent-above-child, mainline shares parent column, forbidden-column avoidance, tree contiguity, collapse keeps most-recently-active, solo filter + cross-tab annotations. - Optionally extend `test:e2e` with a viewer-render smoke check. ## Build order 1. `viewModel` + `chronologicalLayout` + `GraphCanvas` + view switcher. 2. `treeLayout` (second strategy on the same canvas). 3. Collapse. 4. Solo + tab-open buttons. Each step is independently testable and leaves a working viewer.