Skip to content

Commit 8959e15

Browse files
authored
Merge pull request #162 from jitendra-kumawat/master
Updated arrange method to support vertical layout of nodes
2 parents 2401cec + b5aab00 commit 8959e15

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
@@ -417,7 +417,7 @@ export declare class LGraph {
417417
/**
418418
* Positions every node in a more readable manner
419419
*/
420-
arrange(margin?: number): void;
420+
arrange(margin?: number,layout?: string): void;
421421
/**
422422
* Returns the amount of time the graph has been running in milliseconds
423423
* @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
@@ -87,6 +87,7 @@
8787
NO_TITLE: 1,
8888
TRANSPARENT_TITLE: 2,
8989
AUTOHIDE_TITLE: 3,
90+
VERTICAL_LAYOUT: "vertical", // arrange nodes vertically
9091

9192
proxy: null, //used to redirect calls
9293
node_images_path: "",
@@ -1258,7 +1259,7 @@
12581259
* Positions every node in a more readable manner
12591260
* @method arrange
12601261
*/
1261-
LGraph.prototype.arrange = function(margin) {
1262+
LGraph.prototype.arrange = function (margin, layout) {
12621263
margin = margin || 100;
12631264

12641265
var nodes = this.computeExecutionOrder(false, true);
@@ -1283,12 +1284,14 @@
12831284
var y = margin + LiteGraph.NODE_TITLE_HEIGHT;
12841285
for (var j = 0; j < column.length; ++j) {
12851286
var node = column[j];
1286-
node.pos[0] = x;
1287-
node.pos[1] = y;
1288-
if (node.size[0] > max_size) {
1289-
max_size = node.size[0];
1290-
}
1291-
y += node.size[1] + margin + LiteGraph.NODE_TITLE_HEIGHT;
1287+
node.pos[0] = (layout == LiteGraph.VERTICAL_LAYOUT) ? y : x;
1288+
node.pos[1] = (layout == LiteGraph.VERTICAL_LAYOUT) ? x : y;
1289+
max_size_index = (layout == LiteGraph.VERTICAL_LAYOUT) ? 1 : 0;
1290+
if (node.size[max_size_index] > max_size) {
1291+
max_size = node.size[max_size_index];
1292+
}
1293+
node_size_index = (layout == LiteGraph.VERTICAL_LAYOUT) ? 0 : 1;
1294+
y += node.size[node_size_index] + margin + LiteGraph.NODE_TITLE_HEIGHT;
12921295
}
12931296
x += max_size + margin;
12941297
}

0 commit comments

Comments
 (0)