Skip to content

#1 Persistent memory for AI coding agents based on real-world benchmarks

ui(viewer): update graph interface with grid, zoom, and glow effects

tanmaishi3652276448c8
diff --git a/src/viewer/index.html b/src/viewer/index.html
index c09233ee..bd948189 100644
--- a/src/viewer/index.html
+++ b/src/viewer/index.html
@@ -693,12 +693,16 @@
.graph-legend { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border-light); }
.graph-legend-item { display: flex; align-items: center; gap: 6px; padding: 3px 0; font-size: 11px; font-family: var(--font-ui); color: var(--ink-muted); }
.graph-legend-shape { width: 16px; height: 16px; display: flex; align-items: center; justify-content: center; }
- .graph-tooltip { position: absolute; background: var(--bg); border: 1px solid var(--border); padding: 8px 12px; font-size: 11px; font-family: var(--font-ui); pointer-events: none; z-index: 10; box-shadow: 3px 3px 0px 0px var(--border); max-width: 240px; display: none; }
- .graph-tooltip.visible { display: block; }
- .graph-tooltip .tt-name { font-weight: 700; color: var(--ink); margin-bottom: 2px; font-family: var(--font-display); }
- .graph-tooltip .tt-type { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 4px; }
- .graph-tooltip .tt-prop { font-size: 10px; color: var(--ink-muted); }
- .graph-tooltip .tt-conns { font-size: 10px; color: var(--ink-faint); margin-top: 4px; border-top: 1px solid var(--border-light); padding-top: 4px; }
+ .graph-tooltip { position: absolute; background: rgba(255,255,255,0.88); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border: 1px solid rgba(17,17,17,0.08); padding: 12px 16px; font-size: 11px; font-family: var(--font-ui); pointer-events: none; z-index: 10; box-shadow: 0 8px 32px rgba(0,0,0,0.12), 0 2px 8px rgba(0,0,0,0.06); max-width: 260px; display: none; border-radius: 8px; transition: opacity 0.15s ease; }
+ .graph-tooltip.visible { display: block; opacity: 1; }
+ .graph-tooltip .tt-name { font-weight: 700; color: var(--ink); margin-bottom: 4px; font-family: var(--font-display); font-size: 13px; }
+ .graph-tooltip .tt-type { font-size: 9px; text-transform: uppercase; letter-spacing: 0.1em; margin-bottom: 6px; font-weight: 600; padding: 2px 6px; border-radius: 3px; display: inline-block; }
+ .graph-tooltip .tt-prop { font-size: 10px; color: var(--ink-muted); padding: 1px 0; }
+ .graph-tooltip .tt-conns { font-size: 10px; color: var(--ink-faint); margin-top: 6px; border-top: 1px solid rgba(17,17,17,0.08); padding-top: 6px; font-family: var(--font-mono); }
+ .graph-controls { position: absolute; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: 2px; z-index: 5; }
+ .graph-controls button { width: 36px; height: 36px; font-size: 18px; cursor: pointer; background: rgba(255,255,255,0.92); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); border: 1px solid rgba(17,17,17,0.1); color: var(--ink); display: flex; align-items: center; justify-content: center; font-weight: 500; font-family: var(--font-ui); border-radius: 6px; transition: all 0.15s ease; box-shadow: 0 2px 8px rgba(0,0,0,0.06); }
+ .graph-controls button:hover { background: var(--ink); color: var(--bg); transform: scale(1.05); box-shadow: 0 4px 12px rgba(0,0,0,0.15); }
+ .graph-controls .ctrl-divider { height: 1px; background: var(--border-light); margin: 2px 4px; }
.type-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.type-chip { font-size: 10px; padding: 3px 10px; border: 1px solid var(--border-light); cursor: pointer; font-family: var(--font-ui); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; transition: all 0.15s; background: var(--bg); }
@@ -1181,7 +1185,7 @@
async function loadGraph() {
var el = document.getElementById('view-graph');
- el.innerHTML = '<div class="graph-container"><div class="graph-canvas-wrap"><canvas id="graph-canvas"></canvas><div class="graph-tooltip" id="graph-tooltip"></div></div><div class="graph-sidebar" id="graph-sidebar"></div></div>';
+ el.innerHTML = '<div class="graph-container"><div class="graph-canvas-wrap"><canvas id="graph-canvas"></canvas><div class="graph-controls"><button title="Zoom In" onclick="zoomGraph(1)">+</button><button title="Zoom Out" onclick="zoomGraph(-1)">&minus;</button><div class="ctrl-divider"></div><button title="Recenter" onclick="recenterGraph()">⌖</button></div><div class="graph-tooltip" id="graph-tooltip"></div></div><div class="graph-sidebar" id="graph-sidebar"></div></div>';
var results = await Promise.all([
apiPost('graph/query', {}),
@@ -1232,13 +1236,14 @@
var html = '<input type="text" class="graph-search" id="graph-search" placeholder="Search nodes...">';
- html += '<h3>Graph Stats</h3>';
- html += '<div style="display:flex;gap:16px;margin-bottom:12px;">';
- html += '<div><span style="font-size:24px;font-weight:900;font-family:var(--font-display);color:var(--ink);">' + nodeCount + '</span><div style="font-size:9px;color:var(--ink-muted);text-transform:uppercase;letter-spacing:0.1em;font-family:var(--font-ui);font-weight:600;">Nodes</div></div>';
- html += '<div><span style="font-size:24px;font-weight:900;font-family:var(--font-display);color:var(--ink);">' + edgeCount + '</span><div style="font-size:9px;color:var(--ink-muted);text-transform:uppercase;letter-spacing:0.1em;font-family:var(--font-ui);font-weight:600;">Edges</div></div>';
+ html += '<h3 style="margin-top:16px;font-size:10px;text-transform:uppercase;letter-spacing:0.12em;color:var(--ink-muted);font-family:var(--font-ui);font-weight:700;">Graph Stats</h3>';
+ html += '<div style="display:flex;gap:20px;margin:10px 0 16px;padding:12px;background:var(--bg-alt);border:1px solid var(--border-light);border-radius:4px;">';
+ html += '<div style="text-align:center;flex:1;"><span style="font-size:28px;font-weight:900;font-family:var(--font-display);color:var(--ink);line-height:1;">' + nodeCount + '</span><div style="font-size:8px;color:var(--ink-faint);text-transform:uppercase;letter-spacing:0.12em;font-family:var(--font-ui);font-weight:600;margin-top:4px;">Nodes</div></div>';
+ html += '<div style="width:1px;background:var(--border-light);"></div>';
+ html += '<div style="text-align:center;flex:1;"><span style="font-size:28px;font-weight:900;font-family:var(--font-display);color:var(--ink);line-height:1;">' + edgeCount + '</span><div style="font-size:8px;color:var(--ink-faint);text-transform:uppercase;letter-spacing:0.12em;font-family:var(--font-ui);font-weight:600;margin-top:4px;">Edges</div></div>';
html += '</div>';
- html += '<h3 style="margin-top:16px;">Filter by Type</h3>';
+ html += '<h3 style="margin-top:12px;font-size:10px;text-transform:uppercase;letter-spacing:0.12em;color:var(--ink-muted);font-family:var(--font-ui);font-weight:700;">Filter by Type</h3>';
Object.keys(state.graph.filters).forEach(function(type) {
var color = NODE_COLORS[type] || '#666666';
html += '<label class="filter-item"><input type="checkbox" checked data-type="' + esc(type) + '"><span class="filter-dot" style="background:' + color + '"></span>' + esc(type) + '</label>';
@@ -1257,7 +1262,7 @@
});
html += '</div>';
- html += '<button class="btn" style="margin-top:14px;width:100%;" onclick="rebuildGraph()">Rebuild Graph</button>';
+ html += '<button class="btn" style="margin-top:14px;width:100%;font-size:11px;padding:8px;letter-spacing:0.06em;transition:all 0.15s ease;" onclick="rebuildGraph()" onmouseover="this.style.background=\'var(--ink)\';this.style.color=\'var(--bg)\'" onmouseout="this.style.background=\'\';this.style.color=\'\'">↻ Rebuild Graph</button>';
html += '<div id="selected-node-panel"></div>';
sb.innerHTML = html;
@@ -1314,7 +1319,7 @@
x: Math.cos(angle) * radius + (Math.random() - 0.5) * 50,
y: Math.sin(angle) * radius + (Math.random() - 0.5) * 50,
vx: 0, vy: 0,
- r: Math.max(6, Math.min(20, 6 + deg * 2))
+ r: Math.max(8, Math.min(22, 8 + deg * 2.5))
};
});
graphSim.edges = state.graph.edges.slice();
@@ -1413,8 +1418,30 @@
var factor = e.deltaY > 0 ? 0.9 : 1.1;
graphSim.zoom = Math.max(0.1, Math.min(5, graphSim.zoom * factor));
}, { passive: false });
+ canvas.addEventListener('dblclick', function(e) {
+ var c = canvasCoords(e);
+ var node = findNode(c.x, c.y);
+ if (node) {
+ selectGraphNode(node);
+ expandNode(node.id);
+ }
+ });
}
+ window.zoomGraph = function(dir) {
+ var factor = dir > 0 ? 1.25 : 0.8;
+ graphSim.zoom = Math.max(0.1, Math.min(5, graphSim.zoom * factor));
+ };
+ window.recenterGraph = function() {
+ graphSim.zoom = 1;
+ if (graphSim.canvas) {
+ var cw = graphSim.canvas.width / window.devicePixelRatio;
+ var ch = graphSim.canvas.height / window.devicePixelRatio;
+ graphSim.panX = cw / 2;
+ graphSim.panY = ch / 2;
+ }
+ };
+
function selectGraphNode(simNode) {
state.graph.selectedNode = simNode;
var panel = document.getElementById('selected-node-panel');
@@ -1573,6 +1600,20 @@
var h = canvas.height / window.devicePixelRatio;
ctx.clearRect(0, 0, w, h);
+
+ // --- Canvas grid background ---
+ var gridSize = 24;
+ ctx.save();
+ ctx.strokeStyle = 'rgba(0,0,0,0.04)';
+ ctx.lineWidth = 0.5;
+ for (var gx = 0; gx < w; gx += gridSize) {
+ ctx.beginPath(); ctx.moveTo(gx, 0); ctx.lineTo(gx, h); ctx.stroke();
+ }
+ for (var gy = 0; gy < h; gy += gridSize) {
+ ctx.beginPath(); ctx.moveTo(0, gy); ctx.lineTo(w, gy); ctx.stroke();
+ }
+ ctx.restore();
+
ctx.save();
ctx.translate(graphSim.panX, graphSim.panY);
ctx.scale(graphSim.zoom, graphSim.zoom);
@@ -1587,6 +1628,22 @@
var edgeLabelZoomThreshold = isDense ? 2.5 : 1.2;
var selectedId = state.graph.selectedNode ? state.graph.selectedNode.id : null;
+ // --- Hover node detection for focus effect ---
+ var hoverNodeId = null;
+ if (!graphSim.dragNode && graphSim.canvas) {
+ var rect = graphSim.canvas.getBoundingClientRect();
+ var hx = (graphSim.mouseX - rect.left - graphSim.panX) / graphSim.zoom;
+ var hy = (graphSim.mouseY - rect.top - graphSim.panY) / graphSim.zoom;
+ for (var hi = graphSim.nodes.length - 1; hi >= 0; hi--) {
+ var hn = graphSim.nodes[hi];
+ if (!state.graph.filters[hn.type]) continue;
+ var hdx = hn.x - hx, hdy = hn.y - hy;
+ if (hdx * hdx + hdy * hdy < hn.r * hn.r + 25) { hoverNodeId = hn.id; break; }
+ }
+ }
+ var focusNodeId = selectedId || hoverNodeId;
+
+ // --- Draw edges ---
graphSim.edges.forEach(function(e) {
var s = nodeMap[e.sourceNodeId];
var t = nodeMap[e.targetNodeId];
@@ -1594,9 +1651,10 @@
if (!state.graph.filters[s.type] || !state.graph.filters[t.type]) return;
var edgeDimmed = searchActive && !(s.name.toLowerCase().includes(graphSearchTerm) || t.name.toLowerCase().includes(graphSearchTerm));
- var isSelectedEdge = selectedId && (e.sourceNodeId === selectedId || e.targetNodeId === selectedId);
+ var isConnectedToFocus = focusNodeId && (e.sourceNodeId === focusNodeId || e.targetNodeId === focusNodeId);
+ var isFocusActive = focusNodeId !== null;
var weight = typeof e.weight === 'number' ? e.weight : 0.5;
- var lineWidth = isSelectedEdge ? 2 + weight * 2 : 1 + weight * 1.5;
+ var lineWidth = isConnectedToFocus ? 2 + weight * 2 : 1 + weight * 1.5;
var dx = t.x - s.x;
var dy = t.y - s.y;
@@ -1607,15 +1665,31 @@
var cpx = (s.x + t.x) / 2 + offsetX;
var cpy = (s.y + t.y) / 2 + offsetY;
+ // Colored edges based on source node type
+ var edgeColor = NODE_COLORS[s.type] || '#666666';
+ var edgeAlpha;
+ if (edgeDimmed) {
+ edgeAlpha = 0.06;
+ } else if (isFocusActive && isConnectedToFocus) {
+ edgeAlpha = 0.65;
+ } else if (isFocusActive && !isConnectedToFocus) {
+ edgeAlpha = 0.06;
+ } else {
+ edgeAlpha = isDense ? 0.15 : 0.25;
+ }
+
ctx.beginPath();
ctx.moveTo(s.x, s.y);
ctx.quadraticCurveTo(cpx, cpy, t.x, t.y);
- var edgeAlpha = edgeDimmed ? 0.08 : isSelectedEdge ? 0.5 : (isDense ? 0.1 : 0.2);
- ctx.strokeStyle = 'rgba(17,17,17,' + edgeAlpha + ')';
+ // Parse hex color to rgba
+ var r = parseInt(edgeColor.slice(1,3), 16);
+ var g = parseInt(edgeColor.slice(3,5), 16);
+ var b = parseInt(edgeColor.slice(5,7), 16);
+ ctx.strokeStyle = 'rgba(' + r + ',' + g + ',' + b + ',' + edgeAlpha + ')';
ctx.lineWidth = lineWidth;
ctx.stroke();
- if (!isDense || isSelectedEdge) {
+ if (!isDense || isConnectedToFocus) {
var arrowAngle = Math.atan2(t.y - cpy, t.x - cpx);
var arrowLen = 5 + lineWidth;
ctx.beginPath();
@@ -1623,44 +1697,71 @@
ctx.lineTo(t.x - (t.r + arrowLen) * Math.cos(arrowAngle - 0.3), t.y - (t.r + arrowLen) * Math.sin(arrowAngle - 0.3));
ctx.lineTo(t.x - (t.r + arrowLen) * Math.cos(arrowAngle + 0.3), t.y - (t.r + arrowLen) * Math.sin(arrowAngle + 0.3));
ctx.closePath();
- ctx.fillStyle = 'rgba(17,17,17,' + (edgeDimmed ? 0.08 : isSelectedEdge ? 0.5 : 0.25) + ')';
+ ctx.fillStyle = 'rgba(' + r + ',' + g + ',' + b + ',' + (edgeDimmed ? 0.06 : isConnectedToFocus ? 0.6 : 0.2) + ')';
ctx.fill();
}
- var showEdgeLabel = e.type && !edgeDimmed && (isSelectedEdge ? graphSim.zoom > 0.6 : graphSim.zoom > edgeLabelZoomThreshold);
+ var showEdgeLabel = e.type && !edgeDimmed && (isConnectedToFocus ? graphSim.zoom > 0.6 : graphSim.zoom > edgeLabelZoomThreshold);
if (showEdgeLabel) {
+ var zoomInv = 1 / graphSim.zoom;
ctx.save();
- ctx.fillStyle = 'rgba(80,80,80,0.8)';
- ctx.font = Math.round(7 / Math.max(graphSim.zoom, 0.8)) + 'px Inter, sans-serif';
+ ctx.fillStyle = isConnectedToFocus ? 'rgba(17,17,17,0.85)' : 'rgba(80,80,80,0.7)';
+ ctx.font = (isConnectedToFocus ? '600 ' : '500 ') + (11 * zoomInv).toFixed(1) + 'px Inter, sans-serif';
ctx.textAlign = 'center';
- ctx.fillText(e.type, cpx, cpy - 4);
+ ctx.fillText(e.type, cpx, cpy - (4 * zoomInv));
ctx.restore();
}
});
+ // --- Draw nodes ---
graphSim.nodes.forEach(function(n) {
if (!state.graph.filters[n.type]) return;
var color = NODE_COLORS[n.type] || '#666666';
var isSelected = selectedId === n.id;
+ var isHovered = hoverNodeId === n.id;
var matchesSearch = !searchActive || n.name.toLowerCase().includes(graphSearchTerm);
+ var isFocusFaded = focusNodeId && n.id !== focusNodeId && !graphSim.edges.some(function(ed) {
+ return (ed.sourceNodeId === focusNodeId && ed.targetNodeId === n.id) ||
+ (ed.targetNodeId === focusNodeId && ed.sourceNodeId === n.id);
+ });
+
+ var nodeAlpha = !matchesSearch ? 0.12 : (isFocusFaded ? 0.2 : 1);
ctx.save();
- if (matchesSearch && (isSelected || !searchActive)) {
+ ctx.globalAlpha = nodeAlpha;
+
+ // Glow effect
+ if (matchesSearch && !isFocusFaded && (isSelected || isHovered || !searchActive)) {
ctx.shadowColor = color;
- ctx.shadowBlur = isSelected ? 14 : (isDense ? 3 : 6);
+ ctx.shadowBlur = isSelected ? 20 : isHovered ? 16 : (isDense ? 4 : 8);
}
+ // Gradient fill
drawNodeShape(ctx, n.x, n.y, n.r, n.type);
- ctx.fillStyle = color;
- ctx.globalAlpha = matchesSearch ? 0.9 : 0.15;
+ var grad = ctx.createRadialGradient(n.x - n.r * 0.3, n.y - n.r * 0.3, 0, n.x, n.y, n.r * 1.2);
+ var cr = parseInt(color.slice(1,3), 16);
+ var cg = parseInt(color.slice(3,5), 16);
+ var cb = parseInt(color.slice(5,7), 16);
+ grad.addColorStop(0, 'rgba(' + Math.min(255, cr + 60) + ',' + Math.min(255, cg + 60) + ',' + Math.min(255, cb + 60) + ',0.95)');
+ grad.addColorStop(1, color);
+ ctx.fillStyle = grad;
ctx.fill();
- ctx.globalAlpha = 1;
ctx.restore();
+ // Selected ring
if (isSelected) {
- drawNodeShape(ctx, n.x, n.y, n.r, n.type);
- ctx.strokeStyle = '#111111';
- ctx.lineWidth = 2.5;
+ ctx.save();
+ drawNodeShape(ctx, n.x, n.y, n.r + 3, n.type);
+ ctx.strokeStyle = color;
+ ctx.lineWidth = 3;
+ ctx.shadowColor = color;
+ ctx.shadowBlur = 12;
+ ctx.stroke();
+ ctx.restore();
+ } else if (isHovered) {
+ drawNodeShape(ctx, n.x, n.y, n.r + 2, n.type);
+ ctx.strokeStyle = color;
+ ctx.lineWidth = 2;
ctx.stroke();
} else if (searchActive && matchesSearch) {
drawNodeShape(ctx, n.x, n.y, n.r, n.type);
@@ -1669,17 +1770,37 @@
ctx.stroke();
}
- var showLabel = matchesSearch && (
- isSelected ||
+ var showLabel = matchesSearch && !isFocusFaded && (
+ isSelected || isHovered ||
(searchActive && matchesSearch) ||
(!isDense && graphSim.zoom > labelZoomThreshold) ||
(isDense && graphSim.zoom > labelZoomThreshold && n.r > 10)
);
if (showLabel) {
- ctx.fillStyle = isSelected ? '#111111' : '#444444';
- ctx.font = (isSelected ? 'bold ' : '') + Math.round(9 / Math.max(graphSim.zoom, 0.6)) + 'px Inter, sans-serif';
+ var zoomInv = 1 / graphSim.zoom;
+ ctx.save();
+ ctx.font = (isSelected || isHovered ? '600 ' : '500 ') + (13 * zoomInv).toFixed(1) + 'px Inter, sans-serif';
ctx.textAlign = 'center';
- ctx.fillText(truncate(n.name, 16), n.x, n.y + n.r + 12);
+
+ var label = truncate(n.name, 18);
+ var textW = ctx.measureText(label).width;
+ var labelW = textW + (16 * zoomInv);
+ var labelH = 20 * zoomInv;
+ var labelY = n.y + n.r + (8 * zoomInv); // Top of the background pill
+
+ ctx.fillStyle = 'rgba(255,255,255,0.92)';
+ ctx.beginPath();
+ ctx.roundRect ? ctx.roundRect(n.x - labelW / 2, labelY, labelW, labelH, 4 * zoomInv) : ctx.rect(n.x - labelW / 2, labelY, labelW, labelH);
+ ctx.fill();
+
+ ctx.strokeStyle = 'rgba(0,0,0,0.08)';
+ ctx.lineWidth = 1 * zoomInv;
+ ctx.stroke();
+
+ ctx.fillStyle = isSelected || isHovered ? '#111111' : '#444444';
+ // Vertically center text in the pill box
+ ctx.fillText(label, n.x, labelY + (14 * zoomInv));
+ ctx.restore();
}
});