Color graph nodes by branch for visual distinction

Each branch gets a unique subtle tint (grey, blue, purple, coral,
teal, sand) so sub-branches are visually distinguishable. HEAD
(yellow) and branch tip (green) colors still take priority.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-28 20:22:45 +01:00
parent 24f9b7d955
commit e2f30b0332

View File

@@ -111,6 +111,30 @@ class HistoryTree:
' edge [color="#888888", arrowsize=0.6, penwidth=1.0];' ' edge [color="#888888", arrowsize=0.6, penwidth=1.0];'
] ]
# Build reverse lookup: node_id -> branch name (walk each branch ancestry)
node_to_branch: dict[str, str] = {}
for b_name, tip_id in self.branches.items():
current = tip_id
while current and current in self.nodes:
if current not in node_to_branch:
node_to_branch[current] = b_name
current = self.nodes[current].get('parent')
# Per-branch color palette (bg, border) — cycles for many branches
_branch_palette = [
('#f9f9f9', '#999999'), # grey (default/main)
('#eef4ff', '#6699cc'), # blue
('#f5eeff', '#9977cc'), # purple
('#fff0ee', '#cc7766'), # coral
('#eefff5', '#66aa88'), # teal
('#fff8ee', '#ccaa55'), # sand
]
branch_names = list(self.branches.keys())
branch_colors = {
b: _branch_palette[i % len(_branch_palette)]
for i, b in enumerate(branch_names)
}
sorted_nodes = sorted(self.nodes.values(), key=lambda x: x["timestamp"]) sorted_nodes = sorted(self.nodes.values(), key=lambda x: x["timestamp"])
# Font sizes and padding - smaller for vertical # Font sizes and padding - smaller for vertical
@@ -138,9 +162,10 @@ class HistoryTree:
if nid in tip_to_branches: if nid in tip_to_branches:
branch_label = ", ".join(tip_to_branches[nid]) branch_label = ", ".join(tip_to_branches[nid])
# COLORS # COLORS — per-branch tint, overridden for HEAD and tips
bg_color = "#f9f9f9" b_name = node_to_branch.get(nid)
border_color = "#999999" bg_color, border_color = branch_colors.get(
b_name, _branch_palette[0])
border_width = "1" border_width = "1"
if nid == self.head_id: if nid == self.head_id: