Compare commits

...
Author SHA1 Message Date
ausboss d9a143b98e Merge branch 'main' of https://github.com/ausboss/ComfyUI-AusBoss into feat/check-layout
# Conflicts:
#	CHANGELOG.md
2026-11-26 11:50:28 -06:00
ausboss e8be47102e Note the example tidy in the changelog
One line under Unreleased: the examples moved, nothing in them changed.
2026-11-25 22:28:27 -06:00
ausboss ac9817945e Keep the tile subgraph's two reroutes apart in the Upscale + Restore example
The two reroutes in the tile subgraph sat on one spot. They now sit apart so each wire can be followed.
2026-11-25 22:28:17 -06:00
ausboss 1068b3fb75 Tidy the example workflows so Check layout finds nothing
Only node and group positions and sizes, and reroute spots, changed. No node, link or value was touched.
2026-11-25 22:28:17 -06:00
ausboss 1bf9f0bbb8 Frame a Check layout jump left of its panel, so the panel never covers it
The panel sits at the right of the canvas, so the jump frames the picked node in the free space on its left.
2026-11-25 22:28:06 -06:00
ausboss 201cd54508 Add Check layout: a list of what makes a workflow hard to read
Right-click the canvas or use the command palette. It lists overlaps, wires that run backwards or hide behind a node, nodes outside every group, a saved zoom too small to read and a missing Workflow Note, inside subgraphs too. Click an entry to jump to it. Nothing is moved. Includes the Chinese strings, README lines and the changelog entry.
2026-11-25 22:28:03 -06:00
18 changed files with 1892 additions and 59 deletions
+9
View File
@@ -4,6 +4,15 @@ All notable changes to ComfyUI-AusBoss are documented here.
## Unreleased
- **Check layout 🆎 shows what makes a workflow hard to read.** Right-click
the canvas or use the command palette. It lists overlapping nodes and
groups, wires that run backwards or hide behind a node, nodes just under a
preview that grows when it runs, nodes outside every group, a saved zoom
too small to read and a missing Workflow Note, inside subgraphs too. Click
an entry to jump to it. Nothing is moved.
- **The example workflows are tidied so Check layout finds nothing.** Only
node and group positions and sizes, and reroute spots, changed. What each
workflow does is the same.
- **Edit Lock 🆎 says what is wrong when the VAE and model don't match.**
The readout used to blame the VAE alone. It now says either file can be
the wrong one, gives the two channel counts it compared, and points to
+2
View File
@@ -495,6 +495,7 @@ If you share workflows, a few of these nodes help the people who download them:
- **Workflow Note** puts a setup card on the canvas with each model's download link, folder and size, the node packs it needs and your links, and checks them against the reader's install.
- **Callout** is a note with big readable text and teal arrows you type with an emoji.
- **Check layout 🆎** lists overlaps, hidden and backwards wires and nodes outside the groups before you share.
- **Image Compare A/B** shows the result against its source with a slider.
- **Seed** keeps runs repeatable, and **Use last run** brings back the seed the last run used.
- **Run Timer** shows how long the whole run took, so a speed note is measured.
@@ -509,6 +510,7 @@ People who download your workflow get the nodes through ComfyUI-Manager's missin
- **Help cards:** the **?** in a classic node's title bar opens its description, inputs and outputs. Nodes 2.0 and titleless nodes such as Run Timer have **About this node** in their right-click menu.
- **Recreate node 🆎** (right-click an AusBoss node) rebuilds a node saved by an older version from the current definition. It keeps the values, links, position and colors.
- **Replace with AusBoss nodes 🆎** (canvas right-click or the command palette) finds third-party nodes this pack can stand in for, such as VideoHelperSuite's Load Video and Video Combine or KJNodes' Color Match. It previews each swap and replaces the ones you leave ticked.
- **Check layout 🆎** (canvas right-click or the command palette) lists what makes a workflow hard to read: overlapping nodes and groups (title bars included), wires that run backwards or hide behind a node, a node just under one that grows when it shows a picture, nodes outside every group, a saved zoom too small for the text to draw, and a missing Workflow Note. It checks inside every subgraph too. Click an entry to jump to it and select it. It moves nothing.
- **Snap into line:** a node, group or selection you drag lines up with the nodes and groups around it, edge to edge or middle to middle, and a teal line shows what it lines up with. Pulling a corner to resize lines up the same way. Hold Shift while you drag to skip it, or turn it off in Settings → 🆎 AusBoss → Canvas.
- **Line up:** select two or more nodes or groups and the selection toolbar gets a Line up button: line up edges or middles, match widths or heights, or space them evenly. With two or more nodes selected, pulling the edge or corner of one resizes them all: a column gets one width, a row one height, a grid both (turn it off in Settings → 🆎 AusBoss → Canvas → Resize together).
- **Node colors:** Settings → 🆎 AusBoss → Appearance sets the scheme for every AusBoss node (AusBoss, Graphite, Slate, Teal, Moss, Plum, Rust, Navy, Custom or Theme default). A node's right-click **AusBoss color** menu recolors just that node, and nodes you colored by hand keep their colors.
@@ -520,7 +520,42 @@
137,
20
]
}
},
"reroutes": [
{
"id": 1,
"pos": [
950,
310
],
"linkIds": [
3,
4
]
},
{
"id": 2,
"parentId": 1,
"pos": [
1370,
310
],
"linkIds": [
3,
4
]
}
],
"linkExtensions": [
{
"id": 3,
"parentId": 2
},
{
"id": 4,
"parentId": 2
}
]
},
"version": 0.4
}
@@ -1706,7 +1706,7 @@
"type": "SetLatentNoiseMask",
"pos": [
20,
354
398
],
"size": [
460,
@@ -1947,7 +1947,7 @@
"type": "KSampler",
"pos": [
1100,
304
338
],
"size": [
460,
@@ -2325,7 +2325,7 @@
0,
0,
500,
428
470
],
"color": "#1d5560",
"flags": {}
@@ -2349,7 +2349,7 @@
1080,
0,
500,
586
620
],
"color": "#1d5560",
"flags": {}
@@ -2361,7 +2361,7 @@
1620,
0,
500,
529
620
],
"color": "#1d5560",
"flags": {}
@@ -2446,7 +2446,8 @@
"origin_slot": 0,
"target_id": 11,
"target_slot": 0,
"type": "CONDITIONING"
"type": "CONDITIONING",
"parentId": 1
},
{
"id": 34,
@@ -2553,7 +2554,19 @@
"type": "IMAGE"
}
],
"extra": {}
"extra": {},
"reroutes": [
{
"id": 1,
"pos": [
1060,
540
],
"linkIds": [
33
]
}
]
}
]
},
@@ -2566,7 +2579,92 @@
20
]
},
"frontendVersion": "1.53.6"
"frontendVersion": "1.53.6",
"reroutes": [
{
"id": 1,
"pos": [
1040,
188
],
"linkIds": [
14
]
},
{
"id": 2,
"parentId": 1,
"pos": [
1580,
188
],
"linkIds": [
14
]
},
{
"id": 3,
"pos": [
1580,
325
],
"linkIds": [
4
]
},
{
"id": 4,
"pos": [
1562,
450
],
"linkIds": [
10
]
},
{
"id": 5,
"pos": [
1580,
425
],
"linkIds": [
11
]
},
{
"id": 6,
"pos": [
1604,
400
],
"linkIds": [
12
]
}
],
"linkExtensions": [
{
"id": 14,
"parentId": 2
},
{
"id": 4,
"parentId": 3
},
{
"id": 10,
"parentId": 4
},
{
"id": 11,
"parentId": 5
},
{
"id": 12,
"parentId": 6
}
]
},
"version": 0.4
}
@@ -2769,7 +2769,7 @@
"type": "KSampler",
"pos": [
1100,
546
646
],
"size": [
460,
@@ -3088,8 +3088,8 @@
"id": 37,
"type": "Reroute",
"pos": [
1100,
450
1082,
510
],
"size": [
75,
@@ -3150,7 +3150,7 @@
"id": 47,
"type": "Reroute",
"pos": [
1200,
1118,
450
],
"size": [
@@ -3214,7 +3214,7 @@
1080,
0,
500,
828
928
],
"color": "#1d5560",
"flags": {}
@@ -3226,7 +3226,7 @@
1620,
0,
500,
529
600
],
"color": "#1d5560",
"flags": {}
@@ -3466,7 +3466,8 @@
"type": "FLOAT"
}
],
"extra": {}
"extra": {},
"reroutes": []
}
]
},
@@ -3479,7 +3480,117 @@
96
]
},
"frontendVersion": "1.53.6"
"frontendVersion": "1.53.6",
"reroutes": [
{
"id": 1,
"pos": [
964,
350
],
"linkIds": [
70
]
},
{
"id": 2,
"pos": [
976,
410
],
"linkIds": [
79
]
},
{
"id": 3,
"pos": [
952,
860
],
"linkIds": [
71
]
},
{
"id": 4,
"parentId": 3,
"pos": [
964,
430
],
"linkIds": [
71
]
},
{
"id": 5,
"pos": [
1556,
420
],
"linkIds": [
73
]
},
{
"id": 6,
"pos": [
1576,
450
],
"linkIds": [
74
]
},
{
"id": 7,
"pos": [
955,
188
],
"linkIds": [
42
]
},
{
"id": 8,
"parentId": 7,
"pos": [
1564,
188
],
"linkIds": [
42
]
}
],
"linkExtensions": [
{
"id": 70,
"parentId": 1
},
{
"id": 79,
"parentId": 2
},
{
"id": 71,
"parentId": 4
},
{
"id": 73,
"parentId": 5
},
{
"id": 74,
"parentId": 6
},
{
"id": 42,
"parentId": 8
}
]
},
"version": 0.4
}
@@ -2183,7 +2183,7 @@
1080,
0,
500,
529
600
],
"color": "#1d5560",
"flags": {}
@@ -2375,7 +2375,8 @@
"type": "MASK"
}
],
"extra": {}
"extra": {},
"reroutes": []
}
]
},
@@ -2388,7 +2389,78 @@
20
]
},
"frontendVersion": "1.53.6"
"frontendVersion": "1.53.6",
"reroutes": [
{
"id": 1,
"pos": [
950,
188
],
"linkIds": [
31
]
},
{
"id": 2,
"parentId": 1,
"pos": [
1462,
188
],
"linkIds": [
31
]
},
{
"id": 3,
"pos": [
1468,
325
],
"linkIds": [
43
]
},
{
"id": 4,
"pos": [
1444,
475
],
"linkIds": [
50
]
},
{
"id": 5,
"pos": [
1468,
450
],
"linkIds": [
51
]
}
],
"linkExtensions": [
{
"id": 31,
"parentId": 2
},
{
"id": 43,
"parentId": 3
},
{
"id": 50,
"parentId": 4
},
{
"id": 51,
"parentId": 5
}
]
},
"version": 0.4
}
@@ -612,7 +612,7 @@
"type": "2f8cb72f-ebab-4ed9-bb0c-328a4e6493d9",
"pos": [
1020,
238
380
],
"size": [
240,
@@ -2180,7 +2180,7 @@
1080,
0,
500,
529
600
],
"color": "#1d5560",
"flags": {}
@@ -2372,7 +2372,8 @@
"type": "MASK"
}
],
"extra": {}
"extra": {},
"reroutes": []
}
]
},
@@ -2385,7 +2386,131 @@
20
]
},
"frontendVersion": "1.53.6"
"frontendVersion": "1.53.6",
"reroutes": [
{
"id": 1,
"pos": [
950,
188
],
"linkIds": [
31
]
},
{
"id": 2,
"parentId": 1,
"pos": [
1580,
188
],
"linkIds": [
31
]
},
{
"id": 3,
"pos": [
968,
900
],
"linkIds": [
48
]
},
{
"id": 4,
"parentId": 3,
"pos": [
984,
350
],
"linkIds": [
48
]
},
{
"id": 5,
"pos": [
1564,
450
],
"linkIds": [
50
]
},
{
"id": 6,
"pos": [
1596,
400
],
"linkIds": [
51
]
},
{
"id": 7,
"pos": [
955,
182
],
"linkIds": [
44
]
},
{
"id": 8,
"pos": [
955,
194
],
"linkIds": [
45
]
},
{
"id": 9,
"pos": [
955,
206
],
"linkIds": [
46
]
}
],
"linkExtensions": [
{
"id": 31,
"parentId": 2
},
{
"id": 48,
"parentId": 4
},
{
"id": 50,
"parentId": 5
},
{
"id": 51,
"parentId": 6
},
{
"id": 44,
"parentId": 7
},
{
"id": 45,
"parentId": 8
},
{
"id": 46,
"parentId": 9
}
]
},
"version": 0.4
}
@@ -2785,7 +2785,7 @@
1080,
0,
500,
719
780
],
"color": "#1d5560",
"flags": {}
@@ -2990,7 +2990,8 @@
"origin_slot": 0,
"target_id": 19,
"target_slot": 0,
"type": "CONDITIONING"
"type": "CONDITIONING",
"parentId": 1
},
{
"id": 147,
@@ -2998,7 +2999,8 @@
"origin_slot": 1,
"target_id": 19,
"target_slot": 1,
"type": "CONDITIONING"
"type": "CONDITIONING",
"parentId": 2
},
{
"id": 148,
@@ -3065,7 +3067,29 @@
"type": "FLOAT"
}
],
"extra": {}
"extra": {},
"reroutes": [
{
"id": 1,
"pos": [
1080,
900
],
"linkIds": [
146
]
},
{
"id": 2,
"pos": [
1090,
900
],
"linkIds": [
147
]
}
]
}
]
},
@@ -3078,7 +3102,53 @@
25
]
},
"frontendVersion": "1.53.6"
"frontendVersion": "1.53.6",
"reroutes": [
{
"id": 1,
"pos": [
1508,
325
],
"linkIds": [
63
]
},
{
"id": 2,
"pos": [
1476,
475
],
"linkIds": [
59
]
},
{
"id": 3,
"pos": [
1508,
400
],
"linkIds": [
60
]
}
],
"linkExtensions": [
{
"id": 63,
"parentId": 1
},
{
"id": 59,
"parentId": 2
},
{
"id": 60,
"parentId": 3
}
]
},
"version": 0.4
}
+30 -1
View File
@@ -1280,7 +1280,36 @@
60
]
},
"frontendVersion": "1.53.6"
"frontendVersion": "1.53.6",
"reroutes": [
{
"id": 1,
"pos": [
1464,
205
],
"linkIds": [
5
]
},
{
"id": 2,
"parentId": 1,
"pos": [
1924,
205
],
"linkIds": [
5
]
}
],
"linkExtensions": [
{
"id": 5,
"parentId": 2
}
]
},
"version": 0.4
}
+58 -1
View File
@@ -1135,7 +1135,64 @@
60
]
},
"frontendVersion": "1.53.6"
"frontendVersion": "1.53.6",
"reroutes": [
{
"id": 1,
"pos": [
1504,
205
],
"linkIds": [
5
]
},
{
"id": 2,
"parentId": 1,
"pos": [
1964,
205
],
"linkIds": [
5
]
},
{
"id": 3,
"pos": [
1508,
441
],
"linkIds": [
2
]
},
{
"id": 4,
"pos": [
1516,
451
],
"linkIds": [
3
]
}
],
"linkExtensions": [
{
"id": 5,
"parentId": 2
},
{
"id": 2,
"parentId": 3
},
{
"id": 3,
"parentId": 4
}
]
},
"version": 0.4
}
@@ -1679,7 +1679,8 @@
"origin_slot": 0,
"target_id": 72,
"target_slot": 1,
"type": "IMAGE"
"type": "IMAGE",
"parentId": 1
},
{
"id": 5,
@@ -1706,7 +1707,19 @@
"type": "STRING"
}
],
"extra": {}
"extra": {},
"reroutes": [
{
"id": 1,
"pos": [
1048,
676
],
"linkIds": [
6
]
}
]
},
{
"id": "fe7eddff-ee33-40d2-98aa-e25b894fc34e",
@@ -2713,7 +2726,8 @@
"origin_slot": 4,
"target_id": 66,
"target_slot": 2,
"type": "AUSBOSS_STITCHER"
"type": "AUSBOSS_STITCHER",
"parentId": 4
},
{
"id": 28,
@@ -2729,7 +2743,8 @@
"origin_slot": 0,
"target_id": 68,
"target_slot": 1,
"type": "IMAGE"
"type": "IMAGE",
"parentId": 2
},
{
"id": 30,
@@ -2780,7 +2795,51 @@
"type": "STRING"
}
],
"extra": {}
"extra": {},
"reroutes": [
{
"id": 1,
"pos": [
522,
248
],
"linkIds": [
29
]
},
{
"id": 2,
"parentId": 1,
"pos": [
1600,
248
],
"linkIds": [
29
]
},
{
"id": 3,
"pos": [
522,
262
],
"linkIds": [
27
]
},
{
"id": 4,
"parentId": 3,
"pos": [
1600,
262
],
"linkIds": [
27
]
}
]
}
]
},
@@ -2793,7 +2852,53 @@
27
]
},
"frontendVersion": "1.53.6"
"frontendVersion": "1.53.6",
"reroutes": [
{
"id": 1,
"pos": [
1460,
360
],
"linkIds": [
35
]
},
{
"id": 2,
"pos": [
1444,
500
],
"linkIds": [
40
]
},
{
"id": 3,
"pos": [
1476,
450
],
"linkIds": [
41
]
}
],
"linkExtensions": [
{
"id": 35,
"parentId": 1
},
{
"id": 40,
"parentId": 2
},
{
"id": 41,
"parentId": 3
}
]
},
"version": 0.4
}
@@ -1025,7 +1025,7 @@
"type": "AUSBOSS_NODES_LoraLoader",
"pos": [
2288,
1040.0
1290
],
"size": [
440,
@@ -2005,9 +2005,9 @@
"title": "3 · Models",
"bounding": [
1968,
960.0,
960,
780,
500.0
540
],
"color": "#1d5560",
"flags": {
@@ -2550,7 +2550,7 @@
"type": "Reroute",
"pos": [
560,
676.0
640
],
"size": [
75,
@@ -2587,8 +2587,8 @@
"id": 25,
"type": "Reroute",
"pos": [
560,
772.0
580,
784
],
"size": [
75,
@@ -3094,7 +3094,8 @@
"origin_slot": 0,
"target_id": 26,
"target_slot": 3,
"type": "LATENT"
"type": "LATENT",
"parentId": 1
},
{
"id": 20,
@@ -3241,7 +3242,19 @@
"type": "IMAGE"
}
],
"extra": {}
"extra": {},
"reroutes": [
{
"id": 1,
"pos": [
1060,
640
],
"linkIds": [
25
]
}
]
},
{
"id": "f03669a3-61c2-44c8-ad63-bad928a695fa",
@@ -3828,7 +3841,8 @@
"type": "MASK"
}
],
"extra": {}
"extra": {},
"reroutes": []
}
]
},
@@ -3841,7 +3855,106 @@
60
]
},
"frontendVersion": "1.53.6"
"frontendVersion": "1.53.6",
"reroutes": [
{
"id": 1,
"pos": [
954,
36
],
"linkIds": [
46,
31
]
},
{
"id": 2,
"parentId": 1,
"pos": [
1945,
36
],
"linkIds": [
46,
31
]
},
{
"id": 3,
"parentId": 2,
"pos": [
2768,
36
],
"linkIds": [
31
]
},
{
"id": 4,
"pos": [
2768,
300
],
"linkIds": [
45
]
},
{
"id": 5,
"parentId": 4,
"pos": [
3208,
300
],
"linkIds": [
45
]
},
{
"id": 6,
"pos": [
956,
1030
],
"linkIds": [
2
]
},
{
"id": 7,
"pos": [
962,
980
],
"linkIds": [
3
]
}
],
"linkExtensions": [
{
"id": 46,
"parentId": 2
},
{
"id": 31,
"parentId": 3
},
{
"id": 45,
"parentId": 5
},
{
"id": 2,
"parentId": 6
},
{
"id": 3,
"parentId": 7
}
]
},
"version": 0.4
}
@@ -921,8 +921,8 @@
"id": 11,
"type": "AUSBOSS_NODES_LoraLoader",
"pos": [
1808,
608
1468,
1072
],
"size": [
400,
@@ -2021,7 +2021,7 @@
"type": "Reroute",
"pos": [
560,
394
430
],
"size": [
75,
@@ -2059,7 +2059,7 @@
"type": "Reroute",
"pos": [
560,
460
360
],
"size": [
75,
@@ -2096,11 +2096,11 @@
"id": 20,
"type": "KSampler",
"pos": [
560,
640,
546
],
"size": [
460,
380,
262
],
"flags": {},
@@ -2607,7 +2607,8 @@
"type": "IMAGE"
}
],
"extra": {}
"extra": {},
"reroutes": []
}
]
},
@@ -2620,7 +2621,64 @@
60
]
},
"frontendVersion": "1.53.6"
"frontendVersion": "1.53.6",
"reroutes": [
{
"id": 1,
"pos": [
1428,
210
],
"linkIds": [
21
]
},
{
"id": 2,
"parentId": 1,
"pos": [
2248,
210
],
"linkIds": [
21
]
},
{
"id": 3,
"pos": [
1820,
400
],
"linkIds": [
27
]
},
{
"id": 4,
"pos": [
1860,
450
],
"linkIds": [
28
]
}
],
"linkExtensions": [
{
"id": 21,
"parentId": 2
},
{
"id": 27,
"parentId": 3
},
{
"id": 28,
"parentId": 4
}
]
},
"version": 0.4
}
}
@@ -1816,7 +1816,8 @@
"type": "IMAGE"
}
],
"extra": {}
"extra": {},
"reroutes": []
},
{
"id": "a988ba93-208b-4af3-b721-61365d1292ac",
@@ -2612,7 +2613,8 @@
"type": "IMAGE"
}
],
"extra": {}
"extra": {},
"reroutes": []
}
]
},
@@ -2624,7 +2626,111 @@
137,
20
]
}
},
"reroutes": [
{
"id": 1,
"pos": [
940,
34
],
"linkIds": [
1
]
},
{
"id": 2,
"parentId": 1,
"pos": [
1420,
34
],
"linkIds": [
1
]
},
{
"id": 3,
"pos": [
940,
38
],
"linkIds": [
13
]
},
{
"id": 4,
"parentId": 3,
"pos": [
1780,
38
],
"linkIds": [
13
]
},
{
"id": 5,
"pos": [
940,
42
],
"linkIds": [
14
]
},
{
"id": 6,
"parentId": 5,
"pos": [
1780,
42
],
"linkIds": [
14
]
},
{
"id": 7,
"pos": [
934,
450
],
"linkIds": [
15
]
},
{
"id": 8,
"parentId": 7,
"pos": [
942,
700
],
"linkIds": [
15
]
}
],
"linkExtensions": [
{
"id": 1,
"parentId": 2
},
{
"id": 13,
"parentId": 4
},
{
"id": 14,
"parentId": 6
},
{
"id": 15,
"parentId": 8
}
]
},
"version": 0.4
}
+329
View File
@@ -0,0 +1,329 @@
// Check layout 🆎 (canvas right-click menu and command palette): lists what
// makes a workflow hard to read and moves nothing. Overlapping nodes and
// groups, wires that run backwards or hide behind a node, a node close under
// one that grows when it runs, nodes outside every group, a saved zoom too
// small to read and a missing Workflow Note, on the top level and inside
// every subgraph. Click an entry to jump to it. The decisions live in
// js/shared/layout_check_math.mjs under node:test.
import { app } from "../../../scripts/app.js";
import { t } from "../shared/i18n.mjs";
import { THEME as T, FONT_UI } from "../shared/theme.mjs";
import { compactAction } from "../shared/panel_controls.mjs";
import { CALLOUT_TYPES, NOTE_TYPES } from "../shared/note_identity.mjs";
import { normalizeNote } from "../shared/workflow_note.mjs";
import { frameBounds } from "../shared/workflow_switches.mjs";
import { KINDS, MIN_ZOOM, checkLayout, countByKind, jumpViewport } from "../shared/layout_check_math.mjs";
const CSS_ID = "ausboss-layout-check-css";
const LABEL = "Check layout";
const FRAME_FILL = 0.8;
// Core nodes that get taller once a run shows its picture or text in them.
// The pack's own preview nodes keep their size (js/input_preview/).
const GROWS = new Set(["PreviewImage", "SaveImage", "SaveAnimatedWEBP", "SaveAnimatedPNG", "SaveWEBM", "SaveVideo", "PreviewAny"]);
const KIND_LABEL = {
"overlap": "Overlapping",
"group-overlap": "Groups overlapping",
"under-grower": "Under a node that grows",
"hidden-wire": "Wire behind a node",
"backward-wire": "Wire runs backwards",
"outside-group": "Outside every group",
"no-groups": "No groups",
"zoom": "Zoomed out too far",
"no-note": "No Workflow Note",
};
function ensureCss() {
if (document.getElementById(CSS_ID)) return;
const style = document.createElement("style");
style.id = CSS_ID;
style.textContent = `
.ausboss-layout-check{position:fixed;z-index:1000;display:flex;flex-direction:column;box-sizing:border-box;width:360px;max-height:70vh;overflow:hidden;border:1px solid ${T.rule};border-radius:10px;background:${T.card};box-shadow:0 12px 40px #0009;color:${T.inkSoft};font:12px/1.4 ${FONT_UI}}
.ausboss-layout-check header{display:flex;align-items:center;gap:6px;padding:10px 10px 8px 14px;border-bottom:1px solid ${T.rule}}
.ausboss-layout-check header b{color:${T.ink};font-size:13px;font-weight:650}
.ausboss-layout-check header span{margin-right:auto;color:${T.faint}}
.ausboss-layout-check-list{overflow:auto;padding:4px 0 6px}
.ausboss-layout-check h4{display:flex;align-items:center;gap:6px;margin:10px 14px 4px;color:${T.label};font:600 11px/1.25 ${FONT_UI}}
.ausboss-layout-check h4 i{color:${T.faint};font-style:normal}
.ausboss-layout-check-row{display:block;box-sizing:border-box;width:100%;padding:5px 12px 5px 11px;border:0;border-left:3px solid transparent;background:transparent;color:${T.inkSoft};font:12px/1.35 ${FONT_UI};text-align:left;cursor:pointer}
.ausboss-layout-check-row:hover{background:${T.fill}}
.ausboss-layout-check-row.is-picked{border-left-color:${T.brand};background:${T.brandSoft}}
.ausboss-layout-check-row:focus-visible{outline:2px solid ${T.brand};outline-offset:-2px}
.ausboss-layout-check-row small{display:block;color:${T.faint};font-size:11px}
.ausboss-layout-check-row.is-info{cursor:default}
.ausboss-layout-check-row.is-info:hover{background:transparent}
.ausboss-layout-check-clean{padding:12px 14px;color:${T.inkSoft}}
.ausboss-layout-check-clean small{display:block;margin-top:2px;color:${T.faint};font-size:11px}
.ausboss-layout-check footer{padding:7px 14px 9px;border-top:1px solid ${T.rule};color:${T.faint};font-size:11px}
`;
document.head.append(style);
}
const el = (tag, className, text) => {
const node = document.createElement(tag);
if (className) node.className = className;
if (text !== undefined && text !== null) node.textContent = text;
return node;
};
// A name from the graph: never translated, whatever it says.
const nameSpan = (text) => {
const span = el("span", "", text);
span.dataset.noI18n = "";
return span;
};
const LINK_MODES = { 0: "straight", 1: "linear", 2: "spline" };
function titleHeight(node) {
const LG = globalThis.LiteGraph;
const none = LG?.NO_TITLE;
if (none !== undefined && (node.title_mode === none || node.constructor?.title_mode === none)) return 0;
return LG?.NODE_TITLE_HEIGHT ?? 30;
}
// A graph as plain numbers for checkLayout.
function readGraph(graph, top) {
const LG = globalThis.LiteGraph;
const nodes = (graph._nodes ?? graph.nodes ?? []).map((node) => {
const collapsed = Boolean(node.flags?.collapsed);
const kind = NOTE_TYPES.has(node.type) ? "note" : CALLOUT_TYPES.has(node.type) ? "callout" : null;
return {
id: node.id,
x: node.pos[0],
y: node.pos[1],
w: collapsed ? (node._collapsed_width ?? LG?.NODE_COLLAPSED_WIDTH ?? 80) : node.size[0],
h: collapsed ? 0 : node.size[1],
titleHeight: titleHeight(node),
grows: GROWS.has(node.type),
kind,
};
});
const mode = app.canvas?.links_render_mode;
const links = [];
if (mode !== LG?.HIDDEN_LINK) {
const all = graph.links instanceof Map ? [...graph.links.values()] : Object.values(graph.links ?? {});
for (const link of all) {
const from = link && graph.getNodeById?.(link.origin_id);
const to = link && graph.getNodeById?.(link.target_id);
if (!from || !to) continue;
const start = from.getConnectionPos?.(false, link.origin_slot);
const end = to.getConnectionPos?.(true, link.target_slot);
if (!start || !end) continue;
const via = [];
for (let id = link.parentId, guard = 0; id !== undefined && id !== null && guard < 64; guard++) {
const reroute = graph.reroutes?.get?.(id);
if (!reroute) break;
via.unshift([reroute.pos[0], reroute.pos[1]]);
id = reroute.parentId;
}
links.push({ id: link.id, from: from.id, to: to.id, points: [[start[0], start[1]], ...via, [end[0], end[1]]] });
}
}
const groups = (graph.groups ?? graph._groups ?? []).map((group) => {
const [x, y, w, h] = group._bounding ?? [group.pos[0], group.pos[1], group.size[0], group.size[1]];
return { id: group.id, x, y, w, h };
});
const shape = { nodes, links, groups, linkMode: LINK_MODES[mode] ?? "spline", topLevel: top };
if (top) {
const notes = (graph._nodes ?? []).filter((node) => NOTE_TYPES.has(node.type));
shape.noteFilled = notes.some((node) => {
const note = normalizeNote(node.widgets?.find((widget) => widget.name === "note")?.value);
return Boolean(note.title && note.body.trim());
});
if (app.canvas?.graph === graph) shape.scale = app.canvas.ds?.scale;
}
return shape;
}
// Every issue of the workflow, each with the graph it is in and the names of
// the boxes that lead there.
function findIssues() {
const root = app.rootGraph ?? app.graph;
if (!root) return [];
const graphs = [{ graph: root, path: [] }];
for (const sub of root.subgraphs?.values?.() ?? []) graphs.push({ graph: sub, path: [sub.name || "Subgraph"] });
const out = [];
for (const { graph, path } of graphs) {
for (const issue of checkLayout(readGraph(graph, path.length === 0))) out.push({ ...issue, graph, path });
}
return out.sort((a, b) => KINDS.indexOf(a.kind) - KINDS.indexOf(b.kind));
}
const nodeName = (graph, id) => {
const node = graph.getNodeById?.(id);
return node?.getTitle?.() ?? node?.title ?? String(id);
};
const groupName = (graph, id) => (graph.groups ?? []).find((group) => group.id === id)?.title || "Group";
// The two lines of an entry: what, and why or where.
function describe(issue) {
const { graph } = issue;
const names = (ids) => ids.map((id) => nodeName(graph, id));
const main = [];
const small = [];
const wires = issue.wires > 1 ? [" · ", el("span", "", `${issue.wires} wires`)] : [];
switch (issue.kind) {
case "overlap":
main.push(nameSpan(names(issue.nodes).join(" × ")));
small.push("Title bars count too");
break;
case "group-overlap":
main.push(nameSpan(issue.groups.map((id) => groupName(graph, id)).join(" × ")));
small.push("One group crosses the other");
break;
case "under-grower":
main.push(nameSpan(nodeName(graph, issue.nodes[0])));
small.push(el("span", "", "Under:"), " ", nameSpan(nodeName(graph, issue.nodes[1])));
break;
case "hidden-wire":
main.push(nameSpan(names(issue.nodes.slice(0, 2)).join(" → ")));
small.push(el("span", "", "Behind:"), " ", nameSpan(names(issue.behind).join(", ")), ...wires);
break;
case "backward-wire":
main.push(nameSpan(names(issue.nodes).join(" → ")));
small.push(el("span", "", "Ends left of where it starts"), ...wires);
break;
case "outside-group":
main.push(nameSpan(nodeName(graph, issue.nodes[0])));
small.push("Move it into a group");
break;
case "no-groups":
main.push("Nothing here is in a group");
small.push("Put each step in a numbered group");
break;
case "zoom":
main.push(el("span", "", "Saved zoom:"), " ", nameSpan(issue.scale.toFixed(2)));
small.push(el("span", "", `Below ${MIN_ZOOM.toFixed(2)} the text on nodes stops drawing`));
break;
case "no-note":
main.push(issue.empty ? "The Workflow Note has no title or steps" : "Add a Workflow Note");
small.push("It tells people what the workflow does and how to run it");
break;
default:
main.push(issue.kind);
}
if (issue.path.length) small.push(small.length ? " · " : "", el("span", "", "Inside:"), " ", nameSpan(issue.path.join(" › ")));
return { main, small };
}
// Open the graph the issue is in, select what it names and bring it into view.
function jump(issue) {
const canvas = app.canvas;
if (!canvas) return;
const { graph } = issue;
if (canvas.graph !== graph) {
const root = app.rootGraph ?? app.graph;
if (graph !== root && typeof canvas.openSubgraph === "function") canvas.openSubgraph(graph);
else canvas.setGraph?.(graph);
}
canvas.deselectAll?.();
for (const id of issue.nodes ?? []) {
const node = graph.getNodeById?.(id);
if (node) canvas.select?.(node);
}
for (const id of issue.groups ?? []) {
const group = (graph.groups ?? []).find((item) => item.id === id);
if (group) canvas.select?.(group);
}
const focus = issue.focus;
if (focus) {
const view = canvas.canvas?.getBoundingClientRect?.();
// Frame it in the part of the canvas left of the panel, so what the
// panel names is never under it.
const viewport = jumpViewport(view, panel?.getBoundingClientRect?.());
const size = viewport ? [viewport[2], viewport[3]] : [view?.width, view?.height];
const rect = frameBounds([focus[0], focus[1], focus[2] - focus[0], focus[3] - focus[1]], size, FRAME_FILL);
const options = viewport ? { zoom: FRAME_FILL, viewport } : { zoom: FRAME_FILL };
if (typeof canvas.animateToBounds === "function") canvas.animateToBounds(rect, options);
else canvas.ds?.fitToBounds?.(rect, options);
}
canvas.setDirty?.(true, true);
}
let panel = null;
function onKey(event) {
if (event.key !== "Escape" || !panel || event.target?.closest?.("input,textarea,select,[contenteditable]")) return;
closePanel();
}
function closePanel() {
if (!panel) return;
panel.remove();
panel = null;
window.removeEventListener("keydown", onKey, true);
}
function fill(list, count) {
const issues = findIssues();
list.replaceChildren();
count.textContent = issues.length === 0 ? "Nothing to fix" : issues.length === 1 ? "1 thing to look at" : `${issues.length} things to look at`;
if (!issues.length) {
const clean = el("div", "ausboss-layout-check-clean", "Nothing to fix.");
clean.append(el("small", "", "No overlaps, no hidden or backwards wires, and every node sits in a group."));
list.append(clean);
return;
}
for (const [kind, total] of countByKind(issues)) {
const heading = el("h4", "", KIND_LABEL[kind] ?? kind);
heading.append(el("i", "", String(total)));
list.append(heading);
for (const issue of issues.filter((item) => item.kind === kind)) {
const { main, small } = describe(issue);
const canJump = Boolean(issue.focus || issue.nodes?.length || issue.groups?.length);
const row = el(canJump ? "button" : "div", `ausboss-layout-check-row${canJump ? "" : " is-info"}`);
if (canJump) row.type = "button";
row.append(...main);
if (small.length) {
const line = el("small");
line.append(...small);
row.append(line);
}
if (canJump) {
row.addEventListener("click", () => {
list.querySelector(".is-picked")?.classList.remove("is-picked");
row.classList.add("is-picked");
jump(issue);
});
}
list.append(row);
}
}
}
function openPanel() {
closePanel();
ensureCss();
panel = el("div", "ausboss-layout-check");
panel.setAttribute("role", "dialog");
panel.setAttribute("aria-label", LABEL);
const head = el("header");
const count = el("span");
const again = compactAction("Check again", "Look at the workflow again after a change");
const close = compactAction("✕", "Close");
head.append(el("b", "", LABEL), count, again, close);
const list = el("div", "ausboss-layout-check-list");
panel.append(head, list, el("footer", "", "Click an entry to jump to it. Nothing is moved."));
again.addEventListener("click", () => fill(list, count));
close.addEventListener("click", closePanel);
// The panel is not part of the canvas: a press here must not start a drag.
panel.addEventListener("pointerdown", (event) => event.stopPropagation());
const rect = app.canvas?.canvas?.getBoundingClientRect?.();
panel.style.left = `${(rect?.right ?? window.innerWidth) - 376}px`;
panel.style.top = `${(rect?.top ?? 0) + 100}px`;
document.body.append(panel);
window.addEventListener("keydown", onKey, true);
fill(list, count);
}
app.registerExtension({
name: "AusBoss.LayoutCheck",
commands: [{ id: "AusBoss.CheckLayout", label: `AusBoss: ${LABEL}`, function: openPanel }],
getCanvasMenuItems() {
return [{ content: `${t(LABEL)} 🆎`, callback: openPanel }];
},
afterConfigureGraph() {
closePanel();
},
});
+33
View File
@@ -326,6 +326,37 @@ export const ZH = {
"Your own ratios from ausboss_presets.json. Picking one works like a ratio button.": "来自 ausboss_presets.json 的自定义比例。选中它的效果和点比例按钮一样。",
"Choose or upload an image": "选择或上传图片",
"Preview could not load this image": "预览无法加载这张图片",
// ---- Check layout
"Check layout": "检查布局",
"Check again": "再检查一次",
"Look at the workflow again after a change": "改动之后再检查一遍工作流",
"Click an entry to jump to it. Nothing is moved.": "点击一项即可跳转过去。不会移动任何东西。",
"Nothing to fix": "没有要改的",
"Nothing to fix.": "没有要改的。",
"No overlaps, no hidden or backwards wires, and every node sits in a group.": "没有重叠,没有被挡住或反向的连线,每个节点都在分组里。",
"1 thing to look at": "1 处需要看一下",
"Overlapping": "重叠",
"Groups overlapping": "分组重叠",
"Under a node that grows": "在会变高的节点下面",
"Wire behind a node": "连线被节点挡住",
"Wire runs backwards": "连线反向",
"Outside every group": "不在任何分组里",
"Zoomed out too far": "缩得太小",
"No Workflow Note": "没有工作流说明",
"Title bars count too": "标题栏也算在内",
"One group crosses the other": "一个分组压到了另一个分组",
"Under:": "位于其下:",
"Behind:": "挡住它的:",
"Ends left of where it starts": "终点在起点左边",
"Move it into a group": "把它移进一个分组",
"Nothing here is in a group": "这里没有东西在分组里",
"Put each step in a numbered group": "把每一步放进带编号的分组",
"Saved zoom:": "保存的缩放:",
"Below 0.60 the text on nodes stops drawing": "低于 0.60 时节点上的文字不再显示",
"The Workflow Note has no title or steps": "工作流说明没有标题或步骤",
"Add a Workflow Note": "添加一个工作流说明",
"It tells people what the workflow does and how to run it": "它告诉大家这个工作流做什么、怎么运行",
"Inside:": "位于:",
};
// Strings that deliberately stay English on a Chinese face: names, symbols
@@ -349,4 +380,6 @@ export const PATTERNS = [
[/^Source · feather (\d+) px · Fill (#[0-9a-fA-F]{6})$/, (m, f, c) => `素材 · 羽化 ${f} px · 填充 ${c}`],
[/^Source · Fill (#[0-9a-fA-F]{6})$/, (m, c) => `素材 · 填充 ${c}`],
[/^(\d+):(\d+): reshape to this ratio\. The flip button on the left sets the orientation\.$/, (m, a, b) => `${a}:${b}:重塑为此比例。左侧的翻转按钮用来切换横竖方向。`],
[/^(\d+) things to look at$/, (m, n) => `${n} 处需要看一下`],
[/^(\d+) wires$/, (m, n) => `${n} 条连线`],
];
+252
View File
@@ -0,0 +1,252 @@
// Check layout 🆎: what makes a workflow hard to read, worked out from plain
// numbers. No DOM and no ComfyUI imports, so node:test runs it
// (tests/layout_check_math.test.mjs); js/layout_check/ reads the canvas
// into this shape, shows the list and jumps to an entry. Nothing here moves
// anything.
//
// The graph, in canvas units:
// nodes: [{ id, title, x, y, w, h, grows, kind }] x, y is the top left of
// the body; the title bar sits above it, titleHeight tall. grows:
// the node gets taller when it shows a run's picture or text.
// kind: "note" for a Workflow Note, "callout" for a Callout.
// groups: [{ id, title, x, y, w, h }]
// links: [{ id, from, to, points: [[x, y], ...] }] the output socket, any
// reroutes on the way, then the input socket.
// scale: the zoom the workflow is saved at (top level only).
// noteFilled: for a top-level graph, whether a Workflow Note has a title
// and instructions (null when there is no note).
export const TITLE_HEIGHT = 30;
// Below this saved zoom ComfyUI stops drawing widget text
// (scripts/workflow_contract.py holds the same number).
export const MIN_ZOOM = 0.6;
// How much taller a node that shows a picture can get after a run. A node
// starting closer than this under it can end up covered.
export const GROW_ROOM = 300;
// A wire runs backwards when it ends further left than the node it starts
// from, by more than this. A wire from a node down to the next one in its
// column ends at the same left edge, which reads fine.
export const BACKWARD_SLACK = 10;
// The order the list shows its kinds in: what hides something first.
export const KINDS = [
"overlap",
"group-overlap",
"under-grower",
"hidden-wire",
"backward-wire",
"outside-group",
"no-groups",
"zoom",
"no-note",
];
const finite = (value, fallback = 0) => (Number.isFinite(Number(value)) ? Number(value) : fallback);
// [left, top, right, bottom] of a node with its title bar.
// A node drawn without a title bar (a Callout tile) gives its own
// `titleHeight` of 0.
export function nodeBox(node, titleHeight = TITLE_HEIGHT) {
const x = finite(node?.x);
const y = finite(node?.y);
const top = Number.isFinite(node?.titleHeight) ? node.titleHeight : titleHeight;
return [x, y - top, x + Math.max(0, finite(node?.w)), y + Math.max(0, finite(node?.h))];
}
export function groupBox(group) {
const x = finite(group?.x);
const y = finite(group?.y);
return [x, y, x + Math.max(0, finite(group?.w)), y + Math.max(0, finite(group?.h))];
}
// Two boxes share more than `slack` units both ways.
export function boxesOverlap(a, b, slack = 1) {
return Math.min(a[2], b[2]) > Math.max(a[0], b[0]) + slack && Math.min(a[3], b[3]) > Math.max(a[1], b[1]) + slack;
}
// `inner` sits wholly inside `outer`, give or take `slack`.
export function boxInside(inner, outer, slack = 1) {
return inner[0] >= outer[0] - slack && inner[1] >= outer[1] - slack && inner[2] <= outer[2] + slack && inner[3] <= outer[3] + slack;
}
export function unionBox(boxes) {
const list = boxes.filter(Boolean);
if (!list.length) return null;
return [
Math.min(...list.map((box) => box[0])),
Math.min(...list.map((box) => box[1])),
Math.max(...list.map((box) => box[2])),
Math.max(...list.map((box) => box[3])),
];
}
// Points along a wire, the way the canvas draws one: from each point to the
// next a curve that leaves to the right and arrives from the left, its
// handles a quarter of the distance long. `mode` "straight" or "linear"
// draws straight pieces instead.
export function wirePoints(points, mode = "spline", per = 24) {
const list = (Array.isArray(points) ? points : []).filter((p) => Array.isArray(p) && p.length >= 2).map((p) => [finite(p[0]), finite(p[1])]);
if (list.length < 2) return list;
const out = [list[0]];
for (let i = 1; i < list.length; i++) {
const [ax, ay] = list[i - 1];
const [bx, by] = list[i];
const reach = mode === "spline" ? Math.hypot(bx - ax, by - ay) * 0.25 : 0;
const c1 = [ax + reach, ay];
const c2 = [bx - reach, by];
for (let s = 1; s <= per; s++) {
const t = s / per;
const u = 1 - t;
out.push([
u * u * u * ax + 3 * u * u * t * c1[0] + 3 * u * t * t * c2[0] + t * t * t * bx,
u * u * u * ay + 3 * u * u * t * c1[1] + 3 * u * t * t * c2[1] + t * t * t * by,
]);
}
}
return out;
}
const inBox = (point, box, inset = 2) => point[0] > box[0] + inset && point[0] < box[2] - inset && point[1] > box[1] + inset && point[1] < box[3] - inset;
// A Callout standing in a Workflow Note's own column belongs to the note,
// the way scripts/workflow_contract.py reads it.
function besideNote(node, notes) {
if (node.kind !== "callout") return false;
const left = finite(node.x);
const right = left + finite(node.w);
return notes.some((note) => note.x <= left && right <= note.x + note.w + 1);
}
export function checkLayout(graph, options = {}) {
const titleHeight = finite(options.titleHeight, TITLE_HEIGHT);
const growRoom = finite(options.growRoom, GROW_ROOM);
const nodes = (graph?.nodes ?? []).filter((node) => node && node.id !== undefined && node.id !== null);
const groups = graph?.groups ?? [];
const links = graph?.links ?? [];
const box = new Map(nodes.map((node) => [node.id, nodeBox(node, titleHeight)]));
const issues = [];
const add = (kind, fields) => issues.push({ kind, nodes: [], groups: [], ...fields });
const overlapping = new Set();
for (let i = 0; i < nodes.length; i++) {
for (let j = i + 1; j < nodes.length; j++) {
const a = nodes[i];
const b = nodes[j];
if (!boxesOverlap(box.get(a.id), box.get(b.id))) continue;
overlapping.add(`${a.id}|${b.id}`).add(`${b.id}|${a.id}`);
add("overlap", { nodes: [a.id, b.id], focus: unionBox([box.get(a.id), box.get(b.id)]) });
}
}
for (let i = 0; i < groups.length; i++) {
for (let j = i + 1; j < groups.length; j++) {
const a = groupBox(groups[i]);
const b = groupBox(groups[j]);
// A group wholly inside another is a nested group, which is fine.
if (!boxesOverlap(a, b) || boxInside(a, b) || boxInside(b, a)) continue;
add("group-overlap", { groups: [groups[i].id, groups[j].id], focus: unionBox([a, b]) });
}
}
for (const grower of nodes.filter((node) => node.grows)) {
const top = box.get(grower.id);
for (const node of nodes) {
if (node === grower || overlapping.has(`${grower.id}|${node.id}`)) continue;
const below = box.get(node.id);
const sideways = Math.min(top[2], below[2]) - Math.max(top[0], below[0]);
const gap = below[1] - top[3];
if (sideways > 1 && gap >= -1 && gap < growRoom) {
add("under-grower", { nodes: [node.id, grower.id], gap: Math.max(0, Math.round(gap)), focus: unionBox([top, below]) });
}
}
}
// Two wires between the same two nodes (a model and a clip, say) are one
// entry that counts them.
const wireIssues = new Map();
const addWire = (kind, key, fields) => {
const seen = wireIssues.get(`${kind}|${key}`);
if (seen) {
seen.wires += 1;
seen.links.push(fields.link);
return;
}
const issue = { kind, nodes: [], groups: [], wires: 1, links: [fields.link], ...fields };
wireIssues.set(`${kind}|${key}`, issue);
issues.push(issue);
};
const mode = graph?.linkMode ?? "spline";
for (const link of links) {
const points = wirePoints(link.points, mode);
if (points.length < 2) continue;
const behind = nodes.filter((node) => node.id !== link.from && node.id !== link.to && points.some((p) => inBox(p, box.get(node.id))));
if (behind.length) {
addWire("hidden-wire", `${link.from}|${link.to}|${behind.map((node) => node.id).join(",")}`, {
link: link.id,
nodes: [link.from, link.to, ...behind.map((node) => node.id)],
behind: behind.map((node) => node.id),
focus: unionBox([...behind.map((node) => box.get(node.id)), unionBox(points.map((p) => [p[0], p[1], p[0], p[1]]))]),
});
}
const corners = link.points.map((p) => [finite(p[0]), finite(p[1])]);
const start = box.get(link.from)?.[0] ?? corners[0][0];
if (corners.some((p, i) => i > 0 && p[0] < start - BACKWARD_SLACK)) {
addWire("backward-wire", `${link.from}|${link.to}`, {
link: link.id,
nodes: [link.from, link.to],
focus: unionBox([box.get(link.from), box.get(link.to)].concat(corners.map((p) => [p[0], p[1], p[0], p[1]]))),
});
}
}
const notes = nodes.filter((node) => node.kind === "note");
if (nodes.length && !groups.length) {
add("no-groups", { focus: unionBox([...box.values()]) });
} else if (groups.length) {
const boxes = groups.map(groupBox);
for (const node of nodes) {
if (node.kind === "note" || besideNote(node, notes)) continue;
if (boxes.some((group) => boxInside(box.get(node.id), group))) continue;
add("outside-group", { nodes: [node.id], focus: box.get(node.id) });
}
}
const scale = Number(graph?.scale);
if (Number.isFinite(scale) && scale < MIN_ZOOM) add("zoom", { scale: Math.round(scale * 100) / 100 });
if (graph?.topLevel && nodes.length && !graph.noteFilled) {
add("no-note", notes.length ? { nodes: [notes[0].id], focus: box.get(notes[0].id), empty: true } : {});
}
return issues.sort((a, b) => KINDS.indexOf(a.kind) - KINDS.indexOf(b.kind));
}
// The issues of a graph and every subgraph inside it, each marked with the
// path of box names that leads to it. `graphs` is [{ path: [...names],
// graph }], the top level first.
export function checkAll(graphs, options = {}) {
const out = [];
for (const { path = [], graph } of graphs ?? []) {
for (const issue of checkLayout({ ...graph, topLevel: path.length === 0 && graph?.topLevel !== false }, options)) {
out.push({ ...issue, path });
}
}
return out;
}
// How many issues of each kind, in list order: [[kind, count], ...].
export function countByKind(issues) {
const counts = new Map();
for (const issue of issues ?? []) counts.set(issue.kind, (counts.get(issue.kind) ?? 0) + 1);
return KINDS.filter((kind) => counts.has(kind)).map((kind) => [kind, counts.get(kind)]);
}
// The part of the canvas a jump frames its target in: everything left of the
// Check layout panel, so what it names never lands under it. `view` and
// `panel` are screen boxes ({ left, top, width, height }); the result is
// [x, y, width, height] in the canvas's own pixels, or null for the whole
// canvas (no panel, or too little room beside it).
export function jumpViewport(view, panel, margin = 16, least = 320) {
if (!(view?.width > 0) || !(view?.height > 0) || !panel) return null;
const room = Math.min(view.width, panel.left - view.left - margin);
if (!(room >= least)) return null;
return [0, 0, room, view.height];
}
+229
View File
@@ -0,0 +1,229 @@
// Check layout's decisions (js/shared/layout_check_math.mjs): what counts as
// an overlap, a backwards or hidden wire, a node under one that grows, a node
// outside every group, and a saved zoom too small to read.
import assert from "node:assert/strict";
import test from "node:test";
import {
GROW_ROOM,
KINDS,
MIN_ZOOM,
boxInside,
boxesOverlap,
checkAll,
checkLayout,
countByKind,
jumpViewport,
nodeBox,
wirePoints,
} from "../js/shared/layout_check_math.mjs";
const node = (id, x, y, w = 200, h = 100, extra = {}) => ({ id, title: `n${id}`, x, y, w, h, ...extra });
const group = (id, x, y, w, h) => ({ id, title: `g${id}`, x, y, w, h });
const kinds = (issues) => issues.map((issue) => issue.kind);
const wrapAll = (nodes) => [group(1, -1000, -1000, 4000, 4000)];
test("a node's box includes its title bar", () => {
assert.deepEqual(nodeBox(node(1, 10, 50, 200, 100)), [10, 20, 210, 150]);
assert.deepEqual(nodeBox(node(1, 10, 50, 200, 100), 40), [10, 10, 210, 150]);
});
test("a node without a title bar has none in its box", () => {
assert.deepEqual(nodeBox({ ...node(1, 10, 50, 200, 100), titleHeight: 0 }), [10, 50, 210, 150]);
});
test("boxes that only touch do not overlap", () => {
assert.equal(boxesOverlap([0, 0, 100, 100], [100, 0, 200, 100]), false);
assert.equal(boxesOverlap([0, 0, 100, 100], [99.5, 0, 200, 100]), false);
assert.equal(boxesOverlap([0, 0, 100, 100], [90, 90, 200, 200]), true);
assert.equal(boxInside([10, 10, 20, 20], [0, 0, 100, 100]), true);
assert.equal(boxInside([10, 10, 120, 20], [0, 0, 100, 100]), false);
});
test("a title bar that sits on the node above counts as an overlap", () => {
// n2's body starts 20 under n1's bottom, so its 30-unit title bar overlaps.
const issues = checkLayout({ nodes: [node(1, 0, 0), node(2, 0, 120)], groups: wrapAll() });
assert.deepEqual(kinds(issues), ["overlap"]);
assert.deepEqual(issues[0].nodes, [1, 2]);
assert.deepEqual(issues[0].focus, [0, -30, 200, 220]);
const clear = checkLayout({ nodes: [node(1, 0, 0), node(2, 0, 140)], groups: wrapAll() });
assert.deepEqual(kinds(clear), []);
});
test("groups that cross each other overlap; a group inside another does not", () => {
const crossing = checkLayout({ nodes: [], groups: [group(1, 0, 0, 300, 300), group(2, 200, 200, 300, 300)] });
assert.deepEqual(kinds(crossing), ["group-overlap"]);
assert.deepEqual(crossing[0].groups, [1, 2]);
const nested = checkLayout({ nodes: [], groups: [group(1, 0, 0, 500, 500), group(2, 50, 50, 100, 100)] });
assert.deepEqual(kinds(nested), []);
});
test("a node close under one that grows is flagged, one far below is not", () => {
const grower = node(1, 0, 0, 300, 200, { grows: true });
const near = checkLayout({ nodes: [grower, node(2, 50, 300)], groups: wrapAll() });
assert.deepEqual(kinds(near), ["under-grower"]);
assert.deepEqual(near[0].nodes, [2, 1]);
assert.equal(near[0].gap, 70);
const far = checkLayout({ nodes: [grower, node(2, 50, 200 + 30 + GROW_ROOM + 1)], groups: wrapAll() });
assert.deepEqual(kinds(far), []);
const beside = checkLayout({ nodes: [grower, node(2, 340, 300)], groups: wrapAll() });
assert.deepEqual(kinds(beside), []);
const plain = checkLayout({ nodes: [node(1, 0, 0, 300, 200), node(2, 50, 300)], groups: wrapAll() });
assert.deepEqual(kinds(plain), []);
});
test("a node that already overlaps the grower is an overlap, not both", () => {
const issues = checkLayout({ nodes: [node(1, 0, 0, 300, 200, { grows: true }), node(2, 0, 190)], groups: wrapAll() });
assert.deepEqual(kinds(issues), ["overlap"]);
});
test("a wire that ends left of the node it starts from runs backwards", () => {
const nodes = [node(1, 400, 0), node(2, 0, 300)];
const issues = checkLayout({ nodes, groups: wrapAll(), links: [{ id: 7, from: 1, to: 2, points: [[600, 20], [0, 320]] }] });
assert.deepEqual(kinds(issues), ["backward-wire"]);
assert.equal(issues[0].link, 7);
const forward = checkLayout({ nodes: [node(1, 0, 0), node(2, 400, 0)], groups: wrapAll(), links: [{ id: 7, from: 1, to: 2, points: [[200, 20], [400, 20]] }] });
assert.deepEqual(kinds(forward), []);
// Down to the next node in the same column reads fine, a few units off too.
const column = checkLayout({ nodes: [node(1, 0, 0), node(2, 0, 300)], groups: wrapAll(), links: [{ id: 7, from: 1, to: 2, points: [[200, 20], [0, 320]] }] });
assert.deepEqual(kinds(column), []);
const nearly = checkLayout({ nodes: [node(1, 0, 0), node(2, -8, 300)], groups: wrapAll(), links: [{ id: 7, from: 1, to: 2, points: [[200, 20], [-8, 320]] }] });
assert.deepEqual(kinds(nearly), []);
});
test("a reroute that sends the wire back left counts too", () => {
const issues = checkLayout({
nodes: [node(1, 0, 0), node(2, 600, 0)],
groups: wrapAll(),
links: [{ id: 3, from: 1, to: 2, points: [[200, 20], [-100, 400], [600, 20]] }],
});
assert.ok(kinds(issues).includes("backward-wire"));
});
test("a wire that passes under another node is hidden behind it", () => {
const nodes = [node(1, 0, 0), node(2, 800, 0), node(3, 350, -50, 200, 200)];
const issues = checkLayout({ nodes, groups: wrapAll(), links: [{ id: 9, from: 1, to: 2, points: [[200, 50], [800, 50]] }] });
assert.deepEqual(kinds(issues), ["hidden-wire"]);
assert.deepEqual(issues[0].behind, [3]);
assert.deepEqual(issues[0].nodes, [1, 2, 3]);
// Moved out of the way, nothing is hidden.
nodes[2] = node(3, 350, 300, 200, 200);
assert.deepEqual(kinds(checkLayout({ nodes, groups: wrapAll(), links: [{ id: 9, from: 1, to: 2, points: [[200, 50], [800, 50]] }] })), []);
});
test("the wire is traced as the canvas draws it, curving out to the right first", () => {
const points = wirePoints([[0, 0], [400, 300]]);
assert.deepEqual(points[0], [0, 0]);
assert.deepEqual(points.at(-1), [400, 300]);
// The curve leaves flat: its first sample is further right than down.
assert.ok(points[1][0] > points[1][1]);
// A straight piece stays on the line.
const straight = wirePoints([[0, 0], [400, 300]], "linear", 4);
assert.deepEqual(straight[2], [200, 150]);
assert.deepEqual(wirePoints([[1, 2]]), [[1, 2]]);
assert.deepEqual(wirePoints(null), []);
});
test("a curve that swings under a neighbour is caught", () => {
// A steep wire in a narrow gap swings out past its end (workflow-design.md, Wires 4).
const nodes = [node(1, 0, 0), node(2, 260, 600), node(3, 240, 200, 200, 120)];
const issues = checkLayout({ nodes, groups: wrapAll(), links: [{ id: 1, from: 1, to: 2, points: [[200, 20], [260, 620]] }] });
assert.ok(kinds(issues).includes("hidden-wire"));
});
test("every node has to sit inside a group, title bar included", () => {
const issues = checkLayout({ nodes: [node(1, 20, 40), node(2, 20, 300)], groups: [group(1, 0, 0, 260, 200)] });
assert.deepEqual(kinds(issues), ["outside-group"]);
assert.deepEqual(issues[0].nodes, [2]);
const titleOut = checkLayout({ nodes: [node(1, 20, 20)], groups: [group(1, 0, 0, 260, 200)] });
assert.deepEqual(kinds(titleOut), ["outside-group"]);
});
test("a Workflow Note, and a Callout in its column, may sit outside the groups", () => {
const note = node(1, 0, 0, 400, 600, { kind: "note" });
const callout = node(2, 10, 700, 380, 120, { kind: "callout" });
const loose = node(3, 10, 900, 380, 120, { kind: "callout" });
const issues = checkLayout({ nodes: [note, callout, { ...loose, x: 900 }, node(4, 520, 40)], groups: [group(1, 500, 0, 300, 300)] });
assert.deepEqual(issues.map((issue) => [issue.kind, issue.nodes[0]]), [["outside-group", 3]]);
});
test("a graph with nodes and no groups gets one entry, not one per node", () => {
const issues = checkLayout({ nodes: [node(1, 0, 0), node(2, 400, 0)] });
assert.deepEqual(kinds(issues), ["no-groups"]);
assert.deepEqual(kinds(checkLayout({ nodes: [] })), []);
});
test("a saved zoom below the readable limit is flagged", () => {
assert.deepEqual(kinds(checkLayout({ nodes: [], scale: 0.45 })), ["zoom"]);
assert.equal(checkLayout({ nodes: [], scale: 0.456 })[0].scale, 0.46);
assert.deepEqual(kinds(checkLayout({ nodes: [], scale: MIN_ZOOM })), []);
assert.deepEqual(kinds(checkLayout({ nodes: [] })), []);
});
test("the top level wants a Workflow Note with a title and instructions", () => {
const groups = wrapAll();
assert.deepEqual(kinds(checkLayout({ nodes: [node(1, 0, 0)], groups, topLevel: true, noteFilled: null })), ["no-note"]);
const empty = checkLayout({ nodes: [node(1, 0, 0, 200, 100, { kind: "note" })], groups, topLevel: true, noteFilled: false });
assert.deepEqual(kinds(empty), ["no-note"]);
assert.equal(empty[0].empty, true);
assert.deepEqual(empty[0].nodes, [1]);
assert.deepEqual(kinds(checkLayout({ nodes: [node(1, 0, 0)], groups, topLevel: true, noteFilled: true })), []);
// Inside a box nobody expects a note.
assert.deepEqual(kinds(checkLayout({ nodes: [node(1, 0, 0)], groups })), []);
});
test("subgraphs are checked with their path, and only the top level wants a note", () => {
const issues = checkAll([
{ path: [], graph: { nodes: [node(1, 0, 0)], groups: wrapAll(), noteFilled: true } },
{ path: ["Cut out the area"], graph: { nodes: [node(5, 0, 0), node(6, 0, 100)], groups: wrapAll() } },
]);
assert.deepEqual(issues.map((issue) => [issue.kind, issue.path]), [["overlap", ["Cut out the area"]]]);
});
test("the list is in a fixed order and counts each kind", () => {
const issues = checkLayout({
nodes: [node(1, 0, 0), node(2, 0, 100), node(3, 2000, 2000)],
groups: [group(1, -50, -50, 400, 400)],
scale: 0.3,
});
assert.deepEqual(kinds(issues), ["overlap", "outside-group", "zoom"]);
assert.deepEqual(countByKind([...issues, issues[0]]), [["overlap", 2], ["outside-group", 1], ["zoom", 1]]);
assert.equal(new Set(KINDS).size, KINDS.length);
});
test("bad input gives no issues instead of throwing", () => {
assert.deepEqual(checkLayout(null), []);
assert.deepEqual(checkLayout({ nodes: [{ id: null }, null], groups: null, links: [{ id: 1, from: 1, to: 2, points: [] }] }), []);
assert.deepEqual(checkAll(null), []);
});
test("two wires between the same nodes behind the same node are one entry", () => {
const nodes = [node(1, 0, 0), node(2, 800, 0), node(3, 350, -50, 200, 200)];
const links = [
{ id: 9, from: 1, to: 2, points: [[200, 50], [800, 50]] },
{ id: 10, from: 1, to: 2, points: [[200, 70], [800, 70]] },
];
const issues = checkLayout({ nodes, groups: wrapAll(), links });
assert.deepEqual(kinds(issues), ["hidden-wire"]);
assert.equal(issues[0].wires, 2);
assert.deepEqual(issues[0].links, [9, 10]);
const back = checkLayout({ nodes: [node(1, 400, 0), node(2, 0, 300)], groups: wrapAll(), links: [
{ id: 1, from: 1, to: 2, points: [[600, 20], [0, 320]] },
{ id: 2, from: 1, to: 2, points: [[600, 40], [0, 340]] },
] });
assert.deepEqual(back.map((issue) => [issue.kind, issue.wires]), [["backward-wire", 2]]);
});
test("a jump frames its target left of the panel, so the panel never covers it", () => {
const view = { left: 0, top: 40, width: 1600, height: 900 };
// The panel on the right: the jump uses the canvas left of it, less a margin.
assert.deepEqual(jumpViewport(view, { left: 1220, top: 60, width: 360, height: 500 }), [0, 0, 1204, 900]);
// A canvas that does not start at the screen's left edge.
assert.deepEqual(jumpViewport({ ...view, left: 300 }, { left: 1520 }), [0, 0, 1204, 900]);
// No panel, or too little room beside it: the whole canvas.
assert.equal(jumpViewport(view, null), null);
assert.equal(jumpViewport(view, { left: 200 }), null);
assert.equal(jumpViewport(null, { left: 1220 }), null);
});