Skip to content

Commit 49e3fe7

Browse files
author
tamat
committed
Merge branch 'master' of https://github.com/jagenjo/litegraph.js
2 parents a46101d + b3862e9 commit 49e3fe7

5 files changed

Lines changed: 150 additions & 12 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ graph.start()
139139

140140
## Projects using it
141141

142+
### [comfyUI](https://github.com/comfyanonymous/ComfyUI)
143+
![screenshot](https://github.com/comfyanonymous/ComfyUI/blob/6efe561c2a7321501b1b27f47039c7616dda1860/comfyui_screenshot.png)
144+
142145
### [webglstudio.org](http://webglstudio.org)
143146

144147
![WebGLStudio](imgs/webglstudio.gif "WebGLStudio")

src/litegraph.d.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -825,9 +825,12 @@ export declare class LGraphNode {
825825

826826
/**
827827
* returns the bounding of the object, used for rendering purposes
828-
* @return [x, y, width, height]
828+
* @method getBounding
829+
* @param out [optional] a place to store the output, to free garbage
830+
* @param compute_outer [optional] set to true to include the shadow and connection points in the bounding calculation
831+
* @return the bounding box in format of [topleft_cornerx, topleft_cornery, width, height]
829832
*/
830-
getBounding(): Vector4;
833+
getBounding(out?: Vector4, compute_outer?: boolean): Vector4;
831834
/** checks if a point is inside the shape of a node */
832835
isPointInside(
833836
x: number,

src/litegraph.js

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2530,7 +2530,7 @@
25302530
var w = this.widgets[i];
25312531
if(!w)
25322532
continue;
2533-
if(w.options && w.options.property && this.properties[ w.options.property ])
2533+
if(w.options && w.options.property && (this.properties[ w.options.property ] != undefined))
25342534
w.value = JSON.parse( JSON.stringify( this.properties[ w.options.property ] ) );
25352535
}
25362536
if (info.widgets_values) {
@@ -3773,16 +3773,42 @@
37733773

37743774
/**
37753775
* returns the bounding of the object, used for rendering purposes
3776-
* bounding is: [topleft_cornerx, topleft_cornery, width, height]
37773776
* @method getBounding
3778-
* @return {Float32Array[4]} the total size
3777+
* @param out {Float32Array[4]?} [optional] a place to store the output, to free garbage
3778+
* @param compute_outer {boolean?} [optional] set to true to include the shadow and connection points in the bounding calculation
3779+
* @return {Float32Array[4]} the bounding box in format of [topleft_cornerx, topleft_cornery, width, height]
37793780
*/
3780-
LGraphNode.prototype.getBounding = function(out) {
3781+
LGraphNode.prototype.getBounding = function(out, compute_outer) {
37813782
out = out || new Float32Array(4);
3782-
out[0] = this.pos[0] - 4;
3783-
out[1] = this.pos[1] - LiteGraph.NODE_TITLE_HEIGHT;
3784-
out[2] = this.size[0] + 4;
3785-
out[3] = this.flags.collapsed ? LiteGraph.NODE_TITLE_HEIGHT : this.size[1] + LiteGraph.NODE_TITLE_HEIGHT;
3783+
const nodePos = this.pos;
3784+
const isCollapsed = this.flags.collapsed;
3785+
const nodeSize = this.size;
3786+
3787+
let left_offset = 0;
3788+
// 1 offset due to how nodes are rendered
3789+
let right_offset = 1 ;
3790+
let top_offset = 0;
3791+
let bottom_offset = 0;
3792+
3793+
if (compute_outer) {
3794+
// 4 offset for collapsed node connection points
3795+
left_offset = 4;
3796+
// 6 offset for right shadow and collapsed node connection points
3797+
right_offset = 6 + left_offset;
3798+
// 4 offset for collapsed nodes top connection points
3799+
top_offset = 4;
3800+
// 5 offset for bottom shadow and collapsed node connection points
3801+
bottom_offset = 5 + top_offset;
3802+
}
3803+
3804+
out[0] = nodePos[0] - left_offset;
3805+
out[1] = nodePos[1] - LiteGraph.NODE_TITLE_HEIGHT - top_offset;
3806+
out[2] = isCollapsed ?
3807+
(this._collapsed_width || LiteGraph.NODE_COLLAPSED_WIDTH) + right_offset :
3808+
nodeSize[0] + right_offset;
3809+
out[3] = isCollapsed ?
3810+
LiteGraph.NODE_TITLE_HEIGHT + bottom_offset :
3811+
nodeSize[1] + LiteGraph.NODE_TITLE_HEIGHT + bottom_offset;
37863812

37873813
if (this.onBounding) {
37883814
this.onBounding(out);
@@ -7671,7 +7697,7 @@ LGraphNode.prototype.executeAction = function(action)
76717697
continue;
76727698
}
76737699

7674-
if (!overlapBounding(this.visible_area, n.getBounding(temp))) {
7700+
if (!overlapBounding(this.visible_area, n.getBounding(temp, true))) {
76757701
continue;
76767702
} //out of the visible area
76777703

src/nodes/base.js

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,8 @@
529529
GraphInput.title = "Input";
530530
GraphInput.desc = "Input of the graph";
531531

532-
GraphInput.prototype.onConfigure = function()
532+
GraphInput.prototype.onConfigure = function()
533+
533534
{
534535
this.updateType();
535536
}
@@ -983,6 +984,48 @@
983984

984985
LiteGraph.registerNodeType("basic/file", ConstantFile);
985986

987+
988+
//to store json objects
989+
function JSONParse() {
990+
this.addInput("parse", LiteGraph.ACTION);
991+
this.addInput("json", "string");
992+
this.addOutput("done", LiteGraph.EVENT);
993+
this.addOutput("object", "object");
994+
this.widget = this.addWidget("button","parse","",this.parse.bind(this));
995+
this._str = null;
996+
this._obj = null;
997+
}
998+
999+
JSONParse.title = "JSON Parse";
1000+
JSONParse.desc = "Parses JSON String into object";
1001+
1002+
JSONParse.prototype.parse = function()
1003+
{
1004+
if(!this._str)
1005+
return;
1006+
1007+
try {
1008+
this._str = this.getInputData(1);
1009+
this._obj = JSON.parse(this._str);
1010+
this.boxcolor = "#AEA";
1011+
this.triggerSlot(0);
1012+
} catch (err) {
1013+
this.boxcolor = "red";
1014+
}
1015+
}
1016+
1017+
JSONParse.prototype.onExecute = function() {
1018+
this._str = this.getInputData(1);
1019+
this.setOutputData(1, this._obj);
1020+
};
1021+
1022+
JSONParse.prototype.onAction = function(name) {
1023+
if(name == "parse")
1024+
this.parse();
1025+
}
1026+
1027+
LiteGraph.registerNodeType("basic/jsonparse", JSONParse);
1028+
9861029
//to store json objects
9871030
function ConstantData() {
9881031
this.addOutput("data", "object");

src/nodes/network.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,4 +362,67 @@
362362
};
363363

364364
LiteGraph.registerNodeType("network/sillyclient", LGSillyClient);
365+
366+
//HTTP Request
367+
function HTTPRequestNode() {
368+
var that = this;
369+
this.addInput("request", LiteGraph.ACTION);
370+
this.addInput("url", "string");
371+
this.addProperty("url", "");
372+
this.addOutput("ready", LiteGraph.EVENT);
373+
this.addOutput("data", "string");
374+
this.addWidget("button", "Fetch", null, this.fetch.bind(this));
375+
this._data = null;
376+
this._fetching = null;
377+
}
378+
379+
HTTPRequestNode.title = "HTTP Request";
380+
HTTPRequestNode.desc = "Fetch data through HTTP";
381+
382+
HTTPRequestNode.prototype.fetch = function()
383+
{
384+
var url = this.properties.url;
385+
if(!url)
386+
return;
387+
388+
this.boxcolor = "#FF0";
389+
var that = this;
390+
this._fetching = fetch(url)
391+
.then(resp=>{
392+
if(!resp.ok)
393+
{
394+
this.boxcolor = "#F00";
395+
that.trigger("error");
396+
}
397+
else
398+
{
399+
this.boxcolor = "#0F0";
400+
return resp.text();
401+
}
402+
})
403+
.then(data=>{
404+
that._data = data;
405+
that._fetching = null;
406+
that.trigger("ready");
407+
});
408+
}
409+
410+
HTTPRequestNode.prototype.onAction = function(evt)
411+
{
412+
if(evt == "request")
413+
this.fetch();
414+
}
415+
416+
HTTPRequestNode.prototype.onExecute = function() {
417+
this.setOutputData(1, this._data);
418+
};
419+
420+
HTTPRequestNode.prototype.onGetOutputs = function() {
421+
return [["error",LiteGraph.EVENT]];
422+
}
423+
424+
LiteGraph.registerNodeType("network/httprequest", HTTPRequestNode);
425+
426+
427+
365428
})(this);

0 commit comments

Comments
 (0)