Brain: hover labels, activity falloff, rim-anchored directed edges
A name under every circle was most of what the graph drew, and none of it was what someone looks at the brain for. Only the hovered or keyboard-focused neuron names itself now — a failing one always does, since colour is never the only carrier of a status. The label is absolute and the collide radius already held that space, so revealing one moves nothing. Taking it out of flow also fixed the off-centre edges: the node box was as wide as its widest label, so a 32px circle inside a 140px box sat 54px left of where the layout put it and every edge aimed at the box rather than at the circle. Neurons are filled discs rather than `bg-card` outlines, which were a hairline against `--background` in light and close to nothing in dark. The fill is a neutral `--muted-foreground` alpha and stays neutral: status still speaks only through the border and the word beneath. Its lightness carries how recently the open page saw that neuron publish — brightest just after it fires, decaying over 90s to a floor it never drops below, so a graph left open sorts itself into what is busy and what is not. Edges do the same on their stroke. The signal is only what this session has seen on the socket, so a fresh page starts everything at a neutral middle rather than claiming a history it does not have. Both are CSS transitions gated on `prefers-reduced-motion`, decayed out of and snapped into, never the other way round. `BrainEdge` now carries both circle radii and trims its path back to the rims, with an arrowhead at the end it flows into. The barbs are two more segments of the same stroked path rather than an SVG marker, so they dim with the line they belong to. Neither trim reaches past the midpoint, so neurons closer together than their radii still get a line pointing the right way. `edge-pulse` reads its landing colour from `--edge-rest` instead of naming `--muted-foreground`, so a selected edge — which rests in blue — decays into its own colour instead of crossing to grey and snapping back at the end. Obsidian's graph view is the reference for the first three: filled nodes sized by degree, labels on a fade threshold with hover to recover them, and arrows as an explicit affordance. The falloff-by-opacity encoding is the standard one in the dynamic-graph literature.
This commit is contained in:
@@ -22,7 +22,7 @@ import { useEffect, useMemo } from "react"
|
||||
|
||||
import type { BrainGraph } from "@/client"
|
||||
import { scaleIn } from "@/lib/motion"
|
||||
import { BrainEdge } from "./BrainEdge"
|
||||
import { BrainEdge, type BrainEdgeData } from "./BrainEdge"
|
||||
import { BrainNode, type BrainNodeData } from "./BrainNode"
|
||||
import "./flow.css"
|
||||
import { graphQueryOptions } from "./queries"
|
||||
@@ -38,7 +38,10 @@ const edgeTypes = { brain: BrainEdge }
|
||||
/** Circle diameter, from how many neurons this one is wired to. */
|
||||
const SIZE_MIN = 32
|
||||
const SIZE_MAX = 96
|
||||
/** Room around a circle for its label, so the layout does not overlap them. */
|
||||
/**
|
||||
* Room around a circle for the label it shows on hover. Reserved in the layout
|
||||
* rather than in the node box, so revealing a label moves nothing.
|
||||
*/
|
||||
const LABEL_ROOM = 26
|
||||
|
||||
type Placed = SimulationNodeDatum & { id: string; size: number; room: number }
|
||||
@@ -105,6 +108,10 @@ function build(graph: BrainGraph): { nodes: Node[]; edges: Edge[] } {
|
||||
.stop()
|
||||
.tick(300)
|
||||
|
||||
// Both of an edge's handles sit at a neuron's centre, so the edge is what has
|
||||
// to trim itself back to the rims; the radius is only known here.
|
||||
const radius = new Map(placed.map((node) => [node.id, node.size / 2]))
|
||||
|
||||
return {
|
||||
nodes: placed.map((node, index) => {
|
||||
const source = (graph.nodes ?? [])[index]
|
||||
@@ -130,7 +137,11 @@ function build(graph: BrainGraph): { nodes: Node[]; edges: Edge[] } {
|
||||
type: "brain",
|
||||
source: edge.source,
|
||||
target: edge.target,
|
||||
data: { messages: edge.messages ?? [] },
|
||||
data: {
|
||||
messages: edge.messages ?? [],
|
||||
sourceRadius: radius.get(edge.source) ?? 0,
|
||||
targetRadius: radius.get(edge.target) ?? 0,
|
||||
} satisfies BrainEdgeData,
|
||||
})),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user