retroflow 0.4.2__tar.gz → 0.4.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {retroflow-0.4.2 → retroflow-0.4.4}/PKG-INFO +1 -1
- {retroflow-0.4.2 → retroflow-0.4.4}/pyproject.toml +1 -1
- {retroflow-0.4.2 → retroflow-0.4.4}/src/retroflow/__init__.py +1 -1
- {retroflow-0.4.2 → retroflow-0.4.4}/src/retroflow/generator.py +180 -18
- {retroflow-0.4.2 → retroflow-0.4.4}/src/retroflow/renderer.py +5 -6
- {retroflow-0.4.2 → retroflow-0.4.4}/tests/unit/test_renderer.py +2 -2
- {retroflow-0.4.2 → retroflow-0.4.4}/uv.lock +1 -1
- {retroflow-0.4.2 → retroflow-0.4.4}/.github/workflows/publish.yml +0 -0
- {retroflow-0.4.2 → retroflow-0.4.4}/.github/workflows/test.yml +0 -0
- {retroflow-0.4.2 → retroflow-0.4.4}/.gitignore +0 -0
- {retroflow-0.4.2 → retroflow-0.4.4}/.python-version +0 -0
- {retroflow-0.4.2 → retroflow-0.4.4}/CLAUDE.md +0 -0
- {retroflow-0.4.2 → retroflow-0.4.4}/LICENSE +0 -0
- {retroflow-0.4.2 → retroflow-0.4.4}/README.md +0 -0
- {retroflow-0.4.2 → retroflow-0.4.4}/codecov.yml +0 -0
- {retroflow-0.4.2 → retroflow-0.4.4}/src/retroflow/layout.py +0 -0
- {retroflow-0.4.2 → retroflow-0.4.4}/src/retroflow/parser.py +0 -0
- {retroflow-0.4.2 → retroflow-0.4.4}/src/retroflow/py.typed +0 -0
- {retroflow-0.4.2 → retroflow-0.4.4}/src/retroflow/router.py +0 -0
- {retroflow-0.4.2 → retroflow-0.4.4}/tests/conftest.py +0 -0
- {retroflow-0.4.2 → retroflow-0.4.4}/tests/integration/__init__.py +0 -0
- {retroflow-0.4.2 → retroflow-0.4.4}/tests/integration/test_flowchart_generation.py +0 -0
- {retroflow-0.4.2 → retroflow-0.4.4}/tests/unit/__init__.py +0 -0
- {retroflow-0.4.2 → retroflow-0.4.4}/tests/unit/test_coverage_extras.py +0 -0
- {retroflow-0.4.2 → retroflow-0.4.4}/tests/unit/test_generator.py +0 -0
- {retroflow-0.4.2 → retroflow-0.4.4}/tests/unit/test_layout.py +0 -0
- {retroflow-0.4.2 → retroflow-0.4.4}/tests/unit/test_parser.py +0 -0
- {retroflow-0.4.2 → retroflow-0.4.4}/tests/unit/test_router.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: retroflow
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.4
|
|
4
4
|
Summary: Generate beautiful ASCII and PNG flowcharts from simple text descriptions
|
|
5
5
|
Project-URL: Homepage, https://github.com/ronikobrosly/retroflow
|
|
6
6
|
Project-URL: Repository, https://github.com/ronikobrosly/retroflow
|
|
@@ -19,7 +19,7 @@ from .parser import ParseError, Parser, parse_flowchart
|
|
|
19
19
|
from .renderer import BoxRenderer, Canvas, LineRenderer
|
|
20
20
|
from .router import BoxInfo, EdgeRoute, EdgeRouter
|
|
21
21
|
|
|
22
|
-
__version__ = "0.4.
|
|
22
|
+
__version__ = "0.4.4"
|
|
23
23
|
|
|
24
24
|
__all__ = [
|
|
25
25
|
"FlowchartGenerator",
|
|
@@ -5,6 +5,7 @@ Combines parsing, layout, and rendering to produce
|
|
|
5
5
|
beautiful ASCII flowcharts.
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
|
+
from dataclasses import dataclass
|
|
8
9
|
from pathlib import Path
|
|
9
10
|
from typing import Dict, List, Optional, Tuple
|
|
10
11
|
|
|
@@ -22,6 +23,17 @@ from .renderer import (
|
|
|
22
23
|
)
|
|
23
24
|
|
|
24
25
|
|
|
26
|
+
@dataclass
|
|
27
|
+
class LayerBoundary:
|
|
28
|
+
"""Boundary information for a layer."""
|
|
29
|
+
|
|
30
|
+
layer_idx: int
|
|
31
|
+
top_y: int # Top of layer (where boxes start)
|
|
32
|
+
bottom_y: int # Bottom of layer (including shadow)
|
|
33
|
+
gap_start_y: int # Start of gap below this layer
|
|
34
|
+
gap_end_y: int # End of gap (start of next layer)
|
|
35
|
+
|
|
36
|
+
|
|
25
37
|
class FlowchartGenerator:
|
|
26
38
|
"""
|
|
27
39
|
Generate ASCII flowcharts from simple text descriptions.
|
|
@@ -91,6 +103,11 @@ class FlowchartGenerator:
|
|
|
91
103
|
layout_result, box_dimensions, left_margin=back_edge_margin
|
|
92
104
|
)
|
|
93
105
|
|
|
106
|
+
# Calculate layer boundaries for safe edge routing
|
|
107
|
+
layer_boundaries = self._calculate_layer_boundaries(
|
|
108
|
+
layout_result, box_dimensions
|
|
109
|
+
)
|
|
110
|
+
|
|
94
111
|
# Calculate canvas size
|
|
95
112
|
canvas_width, canvas_height = self._calculate_canvas_size(
|
|
96
113
|
box_dimensions, box_positions
|
|
@@ -102,8 +119,10 @@ class FlowchartGenerator:
|
|
|
102
119
|
# Draw boxes first
|
|
103
120
|
self._draw_boxes(canvas, box_dimensions, box_positions, layout_result)
|
|
104
121
|
|
|
105
|
-
# Draw forward edges
|
|
106
|
-
self._draw_edges(
|
|
122
|
+
# Draw forward edges with layer-aware routing
|
|
123
|
+
self._draw_edges(
|
|
124
|
+
canvas, layout_result, box_dimensions, box_positions, layer_boundaries
|
|
125
|
+
)
|
|
107
126
|
|
|
108
127
|
# Draw back edges along the left margin
|
|
109
128
|
if layout_result.back_edges:
|
|
@@ -339,6 +358,64 @@ class FlowchartGenerator:
|
|
|
339
358
|
|
|
340
359
|
return positions
|
|
341
360
|
|
|
361
|
+
def _calculate_layer_boundaries(
|
|
362
|
+
self,
|
|
363
|
+
layout_result: LayoutResult,
|
|
364
|
+
box_dimensions: Dict[str, BoxDimensions],
|
|
365
|
+
) -> List[LayerBoundary]:
|
|
366
|
+
"""
|
|
367
|
+
Calculate the y-boundaries for each layer.
|
|
368
|
+
|
|
369
|
+
This information is used for safe edge routing - horizontal segments
|
|
370
|
+
should be placed in the gaps between layers where no boxes exist.
|
|
371
|
+
|
|
372
|
+
Returns:
|
|
373
|
+
List of LayerBoundary objects, one per layer
|
|
374
|
+
"""
|
|
375
|
+
boundaries: List[LayerBoundary] = []
|
|
376
|
+
|
|
377
|
+
# Calculate layer heights (same logic as _calculate_positions)
|
|
378
|
+
layer_heights: List[int] = []
|
|
379
|
+
for layer in layout_result.layers:
|
|
380
|
+
max_height = 0
|
|
381
|
+
for node_name in layer:
|
|
382
|
+
dims = box_dimensions[node_name]
|
|
383
|
+
box_height = dims.height + (2 if self.shadow else 0)
|
|
384
|
+
max_height = max(max_height, box_height)
|
|
385
|
+
layer_heights.append(max_height)
|
|
386
|
+
|
|
387
|
+
# Calculate y positions for each layer
|
|
388
|
+
y_positions: List[int] = [0]
|
|
389
|
+
for height in layer_heights[:-1]:
|
|
390
|
+
y_positions.append(y_positions[-1] + height + self.vertical_spacing)
|
|
391
|
+
|
|
392
|
+
# Build boundary objects
|
|
393
|
+
num_layers = len(layout_result.layers)
|
|
394
|
+
for i in range(num_layers):
|
|
395
|
+
top_y = y_positions[i]
|
|
396
|
+
bottom_y = top_y + layer_heights[i] - 1 # -1 because it's inclusive
|
|
397
|
+
|
|
398
|
+
# Gap starts after the shadow (bottom_y is already inclusive of shadow)
|
|
399
|
+
gap_start_y = top_y + layer_heights[i]
|
|
400
|
+
|
|
401
|
+
# Gap ends at the start of the next layer (or canvas edge)
|
|
402
|
+
if i < num_layers - 1:
|
|
403
|
+
gap_end_y = y_positions[i + 1] - 1
|
|
404
|
+
else:
|
|
405
|
+
gap_end_y = gap_start_y + self.vertical_spacing # Last layer
|
|
406
|
+
|
|
407
|
+
boundaries.append(
|
|
408
|
+
LayerBoundary(
|
|
409
|
+
layer_idx=i,
|
|
410
|
+
top_y=top_y,
|
|
411
|
+
bottom_y=bottom_y,
|
|
412
|
+
gap_start_y=gap_start_y,
|
|
413
|
+
gap_end_y=gap_end_y,
|
|
414
|
+
)
|
|
415
|
+
)
|
|
416
|
+
|
|
417
|
+
return boundaries
|
|
418
|
+
|
|
342
419
|
def _calculate_canvas_size(
|
|
343
420
|
self,
|
|
344
421
|
box_dimensions: Dict[str, BoxDimensions],
|
|
@@ -376,6 +453,7 @@ class FlowchartGenerator:
|
|
|
376
453
|
layout_result: LayoutResult,
|
|
377
454
|
box_dimensions: Dict[str, BoxDimensions],
|
|
378
455
|
box_positions: Dict[str, Tuple[int, int]],
|
|
456
|
+
layer_boundaries: List[LayerBoundary],
|
|
379
457
|
) -> None:
|
|
380
458
|
"""Draw all forward edges on the canvas (skip back edges)."""
|
|
381
459
|
|
|
@@ -431,6 +509,8 @@ class FlowchartGenerator:
|
|
|
431
509
|
box_positions,
|
|
432
510
|
edges_from.get(source, []),
|
|
433
511
|
edges_to.get(target, []),
|
|
512
|
+
layer_boundaries,
|
|
513
|
+
src_layer,
|
|
434
514
|
)
|
|
435
515
|
|
|
436
516
|
def _draw_edge(
|
|
@@ -442,28 +522,78 @@ class FlowchartGenerator:
|
|
|
442
522
|
box_positions: Dict[str, Tuple[int, int]],
|
|
443
523
|
source_targets: List[str],
|
|
444
524
|
target_sources: List[str],
|
|
525
|
+
layer_boundaries: List[LayerBoundary],
|
|
526
|
+
src_layer: int,
|
|
445
527
|
) -> None:
|
|
446
|
-
"""Draw a single edge from source to target."""
|
|
528
|
+
"""Draw a single edge from source to target with layer-aware routing."""
|
|
447
529
|
src_dims = box_dimensions[source]
|
|
448
530
|
tgt_dims = box_dimensions[target]
|
|
449
531
|
src_x, src_y = box_positions[source]
|
|
450
532
|
tgt_x, tgt_y = box_positions[target]
|
|
451
533
|
|
|
452
|
-
#
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
)
|
|
459
|
-
|
|
534
|
+
# Check if boxes overlap horizontally (inside borders)
|
|
535
|
+
src_left = src_x + 1
|
|
536
|
+
src_right = src_x + src_dims.width - 2
|
|
537
|
+
tgt_left = tgt_x + 1
|
|
538
|
+
tgt_right = tgt_x + tgt_dims.width - 2
|
|
539
|
+
|
|
540
|
+
overlap_left = max(src_left, tgt_left)
|
|
541
|
+
overlap_right = min(src_right, tgt_right)
|
|
542
|
+
has_overlap = overlap_left < overlap_right
|
|
543
|
+
|
|
544
|
+
if has_overlap:
|
|
545
|
+
# Boxes overlap - find which targets from this source also overlap
|
|
546
|
+
overlapping_targets = []
|
|
547
|
+
for t in source_targets:
|
|
548
|
+
t_dims = box_dimensions[t]
|
|
549
|
+
t_x, _ = box_positions[t]
|
|
550
|
+
t_left = t_x + 1
|
|
551
|
+
t_right = t_x + t_dims.width - 2
|
|
552
|
+
t_overlap_left = max(src_left, t_left)
|
|
553
|
+
t_overlap_right = min(src_right, t_right)
|
|
554
|
+
if t_overlap_left < t_overlap_right:
|
|
555
|
+
overlapping_targets.append(t)
|
|
556
|
+
|
|
557
|
+
# Distribute ports within the overlap region for overlapping targets
|
|
558
|
+
overlap_width = overlap_right - overlap_left
|
|
559
|
+
overlap_count = len(overlapping_targets)
|
|
560
|
+
overlap_idx = overlapping_targets.index(target)
|
|
561
|
+
|
|
562
|
+
if overlap_count == 1:
|
|
563
|
+
# Single overlapping target - use center of overlap
|
|
564
|
+
port_x = (overlap_left + overlap_right) // 2
|
|
565
|
+
else:
|
|
566
|
+
# Multiple overlapping targets - distribute within overlap
|
|
567
|
+
if overlap_width >= overlap_count * 2:
|
|
568
|
+
# Enough space to distribute
|
|
569
|
+
spacing = overlap_width // (overlap_count + 1)
|
|
570
|
+
port_x = overlap_left + spacing * (overlap_idx + 1)
|
|
571
|
+
else:
|
|
572
|
+
# Tight space - just use center offset slightly
|
|
573
|
+
port_x = overlap_left + (overlap_width * (overlap_idx + 1)) // (
|
|
574
|
+
overlap_count + 1
|
|
575
|
+
)
|
|
576
|
+
|
|
577
|
+
# Use same x for both source and target (straight line)
|
|
578
|
+
src_port_x = port_x
|
|
579
|
+
tgt_port_x = port_x
|
|
580
|
+
else:
|
|
581
|
+
# No horizontal overlap - use distributed ports
|
|
582
|
+
# Source: exit from bottom
|
|
583
|
+
src_port_count = len(source_targets)
|
|
584
|
+
src_port_idx = source_targets.index(target)
|
|
585
|
+
src_port_x = self._calculate_port_x(
|
|
586
|
+
src_x, src_dims.width, src_port_idx, src_port_count
|
|
587
|
+
)
|
|
460
588
|
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
589
|
+
# Target: enter from top
|
|
590
|
+
tgt_port_count = len(target_sources)
|
|
591
|
+
tgt_port_idx = target_sources.index(source)
|
|
592
|
+
tgt_port_x = self._calculate_port_x(
|
|
593
|
+
tgt_x, tgt_dims.width, tgt_port_idx, tgt_port_count
|
|
594
|
+
)
|
|
595
|
+
|
|
596
|
+
src_port_y = src_y + src_dims.height - 1 # Bottom border
|
|
467
597
|
tgt_port_y = tgt_y # Top border
|
|
468
598
|
|
|
469
599
|
# Modify source bottom border to show exit point (tee down)
|
|
@@ -482,7 +612,9 @@ class FlowchartGenerator:
|
|
|
482
612
|
canvas.set(tgt_port_x, tgt_port_y - 1, ARROW_CHARS["down"])
|
|
483
613
|
else:
|
|
484
614
|
# Need to route with horizontal segment
|
|
485
|
-
|
|
615
|
+
# Use layer-aware routing: place horizontal segment in the gap zone
|
|
616
|
+
# below the source layer where no boxes can exist
|
|
617
|
+
mid_y = self._get_safe_horizontal_y(layer_boundaries, src_layer, start_y)
|
|
486
618
|
|
|
487
619
|
# Vertical from source to mid
|
|
488
620
|
self._draw_vertical_line(canvas, src_port_x, start_y, mid_y - 1)
|
|
@@ -508,6 +640,36 @@ class FlowchartGenerator:
|
|
|
508
640
|
# Draw arrow one row above target box (doesn't overwrite border)
|
|
509
641
|
canvas.set(tgt_port_x, tgt_port_y - 1, ARROW_CHARS["down"])
|
|
510
642
|
|
|
643
|
+
def _get_safe_horizontal_y(
|
|
644
|
+
self,
|
|
645
|
+
layer_boundaries: List[LayerBoundary],
|
|
646
|
+
src_layer: int,
|
|
647
|
+
start_y: int,
|
|
648
|
+
) -> int:
|
|
649
|
+
"""
|
|
650
|
+
Get a safe y-coordinate for horizontal edge routing.
|
|
651
|
+
|
|
652
|
+
Places the horizontal segment in the gap zone below the source layer,
|
|
653
|
+
ensuring it doesn't pass through any boxes.
|
|
654
|
+
|
|
655
|
+
Args:
|
|
656
|
+
layer_boundaries: List of layer boundary information
|
|
657
|
+
src_layer: The layer index of the source node
|
|
658
|
+
start_y: The y-coordinate where the edge starts (below source box)
|
|
659
|
+
|
|
660
|
+
Returns:
|
|
661
|
+
A y-coordinate in the gap zone that's safe for horizontal routing
|
|
662
|
+
"""
|
|
663
|
+
if src_layer < len(layer_boundaries):
|
|
664
|
+
boundary = layer_boundaries[src_layer]
|
|
665
|
+
# Place horizontal line in the middle of the gap zone
|
|
666
|
+
gap_middle = (boundary.gap_start_y + boundary.gap_end_y) // 2
|
|
667
|
+
# Ensure we're at least at start_y (below the source shadow)
|
|
668
|
+
return max(gap_middle, start_y + 1)
|
|
669
|
+
else:
|
|
670
|
+
# Fallback: just below the start
|
|
671
|
+
return start_y + 2
|
|
672
|
+
|
|
511
673
|
def _calculate_port_x(
|
|
512
674
|
self, box_x: int, box_width: int, port_idx: int, port_count: int
|
|
513
675
|
) -> int:
|
|
@@ -100,7 +100,7 @@ class BoxRenderer:
|
|
|
100
100
|
Renders boxes with shadows and wrapped text.
|
|
101
101
|
"""
|
|
102
102
|
|
|
103
|
-
def __init__(self, max_text_width: int = 20, padding: int =
|
|
103
|
+
def __init__(self, max_text_width: int = 20, padding: int = 2, shadow: bool = True):
|
|
104
104
|
self.max_text_width = max_text_width
|
|
105
105
|
self.padding = padding
|
|
106
106
|
self.shadow = shadow
|
|
@@ -141,9 +141,8 @@ class BoxRenderer:
|
|
|
141
141
|
# Box width = text_width + 2*padding + 2 (for borders)
|
|
142
142
|
box_width = text_width + 2 * self.padding + 2
|
|
143
143
|
|
|
144
|
-
# Box height = num_lines + 2
|
|
145
|
-
|
|
146
|
-
box_height = len(lines) + 2 # Just borders, no vertical padding
|
|
144
|
+
# Box height = num_lines + 2 (for borders) + 2 (for vertical padding)
|
|
145
|
+
box_height = len(lines) + 4
|
|
147
146
|
|
|
148
147
|
return BoxDimensions(
|
|
149
148
|
width=box_width, height=box_height, text_lines=lines, padding=self.padding
|
|
@@ -194,9 +193,9 @@ class BoxRenderer:
|
|
|
194
193
|
for i in range(1, w + 1):
|
|
195
194
|
canvas.set(x + i, y + h, BOX_CHARS["shadow"])
|
|
196
195
|
|
|
197
|
-
# Draw text (centered)
|
|
196
|
+
# Draw text (centered, with 1 line vertical padding)
|
|
198
197
|
for line_idx, line in enumerate(dimensions.text_lines):
|
|
199
|
-
text_y = y +
|
|
198
|
+
text_y = y + 2 + line_idx
|
|
200
199
|
# Center the text within the box
|
|
201
200
|
available_width = w - 2 # Minus borders
|
|
202
201
|
text_x = x + 1 + (available_width - len(line)) // 2
|
|
@@ -116,7 +116,7 @@ class TestBoxRenderer:
|
|
|
116
116
|
"""Test BoxRenderer creation with defaults."""
|
|
117
117
|
br = BoxRenderer()
|
|
118
118
|
assert br.max_text_width == 20
|
|
119
|
-
assert br.padding ==
|
|
119
|
+
assert br.padding == 2
|
|
120
120
|
assert br.shadow is True
|
|
121
121
|
|
|
122
122
|
def test_box_renderer_custom_params(self):
|
|
@@ -130,7 +130,7 @@ class TestBoxRenderer:
|
|
|
130
130
|
"""Test box dimensions for short text."""
|
|
131
131
|
dims = box_renderer.calculate_box_dimensions("Hi")
|
|
132
132
|
assert dims.text_lines == ["Hi"]
|
|
133
|
-
assert dims.height ==
|
|
133
|
+
assert dims.height == 5 # 1 text line + 2 borders + 2 vertical padding
|
|
134
134
|
|
|
135
135
|
def test_calculate_box_dimensions_longer_text(self, box_renderer):
|
|
136
136
|
"""Test box dimensions for longer text that wraps."""
|
|
@@ -622,7 +622,7 @@ wheels = [
|
|
|
622
622
|
|
|
623
623
|
[[package]]
|
|
624
624
|
name = "retroflow"
|
|
625
|
-
version = "0.4.
|
|
625
|
+
version = "0.4.3"
|
|
626
626
|
source = { editable = "." }
|
|
627
627
|
dependencies = [
|
|
628
628
|
{ name = "networkx", version = "3.2.1", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.10'" },
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|