Skip to content

Commit 5365cd1

Browse files
Updated arrange method to support vertical layouting of nodes
1 parent d46bc11 commit 5365cd1

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

src/litegraph.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ export declare class LGraph {
412412
/**
413413
* Positions every node in a more readable manner
414414
*/
415-
arrange(margin?: number): void;
415+
arrange(margin?: number,layout?: string): void;
416416
/**
417417
* Returns the amount of time the graph has been running in milliseconds
418418
* @return number of milliseconds the graph has been running

src/litegraph.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
NO_TITLE: 1,
8181
TRANSPARENT_TITLE: 2,
8282
AUTOHIDE_TITLE: 3,
83+
VERTICAL_LAYOUT: "vertical", // arrange nodes vertically
8384

8485
proxy: null, //used to redirect calls
8586
node_images_path: "",
@@ -1146,7 +1147,7 @@
11461147
* Positions every node in a more readable manner
11471148
* @method arrange
11481149
*/
1149-
LGraph.prototype.arrange = function(margin) {
1150+
LGraph.prototype.arrange = function (margin, layout) {
11501151
margin = margin || 100;
11511152

11521153
var nodes = this.computeExecutionOrder(false, true);
@@ -1171,12 +1172,14 @@
11711172
var y = margin + LiteGraph.NODE_TITLE_HEIGHT;
11721173
for (var j = 0; j < column.length; ++j) {
11731174
var node = column[j];
1174-
node.pos[0] = x;
1175-
node.pos[1] = y;
1176-
if (node.size[0] > max_size) {
1177-
max_size = node.size[0];
1178-
}
1179-
y += node.size[1] + margin + LiteGraph.NODE_TITLE_HEIGHT;
1175+
node.pos[0] = (layout == LiteGraph.VERTICAL_LAYOUT) ? y : x;
1176+
node.pos[1] = (layout == LiteGraph.VERTICAL_LAYOUT) ? x : y;
1177+
max_size_index = (layout == LiteGraph.VERTICAL_LAYOUT) ? 1 : 0;
1178+
if (node.size[max_size_index] > max_size) {
1179+
max_size = node.size[max_size_index];
1180+
}
1181+
node_size_index = (layout == LiteGraph.VERTICAL_LAYOUT) ? 0 : 1;
1182+
y += node.size[node_size_index] + margin + LiteGraph.NODE_TITLE_HEIGHT
11801183
}
11811184
x += max_size + margin;
11821185
}

0 commit comments

Comments
 (0)