Spaces:
Sleeping
Sleeping
Create lineage_visualizer.py
Browse files- lineage_visualizer.py +26 -0
lineage_visualizer.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Author: Liam Grinstead
|
| 2 |
+
# Renders agent lineage as an SVG tree diagram
|
| 3 |
+
|
| 4 |
+
from lineage_tracker import LINEAGE
|
| 5 |
+
|
| 6 |
+
def render_lineage(agent_id):
|
| 7 |
+
children = LINEAGE.get(agent_id, [])
|
| 8 |
+
if not children:
|
| 9 |
+
return f"<svg width='400' height='100'><text x='10' y='50'>No lineage for {agent_id}</text></svg>"
|
| 10 |
+
|
| 11 |
+
svg = "<svg width='600' height='400'>"
|
| 12 |
+
svg += f"<text x='10' y='30' font-size='16'>Lineage of {agent_id}</text>"
|
| 13 |
+
svg += f"<circle cx='300' cy='60' r='20' fill='purple'/>"
|
| 14 |
+
svg += f"<text x='280' y='100' font-size='12'>{agent_id}</text>"
|
| 15 |
+
|
| 16 |
+
y_offset = 160
|
| 17 |
+
x_step = 120
|
| 18 |
+
for i, child in enumerate(children):
|
| 19 |
+
x_pos = 100 + i * x_step
|
| 20 |
+
svg += f"<line x1='300' y1='80' x2='{x_pos}' y2='{y_offset-20}' stroke='black'/>"
|
| 21 |
+
svg += f"<circle cx='{x_pos}' cy='{y_offset}' r='15' fill='green'>"
|
| 22 |
+
svg += "<animate attributeName='r' values='15;20;15' dur='2s' repeatCount='indefinite'/>"
|
| 23 |
+
svg += "</circle>"
|
| 24 |
+
svg += f"<text x='{x_pos-20}' y='{y_offset+40}' font-size='12'>{child['child_id']}</text>"
|
| 25 |
+
svg += "</svg>"
|
| 26 |
+
return svg
|