Add HTML5 flowchart depth controls
CI / python (push) Has been cancelled
CI / rust (push) Has been cancelled

This commit is contained in:
2026-05-17 01:22:28 +03:00
parent 20c1b1809b
commit 6cc669f694
3 changed files with 49 additions and 6 deletions
+32 -3
View File
@@ -252,11 +252,11 @@ def render_html5_flowchart(
flowchart: object | None,
*,
focus: str | None = None,
depth: int = 1,
oob: bool = False,
) -> str:
hx_url = f"/html5/projects/{quote(project_id)}/flowchart"
if focus:
hx_url = f"{hx_url}?focus={quote(focus, safe='')}"
normalized_depth = min(max(depth, 1), 3)
hx_url = _flowchart_url(project_id, focus, normalized_depth)
oob_attr = ' hx-swap-oob="outerHTML"' if oob else ""
if flowchart is None:
return f"""
@@ -290,6 +290,7 @@ def render_html5_flowchart(
{oob_attr}
>
<div class="panel-title">Карта связей · {escape(mode)}</div>
{_flowchart_depth_actions(project_id, focus, normalized_depth)}
<dl class="report-grid">
{_metric("Nodes", len(nodes))}
{_metric("Edges", len(edges))}
@@ -1750,6 +1751,34 @@ def _flowchart_edge_item(edge: object, nodes: Iterable[object]) -> str:
"""
def _flowchart_url(project_id: str, focus: str | None, depth: int) -> str:
params = []
if focus:
params.append(f"focus={quote(focus, safe='')}")
params.append(f"depth={depth}")
return f"/html5/projects/{quote(project_id)}/flowchart?{'&'.join(params)}"
def _flowchart_depth_actions(project_id: str, focus: str | None, active_depth: int) -> str:
buttons = []
for depth in [1, 2, 3]:
active = ' aria-current="page" data-html5-object-action-active="true"' if depth == active_depth else ""
url = _flowchart_url(project_id, focus, depth)
buttons.append(
f"""
<a
class="button"
href="{url}"
hx-get="{url}"
hx-target="[data-html5-flowchart]"
hx-swap="outerHTML"
{active}
>Depth {depth}</a>
"""
)
return f'<nav class="object-actions" data-html5-flowchart-actions>{"".join(buttons)}</nav>'
def _flowchart_node_item(node: object) -> str:
name = str(getattr(node, "qualified_name", "") or getattr(node, "label", "") or "node")
kind = str(getattr(node, "kind", "") or "NODE")
+2 -2
View File
@@ -1752,7 +1752,7 @@ async def html5_project_flowchart(
) -> Response:
flowchart = await project_flowchart(project_id, focus=focus, depth=depth, limit=limit)
return Response(
render_html5_flowchart(project_id, flowchart, focus=focus),
render_html5_flowchart(project_id, flowchart, focus=focus, depth=depth),
media_type="text/html; charset=utf-8",
)
@@ -1784,7 +1784,7 @@ async def html5_project_object_context(project_id: str, object_name: str, mode:
flowchart,
mode,
)
flowchart_context = render_html5_flowchart(project_id, flowchart, focus=object_name, oob=True)
flowchart_context = render_html5_flowchart(project_id, flowchart, focus=object_name, depth=1, oob=True)
source_context = render_html5_source(source_node, oob=True) if source_node is not None else ""
symbol_context = render_html5_symbol_detail(project_id, symbol_references, oob=True)
report_context = render_html5_object_report(