From c33e2642e1bae526a40305e02ad04079b9a6163d Mon Sep 17 00:00:00 2001 From: Max Richter Date: Thu, 18 Apr 2024 14:10:08 +0200 Subject: [PATCH] feat: improve zoom performance by adding a tiny rand offset to nodes --- app/src/lib/graph-interface/graph-manager.ts | 2 + .../graph-interface/graph/GraphView.svelte | 122 +++++----- app/src/lib/graph-interface/node/Node.svelte | 211 +++++++++--------- .../graph-interface/node/NodeParameter.svelte | 4 - app/src/lib/runtime-executor.ts | 4 +- app/src/routes/+page.svelte | 2 +- packages/types/index.ts | 1 + 7 files changed, 178 insertions(+), 168 deletions(-) diff --git a/app/src/lib/graph-interface/graph-manager.ts b/app/src/lib/graph-interface/graph-manager.ts index a2730df..0bde9a4 100644 --- a/app/src/lib/graph-interface/graph-manager.ts +++ b/app/src/lib/graph-interface/graph-manager.ts @@ -119,6 +119,7 @@ export class GraphManager extends EventEmitter<{ "save": Graph, "result": any }> const nodeType = this.nodeRegistry.getNode(node.type); if (nodeType) { node.tmp = { + random: (Math.random() - 0.5) * 2, type: nodeType }; } @@ -173,6 +174,7 @@ export class GraphManager extends EventEmitter<{ "save": Graph, "result": any }> return; } node.tmp = node.tmp || {}; + node.tmp.random = (Math.random() - 0.5) * 2; node.tmp.type = nodeType; } diff --git a/app/src/lib/graph-interface/graph/GraphView.svelte b/app/src/lib/graph-interface/graph/GraphView.svelte index 083fd69..5b992cd 100644 --- a/app/src/lib/graph-interface/graph/GraphView.svelte +++ b/app/src/lib/graph-interface/graph/GraphView.svelte @@ -1,78 +1,80 @@ {#each $edges as edge (`${edge[0].id}-${edge[1]}-${edge[2].id}-${edge[3]}`)} - {@const pos = getEdgePosition(edge)} - {@const [x1, y1, x2, y2] = pos} - + {@const pos = getEdgePosition(edge)} + {@const [x1, y1, x2, y2] = pos} + {/each} -
- {#each $nodes.values() as node (node.id)} - - {/each} -
+
+ {#each $nodes.values() as node (node.id)} + + {/each} +
diff --git a/app/src/lib/graph-interface/node/Node.svelte b/app/src/lib/graph-interface/node/Node.svelte index d46987c..999abd8 100644 --- a/app/src/lib/graph-interface/node/Node.svelte +++ b/app/src/lib/graph-interface/node/Node.svelte @@ -1,129 +1,138 @@ - - + +
zLimit ? "block" : "none"} + class:selected={isSelected} + class:out-of-view={!inView} + data-node-id={node.id} + bind:this={ref} > - + - {#each parameters as [key, value], i} - - {/each} + {#each parameters as [key, value], i} + + {/each}
diff --git a/app/src/lib/graph-interface/node/NodeParameter.svelte b/app/src/lib/graph-interface/node/NodeParameter.svelte index 4ecd040..1b8f623 100644 --- a/app/src/lib/graph-interface/node/NodeParameter.svelte +++ b/app/src/lib/graph-interface/node/NodeParameter.svelte @@ -156,10 +156,6 @@ box-sizing: border-box; } - :global(.zoom-small) .content { - display: none; - } - svg { position: absolute; box-sizing: border-box; diff --git a/app/src/lib/runtime-executor.ts b/app/src/lib/runtime-executor.ts index d05a945..74f13a4 100644 --- a/app/src/lib/runtime-executor.ts +++ b/app/src/lib/runtime-executor.ts @@ -183,7 +183,7 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor { return value; }); - console.log(transformed_inputs); + // console.log(transformed_inputs); const a2 = performance.now(); @@ -191,7 +191,7 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor { const _inputs = concat_encoded(transformed_inputs); const a3 = performance.now(); - console.log(`executing ${node_type.id || node.id}`, _inputs); + // console.log(`executing ${node_type.id || node.id}`, _inputs); results[node.id] = node_type.execute(_inputs) as number; const duration = performance.now() - a3; if (duration > 5) { diff --git a/app/src/routes/+page.svelte b/app/src/routes/+page.svelte index fb8d1d6..4a1d69d 100644 --- a/app/src/routes/+page.svelte +++ b/app/src/routes/+page.svelte @@ -75,7 +75,7 @@ header diff --git a/packages/types/index.ts b/packages/types/index.ts index c282340..7674de8 100644 --- a/packages/types/index.ts +++ b/packages/types/index.ts @@ -8,6 +8,7 @@ export type Node = { tmp?: { depth?: number; mesh?: any; + random?: number; parents?: Node[], children?: Node[], inputNodes?: Record