frameplot 0.5.3__tar.gz → 0.5.6__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.
- {frameplot-0.5.3/src/frameplot.egg-info → frameplot-0.5.6}/PKG-INFO +8 -1
- {frameplot-0.5.3 → frameplot-0.5.6}/README.md +7 -0
- {frameplot-0.5.3 → frameplot-0.5.6}/pyproject.toml +1 -1
- {frameplot-0.5.3 → frameplot-0.5.6}/src/frameplot/api.py +6 -2
- {frameplot-0.5.3 → frameplot-0.5.6}/src/frameplot/layout/order.py +0 -123
- {frameplot-0.5.3 → frameplot-0.5.6}/src/frameplot/layout/route.py +39 -3
- {frameplot-0.5.3 → frameplot-0.5.6}/src/frameplot/layout/text.py +14 -8
- {frameplot-0.5.3 → frameplot-0.5.6}/src/frameplot/model.py +8 -5
- {frameplot-0.5.3 → frameplot-0.5.6}/src/frameplot/render/svg.py +93 -23
- {frameplot-0.5.3 → frameplot-0.5.6/src/frameplot.egg-info}/PKG-INFO +8 -1
- {frameplot-0.5.3 → frameplot-0.5.6}/tests/test_rendering.py +103 -9
- {frameplot-0.5.3 → frameplot-0.5.6}/LICENSE +0 -0
- {frameplot-0.5.3 → frameplot-0.5.6}/setup.cfg +0 -0
- {frameplot-0.5.3 → frameplot-0.5.6}/src/frameplot/__init__.py +0 -0
- {frameplot-0.5.3 → frameplot-0.5.6}/src/frameplot/layout/__init__.py +0 -0
- {frameplot-0.5.3 → frameplot-0.5.6}/src/frameplot/layout/place.py +0 -0
- {frameplot-0.5.3 → frameplot-0.5.6}/src/frameplot/layout/rank.py +0 -0
- {frameplot-0.5.3 → frameplot-0.5.6}/src/frameplot/layout/scc.py +0 -0
- {frameplot-0.5.3 → frameplot-0.5.6}/src/frameplot/layout/types.py +0 -0
- {frameplot-0.5.3 → frameplot-0.5.6}/src/frameplot/layout/validate.py +0 -0
- {frameplot-0.5.3 → frameplot-0.5.6}/src/frameplot/render/__init__.py +0 -0
- {frameplot-0.5.3 → frameplot-0.5.6}/src/frameplot/render/png.py +0 -0
- {frameplot-0.5.3 → frameplot-0.5.6}/src/frameplot/theme.py +0 -0
- {frameplot-0.5.3 → frameplot-0.5.6}/src/frameplot.egg-info/SOURCES.txt +0 -0
- {frameplot-0.5.3 → frameplot-0.5.6}/src/frameplot.egg-info/dependency_links.txt +0 -0
- {frameplot-0.5.3 → frameplot-0.5.6}/src/frameplot.egg-info/requires.txt +0 -0
- {frameplot-0.5.3 → frameplot-0.5.6}/src/frameplot.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: frameplot
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.6
|
|
4
4
|
Summary: Turn Python-defined pipeline graphs into presentation-ready SVG and PNG diagrams.
|
|
5
5
|
Author: Small Turtle 2
|
|
6
6
|
License-Expression: MIT
|
|
@@ -147,6 +147,12 @@ Top-level imports are the supported public API:
|
|
|
147
147
|
- `to_png_bytes(scale=4.0) -> bytes`
|
|
148
148
|
- `save_png(path, scale=4.0) -> None`
|
|
149
149
|
|
|
150
|
+
## Modeling Guidance
|
|
151
|
+
|
|
152
|
+
- Keep the main graph at one abstraction level. Frameplot lays the pipeline out as a dependency-driven left-to-right graph, not as a freeform block diagram.
|
|
153
|
+
- Use `DetailPanel` for repeated block internals or per-stage mechanics that would otherwise create long-range edges in the main graph.
|
|
154
|
+
- Use `Group` to highlight nearby related nodes, not to force distant nodes to stay together. Groups are visual overlays and routing obstacles, so very wide groups can increase route detours.
|
|
155
|
+
|
|
150
156
|
## Advanced Example: Multi-cloud Data Pipeline
|
|
151
157
|
|
|
152
158
|
The hero image at the top and the theme gallery above are generated from [`examples/theme_heroes.py`](https://github.com/smturtle2/frameplot/blob/main/examples/theme_heroes.py), using the shared pipeline definition in [`examples/hero_pipeline.py`](https://github.com/smturtle2/frameplot/blob/main/examples/hero_pipeline.py). Together they showcase:
|
|
@@ -161,6 +167,7 @@ The hero image at the top and the theme gallery above are generated from [`examp
|
|
|
161
167
|
- Edge labels are not supported yet, but edge-to-edge joins can render optional `+` / `x` badges.
|
|
162
168
|
- Groups stay visual overlays, and routes leaving or re-entering grouped nodes bend outside grouped areas.
|
|
163
169
|
- Detail panels render as separate lower insets attached to a focus node in the main flow.
|
|
170
|
+
- If a sample looks stretched or routes far outside the intended block, the graph usually mixes stage-level flow with internal logic in one plane; move the internals into a `DetailPanel`.
|
|
164
171
|
|
|
165
172
|
## Development
|
|
166
173
|
|
|
@@ -118,6 +118,12 @@ Top-level imports are the supported public API:
|
|
|
118
118
|
- `to_png_bytes(scale=4.0) -> bytes`
|
|
119
119
|
- `save_png(path, scale=4.0) -> None`
|
|
120
120
|
|
|
121
|
+
## Modeling Guidance
|
|
122
|
+
|
|
123
|
+
- Keep the main graph at one abstraction level. Frameplot lays the pipeline out as a dependency-driven left-to-right graph, not as a freeform block diagram.
|
|
124
|
+
- Use `DetailPanel` for repeated block internals or per-stage mechanics that would otherwise create long-range edges in the main graph.
|
|
125
|
+
- Use `Group` to highlight nearby related nodes, not to force distant nodes to stay together. Groups are visual overlays and routing obstacles, so very wide groups can increase route detours.
|
|
126
|
+
|
|
121
127
|
## Advanced Example: Multi-cloud Data Pipeline
|
|
122
128
|
|
|
123
129
|
The hero image at the top and the theme gallery above are generated from [`examples/theme_heroes.py`](https://github.com/smturtle2/frameplot/blob/main/examples/theme_heroes.py), using the shared pipeline definition in [`examples/hero_pipeline.py`](https://github.com/smturtle2/frameplot/blob/main/examples/hero_pipeline.py). Together they showcase:
|
|
@@ -132,6 +138,7 @@ The hero image at the top and the theme gallery above are generated from [`examp
|
|
|
132
138
|
- Edge labels are not supported yet, but edge-to-edge joins can render optional `+` / `x` badges.
|
|
133
139
|
- Groups stay visual overlays, and routes leaving or re-entering grouped nodes bend outside grouped areas.
|
|
134
140
|
- Detail panels render as separate lower insets attached to a focus node in the main flow.
|
|
141
|
+
- If a sample looks stretched or routes far outside the intended block, the graph usually mixes stage-level flow with internal logic in one plane; move the internals into a `DetailPanel`.
|
|
135
142
|
|
|
136
143
|
## Development
|
|
137
144
|
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "frameplot"
|
|
7
|
-
version = "0.5.
|
|
7
|
+
version = "0.5.6"
|
|
8
8
|
description = "Turn Python-defined pipeline graphs into presentation-ready SVG and PNG diagrams."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.11"
|
|
@@ -19,8 +19,12 @@ class Pipeline:
|
|
|
19
19
|
"""Describe and render a pipeline diagram.
|
|
20
20
|
|
|
21
21
|
The constructor accepts any iterable of nodes, edges, and groups, then
|
|
22
|
-
normalizes them to tuples for deterministic rendering.
|
|
23
|
-
|
|
22
|
+
normalizes them to tuples for deterministic rendering. The main graph uses
|
|
23
|
+
dependency-driven left-to-right auto-layout, so it works best when kept to
|
|
24
|
+
one abstraction level. If stage flow and internal mechanics are mixed into
|
|
25
|
+
the same graph, ranks can stretch and routes can become unexpectedly long;
|
|
26
|
+
move those internals into a :class:`DetailPanel` instead. Passing
|
|
27
|
+
`theme=None` uses the default :class:`Theme`.
|
|
24
28
|
"""
|
|
25
29
|
|
|
26
30
|
nodes: tuple[Node, ...]
|
|
@@ -33,9 +33,6 @@ def order_nodes(
|
|
|
33
33
|
_resort_rank(nodes_by_rank[rank], outgoing, order, validated)
|
|
34
34
|
_refresh_order(nodes_by_rank[rank], order)
|
|
35
35
|
|
|
36
|
-
if isinstance(validated, ValidatedDetailPanel):
|
|
37
|
-
_apply_detail_panel_shared_source_lanes(validated, ranks, order)
|
|
38
|
-
|
|
39
36
|
if isinstance(validated, ValidatedPipeline) and validated.detail_panel is not None:
|
|
40
37
|
_apply_detail_panel_bias(validated, nodes_by_rank, ranks, order)
|
|
41
38
|
|
|
@@ -120,126 +117,6 @@ def _apply_detail_panel_bias(
|
|
|
120
117
|
for index, node_id in enumerate(rank_focus_nodes):
|
|
121
118
|
order[node_id] = start_row + index
|
|
122
119
|
|
|
123
|
-
|
|
124
|
-
def _apply_detail_panel_shared_source_lanes(
|
|
125
|
-
validated: ValidatedDetailPanel,
|
|
126
|
-
ranks: dict[str, int],
|
|
127
|
-
order: dict[str, int],
|
|
128
|
-
) -> None:
|
|
129
|
-
group_membership = _group_membership(validated)
|
|
130
|
-
components = _weak_components(validated)
|
|
131
|
-
incoming, outgoing = _forward_neighbors(validated, ranks)
|
|
132
|
-
|
|
133
|
-
for component_nodes in components:
|
|
134
|
-
component_set = set(component_nodes)
|
|
135
|
-
shared_sources = [
|
|
136
|
-
node_id
|
|
137
|
-
for node_id in component_nodes
|
|
138
|
-
if _is_detail_panel_shared_source(
|
|
139
|
-
node_id,
|
|
140
|
-
component_set,
|
|
141
|
-
group_membership,
|
|
142
|
-
incoming,
|
|
143
|
-
outgoing,
|
|
144
|
-
order,
|
|
145
|
-
)
|
|
146
|
-
]
|
|
147
|
-
if not shared_sources:
|
|
148
|
-
continue
|
|
149
|
-
|
|
150
|
-
shared_sources.sort(key=lambda node_id: (order[node_id], validated.node_index[node_id], node_id))
|
|
151
|
-
shared_source_ids = set(shared_sources)
|
|
152
|
-
nonshared_rows = _reorder_component_nodes(
|
|
153
|
-
validated,
|
|
154
|
-
ranks,
|
|
155
|
-
component_set - shared_source_ids,
|
|
156
|
-
)
|
|
157
|
-
|
|
158
|
-
for index, node_id in enumerate(shared_sources):
|
|
159
|
-
order[node_id] = index
|
|
160
|
-
for node_id, row in nonshared_rows.items():
|
|
161
|
-
order[node_id] = row + len(shared_sources)
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
def _is_detail_panel_shared_source(
|
|
165
|
-
node_id: str,
|
|
166
|
-
component_nodes: set[str],
|
|
167
|
-
group_membership: dict[str, tuple[str, ...]],
|
|
168
|
-
incoming: dict[str, list[str]],
|
|
169
|
-
outgoing: dict[str, list[str]],
|
|
170
|
-
order: dict[str, int],
|
|
171
|
-
) -> bool:
|
|
172
|
-
if group_membership.get(node_id):
|
|
173
|
-
return False
|
|
174
|
-
if incoming.get(node_id):
|
|
175
|
-
return False
|
|
176
|
-
|
|
177
|
-
targets = [target_id for target_id in outgoing.get(node_id, ()) if target_id in component_nodes]
|
|
178
|
-
if len(set(targets)) < 2:
|
|
179
|
-
return False
|
|
180
|
-
|
|
181
|
-
downstream_lanes = {
|
|
182
|
-
(
|
|
183
|
-
order[target_id],
|
|
184
|
-
group_membership.get(target_id, ()),
|
|
185
|
-
)
|
|
186
|
-
for target_id in targets
|
|
187
|
-
}
|
|
188
|
-
return len(downstream_lanes) >= 2
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
def _group_membership(
|
|
192
|
-
validated: ValidatedPipeline | ValidatedDetailPanel,
|
|
193
|
-
) -> dict[str, tuple[str, ...]]:
|
|
194
|
-
memberships: dict[str, list[str]] = defaultdict(list)
|
|
195
|
-
for group in validated.groups:
|
|
196
|
-
for node_id in group.node_ids:
|
|
197
|
-
memberships[node_id].append(group.id)
|
|
198
|
-
return {
|
|
199
|
-
node_id: tuple(sorted(group_ids))
|
|
200
|
-
for node_id, group_ids in memberships.items()
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
def _reorder_component_nodes(
|
|
205
|
-
validated: ValidatedPipeline | ValidatedDetailPanel,
|
|
206
|
-
ranks: dict[str, int],
|
|
207
|
-
included_node_ids: set[str],
|
|
208
|
-
) -> dict[str, int]:
|
|
209
|
-
if not included_node_ids:
|
|
210
|
-
return {}
|
|
211
|
-
|
|
212
|
-
nodes_by_rank: dict[int, list[str]] = defaultdict(list)
|
|
213
|
-
for node_id in included_node_ids:
|
|
214
|
-
nodes_by_rank[ranks[node_id]].append(node_id)
|
|
215
|
-
|
|
216
|
-
for rank_nodes in nodes_by_rank.values():
|
|
217
|
-
rank_nodes.sort(key=validated.node_index.__getitem__)
|
|
218
|
-
|
|
219
|
-
local_order = {
|
|
220
|
-
node_id: index
|
|
221
|
-
for rank_nodes in nodes_by_rank.values()
|
|
222
|
-
for index, node_id in enumerate(rank_nodes)
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
incoming, outgoing = _forward_neighbors(
|
|
226
|
-
validated,
|
|
227
|
-
ranks,
|
|
228
|
-
included_node_ids=included_node_ids,
|
|
229
|
-
)
|
|
230
|
-
ordered_ranks = sorted(nodes_by_rank)
|
|
231
|
-
|
|
232
|
-
for _ in range(4):
|
|
233
|
-
for rank in ordered_ranks[1:]:
|
|
234
|
-
_resort_rank(nodes_by_rank[rank], incoming, local_order, validated)
|
|
235
|
-
_refresh_order(nodes_by_rank[rank], local_order)
|
|
236
|
-
for rank in reversed(ordered_ranks[:-1]):
|
|
237
|
-
_resort_rank(nodes_by_rank[rank], outgoing, local_order, validated)
|
|
238
|
-
_refresh_order(nodes_by_rank[rank], local_order)
|
|
239
|
-
|
|
240
|
-
return local_order
|
|
241
|
-
|
|
242
|
-
|
|
243
120
|
def _detail_focus_path_nodes(
|
|
244
121
|
validated: ValidatedPipeline,
|
|
245
122
|
ranks: dict[str, int],
|
|
@@ -810,7 +810,9 @@ def _select_forward_route(
|
|
|
810
810
|
target_node.node.id,
|
|
811
811
|
routing_groups,
|
|
812
812
|
)
|
|
813
|
-
evaluations: list[
|
|
813
|
+
evaluations: list[
|
|
814
|
+
tuple[bool, tuple[int, int, int, int, float, float, int, float, int, float, int], CandidatePath]
|
|
815
|
+
] = []
|
|
814
816
|
|
|
815
817
|
for candidate_index, (kind, candidate) in enumerate(candidates):
|
|
816
818
|
clearance_ok = _path_respects_group_clearance(
|
|
@@ -1560,7 +1562,7 @@ def _select_candidate_with_priority(
|
|
|
1560
1562
|
evaluations: list[
|
|
1561
1563
|
tuple[
|
|
1562
1564
|
bool,
|
|
1563
|
-
tuple[int, int, int, float, float, int, float, int, float, int],
|
|
1565
|
+
tuple[int, int, int, int, float, float, int, float, int, float, int],
|
|
1564
1566
|
CandidatePath,
|
|
1565
1567
|
]
|
|
1566
1568
|
],
|
|
@@ -1748,7 +1750,7 @@ def _forward_priority_key(
|
|
|
1748
1750
|
theme: "Theme",
|
|
1749
1751
|
has_relevant_groups: bool,
|
|
1750
1752
|
interactions: InteractionMetrics,
|
|
1751
|
-
) -> tuple[int, int, int, float, float, int, float, int, float, int]:
|
|
1753
|
+
) -> tuple[int, int, int, int, float, float, int, float, int, float, int]:
|
|
1752
1754
|
collisions, backwards, bends, length = _route_metrics(
|
|
1753
1755
|
candidate,
|
|
1754
1756
|
nodes=nodes,
|
|
@@ -1758,6 +1760,16 @@ def _forward_priority_key(
|
|
|
1758
1760
|
return (
|
|
1759
1761
|
interactions.edge_crossings,
|
|
1760
1762
|
collisions,
|
|
1763
|
+
_clean_direct_elbow_priority(
|
|
1764
|
+
kind,
|
|
1765
|
+
collisions=collisions,
|
|
1766
|
+
backwards=backwards,
|
|
1767
|
+
bends=bends,
|
|
1768
|
+
has_relevant_groups=has_relevant_groups,
|
|
1769
|
+
interactions=interactions,
|
|
1770
|
+
source_node=source_node,
|
|
1771
|
+
target_node=target_node,
|
|
1772
|
+
),
|
|
1761
1773
|
_forward_side_change_penalty(kind, has_relevant_groups=has_relevant_groups),
|
|
1762
1774
|
interactions.edge_overlap_length,
|
|
1763
1775
|
interactions.obstacle_overlap_length,
|
|
@@ -1775,6 +1787,30 @@ def _forward_priority_key(
|
|
|
1775
1787
|
)
|
|
1776
1788
|
|
|
1777
1789
|
|
|
1790
|
+
def _clean_direct_elbow_priority(
|
|
1791
|
+
kind: str,
|
|
1792
|
+
*,
|
|
1793
|
+
collisions: int,
|
|
1794
|
+
backwards: float,
|
|
1795
|
+
bends: int,
|
|
1796
|
+
has_relevant_groups: bool,
|
|
1797
|
+
interactions: InteractionMetrics,
|
|
1798
|
+
source_node: LayoutNode,
|
|
1799
|
+
target_node: LayoutNode,
|
|
1800
|
+
) -> int:
|
|
1801
|
+
if kind != "direct_elbow" or has_relevant_groups:
|
|
1802
|
+
return 1
|
|
1803
|
+
if source_node.order >= target_node.order:
|
|
1804
|
+
return 1
|
|
1805
|
+
if collisions != 0 or bends != 1 or backwards > EPSILON:
|
|
1806
|
+
return 1
|
|
1807
|
+
if interactions.edge_crossings != 0 or interactions.edge_overlap_length > EPSILON:
|
|
1808
|
+
return 1
|
|
1809
|
+
if interactions.obstacle_overlap_length > EPSILON or interactions.obstacle_crossings != 0:
|
|
1810
|
+
return 1
|
|
1811
|
+
return 0
|
|
1812
|
+
|
|
1813
|
+
|
|
1778
1814
|
def _forward_kind_priority(
|
|
1779
1815
|
kind: str,
|
|
1780
1816
|
*,
|
|
@@ -64,14 +64,20 @@ def measure_text(validated: ValidatedPipeline) -> dict[str, MeasuredText]:
|
|
|
64
64
|
def _wrap(value: str | None, width: int) -> list[str]:
|
|
65
65
|
if not value:
|
|
66
66
|
return []
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
67
|
+
lines: list[str] = []
|
|
68
|
+
for explicit_line in value.splitlines() or [value]:
|
|
69
|
+
if explicit_line == "":
|
|
70
|
+
lines.append("")
|
|
71
|
+
continue
|
|
72
|
+
wrapped = textwrap.wrap(
|
|
73
|
+
explicit_line,
|
|
74
|
+
width=width,
|
|
75
|
+
break_long_words=True,
|
|
76
|
+
break_on_hyphens=False,
|
|
77
|
+
drop_whitespace=True,
|
|
78
|
+
)
|
|
79
|
+
lines.extend(wrapped or [explicit_line])
|
|
80
|
+
return lines
|
|
75
81
|
|
|
76
82
|
|
|
77
83
|
def _max_line_width(lines: tuple[str, ...], font_size: float, ratio: float) -> float:
|
|
@@ -76,9 +76,10 @@ class Edge:
|
|
|
76
76
|
class Group:
|
|
77
77
|
"""Highlight related nodes or edges with a labeled overlay.
|
|
78
78
|
|
|
79
|
-
Groups stay visual first
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
Groups stay visual first: they do not pin members together or force a
|
|
80
|
+
compact cluster. Layout still follows dependency ranks, and routes leaving
|
|
81
|
+
or re-entering grouped nodes bend outside the grouped area. At least one
|
|
82
|
+
node or edge reference is required.
|
|
82
83
|
"""
|
|
83
84
|
|
|
84
85
|
id: str
|
|
@@ -106,8 +107,10 @@ class Group:
|
|
|
106
107
|
class DetailPanel:
|
|
107
108
|
"""Expand a focus node into a lower inset with its own mini-graph.
|
|
108
109
|
|
|
109
|
-
|
|
110
|
-
|
|
110
|
+
Use a detail panel when a node's internal mechanics would otherwise add
|
|
111
|
+
long-range or cross-level edges to the main graph. The focus node must
|
|
112
|
+
exist in the main pipeline graph, and the panel must contain at least one
|
|
113
|
+
node.
|
|
111
114
|
"""
|
|
112
115
|
|
|
113
116
|
id: str
|
|
@@ -51,7 +51,7 @@ def render_svg(layout: LayoutResult, theme: Theme) -> str:
|
|
|
51
51
|
)
|
|
52
52
|
|
|
53
53
|
group_layer = ET.SubElement(root, ET.QName(SVG_NS, "g"), attrib={"id": "groups"})
|
|
54
|
-
|
|
54
|
+
_render_group_shapes(group_layer, layout.main, theme, metrics)
|
|
55
55
|
|
|
56
56
|
if layout.detail_panel is not None:
|
|
57
57
|
guide_layer = ET.SubElement(root, ET.QName(SVG_NS, "g"), attrib={"id": "detail-panel-guides"})
|
|
@@ -62,8 +62,8 @@ def render_svg(layout: LayoutResult, theme: Theme) -> str:
|
|
|
62
62
|
ET.QName(SVG_NS, "g"),
|
|
63
63
|
attrib={"id": f"detail-panel-{layout.detail_panel.panel.id}"},
|
|
64
64
|
)
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
_render_detail_panel_container_shape(panel_layer, layout.detail_panel, theme, metrics)
|
|
66
|
+
_render_group_shapes(panel_layer, layout.detail_panel.graph, theme, metrics)
|
|
67
67
|
|
|
68
68
|
edge_layer = ET.SubElement(root, ET.QName(SVG_NS, "g"), attrib={"id": "edges"})
|
|
69
69
|
_render_edges(edge_layer, layout.main.edges, marker_ids, theme, metrics)
|
|
@@ -86,6 +86,12 @@ def render_svg(layout: LayoutResult, theme: Theme) -> str:
|
|
|
86
86
|
id_prefix=f"detail-panel-{layout.detail_panel.panel.id}-",
|
|
87
87
|
)
|
|
88
88
|
|
|
89
|
+
label_layer = ET.SubElement(root, ET.QName(SVG_NS, "g"), attrib={"id": "labels"})
|
|
90
|
+
_render_group_labels(label_layer, layout.main, theme, metrics)
|
|
91
|
+
if layout.detail_panel is not None:
|
|
92
|
+
_render_detail_panel_title(label_layer, layout.detail_panel, theme, metrics)
|
|
93
|
+
_render_group_labels(label_layer, layout.detail_panel.graph, theme, metrics)
|
|
94
|
+
|
|
89
95
|
return ET.tostring(root, encoding="unicode")
|
|
90
96
|
|
|
91
97
|
|
|
@@ -142,7 +148,7 @@ def _build_shadow_filter(defs: ET.Element, metrics: ResolvedThemeMetrics) -> Non
|
|
|
142
148
|
ET.SubElement(merge, ET.QName(SVG_NS, "feMergeNode"), attrib={"in": "SourceGraphic"})
|
|
143
149
|
|
|
144
150
|
|
|
145
|
-
def
|
|
151
|
+
def _render_group_shapes(
|
|
146
152
|
parent: ET.Element,
|
|
147
153
|
graph: GraphLayout,
|
|
148
154
|
theme: Theme,
|
|
@@ -180,18 +186,28 @@ def _render_groups(
|
|
|
180
186
|
"stroke-linecap": "round",
|
|
181
187
|
},
|
|
182
188
|
)
|
|
183
|
-
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def _render_group_labels(
|
|
192
|
+
parent: ET.Element,
|
|
193
|
+
graph: GraphLayout,
|
|
194
|
+
theme: Theme,
|
|
195
|
+
metrics: ResolvedThemeMetrics,
|
|
196
|
+
) -> None:
|
|
197
|
+
for overlay in graph.groups:
|
|
198
|
+
_render_label_text(
|
|
184
199
|
parent,
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
200
|
+
text=overlay.group.label,
|
|
201
|
+
x=overlay.bounds.x + theme.group_padding,
|
|
202
|
+
baseline_y=overlay.bounds.y + metrics.group_label_baseline_offset,
|
|
203
|
+
font_family=theme.title_font_family,
|
|
204
|
+
font_size=theme.subtitle_font_size,
|
|
205
|
+
font_weight=theme.title_font_weight,
|
|
206
|
+
text_color=theme.group_label_color,
|
|
207
|
+
underpaint_color=theme.background_color,
|
|
208
|
+
underpaint_opacity=1.0,
|
|
209
|
+
underpaint_width=max(theme.stroke_width * 3.0, theme.subtitle_font_size * 0.24),
|
|
210
|
+
)
|
|
195
211
|
|
|
196
212
|
|
|
197
213
|
def _render_guide_lines(parent: ET.Element, guide_lines: tuple[GuideLine, ...], theme: Theme) -> None:
|
|
@@ -209,7 +225,7 @@ def _render_guide_lines(parent: ET.Element, guide_lines: tuple[GuideLine, ...],
|
|
|
209
225
|
)
|
|
210
226
|
|
|
211
227
|
|
|
212
|
-
def
|
|
228
|
+
def _render_detail_panel_container_shape(
|
|
213
229
|
parent: ET.Element,
|
|
214
230
|
detail_panel: DetailPanelLayout,
|
|
215
231
|
theme: Theme,
|
|
@@ -243,18 +259,72 @@ def _render_detail_panel_container(
|
|
|
243
259
|
},
|
|
244
260
|
)
|
|
245
261
|
|
|
262
|
+
|
|
263
|
+
def _render_detail_panel_title(
|
|
264
|
+
parent: ET.Element,
|
|
265
|
+
detail_panel: DetailPanelLayout,
|
|
266
|
+
theme: Theme,
|
|
267
|
+
metrics: ResolvedThemeMetrics,
|
|
268
|
+
) -> None:
|
|
269
|
+
_render_label_text(
|
|
270
|
+
parent,
|
|
271
|
+
text=detail_panel.panel.label,
|
|
272
|
+
x=detail_panel.bounds.x + theme.detail_panel_padding,
|
|
273
|
+
baseline_y=detail_panel.bounds.y + metrics.detail_panel_title_baseline_offset,
|
|
274
|
+
font_family=theme.title_font_family,
|
|
275
|
+
font_size=theme.subtitle_font_size,
|
|
276
|
+
font_weight=theme.title_font_weight,
|
|
277
|
+
text_color=theme.detail_panel_title_color,
|
|
278
|
+
underpaint_color=detail_panel.fill,
|
|
279
|
+
underpaint_opacity=1.0,
|
|
280
|
+
underpaint_width=max(theme.stroke_width * 3.0, theme.subtitle_font_size * 0.26),
|
|
281
|
+
)
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
def _render_label_text(
|
|
285
|
+
parent: ET.Element,
|
|
286
|
+
*,
|
|
287
|
+
text: str,
|
|
288
|
+
x: float,
|
|
289
|
+
baseline_y: float,
|
|
290
|
+
font_family: str,
|
|
291
|
+
font_size: float,
|
|
292
|
+
font_weight: int,
|
|
293
|
+
text_color: str,
|
|
294
|
+
underpaint_color: str,
|
|
295
|
+
underpaint_opacity: float,
|
|
296
|
+
underpaint_width: float,
|
|
297
|
+
) -> None:
|
|
298
|
+
ET.SubElement(
|
|
299
|
+
parent,
|
|
300
|
+
ET.QName(SVG_NS, "text"),
|
|
301
|
+
attrib={
|
|
302
|
+
"x": _fmt(x),
|
|
303
|
+
"y": _fmt(baseline_y),
|
|
304
|
+
"fill": underpaint_color,
|
|
305
|
+
"fill-opacity": _fmt(underpaint_opacity),
|
|
306
|
+
"stroke": underpaint_color,
|
|
307
|
+
"stroke-opacity": _fmt(underpaint_opacity),
|
|
308
|
+
"stroke-width": _fmt(underpaint_width),
|
|
309
|
+
"stroke-linejoin": "round",
|
|
310
|
+
"font-family": font_family,
|
|
311
|
+
"font-size": _fmt(font_size),
|
|
312
|
+
"font-weight": str(font_weight),
|
|
313
|
+
},
|
|
314
|
+
).text = text
|
|
315
|
+
|
|
246
316
|
ET.SubElement(
|
|
247
317
|
parent,
|
|
248
318
|
ET.QName(SVG_NS, "text"),
|
|
249
319
|
attrib={
|
|
250
|
-
"x": _fmt(
|
|
251
|
-
"y": _fmt(
|
|
252
|
-
"fill":
|
|
253
|
-
"font-family":
|
|
254
|
-
"font-size": _fmt(
|
|
255
|
-
"font-weight": str(
|
|
320
|
+
"x": _fmt(x),
|
|
321
|
+
"y": _fmt(baseline_y),
|
|
322
|
+
"fill": text_color,
|
|
323
|
+
"font-family": font_family,
|
|
324
|
+
"font-size": _fmt(font_size),
|
|
325
|
+
"font-weight": str(font_weight),
|
|
256
326
|
},
|
|
257
|
-
).text =
|
|
327
|
+
).text = text
|
|
258
328
|
|
|
259
329
|
|
|
260
330
|
def _render_edges(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: frameplot
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.6
|
|
4
4
|
Summary: Turn Python-defined pipeline graphs into presentation-ready SVG and PNG diagrams.
|
|
5
5
|
Author: Small Turtle 2
|
|
6
6
|
License-Expression: MIT
|
|
@@ -147,6 +147,12 @@ Top-level imports are the supported public API:
|
|
|
147
147
|
- `to_png_bytes(scale=4.0) -> bytes`
|
|
148
148
|
- `save_png(path, scale=4.0) -> None`
|
|
149
149
|
|
|
150
|
+
## Modeling Guidance
|
|
151
|
+
|
|
152
|
+
- Keep the main graph at one abstraction level. Frameplot lays the pipeline out as a dependency-driven left-to-right graph, not as a freeform block diagram.
|
|
153
|
+
- Use `DetailPanel` for repeated block internals or per-stage mechanics that would otherwise create long-range edges in the main graph.
|
|
154
|
+
- Use `Group` to highlight nearby related nodes, not to force distant nodes to stay together. Groups are visual overlays and routing obstacles, so very wide groups can increase route detours.
|
|
155
|
+
|
|
150
156
|
## Advanced Example: Multi-cloud Data Pipeline
|
|
151
157
|
|
|
152
158
|
The hero image at the top and the theme gallery above are generated from [`examples/theme_heroes.py`](https://github.com/smturtle2/frameplot/blob/main/examples/theme_heroes.py), using the shared pipeline definition in [`examples/hero_pipeline.py`](https://github.com/smturtle2/frameplot/blob/main/examples/hero_pipeline.py). Together they showcase:
|
|
@@ -161,6 +167,7 @@ The hero image at the top and the theme gallery above are generated from [`examp
|
|
|
161
167
|
- Edge labels are not supported yet, but edge-to-edge joins can render optional `+` / `x` badges.
|
|
162
168
|
- Groups stay visual overlays, and routes leaving or re-entering grouped nodes bend outside grouped areas.
|
|
163
169
|
- Detail panels render as separate lower insets attached to a focus node in the main flow.
|
|
170
|
+
- If a sample looks stretched or routes far outside the intended block, the graph usually mixes stage-level flow with internal logic in one plane; move the internals into a `DetailPanel`.
|
|
164
171
|
|
|
165
172
|
## Development
|
|
166
173
|
|
|
@@ -905,6 +905,24 @@ def test_grouped_forward_edge_can_use_right_side_direct_elbow() -> None:
|
|
|
905
905
|
assert all(not _point_in_bounds(point, inputs) for point in bends)
|
|
906
906
|
|
|
907
907
|
|
|
908
|
+
def test_generate_pipeline_script_prefers_clean_single_bend_guidance_elbow() -> None:
|
|
909
|
+
namespace = runpy.run_path("test/generate_pipeline.py")
|
|
910
|
+
pipeline = namespace["build_pipeline"]()
|
|
911
|
+
layout = build_layout(pipeline)
|
|
912
|
+
routed = {edge.edge.id: edge for edge in layout.main.edges}
|
|
913
|
+
guide = layout.main.nodes["h_feature"]
|
|
914
|
+
target = layout.main.nodes["main_blocks"]
|
|
915
|
+
|
|
916
|
+
points = routed["h_to_main"].points
|
|
917
|
+
bends = _bend_points(points)
|
|
918
|
+
|
|
919
|
+
assert len(points) == 3
|
|
920
|
+
assert bends == [points[1]]
|
|
921
|
+
assert points[0] == Point(guide.right, guide.center_y)
|
|
922
|
+
assert points[1] == Point(target.center_x, guide.center_y)
|
|
923
|
+
assert points[-1] == Point(target.center_x, target.y)
|
|
924
|
+
|
|
925
|
+
|
|
908
926
|
def test_back_edge_leaves_group_before_bending() -> None:
|
|
909
927
|
pipeline = Pipeline(
|
|
910
928
|
nodes=[
|
|
@@ -1366,6 +1384,30 @@ def test_text_measurement_and_render_share_resolved_baselines() -> None:
|
|
|
1366
1384
|
assert float(texts[1].attrib["y"]) == pytest.approx(expected_subtitle_y)
|
|
1367
1385
|
|
|
1368
1386
|
|
|
1387
|
+
def test_text_measurement_preserves_explicit_newlines() -> None:
|
|
1388
|
+
pipeline = Pipeline(
|
|
1389
|
+
nodes=[Node("focus", "Primary Title", "First subtitle line\nSecond subtitle line")],
|
|
1390
|
+
edges=[],
|
|
1391
|
+
)
|
|
1392
|
+
|
|
1393
|
+
layout = build_layout(pipeline)
|
|
1394
|
+
layout_node = layout.main.nodes["focus"]
|
|
1395
|
+
node_group = ET.fromstring(pipeline.to_svg()).find(".//svg:g[@id='focus']", SVG_NS)
|
|
1396
|
+
|
|
1397
|
+
assert node_group is not None
|
|
1398
|
+
texts = node_group.findall("svg:text", SVG_NS)
|
|
1399
|
+
|
|
1400
|
+
assert layout_node.subtitle_lines == ("First subtitle line", "Second subtitle line")
|
|
1401
|
+
assert [text.text for text in texts] == [
|
|
1402
|
+
"Primary Title",
|
|
1403
|
+
"First subtitle line",
|
|
1404
|
+
"Second subtitle line",
|
|
1405
|
+
]
|
|
1406
|
+
assert float(texts[2].attrib["y"]) - float(texts[1].attrib["y"]) == pytest.approx(
|
|
1407
|
+
layout_node.subtitle_line_height
|
|
1408
|
+
)
|
|
1409
|
+
|
|
1410
|
+
|
|
1369
1411
|
def test_detail_panel_renders_as_separate_block_with_guides() -> None:
|
|
1370
1412
|
pipeline = Pipeline(
|
|
1371
1413
|
nodes=[
|
|
@@ -1399,6 +1441,50 @@ def test_detail_panel_renders_as_separate_block_with_guides() -> None:
|
|
|
1399
1441
|
assert svg.count('marker-end="url(#arrow-') == 4
|
|
1400
1442
|
|
|
1401
1443
|
|
|
1444
|
+
def test_group_and_detail_panel_labels_render_after_nodes() -> None:
|
|
1445
|
+
theme = Theme.dark()
|
|
1446
|
+
pipeline = Pipeline(
|
|
1447
|
+
nodes=[
|
|
1448
|
+
Node("source", "Source"),
|
|
1449
|
+
Node("focus", "Focus"),
|
|
1450
|
+
],
|
|
1451
|
+
edges=[Edge("e1", "source", "focus")],
|
|
1452
|
+
groups=[Group("g1", "Shared Stage", ("source", "focus"))],
|
|
1453
|
+
detail_panel=DetailPanel(
|
|
1454
|
+
"detail",
|
|
1455
|
+
"focus",
|
|
1456
|
+
"Expanded Focus",
|
|
1457
|
+
nodes=(Node("inner", "Inner"),),
|
|
1458
|
+
edges=(),
|
|
1459
|
+
),
|
|
1460
|
+
theme=theme,
|
|
1461
|
+
)
|
|
1462
|
+
|
|
1463
|
+
root = ET.fromstring(pipeline.to_svg())
|
|
1464
|
+
layer_ids = [child.attrib.get("id") for child in root if child.tag == f"{{{SVG_NS['svg']}}}g"]
|
|
1465
|
+
labels = root.find(".//svg:g[@id='labels']", SVG_NS)
|
|
1466
|
+
|
|
1467
|
+
assert labels is not None
|
|
1468
|
+
label_rects = labels.findall("svg:rect", SVG_NS)
|
|
1469
|
+
label_texts = labels.findall("svg:text", SVG_NS)
|
|
1470
|
+
shared_stage = [text for text in label_texts if text.text == "Shared Stage"]
|
|
1471
|
+
expanded_focus = [text for text in label_texts if text.text == "Expanded Focus"]
|
|
1472
|
+
|
|
1473
|
+
assert not label_rects
|
|
1474
|
+
assert len(shared_stage) == 2
|
|
1475
|
+
assert len(expanded_focus) == 2
|
|
1476
|
+
assert shared_stage[0].attrib["stroke"] == theme.background_color
|
|
1477
|
+
assert shared_stage[0].attrib["fill"] == theme.background_color
|
|
1478
|
+
assert shared_stage[1].attrib["fill"] == theme.group_label_color
|
|
1479
|
+
assert "stroke" not in shared_stage[1].attrib
|
|
1480
|
+
assert expanded_focus[0].attrib["stroke"] == theme.detail_panel_fill
|
|
1481
|
+
assert expanded_focus[0].attrib["fill"] == theme.detail_panel_fill
|
|
1482
|
+
assert expanded_focus[1].attrib["fill"] == theme.detail_panel_title_color
|
|
1483
|
+
assert "stroke" not in expanded_focus[1].attrib
|
|
1484
|
+
assert layer_ids.index("nodes") < layer_ids.index("labels")
|
|
1485
|
+
assert layer_ids.index("edge-joins") < layer_ids.index("labels")
|
|
1486
|
+
|
|
1487
|
+
|
|
1402
1488
|
def test_detail_panel_biases_focus_flow_to_lower_rows() -> None:
|
|
1403
1489
|
pipeline = Pipeline(
|
|
1404
1490
|
nodes=[
|
|
@@ -1472,25 +1558,33 @@ def test_detail_panel_nested_groups_keep_visible_inner_gap_and_header_clearance(
|
|
|
1472
1558
|
assert child.y - parent.y > pipeline.theme.subtitle_font_size * metrics.line_height_ratio
|
|
1473
1559
|
|
|
1474
1560
|
|
|
1475
|
-
def
|
|
1561
|
+
def test_detail_panel_shared_guidance_node_uses_general_lane_ordering() -> None:
|
|
1476
1562
|
layout = build_layout(_build_generate_pipeline_fixture())
|
|
1477
1563
|
panel_nodes = layout.detail_panel.graph.nodes
|
|
1478
|
-
panel_groups = layout.detail_panel.graph.groups
|
|
1479
1564
|
routed = {edge.edge.id: edge for edge in layout.detail_panel.graph.edges}
|
|
1480
1565
|
h_node = panel_nodes["panel_h"]
|
|
1481
1566
|
source_lane_one = _source_access_segment(routed["panel_h_to_nca_c"].points)
|
|
1482
1567
|
source_lane_two = _source_access_segment(routed["panel_h_to_nca_m"].points)
|
|
1483
1568
|
|
|
1484
|
-
assert
|
|
1485
|
-
assert
|
|
1486
|
-
assert panel_nodes["panel_m_in"].order ==
|
|
1487
|
-
assert
|
|
1488
|
-
assert routed["panel_h_to_nca_c"].points[0].x == h_node.right
|
|
1489
|
-
assert routed["panel_h_to_nca_m"].points[0].x == h_node.right
|
|
1490
|
-
assert routed["panel_h_to_nca_c"].points[0].y != routed["panel_h_to_nca_m"].points[0].y
|
|
1569
|
+
assert panel_nodes["panel_c_in"].order == panel_nodes["panel_nca_c"].order == 0
|
|
1570
|
+
assert h_node.order == panel_nodes["panel_nca_m"].order == 1
|
|
1571
|
+
assert panel_nodes["panel_m_in"].order == 2
|
|
1572
|
+
assert h_node.order != 0
|
|
1491
1573
|
assert _collinear_overlap_length(*source_lane_one, *source_lane_two) == pytest.approx(0.0, abs=0.01)
|
|
1492
1574
|
|
|
1493
1575
|
|
|
1576
|
+
def test_generate_pipeline_script_detail_panel_aligns_guidance_with_candidate_lane() -> None:
|
|
1577
|
+
namespace = runpy.run_path("test/generate_pipeline.py")
|
|
1578
|
+
pipeline = namespace["build_pipeline"]()
|
|
1579
|
+
layout = build_layout(pipeline)
|
|
1580
|
+
panel_nodes = layout.detail_panel.graph.nodes
|
|
1581
|
+
routed = {edge.edge.id: edge for edge in layout.detail_panel.graph.edges}
|
|
1582
|
+
|
|
1583
|
+
assert panel_nodes["panel_h"].order == panel_nodes["panel_local_c"].order == panel_nodes["panel_global_c"].order == 0
|
|
1584
|
+
assert panel_nodes["panel_local_m"].order == panel_nodes["panel_global_m"].order == 1
|
|
1585
|
+
assert routed["panel_h_to_local_c"].points[0].y == routed["panel_h_to_local_c"].points[-1].y
|
|
1586
|
+
|
|
1587
|
+
|
|
1494
1588
|
def test_generate_pipeline_row_gap_no_longer_scales_with_raw_cross_row_edge_count() -> None:
|
|
1495
1589
|
layout = build_layout(_build_generate_pipeline_fixture())
|
|
1496
1590
|
gap = _row_gap_between_rows(layout.main.nodes, 0, 1)
|
|
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
|