execweave 1.0.0__py3-none-any.whl
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.
- execweave/__init__.py +3 -0
- execweave/__main__.py +5 -0
- execweave/_conversation_records_core.py +902 -0
- execweave/_dashboard_shell_base.py +148 -0
- execweave/_http_proxy_base.py +565 -0
- execweave/_http_proxy_bounded.py +560 -0
- execweave/_http_proxy_stage.py +509 -0
- execweave/acceptance_output.py +19 -0
- execweave/agent_bootstrap.py +395 -0
- execweave/agent_topology.py +313 -0
- execweave/agent_trace.py +1162 -0
- execweave/agy_preview_sanitize.py +102 -0
- execweave/analysis.py +427 -0
- execweave/anthropic.py +228 -0
- execweave/anthropic_cli.py +171 -0
- execweave/anthropic_full_fidelity.py +385 -0
- execweave/antigravity_adapter.py +112 -0
- execweave/antigravity_adapter_base.py +479 -0
- execweave/antigravity_full_fidelity.py +656 -0
- execweave/antigravity_full_fidelity_base.py +172 -0
- execweave/antigravity_full_fidelity_collaboration_base.py +451 -0
- execweave/antigravity_hook_cli.py +209 -0
- execweave/antigravity_record.py +96 -0
- execweave/antigravity_subagent_linkage.py +449 -0
- execweave/antigravity_trace_capability.py +39 -0
- execweave/auto_specialized.py +547 -0
- execweave/backends.py +102 -0
- execweave/benchmark.py +80 -0
- execweave/claude_adapter.py +517 -0
- execweave/claude_child_transcript.py +314 -0
- execweave/claude_delegation.py +136 -0
- execweave/claude_full_fidelity.py +396 -0
- execweave/claude_hook_cli.py +209 -0
- execweave/claude_hook_contract.py +943 -0
- execweave/claude_model_observer.py +353 -0
- execweave/claude_record.py +106 -0
- execweave/cli.py +629 -0
- execweave/codex_adapter.py +455 -0
- execweave/codex_conversation.py +621 -0
- execweave/codex_full_fidelity.py +287 -0
- execweave/codex_hook_cli.py +301 -0
- execweave/codex_hook_entry.py +207 -0
- execweave/codex_hook_lifecycle.py +363 -0
- execweave/codex_message_diagnostics.py +322 -0
- execweave/codex_message_transport_diagnostics.py +399 -0
- execweave/codex_record.py +199 -0
- execweave/codex_rollout_structures.py +402 -0
- execweave/codex_rollout_trace.py +56 -0
- execweave/codex_rollout_trace_base.py +1509 -0
- execweave/collector.py +768 -0
- execweave/command.py +157 -0
- execweave/command_privacy.py +20 -0
- execweave/content_evidence.py +101 -0
- execweave/content_integrity.py +289 -0
- execweave/content_store.py +273 -0
- execweave/controlled_checks.py +561 -0
- execweave/conversation_archive.py +338 -0
- execweave/conversation_message_identity.py +264 -0
- execweave/conversation_preview.py +66 -0
- execweave/conversation_preview_antigravity.py +32 -0
- execweave/conversation_preview_claude.py +31 -0
- execweave/conversation_preview_codex.py +107 -0
- execweave/conversation_preview_common.py +180 -0
- execweave/conversation_preview_generic.py +188 -0
- execweave/conversation_preview_lines.py +133 -0
- execweave/conversation_preview_transcript.py +121 -0
- execweave/conversation_records.py +349 -0
- execweave/conversation_records_antigravity.py +370 -0
- execweave/conversation_records_codex.py +83 -0
- execweave/conversation_records_common.py +17 -0
- execweave/conversation_records_ollama.py +39 -0
- execweave/correlation.py +818 -0
- execweave/cursor_adapter.py +349 -0
- execweave/cursor_delegation.py +87 -0
- execweave/cursor_delegation_base.py +220 -0
- execweave/cursor_full_fidelity.py +489 -0
- execweave/cursor_hook_cli.py +195 -0
- execweave/cursor_hook_contract.py +439 -0
- execweave/cursor_lifecycle.py +159 -0
- execweave/cursor_record.py +96 -0
- execweave/dashboard_shell.py +283 -0
- execweave/delivery_status.py +94 -0
- execweave/entry.py +98 -0
- execweave/evidence_availability.py +113 -0
- execweave/evidence_grade.py +166 -0
- execweave/fidelity.py +304 -0
- execweave/filesystem.py +327 -0
- execweave/finalization.py +92 -0
- execweave/focus.py +118 -0
- execweave/framework_adapters/__init__.py +34 -0
- execweave/framework_adapters/autogen.py +398 -0
- execweave/framework_adapters/base.py +580 -0
- execweave/framework_adapters/camel.py +270 -0
- execweave/framework_adapters/camel_channel.py +71 -0
- execweave/framework_adapters/metagpt.py +315 -0
- execweave/framework_adapters/metagpt_ollama_compat.py +54 -0
- execweave/framework_adapters/metagpt_recording.py +342 -0
- execweave/framework_adapters/registry.py +90 -0
- execweave/graph.py +590 -0
- execweave/graph_ops.py +472 -0
- execweave/hook_command.py +32 -0
- execweave/hook_delivery.py +32 -0
- execweave/hook_input.py +16 -0
- execweave/http_proxy.py +187 -0
- execweave/http_proxy_cli.py +84 -0
- execweave/inference_gateway.py +476 -0
- execweave/inference_gateway_cli.py +211 -0
- execweave/inference_gateway_full_fidelity.py +613 -0
- execweave/inference_identity.py +76 -0
- execweave/inference_identity_cli.py +60 -0
- execweave/integrity.py +235 -0
- execweave/integrity_cli.py +55 -0
- execweave/investigation_index.py +445 -0
- execweave/litellm_callback.py +211 -0
- execweave/litellm_callback_cli.py +42 -0
- execweave/live.py +445 -0
- execweave/live_core.py +972 -0
- execweave/live_view.py +109 -0
- execweave/live_view_extra_style.py +11 -0
- execweave/live_view_markup.py +29 -0
- execweave/live_view_process_layout.py +650 -0
- execweave/live_view_readability.py +502 -0
- execweave/live_view_script_a.py +59 -0
- execweave/live_view_script_b.py +97 -0
- execweave/live_view_script_c.py +59 -0
- execweave/live_view_script_d.py +40 -0
- execweave/live_view_style.py +34 -0
- execweave/model_runtime.py +560 -0
- execweave/model_runtime_cli.py +265 -0
- execweave/model_runtime_full_fidelity.py +519 -0
- execweave/observation.py +53 -0
- execweave/observation_demo.py +69 -0
- execweave/openai_agents.py +267 -0
- execweave/openai_agents_sdk.py +453 -0
- execweave/openai_compatible.py +239 -0
- execweave/openai_compatible_cli.py +189 -0
- execweave/openai_compatible_full_fidelity.py +438 -0
- execweave/opencode_adapter.py +325 -0
- execweave/opencode_event_contract.py +734 -0
- execweave/opencode_full_fidelity.py +198 -0
- execweave/opencode_hook_cli.py +119 -0
- execweave/opencode_plugin_cli.py +150 -0
- execweave/opencode_record.py +96 -0
- execweave/opencode_task_linkage.py +225 -0
- execweave/overhead_benchmark.py +440 -0
- execweave/privacy.py +84 -0
- execweave/private_io.py +465 -0
- execweave/provider_capability.py +578 -0
- execweave/provider_lifecycle.py +282 -0
- execweave/provider_record.py +290 -0
- execweave/reader_identity.py +13 -0
- execweave/redacted_archive.py +906 -0
- execweave/risk.py +106 -0
- execweave/rule_pack.py +359 -0
- execweave/rule_pack_cli.py +57 -0
- execweave/run_assessment.py +200 -0
- execweave/runtime_endpoint_availability.py +44 -0
- execweave/scalability_benchmark.py +195 -0
- execweave/schema.py +62 -0
- execweave/scope.py +85 -0
- execweave/semantic.py +453 -0
- execweave/session_summary.py +159 -0
- execweave/sink.py +71 -0
- execweave/strace_backend.py +927 -0
- execweave/stream_assembly.py +363 -0
- execweave/task_artifacts.py +192 -0
- execweave/task_validation.py +317 -0
- execweave/theme.py +40 -0
- execweave/top.py +599 -0
- execweave/top_cli.py +150 -0
- execweave/validate.py +196 -0
- execweave/vendor/dagre.min.js +815 -0
- execweave/view_cli.py +49 -0
- execweave/viewer.py +474 -0
- execweave/viewer_agent_panel.py +630 -0
- execweave/viewer_agent_panel_antigravity.py +31 -0
- execweave/viewer_agent_panel_claude.py +9 -0
- execweave/viewer_agent_panel_codex.py +50 -0
- execweave/viewer_agent_panel_cursor.py +9 -0
- execweave/viewer_agent_panel_default.py +79 -0
- execweave/viewer_agent_panel_ollama.py +20 -0
- execweave/viewer_agent_panel_opencode.py +9 -0
- execweave/viewer_agent_panel_registry.py +20 -0
- execweave/viewer_archive_verifier.py +178 -0
- execweave/viewer_background_files.py +86 -0
- execweave/viewer_content_browser.py +307 -0
- execweave/viewer_content_health.py +208 -0
- execweave/viewer_content_inspector.py +309 -0
- execweave/viewer_controlled_checks.py +258 -0
- execweave/viewer_conversation_sync.py +115 -0
- execweave/viewer_dashboard_clean.py +405 -0
- execweave/viewer_dashboard_focus.py +127 -0
- execweave/viewer_dashboard_hardening.py +264 -0
- execweave/viewer_dashboard_hardening_v2.py +62 -0
- execweave/viewer_dashboard_projection.py +261 -0
- execweave/viewer_delivery_status.py +155 -0
- execweave/viewer_edge_decross.py +117 -0
- execweave/viewer_execution_flow.py +611 -0
- execweave/viewer_execution_flow_provider_normalization.py +107 -0
- execweave/viewer_execution_flow_safety.py +349 -0
- execweave/viewer_external_endpoints.py +307 -0
- execweave/viewer_flow_canvas.py +1140 -0
- execweave/viewer_flow_layout.py +922 -0
- execweave/viewer_fold_state.py +31 -0
- execweave/viewer_framework_flow.py +68 -0
- execweave/viewer_framework_model_output.py +133 -0
- execweave/viewer_gif.py +278 -0
- execweave/viewer_history_browser.py +225 -0
- execweave/viewer_investigation.py +268 -0
- execweave/viewer_layout_geometry.py +192 -0
- execweave/viewer_layout_v2.py +429 -0
- execweave/viewer_layout_v2_detached.py +25 -0
- execweave/viewer_limits.py +93 -0
- execweave/viewer_live_layout.py +61 -0
- execweave/viewer_message_handoffs.py +114 -0
- execweave/viewer_projection.py +488 -0
- execweave/viewer_projection_base.py +522 -0
- execweave/viewer_projection_bridges.py +214 -0
- execweave/viewer_recorded_sources.py +146 -0
- execweave/viewer_run_assessment.py +274 -0
- execweave/viewer_run_guide.py +175 -0
- execweave/viewer_runtime_evidence.py +258 -0
- execweave/viewer_semantic_projection.py +641 -0
- execweave/viewer_session_flow.py +491 -0
- execweave/viewer_structure_share.py +132 -0
- execweave/viewer_task_validation.py +241 -0
- execweave/viewer_tool_mirror_identity.py +75 -0
- execweave/viewer_workflow_mode.py +127 -0
- execweave/workflow.py +183 -0
- execweave-1.0.0.dist-info/METADATA +462 -0
- execweave-1.0.0.dist-info/RECORD +234 -0
- execweave-1.0.0.dist-info/WHEEL +4 -0
- execweave-1.0.0.dist-info/entry_points.txt +30 -0
- execweave-1.0.0.dist-info/licenses/LICENSE +16 -0
|
@@ -0,0 +1,1140 @@
|
|
|
1
|
+
"""Solve the canvas layout over the graph the canvas actually draws.
|
|
2
|
+
|
|
3
|
+
``viewer_flow_layout`` lays out the projected graph, server side. The canvas draws a
|
|
4
|
+
different graph: it withholds whole node types for its own reasons, and it synthesises
|
|
5
|
+
nodes of its own -- a model context, an orchestration step -- that the projection never
|
|
6
|
+
saw. Columns solved on one graph and edges drawn on the other is what put a node behind
|
|
7
|
+
something that leads to it, so the edge folded back into its right-hand side.
|
|
8
|
+
|
|
9
|
+
So the projection's layers and rows arrive here as the preferred answer, not the final
|
|
10
|
+
one, and the column each node takes is solved again over exactly the set being drawn.
|
|
11
|
+
Every edge of that set that is not part of a cycle then runs strictly left to right, and
|
|
12
|
+
the rows the projection solved are kept wherever they do not collide.
|
|
13
|
+
|
|
14
|
+
Both seams fall back to the previous behaviour when a payload carries no ``viewer_flow``,
|
|
15
|
+
so an older run artifact, a compact payload, or a graph the layout declined to describe
|
|
16
|
+
still renders exactly as it did before.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
FLOW_CANVAS_SCRIPT = r"""
|
|
22
|
+
// Column pitch is measured, not assumed: a column is as wide as its widest label plus a
|
|
23
|
+
// gap, so a long path pushes only the columns after it instead of overlapping its
|
|
24
|
+
// neighbour. Mirrors what the lane table did, keyed on layer instead of type.
|
|
25
|
+
const EXECWEAVE_FLOW_COL_GAP=72,EXECWEAVE_FLOW_ROW_GAP=104,EXECWEAVE_FLOW_TOP=100;
|
|
26
|
+
// the clear space kept between two boxes stacked in the same column
|
|
27
|
+
const EXECWEAVE_FLOW_ROW_PAD=28;
|
|
28
|
+
let execweaveFlowSpec=null,execweaveFlowColumnX=null,execweaveFlowSolved=null;
|
|
29
|
+
function execweaveFlowPayload(){return execweaveFlowSpec}
|
|
30
|
+
function execweaveFlowInvalidate(){execweaveFlowColumnX=null;execweaveFlowSolved=null}
|
|
31
|
+
function execweaveRememberFlow(data){
|
|
32
|
+
const flow=data&&typeof data==='object'?data.viewer_flow:null;
|
|
33
|
+
if(flow&&Array.isArray(flow.nodes)){execweaveFlowSpec=flow;execweaveFlowInvalidate()}
|
|
34
|
+
return execweaveFlowSpec;
|
|
35
|
+
}
|
|
36
|
+
function execweaveFlowNodeIds(){
|
|
37
|
+
const flow=execweaveFlowSpec;
|
|
38
|
+
if(!flow||!Array.isArray(flow.nodes))return null;
|
|
39
|
+
const ids=new Set();
|
|
40
|
+
for(const entry of flow.nodes)if(entry&&entry.id)ids.add(String(entry.id));
|
|
41
|
+
return ids.size?ids:null;
|
|
42
|
+
}
|
|
43
|
+
// Every node the layout says it folded into another, so a node that is in neither list
|
|
44
|
+
// can be told apart from one that was deliberately hidden.
|
|
45
|
+
function execweaveFlowCollapsed(){
|
|
46
|
+
const flow=execweaveFlowSpec,ids=new Set();
|
|
47
|
+
const map=flow&&flow.collapsed;
|
|
48
|
+
if(map)for(const key of Object.keys(map))ids.add(String(key));
|
|
49
|
+
return ids;
|
|
50
|
+
}
|
|
51
|
+
// Narrow whatever the existing display filter produced to the set the projection says
|
|
52
|
+
// is drawn. Deliberately an intersection and not a replacement: the browser withholds
|
|
53
|
+
// types for its own reasons, and overriding that puts back nodes it meant to hide.
|
|
54
|
+
// Anything withheld stays in `graph`, so panels and lookups still find it.
|
|
55
|
+
function execweaveFlowDisplay(data,display){
|
|
56
|
+
execweaveRememberFlow(data);
|
|
57
|
+
const ids=execweaveFlowNodeIds();
|
|
58
|
+
if(!ids)return display;
|
|
59
|
+
const all=display.nodes||[];
|
|
60
|
+
// The display step ahead of this one owns the fold budget. It keeps the most recent
|
|
61
|
+
// members of a crowded type and adds one `viewer:folded:` node listing the rest, which
|
|
62
|
+
// the reader opens to reach them; the number it keeps is a setting the run chooses.
|
|
63
|
+
// The flow layout folds as well, and where the two disagree this one stands, because
|
|
64
|
+
// it is the one the reader asked for and the only one with a way back to what it hid.
|
|
65
|
+
const foldedTypes=new Set();
|
|
66
|
+
for(const node of all){
|
|
67
|
+
const members=node&&node.attributes&&node.attributes.viewer_folded_members;
|
|
68
|
+
if(!Array.isArray(members))continue;
|
|
69
|
+
foldedTypes.add(String(node.type||''));
|
|
70
|
+
for(const member of members)if(member&&member.type)foldedTypes.add(String(member.type));
|
|
71
|
+
}
|
|
72
|
+
const budgeted=node=>{
|
|
73
|
+
if(!node)return false;
|
|
74
|
+
if(node.attributes&&node.attributes.viewer_folded)return true;
|
|
75
|
+
return foldedTypes.has(String(node.type||''));
|
|
76
|
+
};
|
|
77
|
+
// A node the projection never saw -- one that arrived after the layout was worked out,
|
|
78
|
+
// or that the browser built for itself -- is not something this layout chose to hide.
|
|
79
|
+
// It has no entry saying it was folded into anything either, so dropping it would lose
|
|
80
|
+
// it outright. Keep it; the solver settles a column for it from what it connects to.
|
|
81
|
+
const folded=execweaveFlowCollapsed();
|
|
82
|
+
const known=node=>ids.has(String(node.id))||folded.has(String(node.id));
|
|
83
|
+
const nodes=all.filter(node=>node&&(ids.has(String(node.id))||budgeted(node)||!known(node)));
|
|
84
|
+
if(!nodes.length)return display;
|
|
85
|
+
const kept=new Set(nodes.map(node=>String(node.id)));
|
|
86
|
+
const edges=(display.edges||[]).filter(edge=>edge&&kept.has(String(edge.source))&&kept.has(String(edge.target)));
|
|
87
|
+
return{...display,nodes,edges,node_count:nodes.length,edge_count:edges.length};
|
|
88
|
+
}
|
|
89
|
+
// What the projection would like this node's column and row to be. Membership in its own
|
|
90
|
+
// node list, not the presence of the attributes: a node the browser synthesises from
|
|
91
|
+
// another one inherits that node's layer and row, and reading those back places it
|
|
92
|
+
// exactly on top of the node it was copied from.
|
|
93
|
+
function execweaveFlowPreference(id){
|
|
94
|
+
const projected=nodeById.get(id)?.attributes||{};
|
|
95
|
+
// The browser's session projection runs after the Python flow projection. Its
|
|
96
|
+
// explicit ranks supersede copied resource layers, including synthetic nodes.
|
|
97
|
+
if(Number.isInteger(projected.viewer_flow_rank)&&[...nodeById.values()].some(n=>n.attributes?.viewer_session_flow))return{layer:projected.viewer_flow_rank,row:0};
|
|
98
|
+
const owned=execweaveFlowNodeIds();
|
|
99
|
+
// A folded member is still drawn when the browser's file/type budget keeps it. Its
|
|
100
|
+
// annotation carries the survivor's solved layer and row, so keep that preference;
|
|
101
|
+
// treating it as a brand-new node makes the member drift away from the group the flow
|
|
102
|
+
// layout deliberately folded it into and raises crossings in a fully unfolded view.
|
|
103
|
+
if(owned&&!owned.has(String(id))&&!execweaveFlowCollapsed().has(String(id)))return null;
|
|
104
|
+
const node=nodeById.get(id);if(!node)return null;
|
|
105
|
+
const a=node.attributes||{};
|
|
106
|
+
if(!Number.isInteger(a.viewer_layer))return null;
|
|
107
|
+
// viewer_row is a solved coordinate and may be fractional; viewer_order is the ordinal
|
|
108
|
+
// it was derived from, and stands in for older payloads that carry no row.
|
|
109
|
+
const row=Number.isFinite(a.viewer_row)?a.viewer_row:a.viewer_order;
|
|
110
|
+
return{layer:a.viewer_layer,row:Number.isFinite(row)?row:null};
|
|
111
|
+
}
|
|
112
|
+
// The edges between the nodes on the canvas, as one entry per ordered pair. Two nodes
|
|
113
|
+
// joined by several relations are one constraint on the layout, not several. A pair is
|
|
114
|
+
// a return only when the session projection marked every one of its edges as one.
|
|
115
|
+
function execweaveFlowEdgePairs(){
|
|
116
|
+
const pairs=new Map();
|
|
117
|
+
if(typeof edgeById==='undefined')return pairs;
|
|
118
|
+
for(const edge of edgeById.values()){
|
|
119
|
+
const source=String(edge.source),target=String(edge.target);
|
|
120
|
+
if(source===target||!nodeById.has(source)||!nodeById.has(target))continue;
|
|
121
|
+
const key=source+'|'+target,returns=edge.viewer_flow_feedback===true;
|
|
122
|
+
if(!pairs.has(key))pairs.set(key,{source,target,returns});
|
|
123
|
+
else if(!returns)pairs.get(key).returns=false;
|
|
124
|
+
}
|
|
125
|
+
return pairs;
|
|
126
|
+
}
|
|
127
|
+
// Solve every drawn node's column and row together, over the drawn graph.
|
|
128
|
+
//
|
|
129
|
+
// A cycle has no left-to-right order, so one edge of each has to fold back whatever we
|
|
130
|
+
// do. Ranking the nodes first, and calling an edge that runs against that rank the
|
|
131
|
+
// feedback edge, picks which one: the projection's own layering is the rank wherever it
|
|
132
|
+
// has an opinion, so its decisions about direction survive, and a node it never saw takes
|
|
133
|
+
// a rank from the company it keeps. Longest path over what is left then puts every other
|
|
134
|
+
// edge on a strictly increasing column, which is the property that was missing.
|
|
135
|
+
function execweaveFlowSolve(){
|
|
136
|
+
const solved=new Map();
|
|
137
|
+
execweaveFlowSolved=solved;
|
|
138
|
+
if(typeof nodeById==='undefined'||!nodeById.size)return solved;
|
|
139
|
+
const ids=[...nodeById.keys()].map(String);
|
|
140
|
+
const pairs=[...execweaveFlowEdgePairs().values()];
|
|
141
|
+
const before=new Map(ids.map(id=>[id,[]])),after=new Map(ids.map(id=>[id,[]]));
|
|
142
|
+
for(const pair of pairs){after.get(pair.source).push(pair.target);before.get(pair.target).push(pair.source)}
|
|
143
|
+
|
|
144
|
+
const preference=new Map(ids.map(id=>[id,execweaveFlowPreference(id)]));
|
|
145
|
+
const hasPreference=[...preference.values()].some(value=>value!==null);
|
|
146
|
+
const rank=new Map(ids.map(id=>[id,preference.get(id)?preference.get(id).layer:null]));
|
|
147
|
+
// A node with no preference of its own settles just after whatever leads to it, or
|
|
148
|
+
// just before whatever it leads to. Repeat so a chain of them settles end to end.
|
|
149
|
+
for(let pass=0;pass<ids.length&&ids.some(id=>rank.get(id)===null);pass++){
|
|
150
|
+
let moved=false;
|
|
151
|
+
for(const id of ids){
|
|
152
|
+
if(rank.get(id)!==null)continue;
|
|
153
|
+
const back=before.get(id).map(peer=>rank.get(peer)).filter(value=>value!==null);
|
|
154
|
+
const fore=after.get(id).map(peer=>rank.get(peer)).filter(value=>value!==null);
|
|
155
|
+
if(!back.length&&!fore.length)continue;
|
|
156
|
+
rank.set(id,back.length?Math.max(...back)+1:Math.min(...fore)-1);moved=true;
|
|
157
|
+
}
|
|
158
|
+
if(!moved)break;
|
|
159
|
+
}
|
|
160
|
+
for(const id of ids)if(rank.get(id)===null)rank.set(id,0);
|
|
161
|
+
|
|
162
|
+
const order=new Map();
|
|
163
|
+
[...ids].sort((a,b)=>rank.get(a)-rank.get(b)||a.localeCompare(b)).forEach((id,index)=>order.set(id,index));
|
|
164
|
+
|
|
165
|
+
// Which edges fold back is decided by finding the cycles, not by comparing ranks: two
|
|
166
|
+
// nodes of equal rank would otherwise have their edge pointed by whichever id sorts
|
|
167
|
+
// first, and an orchestration step landed in the same column as the agents it targets
|
|
168
|
+
// because of it. An edge is feedback only when its target is already open on the search
|
|
169
|
+
// stack, which is to say only when it closes a cycle. Every other edge is kept, so a
|
|
170
|
+
// node always takes a column after the nodes that lead to it.
|
|
171
|
+
const feedback=new Set(),state=new Map(ids.map(id=>[id,0]));
|
|
172
|
+
// A recorded reply remains a return even if the dispatch was outside this
|
|
173
|
+
// recording; do not move the main agent behind its received message history.
|
|
174
|
+
// The session projection names its own returns (a child reporting back, an actor
|
|
175
|
+
// replying into its session); folding those keeps root, model and session leftmost.
|
|
176
|
+
for(const pair of pairs){
|
|
177
|
+
const source=nodeById.get(pair.source),target=nodeById.get(pair.target);
|
|
178
|
+
if(pair.returns||target?.attributes?.viewer_session_flow&&(source?.attributes?.viewer_framework_messages||source?.attributes?.viewer_return_message))feedback.add(pair.source+'|'+pair.target);
|
|
179
|
+
}
|
|
180
|
+
// With a viewer_flow payload, prefer the projection's layer order when choosing the
|
|
181
|
+
// DFS roots. Without one (the dashboard shell also accepts a raw static graph), keep
|
|
182
|
+
// the graph's insertion order: sorting IDs would visit `agent:child:*` before
|
|
183
|
+
// `agent:root` and incorrectly reverse SPAWNED_AGENT instead of SUBAGENT_STOPPED.
|
|
184
|
+
const roots=[...ids].sort((a,b)=>{
|
|
185
|
+
const pa=preference.get(a),pb=preference.get(b);
|
|
186
|
+
return pa&&pb&&pa.layer!==pb.layer?pa.layer-pb.layer:0;
|
|
187
|
+
});
|
|
188
|
+
for(const root of roots){
|
|
189
|
+
if(state.get(root))continue;
|
|
190
|
+
const stack=[{id:root,next:0}];
|
|
191
|
+
state.set(root,1);
|
|
192
|
+
while(stack.length){
|
|
193
|
+
const frame=stack[stack.length-1];
|
|
194
|
+
const peers=after.get(frame.id);
|
|
195
|
+
if(frame.next>=peers.length){state.set(frame.id,2);stack.pop();continue}
|
|
196
|
+
const peer=peers[frame.next++];
|
|
197
|
+
if(feedback.has(frame.id+'|'+peer))continue;
|
|
198
|
+
const seen=state.get(peer);
|
|
199
|
+
if(seen===1)feedback.add(frame.id+'|'+peer);
|
|
200
|
+
else if(seen===0){state.set(peer,1);stack.push({id:peer,next:0})}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
const parents=new Map(ids.map(id=>[id,[]])),pending=new Map(ids.map(id=>[id,0]));
|
|
204
|
+
for(const pair of pairs){
|
|
205
|
+
if(feedback.has(pair.source+'|'+pair.target))continue;
|
|
206
|
+
parents.get(pair.target).push(pair.source);
|
|
207
|
+
pending.set(pair.target,pending.get(pair.target)+1);
|
|
208
|
+
}
|
|
209
|
+
// The projection's own layer is a floor, not a starting point to be recomputed away: it
|
|
210
|
+
// counts depth through nodes the canvas hides, and rebuilding depth from the drawn edges
|
|
211
|
+
// alone collapses a run into three columns. Longest path only ever pushes a node further
|
|
212
|
+
// right, so every kept edge gains a column and the structure the projection found holds.
|
|
213
|
+
const layer=new Map(ids.map(id=>{
|
|
214
|
+
const want=preference.get(id);
|
|
215
|
+
return[id,want?want.layer:0];
|
|
216
|
+
}));
|
|
217
|
+
const ready=ids.filter(id=>!pending.get(id)).sort((a,b)=>order.get(a)-order.get(b));
|
|
218
|
+
for(let head=0;head<ready.length;head++){
|
|
219
|
+
const id=ready[head];
|
|
220
|
+
const depths=parents.get(id).map(peer=>layer.get(peer)+1);
|
|
221
|
+
if(depths.length)layer.set(id,Math.max(layer.get(id),...depths));
|
|
222
|
+
for(const peer of after.get(id)){
|
|
223
|
+
if(feedback.has(id+'|'+peer))continue;
|
|
224
|
+
pending.set(peer,pending.get(peer)-1);
|
|
225
|
+
if(!pending.get(peer))ready.push(peer);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// Rows: keep the row the projection solved, and give a node it never saw the average of
|
|
230
|
+
// the neighbours that do have one, so it lands beside its own edges. A raw static graph
|
|
231
|
+
// has no projection rows at all; seed those by the stable order within each solved
|
|
232
|
+
// column, rather than by the global node index (which leaves the first real column with
|
|
233
|
+
// a misleading gap and makes static/live dashboards disagree about child order).
|
|
234
|
+
const desired=new Map(ids.map(id=>{
|
|
235
|
+
const want=preference.get(id);
|
|
236
|
+
return[id,want&&want.row!==null?want.row:null];
|
|
237
|
+
}));
|
|
238
|
+
if(!hasPreference){
|
|
239
|
+
const byLayer=new Map();
|
|
240
|
+
for(const id of ids){
|
|
241
|
+
const value=layer.get(id);
|
|
242
|
+
if(!byLayer.has(value))byLayer.set(value,[]);
|
|
243
|
+
byLayer.get(value).push(id);
|
|
244
|
+
}
|
|
245
|
+
for(const members of byLayer.values()){
|
|
246
|
+
members.sort((a,b)=>order.get(a)-order.get(b));
|
|
247
|
+
members.forEach((id,index)=>desired.set(id,index));
|
|
248
|
+
}
|
|
249
|
+
}else{
|
|
250
|
+
for(let pass=0;pass<ids.length&&ids.some(id=>desired.get(id)===null);pass++){
|
|
251
|
+
let moved=false;
|
|
252
|
+
for(const id of ids){
|
|
253
|
+
if(desired.get(id)!==null)continue;
|
|
254
|
+
const rows=[...before.get(id),...after.get(id)].map(peer=>desired.get(peer)).filter(value=>value!==null);
|
|
255
|
+
if(!rows.length)continue;
|
|
256
|
+
desired.set(id,rows.reduce((a,b)=>a+b,0)/rows.length);moved=true;
|
|
257
|
+
}
|
|
258
|
+
if(!moved)break;
|
|
259
|
+
}
|
|
260
|
+
ids.forEach((id,index)=>{if(desired.get(id)===null)desired.set(id,index)});
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// Separate within a column, in the order the desired rows already imply, so a node only
|
|
264
|
+
// ever moves far enough to clear the one above it.
|
|
265
|
+
const columns=new Map();
|
|
266
|
+
for(const id of ids){
|
|
267
|
+
const value=layer.get(id);
|
|
268
|
+
if(!columns.has(value))columns.set(value,[]);
|
|
269
|
+
columns.get(value).push(id);
|
|
270
|
+
}
|
|
271
|
+
for(const [value,members] of columns){
|
|
272
|
+
members.sort((a,b)=>desired.get(a)-desired.get(b)||a.localeCompare(b));
|
|
273
|
+
let floor=-Infinity;
|
|
274
|
+
for(const id of members){
|
|
275
|
+
const row=Math.max(desired.get(id),floor+1);
|
|
276
|
+
solved.set(id,{layer:value,row});floor=row;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
// Order each column so the drawn links cross as few times as the columns allow: sweep by
|
|
280
|
+
// the mean row of each node's neighbours, keep the order that crosses the fewest links,
|
|
281
|
+
// then swap neighbours wherever that alone removes a crossing. A tie keeps the order it
|
|
282
|
+
// was given. Sessions keep their own order among themselves, because their names count
|
|
283
|
+
// up in it. A link back into an earlier column is drawn between the same two columns as
|
|
284
|
+
// one forward, so it is counted as one: leaving it out ordered a reply as if it were not
|
|
285
|
+
// there, and it crossed everything its sender sent below it.
|
|
286
|
+
const untangle=(layerOf,members)=>{
|
|
287
|
+
const values=[...members.keys()].sort((a,b)=>a-b);
|
|
288
|
+
const links=[];
|
|
289
|
+
for(const pair of pairs){
|
|
290
|
+
const l0=layerOf.get(pair.source),l1=layerOf.get(pair.target);
|
|
291
|
+
if(l0===undefined||l1===undefined||l0===l1)continue;
|
|
292
|
+
links.push(l0<l1?{source:pair.source,target:pair.target}:{source:pair.target,target:pair.source});
|
|
293
|
+
}
|
|
294
|
+
const peers=new Map([...layerOf.keys()].map(id=>[id,{back:[],fore:[]}]));
|
|
295
|
+
for(const pair of links){peers.get(pair.target).back.push(pair.source);peers.get(pair.source).fore.push(pair.target)}
|
|
296
|
+
const at=new Map(),place=()=>{for(const list of members.values())list.forEach((id,row)=>at.set(id,row))};
|
|
297
|
+
// A link that skips columns passes the columns between as well, at the height a straight
|
|
298
|
+
// line between its ends has there, which is where the router draws it unless a box
|
|
299
|
+
// stands in the way. Two links cross between two adjacent columns when their order
|
|
300
|
+
// there flips; counting only links between the same pair of columns would order a
|
|
301
|
+
// column as if the long links through it were not there. A box in the way is counted
|
|
302
|
+
// as well: the router has to bend the link around it, over or under the links that box
|
|
303
|
+
// sends on, and an order that leaves the line clear is the one that reads.
|
|
304
|
+
const index=new Map(values.map((value,i)=>[value,i]));
|
|
305
|
+
const crossings=()=>{
|
|
306
|
+
const gaps=new Map();let total=0;
|
|
307
|
+
for(const pair of links){
|
|
308
|
+
const l0=layerOf.get(pair.source),l1=layerOf.get(pair.target),r0=at.get(pair.source),r1=at.get(pair.target);
|
|
309
|
+
const height=i=>r0+(r1-r0)*(values[i]-l0)/(l1-l0);
|
|
310
|
+
for(let i=index.get(l0);i<index.get(l1);i++){
|
|
311
|
+
if(!gaps.has(i))gaps.set(i,[]);
|
|
312
|
+
gaps.get(i).push([height(i),height(i+1)]);
|
|
313
|
+
const y=height(i+1);
|
|
314
|
+
if(i+1<index.get(l1)&&y>-.4&&y<members.get(values[i+1]).length-.6&&Math.abs(y-Math.round(y))<.4)total++;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
for(const list of gaps.values())for(let i=0;i<list.length;i++)for(let j=i+1;j<list.length;j++){
|
|
318
|
+
if((list[i][0]-list[j][0])*(list[i][1]-list[j][1])<0)total++;
|
|
319
|
+
}
|
|
320
|
+
return total;
|
|
321
|
+
};
|
|
322
|
+
const isSession=id=>nodeById.get(id)?.type==='session';
|
|
323
|
+
const arrange=(list,side)=>{
|
|
324
|
+
const mean=new Map(list.map((id,row)=>{
|
|
325
|
+
const near=peers.get(id)[side];
|
|
326
|
+
return[id,near.length?near.reduce((sum,peer)=>sum+at.get(peer),0)/near.length:row];
|
|
327
|
+
}));
|
|
328
|
+
const next=[...list].sort((a,b)=>mean.get(a)-mean.get(b));
|
|
329
|
+
const sessions=list.filter(isSession);let k=0;
|
|
330
|
+
return next.map(id=>isSession(id)?sessions[k++]:id);
|
|
331
|
+
};
|
|
332
|
+
place();
|
|
333
|
+
let best=new Map([...members].map(([value,list])=>[value,[...list]]));
|
|
334
|
+
let fewest=links.length<=1500?crossings():0;
|
|
335
|
+
for(let round=0;round<4&&fewest>0;round++){
|
|
336
|
+
for(const [sweep,side] of [[values.slice(1),'back'],[values.slice(0,-1).reverse(),'fore']]){
|
|
337
|
+
for(const value of sweep){members.set(value,arrange(members.get(value),side));place()}
|
|
338
|
+
const now=crossings();
|
|
339
|
+
if(now<fewest){fewest=now;best=new Map([...members].map(([value,list])=>[value,[...list]]))}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
// Means tie whenever two nodes hang off the same neighbour, and the sweep cannot tell
|
|
343
|
+
// them apart then. Swap two neighbours in a column wherever that alone removes a
|
|
344
|
+
// crossing, until no swap does.
|
|
345
|
+
for(const [value,list] of best)members.set(value,[...list]);
|
|
346
|
+
place();
|
|
347
|
+
if(links.length<=250){
|
|
348
|
+
for(let pass=0,improved=true;improved&&fewest>0&&pass<8;pass++){
|
|
349
|
+
improved=false;
|
|
350
|
+
for(const list of members.values())for(let i=0;i+1<list.length&&fewest>0;i++){
|
|
351
|
+
if(isSession(list[i])&&isSession(list[i+1]))continue;
|
|
352
|
+
[list[i],list[i+1]]=[list[i+1],list[i]];place();
|
|
353
|
+
const now=crossings();
|
|
354
|
+
if(now<fewest){fewest=now;improved=true}else{[list[i],list[i+1]]=[list[i+1],list[i]];place()}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
return members;
|
|
359
|
+
};
|
|
360
|
+
// The session projection ranks its nodes into columns and leaves their order within a
|
|
361
|
+
// column to the canvas, where every node had row 0 and ties fell to the id: a model the
|
|
362
|
+
// run switched to sorted above the one it started with, and their edges into the
|
|
363
|
+
// session crossed for no reason. Start each column in the order its nodes first took
|
|
364
|
+
// part in the run and untangle from there; a tie keeps the earlier order, so time
|
|
365
|
+
// decides wherever the structure does not.
|
|
366
|
+
if(ids.some(id=>nodeById.get(id)?.attributes?.viewer_session_flow)&&ids.length<=400){
|
|
367
|
+
const pointOf=item=>({seq:item?.first_sequence,stamp:item?.first_seen});
|
|
368
|
+
const cmp=(p,q)=>Number.isInteger(p.seq)&&Number.isInteger(q.seq)?p.seq-q.seq
|
|
369
|
+
:!p.stamp-!q.stamp||String(p.stamp||'').localeCompare(String(q.stamp||''));
|
|
370
|
+
const first=new Map(ids.map(id=>[id,pointOf(nodeById.get(id))]));
|
|
371
|
+
for(const edge of edgeById.values()){
|
|
372
|
+
const point=pointOf(edge);
|
|
373
|
+
for(const id of [String(edge.source),String(edge.target)])if(first.has(id)&&cmp(point,first.get(id))<0)first.set(id,point);
|
|
374
|
+
}
|
|
375
|
+
const values=[...new Set(ids.map(id=>layer.get(id)))].sort((a,b)=>a-b);
|
|
376
|
+
const members=new Map(values.map(value=>[value,ids.filter(id=>layer.get(id)===value)
|
|
377
|
+
.sort((a,b)=>cmp(first.get(a),first.get(b))||a.localeCompare(b))]));
|
|
378
|
+
untangle(layer,members);
|
|
379
|
+
for(const [value,list] of members)list.forEach((id,row)=>solved.set(id,{layer:value,row}));
|
|
380
|
+
}
|
|
381
|
+
return solved;
|
|
382
|
+
}
|
|
383
|
+
function execweaveFlowCoords(id){
|
|
384
|
+
if(!execweaveFlowSolved)execweaveFlowSolve();
|
|
385
|
+
return execweaveFlowSolved.get(String(id))||null;
|
|
386
|
+
}
|
|
387
|
+
// A column must clear its widest box. The renderer's own measurement is the authority
|
|
388
|
+
// where it is available; where it is not, estimate from the label rather than assuming
|
|
389
|
+
// the minimum, because assuming the minimum is what lets a long label overlap the
|
|
390
|
+
// column beside it.
|
|
391
|
+
function execweaveFlowWidth(id){
|
|
392
|
+
try{const measured=execweaveWidthOf(id);if(Number.isFinite(measured)&&measured>0)return measured}catch(_){}
|
|
393
|
+
const node=nodeById.get(id),label=String(node&&(node.name||node.id)||'');
|
|
394
|
+
const estimated=label.length*7.1+EXECWEAVE_LABEL_PAD*2;
|
|
395
|
+
return Math.min(EXECWEAVE_NODE_W_MAX,Math.max(EXECWEAVE_NODE_W,estimated));
|
|
396
|
+
}
|
|
397
|
+
function execweaveFlowColumns(){
|
|
398
|
+
if(execweaveFlowColumnX)return execweaveFlowColumnX;
|
|
399
|
+
const widest=new Map();
|
|
400
|
+
for(const id of nodeById.keys()){
|
|
401
|
+
const at=execweaveFlowCoords(id);if(!at)continue;
|
|
402
|
+
const width=execweaveFlowWidth(id);
|
|
403
|
+
if(!widest.has(at.layer)||widest.get(at.layer)<width)widest.set(at.layer,width);
|
|
404
|
+
}
|
|
405
|
+
const x={};let cursor=0;
|
|
406
|
+
for(const value of [...widest.keys()].sort((a,b)=>a-b)){
|
|
407
|
+
x[value]=cursor;cursor+=widest.get(value)+EXECWEAVE_FLOW_COL_GAP;
|
|
408
|
+
}
|
|
409
|
+
execweaveFlowColumnX=x;return x;
|
|
410
|
+
}
|
|
411
|
+
// Every corner on a drawn edge comes from a route that was solved against positions the
|
|
412
|
+
// flow layout has since replaced. Dagre's polyline is the origin: `routePoints` holds it,
|
|
413
|
+
// `rawDagreRoutePoints` holds the pristine copy, and the retarget step re-seeds the first
|
|
414
|
+
// from the second on every route call -- so clearing only `routePoints` is undone before
|
|
415
|
+
// the next paint. Clearing both leaves the retarget with nothing to restore, and each
|
|
416
|
+
// edge falls back to the plain curve between its own two endpoints. An already-present
|
|
417
|
+
// empty Map is truthy, so the re-seed guard keeps it empty from then on.
|
|
418
|
+
function execweaveFlowScrubGeometry(topo){
|
|
419
|
+
if(!topo)return;
|
|
420
|
+
if(topo.routePoints)topo.routePoints=new Map();
|
|
421
|
+
if(topo.rawDagreRoutePoints)topo.rawDagreRoutePoints=new Map();
|
|
422
|
+
}
|
|
423
|
+
// A router picks which side of a box an edge leaves and enters by comparing the two
|
|
424
|
+
// nodes' ranks in the topology, not by comparing where they were actually drawn. Left as
|
|
425
|
+
// it was, an edge whose column the flow layout changed keeps the old answer and arrives
|
|
426
|
+
// at the right-hand side of a node that sits to the right of its source. The rank is the
|
|
427
|
+
// column, so say so.
|
|
428
|
+
function execweaveFlowSyncSpec(topo){
|
|
429
|
+
if(!topo||!topo.spec||!topo.spec.get)return;
|
|
430
|
+
for(const id of nodeById.keys()){
|
|
431
|
+
const at=execweaveFlowCoords(id),spec=topo.spec.get(id);
|
|
432
|
+
if(!at||!spec)continue;
|
|
433
|
+
spec.rank=at.layer;spec.order=at.row;
|
|
434
|
+
const p=positions.get(id);
|
|
435
|
+
if(p){spec.x=p.x;spec.y=p.y}
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
// Every edge on the canvas is drawn as a smooth curve. Two other shapes reach this
|
|
439
|
+
// point: a bundle draws its trunk as a horizontal-vertical-horizontal rail, and an
|
|
440
|
+
// ordinary edge arrives from dagre as a run of straight segments. Both put visible
|
|
441
|
+
// corners on the canvas, and both are there for a reason -- the run of segments is what
|
|
442
|
+
// steers an edge around the boxes between its ends. So the corners are rounded off
|
|
443
|
+
// rather than removed: the same points, in the same order, joined by a spline that
|
|
444
|
+
// passes through every one of them. The route still goes where it went, and the
|
|
445
|
+
// grouping a bundle carries is untouched -- the DOM keeps `data-bundle-size` and the
|
|
446
|
+
// panels that count members still read it.
|
|
447
|
+
let execweaveFlowRouteWrapped=false;
|
|
448
|
+
// Where this layout last put each node. Another authority -- Arrange, a drag -- may
|
|
449
|
+
// move a node afterwards, and once it has, the columns are no longer what is on screen
|
|
450
|
+
// and the geometry that belongs to them is no longer the geometry to draw.
|
|
451
|
+
const execweaveFlowPlaced=new Map();
|
|
452
|
+
// Read a path back as the points it visits. Only the commands the routers emit are
|
|
453
|
+
// understood; anything else means the path is not ours to redraw.
|
|
454
|
+
function execweaveFlowPathPoints(d){
|
|
455
|
+
const tokens=String(d).match(/[A-Za-z]|-?[0-9.]+/g);
|
|
456
|
+
if(!tokens)return null;
|
|
457
|
+
const points=[];let x=0,y=0,index=0;
|
|
458
|
+
while(index<tokens.length){
|
|
459
|
+
const command=tokens[index++];
|
|
460
|
+
if(!/[A-Za-z]/.test(command))return null;
|
|
461
|
+
const number=()=>{const value=Number(tokens[index++]);return Number.isFinite(value)?value:NaN};
|
|
462
|
+
if(command==='M'||command==='L'){x=number();y=number()}
|
|
463
|
+
else if(command==='H'){x=number()}
|
|
464
|
+
else if(command==='V'){y=number()}
|
|
465
|
+
else return null;
|
|
466
|
+
if(!Number.isFinite(x)||!Number.isFinite(y))return null;
|
|
467
|
+
points.push({x,y});
|
|
468
|
+
}
|
|
469
|
+
return points.length>=2?points:null;
|
|
470
|
+
}
|
|
471
|
+
// Catmull-Rom through the points, written out as the cubics an SVG path takes. The
|
|
472
|
+
// curve touches every original point, so an edge routed around a box still clears it.
|
|
473
|
+
function execweaveFlowSpline(points){
|
|
474
|
+
const parts=[`M ${points[0].x} ${points[0].y}`];
|
|
475
|
+
for(let i=0;i<points.length-1;i++){
|
|
476
|
+
const p0=points[i>0?i-1:0],p1=points[i],p2=points[i+1],p3=points[i+2<points.length?i+2:points.length-1];
|
|
477
|
+
// Half the usual control arm. A full Catmull-Rom arm overshoots the corner it is
|
|
478
|
+
// rounding, and the segments it rounds here are what steer an edge past a box, so
|
|
479
|
+
// an overshoot puts the curve back through the box the corner existed to avoid.
|
|
480
|
+
const c1x=Math.max(Math.min(p1.x+(p2.x-p0.x)/12,Math.max(p1.x,p2.x)),Math.min(p1.x,p2.x));
|
|
481
|
+
const c1y=Math.max(Math.min(p1.y+(p2.y-p0.y)/12,Math.max(p1.y,p2.y)),Math.min(p1.y,p2.y));
|
|
482
|
+
const c2x=Math.max(Math.min(p2.x-(p3.x-p1.x)/12,Math.max(p1.x,p2.x)),Math.min(p1.x,p2.x));
|
|
483
|
+
const c2y=Math.max(Math.min(p2.y-(p3.y-p1.y)/12,Math.max(p1.y,p2.y)),Math.min(p1.y,p2.y));
|
|
484
|
+
parts.push(`C ${c1x} ${c1y}, ${c2x} ${c2y}, ${p2.x} ${p2.y}`);
|
|
485
|
+
}
|
|
486
|
+
return parts.join(' ');
|
|
487
|
+
}
|
|
488
|
+
// An edge runs straight from one port to the other, and whatever sits between them is
|
|
489
|
+
// run straight through. The pipeline this layout replaces avoided that with dagre's
|
|
490
|
+
// route points, which were computed for the positions it replaced, so the avoidance has
|
|
491
|
+
// to be done again here. A blocker is any drawn box the run passes through, in any
|
|
492
|
+
// column -- the ones that reach the canvas are usually in the target's own column,
|
|
493
|
+
// stacked above and below it -- and each contributes one waypoint clear of whichever
|
|
494
|
+
// of its horizontal edges the run is nearer.
|
|
495
|
+
const EXECWEAVE_FLOW_CLEARANCE=8;
|
|
496
|
+
// The height of a drawn box, from whichever of the two authorities is in scope here.
|
|
497
|
+
function execweaveFlowBoxHeight(id){
|
|
498
|
+
if(typeof execweaveHeightOf==='function')return execweaveHeightOf(id);
|
|
499
|
+
const measured=execweaveTopology&&execweaveTopology.height&&execweaveTopology.height.get(id);
|
|
500
|
+
return Number.isFinite(measured)?measured:50;
|
|
501
|
+
}
|
|
502
|
+
function execweaveFlowHolds(id){
|
|
503
|
+
const placed=execweaveFlowPlaced.get(id),now=positions.get(id);
|
|
504
|
+
return !!placed&&!!now&&Math.abs(placed.x-now.x)<.5&&Math.abs(placed.y-now.y)<.5;
|
|
505
|
+
}
|
|
506
|
+
function execweaveFlowAvoid(edge,base){
|
|
507
|
+
if(!execweaveFlowHolds(edge.source)||!execweaveFlowHolds(edge.target))return null
|
|
508
|
+
if(!execweaveFlowCoords(edge.source)||!execweaveFlowCoords(edge.target))return null
|
|
509
|
+
const sp=positions.get(edge.source),tp=positions.get(edge.target);
|
|
510
|
+
if(!sp||!tp)return null;
|
|
511
|
+
// Two nodes in one column have no room between them for a line: drawn from the right
|
|
512
|
+
// edge of one to the left edge of the other it runs down the column and through every
|
|
513
|
+
// box on the way, and even a near-vertical curve leans far enough to clip its
|
|
514
|
+
// neighbour. Take it out into the empty space beside the column and back.
|
|
515
|
+
const fromAt=execweaveFlowCoords(edge.source),toAt=execweaveFlowCoords(edge.target);
|
|
516
|
+
if(fromAt&&toAt&&fromAt.layer===toAt.layer){
|
|
517
|
+
const edgeOf=id=>positions.get(id).x+execweaveWidthOf(id);
|
|
518
|
+
const sourceEdge=edgeOf(edge.source),targetEdge=edgeOf(edge.target);
|
|
519
|
+
const side=Math.max(sourceEdge,targetEdge);
|
|
520
|
+
const centre=id=>positions.get(id).y+execweaveFlowBoxHeight(id)/2;
|
|
521
|
+
const a=execweaveFlowPortAt(edge,'s',centre(edge.source)),z=execweaveFlowPortAt(edge,'t',centre(edge.target));
|
|
522
|
+
const rail=side+EXECWEAVE_FLOW_COL_GAP*.45;
|
|
523
|
+
return Object.assign({},base,{d:`M ${sourceEdge} ${a} C ${rail} ${a}, ${rail} ${z}, ${targetEdge} ${z}`,
|
|
524
|
+
labelX:side+EXECWEAVE_FLOW_COL_GAP*.45,labelY:(a+z)/2-8});
|
|
525
|
+
}
|
|
526
|
+
const run=execweaveFlowRunOf(edge);
|
|
527
|
+
if(!run)return null;
|
|
528
|
+
execweaveFlowLaneApply(edge,run);
|
|
529
|
+
const points=run.back?run.points.slice().reverse():run.points;
|
|
530
|
+
return Object.assign({},base,{d:execweaveFlowSpline(points),labelX:run.labelX,labelY:run.labelY});
|
|
531
|
+
}
|
|
532
|
+
// The run an edge between two columns takes, solved left to right; `back` is set on one
|
|
533
|
+
// drawn the other way. Null when the edge is not this layout's to draw.
|
|
534
|
+
function execweaveFlowRunOf(edge){
|
|
535
|
+
if(!execweaveFlowHolds(edge.source)||!execweaveFlowHolds(edge.target))return null;
|
|
536
|
+
const fromAt=execweaveFlowCoords(edge.source),toAt=execweaveFlowCoords(edge.target);
|
|
537
|
+
if(!fromAt||!toAt||fromAt.layer===toAt.layer)return null;
|
|
538
|
+
const sp=positions.get(edge.source),tp=positions.get(edge.target);
|
|
539
|
+
if(!sp||!tp)return null;
|
|
540
|
+
const id=edgeId(edge),topo=execweaveTopology;
|
|
541
|
+
const sx=sp.x+execweaveWidthOf(edge.source),tx=tp.x;
|
|
542
|
+
const sy=execweaveFlowPortAt(edge,'s',execweavePortY(sp,topo.sourcePort.get(id),edge.source));
|
|
543
|
+
const ty=execweaveFlowPortAt(edge,'t',execweavePortY(tp,topo.targetPort.get(id),edge.target));
|
|
544
|
+
if(tx-sx>1)return execweaveFlowRun(edge,sx,sy,tx,ty,tp.x);
|
|
545
|
+
// An edge into a column further left -- a reply routed back to the agent it answers --
|
|
546
|
+
// leaves the left side of its source and enters the right side of its target. Solved
|
|
547
|
+
// left to right as the run between those two sides and drawn the other way, it clears
|
|
548
|
+
// the same boxes a forward edge would, and its arrow still faces its target.
|
|
549
|
+
const back=tp.x+execweaveWidthOf(edge.target),front=sp.x;
|
|
550
|
+
if(!(front-back>1))return null;
|
|
551
|
+
return Object.assign(execweaveFlowRun(edge,back,ty,front,sy,sp.x,true),{back:true});
|
|
552
|
+
}
|
|
553
|
+
// Where on its box each line leaves and arrives. A box's left side takes the lines that
|
|
554
|
+
// come into it and the ones that go back out of it to a column further left; its right
|
|
555
|
+
// side takes the lines that leave it, the ones that come back into it, and the ones drawn
|
|
556
|
+
// beside its own column. Counted apart, an arrow coming in and a line going out of the
|
|
557
|
+
// same side are both put at its middle, and one line arriving where another leaves reads
|
|
558
|
+
// as a single line with its arrow at the wrong end.
|
|
559
|
+
// A side is shared out top to bottom in the order its lines head off in. That is not the
|
|
560
|
+
// order of the boxes at their other ends: a line to a box level with this one that has to
|
|
561
|
+
// go over the boxes between heads up, and given the lower port it cuts across the line
|
|
562
|
+
// that runs straight. So the runs are laid out once with the sides shared out by the
|
|
563
|
+
// boxes at the other ends, and the sides shared out again by the height each run turns
|
|
564
|
+
// to first. Lines of one kind, drawn alike, that come together at the same turn before
|
|
565
|
+
// reaching this box already run as one line from there, so they are given one port and
|
|
566
|
+
// end in one arrow instead of a row of arrows splitting off the last few pixels.
|
|
567
|
+
let execweaveFlowPorts=null;
|
|
568
|
+
function execweaveFlowPortPlan(){
|
|
569
|
+
if(typeof edgeById==='undefined')return null;
|
|
570
|
+
const key=execweaveFlowLaneKey();
|
|
571
|
+
if(execweaveFlowPorts&&execweaveFlowPorts.key===key&&execweaveFlowPorts.edges===edgeById)return execweaveFlowPorts;
|
|
572
|
+
const plan={key,edges:edgeById,at:new Map()};
|
|
573
|
+
execweaveFlowPorts=plan;
|
|
574
|
+
if(edgeById.size>400)return plan;
|
|
575
|
+
const sides=new Map();
|
|
576
|
+
const add=(node,side,end,other,edge)=>{
|
|
577
|
+
if(!sides.has(node))sides.set(node,{left:[],right:[]});
|
|
578
|
+
sides.get(node)[side].push({end,other,kind:`${String(edge.relation||'')}\0${edge.causal===true?'c':edge.causal===false?'n':''}${edge.inferred===true?'i':''}`});
|
|
579
|
+
};
|
|
580
|
+
const drawn=[];
|
|
581
|
+
for(const edge of edgeById.values()){
|
|
582
|
+
if(!execweaveFlowHolds(edge.source)||!execweaveFlowHolds(edge.target))continue;
|
|
583
|
+
const fromAt=execweaveFlowCoords(edge.source),toAt=execweaveFlowCoords(edge.target);
|
|
584
|
+
if(!fromAt||!toAt)continue;
|
|
585
|
+
const sp=positions.get(edge.source),tp=positions.get(edge.target);
|
|
586
|
+
if(!sp||!tp)continue;
|
|
587
|
+
const id=edgeId(edge);
|
|
588
|
+
let from,to;
|
|
589
|
+
if(fromAt.layer===toAt.layer){from='right';to='right'}
|
|
590
|
+
else if(tp.x-(sp.x+execweaveWidthOf(edge.source))>1){from='right';to='left'}
|
|
591
|
+
else if(sp.x-(tp.x+execweaveWidthOf(edge.target))>1){from='left';to='right'}
|
|
592
|
+
else continue;
|
|
593
|
+
add(edge.source,from,id+'>s',edge.target,edge);
|
|
594
|
+
add(edge.target,to,id+'>t',edge.source,edge);
|
|
595
|
+
if(fromAt.layer!==toAt.layer)drawn.push(edge);
|
|
596
|
+
}
|
|
597
|
+
const centre=id=>positions.get(id).y+execweaveFlowBoxHeight(id)/2;
|
|
598
|
+
const share=(at,towards,turn)=>{
|
|
599
|
+
for(const [node,both] of sides){
|
|
600
|
+
const box=positions.get(node),height=execweaveFlowBoxHeight(node);
|
|
601
|
+
for(const list of [both.left,both.right]){
|
|
602
|
+
list.sort((a,b)=>towards(a)-towards(b)||centre(a.other)-centre(b.other)||positions.get(a.other).x-positions.get(b.other).x||(a.end<b.end?-1:a.end>b.end?1:0));
|
|
603
|
+
const slots=new Map(),slotOf=list.map(entry=>{
|
|
604
|
+
const at=turn&&turn.get(entry.end),key=at==null?entry.end:`${entry.kind}\0${at}`;
|
|
605
|
+
if(!slots.has(key))slots.set(key,slots.size);
|
|
606
|
+
return slots.get(key);
|
|
607
|
+
});
|
|
608
|
+
list.forEach((entry,index)=>at.set(entry.end,slots.size<2?box.y+height/2:box.y+10+(height-20)*slotOf[index]/(slots.size-1)));
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
};
|
|
612
|
+
share(plan.at,entry=>centre(entry.other));
|
|
613
|
+
// The height a run first turns to, away from the port at one end of it: the first
|
|
614
|
+
// stop at another height after the start, or the last one before the end. Where that
|
|
615
|
+
// stop is a bend on the way rather than the far end, it is also the turn the line
|
|
616
|
+
// comes from.
|
|
617
|
+
const heads=new Map(),turns=new Map();
|
|
618
|
+
for(const edge of drawn){
|
|
619
|
+
let run=null;
|
|
620
|
+
try{run=execweaveFlowRunOf(edge)}catch(_){run=null}
|
|
621
|
+
if(!run||run.points.length<2)continue;
|
|
622
|
+
const points=run.points,last=points.length-1,id=edgeId(edge);
|
|
623
|
+
let firstAt=last,finalAt=0;
|
|
624
|
+
for(let i=1;i<=last;i++)if(Math.abs(points[i].y-points[0].y)>.5){firstAt=i;break}
|
|
625
|
+
for(let i=last-1;i>=0;i--)if(Math.abs(points[i].y-points[last].y)>.5){finalAt=i;break}
|
|
626
|
+
heads.set(id+(run.back?'>t':'>s'),Math.round(points[firstAt].y));
|
|
627
|
+
heads.set(id+(run.back?'>s':'>t'),Math.round(points[finalAt].y));
|
|
628
|
+
if(firstAt<last)turns.set(id+(run.back?'>t':'>s'),`${Math.round(points[firstAt].x)},${Math.round(points[firstAt].y)}`);
|
|
629
|
+
if(finalAt>0)turns.set(id+(run.back?'>s':'>t'),`${Math.round(points[finalAt].x)},${Math.round(points[finalAt].y)}`);
|
|
630
|
+
}
|
|
631
|
+
const at=new Map();
|
|
632
|
+
share(at,entry=>heads.has(entry.end)?heads.get(entry.end):Math.round(centre(entry.other)),turns);
|
|
633
|
+
plan.at=at;
|
|
634
|
+
return plan;
|
|
635
|
+
}
|
|
636
|
+
// The height this edge leaves its source ('s') or enters its target ('t') at; `fallback`
|
|
637
|
+
// where the plan has none: a canvas too large to plan, or a line this layout does not draw.
|
|
638
|
+
function execweaveFlowPortAt(edge,end,fallback){
|
|
639
|
+
let plan=null;
|
|
640
|
+
try{plan=execweaveFlowPortPlan()}catch(_){plan=null}
|
|
641
|
+
const at=plan&&plan.at.get(edgeId(edge)+'>'+end);
|
|
642
|
+
return Number.isFinite(at)?at:fallback;
|
|
643
|
+
}
|
|
644
|
+
// Runs that clear the same boxes the same way are sent to the same height, and where
|
|
645
|
+
// their level stretches meet they are drawn as one line: nothing on the canvas says which
|
|
646
|
+
// end belongs to which. Two runs that share an end and are drawn alike may merge, since
|
|
647
|
+
// they meet at that box anyway; a solid line laid over a dashed one would read as neither,
|
|
648
|
+
// so those, and any other two that would run along one height, are put on lanes a few pixels
|
|
649
|
+
// apart. The shorter stretch keeps the height it was given, nearest the boxes, and the
|
|
650
|
+
// longer is moved out past it, so a stretch lying inside another is not crossed by it.
|
|
651
|
+
// A lane depends on every other run at that height, so all runs are laid out together
|
|
652
|
+
// and the lanes kept until something moves or the graph changes.
|
|
653
|
+
const EXECWEAVE_FLOW_LANE=8;
|
|
654
|
+
let execweaveFlowLanes=null;
|
|
655
|
+
function execweaveFlowLaneKey(){
|
|
656
|
+
let key=Math.imul(edgeById.size+1,0x9e3779b1)^nodeById.size;
|
|
657
|
+
for(const p of positions.values()){
|
|
658
|
+
key=Math.imul(key^Math.round(p.x*2),0x85ebca6b);
|
|
659
|
+
key=Math.imul(key^Math.round(p.y*2),0xc2b2ae35);
|
|
660
|
+
}
|
|
661
|
+
return key;
|
|
662
|
+
}
|
|
663
|
+
function execweaveFlowLevels(points){
|
|
664
|
+
const levels=[];
|
|
665
|
+
for(let i=1;i+2<points.length;i++){
|
|
666
|
+
const a=points[i],b=points[i+1];
|
|
667
|
+
if(Math.abs(a.y-b.y)>.5||Math.abs(a.x-b.x)<4)continue;
|
|
668
|
+
const last=levels[levels.length-1];
|
|
669
|
+
if(last&&last.to===i&&Math.abs(last.y-a.y)<=.5){last.to=i+1;last.hi=Math.max(last.hi,b.x);continue}
|
|
670
|
+
levels.push({from:i,to:i+1,y:a.y,lo:Math.min(a.x,b.x),hi:Math.max(a.x,b.x)});
|
|
671
|
+
}
|
|
672
|
+
return levels;
|
|
673
|
+
}
|
|
674
|
+
function execweaveFlowLanePlan(){
|
|
675
|
+
if(typeof edgeById==='undefined')return null;
|
|
676
|
+
const key=execweaveFlowLaneKey();
|
|
677
|
+
if(execweaveFlowLanes&&execweaveFlowLanes.key===key&&execweaveFlowLanes.edges===edgeById)return execweaveFlowLanes;
|
|
678
|
+
const plan={key,edges:edgeById,shift:new Map()};
|
|
679
|
+
execweaveFlowLanes=plan;
|
|
680
|
+
if(edgeById.size>400)return plan;
|
|
681
|
+
const levels=[];
|
|
682
|
+
for(const edge of edgeById.values()){
|
|
683
|
+
let run=null;
|
|
684
|
+
try{run=execweaveFlowRunOf(edge)}catch(_){run=null}
|
|
685
|
+
if(!run)continue;
|
|
686
|
+
for(const level of execweaveFlowLevels(run.points))levels.push(Object.assign(level,{edge,id:edgeId(edge),points:run.points}));
|
|
687
|
+
}
|
|
688
|
+
const look=edge=>`${edge.causal===true?'c':edge.causal===false?'n':''}${edge.inferred===true?'i':''}`;
|
|
689
|
+
const near=24,meets=(a,b)=>(a.edge.source===b.edge.source||a.edge.target===b.edge.target)&&look(a.edge)===look(b.edge);
|
|
690
|
+
const groups=new Map();
|
|
691
|
+
for(const level of levels){const at=Math.round(level.y);if(!groups.has(at))groups.set(at,[]);groups.get(at).push(level)}
|
|
692
|
+
for(const group of groups.values()){
|
|
693
|
+
if(group.length<2)continue;
|
|
694
|
+
group.sort((a,b)=>(a.hi-a.lo)-(b.hi-b.lo)||(a.id<b.id?-1:a.id>b.id?1:a.from-b.from));
|
|
695
|
+
const lane=new Map();
|
|
696
|
+
for(const level of group){
|
|
697
|
+
const used=new Set();
|
|
698
|
+
for(const [other,value] of lane){
|
|
699
|
+
if(meets(level,other))continue;
|
|
700
|
+
if(level.lo<other.hi+near&&other.lo<level.hi+near)used.add(value);
|
|
701
|
+
}
|
|
702
|
+
let value=0;while(used.has(value))value++;
|
|
703
|
+
lane.set(level,value);
|
|
704
|
+
}
|
|
705
|
+
for(const [level,value] of lane){
|
|
706
|
+
if(!value)continue;
|
|
707
|
+
// Out towards whichever side has the more room above or below this stretch.
|
|
708
|
+
const pad=EXECWEAVE_FLOW_CLEARANCE;let up=Infinity,down=Infinity;
|
|
709
|
+
for(const other of nodeById.keys()){
|
|
710
|
+
const box=positions.get(other);if(!box)continue;
|
|
711
|
+
if(box.x+execweaveWidthOf(other)+pad<=level.lo||box.x-pad>=level.hi)continue;
|
|
712
|
+
const top=box.y-pad,bottom=box.y+execweaveFlowBoxHeight(other)+pad;
|
|
713
|
+
if(bottom<=level.y)up=Math.min(up,level.y-bottom);
|
|
714
|
+
else if(top>=level.y)down=Math.min(down,top-level.y);
|
|
715
|
+
}
|
|
716
|
+
const room=Math.max(up,down),offset=value*EXECWEAVE_FLOW_LANE;
|
|
717
|
+
if(offset>room-2)continue;
|
|
718
|
+
const moved=level.points.map((p,i)=>i>=level.from&&i<=level.to?{x:p.x,y:p.y+(up>=down?-offset:offset)}:p);
|
|
719
|
+
if(execweaveFlowBoxHits(level.edge,moved)>execweaveFlowBoxHits(level.edge,level.points))continue;
|
|
720
|
+
if(!plan.shift.has(level.id))plan.shift.set(level.id,[]);
|
|
721
|
+
plan.shift.get(level.id).push({from:level.from,to:level.to,y:level.y,by:up>=down?-offset:offset});
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
return plan;
|
|
725
|
+
}
|
|
726
|
+
// Move this run's level stretches onto the lanes the plan gave them, but only where the
|
|
727
|
+
// run is still the one the plan was made from.
|
|
728
|
+
function execweaveFlowLaneApply(edge,run){
|
|
729
|
+
let plan=null;
|
|
730
|
+
try{plan=execweaveFlowLanePlan()}catch(_){plan=null}
|
|
731
|
+
const moves=plan&&plan.shift.get(edgeId(edge));
|
|
732
|
+
if(!moves)return run;
|
|
733
|
+
for(const move of moves){
|
|
734
|
+
const span=run.points.slice(move.from,move.to+1);
|
|
735
|
+
if(span.length!==move.to-move.from+1||span.some(p=>Math.abs(p.y-move.y)>.5))continue;
|
|
736
|
+
const lo=Math.min(...span.map(p=>p.x)),hi=Math.max(...span.map(p=>p.x));
|
|
737
|
+
for(let i=move.from;i<=move.to;i++)run.points[i]={x:run.points[i].x,y:run.points[i].y+move.by};
|
|
738
|
+
if(Math.abs(run.labelY+8-move.y)<=.5&&run.labelX>=lo&&run.labelX<=hi)run.labelY+=move.by;
|
|
739
|
+
}
|
|
740
|
+
return run;
|
|
741
|
+
}
|
|
742
|
+
// What a run would cost to draw: first every box its straight pieces pass through, since
|
|
743
|
+
// clearing one column can aim the rest of the run into a box further on; then how many
|
|
744
|
+
// of the other links it would cross, each link taken as the straight line from the side
|
|
745
|
+
// of its source it leaves to the side of its target it enters. A link within one column,
|
|
746
|
+
// or one that shares an end with this one, is left out: the first is drawn beside its
|
|
747
|
+
// column, and the second meets this run at a box, not across it.
|
|
748
|
+
function execweaveFlowBoxHits(edge,points){
|
|
749
|
+
const pad=EXECWEAVE_FLOW_CLEARANCE;
|
|
750
|
+
let total=0;
|
|
751
|
+
for(const other of nodeById.keys()){
|
|
752
|
+
if(other===edge.source||other===edge.target)continue;
|
|
753
|
+
const box=positions.get(other);if(!box)continue;
|
|
754
|
+
const left=box.x-pad,right=box.x+execweaveWidthOf(other)+pad;
|
|
755
|
+
const top=box.y-pad,bottom=box.y+execweaveFlowBoxHeight(other)+pad;
|
|
756
|
+
for(let i=0;i+1<points.length;i++){
|
|
757
|
+
const a=points[i],b=points[i+1];
|
|
758
|
+
const lo=Math.max(Math.min(a.x,b.x),left),hi=Math.min(Math.max(a.x,b.x),right);
|
|
759
|
+
if(!(hi>lo))continue;
|
|
760
|
+
const at=x=>b.x===a.x?a.y:a.y+(b.y-a.y)*(x-a.x)/(b.x-a.x);
|
|
761
|
+
const ya=at(lo),yb=at(hi);
|
|
762
|
+
if(Math.max(ya,yb)>top&&Math.min(ya,yb)<bottom){total++;break}
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
return total;
|
|
766
|
+
}
|
|
767
|
+
function execweaveFlowCrossings(edge,points){
|
|
768
|
+
let total=execweaveFlowBoxHits(edge,points)*1000;
|
|
769
|
+
if(typeof edgeById==='undefined'||edgeById.size>400)return total;
|
|
770
|
+
const cut=(a,b,c,d)=>{
|
|
771
|
+
const side=(p,q,r)=>(q.x-p.x)*(r.y-p.y)-(q.y-p.y)*(r.x-p.x);
|
|
772
|
+
return side(a,b,c)*side(a,b,d)<0&&side(c,d,a)*side(c,d,b)<0;
|
|
773
|
+
};
|
|
774
|
+
for(const other of edgeById.values()){
|
|
775
|
+
if(other===edge)continue;
|
|
776
|
+
if(other.source===edge.source||other.source===edge.target||other.target===edge.source||other.target===edge.target)continue;
|
|
777
|
+
const sp=positions.get(other.source),tp=positions.get(other.target);
|
|
778
|
+
if(!sp||!tp)continue;
|
|
779
|
+
const from=execweaveFlowCoords(other.source),to=execweaveFlowCoords(other.target);
|
|
780
|
+
if(from&&to&&from.layer===to.layer)continue;
|
|
781
|
+
const sw=execweaveWidthOf(other.source),tw=execweaveWidthOf(other.target);
|
|
782
|
+
const sm=sp.y+execweaveFlowBoxHeight(other.source)/2,tm=tp.y+execweaveFlowBoxHeight(other.target)/2;
|
|
783
|
+
const chord=sp.x+sw<=tp.x?[{x:sp.x+sw,y:sm},{x:tp.x,y:tm}]:[{x:tp.x+tw,y:tm},{x:sp.x,y:sm}];
|
|
784
|
+
for(let i=0;i+1<points.length;i++)if(cut(points[i],points[i+1],chord[0],chord[1])){total++;break}
|
|
785
|
+
}
|
|
786
|
+
return total;
|
|
787
|
+
}
|
|
788
|
+
// The run from (sx,sy) to (tx,ty), left to right, stepped around every box between. The
|
|
789
|
+
// box whose column the run ends in starts at endX. A returning run starts at the box it
|
|
790
|
+
// returns to.
|
|
791
|
+
function execweaveFlowRun(edge,sx,sy,tx,ty,endX,returning){
|
|
792
|
+
const runY=x=>sy+(ty-sy)*(x-sx)/(tx-sx);
|
|
793
|
+
const waypoints=[],blocked=[];let approach=false;
|
|
794
|
+
for(const other of nodeById.keys()){
|
|
795
|
+
if(other===edge.source||other===edge.target)continue;
|
|
796
|
+
// Any box on the canvas is in the way, whether or not this layout placed it.
|
|
797
|
+
const box=positions.get(other);if(!box)continue;
|
|
798
|
+
const pad=EXECWEAVE_FLOW_CLEARANCE;
|
|
799
|
+
const left=box.x-pad,right=box.x+execweaveWidthOf(other)+pad;
|
|
800
|
+
const top=box.y-pad,bottom=box.y+execweaveFlowBoxHeight(other)+pad;
|
|
801
|
+
// the part of the run that lies within the box's columns, if any
|
|
802
|
+
const lo=Math.max(sx,Math.min(tx,left)),hi=Math.max(sx,Math.min(tx,right));
|
|
803
|
+
if(!(hi-lo>1))continue;
|
|
804
|
+
const ya=runY(lo),yb=runY(hi);
|
|
805
|
+
if(Math.max(ya,yb)<top||Math.min(ya,yb)>bottom)continue;
|
|
806
|
+
// A blocker standing in the target's own column cannot be stepped over inside that
|
|
807
|
+
// column: the run has nowhere left to go before the port. What clears it is to reach
|
|
808
|
+
// the port's height while there is still room, and come in level.
|
|
809
|
+
if(box.x>=endX-1){approach=true;continue}
|
|
810
|
+
blocked.push({lo,hi});
|
|
811
|
+
}
|
|
812
|
+
// Clear a column for its whole width, not only at its middle: one waypoint in the
|
|
813
|
+
// centre lets the curve back in on the way to it. Two, one at each side, carry the run
|
|
814
|
+
// level past it. Every box in the column is cleared at once, through whichever opening
|
|
815
|
+
// lies nearest the line -- above the column, below it, or the gap between two boxes --
|
|
816
|
+
// since clearing them one at a time sends the run over one box and under the next, and
|
|
817
|
+
// two such stops in one column can only be resolved by leaving the column altogether.
|
|
818
|
+
blocked.sort((a,b)=>a.lo-b.lo);
|
|
819
|
+
const columns=[];
|
|
820
|
+
for(const span of blocked){
|
|
821
|
+
const last=columns[columns.length-1];
|
|
822
|
+
if(last&&span.lo<last.hi)last.hi=Math.max(last.hi,span.hi);else columns.push({...span});
|
|
823
|
+
}
|
|
824
|
+
for(const {lo,hi} of columns){
|
|
825
|
+
const pad=EXECWEAVE_FLOW_CLEARANCE,here=runY((lo+hi)/2),taken=[];
|
|
826
|
+
for(const other of nodeById.keys()){
|
|
827
|
+
if(other===edge.source||other===edge.target)continue;
|
|
828
|
+
const box=positions.get(other);if(!box)continue;
|
|
829
|
+
if(box.x+execweaveWidthOf(other)+pad<=lo||box.x-pad>=hi)continue;
|
|
830
|
+
taken.push([box.y-pad-10,box.y+execweaveFlowBoxHeight(other)+pad+10]);
|
|
831
|
+
}
|
|
832
|
+
taken.sort((a,b)=>a[0]-b[0]);
|
|
833
|
+
// The nearest opening above the line and the nearest below it are both short ways
|
|
834
|
+
// round; of the two, take the one that runs into fewer boxes and crosses fewer of the
|
|
835
|
+
// other links, and the nearer only when they cost the same.
|
|
836
|
+
let above=null,below=null,floor=-Infinity;
|
|
837
|
+
const open=(from,to)=>{
|
|
838
|
+
if(!(to>=from))return;
|
|
839
|
+
const y=Math.min(to,Math.max(from,here));
|
|
840
|
+
if(y<=here&&(above===null||y>above))above=y;
|
|
841
|
+
if(y>=here&&(below===null||y<below))below=y;
|
|
842
|
+
};
|
|
843
|
+
for(const [top,bottom] of taken){open(floor,top);floor=Math.max(floor,bottom)}
|
|
844
|
+
open(floor,Infinity);
|
|
845
|
+
const options=[above,below].filter(y=>y!==null);
|
|
846
|
+
const cost=y=>execweaveFlowCrossings(edge,[{x:sx,y:sy},{x:lo,y},{x:hi,y},{x:tx,y:ty}]);
|
|
847
|
+
let clear=options[0];
|
|
848
|
+
if(options.length>1&&above!==below){
|
|
849
|
+
const up=cost(above),down=cost(below);
|
|
850
|
+
clear=up<down?above:down<up?below:Math.abs(above-here)<=Math.abs(below-here)?above:below;
|
|
851
|
+
}
|
|
852
|
+
waypoints.push({x:lo,y:clear},{x:hi,y:clear});
|
|
853
|
+
}
|
|
854
|
+
if(approach)waypoints.push({x:tx-Math.min(44,(tx-sx)*.45),y:ty});
|
|
855
|
+
// A run that falls much further than it travels cannot be stepped past box by box:
|
|
856
|
+
// clipped to any one box's width it is a sliver, and every box in that column stands
|
|
857
|
+
// in it, so the stops pile up in a few pixels and read as a scribble. The space between
|
|
858
|
+
// two columns is empty by construction, so the descent belongs there instead. Enter a
|
|
859
|
+
// clear horizontal band before the first middle box, cross the full middle span, then
|
|
860
|
+
// come back to the port level after the last one; stopping at the midpoint would leave
|
|
861
|
+
// the final horizontal run cutting through that last box.
|
|
862
|
+
// A run back across columns with anything in its way takes the band as well, and the
|
|
863
|
+
// side is chosen by the box it returns to alone: every return into one box then shares
|
|
864
|
+
// a single trunk, rather than some passing over the graph and the rest under it.
|
|
865
|
+
const middle=[];
|
|
866
|
+
for(const other of nodeById.keys()){
|
|
867
|
+
if(other===edge.source||other===edge.target)continue;
|
|
868
|
+
const box=positions.get(other);if(!box)continue;
|
|
869
|
+
if(box.x>sx+1&&box.x+execweaveFlowWidth(other)<tx-1){
|
|
870
|
+
middle.push({box,width:execweaveFlowWidth(other),height:execweaveFlowBoxHeight(other)});
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
if(waypoints.length>3||returning&&waypoints.length&&middle.length){
|
|
874
|
+
const firstLeft=Math.min(...middle.map(item=>item.box.x))-EXECWEAVE_FLOW_CLEARANCE;
|
|
875
|
+
const middleRight=Math.max(...middle.map(item=>item.box.x+item.width));
|
|
876
|
+
const middleTop=Math.min(...middle.map(item=>item.box.y-EXECWEAVE_FLOW_CLEARANCE));
|
|
877
|
+
const middleBottom=Math.max(...middle.map(item=>item.box.y+item.height+EXECWEAVE_FLOW_CLEARANCE));
|
|
878
|
+
const above=middleTop-10,below=middleBottom+10;
|
|
879
|
+
const safeY=returning?(Math.abs(sy-above)<=Math.abs(sy-below)?above:below)
|
|
880
|
+
:Math.abs(sy-above)+Math.abs(ty-above)<=Math.abs(sy-below)+Math.abs(ty-below)?above:below;
|
|
881
|
+
const entry=Math.max(sx+EXECWEAVE_FLOW_CLEARANCE+2,Math.min(firstLeft-10,(sx+firstLeft)/2));
|
|
882
|
+
const exit=Math.min(tx-EXECWEAVE_FLOW_CLEARANCE-2,Math.max(middleRight+10,(tx+middleRight)/2));
|
|
883
|
+
if(exit>entry+2){
|
|
884
|
+
return{points:[{x:sx,y:sy},{x:entry,y:sy},{x:entry,y:safeY},
|
|
885
|
+
{x:exit,y:safeY},{x:exit,y:ty},{x:tx,y:ty}],
|
|
886
|
+
labelX:(entry+exit)/2,labelY:safeY-8};
|
|
887
|
+
}
|
|
888
|
+
const corridor=(sx+tx)/2;
|
|
889
|
+
return{points:[{x:sx,y:sy},{x:corridor,y:sy},{x:corridor,y:ty},{x:tx,y:ty}],
|
|
890
|
+
labelX:corridor,labelY:(sy+ty)/2-8};
|
|
891
|
+
}
|
|
892
|
+
// A waypoint that clears one box can land inside the next one along. Walk each of them
|
|
893
|
+
// out of whatever it is standing in, in the direction it was already heading.
|
|
894
|
+
for(const stop of waypoints){
|
|
895
|
+
for(let attempt=0;attempt<12;attempt++){
|
|
896
|
+
let moved=false;
|
|
897
|
+
for(const other of nodeById.keys()){
|
|
898
|
+
if(other===edge.source||other===edge.target)continue;
|
|
899
|
+
const box=positions.get(other);if(!box)continue;
|
|
900
|
+
const pad=EXECWEAVE_FLOW_CLEARANCE;
|
|
901
|
+
if(stop.x<box.x-pad||stop.x>box.x+execweaveFlowWidth(other)+pad)continue;
|
|
902
|
+
const top=box.y-pad,bottom=box.y+execweaveFlowBoxHeight(other)+pad;
|
|
903
|
+
if(stop.y<top||stop.y>bottom)continue;
|
|
904
|
+
stop.y=stop.y<=(top+bottom)/2?top-10:bottom+10;moved=true;
|
|
905
|
+
}
|
|
906
|
+
if(!moved)break;
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
// No waypoints means the run is already clear, and it is still the path to draw: the
|
|
910
|
+
// route the base router offers was computed for the positions this layout replaced,
|
|
911
|
+
// so following it now walks through boxes that have since moved into its way.
|
|
912
|
+
waypoints.sort((a,b)=>a.x-b.x);
|
|
913
|
+
// Two blockers in the same column give one waypoint, not two on top of each other.
|
|
914
|
+
const stops=[];
|
|
915
|
+
for(const stop of waypoints){
|
|
916
|
+
const last=stops[stops.length-1];
|
|
917
|
+
if(last&&Math.abs(last.x-stop.x)<2){if(Math.abs(stop.y-runY(stop.x))>Math.abs(last.y-runY(last.x)))last.y=stop.y;continue}
|
|
918
|
+
stops.push(stop);
|
|
919
|
+
}
|
|
920
|
+
return{points:[{x:sx,y:sy},...stops,{x:tx,y:ty}],labelX:(sx+tx)/2,labelY:(sy+ty)/2-8};
|
|
921
|
+
}
|
|
922
|
+
// The router is reassigned several times as the page builds, so wrap whatever is current
|
|
923
|
+
// at the first paint rather than at load, and wrap it only once.
|
|
924
|
+
function execweaveFlowInstallRoute(){
|
|
925
|
+
if(execweaveFlowRouteWrapped)return;
|
|
926
|
+
if(typeof execweaveRoute!=='function')return;
|
|
927
|
+
execweaveFlowRouteWrapped=true;
|
|
928
|
+
const execweaveFlowRouteBase=execweaveRoute;
|
|
929
|
+
execweaveRoute=function(edge){
|
|
930
|
+
const value=execweaveFlowRouteBase(edge);
|
|
931
|
+
if(!value||typeof value.d!=='string')return value;
|
|
932
|
+
// A path already drawn as cubics is what this wants; anything carrying a line, a
|
|
933
|
+
// horizontal or a vertical segment has a corner in it and gets rounded off.
|
|
934
|
+
try{
|
|
935
|
+
const clear=execweaveFlowAvoid(edge,value);
|
|
936
|
+
if(clear)return clear;
|
|
937
|
+
if(!/[LHVlhv]/.test(value.d))return value;
|
|
938
|
+
const points=execweaveFlowPathPoints(value.d);
|
|
939
|
+
if(!points)return value;
|
|
940
|
+
return Object.assign({},value,{d:execweaveFlowSpline(points)});
|
|
941
|
+
}catch(_){return value}
|
|
942
|
+
};
|
|
943
|
+
}
|
|
944
|
+
// The dagre engine, layout v2 and the lane table all write `positions`, and whichever
|
|
945
|
+
// runs last wins. Rather than compete with them, take the positions they produced and
|
|
946
|
+
// overwrite the ones the flow layout has an opinion about. A node it says nothing about
|
|
947
|
+
// keeps whatever the previous authority chose for it.
|
|
948
|
+
function execweaveApplyFlowPositions(){
|
|
949
|
+
if(typeof positions==='undefined'||!positions||!positions.set)return 0;
|
|
950
|
+
// The drawn set changes as nodes arrive, so the solve belongs to the paint, not to the
|
|
951
|
+
// payload that happened to introduce them.
|
|
952
|
+
execweaveFlowInvalidate();
|
|
953
|
+
execweaveFlowInstallRoute();
|
|
954
|
+
const x=execweaveFlowColumns();let applied=0;
|
|
955
|
+
// A row is not always a whole number -- it carries the alignment the layout wants
|
|
956
|
+
// against the columns either side -- so two rows can land closer together than the
|
|
957
|
+
// boxes they hold are tall. Take the row as the height the node wants to sit at, then
|
|
958
|
+
// walk each column from the top and push any box that would land on the one above it.
|
|
959
|
+
const byColumn=new Map();
|
|
960
|
+
for(const id of nodeById.keys()){
|
|
961
|
+
const at=execweaveFlowCoords(id);if(!at)continue;
|
|
962
|
+
if(!Number.isFinite(x[at.layer]))continue;
|
|
963
|
+
if(!byColumn.has(at.layer))byColumn.set(at.layer,[]);
|
|
964
|
+
byColumn.get(at.layer).push({id,y:EXECWEAVE_FLOW_TOP+at.row*EXECWEAVE_FLOW_ROW_GAP});
|
|
965
|
+
}
|
|
966
|
+
for(const [layer,column] of byColumn){
|
|
967
|
+
column.sort((a,b)=>a.y-b.y||String(a.id).localeCompare(String(b.id)));
|
|
968
|
+
let floor=-Infinity;
|
|
969
|
+
for(const seat of column){
|
|
970
|
+
const y=Math.max(seat.y,floor);
|
|
971
|
+
positions.set(seat.id,{x:x[layer],y});
|
|
972
|
+
execweaveFlowPlaced.set(seat.id,{x:x[layer],y});
|
|
973
|
+
const group=nodeElements.get(seat.id);
|
|
974
|
+
if(group)group.setAttribute('transform',`translate(${x[layer]} ${y})`);
|
|
975
|
+
floor=y+execweaveFlowBoxHeight(seat.id)+EXECWEAVE_FLOW_ROW_PAD;
|
|
976
|
+
applied++;
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
if(!applied)return 0;
|
|
980
|
+
try{execweaveFlowSyncSpec(execweaveTopology)}catch(_){}
|
|
981
|
+
try{execweaveFlowScrubGeometry(execweaveTopology)}catch(_){}
|
|
982
|
+
try{if(typeof execweaveRecomputePorts==='function')execweaveRecomputePorts(execweaveTopology)}catch(_){}
|
|
983
|
+
try{for(const id of nodeById.keys()){const node=nodeById.get(id);if(node)updateNodeElement(node)}}catch(_){}
|
|
984
|
+
try{for(const edge of edgeById.values())updateEdgeElement(edge)}catch(_){}
|
|
985
|
+
try{execweaveFlowSpreadLabels()}catch(_){}
|
|
986
|
+
return applied;
|
|
987
|
+
}
|
|
988
|
+
// Edges that share a gap between two columns put their labels at the same midpoint, and
|
|
989
|
+
// two relation names written over each other read as neither. A label that lands on one
|
|
990
|
+
// already placed moves to the nearest seat that is clear of every placed label and covers
|
|
991
|
+
// no more of the boxes than where the router put it: a point further along its own edge,
|
|
992
|
+
// or a few pixels above or below. With no such seat it stays where it was.
|
|
993
|
+
//
|
|
994
|
+
// Returns into one box share one trunk, so the router puts all of their labels on the same
|
|
995
|
+
// point. Those labels name one relation into one target; the first stands for all of them
|
|
996
|
+
// with their total count, and the rest are folded behind it.
|
|
997
|
+
//
|
|
998
|
+
// Each pass first undoes what the previous one did, so running it again over labels the
|
|
999
|
+
// edges have not redrawn since leaves them where one pass would.
|
|
1000
|
+
function execweaveFlowSpreadLabels(){
|
|
1001
|
+
if(typeof edgeElements==='undefined'||edgeElements.size>600)return;
|
|
1002
|
+
for(const els of edgeElements.values()){
|
|
1003
|
+
const label=els.label;if(!label)continue;
|
|
1004
|
+
if(label.dataset.execweaveFolded==='1'){label.style.display='';delete label.dataset.execweaveFolded}
|
|
1005
|
+
const text=label.dataset.execweaveFoldedText;
|
|
1006
|
+
if(text!==undefined){
|
|
1007
|
+
const [from,to]=JSON.parse(text);if(label.textContent===to)label.textContent=from;
|
|
1008
|
+
delete label.dataset.execweaveFoldedText;
|
|
1009
|
+
}
|
|
1010
|
+
const moved=label.dataset.execweaveSpread;
|
|
1011
|
+
if(moved!==undefined){
|
|
1012
|
+
const [x0,y0,x,y]=moved.split(',').map(Number);
|
|
1013
|
+
if(Number(label.getAttribute('x'))===x&&Number(label.getAttribute('y'))===y){label.setAttribute('x',x0);label.setAttribute('y',y0)}
|
|
1014
|
+
delete label.dataset.execweaveSpread;
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
const stacks=new Map();
|
|
1018
|
+
for(const [id,els] of edgeElements){
|
|
1019
|
+
const label=els.label,edge=edgeById.get(id);
|
|
1020
|
+
if(!label||!edge||label.getAttribute('aria-hidden')==='true'||label.style.display==='none')continue;
|
|
1021
|
+
const x=Number(label.getAttribute('x')),y=Number(label.getAttribute('y'));
|
|
1022
|
+
if(!Number.isFinite(x)||!Number.isFinite(y))continue;
|
|
1023
|
+
const key=[edge.target,edge.relation,Math.round(x),Math.round(y)].join('\u0000');
|
|
1024
|
+
if(!stacks.has(key))stacks.set(key,[]);stacks.get(key).push({label,edge});
|
|
1025
|
+
}
|
|
1026
|
+
for(const stack of stacks.values()){
|
|
1027
|
+
if(stack.length<2)continue;
|
|
1028
|
+
const keep=stack[0].label,from=keep.textContent;
|
|
1029
|
+
const total=stack.reduce((sum,{edge})=>sum+Math.max(1,Number(edge.count)||1),0);
|
|
1030
|
+
const to=`${stack[0].edge.relation} ×${total}`;
|
|
1031
|
+
keep.textContent=to;keep.dataset.execweaveFoldedText=JSON.stringify([from,to]);
|
|
1032
|
+
for(const {label} of stack.slice(1)){label.style.display='none';label.dataset.execweaveFolded='1'}
|
|
1033
|
+
}
|
|
1034
|
+
const boxes=[];
|
|
1035
|
+
for(const [id,p] of positions)if(nodeById.has(id))boxes.push({x:p.x,y:p.y,w:execweaveWidthOf(id),h:execweaveFlowBoxHeight(id)});
|
|
1036
|
+
const clashes=(box,list)=>list.some(other=>box.x<other.x+other.w+1&&box.x+box.w+1>other.x&&box.y<other.y+other.h+1&&box.y+box.h+1>other.y);
|
|
1037
|
+
const covered=box=>boxes.reduce((sum,other)=>sum
|
|
1038
|
+
+Math.max(0,Math.min(box.x+box.w,other.x+other.w)-Math.max(box.x,other.x))
|
|
1039
|
+
*Math.max(0,Math.min(box.y+box.h,other.y+other.h)-Math.max(box.y,other.y)),0);
|
|
1040
|
+
const placed=[];
|
|
1041
|
+
for(const els of edgeElements.values()){
|
|
1042
|
+
const label=els.label,path=els.visible;
|
|
1043
|
+
if(!label||!path||label.getAttribute('aria-hidden')==='true'||label.style.display==='none')continue;
|
|
1044
|
+
let box;try{box=label.getBBox()}catch(_){continue}
|
|
1045
|
+
if(!(box.width>0&&box.height>0))continue;
|
|
1046
|
+
const x0=Number(label.getAttribute('x')),y0=Number(label.getAttribute('y'));
|
|
1047
|
+
if(!Number.isFinite(x0)||!Number.isFinite(y0))continue;
|
|
1048
|
+
const at=(x,y)=>({x:box.x-x0+x,y:box.y-y0+y,w:box.width,h:box.height});
|
|
1049
|
+
let x=x0,y=y0;
|
|
1050
|
+
if(clashes(at(x0,y0),placed)){
|
|
1051
|
+
const limit=covered(at(x0,y0)),seats=[];
|
|
1052
|
+
for(let dy=1;dy<=3*box.height;dy++)seats.push([x0,y0-dy],[x0,y0+dy]);
|
|
1053
|
+
let length=0;try{length=path.getTotalLength()}catch(_){}
|
|
1054
|
+
if(length>0)for(let share=.1;share<.95;share+=.05){
|
|
1055
|
+
const point=path.getPointAtLength(length*share);
|
|
1056
|
+
seats.push([point.x,point.y-4],[point.x,point.y+box.height+2]);
|
|
1057
|
+
}
|
|
1058
|
+
seats.sort((a,b)=>Math.hypot(a[0]-x0,a[1]-y0)-Math.hypot(b[0]-x0,b[1]-y0));
|
|
1059
|
+
for(const [sx,sy] of seats){
|
|
1060
|
+
const seat=at(sx,sy);
|
|
1061
|
+
if(!clashes(seat,placed)&&covered(seat)<=limit){x=sx;y=sy;break}
|
|
1062
|
+
}
|
|
1063
|
+
if(x!==x0||y!==y0){label.setAttribute('x',x);label.setAttribute('y',y);label.dataset.execweaveSpread=[x0,y0,x,y].join(',')}
|
|
1064
|
+
}
|
|
1065
|
+
placed.push(at(x,y));
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
if(typeof refreshEdgeLabels==='function'){
|
|
1069
|
+
// The snapshot draws every edge, then refreshes their labels; only after that pass does
|
|
1070
|
+
// every label have a place to be spread from.
|
|
1071
|
+
const refreshBase=refreshEdgeLabels;
|
|
1072
|
+
refreshEdgeLabels=function(){refreshBase();try{execweaveFlowSpreadLabels()}catch(_){}};
|
|
1073
|
+
}
|
|
1074
|
+
try{window.__execweaveFlow={payload:execweaveFlowPayload,columns:execweaveFlowColumns,solve:execweaveFlowSolve,apply:execweaveApplyFlowPositions,spreadLabels:execweaveFlowSpreadLabels}}catch(_){}
|
|
1075
|
+
""".strip()
|
|
1076
|
+
|
|
1077
|
+
_FINAL_LAYOUT_SEAM = "function execweaveInstallFinalLayout(priorY){"
|
|
1078
|
+
_FINAL_LAYOUT_REPLACEMENT = (
|
|
1079
|
+
"function execweaveInstallFinalLayout(priorY){\n"
|
|
1080
|
+
" execweaveInstallFinalLayoutPreFlow(priorY);\n"
|
|
1081
|
+
" try{execweaveApplyFlowPositions()}catch(_){}\n"
|
|
1082
|
+
"}\n"
|
|
1083
|
+
"function execweaveInstallFinalLayoutPreFlow(priorY){"
|
|
1084
|
+
)
|
|
1085
|
+
|
|
1086
|
+
|
|
1087
|
+
_DESIRED_SEAM = (
|
|
1088
|
+
"function execweaveDesiredPosition(id){const value=execweaveTopology.spec.get(id);"
|
|
1089
|
+
"return value?{x:value.x,y:value.y}:{x:0,y:0}}"
|
|
1090
|
+
)
|
|
1091
|
+
|
|
1092
|
+
_DESIRED_REPLACEMENT = (
|
|
1093
|
+
"function execweaveDesiredPosition(id){\n"
|
|
1094
|
+
" const at=execweaveFlowCoords(id);\n"
|
|
1095
|
+
" if(at){const x=execweaveFlowColumns();\n"
|
|
1096
|
+
" if(Number.isFinite(x[at.layer]))"
|
|
1097
|
+
"return{x:x[at.layer],y:EXECWEAVE_FLOW_TOP+at.row*EXECWEAVE_FLOW_ROW_GAP}}\n"
|
|
1098
|
+
" const value=execweaveTopology.spec.get(id);return value?{x:value.x,y:value.y}:{x:0,y:0}\n"
|
|
1099
|
+
"}"
|
|
1100
|
+
)
|
|
1101
|
+
|
|
1102
|
+
# Wrap the display filter by name rather than at its call site. Declarations hoist, so
|
|
1103
|
+
# the wrapper may be written above the function it renames, and `execweaveDashboardGraph`
|
|
1104
|
+
# keeps both its name and every existing call to it. The suffix is deliberately not
|
|
1105
|
+
# `Base`: a later injector already binds `execweaveDashboardGraphBase` to whatever this
|
|
1106
|
+
# name resolves to, and two declarations of it are a page-wide SyntaxError.
|
|
1107
|
+
_DISPLAY_SEAM = "function execweaveDashboardGraph(data){"
|
|
1108
|
+
_DISPLAY_REPLACEMENT = (
|
|
1109
|
+
FLOW_CANVAS_SCRIPT
|
|
1110
|
+
+ "\nfunction execweaveDashboardGraph(data){"
|
|
1111
|
+
"return execweaveFlowDisplay(data,execweaveDashboardGraphPreFlow(data))}\n"
|
|
1112
|
+
"function execweaveDashboardGraphPreFlow(data){"
|
|
1113
|
+
)
|
|
1114
|
+
|
|
1115
|
+
|
|
1116
|
+
_ARRANGE_SEAM = "if(arrangeButton)arrangeButton.onclick=()=>execweaveArrangePositions();"
|
|
1117
|
+
_ARRANGE_REPLACEMENT = (
|
|
1118
|
+
# This handler is emitted after the flow script in the final page, so it is the
|
|
1119
|
+
# binding that remains active. Apply the flow contract here; only an empty flow falls
|
|
1120
|
+
# back to the older arrangement implementation.
|
|
1121
|
+
"if(arrangeButton)arrangeButton.onclick=()=>{"
|
|
1122
|
+
"try{if(execweaveApplyFlowPositions())return}catch(_){}"
|
|
1123
|
+
"execweaveArrangePositions();};"
|
|
1124
|
+
)
|
|
1125
|
+
|
|
1126
|
+
|
|
1127
|
+
def inject_flow_canvas(html: str) -> str:
|
|
1128
|
+
"""Point the canvas at ``viewer_flow``, leaving every other reader on the full graph."""
|
|
1129
|
+
if html.count(_DESIRED_SEAM) != 1:
|
|
1130
|
+
raise RuntimeError("flow canvas desired-position seam changed")
|
|
1131
|
+
html = html.replace(_DESIRED_SEAM, _DESIRED_REPLACEMENT, 1)
|
|
1132
|
+
if html.count(_DISPLAY_SEAM) != 1:
|
|
1133
|
+
raise RuntimeError("flow canvas display seam changed")
|
|
1134
|
+
html = html.replace(_DISPLAY_SEAM, _DISPLAY_REPLACEMENT, 1)
|
|
1135
|
+
if html.count(_FINAL_LAYOUT_SEAM) != 1:
|
|
1136
|
+
raise RuntimeError("flow canvas final-layout seam changed")
|
|
1137
|
+
html = html.replace(_FINAL_LAYOUT_SEAM, _FINAL_LAYOUT_REPLACEMENT, 1)
|
|
1138
|
+
if html.count(_ARRANGE_SEAM) != 1:
|
|
1139
|
+
raise RuntimeError("flow canvas arrange seam changed")
|
|
1140
|
+
return html.replace(_ARRANGE_SEAM, _ARRANGE_REPLACEMENT, 1)
|