Skip to content

Commit

Permalink
Merge pull request jagenjo#162 from jitendra-kumawat/master
Browse files Browse the repository at this point in the history
Updated arrange method to support vertical layout of nodes
  • Loading branch information
jagenjo authored Dec 2, 2021
2 parents 2401cec + b5aab00 commit 8959e15
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/litegraph.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ export declare class LGraph {
/**
* Positions every node in a more readable manner
*/
arrange(margin?: number): void;
arrange(margin?: number,layout?: string): void;
/**
* Returns the amount of time the graph has been running in milliseconds
* @return number of milliseconds the graph has been running
Expand Down
17 changes: 10 additions & 7 deletions src/litegraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
NO_TITLE: 1,
TRANSPARENT_TITLE: 2,
AUTOHIDE_TITLE: 3,
VERTICAL_LAYOUT: "vertical", // arrange nodes vertically

proxy: null, //used to redirect calls
node_images_path: "",
Expand Down Expand Up @@ -1258,7 +1259,7 @@
* Positions every node in a more readable manner
* @method arrange
*/
LGraph.prototype.arrange = function(margin) {
LGraph.prototype.arrange = function (margin, layout) {
margin = margin || 100;

var nodes = this.computeExecutionOrder(false, true);
Expand All @@ -1283,12 +1284,14 @@
var y = margin + LiteGraph.NODE_TITLE_HEIGHT;
for (var j = 0; j < column.length; ++j) {
var node = column[j];
node.pos[0] = x;
node.pos[1] = y;
if (node.size[0] > max_size) {
max_size = node.size[0];
}
y += node.size[1] + margin + LiteGraph.NODE_TITLE_HEIGHT;
node.pos[0] = (layout == LiteGraph.VERTICAL_LAYOUT) ? y : x;
node.pos[1] = (layout == LiteGraph.VERTICAL_LAYOUT) ? x : y;
max_size_index = (layout == LiteGraph.VERTICAL_LAYOUT) ? 1 : 0;
if (node.size[max_size_index] > max_size) {
max_size = node.size[max_size_index];
}
node_size_index = (layout == LiteGraph.VERTICAL_LAYOUT) ? 0 : 1;
y += node.size[node_size_index] + margin + LiteGraph.NODE_TITLE_HEIGHT;
}
x += max_size + margin;
}
Expand Down

0 comments on commit 8959e15

Please sign in to comment.