Update history_tree.py

This commit is contained in:
2026-01-02 16:09:33 +01:00
committed by GitHub
parent 14aabb49ce
commit 08955b2e0c

View File

@@ -55,19 +55,19 @@ 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 Graph with HTML Labels and Tooltips.""" """Generates a Compact, Readable Horizontal Graph using HTML Labels."""
dot = [ dot = [
'digraph History {', 'digraph History {',
' rankdir=LR;', ' rankdir=LR;',
' bgcolor="white";', ' bgcolor="white";',
' splines=ortho;', # Clean right-angle lines
# TIGHT LAYOUT # TIGHT SPACING
' nodesep=0.2;', ' nodesep=0.2;',
' ranksep=0.3;', ' ranksep=0.3;',
' splines=ortho;', # Orthogonal lines (right angles) look cleaner/techier
# BASE NODE STYLE # GLOBAL STYLES
' node [shape=plain, fontname="Arial", fontsize=9];', # shape=plain for HTML labels ' node [shape=plain, fontname="Arial"];',
' edge [color="#888888", arrowsize=0.6, penwidth=1.0];' ' edge [color="#888888", arrowsize=0.6, penwidth=1.0];'
] ]
@@ -77,36 +77,35 @@ class HistoryTree:
nid = n["id"] nid = n["id"]
full_note = n.get('note', 'Step') full_note = n.get('note', 'Step')
# Sanitize for HTML (replace quotes) # Truncate slightly for display, but keep enough to read
safe_note = full_note.replace('"', "'") # HTML Labels allow distinct styling for Title vs ID
display_note = (full_note[:15] + '..') if len(full_note) > 15 else full_note
# Truncate visual label # COLORS
short_note = (full_note[:12] + '..') if len(full_note) > 12 else full_note bg_color = "#f9f9f9"
border_color = "#999999"
# Determine Colors
bg_color = "#f4f4f4"
border_color = "#cccccc"
border_width = "1" border_width = "1"
if nid == self.head_id: if nid == self.head_id:
bg_color = "#fff6cd" # Yellow bg_color = "#fff6cd" # Yellow for Current
border_color = "#eebb00" border_color = "#eebb00"
border_width = "2" border_width = "2"
elif nid in self.branches.values(): elif nid in self.branches.values():
bg_color = "#e6ffe6" # Green tip bg_color = "#e6ffe6" # Green for Tips
border_color = "#99cc99" border_color = "#66aa66"
# HTML Label Construction # HTML LABEL (Table)
# This creates a tight table-like node # This is the trick to make it compact but readable
label = ( label = (
f'<<TABLE BORDER="{border_width}" CELLBORDER="0" CELLSPACING="0" CELLPADDING="4" BGCOLOR="{bg_color}" COLOR="{border_color}">' f'<<TABLE BORDER="{border_width}" CELLBORDER="0" CELLSPACING="0" CELLPADDING="4" BGCOLOR="{bg_color}" COLOR="{border_color}">'
f'<TR><TD><B>{short_note}</B></TD></TR>' f'<TR><TD><B><FONT POINT-SIZE="10">{display_note}</FONT></B></TD></TR>'
f'<TR><TD><FONT POINT-SIZE="8" COLOR="#666666">{nid[:4]}</FONT></TD></TR>' f'<TR><TD><FONT POINT-SIZE="8" COLOR="#555555">{nid[:4]}</FONT></TD></TR>'
f'</TABLE>>' f'</TABLE>>'
) )
# Add node with Tooltip # Tooltip shows full text on hover
dot.append(f' "{nid}" [label={label}, tooltip="{safe_note}"];') safe_tooltip = full_note.replace('"', "'")
dot.append(f' "{nid}" [label={label}, tooltip="{safe_tooltip}"];')
if n["parent"] and n["parent"] in self.nodes: if n["parent"] and n["parent"] in self.nodes:
dot.append(f' "{n["parent"]}" -> "{nid}";') dot.append(f' "{n["parent"]}" -> "{nid}";')