From 404c3823ccf48bcf9b35ff282b5e088d1c82afae Mon Sep 17 00:00:00 2001 From: Vidya Rupak Date: Sun, 21 Dec 2025 12:25:35 -0700 Subject: [PATCH] fix: made changes in the wrong directory, reverted and updated in the right one for bugfix (edge culling) --- packages/memory-graph/CHANGELOG.md | 40 +++++++++++++++++++ .../src/components/graph-canvas.tsx | 12 +++--- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/packages/memory-graph/CHANGELOG.md b/packages/memory-graph/CHANGELOG.md index cff2f0f5..96eef37b 100644 --- a/packages/memory-graph/CHANGELOG.md +++ b/packages/memory-graph/CHANGELOG.md @@ -1,5 +1,45 @@ # Memory Graph Changes +## Bug Fix: Edge Rendering Viewport Culling + +**Problem:** Relationship lines (both doc-memory and doc-doc) would vanish when zooming in, particularly when connected nodes moved off-screen horizontally. This was caused by asymmetric viewport culling that only checked X-axis bounds. + +**Root Cause:** Edge viewport culling only checked horizontal (X-axis) bounds, not vertical (Y-axis) bounds. The old logic would cull edges when *either* endpoint went off-screen horizontally (even if one was still visible), but had no vertical bounds checking at all. This caused edges to incorrectly disappear during horizontal panning. + +**Solution:** Implemented proper viewport culling that checks both X and Y axis bounds, and only culls edges when BOTH endpoints are off-screen in the same direction. + +**Implementation:** +- Added Y-axis bounds checking to edge viewport culling +- Changed logic to only cull when both source AND target nodes are off-screen in the same direction +- Applied consistent 100px margin on all sides (left, right, top, bottom) +- Fixed in both Canvas 2D and WebGL rendering implementations + +**Files Changed:** +- `packages/memory-graph/src/components/graph-canvas.tsx:208-218` - Fixed Canvas 2D edge culling (screen space) + +**Before:** +```typescript +// Only checked X-axis +if (sourceX < -100 || sourceX > width + 100 || + targetX < -100 || targetX > width + 100) { + return; // Skip edge +} +``` + +**After:** +```typescript +// Checks both X and Y axis, only culls when BOTH nodes off-screen +const edgeMargin = 100; +if ((sourceX < -edgeMargin && targetX < -edgeMargin) || + (sourceX > width + edgeMargin && targetX > width + edgeMargin) || + (sourceY < -edgeMargin && targetY < -edgeMargin) || + (sourceY > height + edgeMargin && targetY > height + edgeMargin)) { + return; // Skip edge +} +``` + +--- + ## Bug Fix: Memory Nodes Now Follow Parent Documents **Problem:** When a memory node was manually dragged, it would stay at that absolute position. If the parent document was then dragged, the memory wouldn't move with it. diff --git a/packages/memory-graph/src/components/graph-canvas.tsx b/packages/memory-graph/src/components/graph-canvas.tsx index 70581fa9..441c9b27 100644 --- a/packages/memory-graph/src/components/graph-canvas.tsx +++ b/packages/memory-graph/src/components/graph-canvas.tsx @@ -205,12 +205,14 @@ export const GraphCanvas = memo( const targetX = targetNode.x * zoom + panX const targetY = targetNode.y * zoom + panY - // Enhanced viewport culling with edge type considerations + // Enhanced viewport culling with proper X and Y axis bounds checking + // Only cull edges when BOTH endpoints are off-screen in the same direction + const edgeMargin = 100 if ( - sourceX < -100 || - sourceX > width + 100 || - targetX < -100 || - targetX > width + 100 + (sourceX < -edgeMargin && targetX < -edgeMargin) || + (sourceX > width + edgeMargin && targetX > width + edgeMargin) || + (sourceY < -edgeMargin && targetY < -edgeMargin) || + (sourceY > height + edgeMargin && targetY > height + edgeMargin) ) { return }