Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,20 @@ graphtty reads a simple JSON format:

## Benchmarks

graphtty uses a custom Sugiyama-style layout engine and optimized canvas operations for fast rendering. Benchmarks across all 9 sample graphs (50 iterations each, Python 3.11):
graphtty uses a custom Sugiyama-style layout engine and optimized canvas operations for fast rendering. Benchmarks across all 10 sample graphs (50 iterations each, Python 3.11):

| Sample | Avg (ms) | Ops/sec |
|---|---:|---:|
| react-agent (4 nodes) | 0.15 | 6,522 |
| deep-agent (7 nodes) | 0.31 | 3,161 |
| function-agent (8 nodes) | 0.36 | 2,806 |
| workflow-agent (11 nodes) | 0.42 | 2,370 |
| world-map (15 nodes) | 0.55 | 1,818 |
| supervisor-agent (7+subs) | 0.71 | 1,406 |
| rag-pipeline (10 nodes) | 0.74 | 1,347 |
| etl-pipeline (12 nodes) | 0.84 | 1,193 |
| code-review (8+subs) | 1.16 | 864 |
| react-agent (4 nodes) | 0.15 | 6,593 |
| book-writer-agent (6 nodes) | 0.25 | 4,083 |
| deep-agent (7 nodes) | 0.32 | 3,144 |
| function-agent (8 nodes) | 0.37 | 2,686 |
| workflow-agent (11 nodes) | 0.49 | 2,060 |
| world-map (15 nodes) | 0.61 | 1,651 |
| rag-pipeline (10 nodes) | 0.70 | 1,427 |
| supervisor-agent (7+subs) | 0.80 | 1,250 |
| etl-pipeline (12 nodes) | 0.82 | 1,225 |
| code-review (8+subs) | 1.21 | 829 |

Run `python scripts/benchmark.py` to reproduce on your machine.

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "graphtty"
version = "0.1.4"
version = "0.1.5"
description = "Turn any directed graph into colored ASCII art for your terminal"
readme = "README.md"
license = "MIT"
Expand Down
67 changes: 67 additions & 0 deletions samples/book-writer-agent/graph.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"nodes": [
{
"id": "__start__",
"name": "__start__",
"type": "__start__",
"subgraph": null
},
{
"id": "create_chapter_files",
"name": "create_chapter_files",
"type": "node",
"subgraph": null
},
{
"id": "generate_book_outline",
"name": "generate_book_outline",
"type": "node",
"subgraph": null
},
{
"id": "generate_chapters_content",
"name": "generate_chapters_content",
"type": "node",
"subgraph": null
},
{
"id": "upload_chapter_files",
"name": "upload_chapter_files",
"type": "node",
"subgraph": null
},
{
"id": "__end__",
"name": "__end__",
"type": "__end__",
"subgraph": null
}
],
"edges": [
{
"source": "create_chapter_files",
"target": "upload_chapter_files",
"label": "ChaptersFilesEvent"
},
{
"source": "__start__",
"target": "generate_book_outline",
"label": "BookRequestEvent"
},
{
"source": "generate_book_outline",
"target": "generate_chapters_content",
"label": "BookOutlineEvent"
},
{
"source": "generate_chapters_content",
"target": "create_chapter_files",
"label": "ChaptersContentEvent"
},
{
"source": "upload_chapter_files",
"target": "__end__",
"label": "BookCompleteEvent"
}
]
}
Binary file added screenshots/book-writer-agent.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/code-review.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/deep-agent.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/etl-pipeline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/function-agent.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/rag-pipeline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/react-agent.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/supervisor-agent.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/workflow-agent.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/world-map.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions scripts/generate_screenshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ def main():
"monokai",
"Function Agent (monokai)",
),
(
"samples/book-writer-agent/graph.json",
"nord",
"Book Writer Agent (nord)",
),
]

images: list[tuple[str, Image.Image]] = []
Expand Down
6 changes: 3 additions & 3 deletions src/graphtty/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def _assign_coordinates(
new_centers: dict[str, float] = {}
for nid in order:
w = node_sizes[nid][0]
ideal_x = int(desired[nid] - w / 2.0)
ideal_x = round(desired[nid]) - w // 2
x = max(ideal_x, cx)
new_x[nid] = x
new_centers[nid] = x + w / 2.0
Expand Down Expand Up @@ -346,7 +346,7 @@ def _assign_coordinates(
continue
desired_center = sum(child_cx) / len(child_cx)
w = node_sizes[nid][0]
x = max(int(desired_center - w / 2.0), 0)
x = max(round(desired_center) - w // 2, 0)
layer_x[li] = {nid: x}
layer_centers[li] = {nid: x + w / 2.0}

Expand All @@ -363,7 +363,7 @@ def _assign_coordinates(
continue
desired_center = sum(parent_cx) / len(parent_cx)
w = node_sizes[nid][0]
x = max(int(desired_center - w / 2.0), 0)
x = max(round(desired_center) - w // 2, 0)
layer_x[li] = {nid: x}
layer_centers[li] = {nid: x + w / 2.0}

Expand Down
22 changes: 21 additions & 1 deletion src/graphtty/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,27 @@ def _do_render_canvas(
)
corridor_map.update(fwd_map)
extra_right = max(extra_right, fwd_extra)
max_x = max(b.x + b.w for b in boxes.values()) + extra_right + options.padding
# Account for edge labels that extend past the rightmost box
label_max_x = 0
for edge in graph.edges:
if not edge.label:
continue
src_box = boxes.get(edge.source)
tgt_box = boxes.get(edge.target)
if src_box is None or tgt_box is None:
continue
# Straight forward edges: label at tgt_cx + 2
if src_box.bottom < tgt_box.top:
cx = (
tgt_box.cx
if abs(src_box.cx - tgt_box.cx) <= _STRAIGHT_TOLERANCE
else (src_box.cx + tgt_box.cx) // 2
)
label_right = cx + 2 + len(edge.label)
if label_right > label_max_x:
label_max_x = label_right
box_max_x = max(b.x + b.w for b in boxes.values())
max_x = max(box_max_x + extra_right, label_max_x) + options.padding
max_y = max(b.y + b.h for b in boxes.values()) + options.padding
canvas = Canvas(max_x, max_y)

Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.