Closed kriffe closed 6 years ago
I can implement it easily, I already have the level where every node belongs. I will try
Great!
Looks like the package is designed to be a node module (used with require). If you rewrite the last lines in topsort.js as an optional export (see below) it can be tested. And if it works good I can publish a fork on npm with the optional and we can include it as a dependency in through npm (npm install package.json --save topsort)
Original end of file
//...
module.exports = topsort
End of file rewrite for include as
//...
if (typeof module !== 'undefined' && typeof module.exports !== 'undefined'){
module.exports = topsort
}
Has there been any work on this? I've got some fairly large and complex node graphs that could use some sorting.
I will consider programing my own sorting function to limit dependencies, but besides that, how the heck did you manage to create that!
Great!
The graph is from Battlefield 3 data. It's basically how the game handles everything about an object, kinda like Unreal's Blueprint system.
Here it is if you want to check it out. http://powback.com/wEBX/#Characters/Soldiers/MpSoldier.json
@jagenjo : Have you considered adding a wrapper to the compiler (or in the future perhaps use webpack)? This should ensure that the library has no dependencies when used externally. Functions like topsort will then be bundled inside the closure and the use wont notice or be able to interact.
Probably need of exporting multiple functions (LGraph, LGraphCanvas, LGraphNode) or bundling into a LITEGRAPH container as discussed in https://github.com/jagenjo/litegraph.js/issues/12
How to enable wrapper in args for google-closure-compiler (in grunt-script)
output_wrapper: '"var LITEGRAPH = (function(){%output% return LITEGRAPH;}).call(this);"'
Well, Im still very hesitant to add dependencies to my libraries, because they make the litegraph base library grow exponentially, but I understand your point of view.
Currently LiteGraph can run on nodejs (I added that last month) so it shouldnt be a problem to create another repo that includes more features without having to include it in the core library.
@jagenjo Ah, nice! i see that now. Then a closure is already in place.
Could perhaps a repo called litegrpah-editor.js be created and have theese kind of functions like topsort? If possible from local example or from the webglstudio.js project perhaps?
I have implemented a positioning system using Springly, and the results are pretty good with just 3 lines of code.
I'm still looking into some solutions that are less physics-based.
For future reference: I had great success with Cytoscape as a translation layer:
I simply generated the Cytoscape graph simultaneously and applied the generated node positions to the Litegraph nodes as well.
well, that approach looks way better than mine.
I just uploaded a new method for LGraph called arrange, this method positions the nodes according to level of dependencies, it doesnt look perfect but good enough for most cases. I will give it another try in the future to get something closer to what you got.
@Powback if possible can u share code example of using cytoscape with litegraph ? thanks
@Powback if possible can u share code example of using cytoscape with litegraph ? thanks
@phineas-pta Yeah, you can find some reference code here: https://github.com/Powback/wEBX/blob/master/script/NodeGraph.js#L1095
ty for the fast answer 😄
@Powback just fyi in fact u dont have to import cytoscape.js
nor cytoscape-dagre.js
at all, only need dagre.js
coz that's what actually arrange nodes not cytoscape
u can check out my quick dirty code: comfyanonymous/ComfyUI#1547
Perhaps the toposort library could be used for automatic node placement (if not already implemented)?
Or perhaps it could be useful in some other way.
https://www.npmjs.com/package/toposort
Used in https://github.com/GooTechnologies/shader-graph