From e25c21026c9bc228712e1a5ecfcb2ebea09e7864 Mon Sep 17 00:00:00 2001 From: Chenlei Hu Date: Mon, 2 Sep 2024 14:31:05 -0400 Subject: [PATCH] Fix LGraphNode.pos serialization (#107) --- src/litegraph.js | 4 ++-- test/LGraphNode.test.ts | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 test/LGraphNode.test.ts diff --git a/src/litegraph.js b/src/litegraph.js index 4780134ef..729e759b7 100755 --- a/src/litegraph.js +++ b/src/litegraph.js @@ -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) { diff --git a/test/LGraphNode.test.ts b/test/LGraphNode.test.ts new file mode 100644 index 000000000..1543edf86 --- /dev/null +++ b/test/LGraphNode.test.ts @@ -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])); + }); +}); \ No newline at end of file