Skip to content

Commit 2bbfdb6

Browse files
committed
Fixes for subgraph page #24
1 parent 508f657 commit 2bbfdb6

File tree

5 files changed

+162
-7
lines changed

5 files changed

+162
-7
lines changed

.eslintrc.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,7 @@ module.exports = {
1515
'no-tabs': 'off',
1616
'import/extensions': 'off',
1717
'prefer-rest-params': 'off', // allow use of arguments
18+
'no-continue': 'off',
19+
'no-restricted-syntax': 'off',
1820
},
1921
};

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@ python -m http.server
2828

2929
## Changelog
3030

31+
2025-07-15 v1.0.17: Draw connections in subgraph mode. https://github.com/niknah/quick-connections/issues/24
3132
2025-07-04 v1.0.16: Problem with the enable/disable toggle not working. https://github.com/niknah/quick-connections/issues/19
3233
2024-11-03: It defaults to mostly 90 or 45 degree lines now. This can be changed in the options back to the old way(connect any angle when nothing is blocking).

docs/CircuitBoardLines.js

Lines changed: 80 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
const EPSILON = 1e-6;
1919
const INSIDE = 1;
2020
const OUTSIDE = 0;
21+
2122
function clipT(num, denom, c) {
2223
/* eslint-disable one-var,no-param-reassign,prefer-destructuring,operator-linebreak */
2324
/* eslint-disable one-var-declaration-per-line,nonblock-statement-body-position,curly */
@@ -828,14 +829,90 @@ export class CircuitBoardLines {
828829
return false;
829830
}
830831

831-
this.recalcMapLinksCheck();
832+
try {
833+
this.recalcMapLinksCheck();
834+
835+
this.mapLinks.drawLinks(ctx);
832836

833-
this.mapLinks.drawLinks(ctx);
834-
this.lastDrawConnections = new Date().getTime();
837+
if (this.canvas.subgraph) {
838+
this.drawSubgraphConnections(ctx, this.canvas.graph, this.canvas.subgraph);
839+
}
840+
} catch(e) {
841+
console.error('drawConnections crash', e);
842+
} finally {
843+
this.lastDrawConnections = new Date().getTime();
844+
}
835845

836846
return true;
837847
}
838848

