diff --git a/app/src/lib/graph-interface/graph/Graph.svelte b/app/src/lib/graph-interface/graph/Graph.svelte
index cca4a02..e14e922 100644
--- a/app/src/lib/graph-interface/graph/Graph.svelte
+++ b/app/src/lib/graph-interface/graph/Graph.svelte
@@ -1,6 +1,5 @@
{
+ $effect(() => {
+ localStorage.setItem("cameraPosition", `[${this.cameraPosition[0]},${this.cameraPosition[1]},${this.cameraPosition[2]}]`)
+ })
+ })
+ const storedPosition = localStorage.getItem("cameraPosition")
+ if (storedPosition) {
+ try {
+ const d = JSON.parse(storedPosition);
+ this.cameraPosition[0] = d[0];
+ this.cameraPosition[1] = d[1];
+ this.cameraPosition[2] = d[2];
+ } catch (e) {
+ console.log("Failed to parsed stored camera position", e);
+ }
+ }
+ }
width = $state(100);
height = $state(100);
@@ -80,42 +97,24 @@ export class GraphState {
isBodyFocused = () => document?.activeElement?.nodeName !== "INPUT";
- setCameraTransform(
- x = this.cameraPosition[0],
- y = this.cameraPosition[1],
- z = this.cameraPosition[2],
- ) {
- if (this.camera) {
- this.camera.position.x = x;
- this.camera.position.z = y;
- this.camera.zoom = z;
- }
- this.cameraPosition = [x, y, z];
- localStorage.setItem("cameraPosition", JSON.stringify(this.cameraPosition));
- }
-
-
updateNodePosition(node: NodeInstance) {
- if (node.state.ref && node.state.mesh) {
- if (node.state["x"] !== undefined && node.state["y"] !== undefined) {
+ if (
+ node.state.x === node.position[0] &&
+ node.state.y === node.position[1]
+ ) {
+ delete node.state.x;
+ delete node.state.y;
+ }
+
+ if (node.state["x"] !== undefined && node.state["y"] !== undefined) {
+ if (node.state.ref) {
node.state.ref.style.setProperty("--nx", `${node.state.x * 10}px`);
node.state.ref.style.setProperty("--ny", `${node.state.y * 10}px`);
- node.state.mesh.position.x = node.state.x + 10;
- node.state.mesh.position.z = node.state.y + this.getNodeHeight(node.type) / 2;
- if (
- node.state.x === node.position[0] &&
- node.state.y === node.position[1]
- ) {
- delete node.state.x;
- delete node.state.y;
- }
- this.graph.edges = [...this.graph.edges];
- } else {
+ }
+ } else {
+ if (node.state.ref) {
node.state.ref.style.setProperty("--nx", `${node.position[0] * 10}px`);
node.state.ref.style.setProperty("--ny", `${node.position[1] * 10}px`);
- node.state.mesh.position.x = node.position[0] + 10;
- node.state.mesh.position.z =
- node.position[1] + this.getNodeHeight(node.type) / 2;
}
}
}
diff --git a/app/src/lib/graph-interface/keymaps.ts b/app/src/lib/graph-interface/keymaps.ts
index f57e889..7dec61a 100644
--- a/app/src/lib/graph-interface/keymaps.ts
+++ b/app/src/lib/graph-interface/keymaps.ts
@@ -88,11 +88,9 @@ export function setupKeymaps(keymap: Keymap, graph: GraphManager, graphState: Gr
const ease = (t: number) => (t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t);
animate(500, (a: number) => {
- graphState.setCameraTransform(
- lerp(camX, average[0], ease(a)),
- lerp(camY, average[1], ease(a)),
- lerp(camZ, 2, ease(a)),
- );
+ graphState.cameraPosition[0] = lerp(camX, average[0], ease(a));
+ graphState.cameraPosition[1] = lerp(camY, average[1], ease(a));
+ graphState.cameraPosition[2] = lerp(camZ, 2, ease(a))
if (graphState.mouseDown) return false;
});
},