Update history_tree.py

This commit is contained in:
2026-01-02 13:29:37 +01:00
committed by GitHub
parent af174839e8
commit 244f0f44d7

View File

@@ -55,39 +55,50 @@ class HistoryTree:
return {"nodes": self.nodes, "branches": self.branches, "head_id": self.head_id} return {"nodes": self.nodes, "branches": self.branches, "head_id": self.head_id}
def generate_horizontal_graph(self): def generate_horizontal_graph(self):
"""Generates a Compact Fusion 360-style Horizontal Graph.""" """Generates a Compact, White-Background Horizontal Graph."""
dot = [ dot = [
'digraph History {', 'digraph History {',
' rankdir=LR;', ' rankdir=LR;',
' bgcolor="transparent";', # 1. Force White Background (Fixes the black/transparent issue)
# COMPACT STYLING ' bgcolor="white";',
' nodesep=0.3;',
' ranksep=0.4;', # 2. TIGHT Layout settings (Fixes "Too Big")
' node [shape=rect, style="filled,rounded", fontname="Arial", fontsize=10, height=0.4, margin="0.1,0.05"];', ' nodesep=0.2;', # Closer together horizontally
' edge [color="#888888", arrowsize=0.6, penwidth=1.0];' ' ranksep=0.3;', # Closer together vertically
' ratio=compress;', # Try to compress the drawing
# 3. Small Node Styling
# height=0 forces node to fit text exactly
# margin=0.05 removes internal padding
' node [shape=box, style="filled,rounded", fillcolor="#f9f9f9", fontname="Arial", fontsize=9, height=0, margin="0.05,0.05"];',
' edge [color="#666666", arrowsize=0.5, penwidth=1.0];'
] ]
sorted_nodes = sorted(self.nodes.values(), key=lambda x: x["timestamp"]) sorted_nodes = sorted(self.nodes.values(), key=lambda x: x["timestamp"])
for n in sorted_nodes: for n in sorted_nodes:
nid = n["id"] nid = n["id"]
# TRUNCATE LABEL to keep box small
full_note = n.get('note', 'Step')
short_note = (full_note[:15] + '..') if len(full_note) > 15 else full_note
label = f"{short_note}\\n<{nid[:4]}>" # 4. Aggressive Text Truncation
full_note = n.get('note', 'Step')
# Keep only first 12 chars to keep box small
short_note = (full_note[:12] + '..') if len(full_note) > 12 else full_note
# Use simple label
label = f"{short_note}\\n{nid[:4]}"
# Styling # Styling
color = "#e0e0e0" color = "#f0f0f0" # Light Grey default
penwidth = "1" penwidth = "1"
# Active Node (HEAD) - Yellow
if nid == self.head_id: if nid == self.head_id:
color = "#ffeba0" # Active Yellow color = "#fff6cd"
penwidth = "2" penwidth = "2"
# Branch Tips - Light Green
if nid in self.branches.values(): if nid in self.branches.values():
# Branch tips get slightly darker border if color == "#f0f0f0": color = "#e6ffe6"
if color == "#e0e0e0": color = "#d0f0c0"
dot.append(f' "{nid}" [label="{label}", fillcolor="{color}", penwidth="{penwidth}"];') dot.append(f' "{nid}" [label="{label}", fillcolor="{color}", penwidth="{penwidth}"];')