Updated arrange method to support vertical layouting of nodes

This commit is contained in:
jitendra kumawat
2020-07-28 12:56:49 +05:30
parent d46bc11816
commit 5365cd1af7
2 changed files with 10 additions and 7 deletions

2
src/litegraph.d.ts vendored
View File

@@ -412,7 +412,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

View File

@@ -80,6 +80,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: "",
@@ -1146,7 +1147,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);
@@ -1171,12 +1172,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];
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];
}
y += node.size[1] + margin + LiteGraph.NODE_TITLE_HEIGHT;
node_size_index = (layout == LiteGraph.VERTICAL_LAYOUT) ? 0 : 1;
y += node.size[node_size_index] + margin + LiteGraph.NODE_TITLE_HEIGHT
}
x += max_size + margin;
}