The Tree Model and Tidy-Tree Auto-Layout
AnyTool Mind Map Tool keeps a single map object as its source of truth: a title, a rootId, and a nodes record mapping each id to a node with text, a colour key, a collapsed flag and an ordered array of child ids — a tree expressed as an id→node map. Positions are never stored; they are derived by a pure tidy-tree layout recomputed on every change. A post-order walk assigns each visible leaf the next free row (× a fixed row gap) and gives every parent the average y of its visible children, while a node’s x is simply its depth × a fixed level gap, producing a horizontal tree that grows to the right with siblings that never overlap and parents centred on their subtrees. A collapsed node contributes nothing to the walk, so hiding a branch instantly reclaims its vertical space. The drawing is then normalised into a positive coordinate space with a margin, and each parent-to-child link is rendered as a cubic-bézier connector tinted with the child branch’s colour.
- Map = title + rootId + nodes record (id → { text, color, collapsed, children[] }); positions are derived, not stored
- x = depth × level gap; y from a post-order walk: leaves take the next row, parents centre on visible children
- Collapsed branches are excluded from the walk, so hiding a branch reclaims space immediately
- Connectors are cubic-bézier curves from a parent’s right edge to a child’s left edge, tinted per branch
- Layout is pure and recomputed (useMemo) on every change; a Fit button scales the whole map to the viewport