849+
drawSubgraphConnections(
850+
ctx,
851+
graph,
852+
subgraph,
853+
) {
854+
for (const output of subgraph.inputNode.slots) { // eslint-disable-line no-restricted-syntax
855+
if (!output.linkIds.length) {
856+
continue;
857+
}
858+
859+
// find link info
860+
for (const linkId of output.linkIds) { // eslint-disable-line no-restricted-syntax
861+
const resolved = LiteGraph.LLink.resolve(linkId, graph);
862+
if (!resolved) continue;
863+
864+
const { link, inputNode, input } = resolved;
865+
if (!inputNode || !input)
866+
continue;
867+
868+
const endPos = inputNode.getInputPos(link.target_slot);
869+
870+
const startDir = input.dir || LiteGraph.RIGHT;
871+
const endDir = input.dir || LiteGraph.LEFT;
872+
873+
this.canvas.renderLink(
874+
ctx,
875+
output.pos,
876+
endPos,
877+
link,
878+
false,
879+
0,
880+
null,
881+
startDir,
882+
endDir,
883+
);
884+
}
885+
}
886+
887+
for (const input of subgraph.outputNode.slots) { // eslint-disable-line no-restricted-syntax
888+
if (!input.linkIds.length) continue;
889+
890+
// find link info
891+
const resolved = LiteGraph.LLink.resolve(input.linkIds[0], graph);
892+
if (!resolved) continue;
893+
894+
const { link, outputNode, output } = resolved;
895+
if (!outputNode || !output) continue;
896+
897+
const startPos = outputNode.getOutputPos(link.origin_slot);
898+
899+
const startDir = output.dir || LiteGraph.RIGHT;
900+
const endDir = input.dir || LiteGraph.LEFT;
901+
902+
this.canvas.renderLink(
903+
ctx,
904+
startPos,
905+
input.pos,
906+
link,
907+
false,
908+
0,
909+
null,
910+
startDir,
911+
endDir,
912+
);
913+
}
914+
}
915+
839916
init() {
840917
const oldDrawConnections = LGraphCanvas.prototype.drawConnections;
841918
const t = this;

js/CircuitBoardLines.js

Lines changed: 78 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
const EPSILON = 1e-6;
1919
const INSIDE = 1;
2020
const OUTSIDE = 0;
21+
2122
function clipT(num, denom, c) {
2223
/* eslint-disable one-var,no-param-reassign,prefer-destructuring,operator-linebreak */
2324
/* eslint-disable one-var-declaration-per-line,nonblock-statement-body-position,curly */
@@ -828,14 +829,88 @@ export class CircuitBoardLines {
828829
return false;
829830
}
830831

831-
this.recalcMapLinksCheck();
832+
try {
833+
this.recalcMapLinksCheck();
834+
835+
this.mapLinks.drawLinks(ctx);
832836

833-
this.mapLinks.drawLinks(ctx);
834-
this.lastDrawConnections = new Date().getTime();
837+
if (this.canvas.subgraph) {
838+
this.drawSubgraphConnections(ctx, this.canvas.graph, this.canvas.subgraph);
839+
}
840+
} finally {
841+
this.lastDrawConnections = new Date().getTime();
842+
}
835843

836844
return true;
837845
}
838846

847+
drawSubgraphConnections(
848+
ctx,
849+
graph,
850+
subgraph,
851+
) {
852+
for (const output of subgraph.inputNode.slots) { // eslint-disable-line no-restricted-syntax
853+
if (!output.linkIds.length) {
854+
continue;
855+
}
856+
857+
// find link info
858+
for (const linkId of output.linkIds) { // eslint-disable-line no-restricted-syntax
859+
const resolved = LiteGraph.LLink.resolve(linkId, graph);
860+
if (!resolved) continue;
861+
862+
const { link, inputNode, input } = resolved;
863+
if (!inputNode || !input)
864+
continue;
865+
866+
const endPos = inputNode.getInputPos(link.target_slot);
867+
868+
const startDir = input.dir || LiteGraph.RIGHT;
869+
const endDir = input.dir || LiteGraph.LEFT;
870+
871+
this.canvas.renderLink(
872+
ctx,
873+
output.pos,
874+
endPos,
875+
link,
876+
false,
877+
0,
878+
null,
879+
startDir,
880+
endDir,
881+
);
882+
}
883+
}
884+
885+
for (const input of subgraph.outputNode.slots) { // eslint-disable-line no-restricted-syntax
886+
if (!input.linkIds.length) continue;
887+
888+
// find link info
889+
const resolved = LiteGraph.LLink.resolve(input.linkIds[0], graph);
890+
if (!resolved) continue;
891+
892+
const { link, outputNode, output } = resolved;
893+
if (!outputNode || !output) continue;
894+
895+
const startPos = outputNode.getOutputPos(link.origin_slot);
896+
897+
const startDir = output.dir || LiteGraph.RIGHT;
898+
const endDir = input.dir || LiteGraph.LEFT;
899+
900+
this.canvas.renderLink(
901+
ctx,
902+
startPos,
903+
input.pos,
904+
link,
905+
false,
906+
0,
907+
null,
908+
startDir,
909+
endDir,
910+
);
911+
}
912+
}
913+
839914
init() {
840915
const oldDrawConnections = LGraphCanvas.prototype.drawConnections;
841916
const t = this;

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[project]
22
name = "quick-connections"
33
description = "Quick connections, Circuit board connections"
4-
version = "1.0.17"
4+
version = "1.0.18"
55
license = {text = "MIT License"}
66

77
[project.urls]

0 commit comments

Comments
 (0)