Skip to content

Commit

Permalink
Fix LGraphNode.pos serialization (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
huchenlei authored Sep 2, 2024
1 parent 8a8ebb4 commit e25c210
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/litegraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -2348,8 +2348,8 @@ const globalExport = {};
this.title = title || "Unnamed";
this.size = [LiteGraph.NODE_WIDTH, 60];
this.graph = null;

this._pos = new Float32Array(10, 10);
// Initialize _pos with a Float32Array of length 2, default value [10, 10]
this._pos = new Float32Array([10, 10]);

Object.defineProperty(this, "pos", {
set: function (v) {
Expand Down
12 changes: 12 additions & 0 deletions test/LGraphNode.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {
LGraphNode,
} from "../dist/litegraph.es.js";

describe("LGraphNode", () => {
it("should serialize position correctly", () => {
const node = new LGraphNode("TestNode");
node.pos = [10, 10];
expect(node.pos).toEqual(new Float32Array([10, 10]));
expect(node.serialize().pos).toEqual(new Float32Array([10, 10]));
});
});

0 comments on commit e25c210

Please sign in to comment.