Skip to content

Commit

Permalink
Revert "Add canvas update events (#297)" (#310)
Browse files Browse the repository at this point in the history
This reverts commit 0e8f02f.
  • Loading branch information
huchenlei authored Nov 16, 2024
1 parent 0e8f02f commit f26f7db
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 42 deletions.
17 changes: 6 additions & 11 deletions src/LGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ export class LGraph implements LinkNetwork, Serialisable<SerialisableGraph> {
onExecuteStep?(): void
onNodeAdded?(node: LGraphNode): void
onNodeRemoved?(node: LGraphNode): void
onNodeUpdated?(node: LGraphNode): void
onTrigger?(action: string, param: unknown): void
onInputRenamed?(old_name: string, name: string): void
onInputTypeChanged?(name: string, type: string): void
Expand All @@ -146,8 +145,8 @@ export class LGraph implements LinkNetwork, Serialisable<SerialisableGraph> {
onOutputRenamed?(old_name: string, name: string): void
onOutputTypeChanged?(name: string, type: string): void
onOutputRemoved?(name: string): void
onBeforeChange?(graph: LGraph, node?: LGraphNode): void
onAfterChange?(graph: LGraph, node?: LGraphNode): void
onBeforeChange?(graph: LGraph, info?: LGraphNode): void
onAfterChange?(graph: LGraph, info?: LGraphNode): void
onConnectionChange?(node: LGraphNode): void
on_change?(graph: LGraph): void
onSerialize?(data: ISerialisedGraph | SerialisableGraph): void
Expand Down Expand Up @@ -1206,19 +1205,15 @@ export class LGraph implements LinkNetwork, Serialisable<SerialisableGraph> {
}
}
//used for undo, called before any change is made to the graph
beforeChange(node?: LGraphNode): void {
this.onBeforeChange?.(this, node)
beforeChange(info?: LGraphNode): void {
this.onBeforeChange?.(this, info)
this.canvasAction(c => c.onBeforeChange?.(this))
}
//used to resend actions, called after any change is made to the graph
afterChange(node?: LGraphNode): void {
this.onAfterChange?.(this, node)
afterChange(info?: LGraphNode): void {
this.onAfterChange?.(this, info)
this.canvasAction(c => c.onAfterChange?.(this))
}
nodeUpdate(node?: LGraphNode): void {
this.onNodeUpdated?.(node)
this.canvasAction(c => c.onNodeUpdated?.(node))
}
connectionChange(node: LGraphNode): void {
this.updateExecutionOrder()
this.onConnectionChange?.(node)
Expand Down
32 changes: 1 addition & 31 deletions src/LGraphCanvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,6 @@ export class LGraphCanvas {
onBeforeChange?(graph: LGraph): void
/** called after modifying the graph */
onAfterChange?(graph: LGraph): void
onPositionChanged?: (offset: Point) => void
onZoomChanged?: (scale: number) => void
onClear?: () => void
/** called after moving a node */
onNodeMoved?: (node_dragged: LGraphNode) => void
Expand All @@ -386,8 +384,6 @@ export class LGraphCanvas {
onShowNodePanel?: (n: LGraphNode) => void
onNodeSelected?: (node: LGraphNode) => void
onNodeDeselected?: (node: LGraphNode) => void
onNodeUpdated?: (node: LGraphNode) => void
onNodeWidgetChanged?: (node: LGraphNode, name: string, value: unknown, widget: IWidget) => void
onRender?: (canvas: HTMLCanvasElement, ctx: CanvasRenderingContext2D) => void
/** Implement this function to allow conversion of widget types to input types, e.g. number -> INT or FLOAT for widget link validation checks */
getWidgetLinkType?: (widget: IWidget, node: LGraphNode) => string | null | undefined
Expand Down Expand Up @@ -2361,10 +2357,6 @@ export class LGraphCanvas {
this.ds.offset[0] += delta[0] / this.ds.scale
this.ds.offset[1] += delta[1] / this.ds.scale
this.#dirty()

if (this.onPositionChanged) {
this.onPositionChanged(this.ds.offset)
}
} else if ((this.allow_interaction || (node && node.flags.allow_interaction)) && !this.read_only) {
if (this.connecting_links) this.dirty_canvas = true

Expand Down Expand Up @@ -2808,14 +2800,6 @@ export class LGraphCanvas {

this.ds.changeScale(scale, [e.clientX, e.clientY])

if (this.onZoomChanged) {
this.onZoomChanged(scale)
}

if (this.onPositionChanged) {
this.onPositionChanged(this.ds.offset)
}

this.graph.change()

e.preventDefault()
Expand Down Expand Up @@ -3510,10 +3494,6 @@ export class LGraphCanvas {
node.size[1] * 0.5 +
(this.canvas.height * 0.5) / (this.ds.scale * dpi)
this.setDirty(true, true)

if (this.onPositionChanged) {
this.onPositionChanged(this.ds.offset)
}
}
/**
* adds some useful properties to a mouse event, like the position in graph coordinates
Expand Down Expand Up @@ -5947,9 +5927,7 @@ export class LGraphCanvas {
if (event.type === LiteGraph.pointerevents_method + "down") {
if (w.callback) {
setTimeout(function () {
that.onNodeWidgetChanged?.(node, w.name, w.value, w)
node.onWidgetChanged?.(w.name, w.value, old_value, w)
w.callback(w, that, node, pos, event)
w.callback(w, that, node, pos, event)
}, 20)
}
w.clicked = true
Expand Down Expand Up @@ -6089,7 +6067,6 @@ export class LGraphCanvas {

//value changed
if (old_value != w.value) {
that.onNodeWidgetChanged?.(node, w.name, w.value, w)
node.onWidgetChanged?.(w.name, w.value, old_value, w)
node.graph._version++
}
Expand All @@ -6100,9 +6077,6 @@ export class LGraphCanvas {
function inner_value_change(widget: IWidget, value: TWidgetValue) {
const v = widget.type === "number" ? Number(value) : value
widget.value = v

that.onNodeWidgetChanged?.(node, widget.name, widget.value, widget)

if (widget.options?.property && node.properties[widget.options.property] !== undefined) {
node.setProperty(widget.options.property, v)
}
Expand Down Expand Up @@ -8189,10 +8163,6 @@ export class LGraphCanvas {

this.setDirty(true, true)

if (this.onPositionChanged) {
this.onPositionChanged(this.ds.offset)
}

if (progress < 1) {
animationId = requestAnimationFrame(animate)
} else {
Expand Down

0 comments on commit f26f7db

Please sign in to comment.