-
Notifications
You must be signed in to change notification settings - Fork 628
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
is there an onGraphChange() or onCanvasChange() event? #458
Comments
LGraph.onchange() will be fired even when zooming and dragging canvas, without graph nodes values change LGraph.onAfterChange() will not be fired when a node widget value change, either not fired when configure() a new graph....🫠 this is what I'm doing now but I don't think this is accurate:
|
Perhaps someone needs it, I'll leave the code here that I'm sure can be used (there might be performance issues, but it can ensure that the graph change event is triggered correctly): class LGraphPro extends LGraph {
private _graph_cache = {} as serializedLGraph;
emit(...args: any[]) { /* ... */ }
change(): void {
super.change();
this.emit("change");
this.checkGraphChange();
}
connectionChange(node: LGraphNode): void {
super.connectionChange?.(node);
this.emit("connection_change", node);
this.checkGraphChange();
}
serializeDeep(options?: {
skip_inputs?: boolean;
skip_outputs?: boolean;
skip_properties?: boolean;
skip_links?: boolean;
skip_nodes?: boolean;
}) {
const graph_obj = this.serialize();
graph_obj.nodes.sort((a, b) => a.id - b.id);
if (options?.skip_inputs) {
graph_obj.nodes.map((x) => (x.inputs = []));
}
if (options?.skip_outputs) {
graph_obj.nodes.map((x) => (x.outputs = []));
}
if (options?.skip_properties) {
graph_obj.nodes.map((x) => (x.properties = {}));
}
if (options?.skip_links) {
graph_obj.links = [];
}
if (options?.skip_nodes) {
graph_obj.nodes = [];
}
return cloneDeep(graph_obj);
}
private checkGraphChange() {
const graph_obj = this.serializeDeep({
skip_inputs: true,
skip_outputs: true,
skip_properties: true,
});
if (deepEqual(graph_obj, this._graph_cache)) {
return;
}
this._graph_cache = graph_obj;
this.events?.emit("graph_change", this.serializeDeep());
}
} |
I need to listen for when user change the graph or canvas. If an event can be emitted and listened for it would be great!
The text was updated successfully, but these errors were encountered: