diff --git a/src/electron/lib/ai/ai-cookbook.ts b/src/electron/lib/ai/ai-cookbook.ts index cfde3464..2498e290 100644 --- a/src/electron/lib/ai/ai-cookbook.ts +++ b/src/electron/lib/ai/ai-cookbook.ts @@ -155,7 +155,9 @@ export function addNode( const node = registry[args.signature]; if (!node) return errorResponse("The provided signature is invalid : node does not exist"); - const response = graphManager.addNode(graphId, node, CoreGraphUpdateParticipant.ai); + // TODO: Calculate at what position to add node then set pos + const pos = { x: 0, y: 0 }; + const response = graphManager.addNode(graphId, node, pos, CoreGraphUpdateParticipant.ai); if (response.status === "success" && response.data) { // Truncate ids diff --git a/src/electron/lib/api/apis/GraphApi.ts b/src/electron/lib/api/apis/GraphApi.ts index 473d1273..24e5f4fa 100644 --- a/src/electron/lib/api/apis/GraphApi.ts +++ b/src/electron/lib/api/apis/GraphApi.ts @@ -4,7 +4,7 @@ import { type UUID } from "../../../../shared/utils/UniqueEntity"; import { type NodeSignature } from "../../../../shared/ui/ToolboxTypes"; import { type INodeUIInputs } from "../../../../shared/types"; import { CoreGraphUpdateParticipant } from "../../core-graph/CoreGraphInteractors"; -import type { GraphMetadata } from "../../../../shared/ui/UIGraph"; +import type { GraphMetadata, SvelvetCanvasPos } from "../../../../shared/ui/UIGraph"; // Graphs across projects are stored homogeneously and referenced by UUID export class GraphApi implements ElectronMainApi { @@ -15,10 +15,11 @@ export class GraphApi implements ElectronMainApi { } // TODO: Implement these properly - async addNode(graphUUID: UUID, nodeSignature: NodeSignature) { + async addNode(graphUUID: UUID, nodeSignature: NodeSignature, pos: SvelvetCanvasPos) { return this._blix.graphManager.addNode( graphUUID, this._blix.toolbox.getNodeInstance(nodeSignature), + pos, CoreGraphUpdateParticipant.user ); } diff --git a/src/electron/lib/core-graph/CoreGraph.ts b/src/electron/lib/core-graph/CoreGraph.ts index 2dd5c7a9..c2beb4d8 100644 --- a/src/electron/lib/core-graph/CoreGraph.ts +++ b/src/electron/lib/core-graph/CoreGraph.ts @@ -9,7 +9,7 @@ import { import type { EdgeToJSON, GraphToJSON, NodeToJSON } from "./CoreGraphExporter"; import { type NodeSignature } from "../../../shared/ui/ToolboxTypes"; import type { INodeUIInputs, QueryResponse, UIValue } from "../../../shared/types"; -import { type GraphMetadata } from "../../../shared/ui/UIGraph"; +import { type GraphMetadata, type SvelvetCanvasPos } from "../../../shared/ui/UIGraph"; import { type MediaOutputId } from "../../../shared/types/media"; // ========================================= @@ -51,6 +51,9 @@ export class CoreGraph extends UniqueEntity { // Maps a node UUID to a list of UI inputs private uiInputs: { [key: UUID]: CoreNodeUIInputs }; + // Maps a node UUID to a UI canvas position + private uiPositions: { [key: UUID]: SvelvetCanvasPos }; + // private subscribers: CoreGraphSubscriber[]; private static nodeTracker = 0; constructor() { @@ -61,6 +64,7 @@ export class CoreGraph extends UniqueEntity { this.edgeSrc = {}; this.outputNodes = {}; this.uiInputs = {}; + this.uiPositions = {}; this.metadata = { displayName: "Graph", }; @@ -156,8 +160,15 @@ export class CoreGraph extends UniqueEntity { return this.uiInputs[nodeUUID]?.getInputs || null; } + public get getUIPositions() { + return this.uiPositions; + } + // We need to pass in node name and plugin name - public addNode(node: NodeInstance): QueryResponse<{ + public addNode( + node: NodeInstance, + pos: SvelvetCanvasPos + ): QueryResponse<{ nodeId: UUID; inputs: string[]; outputs: string[]; @@ -185,6 +196,8 @@ export class CoreGraph extends UniqueEntity { // console.log(QueryResponseStatus.success) const anchors: AiAnchors = n.returnAnchors(); + // Add position of node to graph + this.uiPositions[n.uuid] = pos; return { status: "success", message: "Node added succesfully", diff --git a/src/electron/lib/core-graph/CoreGraphImporter.ts b/src/electron/lib/core-graph/CoreGraphImporter.ts index f807c4c5..9fd91241 100644 --- a/src/electron/lib/core-graph/CoreGraphImporter.ts +++ b/src/electron/lib/core-graph/CoreGraphImporter.ts @@ -56,7 +56,8 @@ export class CoreGraphImporter { const nodes: { [key: number]: UUID } = {}; for (const node of json.nodes) { const nodeInstance: NodeInstance = this._toolbox.getNodeInstance(node.signature); - const res = graph.addNode(nodeInstance); + // TODO: fix importer to use imported node positions + const res = graph.addNode(nodeInstance, { x: 0, y: 0 }); if (res.status === "success" && res.data) { nodes[cnt++] = res.data?.nodeId; } diff --git a/src/electron/lib/core-graph/CoreGraphInteractors.ts b/src/electron/lib/core-graph/CoreGraphInteractors.ts index 6abd3008..380edeec 100644 --- a/src/electron/lib/core-graph/CoreGraphInteractors.ts +++ b/src/electron/lib/core-graph/CoreGraphInteractors.ts @@ -98,6 +98,7 @@ export class IPCGraphSubscriber extends CoreGraphSubscriber { onGraphChanged(graphId: UUID, graphData: CoreGraph): void { const uiGraph: UIGraph = new UIGraph(graphId); uiGraph.metadata = graphData.getMetadata; + uiGraph.uiPositions = graphData.getUIPositions; const nodesAndEdges: NodesAndEdgesGraph = graphData.exportNodesAndEdges(); for (const node in nodesAndEdges.nodes) { diff --git a/src/electron/lib/core-graph/CoreGraphManager.ts b/src/electron/lib/core-graph/CoreGraphManager.ts index 08c684df..4e3b4e11 100644 --- a/src/electron/lib/core-graph/CoreGraphManager.ts +++ b/src/electron/lib/core-graph/CoreGraphManager.ts @@ -13,7 +13,7 @@ import { NodeInstance } from "../registries/ToolboxRegistry"; import { Blix } from "../Blix"; import type { INodeUIInputs, QueryResponse } from "../../../shared/types"; import type { MediaOutputId } from "../../../shared/types/media"; -import { type GraphMetadata } from "../../../shared/ui/UIGraph"; +import { type GraphMetadata, type SvelvetCanvasPos } from "../../../shared/ui/UIGraph"; const GRAPH_UPDATED_EVENT = new Set([CoreGraphUpdateEvent.graphUpdated]); @@ -47,11 +47,12 @@ export class CoreGraphManager { addNode( graphUUID: UUID, node: NodeInstance, + pos: SvelvetCanvasPos, participant: CoreGraphUpdateParticipant ): QueryResponse<{ nodeId: UUID; inputs: string[]; outputs: string[] }> { if (this._graphs[graphUUID] === undefined) return { status: "error", message: "Graph does not exist" }; - const res = this._graphs[graphUUID].addNode(node); + const res = this._graphs[graphUUID].addNode(node, pos); if (res.status === "success") this.onGraphUpdated(graphUUID, GRAPH_UPDATED_EVENT, participant); return res; } diff --git a/src/electron/lib/core-graph/CoreGraphTesting.ts b/src/electron/lib/core-graph/CoreGraphTesting.ts index 4f11e4e7..9282500b 100644 --- a/src/electron/lib/core-graph/CoreGraphTesting.ts +++ b/src/electron/lib/core-graph/CoreGraphTesting.ts @@ -192,10 +192,12 @@ export class TestGraph { const g2: CoreGraph = new CoreGraph(); - g2.addNode(tempNodesInt[0]); - g2.addNode(tempNodesInt[1]); - g2.addNode(tempNodesInt[2]); - g2.addNode(tempNodesInt[3]); + const pos = { x: 0, y: 0 }; + g2.addNode(this.tempNodes[0], pos); + g2.addNode(this.tempNodes[1], pos); + g2.addNode(this.tempNodes[2], pos); + g2.addNode(this.tempNodes[3], pos); + // g2.addNode(tempNodesInt[4]); // g2.addNode(tempNodesInt[5]); @@ -267,10 +269,10 @@ export class TestGraph { // ===================================== const g1: CoreGraph = new CoreGraph(); - - g1.addNode(this.tempNodes[0]); - g1.addNode(this.tempNodes[1]); - g1.addNode(this.tempNodes[2]); + const pos = { x: 0, y: 0 }; + g1.addNode(this.tempNodes[0], pos); + g1.addNode(this.tempNodes[1], pos); + g1.addNode(this.tempNodes[2], pos); const nodes = g1.getNodes; const actualNode1 = Object.values(nodes)[0]; @@ -325,12 +327,13 @@ export class TestGraph { const g2: CoreGraph = new CoreGraph(); - g2.addNode(this.tempNodes[0]); - g2.addNode(this.tempNodes[1]); - g2.addNode(this.tempNodes[2]); - g2.addNode(this.tempNodes[3]); - g2.addNode(this.tempNodes[4]); - g2.addNode(this.tempNodes[5]); + const pos = { x: 0, y: 0 }; + g2.addNode(this.tempNodes[0], pos); + g2.addNode(this.tempNodes[1], pos); + g2.addNode(this.tempNodes[2], pos); + g2.addNode(this.tempNodes[3], pos); + g2.addNode(this.tempNodes[4], pos); + g2.addNode(this.tempNodes[5], pos); const g2Nodes = g2.getNodes; const g2Node1 = Object.values(g2Nodes)[0]; @@ -408,8 +411,9 @@ export class TestGraph { const g3: CoreGraph = new CoreGraph(); - g3.addNode(this.tempNodes[0]); - g3.addNode(this.tempNodes[1]); + const pos = { x: 0, y: 0 }; + g3.addNode(this.tempNodes[0], pos); + g3.addNode(this.tempNodes[1], pos); const g3Nodes = g3.getNodes; const g3Node1 = Object.values(g3Nodes)[0]; @@ -456,9 +460,9 @@ export class TestGraph { // ===================================== const g4: CoreGraph = new CoreGraph(); - - g4.addNode(this.tempNodes[0]); - g4.addNode(this.tempNodes[1]); + const pos = { x: 0, y: 0 }; + g4.addNode(this.tempNodes[0], pos); + g4.addNode(this.tempNodes[1], pos); const g4Nodes = g4.getNodes; const g4Node1 = Object.values(g4Nodes)[0]; @@ -504,7 +508,7 @@ export class TestGraph { const g5: CoreGraph = new CoreGraph(); - g5.addNode(this.tempNodes[0]); + g5.addNode(this.tempNodes[0], { x: 0, y: 0 }); const g5Nodes = g5.getNodes; const g5Node1 = Object.values(g5Nodes)[0]; @@ -538,11 +542,12 @@ export class TestGraph { const g6: CoreGraph = new CoreGraph(); - g6.addNode(this.tempNodes[0]); - g6.addNode(this.tempNodes[1]); - g6.addNode(this.tempNodes[2]); - g6.addNode(this.tempNodes[3]); - g6.addNode(this.tempNodes[4]); + const pos = { x: 0, y: 0 }; + g6.addNode(this.tempNodes[0], pos); + g6.addNode(this.tempNodes[1], pos); + g6.addNode(this.tempNodes[2], pos); + g6.addNode(this.tempNodes[3], pos); + g6.addNode(this.tempNodes[4], pos); const g6Nodes = g6.getNodes; const g6Node1 = Object.values(g6Nodes)[0]; @@ -621,11 +626,12 @@ export class TestGraph { const g6: CoreGraph = new CoreGraph(); - g6.addNode(this.tempNodes[0]); - g6.addNode(this.tempNodes[1]); - g6.addNode(this.tempNodes[2]); - g6.addNode(this.tempNodes[3]); - g6.addNode(this.tempNodes[4]); + const pos = { x: 0, y: 0 }; + g6.addNode(this.tempNodes[0], pos); + g6.addNode(this.tempNodes[1], pos); + g6.addNode(this.tempNodes[2], pos); + g6.addNode(this.tempNodes[3], pos); + g6.addNode(this.tempNodes[4], pos); const g6Nodes = g6.getNodes; const g6Node1 = Object.values(g6Nodes)[0]; @@ -706,12 +712,12 @@ export class TestGraph { // ===================================== const g6: CoreGraph = new CoreGraph(); - - g6.addNode(this.tempNodes[0]); - g6.addNode(this.tempNodes[1]); - g6.addNode(this.tempNodes[2]); - g6.addNode(this.tempNodes[3]); - g6.addNode(this.tempNodes[4]); + const pos = { x: 0, y: 0 }; + g6.addNode(this.tempNodes[0], pos); + g6.addNode(this.tempNodes[1], pos); + g6.addNode(this.tempNodes[2], pos); + g6.addNode(this.tempNodes[3], pos); + g6.addNode(this.tempNodes[4], pos); const g6Nodes = g6.getNodes; const g6Node1 = Object.values(g6Nodes)[0]; @@ -919,8 +925,8 @@ export function testStuffies(blix: Blix) { const graph = blix.graphManager.createGraph(); project.addGraph(graph); const g = blix.graphManager.getGraph(graph); - g.addNode(tempNodes[0]); - g.addNode(tempNodes[1]); + g.addNode(tempNodes[0], { x: 0, y: 0 }); + g.addNode(tempNodes[1], { x: 0, y: 0 }); const nodes = g.getNodes; const node1 = Object.values(nodes)[0]; diff --git a/src/electron/lib/projects/ProjectCommands.ts b/src/electron/lib/projects/ProjectCommands.ts index e9e7cfdc..148884a9 100644 --- a/src/electron/lib/projects/ProjectCommands.ts +++ b/src/electron/lib/projects/ProjectCommands.ts @@ -18,6 +18,7 @@ import { CoreGraphUpdateParticipant, } from "../core-graph/CoreGraphInteractors"; import sharp from "sharp"; +import type { SvelvetCanvasPos } from "../../../shared/ui/UIGraph"; export type SaveProjectArgs = { projectId: UUID; diff --git a/src/frontend/lib/stores/CommandStore.ts b/src/frontend/lib/stores/CommandStore.ts index 237d47c4..89354973 100644 --- a/src/frontend/lib/stores/CommandStore.ts +++ b/src/frontend/lib/stores/CommandStore.ts @@ -50,6 +50,7 @@ function createCommandStore() { const blixCommandParams: Record any> = { "blix.projects.save": () => { const project = get(projectsStore).activeProject; + // await window.apis.graphApi.updateUIPositions(project?.graphs); return { projectId: project?.id, layout: project?.layout.saveLayout(), diff --git a/src/frontend/lib/stores/GraphStore.ts b/src/frontend/lib/stores/GraphStore.ts index 5dd18efe..558fcec0 100644 --- a/src/frontend/lib/stores/GraphStore.ts +++ b/src/frontend/lib/stores/GraphStore.ts @@ -9,6 +9,7 @@ import { type SvelvetCanvasPos, constructUIValueStore, type GraphMetadata, + NodeStylingStore, } from "@shared/ui/UIGraph"; import { writable, get, derived, type Writable, type Readable } from "svelte/store"; import { toolboxStore } from "./ToolboxStore"; @@ -31,7 +32,13 @@ import { tick } from "svelte"; // type Connections = (string | number | [string | number, string | number] | null)[]; // TODO: Return a GraphStore in createGraphStore for typing +export type GraphView = { + translation: { x: number; y: number }; + dimensions: { width: number; height: number }; + zoom: number; +}; export class GraphStore { + view: Writable; graphStore: Writable; uiInputUnsubscribers: { [key: GraphNodeUUID]: (() => void)[] } = {}; uiInputSubscribers: { [key: GraphNodeUUID]: () => void } = {}; @@ -39,6 +46,7 @@ export class GraphStore { constructor(public uuid: GraphUUID) { // Starts with empty graph this.graphStore = writable(new UIGraph(uuid)); + this.view = writable(); } public refreshUIInputs(newUIInputs: IGraphUIInputs) { @@ -75,10 +83,13 @@ export class GraphStore { if (oldNodes[node]) { // Node carried over from old graph, maintain its styling / UI inputs graph.nodes[node].styling = oldNodes[node].styling; + // graph.nodes[node].styling.pos = graph.nodes[node].inputUIValues = oldNodes[node].inputUIValues; } else { // If node has a UI input, create a store and subscribe to it const toolboxNode = toolboxStore.getNode(graph.nodes[node].signature); + graph.nodes[node].styling = new NodeStylingStore(); + graph.nodes[node].styling!.pos.set(newGraph.uiPositions[node]); if (toolboxNode.ui) { graph.nodes[node].inputUIValues = constructUIValueStore( @@ -128,9 +139,9 @@ export class GraphStore { }); } - async addNode(nodeSignature: NodeSignature, pos?: SvelvetCanvasPos) { + async addNode(nodeSignature: NodeSignature, pos: SvelvetCanvasPos) { const thisUUID = get(this.graphStore).uuid; - const res = await window.apis.graphApi.addNode(thisUUID, nodeSignature); + const res = await window.apis.graphApi.addNode(thisUUID, nodeSignature, pos); // if (pos) { // console.log("SET NODE POS", pos); diff --git a/src/frontend/ui/tiles/Graph.svelte b/src/frontend/ui/tiles/Graph.svelte index 82b5fe4a..d682e86a 100644 --- a/src/frontend/ui/tiles/Graph.svelte +++ b/src/frontend/ui/tiles/Graph.svelte @@ -87,6 +87,17 @@ $: zoom = graphData?.transforms?.scale; $: dimensions = graphData?.dimensions; + $: $thisGraphStore?.view?.set({ + translation: $translation, + dimensions: $dimensions, + zoom: $zoom, + }); + // $: if($thisGraphStore?.view) { + // console.log(get($thisGraphStore.view)); + // } + + $: console.log($zoom); + // Hooks exposed by let connectAnchorIds: ( sourceNode: NodeKey, diff --git a/src/frontend/ui/utils/ContextMenu.svelte b/src/frontend/ui/utils/ContextMenu.svelte index 51cf5932..bd7a6318 100644 --- a/src/frontend/ui/utils/ContextMenu.svelte +++ b/src/frontend/ui/utils/ContextMenu.svelte @@ -69,9 +69,12 @@ if (!graphStore) return; if (action.type === "addNode") { + const view = get(graphStore.view); + console.log(view); + console.log(graphMenuState.canvasPos); graphStore.addNode(action.signature, { - x: graphMenuState.canvasPos.x, - y: graphMenuState.canvasPos.y, + x: view.dimensions.width / 2 - view.translation.x / view.zoom, + y: view.dimensions.height / 2 - view.translation.y / view.zoom, }); } }, diff --git a/src/shared/ui/UIGraph.ts b/src/shared/ui/UIGraph.ts index 2840f6fc..dd5ed4fa 100644 --- a/src/shared/ui/UIGraph.ts +++ b/src/shared/ui/UIGraph.ts @@ -16,6 +16,7 @@ export type GraphMetadata = { export class UIGraph { public nodes: { [key: GraphNodeUUID]: GraphNode } = {}; public edges: { [key: GraphAnchorUUID]: GraphEdge } = {}; + public uiPositions: { [key: GraphNodeUUID]: SvelvetCanvasPos } = {}; public metadata: GraphMetadata = { displayName: "Graph", }; diff --git a/tests/integration-tests/core-graph/graphInterpreter.spec.ts b/tests/integration-tests/core-graph/graphInterpreter.spec.ts index 7c5c9106..09f2412c 100644 --- a/tests/integration-tests/core-graph/graphInterpreter.spec.ts +++ b/tests/integration-tests/core-graph/graphInterpreter.spec.ts @@ -153,10 +153,11 @@ describe("Test graph interpreter", () => { blix.toolbox.addInstance(tempNodesInt[2]); const g2: CoreGraph = new CoreGraph(); - - g2.addNode(tempNodesInt[0]); - g2.addNode(tempNodesInt[1]); - g2.addNode(tempNodesInt[2]); + + const pos = { x: 0, y: 0 }; + g2.addNode(tempNodesInt[0], pos); + g2.addNode(tempNodesInt[1], pos); + g2.addNode(tempNodesInt[2], pos); const g2Nodes = g2.getNodes; @@ -261,10 +262,11 @@ describe("Test graph interpreter", () => { blix.toolbox.addInstance(tempNodesInt[2]); const g2: CoreGraph = new CoreGraph(); - - g2.addNode(tempNodesInt[0]); - g2.addNode(tempNodesInt[1]); - g2.addNode(tempNodesInt[2]); + + const pos = { x: 0, y: 0 } + g2.addNode(tempNodesInt[0], pos); + g2.addNode(tempNodesInt[1], pos); + g2.addNode(tempNodesInt[2], pos); const g2Nodes = g2.getNodes; diff --git a/tests/integration-tests/media/mediaManager.spec.ts b/tests/integration-tests/media/mediaManager.spec.ts index 935649ab..87cbab23 100644 --- a/tests/integration-tests/media/mediaManager.spec.ts +++ b/tests/integration-tests/media/mediaManager.spec.ts @@ -129,7 +129,7 @@ describe("Test graph importer", () => { const graph = new CoreGraph(); blix.graphManager.addGraph(graph); - blix.graphManager.addNode(graph.uuid, blix.toolbox.getRegistry()["blix.output"], CoreGraphUpdateParticipant.user); + blix.graphManager.addNode(graph.uuid, blix.toolbox.getRegistry()["blix.output"], { x: 0, y: 0 }, CoreGraphUpdateParticipant.user); //mediaManager.onGraphUpdated(graph.uuid); diff --git a/tests/unit-tests/electron/lib/core-graph/CoreGraph.spec.ts b/tests/unit-tests/electron/lib/core-graph/CoreGraph.spec.ts index 27727fd8..7ed4047d 100644 --- a/tests/unit-tests/electron/lib/core-graph/CoreGraph.spec.ts +++ b/tests/unit-tests/electron/lib/core-graph/CoreGraph.spec.ts @@ -21,7 +21,7 @@ describe("Test backend graph", () => { for(let i = 0; i < 10; i++){ const node = new NodeInstance(`Node-${i}`, "Test-plugin", `Node-${i}`, `This is node ${i}`, `fa-duotone fa-bell`, inputs, outputs); nodes.push(node); - graph.addNode(node); + graph.addNode(node, { x: 0, y: 0 }); } }); @@ -40,7 +40,7 @@ describe("Test backend graph", () => { const input: MinAnchor = { type: "string", displayName: `Test-plugin.Node-${i}.0`, identifier: `in${i}` }; const output: MinAnchor = { type: "string", displayName: `Test-plugin.Node-${i}.1`, identifier: `out${i}` }; const node = new NodeInstance(`Node-${i}`, `Test-plugin`, `Node-${i}`, `This is node ${i}`, `fa-duotone fa-bell`, [input], [output]); - graph.addNode(node); + graph.addNode(node, { x: 0, y: 0 }); names.push(input.displayName, output.displayName); } const anchorNames = Object.values(graph.getAnchors).map((anchor) => anchor.displayName); @@ -65,7 +65,7 @@ describe("Test backend graph", () => { test("Setting a node's position", () => { const node = new NodeInstance("Test-plugin",`Node-1`, `Node-1`, `This is node 1`, `fa-duotone fa-bell`, inputs, outputs); - const response: QueryResponse<{ nodeId: UUID }> = graph.addNode(node); + const response: QueryResponse<{ nodeId: UUID }> = graph.addNode(node, { x: 0, y: 0}); const uuid = (response.data! as { nodeId: UUID }).nodeId; const response2: QueryResponse = graph.setNodePos(uuid, { x: 6, y: 9}); expect(response2.status).toBe("success"); @@ -115,7 +115,7 @@ describe("Test CoreGraph Class", () => { test("Adding a node to a graph", () => { const node = new NodeInstance("Node-1",`Test-Plugin`, `Node-1`, `This is node 1`, `fa-duotone fa-bell`, inputs, outputs); - const response: QueryResponse<{ nodeId: UUID }> = graph.addNode(node); + const response: QueryResponse<{ nodeId: UUID }> = graph.addNode(node, { x: 0, y: 0 }); const uuid = (response.data! as { nodeId: UUID }).nodeId; expect(uuid).toBe(graph.getNodes[uuid].uuid); const node2 = graph.getNodes[uuid]; @@ -128,7 +128,7 @@ test("Adding a node to a graph", () => { test("Removing a node from a graph", () => { const node = new NodeInstance("Test-plugin",`Node-1`, `Node-1`, `This is node 1`, `fa-duotone fa-bell`, inputs, outputs); - const response: QueryResponse<{ nodeId: UUID }> = graph.addNode(node); + const response: QueryResponse<{ nodeId: UUID }> = graph.addNode(node, { x: 0, y: 0 }); const uuid = (response.data! as { nodeId: UUID }).nodeId; graph.removeNode(uuid); expect(graph.getNodes[uuid]).toBeUndefined(); @@ -165,9 +165,10 @@ test("Adding a node to a graph", () => { const node1Instance = new NodeInstance(`${bestNode}-${1}`, `${plugin}`, `${bestNode}-1`, description, icon, inputs1, outputs1); const node2Instance = new NodeInstance(`${bestNode}-${2}`, `${plugin}`, `${bestNode}-2`, description, icon, inputs2, outputs2); - - graph.addNode(node1Instance); - graph.addNode(node2Instance); + + const pos = { x: 0, y: 0 }; + graph.addNode(node1Instance, pos); + graph.addNode(node2Instance, pos); const node1Node = Object.values(graph.getNodes)[0]; @@ -263,8 +264,9 @@ test("Adding a node to a graph", () => { const node1Instance = new NodeInstance(`${node}-${1}`, `${plugin}`, `${node}-1`, description, icon, inputs1, outputs1); const node2Instance = new NodeInstance(`${node}-${2}`, `${plugin}`, `${node}-2`, description, icon, inputs2, outputs2); - graph.addNode(node1Instance); - graph.addNode(node2Instance); + const pos = { x: 0, y: 0 }; + graph.addNode(node1Instance, pos); + graph.addNode(node2Instance, pos); const node1Node = Object.values(graph.getNodes)[0]; const node2Node = Object.values(graph.getNodes)[1]; @@ -335,11 +337,11 @@ test("Adding a node to a graph", () => { const node3Instance = new NodeInstance(`${node}-${3}`, `${plugin}`, `${node}-3`, description, icon, inputs3, outputs3); const node4Instance = new NodeInstance(`${node}-${4}`, `${plugin}`, `${node}-4`, description, icon, inputs4, outputs4); - graph.addNode(node1Instance); - graph.addNode(node2Instance); - graph.addNode(node3Instance); - graph.addNode(node4Instance); - + const pos = { x: 0, y: 0 }; + graph.addNode(node1Instance, pos); + graph.addNode(node2Instance, pos); + graph.addNode(node3Instance, pos); + graph.addNode(node4Instance, pos); const node1Node = Object.values(graph.getNodes)[0]; const node2Node = Object.values(graph.getNodes)[1]; @@ -397,9 +399,10 @@ test("Adding a node to a graph", () => { const node1Instance = new NodeInstance(`${node}-${1}`, `${plugin}`, `${node}-1`, description, icon, inputs1, outputs1); const node2Instance = new NodeInstance(`${node}-${2}`, `${plugin}`, `${node}-2`, description, icon, inputs2, outputs2); - - graph.addNode(node1Instance); - graph.addNode(node2Instance); + + const pos = { x: 0, y: 0 }; + graph.addNode(node1Instance, pos); + graph.addNode(node2Instance, pos); const node1Node = Object.values(graph.getNodes)[0]; const node2Node = Object.values(graph.getNodes)[1]; @@ -471,10 +474,11 @@ test("Adding a node to a graph", () => { const node3Instance = new NodeInstance(`${node}-${3}`, `${plugin}`, `${node}-3`, description, icon, inputs3, outputs3); const node4Instance = new NodeInstance(`${node}-${4}`, `${plugin}`, `${node}-4`, description, icon, inputs4, outputs4); - graph.addNode(node1Instance); - graph.addNode(node2Instance); - graph.addNode(node3Instance); - graph.addNode(node4Instance); + const pos = { x: 0, y: 0 }; + graph.addNode(node1Instance, pos); + graph.addNode(node2Instance, pos); + graph.addNode(node3Instance, pos); + graph.addNode(node4Instance, pos);; const node1Node = Object.values(graph.getNodes)[0]; @@ -722,8 +726,10 @@ describe("Test NodesAndEdgesGraph Class ", () => { const node1Instance = new NodeInstance(`${node}-${1}`, `${plugin}`, `${node}-1`, description, icon, inputs1, outputs1); const node2Instance = new NodeInstance(`${node}-${2}`, `${plugin}`, `${node}-2`, description, icon, inputs2, outputs2); - g.addNode(node1Instance); - g.addNode(node2Instance); + const pos = { x: 0, y: 0 }; + g.addNode(node1Instance, pos); + g.addNode(node2Instance, pos); + const node1Node = Object.values(g.getNodes)[0]; const node2Node = Object.values(g.getNodes)[1]; diff --git a/tests/unit-tests/electron/lib/core-graph/CoreGraphExporter.spec.ts b/tests/unit-tests/electron/lib/core-graph/CoreGraphExporter.spec.ts index 220d921e..68a6849b 100644 --- a/tests/unit-tests/electron/lib/core-graph/CoreGraphExporter.spec.ts +++ b/tests/unit-tests/electron/lib/core-graph/CoreGraphExporter.spec.ts @@ -58,9 +58,9 @@ jest.mock("fs", () => ({ node1 = new NodeInstance("Node-1", "Test-Plugin","Node 1","This is node 1","fa-bell", inputs1, outputs1); node2 = new NodeInstance("Node-2", "Test-Plugin","node 2","This is node 2","fa-bell", inputs2, outputs2); - let response: QueryResponse<{ nodeId: UUID }> = graph.addNode(node1); + let response: QueryResponse<{ nodeId: UUID }> = graph.addNode(node1, { x: 0, y: 0 }); const uuid1 = (response.data! as { nodeId: UUID }).nodeId; - response = graph.addNode(node2); + response = graph.addNode(node2, { x: 0, y: 0}); const uuid2 = (response.data! as { nodeId: UUID }).nodeId; // Get Node objects from graph diff --git a/tests/unit-tests/electron/lib/core-graph/CoreGraphManager.spec.ts b/tests/unit-tests/electron/lib/core-graph/CoreGraphManager.spec.ts index bf5d77af..186733dc 100644 --- a/tests/unit-tests/electron/lib/core-graph/CoreGraphManager.spec.ts +++ b/tests/unit-tests/electron/lib/core-graph/CoreGraphManager.spec.ts @@ -106,7 +106,7 @@ jest.mock("electron-store", () => ({ //Add Node to graph const node = new NodeInstance("Jake", "Shark", "Shark.Jake", "This is the Jake plugin :)", "1149", inputs, outputs); graphManager.addGraph(graph); - graphManager.addNode(graph.uuid,node,CoreGraphUpdateParticipant.system); + graphManager.addNode(graph.uuid,node, { x: 0, y: 0 }, CoreGraphUpdateParticipant.system); const nodes = graphManager.getGraph(graph.uuid).getNodes; expect(Object.keys(nodes).length).toBe(1); }) @@ -120,8 +120,8 @@ jest.mock("electron-store", () => ({ node2.outputs.push(new OutputAnchorInstance("number","bbbb","bbbb.number")); graphManager.addGraph(graph); - graphManager.addNode(graph.uuid,node,CoreGraphUpdateParticipant.system); - graphManager.addNode(graph.uuid,node2,CoreGraphUpdateParticipant.system); + graphManager.addNode(graph.uuid, node, { x: 0, y: 0 }, CoreGraphUpdateParticipant.system); + graphManager.addNode(graph.uuid, node2, { x: 0, y: 0 }, CoreGraphUpdateParticipant.system); let anchors : string[] = []; @@ -144,7 +144,7 @@ jest.mock("electron-store", () => ({ test("Test removeNode", () => { const node = new NodeInstance("Jake", "Shark", "Shark.Jake", "This is the Jake plugin :)", "1149", inputs, outputs); graphManager.addGraph(graph); - graphManager.addNode(graph.uuid,node,CoreGraphUpdateParticipant.system); + graphManager.addNode(graph.uuid, node, { x: 0, y: 0 }, CoreGraphUpdateParticipant.system); let nodes : string[] = []; for(const key in graphManager.getGraph(graph.uuid).getNodes){ @@ -164,8 +164,8 @@ jest.mock("electron-store", () => ({ node2.outputs.push(new OutputAnchorInstance("number","bbbb","bbbb.number")); graphManager.addGraph(graph); - graphManager.addNode(graph.uuid,node,CoreGraphUpdateParticipant.system); - graphManager.addNode(graph.uuid,node2,CoreGraphUpdateParticipant.system); + graphManager.addNode(graph.uuid, node, { x: 0, y: 0 }, CoreGraphUpdateParticipant.system); + graphManager.addNode(graph.uuid, node2, { x: 0, y: 0 }, CoreGraphUpdateParticipant.system); const node1Node = Object.values(graph.getNodes)[0]; @@ -188,7 +188,7 @@ jest.mock("electron-store", () => ({ const node = new NodeInstance("Jake", "Shark", "Shark.Jake", "This is the Jake plugin :)", "1149", inputs, outputs); graphManager.addGraph(graph); - graphManager.addNode(graph.uuid,node,CoreGraphUpdateParticipant.system); + graphManager.addNode(graph.uuid, node, { x: 0, y: 0 }, CoreGraphUpdateParticipant.system); let nodes : string[] = []; for(const key in graphManager.getGraph(graph.uuid).getNodes){ @@ -231,16 +231,16 @@ jest.mock("electron-store", () => ({ expect(result.status).toBe("error"); const node = new NodeInstance("Jake", "Shark", "Shark.Jake", "This is the Jake plugin :)", "1149", inputs, outputs); - const result2 = graphManager.addNode("",node,CoreGraphUpdateParticipant.system); + const result2 = graphManager.addNode("", node, { x: 0, y: 0 }, CoreGraphUpdateParticipant.system); expect(result2.status).toBe("error"); - const result3 = graphManager.removeNode("","",CoreGraphUpdateParticipant.system); + const result3 = graphManager.removeNode("", "", CoreGraphUpdateParticipant.system); expect(result3.status).toBe("error"); - const result4 = graphManager.removeEdge("","",CoreGraphUpdateParticipant.system); + const result4 = graphManager.removeEdge("", "", CoreGraphUpdateParticipant.system); expect(result4.status).toBe("error"); - const result5 = graphManager.setPos("","",0,0,CoreGraphUpdateParticipant.system); + const result5 = graphManager.setPos("","", 0, 0, CoreGraphUpdateParticipant.system); expect(result5.status).toBe("error"); graphManager.addGraph(graph);