retroflow 0.4.2__tar.gz → 0.4.3__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.3}/PKG-INFO +1 -1
- {retroflow-0.4.2 → retroflow-0.4.3}/pyproject.toml +1 -1
- {retroflow-0.4.2 → retroflow-0.4.3}/src/retroflow/__init__.py +1 -1
- {retroflow-0.4.2 → retroflow-0.4.3}/src/retroflow/generator.py +118 -4
- {retroflow-0.4.2 → retroflow-0.4.3}/uv.lock +1 -1
- {retroflow-0.4.2 → retroflow-0.4.3}/.github/workflows/publish.yml +0 -0
- {retroflow-0.4.2 → retroflow-0.4.3}/.github/workflows/test.yml +0 -0
- {retroflow-0.4.2 → retroflow-0.4.3}/.gitignore +0 -0
- {retroflow-0.4.2 → retroflow-0.4.3}/.python-version +0 -0
- {retroflow-0.4.2 → retroflow-0.4.3}/CLAUDE.md +0 -0
- {retroflow-0.4.2 → retroflow-0.4.3}/LICENSE +0 -0
- {retroflow-0.4.2 → retroflow-0.4.3}/README.md +0 -0
- {retroflow-0.4.2 → retroflow-0.4.3}/codecov.yml +0 -0
- {retroflow-0.4.2 → retroflow-0.4.3}/src/retroflow/layout.py +0 -0
- {retroflow-0.4.2 → retroflow-0.4.3}/src/retroflow/parser.py +0 -0
- {retroflow-0.4.2 → retroflow-0.4.3}/src/retroflow/py.typed +0 -0
- {retroflow-0.4.2 → retroflow-0.4.3}/src/retroflow/renderer.py +0 -0
- {retroflow-0.4.2 → retroflow-0.4.3}/src/retroflow/router.py +0 -0
- {retroflow-0.4.2 → retroflow-0.4.3}/tests/conftest.py +0 -0
- {retroflow-0.4.2 → retroflow-0.4.3}/tests/integration/__init__.py +0 -0
- {retroflow-0.4.2 → retroflow-0.4.3}/tests/integration/test_flowchart_generation.py +0 -0
- {retroflow-0.4.2 → retroflow-0.4.3}/tests/unit/__init__.py +0 -0
- {retroflow-0.4.2 → retroflow-0.4.3}/tests/unit/test_coverage_extras.py +0 -0
- {retroflow-0.4.2 → retroflow-0.4.3}/tests/unit/test_generator.py +0 -0
- {retroflow-0.4.2 → retroflow-0.4.3}/tests/unit/test_layout.py +0 -0
- {retroflow-0.4.2 → retroflow-0.4.3}/tests/unit/test_parser.py +0 -0
- {retroflow-0.4.2 → retroflow-0.4.3}/tests/unit/test_renderer.py +0 -0
- {retroflow-0.4.2 → retroflow-0.4.3}/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.3
|
|
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.3"
|
|
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,8 +522,10 @@ 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]
|
|
@@ -482,7 +564,9 @@ class FlowchartGenerator:
|
|
|
482
564
|
canvas.set(tgt_port_x, tgt_port_y - 1, ARROW_CHARS["down"])
|
|
483
565
|
else:
|
|
484
566
|
# Need to route with horizontal segment
|
|
485
|
-
|
|
567
|
+
# Use layer-aware routing: place horizontal segment in the gap zone
|
|
568
|
+
# below the source layer where no boxes can exist
|
|
569
|
+
mid_y = self._get_safe_horizontal_y(layer_boundaries, src_layer, start_y)
|
|
486
570
|
|
|
487
571
|
# Vertical from source to mid
|
|
488
572
|
self._draw_vertical_line(canvas, src_port_x, start_y, mid_y - 1)
|
|
@@ -508,6 +592,36 @@ class FlowchartGenerator:
|
|
|
508
592
|
# Draw arrow one row above target box (doesn't overwrite border)
|
|
509
593
|
canvas.set(tgt_port_x, tgt_port_y - 1, ARROW_CHARS["down"])
|
|
510
594
|
|
|
595
|
+
def _get_safe_horizontal_y(
|
|
596
|
+
self,
|
|
597
|
+
layer_boundaries: List[LayerBoundary],
|
|
598
|
+
src_layer: int,
|
|
599
|
+
start_y: int,
|
|
600
|
+
) -> int:
|
|
601
|
+
"""
|
|
602
|
+
Get a safe y-coordinate for horizontal edge routing.
|
|
603
|
+
|
|
604
|
+
Places the horizontal segment in the gap zone below the source layer,
|
|
605
|
+
ensuring it doesn't pass through any boxes.
|
|
606
|
+
|
|
607
|
+
Args:
|
|
608
|
+
layer_boundaries: List of layer boundary information
|
|
609
|
+
src_layer: The layer index of the source node
|
|
610
|
+
start_y: The y-coordinate where the edge starts (below source box)
|
|
611
|
+
|
|
612
|
+
Returns:
|
|
613
|
+
A y-coordinate in the gap zone that's safe for horizontal routing
|
|
614
|
+
"""
|
|
615
|
+
if src_layer < len(layer_boundaries):
|
|
616
|
+
boundary = layer_boundaries[src_layer]
|
|
617
|
+
# Place horizontal line in the middle of the gap zone
|
|
618
|
+
gap_middle = (boundary.gap_start_y + boundary.gap_end_y) // 2
|
|
619
|
+
# Ensure we're at least at start_y (below the source shadow)
|
|
620
|
+
return max(gap_middle, start_y + 1)
|
|
621
|
+
else:
|
|
622
|
+
# Fallback: just below the start
|
|
623
|
+
return start_y + 2
|
|
624
|
+
|
|
511
625
|
def _calculate_port_x(
|
|
512
626
|
self, box_x: int, box_width: int, port_idx: int, port_count: int
|
|
513
627
|
) -> int:
|
|
@@ -622,7 +622,7 @@ wheels = [
|
|
|
622
622
|
|
|
623
623
|
[[package]]
|
|
624
624
|
name = "retroflow"
|
|
625
|
-
version = "0.4.
|
|
625
|
+
version = "0.4.2"
|
|
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
|
|
File without changes
|
|
File without changes
|