From ab973c6d58d5f4a4c8b8b3e75fc03c946df8edab Mon Sep 17 00:00:00 2001 From: ethanfel Date: Sat, 3 Jan 2026 01:00:35 +0100 Subject: [PATCH] Update history_tree.py --- history_tree.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/history_tree.py b/history_tree.py index a22be45..c49611b 100644 --- a/history_tree.py +++ b/history_tree.py @@ -54,13 +54,17 @@ class HistoryTree: def to_dict(self): return {"nodes": self.nodes, "branches": self.branches, "head_id": self.head_id} - def generate_horizontal_graph(self): - """Generates a Compact, Readable Horizontal Graph using HTML Labels.""" + # --- UPDATED GRAPH GENERATOR --- + def generate_graph(self, direction="LR"): + """ + Generates Graphviz source. + direction: "LR" (Horizontal) or "TB" (Vertical) + """ dot = [ 'digraph History {', - ' rankdir=LR;', + f' rankdir={direction};', # Dynamic Direction ' bgcolor="white";', - ' splines=ortho;', # Clean right-angle lines + ' splines=ortho;', # TIGHT SPACING ' nodesep=0.2;', @@ -77,8 +81,6 @@ class HistoryTree: nid = n["id"] full_note = n.get('note', 'Step') - # Truncate slightly for display, but keep enough to read - # HTML Labels allow distinct styling for Title vs ID display_note = (full_note[:15] + '..') if len(full_note) > 15 else full_note # COLORS @@ -94,8 +96,7 @@ class HistoryTree: bg_color = "#e6ffe6" # Green for Tips border_color = "#66aa66" - # HTML LABEL (Table) - # This is the trick to make it compact but readable + # HTML LABEL label = ( f'<' f'' @@ -103,7 +104,6 @@ class HistoryTree: f'
{display_note}
>' ) - # Tooltip shows full text on hover safe_tooltip = full_note.replace('"', "'") dot.append(f' "{nid}" [label={label}, tooltip="{safe_tooltip}"];')