Home: widen the brain layout, fix its entrance, add a clear button to pinned charts
Playwright Tests / test-playwright (1, 2) (push) Canceled after 0s
Playwright Tests / test-playwright (2, 2) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Compose Smoke Test / test-compose (push) Canceled after 0s
Playwright Tests / merge-reports (push) Canceled after 0s

The force layout settled roughly square, so in a wide band the graph sat as a
small island. Vertical centring now pulls nearly three times as hard as
horizontal and the seed sits on an ellipse, which settles at about 2.2:1
without stretching the circles or the edges.

The graph also slid in on load: the rebuild fit ran with a 300ms duration, so
React Flow animated the pan from its default viewport to the content. The fit
is instant now, and the canvas grows in from the centre with `scaleIn` once it
has a layout.

The pinned chart header said "Esc clears", which a phone cannot act on. It
carries the same "× Clear" button as the list header instead; Escape still
works.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017MeiWk3Yq12n2pTvnQWYvt
This commit is contained in:
2026-08-17 08:33:27 +02:00
co-authored by Claude Opus 5
parent 0832be32a9
commit 5fc7bbee34
2 changed files with 86 additions and 51 deletions
+58 -37
View File
@@ -17,9 +17,11 @@ import {
forceY,
type SimulationNodeDatum,
} from "d3-force"
import { motion } from "motion/react"
import { useEffect, useMemo } from "react"
import type { BrainGraph } from "@/client"
import { scaleIn } from "@/lib/motion"
import { BrainEdge } from "./BrainEdge"
import { BrainNode, type BrainNodeData } from "./BrainNode"
import "./flow.css"
@@ -46,8 +48,8 @@ type Placed = SimulationNodeDatum & { id: string; size: number; room: number }
*
* A live simulation would keep nudging nodes under the pointer while someone is
* panning, and a graph that never stops moving is unreadable. Starting from a
* circle rather than d3's own random phyllotaxis also means the same flows lay
* out the same way twice.
* fixed ellipse rather than d3's own random phyllotaxis also means the same
* flows lay out the same way twice.
*
* `forceX`/`forceY` rather than `forceCenter`: centering only translates the
* whole thing, so unconnected flows — which is most of them — would push each
@@ -68,8 +70,12 @@ function build(graph: BrainGraph): { nodes: Node[]; edges: Edge[] } {
id: node.id,
size,
room: size / 2 + LABEL_ROOM,
x: Math.cos(angle) * radius,
y: Math.sin(angle) * radius,
// An ellipse, not a circle: the band across Home is far wider than it is
// tall, so the layout is meant to come out that way too. Seeding the
// shape it should settle into beats making the forces below fight a
// circle into one.
x: Math.cos(angle) * radius * 1.8,
y: Math.sin(angle) * radius * 0.55,
}
})
const links = (graph.edges ?? []).map((edge) => ({
@@ -89,8 +95,13 @@ function build(graph: BrainGraph): { nodes: Node[]; edges: Edge[] } {
"collide",
forceCollide<Placed>((node) => node.room),
)
.force("x", forceX(0).strength(0.06))
.force("y", forceY(0).strength(0.06))
// Centring pulls nearly three times as hard vertically as horizontally, so
// the graph compresses into a band roughly twice as wide as it is tall
// instead of the square an even pull settles into. Coming out of the
// simulation rather than out of a transform keeps the circles round and the
// edges the length the link force asked for.
.force("x", forceX(0).strength(0.05))
.force("y", forceY(0).strength(0.14))
.stop()
.tick(300)
@@ -144,40 +155,50 @@ function BrainCanvas() {
useEffect(() => {
if (!shape) return
// After the new nodes have been measured, or the fit is of the old ones.
const frame = requestAnimationFrame(() =>
fitView({ ...FIT, duration: 300 }),
)
// Instant, never animated: an animated fit travels from React Flow's
// default viewport to the content, which on first load is the whole graph
// visibly sliding in from the corner.
const frame = requestAnimationFrame(() => fitView(FIT))
return () => cancelAnimationFrame(frame)
}, [shape, fitView])
return (
<ReactFlow
nodes={nodes}
edges={edges}
nodeTypes={nodeTypes}
edgeTypes={edgeTypes}
nodesDraggable={false}
nodesConnectable={false}
elementsSelectable={false}
proOptions={{ hideAttribution: true }}
fitView
fitViewOptions={FIT}
minZoom={0.1}
maxZoom={2}
// A band inside a page that scrolls. React Flow claims the wheel by
// default, so leaving these on would trap the page under the pointer;
// the fit above keeps the whole graph in view without panning anyway.
zoomOnScroll={false}
zoomOnDoubleClick={false}
panOnDrag={false}
preventScrolling={false}
onNodeClick={(_event, node) => {
const [flow] = (node.data as BrainNodeData).flows
if (flow)
navigate({ to: "/flows/$flowName", params: { flowName: flow } })
}}
className="brain-flat h-full w-full"
/>
// Held back until there is a layout, so the graph grows in from the centre
// of the band it is already fitted to rather than appearing mid-pan.
<motion.div
variants={scaleIn}
initial="hidden"
animate={nodes.length ? "visible" : "hidden"}
className="h-full w-full"
>
<ReactFlow
nodes={nodes}
edges={edges}
nodeTypes={nodeTypes}
edgeTypes={edgeTypes}
nodesDraggable={false}
nodesConnectable={false}
elementsSelectable={false}
proOptions={{ hideAttribution: true }}
fitView
fitViewOptions={FIT}
minZoom={0.1}
maxZoom={2}
// A band inside a page that scrolls. React Flow claims the wheel by
// default, so leaving these on would trap the page under the pointer;
// the fit above keeps the whole graph in view without panning anyway.
zoomOnScroll={false}
zoomOnDoubleClick={false}
panOnDrag={false}
preventScrolling={false}
onNodeClick={(_event, node) => {
const [flow] = (node.data as BrainNodeData).flows
if (flow)
navigate({ to: "/flows/$flowName", params: { flowName: flow } })
}}
className="brain-flat h-full w-full"
/>
</motion.div>
)
}
@@ -191,7 +212,7 @@ function BrainCanvas() {
*/
export function BrainView() {
return (
<div className="h-64 w-full sm:h-80">
<div className="h-72 w-full sm:h-96">
<ReactFlowProvider>
<BrainCanvas />
</ReactFlowProvider>