Update history_tree.py
This commit is contained in:
@@ -55,22 +55,21 @@ 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, White-Background Horizontal Graph."""
|
"""Generates a Fixed-Size, Compact Horizontal Graph."""
|
||||||
dot = [
|
dot = [
|
||||||
'digraph History {',
|
'digraph History {',
|
||||||
' rankdir=LR;',
|
' rankdir=LR;',
|
||||||
# 1. Force White Background (Fixes the black/transparent issue)
|
' bgcolor="white";', # Clean background
|
||||||
' bgcolor="white";',
|
|
||||||
|
|
||||||
# 2. TIGHT Layout settings (Fixes "Too Big")
|
# --- COMPACT LAYOUT SETTINGS ---
|
||||||
' nodesep=0.2;', # Closer together horizontally
|
' nodesep=0.15;', # Horizontal gap between nodes
|
||||||
' ranksep=0.3;', # Closer together vertically
|
' ranksep=0.25;', # Vertical gap between branches
|
||||||
' ratio=compress;', # Try to compress the drawing
|
|
||||||
|
|
||||||
# 3. Small Node Styling
|
# --- FIXED SIZE NODES (The Key Fix) ---
|
||||||
# height=0 forces node to fit text exactly
|
# fixedsize=true: Ignores text length, forces the width/height below.
|
||||||
# margin=0.05 removes internal padding
|
# width=1.2: Sets box width to ~100px
|
||||||
' node [shape=box, style="filled,rounded", fillcolor="#f9f9f9", fontname="Arial", fontsize=9, height=0, margin="0.05,0.05"];',
|
# height=0.4: Sets box height to ~30px
|
||||||
|
' node [shape=box, style="filled,rounded", fillcolor="#f9f9f9", fontname="Arial", fontsize=9, fixedsize=true, width=1.3, height=0.45];',
|
||||||
' edge [color="#666666", arrowsize=0.5, penwidth=1.0];'
|
' edge [color="#666666", arrowsize=0.5, penwidth=1.0];'
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -79,26 +78,22 @@ class HistoryTree:
|
|||||||
for n in sorted_nodes:
|
for n in sorted_nodes:
|
||||||
nid = n["id"]
|
nid = n["id"]
|
||||||
|
|
||||||
# 4. Aggressive Text Truncation
|
# Truncate text to fit in the 1.3 inch box
|
||||||
full_note = n.get('note', 'Step')
|
full_note = n.get('note', 'Step')
|
||||||
# Keep only first 12 chars to keep box small
|
short_note = (full_note[:10] + '..') if len(full_note) > 10 else full_note
|
||||||
short_note = (full_note[:12] + '..') if len(full_note) > 12 else full_note
|
|
||||||
|
|
||||||
# Use simple label
|
|
||||||
label = f"{short_note}\\n{nid[:4]}"
|
label = f"{short_note}\\n{nid[:4]}"
|
||||||
|
|
||||||
# Styling
|
# Colors
|
||||||
color = "#f0f0f0" # Light Grey default
|
color = "#f0f0f0"
|
||||||
penwidth = "1"
|
penwidth = "1"
|
||||||
|
|
||||||
# Active Node (HEAD) - Yellow
|
|
||||||
if nid == self.head_id:
|
if nid == self.head_id:
|
||||||
color = "#fff6cd"
|
color = "#fff6cd" # Yellow for Active
|
||||||
penwidth = "2"
|
penwidth = "2"
|
||||||
|
|
||||||
# Branch Tips - Light Green
|
|
||||||
if nid in self.branches.values():
|
if nid in self.branches.values():
|
||||||
if color == "#f0f0f0": color = "#e6ffe6"
|
if color == "#f0f0f0": color = "#e6ffe6" # Green for Branch Tips
|
||||||
|
|
||||||
dot.append(f' "{nid}" [label="{label}", fillcolor="{color}", penwidth="{penwidth}"];')
|
dot.append(f' "{nid}" [label="{label}", fillcolor="{color}", penwidth="{penwidth}"];')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user