diff --git a/.eslintrc b/.eslintrc
index 7285c249fa..11fb9cd75e 100644
--- a/.eslintrc
+++ b/.eslintrc
@@ -44,6 +44,7 @@
"no-constant-condition": "warn",
"no-unused-vars": "warn",
"no-mixed-spaces-and-tabs": "warn",
- "no-unreachable": "warn"
+ "no-unreachable": "warn",
+ "curly": ["warn", "all"]
}
}
diff --git a/src/litegraph-editor.js b/src/litegraph-editor.js
index fe824d35ac..62dd7e77a2 100755
--- a/src/litegraph-editor.js
+++ b/src/litegraph-editor.js
@@ -47,7 +47,7 @@ function Editor(container_id, options) {
".tools-right"
);
- if (!options.skip_livemode)
+ if (!options.skip_livemode) {
this.addToolsButton(
"livemode_button",
"Live",
@@ -55,7 +55,8 @@ function Editor(container_id, options) {
this.onLiveButton.bind(this),
".tools-right"
);
- if (!options.skip_maximize)
+ }
+ if (!options.skip_maximize) {
this.addToolsButton(
"maximize_button",
"",
@@ -63,11 +64,16 @@ function Editor(container_id, options) {
this.onFullscreenButton.bind(this),
".tools-right"
);
- if (options.miniwindow) this.addMiniWindow(300, 200);
+ }
+ if (options.miniwindow) {
+ this.addMiniWindow(300, 200);
+ }
//append to DOM
var parent = document.getElementById(container_id);
- if (parent) parent.appendChild(root);
+ if (parent) {
+ parent.appendChild(root);
+ }
graphcanvas.resize();
//graphcanvas.draw(true,true);
@@ -89,10 +95,12 @@ Editor.prototype.addLoadCounter = function() {
setInterval(function() {
meter.querySelector(".cpuload .fgload").style.width =
2 * self.graph.execution_time * 90 + "px";
- if (self.graph.status == LGraph.STATUS_RUNNING)
+ if (self.graph.status == LGraph.STATUS_RUNNING) {
meter.querySelector(".gpuload .fgload").style.width =
self.graphcanvas.render_time * 10 * 90 + "px";
- else meter.querySelector(".gpuload .fgload").style.width = 4 + "px";
+ } else {
+ meter.querySelector(".gpuload .fgload").style.width = 4 + "px";
+ }
}, 200);
};
@@ -103,7 +111,9 @@ Editor.prototype.addToolsButton = function(
callback,
container
) {
- if (!container) container = ".tools";
+ if (!container) {
+ container = ".tools";
+ }
var button = this.createButton(name, icon_url);
button.id = id;
@@ -128,7 +138,9 @@ Editor.prototype.createPanel = function(title, options) {
Editor.prototype.createButton = function(name, icon_url) {
var button = document.createElement("button");
- if (icon_url) button.innerHTML = "
";
+ if (icon_url) {
+ button.innerHTML = "
";
+ }
button.innerHTML += name;
return button;
};
@@ -181,13 +193,15 @@ Editor.prototype.onLiveButton = function() {
};
Editor.prototype.goFullscreen = function() {
- if (this.root.requestFullscreen)
+ if (this.root.requestFullscreen) {
this.root.requestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
- else if (this.root.mozRequestFullscreen)
+ } else if (this.root.mozRequestFullscreen) {
this.root.requestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
- else if (this.root.webkitRequestFullscreen)
+ } else if (this.root.webkitRequestFullscreen) {
this.root.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
- else throw "Fullscreen not supported";
+ } else {
+ throw "Fullscreen not supported";
+ }
var self = this;
setTimeout(function() {
diff --git a/src/litegraph.js b/src/litegraph.js
index 6cf866edcc..96a295c48a 100755
--- a/src/litegraph.js
+++ b/src/litegraph.js
@@ -97,11 +97,14 @@
*/
registerNodeType: function(type, base_class) {
- if (!base_class.prototype)
+ if (!base_class.prototype) {
throw "Cannot register a simple object, it must be a class with a prototype";
+ }
base_class.type = type;
- if (LiteGraph.debug) console.log("Node registered: " + type);
+ if (LiteGraph.debug) {
+ console.log("Node registered: " + type);
+ }
var categories = type.split("/");
var classname = base_class.name;
@@ -109,15 +112,20 @@
var pos = type.lastIndexOf("/");
base_class.category = type.substr(0, pos);
- if (!base_class.title) base_class.title = classname;
+ if (!base_class.title) {
+ base_class.title = classname;
+ }
//info.name = name.substr(pos+1,name.length - pos);
//extend class
- if (base_class.prototype)
+ if (base_class.prototype) {
//is a class
- for (var i in LGraphNode.prototype)
- if (!base_class.prototype[i])
+ for (var i in LGraphNode.prototype) {
+ if (!base_class.prototype[i]) {
base_class.prototype[i] = LGraphNode.prototype[i];
+ }
+ }
+ }
Object.defineProperty(base_class.prototype, "shape", {
set: function(v) {
@@ -147,27 +155,33 @@
enumerable: true
});
- var prev = this.registered_node_types[type];
+ var prev = this.registered_node_types[type];
this.registered_node_types[type] = base_class;
- if (base_class.constructor.name) this.Nodes[classname] = base_class;
- if(LiteGraph.onNodeTypeRegistered)
- LiteGraph.onNodeTypeRegistered(type,base_class);
- if( prev && LiteGraph.onNodeTypeReplaced)
- LiteGraph.onNodeTypeReplaced(type,base_class,prev);
+ if (base_class.constructor.name) {
+ this.Nodes[classname] = base_class;
+ }
+ if (LiteGraph.onNodeTypeRegistered) {
+ LiteGraph.onNodeTypeRegistered(type, base_class);
+ }
+ if (prev && LiteGraph.onNodeTypeReplaced) {
+ LiteGraph.onNodeTypeReplaced(type, base_class, prev);
+ }
//warnings
- if (base_class.prototype.onPropertyChange)
+ if (base_class.prototype.onPropertyChange) {
console.warn(
"LiteGraph node class " +
type +
" has onPropertyChange method, it must be called onPropertyChanged with d at the end"
);
+ }
if (base_class.supported_extensions) {
- for (var i in base_class.supported_extensions)
+ for (var i in base_class.supported_extensions) {
this.node_types_by_file_extension[
base_class.supported_extensions[i].toLowerCase()
] = base_class;
+ }
}
},
@@ -191,7 +205,7 @@
var params = Array(func.length);
var code = "";
var names = LiteGraph.getParameterNames(func);
- for (var i = 0; i < names.length; ++i)
+ for (var i = 0; i < names.length; ++i) {
code +=
"this.addInput('" +
names[i] +
@@ -200,19 +214,22 @@
? "'" + param_types[i] + "'"
: "0") +
");\n";
+ }
code +=
"this.addOutput('out'," +
(return_type ? "'" + return_type + "'" : 0) +
");\n";
- if (properties)
+ if (properties) {
code +=
"this.properties = " + JSON.stringify(properties) + ";\n";
+ }
var classobj = Function(code);
classobj.title = name.split("/").pop();
classobj.desc = "Generated from " + func.name;
classobj.prototype.onExecute = function onExecute() {
- for (var i = 0; i < params.length; ++i)
+ for (var i = 0; i < params.length; ++i) {
params[i] = this.getInputData(i);
+ }
var r = func.apply(this, params);
this.setOutputData(0, r);
};
@@ -229,8 +246,9 @@
LGraphNode.prototype[name] = func;
for (var i in this.registered_node_types) {
var type = this.registered_node_types[i];
- if (type.prototype[name])
- type.prototype["_" + name] = type.prototype[name]; //keep old in case of replacing
+ if (type.prototype[name]) {
+ type.prototype["_" + name] = type.prototype[name];
+ } //keep old in case of replacing
type.prototype[name] = func;
}
},
@@ -246,10 +264,11 @@
createNode: function(type, title, options) {
var base_class = this.registered_node_types[type];
if (!base_class) {
- if (LiteGraph.debug)
+ if (LiteGraph.debug) {
console.log(
'GraphNode type "' + type + '" not registered.'
);
+ }
return null;
}
@@ -266,21 +285,39 @@
console.error(err);
return null;
}
- } else node = new base_class(title);
+ } else {
+ node = new base_class(title);
+ }
node.type = type;
- if (!node.title && title) node.title = title;
- if (!node.properties) node.properties = {};
- if (!node.properties_info) node.properties_info = [];
- if (!node.flags) node.flags = {};
- if (!node.size) node.size = node.computeSize();
- if (!node.pos) node.pos = LiteGraph.DEFAULT_POSITION.concat();
- if (!node.mode) node.mode = LiteGraph.ALWAYS;
+ if (!node.title && title) {
+ node.title = title;
+ }
+ if (!node.properties) {
+ node.properties = {};
+ }
+ if (!node.properties_info) {
+ node.properties_info = [];
+ }
+ if (!node.flags) {
+ node.flags = {};
+ }
+ if (!node.size) {
+ node.size = node.computeSize();
+ }
+ if (!node.pos) {
+ node.pos = LiteGraph.DEFAULT_POSITION.concat();
+ }
+ if (!node.mode) {
+ node.mode = LiteGraph.ALWAYS;
+ }
//extra options
if (options) {
- for (var i in options) node[i] = options[i];
+ for (var i in options) {
+ node[i] = options[i];
+ }
}
return node;
@@ -307,11 +344,17 @@
var r = [];
for (var i in this.registered_node_types) {
var type = this.registered_node_types[i];
- if (filter && type.filter && type.filter != filter) continue;
+ if (filter && type.filter && type.filter != filter) {
+ continue;
+ }
if (category == "") {
- if (type.category == null) r.push(type);
- } else if (type.category == category) r.push(type);
+ if (type.category == null) {
+ r.push(type);
+ }
+ } else if (type.category == category) {
+ r.push(type);
+ }
}
return r;
@@ -325,14 +368,18 @@
getNodeTypesCategories: function() {
var categories = { "": 1 };
- for (var i in this.registered_node_types)
+ for (var i in this.registered_node_types) {
if (
this.registered_node_types[i].category &&
!this.registered_node_types[i].skip_list
- )
+ ) {
categories[this.registered_node_types[i].category] = 1;
+ }
+ }
var result = [];
- for (var i in categories) result.push(i);
+ for (var i in categories) {
+ result.push(i);
+ }
return result;
},
@@ -341,7 +388,9 @@
var tmp = document.getElementsByTagName("script");
//weird, this array changes by its own, so we use a copy
var script_files = [];
- for (var i in tmp) script_files.push(tmp[i]);
+ for (var i in tmp) {
+ script_files.push(tmp[i]);
+ }
var docHeadObj = document.getElementsByTagName("head")[0];
folder_wildcard = document.location.href + folder_wildcard;
@@ -351,33 +400,47 @@
if (
!src ||
src.substr(0, folder_wildcard.length) != folder_wildcard
- )
+ ) {
continue;
+ }
try {
- if (LiteGraph.debug) console.log("Reloading: " + src);
+ if (LiteGraph.debug) {
+ console.log("Reloading: " + src);
+ }
var dynamicScript = document.createElement("script");
dynamicScript.type = "text/javascript";
dynamicScript.src = src;
docHeadObj.appendChild(dynamicScript);
docHeadObj.removeChild(script_files[i]);
} catch (err) {
- if (LiteGraph.throw_errors) throw err;
- if (LiteGraph.debug)
+ if (LiteGraph.throw_errors) {
+ throw err;
+ }
+ if (LiteGraph.debug) {
console.log("Error while reloading " + src);
+ }
}
}
- if (LiteGraph.debug) console.log("Nodes reloaded");
+ if (LiteGraph.debug) {
+ console.log("Nodes reloaded");
+ }
},
//separated just to improve if it doesn't work
cloneObject: function(obj, target) {
- if (obj == null) return null;
+ if (obj == null) {
+ return null;
+ }
var r = JSON.parse(JSON.stringify(obj));
- if (!target) return r;
+ if (!target) {
+ return r;
+ }
- for (var i in r) target[i] = r[i];
+ for (var i in r) {
+ target[i] = r[i];
+ }
return target;
},
@@ -387,8 +450,9 @@
!type_b || //generic input
type_a == type_b || //same type (is valid for triggers)
(type_a == LiteGraph.EVENT && type_b == LiteGraph.ACTION)
- )
+ ) {
return true;
+ }
// Enforce string type to handle toLowerCase call (-1 number not ok)
type_a = String(type_a);
@@ -397,16 +461,20 @@
type_b = type_b.toLowerCase();
// For nodes supporting multiple connection types
- if (type_a.indexOf(",") == -1 && type_b.indexOf(",") == -1)
+ if (type_a.indexOf(",") == -1 && type_b.indexOf(",") == -1) {
return type_a == type_b;
+ }
// Check all permutations to see if one is valid
var supported_types_a = type_a.split(",");
var supported_types_b = type_b.split(",");
- for (var i = 0; i < supported_types_a.length; ++i)
- for (var j = 0; j < supported_types_b.length; ++j)
- if (supported_types_a[i] == supported_types_b[j])
+ for (var i = 0; i < supported_types_a.length; ++i) {
+ for (var j = 0; j < supported_types_b.length; ++j) {
+ if (supported_types_a[i] == supported_types_b[j]) {
return true;
+ }
+ }
+ }
return false;
},
@@ -421,19 +489,20 @@
});
//timer that works everywhere
- if (typeof performance != "undefined")
+ if (typeof performance != "undefined") {
LiteGraph.getTime = performance.now.bind(performance);
- else if (typeof Date != "undefined" && Date.now)
+ } else if (typeof Date != "undefined" && Date.now) {
LiteGraph.getTime = Date.now.bind(Date);
- else if (typeof process != "undefined")
+ } else if (typeof process != "undefined") {
LiteGraph.getTime = function() {
var t = process.hrtime();
return t[0] * 0.001 + t[1] * 1e-6;
};
- else
+ } else {
LiteGraph.getTime = function getTime() {
return new Date().getTime();
};
+ }
//*********************************************************************************
// LGraph CLASS
@@ -448,11 +517,15 @@
*/
function LGraph(o) {
- if (LiteGraph.debug) console.log("Graph created");
+ if (LiteGraph.debug) {
+ console.log("Graph created");
+ }
this.list_of_graphcanvas = null;
this.clear();
- if (o) this.configure(o);
+ if (o) {
+ this.configure(o);
+ }
}
global.LGraph = LiteGraph.LGraph = LGraph;
@@ -483,11 +556,14 @@
this._version = -1; //used to detect changes
//safe clear
- if (this._nodes)
+ if (this._nodes) {
for (var i = 0; i < this._nodes.length; ++i) {
var node = this._nodes[i];
- if (node.onRemoved) node.onRemoved();
+ if (node.onRemoved) {
+ node.onRemoved();
+ }
}
+ }
//nodes
this._nodes = [];
@@ -535,13 +611,17 @@
*/
LGraph.prototype.attachCanvas = function(graphcanvas) {
- if (graphcanvas.constructor != LGraphCanvas)
+ if (graphcanvas.constructor != LGraphCanvas) {
throw "attachCanvas expects a LGraphCanvas instance";
- if (graphcanvas.graph && graphcanvas.graph != this)
+ }
+ if (graphcanvas.graph && graphcanvas.graph != this) {
graphcanvas.graph.detachCanvas(graphcanvas);
+ }
graphcanvas.graph = this;
- if (!this.list_of_graphcanvas) this.list_of_graphcanvas = [];
+ if (!this.list_of_graphcanvas) {
+ this.list_of_graphcanvas = [];
+ }
this.list_of_graphcanvas.push(graphcanvas);
};
@@ -551,10 +631,14 @@
* @param {GraphCanvas} graph_canvas
*/
LGraph.prototype.detachCanvas = function(graphcanvas) {
- if (!this.list_of_graphcanvas) return;
+ if (!this.list_of_graphcanvas) {
+ return;
+ }
var pos = this.list_of_graphcanvas.indexOf(graphcanvas);
- if (pos == -1) return;
+ if (pos == -1) {
+ return;
+ }
graphcanvas.graph = null;
this.list_of_graphcanvas.splice(pos, 1);
};
@@ -566,10 +650,14 @@
*/
LGraph.prototype.start = function(interval) {
- if (this.status == LGraph.STATUS_RUNNING) return;
+ if (this.status == LGraph.STATUS_RUNNING) {
+ return;
+ }
this.status = LGraph.STATUS_RUNNING;
- if (this.onPlayEvent) this.onPlayEvent();
+ if (this.onPlayEvent) {
+ this.onPlayEvent();
+ }
this.sendEventToAllNodes("onStart");
@@ -585,17 +673,20 @@
window.requestAnimationFrame
) {
function on_frame() {
- if (that.execution_timer_id != -1) return;
+ if (that.execution_timer_id != -1) {
+ return;
+ }
window.requestAnimationFrame(on_frame);
that.runStep(1, !this.catch_errors);
}
this.execution_timer_id = -1;
on_frame();
- } else
+ } else {
this.execution_timer_id = setInterval(function() {
//execute
that.runStep(1, !this.catch_errors);
}, interval);
+ }
};
/**
@@ -604,15 +695,20 @@
*/
LGraph.prototype.stop = function() {
- if (this.status == LGraph.STATUS_STOPPED) return;
+ if (this.status == LGraph.STATUS_STOPPED) {
+ return;
+ }
this.status = LGraph.STATUS_STOPPED;
- if (this.onStopEvent) this.onStopEvent();
+ if (this.onStopEvent) {
+ this.onStopEvent();
+ }
if (this.execution_timer_id != null) {
- if (this.execution_timer_id != -1)
+ if (this.execution_timer_id != -1) {
clearInterval(this.execution_timer_id);
+ }
this.execution_timer_id = null;
}
@@ -634,50 +730,67 @@
var nodes = this._nodes_executable
? this._nodes_executable
: this._nodes;
- if (!nodes) return;
+ if (!nodes) {
+ return;
+ }
if (do_not_catch_errors) {
//iterations
for (var i = 0; i < num; i++) {
for (var j = 0, l = nodes.length; j < l; ++j) {
var node = nodes[j];
- if (node.mode == LiteGraph.ALWAYS && node.onExecute)
+ if (node.mode == LiteGraph.ALWAYS && node.onExecute) {
node.onExecute();
+ }
}
this.fixedtime += this.fixedtime_lapse;
- if (this.onExecuteStep) this.onExecuteStep();
+ if (this.onExecuteStep) {
+ this.onExecuteStep();
+ }
}
- if (this.onAfterExecute) this.onAfterExecute();
+ if (this.onAfterExecute) {
+ this.onAfterExecute();
+ }
} else {
try {
//iterations
for (var i = 0; i < num; i++) {
for (var j = 0, l = nodes.length; j < l; ++j) {
var node = nodes[j];
- if (node.mode == LiteGraph.ALWAYS && node.onExecute)
+ if (node.mode == LiteGraph.ALWAYS && node.onExecute) {
node.onExecute();
+ }
}
this.fixedtime += this.fixedtime_lapse;
- if (this.onExecuteStep) this.onExecuteStep();
+ if (this.onExecuteStep) {
+ this.onExecuteStep();
+ }
}
- if (this.onAfterExecute) this.onAfterExecute();
+ if (this.onAfterExecute) {
+ this.onAfterExecute();
+ }
this.errors_in_execution = false;
} catch (err) {
this.errors_in_execution = true;
- if (LiteGraph.throw_errors) throw err;
- if (LiteGraph.debug)
+ if (LiteGraph.throw_errors) {
+ throw err;
+ }
+ if (LiteGraph.debug) {
console.log("Error during execution: " + err);
+ }
this.stop();
}
}
var now = LiteGraph.getTime();
var elapsed = now - start;
- if (elapsed == 0) elapsed = 1;
+ if (elapsed == 0) {
+ elapsed = 1;
+ }
this.execution_time = 0.001 * elapsed;
this.globaltime += 0.001 * elapsed;
this.iteration += 1;
@@ -693,9 +806,11 @@
LGraph.prototype.updateExecutionOrder = function() {
this._nodes_in_order = this.computeExecutionOrder(false);
this._nodes_executable = [];
- for (var i = 0; i < this._nodes_in_order.length; ++i)
- if (this._nodes_in_order[i].onExecute)
+ for (var i = 0; i < this._nodes_in_order.length; ++i) {
+ if (this._nodes_in_order[i].onExecute) {
this._nodes_executable.push(this._nodes_in_order[i]);
+ }
+ }
};
//This is more internal, it computes the executable nodes in order and returns it
@@ -712,35 +827,49 @@
//search for the nodes without inputs (starting nodes)
for (var i = 0, l = this._nodes.length; i < l; ++i) {
var node = this._nodes[i];
- if (only_onExecute && !node.onExecute) continue;
+ if (only_onExecute && !node.onExecute) {
+ continue;
+ }
M[node.id] = node; //add to pending nodes
var num = 0; //num of input connections
- if (node.inputs)
- for (var j = 0, l2 = node.inputs.length; j < l2; j++)
- if (node.inputs[j] && node.inputs[j].link != null) num += 1;
+ if (node.inputs) {
+ for (var j = 0, l2 = node.inputs.length; j < l2; j++) {
+ if (node.inputs[j] && node.inputs[j].link != null) {
+ num += 1;
+ }
+ }
+ }
if (num == 0) {
//is a starting node
S.push(node);
- if (set_level) node._level = 1;
+ if (set_level) {
+ node._level = 1;
+ }
} //num of input links
else {
- if (set_level) node._level = 0;
+ if (set_level) {
+ node._level = 0;
+ }
remaining_links[node.id] = num;
}
}
while (true) {
- if (S.length == 0) break;
+ if (S.length == 0) {
+ break;
+ }
//get an starting node
var node = S.shift();
L.push(node); //add to ordered list
delete M[node.id]; //remove from the pending nodes
- if (!node.outputs) continue;
+ if (!node.outputs) {
+ continue;
+ }
//for every output
for (var i = 0; i < node.outputs.length; i++) {
@@ -750,17 +879,22 @@
output == null ||
output.links == null ||
output.links.length == 0
- )
+ ) {
continue;
+ }
//for every connection
for (var j = 0; j < output.links.length; j++) {
var link_id = output.links[j];
var link = this.links[link_id];
- if (!link) continue;
+ if (!link) {
+ continue;
+ }
//already visited link (ignore it)
- if (visited_links[link.id]) continue;
+ if (visited_links[link.id]) {
+ continue;
+ }
var target_node = this.getNodeById(link.target_id);
if (target_node == null) {
@@ -772,40 +906,50 @@
set_level &&
(!target_node._level ||
target_node._level <= node._level)
- )
+ ) {
target_node._level = node._level + 1;
+ }
visited_links[link.id] = true; //mark as visited
remaining_links[target_node.id] -= 1; //reduce the number of links remaining
- if (remaining_links[target_node.id] == 0)
- S.push(target_node); //if no more links, then add to starters array
+ if (remaining_links[target_node.id] == 0) {
+ S.push(target_node);
+ } //if no more links, then add to starters array
}
}
}
//the remaining ones (loops)
- for (var i in M) L.push(M[i]);
+ for (var i in M) {
+ L.push(M[i]);
+ }
- if (L.length != this._nodes.length && LiteGraph.debug)
+ if (L.length != this._nodes.length && LiteGraph.debug) {
console.warn("something went wrong, nodes missing");
+ }
var l = L.length;
//save order number in the node
- for (var i = 0; i < l; ++i) L[i].order = i;
+ for (var i = 0; i < l; ++i) {
+ L[i].order = i;
+ }
//sort now by priority
L = L.sort(function(A, B) {
var Ap = A.constructor.priority || A.priority || 0;
var Bp = B.constructor.priority || B.priority || 0;
- if (Ap == Bp)
+ if (Ap == Bp) {
//if same priority, sort by order
return A.order - B.order;
+ }
return Ap - Bp; //sort by priority
});
//save order number in the node, again...
- for (var i = 0; i < l; ++i) L[i].order = i;
+ for (var i = 0; i < l; ++i) {
+ L[i].order = i;
+ }
return L;
};
@@ -823,7 +967,9 @@
while (pending.length) {
var current = pending.shift();
- if (!current.inputs) continue;
+ if (!current.inputs) {
+ continue;
+ }
if (!visited[current.id] && current != node) {
visited[current.id] = true;
ancestors.push(current);
@@ -855,7 +1001,9 @@
for (var i = 0; i < nodes.length; ++i) {
var node = nodes[i];
var col = node._level || 1;
- if (!columns[col]) columns[col] = [];
+ if (!columns[col]) {
+ columns[col] = [];
+ }
columns[col].push(node);
}
@@ -863,14 +1011,18 @@
for (var i = 0; i < columns.length; ++i) {
var column = columns[i];
- if (!column) continue;
+ if (!column) {
+ continue;
+ }
var max_size = 100;
var y = margin;
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];
+ if (node.size[0] > max_size) {
+ max_size = node.size[0];
+ }
y += node.size[1] + margin;
}
x += max_size + margin;
@@ -919,7 +1071,9 @@
mode = mode || LiteGraph.ALWAYS;
var nodes = this._nodes_in_order ? this._nodes_in_order : this._nodes;
- if (!nodes) return;
+ if (!nodes) {
+ return;
+ }
for (var j = 0, l = nodes.length; j < l; ++j) {
var node = nodes[j];
@@ -928,25 +1082,35 @@
node.constructor === LiteGraph.Subgraph &&
eventname != "onExecute"
) {
- if (node.mode == mode)
+ if (node.mode == mode) {
node.sendEventToAllNodes(eventname, params, mode);
+ }
continue;
}
- if (!node[eventname] || node.mode != mode) continue;
- if (params === undefined) node[eventname]();
- else if (params && params.constructor === Array)
+ if (!node[eventname] || node.mode != mode) {
+ continue;
+ }
+ if (params === undefined) {
+ node[eventname]();
+ } else if (params && params.constructor === Array) {
node[eventname].apply(node, params);
- else node[eventname](params);
+ } else {
+ node[eventname](params);
+ }
}
};
LGraph.prototype.sendActionToCanvas = function(action, params) {
- if (!this.list_of_graphcanvas) return;
+ if (!this.list_of_graphcanvas) {
+ return;
+ }
for (var i = 0; i < this.list_of_graphcanvas.length; ++i) {
var c = this.list_of_graphcanvas[i];
- if (c[action]) c[action].apply(c, params);
+ if (c[action]) {
+ c[action].apply(c, params);
+ }
}
};
@@ -957,7 +1121,9 @@
*/
LGraph.prototype.add = function(node, skip_compute_order) {
- if (!node) return;
+ if (!node) {
+ return;
+ }
//groups
if (node.constructor === LGraphGroup) {
@@ -977,12 +1143,16 @@
node.id = ++this.last_node_id;
}
- if (this._nodes.length >= LiteGraph.MAX_NUMBER_OF_NODES)
+ if (this._nodes.length >= LiteGraph.MAX_NUMBER_OF_NODES) {
throw "LiteGraph: max number of nodes in a graph reached";
+ }
//give him an id
- if (node.id == null || node.id == -1) node.id = ++this.last_node_id;
- else if (this.last_node_id < node.id) this.last_node_id = node.id;
+ if (node.id == null || node.id == -1) {
+ node.id = ++this.last_node_id;
+ } else if (this.last_node_id < node.id) {
+ this.last_node_id = node.id;
+ }
node.graph = this;
this._version++;
@@ -990,13 +1160,21 @@
this._nodes.push(node);
this._nodes_by_id[node.id] = node;
- if (node.onAdded) node.onAdded(this);
+ if (node.onAdded) {
+ node.onAdded(this);
+ }
- if (this.config.align_to_grid) node.alignToGrid();
+ if (this.config.align_to_grid) {
+ node.alignToGrid();
+ }
- if (!skip_compute_order) this.updateExecutionOrder();
+ if (!skip_compute_order) {
+ this.updateExecutionOrder();
+ }
- if (this.onNodeAdded) this.onNodeAdded(node);
+ if (this.onNodeAdded) {
+ this.onNodeAdded(node);
+ }
this.setDirtyCanvas(true);
this.change();
@@ -1013,7 +1191,9 @@
LGraph.prototype.remove = function(node) {
if (node.constructor === LiteGraph.LGraphGroup) {
var index = this._groups.indexOf(node);
- if (index != -1) this._groups.splice(index, 1);
+ if (index != -1) {
+ this._groups.splice(index, 1);
+ }
node.graph = null;
this._version++;
this.setDirtyCanvas(true, true);
@@ -1021,29 +1201,40 @@
return;
}
- if (this._nodes_by_id[node.id] == null) return; //not found
+ if (this._nodes_by_id[node.id] == null) {
+ return;
+ } //not found
- if (node.ignore_remove) return; //cannot be removed
+ if (node.ignore_remove) {
+ return;
+ } //cannot be removed
//disconnect inputs
- if (node.inputs)
+ if (node.inputs) {
for (var i = 0; i < node.inputs.length; i++) {
var slot = node.inputs[i];
- if (slot.link != null) node.disconnectInput(i);
+ if (slot.link != null) {
+ node.disconnectInput(i);
+ }
}
+ }
//disconnect outputs
- if (node.outputs)
+ if (node.outputs) {
for (var i = 0; i < node.outputs.length; i++) {
var slot = node.outputs[i];
- if (slot.links != null && slot.links.length)
+ if (slot.links != null && slot.links.length) {
node.disconnectOutput(i);
+ }
}
+ }
//node.id = -1; //why?
//callback
- if (node.onRemoved) node.onRemoved();
+ if (node.onRemoved) {
+ node.onRemoved();
+ }
node.graph = null;
this._version++;
@@ -1052,18 +1243,25 @@
if (this.list_of_graphcanvas) {
for (var i = 0; i < this.list_of_graphcanvas.length; ++i) {
var canvas = this.list_of_graphcanvas[i];
- if (canvas.selected_nodes[node.id])
+ if (canvas.selected_nodes[node.id]) {
delete canvas.selected_nodes[node.id];
- if (canvas.node_dragged == node) canvas.node_dragged = null;
+ }
+ if (canvas.node_dragged == node) {
+ canvas.node_dragged = null;
+ }
}
}
//remove from containers
var pos = this._nodes.indexOf(node);
- if (pos != -1) this._nodes.splice(pos, 1);
+ if (pos != -1) {
+ this._nodes.splice(pos, 1);
+ }
delete this._nodes_by_id[node.id];
- if (this.onNodeRemoved) this.onNodeRemoved(node);
+ if (this.onNodeRemoved) {
+ this.onNodeRemoved(node);
+ }
this.setDirtyCanvas(true, true);
this.change();
@@ -1078,7 +1276,9 @@
*/
LGraph.prototype.getNodeById = function(id) {
- if (id == null) return null;
+ if (id == null) {
+ return null;
+ }
return this._nodes_by_id[id];
};
@@ -1091,9 +1291,11 @@
LGraph.prototype.findNodesByClass = function(classObject, result) {
result = result || [];
result.length = 0;
- for (var i = 0, l = this._nodes.length; i < l; ++i)
- if (this._nodes[i].constructor === classObject)
+ for (var i = 0, l = this._nodes.length; i < l; ++i) {
+ if (this._nodes[i].constructor === classObject) {
result.push(this._nodes[i]);
+ }
+ }
return result;
};
@@ -1107,9 +1309,11 @@
var type = type.toLowerCase();
result = result || [];
result.length = 0;
- for (var i = 0, l = this._nodes.length; i < l; ++i)
- if (this._nodes[i].type.toLowerCase() == type)
+ for (var i = 0, l = this._nodes.length; i < l; ++i) {
+ if (this._nodes[i].type.toLowerCase() == type) {
result.push(this._nodes[i]);
+ }
+ }
return result;
};
@@ -1120,8 +1324,11 @@
* @return {Node} the node or null
*/
LGraph.prototype.findNodeByTitle = function(title) {
- for (var i = 0, l = this._nodes.length; i < l; ++i)
- if (this._nodes[i].title == title) return this._nodes[i];
+ for (var i = 0, l = this._nodes.length; i < l; ++i) {
+ if (this._nodes[i].title == title) {
+ return this._nodes[i];
+ }
+ }
return null;
};
@@ -1133,8 +1340,11 @@
*/
LGraph.prototype.findNodesByTitle = function(title) {
var result = [];
- for (var i = 0, l = this._nodes.length; i < l; ++i)
- if (this._nodes[i].title == title) result.push(this._nodes[i]);
+ for (var i = 0, l = this._nodes.length; i < l; ++i) {
+ if (this._nodes[i].title == title) {
+ result.push(this._nodes[i]);
+ }
+ }
return result;
};
@@ -1150,7 +1360,9 @@
nodes_list = nodes_list || this._nodes;
for (var i = nodes_list.length - 1; i >= 0; i--) {
var n = nodes_list[i];
- if (n.isPointInside(x, y, margin)) return n;
+ if (n.isPointInside(x, y, margin)) {
+ return n;
+ }
}
return null;
};
@@ -1165,39 +1377,43 @@
LGraph.prototype.getGroupOnPos = function(x, y) {
for (var i = this._groups.length - 1; i >= 0; i--) {
var g = this._groups[i];
- if (g.isPointInside(x, y, 2, true)) return g;
+ if (g.isPointInside(x, y, 2, true)) {
+ return g;
+ }
}
return null;
};
/**
* Checks that the node type matches the node type registered, used when replacing a nodetype by a newer version during execution
- * this replaces the ones using the old version with the new version
+ * this replaces the ones using the old version with the new version
* @method checkNodeTypes
*/
LGraph.prototype.checkNodeTypes = function() {
- var changes = false;
+ var changes = false;
for (var i = 0; i < this._nodes.length; i++) {
var node = this._nodes[i];
- var ctor = LiteGraph.registered_node_types[ node.type ];
- if(node.constructor == ctor)
- continue;
- console.log("node being replaced by newer version: " + node.type );
- var newnode = LiteGraph.createNode( node.type );
- changes = true;
- this._nodes[i] = newnode;
- newnode.configure( node.serialize() );
- newnode.graph = this;
- this._nodes_by_id[newnode.id] = newnode;
- if(node.inputs)
- newnode.inputs = node.inputs.concat();
- if(node.outputs)
- newnode.outputs = node.outputs.concat();
+ var ctor = LiteGraph.registered_node_types[node.type];
+ if (node.constructor == ctor) {
+ continue;
+ }
+ console.log("node being replaced by newer version: " + node.type);
+ var newnode = LiteGraph.createNode(node.type);
+ changes = true;
+ this._nodes[i] = newnode;
+ newnode.configure(node.serialize());
+ newnode.graph = this;
+ this._nodes_by_id[newnode.id] = newnode;
+ if (node.inputs) {
+ newnode.inputs = node.inputs.concat();
+ }
+ if (node.outputs) {
+ newnode.outputs = node.outputs.concat();
+ }
}
- this.updateExecutionOrder();
+ this.updateExecutionOrder();
};
-
// ********** GLOBALS *****************
LGraph.prototype.onAction = function(action, param) {
@@ -1207,14 +1423,18 @@
);
for (var i = 0; i < this._input_nodes.length; ++i) {
var node = this._input_nodes[i];
- if (node.properties.name != action) continue;
+ if (node.properties.name != action) {
+ continue;
+ }
node.onAction(action, param);
break;
}
};
LGraph.prototype.trigger = function(action, param) {
- if (this.onTrigger) this.onTrigger(action, param);
+ if (this.onTrigger) {
+ this.onTrigger(action, param);
+ }
};
/**
@@ -1226,16 +1446,21 @@
*/
LGraph.prototype.addInput = function(name, type, value) {
var input = this.inputs[name];
- if (input)
+ if (input) {
//already exist
return;
+ }
this.inputs[name] = { name: name, type: type, value: value };
this._version++;
- if (this.onInputAdded) this.onInputAdded(name, type);
+ if (this.onInputAdded) {
+ this.onInputAdded(name, type);
+ }
- if (this.onInputsOutputsChange) this.onInputsOutputsChange();
+ if (this.onInputsOutputsChange) {
+ this.onInputsOutputsChange();
+ }
};
/**
@@ -1246,7 +1471,9 @@
*/
LGraph.prototype.setInputData = function(name, data) {
var input = this.inputs[name];
- if (!input) return;
+ if (!input) {
+ return;
+ }
input.value = data;
};
@@ -1258,7 +1485,9 @@
*/
LGraph.prototype.getInputData = function(name) {
var input = this.inputs[name];
- if (!input) return null;
+ if (!input) {
+ return null;
+ }
return input.value;
};
@@ -1269,9 +1498,13 @@
* @param {String} new_name
*/
LGraph.prototype.renameInput = function(old_name, name) {
- if (name == old_name) return;
+ if (name == old_name) {
+ return;
+ }
- if (!this.inputs[old_name]) return false;
+ if (!this.inputs[old_name]) {
+ return false;
+ }
if (this.inputs[name]) {
console.error("there is already one input with that name");
@@ -1282,9 +1515,13 @@
delete this.inputs[old_name];
this._version++;
- if (this.onInputRenamed) this.onInputRenamed(old_name, name);
+ if (this.onInputRenamed) {
+ this.onInputRenamed(old_name, name);
+ }
- if (this.onInputsOutputsChange) this.onInputsOutputsChange();
+ if (this.onInputsOutputsChange) {
+ this.onInputsOutputsChange();
+ }
};
/**
@@ -1294,18 +1531,23 @@
* @param {String} type
*/
LGraph.prototype.changeInputType = function(name, type) {
- if (!this.inputs[name]) return false;
+ if (!this.inputs[name]) {
+ return false;
+ }
if (
this.inputs[name].type &&
String(this.inputs[name].type).toLowerCase() ==
String(type).toLowerCase()
- )
+ ) {
return;
+ }
this.inputs[name].type = type;
this._version++;
- if (this.onInputTypeChanged) this.onInputTypeChanged(name, type);
+ if (this.onInputTypeChanged) {
+ this.onInputTypeChanged(name, type);
+ }
};
/**
@@ -1315,14 +1557,20 @@
* @param {String} type
*/
LGraph.prototype.removeInput = function(name) {
- if (!this.inputs[name]) return false;
+ if (!this.inputs[name]) {
+ return false;
+ }
delete this.inputs[name];
this._version++;
- if (this.onInputRemoved) this.onInputRemoved(name);
+ if (this.onInputRemoved) {
+ this.onInputRemoved(name);
+ }
- if (this.onInputsOutputsChange) this.onInputsOutputsChange();
+ if (this.onInputsOutputsChange) {
+ this.onInputsOutputsChange();
+ }
return true;
};
@@ -1337,9 +1585,13 @@
this.outputs[name] = { name: name, type: type, value: value };
this._version++;
- if (this.onOutputAdded) this.onOutputAdded(name, type);
+ if (this.onOutputAdded) {
+ this.onOutputAdded(name, type);
+ }
- if (this.onInputsOutputsChange) this.onInputsOutputsChange();
+ if (this.onInputsOutputsChange) {
+ this.onInputsOutputsChange();
+ }
};
/**
@@ -1350,7 +1602,9 @@
*/
LGraph.prototype.setOutputData = function(name, value) {
var output = this.outputs[name];
- if (!output) return;
+ if (!output) {
+ return;
+ }
output.value = value;
};
@@ -1362,7 +1616,9 @@
*/
LGraph.prototype.getOutputData = function(name) {
var output = this.outputs[name];
- if (!output) return null;
+ if (!output) {
+ return null;
+ }
return output.value;
};
@@ -1373,7 +1629,9 @@
* @param {String} new_name
*/
LGraph.prototype.renameOutput = function(old_name, name) {
- if (!this.outputs[old_name]) return false;
+ if (!this.outputs[old_name]) {
+ return false;
+ }
if (this.outputs[name]) {
console.error("there is already one output with that name");
@@ -1384,9 +1642,13 @@
delete this.outputs[old_name];
this._version++;
- if (this.onOutputRenamed) this.onOutputRenamed(old_name, name);
+ if (this.onOutputRenamed) {
+ this.onOutputRenamed(old_name, name);
+ }
- if (this.onInputsOutputsChange) this.onInputsOutputsChange();
+ if (this.onInputsOutputsChange) {
+ this.onInputsOutputsChange();
+ }
};
/**
@@ -1396,18 +1658,23 @@
* @param {String} type
*/
LGraph.prototype.changeOutputType = function(name, type) {
- if (!this.outputs[name]) return false;
+ if (!this.outputs[name]) {
+ return false;
+ }
if (
this.outputs[name].type &&
String(this.outputs[name].type).toLowerCase() ==
String(type).toLowerCase()
- )
+ ) {
return;
+ }
this.outputs[name].type = type;
this._version++;
- if (this.onOutputTypeChanged) this.onOutputTypeChanged(name, type);
+ if (this.onOutputTypeChanged) {
+ this.onOutputTypeChanged(name, type);
+ }
};
/**
@@ -1416,29 +1683,41 @@
* @param {String} name
*/
LGraph.prototype.removeOutput = function(name) {
- if (!this.outputs[name]) return false;
+ if (!this.outputs[name]) {
+ return false;
+ }
delete this.outputs[name];
this._version++;
- if (this.onOutputRemoved) this.onOutputRemoved(name);
+ if (this.onOutputRemoved) {
+ this.onOutputRemoved(name);
+ }
- if (this.onInputsOutputsChange) this.onInputsOutputsChange();
+ if (this.onInputsOutputsChange) {
+ this.onInputsOutputsChange();
+ }
return true;
};
LGraph.prototype.triggerInput = function(name, value) {
var nodes = this.findNodesByTitle(name);
- for (var i = 0; i < nodes.length; ++i) nodes[i].onTrigger(value);
+ for (var i = 0; i < nodes.length; ++i) {
+ nodes[i].onTrigger(value);
+ }
};
LGraph.prototype.setCallback = function(name, func) {
var nodes = this.findNodesByTitle(name);
- for (var i = 0; i < nodes.length; ++i) nodes[i].setTrigger(func);
+ for (var i = 0; i < nodes.length; ++i) {
+ nodes[i].setTrigger(func);
+ }
};
LGraph.prototype.connectionChange = function(node, link_info) {
this.updateExecutionOrder();
- if (this.onConnectionChange) this.onConnectionChange(node);
+ if (this.onConnectionChange) {
+ this.onConnectionChange(node);
+ }
this._version++;
this.sendActionToCanvas("onConnectionChange");
};
@@ -1449,11 +1728,15 @@
*/
LGraph.prototype.isLive = function() {
- if (!this.list_of_graphcanvas) return false;
+ if (!this.list_of_graphcanvas) {
+ return false;
+ }
for (var i = 0; i < this.list_of_graphcanvas.length; ++i) {
var c = this.list_of_graphcanvas[i];
- if (c.live_mode) return true;
+ if (c.live_mode) {
+ return true;
+ }
}
return false;
};
@@ -1465,16 +1748,24 @@
LGraph.prototype.clearTriggeredSlots = function() {
for (var i in this.links) {
var link_info = this.links[i];
- if (!link_info) continue;
- if (link_info._last_time) link_info._last_time = 0;
+ if (!link_info) {
+ continue;
+ }
+ if (link_info._last_time) {
+ link_info._last_time = 0;
+ }
}
};
/* Called when something visually changed (not the graph!) */
LGraph.prototype.change = function() {
- if (LiteGraph.debug) console.log("Graph changed");
+ if (LiteGraph.debug) {
+ console.log("Graph changed");
+ }
this.sendActionToCanvas("setDirty", [true, true]);
- if (this.on_change) this.on_change(this);
+ if (this.on_change) {
+ this.on_change(this);
+ }
};
LGraph.prototype.setDirtyCanvas = function(fg, bg) {
@@ -1488,9 +1779,13 @@
*/
LGraph.prototype.removeLink = function(link_id) {
var link = this.links[link_id];
- if (!link) return;
+ if (!link) {
+ return;
+ }
var node = this.getNodeById(link.target_id);
- if (node) node.disconnectInput(link.target_slot);
+ if (node) {
+ node.disconnectInput(link.target_slot);
+ }
};
//save and recover app state ***************************************
@@ -1501,30 +1796,35 @@
*/
LGraph.prototype.serialize = function() {
var nodes_info = [];
- for (var i = 0, l = this._nodes.length; i < l; ++i)
+ for (var i = 0, l = this._nodes.length; i < l; ++i) {
nodes_info.push(this._nodes[i].serialize());
+ }
//pack link info into a non-verbose format
var links = [];
for (var i in this.links) {
//links is an OBJECT
var link = this.links[i];
- if(!link.serialize) //weird bug I havent solved yet
- {
- console.warn("weird LLink bug, link info is not a LLink but a regular object");
- var link2 = new LLink();
- for(var i in link)
- link2[i] = link[i];
- this.links[i] = link2;
- link = link2;
- }
+ if (!link.serialize) {
+ //weird bug I havent solved yet
+ console.warn(
+ "weird LLink bug, link info is not a LLink but a regular object"
+ );
+ var link2 = new LLink();
+ for (var i in link) {
+ link2[i] = link[i];
+ }
+ this.links[i] = link2;
+ link = link2;
+ }
links.push(link.serialize());
}
var groups_info = [];
- for (var i = 0; i < this._groups.length; ++i)
+ for (var i = 0; i < this._groups.length; ++i) {
groups_info.push(this._groups[i].serialize());
+ }
var data = {
last_node_id: this.last_node_id,
@@ -1546,9 +1846,13 @@
* @param {Boolean} returns if there was any error parsing
*/
LGraph.prototype.configure = function(data, keep_old) {
- if (!data) return;
+ if (!data) {
+ return;
+ }
- if (!keep_old) this.clear();
+ if (!keep_old) {
+ this.clear();
+ }
var nodes = data.nodes;
@@ -1565,7 +1869,9 @@
}
//copy all stored fields
- for (var i in data) this[i] = data[i];
+ for (var i in data) {
+ this[i] = data[i];
+ }
var error = false;
@@ -1576,10 +1882,11 @@
var n_info = nodes[i]; //stored info
var node = LiteGraph.createNode(n_info.type, n_info.title);
if (!node) {
- if (LiteGraph.debug)
+ if (LiteGraph.debug) {
console.log(
"Node not found or has errors: " + n_info.type
);
+ }
//in case of error we create a replacement node to avoid losing info
node = new LGraphNode();
@@ -1597,18 +1904,21 @@
for (var i = 0, l = nodes.length; i < l; ++i) {
var n_info = nodes[i];
var node = this.getNodeById(n_info.id);
- if (node) node.configure(n_info);
+ if (node) {
+ node.configure(n_info);
+ }
}
}
//groups
this._groups.length = 0;
- if (data.groups)
+ if (data.groups) {
for (var i = 0; i < data.groups.length; ++i) {
var group = new LiteGraph.LGraphGroup();
group.configure(data.groups[i]);
this.add(group);
}
+ }
this.updateExecutionOrder();
this._version++;
@@ -1758,7 +2068,9 @@
Object.defineProperty(this, "pos", {
set: function(v) {
- if (!v || v.length < 2) return;
+ if (!v || v.length < 2) {
+ return;
+ }
this._pos[0] = v[0];
this._pos[1] = v[1];
},
@@ -1788,40 +2100,42 @@
* @method configure
*/
LGraphNode.prototype.configure = function(info) {
- if (this.graph)
- this.graph._version++;
-
+ if (this.graph) {
+ this.graph._version++;
+ }
for (var j in info) {
if (j == "properties") {
//i don't want to clone properties, I want to reuse the old container
for (var k in info.properties) {
this.properties[k] = info.properties[k];
- if (this.onPropertyChanged)
+ if (this.onPropertyChanged) {
this.onPropertyChanged(k, info.properties[k]);
+ }
}
continue;
}
- if (info[j] == null)
- continue;
-
- //this will assign to the node itself anything found inside the serialized object
- if (typeof info[j] == "object") {
+ if (info[j] == null) {
+ continue;
+ } else if (typeof info[j] == "object") {
//object
- if (this[j] && this[j].configure)
- this[j].configure( info[j] );
- else
- this[j] = LiteGraph.cloneObject(info[j], this[j]);
+ if (this[j] && this[j].configure) {
+ this[j].configure(info[j]);
+ } else {
+ this[j] = LiteGraph.cloneObject(info[j], this[j]);
+ }
} //value
- else
- this[j] = info[j];
+ else {
+ this[j] = info[j];
+ }
}
- if (!info.title)
- this.title = this.constructor.title;
+ if (!info.title) {
+ this.title = this.constructor.title;
+ }
if (this.onConnectionsChange) {
- if (this.inputs)
+ if (this.inputs) {
for (var i = 0; i < this.inputs.length; ++i) {
var input = this.inputs[i];
var link_info = this.graph
@@ -1835,11 +2149,14 @@
input
); //link_info has been created now, so its updated
}
+ }
- if (this.outputs)
+ if (this.outputs) {
for (var i = 0; i < this.outputs.length; ++i) {
var output = this.outputs[i];
- if (!output.links) continue;
+ if (!output.links) {
+ continue;
+ }
for (var j = 0; j < output.links.length; ++j) {
var link_info = this.graph
? this.graph.links[output.links[j]]
@@ -1853,15 +2170,20 @@
); //link_info has been created now, so its updated
}
}
+ }
}
if (info.widgets_values && this.widgets) {
- for (var i = 0; i < info.widgets_values.length; ++i)
- if (this.widgets[i])
+ for (var i = 0; i < info.widgets_values.length; ++i) {
+ if (this.widgets[i]) {
this.widgets[i].value = info.widgets_values[i];
+ }
+ }
}
- if (this.onConfigure) this.onConfigure(info);
+ if (this.onConfigure) {
+ this.onConfigure(info);
+ }
};
/**
@@ -1881,42 +2203,60 @@
};
//special case for when there were errors
- if (this.constructor === LGraphNode && this.last_serialization)
+ if (this.constructor === LGraphNode && this.last_serialization) {
return this.last_serialization;
+ }
- if (this.inputs) o.inputs = this.inputs;
+ if (this.inputs) {
+ o.inputs = this.inputs;
+ }
if (this.outputs) {
//clear outputs last data (because data in connections is never serialized but stored inside the outputs info)
- for (var i = 0; i < this.outputs.length; i++)
+ for (var i = 0; i < this.outputs.length; i++) {
delete this.outputs[i]._data;
+ }
o.outputs = this.outputs;
}
- if (this.title && this.title != this.constructor.title)
+ if (this.title && this.title != this.constructor.title) {
o.title = this.title;
+ }
- if (this.properties)
+ if (this.properties) {
o.properties = LiteGraph.cloneObject(this.properties);
+ }
if (this.widgets && this.serialize_widgets) {
o.widgets_values = [];
- for (var i = 0; i < this.widgets.length; ++i)
+ for (var i = 0; i < this.widgets.length; ++i) {
o.widgets_values[i] = this.widgets[i].value;
+ }
}
- if (!o.type) o.type = this.constructor.type;
+ if (!o.type) {
+ o.type = this.constructor.type;
+ }
- if (this.color) o.color = this.color;
- if (this.bgcolor) o.bgcolor = this.bgcolor;
- if (this.boxcolor) o.boxcolor = this.boxcolor;
- if (this.shape) o.shape = this.shape;
+ if (this.color) {
+ o.color = this.color;
+ }
+ if (this.bgcolor) {
+ o.bgcolor = this.bgcolor;
+ }
+ if (this.boxcolor) {
+ o.boxcolor = this.boxcolor;
+ }
+ if (this.shape) {
+ o.shape = this.shape;
+ }
if (this.onSerialize) {
- if (this.onSerialize(o))
+ if (this.onSerialize(o)) {
console.warn(
"node onSerialize shouldnt return anything, data should be stored in the object pass in the first parameter"
);
+ }
}
return o;
@@ -1925,20 +2265,27 @@
/* Creates a clone of this node */
LGraphNode.prototype.clone = function() {
var node = LiteGraph.createNode(this.type);
- if (!node) return null;
+ if (!node) {
+ return null;
+ }
//we clone it because serialize returns shared containers
var data = LiteGraph.cloneObject(this.serialize());
//remove links
- if (data.inputs)
- for (var i = 0; i < data.inputs.length; ++i)
+ if (data.inputs) {
+ for (var i = 0; i < data.inputs.length; ++i) {
data.inputs[i].link = null;
-
- if (data.outputs)
- for (var i = 0; i < data.outputs.length; ++i) {
- if (data.outputs[i].links) data.outputs[i].links.length = 0;
}
+ }
+
+ if (data.outputs) {
+ for (var i = 0; i < data.outputs.length; ++i) {
+ if (data.outputs[i].links) {
+ data.outputs[i].links.length = 0;
+ }
+ }
+ }
delete data["id"];
//remove links
@@ -1973,12 +2320,14 @@
* @param {*} value
*/
LGraphNode.prototype.setProperty = function(name, value) {
- if(!this.properties)
- this.properties = {};
- this.properties[name] = value;
- if (this.onPropertyChanged)
- this.onPropertyChanged(name, value);
- };
+ if (!this.properties) {
+ this.properties = {};
+ }
+ this.properties[name] = value;
+ if (this.onPropertyChanged) {
+ this.onPropertyChanged(name, value);
+ }
+ };
// Execution *************************
/**
@@ -1988,16 +2337,22 @@
* @param {*} data
*/
LGraphNode.prototype.setOutputData = function(slot, data) {
- if (!this.outputs) return;
+ if (!this.outputs) {
+ return;
+ }
//this maybe slow and a niche case
//if(slot && slot.constructor === String)
// slot = this.findOutputSlot(slot);
- if (slot == -1 || slot >= this.outputs.length) return;
+ if (slot == -1 || slot >= this.outputs.length) {
+ return;
+ }
var output_info = this.outputs[slot];
- if (!output_info) return;
+ if (!output_info) {
+ return;
+ }
//store data in the output itself in case we want to debug
output_info._data = data;
@@ -2018,10 +2373,16 @@
* @param {String} datatype
*/
LGraphNode.prototype.setOutputDataType = function(slot, type) {
- if (!this.outputs) return;
- if (slot == -1 || slot >= this.outputs.length) return;
+ if (!this.outputs) {
+ return;
+ }
+ if (slot == -1 || slot >= this.outputs.length) {
+ return;
+ }
var output_info = this.outputs[slot];
- if (!output_info) return;
+ if (!output_info) {
+ return;
+ }
//store data in the output itself in case we want to debug
output_info.type = type;
@@ -2042,25 +2403,36 @@
* @return {*} data or if it is not connected returns undefined
*/
LGraphNode.prototype.getInputData = function(slot, force_update) {
- if (!this.inputs) return; //undefined;
-
- if (slot >= this.inputs.length || this.inputs[slot].link == null)
+ if (!this.inputs) {
return;
+ } //undefined;
+
+ if (slot >= this.inputs.length || this.inputs[slot].link == null) {
+ return;
+ }
var link_id = this.inputs[slot].link;
var link = this.graph.links[link_id];
- if (!link)
+ if (!link) {
//bug: weird case but it happens sometimes
return null;
+ }
- if (!force_update) return link.data;
+ if (!force_update) {
+ return link.data;
+ }
//special case: used to extract data from the incoming connection before the graph has been executed
var node = this.graph.getNodeById(link.origin_id);
- if (!node) return link.data;
+ if (!node) {
+ return link.data;
+ }
- if (node.updateOutputData) node.updateOutputData(link.origin_slot);
- else if (node.onExecute) node.onExecute();
+ if (node.updateOutputData) {
+ node.updateOutputData(link.origin_slot);
+ } else if (node.onExecute) {
+ node.onExecute();
+ }
return link.data;
};
@@ -2072,19 +2444,27 @@
* @return {String} datatype in string format
*/
LGraphNode.prototype.getInputDataType = function(slot) {
- if (!this.inputs) return null; //undefined;
-
- if (slot >= this.inputs.length || this.inputs[slot].link == null)
+ if (!this.inputs) {
return null;
+ } //undefined;
+
+ if (slot >= this.inputs.length || this.inputs[slot].link == null) {
+ return null;
+ }
var link_id = this.inputs[slot].link;
var link = this.graph.links[link_id];
- if (!link)
+ if (!link) {
//bug: weird case but it happens sometimes
return null;
+ }
var node = this.graph.getNodeById(link.origin_id);
- if (!node) return link.type;
+ if (!node) {
+ return link.type;
+ }
var output_info = node.outputs[link.origin_slot];
- if (output_info) return output_info.type;
+ if (output_info) {
+ return output_info.type;
+ }
return null;
};
@@ -2100,7 +2480,9 @@
force_update
) {
var slot = this.findInputSlot(slot_name);
- if (slot == -1) return null;
+ if (slot == -1) {
+ return null;
+ }
return this.getInputData(slot, force_update);
};
@@ -2111,7 +2493,9 @@
* @return {boolean}
*/
LGraphNode.prototype.isInputConnected = function(slot) {
- if (!this.inputs) return false;
+ if (!this.inputs) {
+ return false;
+ }
return slot < this.inputs.length && this.inputs[slot].link != null;
};
@@ -2122,8 +2506,12 @@
* @return {Object} object or null { link: id, name: string, type: string or 0 }
*/
LGraphNode.prototype.getInputInfo = function(slot) {
- if (!this.inputs) return null;
- if (slot < this.inputs.length) return this.inputs[slot];
+ if (!this.inputs) {
+ return null;
+ }
+ if (slot < this.inputs.length) {
+ return this.inputs[slot];
+ }
return null;
};
@@ -2134,12 +2522,20 @@
* @return {LGraphNode} node or null
*/
LGraphNode.prototype.getInputNode = function(slot) {
- if (!this.inputs) return null;
- if (slot >= this.inputs.length) return null;
+ if (!this.inputs) {
+ return null;
+ }
+ if (slot >= this.inputs.length) {
+ return null;
+ }
var input = this.inputs[slot];
- if (!input || input.link === null) return null;
+ if (!input || input.link === null) {
+ return null;
+ }
var link_info = this.graph.links[input.link];
- if (!link_info) return null;
+ if (!link_info) {
+ return null;
+ }
return this.graph.getNodeById(link_info.origin_id);
};
@@ -2150,14 +2546,17 @@
* @return {*} value
*/
LGraphNode.prototype.getInputOrProperty = function(name) {
- if (!this.inputs || !this.inputs.length)
+ if (!this.inputs || !this.inputs.length) {
return this.properties ? this.properties[name] : null;
+ }
for (var i = 0, l = this.inputs.length; i < l; ++i) {
var input_info = this.inputs[i];
if (name == input_info.name && input_info.link != null) {
var link = this.graph.links[input_info.link];
- if (link) return link.data;
+ if (link) {
+ return link.data;
+ }
}
}
return this.properties[name];
@@ -2170,8 +2569,12 @@
* @return {Object} object or null
*/
LGraphNode.prototype.getOutputData = function(slot) {
- if (!this.outputs) return null;
- if (slot >= this.outputs.length) return null;
+ if (!this.outputs) {
+ return null;
+ }
+ if (slot >= this.outputs.length) {
+ return null;
+ }
var info = this.outputs[slot];
return info._data;
@@ -2184,8 +2587,12 @@
* @return {Object} object or null { name: string, type: string, links: [ ids of links in number ] }
*/
LGraphNode.prototype.getOutputInfo = function(slot) {
- if (!this.outputs) return null;
- if (slot < this.outputs.length) return this.outputs[slot];
+ if (!this.outputs) {
+ return null;
+ }
+ if (slot < this.outputs.length) {
+ return this.outputs[slot];
+ }
return null;
};
@@ -2196,7 +2603,9 @@
* @return {boolean}
*/
LGraphNode.prototype.isOutputConnected = function(slot) {
- if (!this.outputs) return false;
+ if (!this.outputs) {
+ return false;
+ }
return (
slot < this.outputs.length &&
this.outputs[slot].links &&
@@ -2210,10 +2619,14 @@
* @return {boolean}
*/
LGraphNode.prototype.isAnyOutputConnected = function() {
- if (!this.outputs) return false;
- for (var i = 0; i < this.outputs.length; ++i)
- if (this.outputs[i].links && this.outputs[i].links.length)
+ if (!this.outputs) {
+ return false;
+ }
+ for (var i = 0; i < this.outputs.length; ++i) {
+ if (this.outputs[i].links && this.outputs[i].links.length) {
return true;
+ }
+ }
return false;
};
@@ -2224,12 +2637,18 @@
* @return {array}
*/
LGraphNode.prototype.getOutputNodes = function(slot) {
- if (!this.outputs || this.outputs.length == 0) return null;
+ if (!this.outputs || this.outputs.length == 0) {
+ return null;
+ }
- if (slot >= this.outputs.length) return null;
+ if (slot >= this.outputs.length) {
+ return null;
+ }
var output = this.outputs[slot];
- if (!output.links || output.links.length == 0) return null;
+ if (!output.links || output.links.length == 0) {
+ return null;
+ }
var r = [];
for (var i = 0; i < output.links.length; i++) {
@@ -2237,7 +2656,9 @@
var link = this.graph.links[link_id];
if (link) {
var target_node = this.graph.getNodeById(link.target_id);
- if (target_node) r.push(target_node);
+ if (target_node) {
+ r.push(target_node);
+ }
}
}
return r;
@@ -2250,9 +2671,13 @@
* @param {*} param
*/
LGraphNode.prototype.trigger = function(action, param) {
- if (!this.outputs || !this.outputs.length) return;
+ if (!this.outputs || !this.outputs.length) {
+ return;
+ }
- if (this.graph) this.graph._last_trigger_time = LiteGraph.getTime();
+ if (this.graph) {
+ this.graph._last_trigger_time = LiteGraph.getTime();
+ }
for (var i = 0; i < this.outputs.length; ++i) {
var output = this.outputs[i];
@@ -2260,8 +2685,9 @@
!output ||
output.type !== LiteGraph.EVENT ||
(action && output.name != action)
- )
+ ) {
continue;
+ }
this.triggerSlot(i, param);
}
};
@@ -2274,38 +2700,52 @@
* @param {Number} link_id [optional] in case you want to trigger and specific output link in a slot
*/
LGraphNode.prototype.triggerSlot = function(slot, param, link_id) {
- if (!this.outputs) return;
+ if (!this.outputs) {
+ return;
+ }
var output = this.outputs[slot];
- if (!output) return;
+ if (!output) {
+ return;
+ }
var links = output.links;
- if (!links || !links.length) return;
+ if (!links || !links.length) {
+ return;
+ }
- if (this.graph) this.graph._last_trigger_time = LiteGraph.getTime();
+ if (this.graph) {
+ this.graph._last_trigger_time = LiteGraph.getTime();
+ }
//for every link attached here
for (var k = 0; k < links.length; ++k) {
var id = links[k];
- if (link_id != null && link_id != id)
+ if (link_id != null && link_id != id) {
//to skip links
continue;
+ }
var link_info = this.graph.links[links[k]];
- if (!link_info)
+ if (!link_info) {
//not connected
continue;
+ }
link_info._last_time = LiteGraph.getTime();
var node = this.graph.getNodeById(link_info.target_id);
- if (!node)
+ if (!node) {
//node not found?
continue;
+ }
//used to mark events in graph
var target_connection = node.inputs[link_info.target_slot];
- if (node.onAction) node.onAction(target_connection.name, param);
- else if (node.mode === LiteGraph.ON_TRIGGER) {
- if (node.onExecute) node.onExecute(param);
+ if (node.onAction) {
+ node.onAction(target_connection.name, param);
+ } else if (node.mode === LiteGraph.ON_TRIGGER) {
+ if (node.onExecute) {
+ node.onExecute(param);
+ }
}
}
};
@@ -2317,24 +2757,32 @@
* @param {Number} link_id [optional] in case you want to trigger and specific output link in a slot
*/
LGraphNode.prototype.clearTriggeredSlot = function(slot, link_id) {
- if (!this.outputs) return;
+ if (!this.outputs) {
+ return;
+ }
var output = this.outputs[slot];
- if (!output) return;
+ if (!output) {
+ return;
+ }
var links = output.links;
- if (!links || !links.length) return;
+ if (!links || !links.length) {
+ return;
+ }
//for every link attached here
for (var k = 0; k < links.length; ++k) {
var id = links[k];
- if (link_id != null && link_id != id)
+ if (link_id != null && link_id != id) {
//to skip links
continue;
+ }
var link_info = this.graph.links[links[k]];
- if (!link_info)
+ if (!link_info) {
//not connected
continue;
+ }
link_info._last_time = 0;
}
};
@@ -2354,10 +2802,18 @@
extra_info
) {
var o = { name: name, type: type, default_value: default_value };
- if (extra_info) for (var i in extra_info) o[i] = extra_info[i];
- if (!this.properties_info) this.properties_info = [];
+ if (extra_info) {
+ for (var i in extra_info) {
+ o[i] = extra_info[i];
+ }
+ }
+ if (!this.properties_info) {
+ this.properties_info = [];
+ }
this.properties_info.push(o);
- if (!this.properties) this.properties = {};
+ if (!this.properties) {
+ this.properties = {};
+ }
this.properties[name] = default_value;
return o;
};
@@ -2373,11 +2829,19 @@
*/
LGraphNode.prototype.addOutput = function(name, type, extra_info) {
var o = { name: name, type: type, links: null };
- if (extra_info) for (var i in extra_info) o[i] = extra_info[i];
+ if (extra_info) {
+ for (var i in extra_info) {
+ o[i] = extra_info[i];
+ }
+ }
- if (!this.outputs) this.outputs = [];
+ if (!this.outputs) {
+ this.outputs = [];
+ }
this.outputs.push(o);
- if (this.onOutputAdded) this.onOutputAdded(o);
+ if (this.onOutputAdded) {
+ this.onOutputAdded(o);
+ }
this.size = this.computeSize();
this.setDirtyCanvas(true, true);
return o;
@@ -2392,11 +2856,19 @@
for (var i = 0; i < array.length; ++i) {
var info = array[i];
var o = { name: info[0], type: info[1], link: null };
- if (array[2]) for (var j in info[2]) o[j] = info[2][j];
+ if (array[2]) {
+ for (var j in info[2]) {
+ o[j] = info[2][j];
+ }
+ }
- if (!this.outputs) this.outputs = [];
+ if (!this.outputs) {
+ this.outputs = [];
+ }
this.outputs.push(o);
- if (this.onOutputAdded) this.onOutputAdded(o);
+ if (this.onOutputAdded) {
+ this.onOutputAdded(o);
+ }
}
this.size = this.computeSize();
@@ -2412,17 +2884,23 @@
this.disconnectOutput(slot);
this.outputs.splice(slot, 1);
for (var i = slot; i < this.outputs.length; ++i) {
- if (!this.outputs[i] || !this.outputs[i].links) continue;
+ if (!this.outputs[i] || !this.outputs[i].links) {
+ continue;
+ }
var links = this.outputs[i].links;
for (var j = 0; j < links.length; ++j) {
var link = this.graph.links[links[j]];
- if (!link) continue;
+ if (!link) {
+ continue;
+ }
link.origin_slot -= 1;
}
}
this.size = this.computeSize();
- if (this.onOutputRemoved) this.onOutputRemoved(slot);
+ if (this.onOutputRemoved) {
+ this.onOutputRemoved(slot);
+ }
this.setDirtyCanvas(true, true);
};
@@ -2436,12 +2914,20 @@
LGraphNode.prototype.addInput = function(name, type, extra_info) {
type = type || 0;
var o = { name: name, type: type, link: null };
- if (extra_info) for (var i in extra_info) o[i] = extra_info[i];
+ if (extra_info) {
+ for (var i in extra_info) {
+ o[i] = extra_info[i];
+ }
+ }
- if (!this.inputs) this.inputs = [];
+ if (!this.inputs) {
+ this.inputs = [];
+ }
this.inputs.push(o);
this.size = this.computeSize();
- if (this.onInputAdded) this.onInputAdded(o);
+ if (this.onInputAdded) {
+ this.onInputAdded(o);
+ }
this.setDirtyCanvas(true, true);
return o;
};
@@ -2455,11 +2941,19 @@
for (var i = 0; i < array.length; ++i) {
var info = array[i];
var o = { name: info[0], type: info[1], link: null };
- if (array[2]) for (var j in info[2]) o[j] = info[2][j];
+ if (array[2]) {
+ for (var j in info[2]) {
+ o[j] = info[2][j];
+ }
+ }
- if (!this.inputs) this.inputs = [];
+ if (!this.inputs) {
+ this.inputs = [];
+ }
this.inputs.push(o);
- if (this.onInputAdded) this.onInputAdded(o);
+ if (this.onInputAdded) {
+ this.onInputAdded(o);
+ }
}
this.size = this.computeSize();
@@ -2475,13 +2969,19 @@
this.disconnectInput(slot);
this.inputs.splice(slot, 1);
for (var i = slot; i < this.inputs.length; ++i) {
- if (!this.inputs[i]) continue;
+ if (!this.inputs[i]) {
+ continue;
+ }
var link = this.graph.links[this.inputs[i].link];
- if (!link) continue;
+ if (!link) {
+ continue;
+ }
link.target_slot -= 1;
}
this.size = this.computeSize();
- if (this.onInputRemoved) this.onInputRemoved(slot);
+ if (this.onInputRemoved) {
+ this.onInputRemoved(slot);
+ }
this.setDirtyCanvas(true, true);
};
@@ -2512,7 +3012,9 @@
* @return {number} the total size
*/
LGraphNode.prototype.computeSize = function(minHeight, out) {
- if (this.constructor.size) return this.constructor.size.concat();
+ if (this.constructor.size) {
+ return this.constructor.size.concat();
+ }
var rows = Math.max(
this.inputs ? this.inputs.length : 1,
@@ -2525,50 +3027,66 @@
(this.constructor.slot_start_y || 0) +
rows * LiteGraph.NODE_SLOT_HEIGHT;
var widgets_height = 0;
- if (this.widgets && this.widgets.length)
+ if (this.widgets && this.widgets.length) {
widgets_height =
this.widgets.length * (LiteGraph.NODE_WIDGET_HEIGHT + 4) + 8;
- if (this.widgets_up) size[1] = Math.max(size[1], widgets_height);
- else size[1] += widgets_height;
+ }
+ if (this.widgets_up) {
+ size[1] = Math.max(size[1], widgets_height);
+ } else {
+ size[1] += widgets_height;
+ }
var font_size = font_size;
var title_width = compute_text_size(this.title);
var input_width = 0;
var output_width = 0;
- if (this.inputs)
+ if (this.inputs) {
for (var i = 0, l = this.inputs.length; i < l; ++i) {
var input = this.inputs[i];
var text = input.label || input.name || "";
var text_width = compute_text_size(text);
- if (input_width < text_width) input_width = text_width;
+ if (input_width < text_width) {
+ input_width = text_width;
+ }
}
+ }
- if (this.outputs)
+ if (this.outputs) {
for (var i = 0, l = this.outputs.length; i < l; ++i) {
var output = this.outputs[i];
var text = output.label || output.name || "";
var text_width = compute_text_size(text);
- if (output_width < text_width) output_width = text_width;
+ if (output_width < text_width) {
+ output_width = text_width;
+ }
}
+ }
size[0] = Math.max(input_width + output_width + 10, title_width);
size[0] = Math.max(size[0], LiteGraph.NODE_WIDTH);
- if (this.widgets && this.widgets.length)
+ if (this.widgets && this.widgets.length) {
size[0] = Math.max(size[0], LiteGraph.NODE_WIDTH * 1.5);
+ }
- if (this.onResize) this.onResize(size);
+ if (this.onResize) {
+ this.onResize(size);
+ }
function compute_text_size(text) {
- if (!text) return 0;
+ if (!text) {
+ return 0;
+ }
return font_size * text.length * 0.6;
}
if (
this.constructor.min_height &&
size[1] < this.constructor.min_height
- )
+ ) {
size[1] = this.constructor.min_height;
+ }
size[1] += 6; //margin
@@ -2588,7 +3106,9 @@
callback,
options
) {
- if (!this.widgets) this.widgets = [];
+ if (!this.widgets) {
+ this.widgets = [];
+ }
var w = {
type: type.toLowerCase(),
name: name,
@@ -2597,18 +3117,24 @@
options: options || {}
};
- if (w.options.y !== undefined) w.y = w.options.y;
+ if (w.options.y !== undefined) {
+ w.y = w.options.y;
+ }
- if (!callback)
+ if (!callback) {
console.warn("LiteGraph addWidget(...) without a callback");
- if (type == "combo" && !w.options.values)
+ }
+ if (type == "combo" && !w.options.values) {
throw "LiteGraph addWidget('combo',...) requires to pass values in options: { values:['red','blue'] }";
+ }
this.widgets.push(w);
return w;
};
LGraphNode.prototype.addCustomWidget = function(custom_widget) {
- if (!this.widgets) this.widgets = [];
+ if (!this.widgets) {
+ this.widgets = [];
+ }
this.widgets.push(custom_widget);
return custom_widget;
};
@@ -2626,7 +3152,9 @@
out[2] = this.size[0] + 4;
out[3] = this.size[1] + LiteGraph.NODE_TITLE_HEIGHT;
- if (this.onBounding) this.onBounding(out);
+ if (this.onBounding) {
+ this.onBounding(out);
+ }
return out;
};
@@ -2641,7 +3169,9 @@
margin = margin || 0;
var margin_top = this.graph && this.graph.isLive() ? 0 : 20;
- if (skip_title) margin_top = 0;
+ if (skip_title) {
+ margin_top = 0;
+ }
if (this.flags && this.flags.collapsed) {
//if ( distance([x,y], [this.pos[0] + this.size[0]*0.5, this.pos[1] + this.size[1]*0.5]) < LiteGraph.NODE_COLLAPSED_RADIUS)
if (
@@ -2654,15 +3184,17 @@
2 * margin,
LiteGraph.NODE_TITLE_HEIGHT + 2 * margin
)
- )
+ ) {
return true;
+ }
} else if (
this.pos[0] - 4 - margin < x &&
this.pos[0] + this.size[0] + 4 + margin > x &&
this.pos[1] - margin_top - margin < y &&
this.pos[1] + this.size[1] + margin > y
- )
+ ) {
return true;
+ }
return false;
};
@@ -2676,7 +3208,7 @@
LGraphNode.prototype.getSlotInPosition = function(x, y) {
//search for inputs
var link_pos = new Float32Array(2);
- if (this.inputs)
+ if (this.inputs) {
for (var i = 0, l = this.inputs.length; i < l; ++i) {
var input = this.inputs[i];
this.getConnectionPos(true, i, link_pos);
@@ -2689,11 +3221,13 @@
20,
10
)
- )
+ ) {
return { input: input, slot: i, link_pos: link_pos };
+ }
}
+ }
- if (this.outputs)
+ if (this.outputs) {
for (var i = 0, l = this.outputs.length; i < l; ++i) {
var output = this.outputs[i];
this.getConnectionPos(false, i, link_pos);
@@ -2706,9 +3240,11 @@
20,
10
)
- )
+ ) {
return { output: output, slot: i, link_pos: link_pos };
+ }
}
+ }
return null;
};
@@ -2720,9 +3256,14 @@
* @return {number} the slot (-1 if not found)
*/
LGraphNode.prototype.findInputSlot = function(name) {
- if (!this.inputs) return -1;
- for (var i = 0, l = this.inputs.length; i < l; ++i)
- if (name == this.inputs[i].name) return i;
+ if (!this.inputs) {
+ return -1;
+ }
+ for (var i = 0, l = this.inputs.length; i < l; ++i) {
+ if (name == this.inputs[i].name) {
+ return i;
+ }
+ }
return -1;
};
@@ -2733,9 +3274,14 @@
* @return {number} the slot (-1 if not found)
*/
LGraphNode.prototype.findOutputSlot = function(name) {
- if (!this.outputs) return -1;
- for (var i = 0, l = this.outputs.length; i < l; ++i)
- if (name == this.outputs[i].name) return i;
+ if (!this.outputs) {
+ return -1;
+ }
+ for (var i = 0, l = this.outputs.length; i < l; ++i) {
+ if (name == this.outputs[i].name) {
+ return i;
+ }
+ }
return -1;
};
@@ -2762,31 +3308,39 @@
if (slot.constructor === String) {
slot = this.findOutputSlot(slot);
if (slot == -1) {
- if (LiteGraph.debug)
+ if (LiteGraph.debug) {
console.log("Connect: Error, no slot of name " + slot);
+ }
return null;
}
} else if (!this.outputs || slot >= this.outputs.length) {
- if (LiteGraph.debug)
+ if (LiteGraph.debug) {
console.log("Connect: Error, slot number not found");
+ }
return null;
}
- if (target_node && target_node.constructor === Number)
+ if (target_node && target_node.constructor === Number) {
target_node = this.graph.getNodeById(target_node);
- if (!target_node) throw "target node is null";
+ }
+ if (!target_node) {
+ throw "target node is null";
+ }
//avoid loopback
- if (target_node == this) return null;
+ if (target_node == this) {
+ return null;
+ }
//you can specify the slot by name
if (target_slot.constructor === String) {
target_slot = target_node.findInputSlot(target_slot);
if (target_slot == -1) {
- if (LiteGraph.debug)
+ if (LiteGraph.debug) {
console.log(
"Connect: Error, no slot of name " + target_slot
);
+ }
return null;
}
} else if (target_slot === LiteGraph.EVENT) {
@@ -2802,14 +3356,16 @@
!target_node.inputs ||
target_slot >= target_node.inputs.length
) {
- if (LiteGraph.debug)
+ if (LiteGraph.debug) {
console.log("Connect: Error, slot number not found");
+ }
return null;
}
//if there is something already plugged there, disconnect
- if (target_node.inputs[target_slot].link != null)
+ if (target_node.inputs[target_slot].link != null) {
target_node.disconnectInput(target_slot);
+ }
//why here??
//this.setDirtyCanvas(false,true);
@@ -2818,12 +3374,14 @@
var output = this.outputs[slot];
//allows nodes to block connection
- if (target_node.onConnectInput)
+ if (target_node.onConnectInput) {
if (
target_node.onConnectInput(target_slot, output.type, output) ===
false
- )
+ ) {
return null;
+ }
+ }
var input = target_node.inputs[target_slot];
var link_info = null;
@@ -2842,20 +3400,25 @@
this.graph.links[link_info.id] = link_info;
//connect in output
- if (output.links == null) output.links = [];
+ if (output.links == null) {
+ output.links = [];
+ }
output.links.push(link_info.id);
//connect in input
target_node.inputs[target_slot].link = link_info.id;
- if (this.graph) this.graph._version++;
- if (this.onConnectionsChange)
+ if (this.graph) {
+ this.graph._version++;
+ }
+ if (this.onConnectionsChange) {
this.onConnectionsChange(
LiteGraph.OUTPUT,
slot,
true,
link_info,
output
- ); //link_info has been created now, so its updated
- if (target_node.onConnectionsChange)
+ );
+ } //link_info has been created now, so its updated
+ if (target_node.onConnectionsChange) {
target_node.onConnectionsChange(
LiteGraph.INPUT,
target_slot,
@@ -2863,6 +3426,7 @@
link_info,
input
);
+ }
if (this.graph && this.graph.onNodeConnectionChange) {
this.graph.onNodeConnectionChange(
LiteGraph.INPUT,
@@ -2898,25 +3462,32 @@
if (slot.constructor === String) {
slot = this.findOutputSlot(slot);
if (slot == -1) {
- if (LiteGraph.debug)
+ if (LiteGraph.debug) {
console.log("Connect: Error, no slot of name " + slot);
+ }
return false;
}
} else if (!this.outputs || slot >= this.outputs.length) {
- if (LiteGraph.debug)
+ if (LiteGraph.debug) {
console.log("Connect: Error, slot number not found");
+ }
return false;
}
//get output slot
var output = this.outputs[slot];
- if (!output || !output.links || output.links.length == 0) return false;
+ if (!output || !output.links || output.links.length == 0) {
+ return false;
+ }
//one of the output links in this slot
if (target_node) {
- if (target_node.constructor === Number)
+ if (target_node.constructor === Number) {
target_node = this.graph.getNodeById(target_node);
- if (!target_node) throw "Target Node not found";
+ }
+ if (!target_node) {
+ throw "Target Node not found";
+ }
for (var i = 0, l = output.links.length; i < l; i++) {
var link_id = output.links[i];
@@ -2928,16 +3499,19 @@
var input = target_node.inputs[link_info.target_slot];
input.link = null; //remove there
delete this.graph.links[link_id]; //remove the link from the links pool
- if (this.graph) this.graph._version++;
- if (target_node.onConnectionsChange)
+ if (this.graph) {
+ this.graph._version++;
+ }
+ if (target_node.onConnectionsChange) {
target_node.onConnectionsChange(
LiteGraph.INPUT,
link_info.target_slot,
false,
link_info,
input
- ); //link_info hasn't been modified so its ok
- if (this.onConnectionsChange)
+ );
+ } //link_info hasn't been modified so its ok
+ if (this.onConnectionsChange) {
this.onConnectionsChange(
LiteGraph.OUTPUT,
slot,
@@ -2945,12 +3519,14 @@
link_info,
output
);
- if (this.graph && this.graph.onNodeConnectionChange)
+ }
+ if (this.graph && this.graph.onNodeConnectionChange) {
this.graph.onNodeConnectionChange(
LiteGraph.OUTPUT,
this,
slot
);
+ }
if (this.graph && this.graph.onNodeConnectionChange) {
this.graph.onNodeConnectionChange(
LiteGraph.OUTPUT,
@@ -2971,33 +3547,38 @@
for (var i = 0, l = output.links.length; i < l; i++) {
var link_id = output.links[i];
var link_info = this.graph.links[link_id];
- if (!link_info)
+ if (!link_info) {
//bug: it happens sometimes
continue;
+ }
var target_node = this.graph.getNodeById(link_info.target_id);
var input = null;
- if (this.graph) this.graph._version++;
+ if (this.graph) {
+ this.graph._version++;
+ }
if (target_node) {
input = target_node.inputs[link_info.target_slot];
input.link = null; //remove other side link
- if (target_node.onConnectionsChange)
+ if (target_node.onConnectionsChange) {
target_node.onConnectionsChange(
LiteGraph.INPUT,
link_info.target_slot,
false,
link_info,
input
- ); //link_info hasn't been modified so its ok
- if (this.graph && this.graph.onNodeConnectionChange)
+ );
+ } //link_info hasn't been modified so its ok
+ if (this.graph && this.graph.onNodeConnectionChange) {
this.graph.onNodeConnectionChange(
LiteGraph.INPUT,
target_node,
link_info.target_slot
);
+ }
}
delete this.graph.links[link_id]; //remove the link from the links pool
- if (this.onConnectionsChange)
+ if (this.onConnectionsChange) {
this.onConnectionsChange(
LiteGraph.OUTPUT,
slot,
@@ -3005,6 +3586,7 @@
link_info,
output
);
+ }
if (this.graph && this.graph.onNodeConnectionChange) {
this.graph.onNodeConnectionChange(
LiteGraph.OUTPUT,
@@ -3037,18 +3619,22 @@
if (slot.constructor === String) {
slot = this.findInputSlot(slot);
if (slot == -1) {
- if (LiteGraph.debug)
+ if (LiteGraph.debug) {
console.log("Connect: Error, no slot of name " + slot);
+ }
return false;
}
} else if (!this.inputs || slot >= this.inputs.length) {
- if (LiteGraph.debug)
+ if (LiteGraph.debug) {
console.log("Connect: Error, slot number not found");
+ }
return false;
}
var input = this.inputs[slot];
- if (!input) return false;
+ if (!input) {
+ return false;
+ }
var link_id = this.inputs[slot].link;
this.inputs[slot].link = null;
@@ -3057,11 +3643,14 @@
var link_info = this.graph.links[link_id];
if (link_info) {
var target_node = this.graph.getNodeById(link_info.origin_id);
- if (!target_node) return false;
+ if (!target_node) {
+ return false;
+ }
var output = target_node.outputs[link_info.origin_slot];
- if (!output || !output.links || output.links.length == 0)
+ if (!output || !output.links || output.links.length == 0) {
return false;
+ }
//search in the inputs list for this link
for (var i = 0, l = output.links.length; i < l; i++) {
@@ -3072,8 +3661,10 @@
}
delete this.graph.links[link_id]; //remove from the pool
- if (this.graph) this.graph._version++;
- if (this.onConnectionsChange)
+ if (this.graph) {
+ this.graph._version++;
+ }
+ if (this.onConnectionsChange) {
this.onConnectionsChange(
LiteGraph.INPUT,
slot,
@@ -3081,7 +3672,8 @@
link_info,
input
);
- if (target_node.onConnectionsChange)
+ }
+ if (target_node.onConnectionsChange) {
target_node.onConnectionsChange(
LiteGraph.OUTPUT,
i,
@@ -3089,6 +3681,7 @@
link_info,
output
);
+ }
if (this.graph && this.graph.onNodeConnectionChange) {
this.graph.onNodeConnectionChange(
LiteGraph.OUTPUT,
@@ -3119,8 +3712,12 @@
) {
out = out || new Float32Array(2);
var num_slots = 0;
- if (is_input && this.inputs) num_slots = this.inputs.length;
- if (!is_input && this.outputs) num_slots = this.outputs.length;
+ if (is_input && this.inputs) {
+ num_slots = this.inputs.length;
+ }
+ if (!is_input && this.outputs) {
+ num_slots = this.outputs.length;
+ }
var offset = LiteGraph.NODE_SLOT_HEIGHT * 0.5;
@@ -3128,12 +3725,17 @@
var w = this._collapsed_width || LiteGraph.NODE_COLLAPSED_WIDTH;
if (this.horizontal) {
out[0] = this.pos[0] + w * 0.5;
- if (is_input)
+ if (is_input) {
out[1] = this.pos[1] - LiteGraph.NODE_TITLE_HEIGHT;
- else out[1] = this.pos[1];
+ } else {
+ out[1] = this.pos[1];
+ }
} else {
- if (is_input) out[0] = this.pos[0];
- else out[0] = this.pos[0] + w;
+ if (is_input) {
+ out[0] = this.pos[0];
+ } else {
+ out[0] = this.pos[0] + w;
+ }
out[1] = this.pos[1] - LiteGraph.NODE_TITLE_HEIGHT * 0.5;
}
return out;
@@ -3169,14 +3771,20 @@
if (this.horizontal) {
out[0] =
this.pos[0] + (slot_number + 0.5) * (this.size[0] / num_slots);
- if (is_input) out[1] = this.pos[1] - LiteGraph.NODE_TITLE_HEIGHT;
- else out[1] = this.pos[1] + this.size[1];
+ if (is_input) {
+ out[1] = this.pos[1] - LiteGraph.NODE_TITLE_HEIGHT;
+ } else {
+ out[1] = this.pos[1] + this.size[1];
+ }
return out;
}
//default vertical slots
- if (is_input) out[0] = this.pos[0] + offset;
- else out[0] = this.pos[0] + this.size[0] + 1 - offset;
+ if (is_input) {
+ out[0] = this.pos[0] + offset;
+ } else {
+ out[0] = this.pos[0] + this.size[0] + 1 - offset;
+ }
out[1] =
this.pos[1] +
(slot_number + 0.7) * LiteGraph.NODE_SLOT_HEIGHT +
@@ -3196,9 +3804,13 @@
/* Console output */
LGraphNode.prototype.trace = function(msg) {
- if (!this.console) this.console = [];
+ if (!this.console) {
+ this.console = [];
+ }
this.console.push(msg);
- if (this.console.length > LGraphNode.MAX_CONSOLE) this.console.shift();
+ if (this.console.length > LGraphNode.MAX_CONSOLE) {
+ this.console.shift();
+ }
this.graph.onNodeTrace(this, msg);
};
@@ -3208,7 +3820,9 @@
dirty_foreground,
dirty_background
) {
- if (!this.graph) return;
+ if (!this.graph) {
+ return;
+ }
this.graph.sendActionToCanvas("setDirty", [
dirty_foreground,
dirty_background
@@ -3269,14 +3883,18 @@ LGraphNode.prototype.executeAction = function(action)
/* Allows to get onMouseMove and onMouseUp events even if the mouse is out of focus */
LGraphNode.prototype.captureInput = function(v) {
- if (!this.graph || !this.graph.list_of_graphcanvas) return;
+ if (!this.graph || !this.graph.list_of_graphcanvas) {
+ return;
+ }
var list = this.graph.list_of_graphcanvas;
for (var i = 0; i < list.length; ++i) {
var c = list[i];
//releasing somebody elses capture?!
- if (!v && c.node_capturing_input != this) continue;
+ if (!v && c.node_capturing_input != this) {
+ continue;
+ }
//change
c.node_capturing_input = v ? this : null;
@@ -3289,9 +3907,14 @@ LGraphNode.prototype.executeAction = function(action)
**/
LGraphNode.prototype.collapse = function(force) {
this.graph._version++;
- if (this.constructor.collapsable === false && !force) return;
- if (!this.flags.collapsed) this.flags.collapsed = true;
- else this.flags.collapsed = false;
+ if (this.constructor.collapsable === false && !force) {
+ return;
+ }
+ if (!this.flags.collapsed) {
+ this.flags.collapsed = true;
+ } else {
+ this.flags.collapsed = false;
+ }
this.setDirtyCanvas(true, true);
};
@@ -3302,8 +3925,11 @@ LGraphNode.prototype.executeAction = function(action)
LGraphNode.prototype.pin = function(v) {
this.graph._version++;
- if (v === undefined) this.flags.pinned = !this.flags.pinned;
- else this.flags.pinned = v;
+ if (v === undefined) {
+ this.flags.pinned = !this.flags.pinned;
+ } else {
+ this.flags.pinned = v;
+ }
};
LGraphNode.prototype.localToScreen = function(x, y, graphcanvas) {
@@ -3333,7 +3959,9 @@ LGraphNode.prototype.executeAction = function(action)
Object.defineProperty(this, "pos", {
set: function(v) {
- if (!v || v.length < 2) return;
+ if (!v || v.length < 2) {
+ return;
+ }
this._pos[0] = v[0];
this._pos[1] = v[1];
},
@@ -3345,7 +3973,9 @@ LGraphNode.prototype.executeAction = function(action)
Object.defineProperty(this, "size", {
set: function(v) {
- if (!v || v.length < 2) return;
+ if (!v || v.length < 2) {
+ return;
+ }
this._size[0] = Math.max(140, v[0]);
this._size[1] = Math.max(80, v[1]);
},
@@ -3381,7 +4011,9 @@ LGraphNode.prototype.executeAction = function(action)
LGraphGroup.prototype.move = function(deltax, deltay, ignore_nodes) {
this._pos[0] += deltax;
this._pos[1] += deltay;
- if (ignore_nodes) return;
+ if (ignore_nodes) {
+ return;
+ }
for (var i = 0; i < this._nodes.length; ++i) {
var node = this._nodes[i];
node.pos[0] += deltax;
@@ -3397,7 +4029,9 @@ LGraphNode.prototype.executeAction = function(action)
for (var i = 0; i < nodes.length; ++i) {
var node = nodes[i];
node.getBounding(node_bounding);
- if (!overlapBounding(this._bounding, node_bounding)) continue; //out of the visible area
+ if (!overlapBounding(this._bounding, node_bounding)) {
+ continue;
+ } //out of the visible area
this._nodes.push(node);
}
};
@@ -3421,7 +4055,9 @@ LGraphNode.prototype.executeAction = function(action)
if (element) {
this.element = element;
- if (!skip_events) this.bindEvents(element);
+ if (!skip_events) {
+ this.bindEvents(element);
+ }
}
}
@@ -3461,7 +4097,9 @@ LGraphNode.prototype.executeAction = function(action)
};
DragAndScale.prototype.onMouse = function(e) {
- if (!this.enabled) return;
+ if (!this.enabled) {
+ return;
+ }
var canvas = this.element;
var rect = canvas.getBoundingClientRect();
@@ -3472,7 +4110,9 @@ LGraphNode.prototype.executeAction = function(action)
e.dragging = this.dragging;
var ignore = false;
- if (this.onmouse) ignore = this.onmouse(e);
+ if (this.onmouse) {
+ ignore = this.onmouse(e);
+ }
if (e.type == "mousedown") {
this.dragging = true;
@@ -3492,7 +4132,9 @@ LGraphNode.prototype.executeAction = function(action)
if (!ignore) {
var deltax = x - this.last_mouse[0];
var deltay = y - this.last_mouse[1];
- if (this.dragging) this.mouseDrag(deltax, deltay);
+ if (this.dragging) {
+ this.mouseDrag(deltax, deltay);
+ }
}
} else if (e.type == "mouseup") {
this.dragging = false;
@@ -3511,10 +4153,12 @@ LGraphNode.prototype.executeAction = function(action)
e.type == "DOMMouseScroll"
) {
e.eventType = "mousewheel";
- if (e.type == "wheel") e.wheel = -e.deltaY;
- else
+ if (e.type == "wheel") {
+ e.wheel = -e.deltaY;
+ } else {
e.wheel =
e.wheelDeltaY != null ? e.wheelDeltaY : e.detail * -60;
+ }
//from stack overflow
e.delta = e.wheelDelta
@@ -3557,19 +4201,30 @@ LGraphNode.prototype.executeAction = function(action)
this.offset[0] += x / this.scale;
this.offset[1] += y / this.scale;
- if (this.onredraw) this.onredraw(this);
+ if (this.onredraw) {
+ this.onredraw(this);
+ }
};
DragAndScale.prototype.changeScale = function(value, zooming_center) {
- if (value < this.min_scale) value = this.min_scale;
- else if (value > this.max_scale) value = this.max_scale;
+ if (value < this.min_scale) {
+ value = this.min_scale;
+ } else if (value > this.max_scale) {
+ value = this.max_scale;
+ }
- if (value == this.scale) return;
+ if (value == this.scale) {
+ return;
+ }
- if (!this.element) return;
+ if (!this.element) {
+ return;
+ }
var rect = this.element.getBoundingClientRect();
- if (!rect) return;
+ if (!rect) {
+ return;
+ }
zooming_center = zooming_center || [
rect.width * 0.5,
@@ -3577,7 +4232,9 @@ LGraphNode.prototype.executeAction = function(action)
];
var center = this.convertCanvasToOffset(zooming_center);
this.scale = value;
- if (Math.abs(this.scale - 1) < 0.01) this.scale = 1;
+ if (Math.abs(this.scale - 1) < 0.01) {
+ this.scale = 1;
+ }
var new_center = this.convertCanvasToOffset(zooming_center);
var delta_offset = [
@@ -3588,7 +4245,9 @@ LGraphNode.prototype.executeAction = function(action)
this.offset[0] += delta_offset[0];
this.offset[1] += delta_offset[1];
- if (this.onredraw) this.onredraw(this);
+ if (this.onredraw) {
+ this.onredraw(this);
+ }
};
DragAndScale.prototype.changeDeltaScale = function(value, zooming_center) {
@@ -3623,8 +4282,9 @@ LGraphNode.prototype.executeAction = function(action)
this.background_image =
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQBJREFUeNrs1rEKwjAUhlETUkj3vP9rdmr1Ysammk2w5wdxuLgcMHyptfawuZX4pJSWZTnfnu/lnIe/jNNxHHGNn//HNbbv+4dr6V+11uF527arU7+u63qfa/bnmh8sWLBgwYJlqRf8MEptXPBXJXa37BSl3ixYsGDBMliwFLyCV/DeLIMFCxYsWLBMwSt4Be/NggXLYMGCBUvBK3iNruC9WbBgwYJlsGApeAWv4L1ZBgsWLFiwYJmCV/AK3psFC5bBggULloJX8BpdwXuzYMGCBctgwVLwCl7Be7MMFixYsGDBsu8FH1FaSmExVfAxBa/gvVmwYMGCZbBg/W4vAQYA5tRF9QYlv/QAAAAASUVORK5CYII=";
- if (canvas && canvas.constructor === String)
+ if (canvas && canvas.constructor === String) {
canvas = document.querySelector(canvas);
+ }
this.ds = new DragAndScale();
this.zoom_modify_alpha = true; //otherwise it generates ugly patterns when scaling down too much
@@ -3696,12 +4356,16 @@ LGraphNode.prototype.executeAction = function(action)
this.visible_links = [];
//link canvas and graph
- if (graph) graph.attachCanvas(this);
+ if (graph) {
+ graph.attachCanvas(this);
+ }
this.setCanvas(canvas);
this.clear();
- if (!options.skip_render) this.startRendering();
+ if (!options.skip_render) {
+ this.startRendering();
+ }
this.autoresize = options.autoresize;
}
@@ -3752,7 +4416,9 @@ LGraphNode.prototype.executeAction = function(action)
this.last_mouseclick = 0;
this.visible_area.set([0, 0, 0, 0]);
- if (this.onClear) this.onClear();
+ if (this.onClear) {
+ this.onClear();
+ }
};
/**
@@ -3762,9 +4428,13 @@ LGraphNode.prototype.executeAction = function(action)
* @param {LGraph} graph
*/
LGraphCanvas.prototype.setGraph = function(graph, skip_clear) {
- if (this.graph == graph) return;
+ if (this.graph == graph) {
+ return;
+ }
- if (!skip_clear) this.clear();
+ if (!skip_clear) {
+ this.clear();
+ }
if (!graph && this.graph) {
this.graph.detachCanvas(this);
@@ -3789,14 +4459,20 @@ LGraphNode.prototype.executeAction = function(action)
* @param {LGraph} graph
*/
LGraphCanvas.prototype.openSubgraph = function(graph) {
- if (!graph) throw "graph cannot be null";
+ if (!graph) {
+ throw "graph cannot be null";
+ }
- if (this.graph == graph) throw "graph cannot be the same";
+ if (this.graph == graph) {
+ throw "graph cannot be the same";
+ }
this.clear();
if (this.graph) {
- if (!this._graph_stack) this._graph_stack = [];
+ if (!this._graph_stack) {
+ this._graph_stack = [];
+ }
this._graph_stack.push(this.graph);
}
@@ -3811,7 +4487,9 @@ LGraphNode.prototype.executeAction = function(action)
* @param {LGraph} assigns a graph
*/
LGraphCanvas.prototype.closeSubgraph = function() {
- if (!this._graph_stack || this._graph_stack.length == 0) return;
+ if (!this._graph_stack || this._graph_stack.length == 0) {
+ return;
+ }
var subgraph_node = this.graph._subgraph_node;
var graph = this._graph_stack.pop();
this.selected_nodes = {};
@@ -3830,8 +4508,8 @@ LGraphNode.prototype.executeAction = function(action)
* @return {LGraph} the active graph
*/
LGraphCanvas.prototype.getCurrentGraph = function() {
- return this.graph;
- }
+ return this.graph;
+ };
/**
* assigns a canvas
@@ -3845,22 +4523,29 @@ LGraphNode.prototype.executeAction = function(action)
if (canvas) {
if (canvas.constructor === String) {
canvas = document.getElementById(canvas);
- if (!canvas)
+ if (!canvas) {
throw "Error creating LiteGraph canvas: Canvas not found";
+ }
}
}
- if (canvas === this.canvas) return;
+ if (canvas === this.canvas) {
+ return;
+ }
if (!canvas && this.canvas) {
//maybe detach events from old_canvas
- if (!skip_events) this.unbindEvents();
+ if (!skip_events) {
+ this.unbindEvents();
+ }
}
this.canvas = canvas;
this.ds.element = canvas;
- if (!canvas) return;
+ if (!canvas) {
+ return;
+ }
//this.canvas.tabindex = "1000";
canvas.className += " lgraphcanvas";
@@ -3876,18 +4561,20 @@ LGraphNode.prototype.executeAction = function(action)
}
if (canvas.getContext == null) {
- if (canvas.localName != "canvas")
+ if (canvas.localName != "canvas") {
throw "Element supplied for LGraphCanvas must be a