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. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XC2jX6Hdj7pxGGKzBTrbqB
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { BaseEdge, type EdgeProps, getStraightPath } from "@xyflow/react"
|
||||
import { BaseEdge, type EdgeProps } from "@xyflow/react"
|
||||
import { memo, useEffect, useRef, useState } from "react"
|
||||
|
||||
import { duration } from "@/lib/motion"
|
||||
@@ -8,9 +8,55 @@ import { useLatestTs } from "./liveStore"
|
||||
export type BrainEdgeData = {
|
||||
/** Every message this connection carries, qualified. */
|
||||
messages: string[]
|
||||
/** Circle radii of the two neurons, so the line can stop at their rims. */
|
||||
sourceRadius: number
|
||||
targetRadius: number
|
||||
[key: string]: unknown
|
||||
}
|
||||
|
||||
/** Arrowhead barb length, and how far its tip stops short of the target rim. */
|
||||
const HEAD = 7
|
||||
const RIM_GAP = 3
|
||||
|
||||
/**
|
||||
* A line from rim to rim, with an arrowhead at the end it flows into.
|
||||
*
|
||||
* Both handles sit at a neuron's centre, so the raw path runs under both
|
||||
* circles: it looks off-centre wherever the circles differ in size, and it says
|
||||
* nothing about which way the value travels. 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 instead of needing a fill of their own.
|
||||
*/
|
||||
function rimPath(
|
||||
sourceX: number,
|
||||
sourceY: number,
|
||||
targetX: number,
|
||||
targetY: number,
|
||||
sourceRadius: number,
|
||||
targetRadius: number,
|
||||
): string {
|
||||
const length = Math.hypot(targetX - sourceX, targetY - sourceY) || 1
|
||||
const unitX = (targetX - sourceX) / length
|
||||
const unitY = (targetY - sourceY) / length
|
||||
// Neither trim reaches past the midpoint, so two neurons closer together than
|
||||
// their radii still get a line pointing the right way rather than a backwards
|
||||
// one. The force layout keeps them apart; this only stops it looking broken.
|
||||
const from = Math.min(sourceRadius, length / 2)
|
||||
const to = Math.min(targetRadius + RIM_GAP, length - from)
|
||||
const startX = sourceX + unitX * from
|
||||
const startY = sourceY + unitY * from
|
||||
const tipX = targetX - unitX * to
|
||||
const tipY = targetY - unitY * to
|
||||
const line = `M${startX},${startY}L${tipX},${tipY}`
|
||||
if (length - from - to < HEAD) return line
|
||||
|
||||
const backX = tipX - unitX * HEAD
|
||||
const backY = tipY - unitY * HEAD
|
||||
const spreadX = (-unitY * HEAD) / 2
|
||||
const spreadY = (unitX * HEAD) / 2
|
||||
return `${line}M${backX + spreadX},${backY + spreadY}L${tipX},${tipY}L${backX - spreadX},${backY - spreadY}`
|
||||
}
|
||||
|
||||
/**
|
||||
* A connection between neurons, lit by whatever passes along it.
|
||||
*
|
||||
@@ -26,12 +72,23 @@ function BrainEdgeComponent({
|
||||
targetY,
|
||||
data,
|
||||
}: EdgeProps) {
|
||||
const { messages } = (data ?? { messages: [] }) as BrainEdgeData
|
||||
const { messages, sourceRadius, targetRadius } = (data ?? {
|
||||
messages: [],
|
||||
sourceRadius: 0,
|
||||
targetRadius: 0,
|
||||
}) as BrainEdgeData
|
||||
const ts = useLatestTs(messages)
|
||||
const [pulsing, setPulsing] = useState(false)
|
||||
const lastTs = useRef(0)
|
||||
|
||||
const [path] = getStraightPath({ sourceX, sourceY, targetX, targetY })
|
||||
const path = rimPath(
|
||||
sourceX,
|
||||
sourceY,
|
||||
targetX,
|
||||
targetY,
|
||||
sourceRadius,
|
||||
targetRadius,
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
if (!ts || ts === lastTs.current) return
|
||||
@@ -41,7 +98,18 @@ function BrainEdgeComponent({
|
||||
return () => clearTimeout(timer)
|
||||
}, [ts])
|
||||
|
||||
return <BaseEdge id={id} path={path} className={cn(pulsing && "edge-live")} />
|
||||
return (
|
||||
<BaseEdge
|
||||
id={id}
|
||||
path={path}
|
||||
className={cn(
|
||||
"brain-edge",
|
||||
// Nothing seen yet this session is not the same as seen and gone quiet.
|
||||
ts === 0 && "brain-idle",
|
||||
pulsing && "brain-hot edge-live",
|
||||
)}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export const BrainEdge = memo(BrainEdgeComponent)
|
||||
|
||||
Reference in New Issue
Block a user