From 9bf032de6963f3a48d038d0186926b8bcc050a49 Mon Sep 17 00:00:00 2001 From: qazal <77887910+Qazalin@users.noreply.github.com> Date: Tue, 14 Oct 2025 10:49:08 +0800 Subject: [PATCH] viz: keep focused shape in view (#12648) --- tinygrad/viz/js/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tinygrad/viz/js/index.js b/tinygrad/viz/js/index.js index c5598fcd7f..29b4c824d6 100644 --- a/tinygrad/viz/js/index.js +++ b/tinygrad/viz/js/index.js @@ -174,7 +174,7 @@ function tabulate(rows) { var data, focusedDevice, focusedShape, canvasZoom, zoomLevel = d3.zoomIdentity; async function renderProfiler() { displayGraph("profiler"); - d3.select(".metadata").html(""); + d3.select(".metadata").node().replaceChildren(focusedShape?.html ?? ""); // layout once! if (data != null) return updateProgress({ start:false }); const profiler = d3.select(".profiler").html(""); @@ -352,7 +352,7 @@ async function renderProfiler() { for (let i=x.length-1; i>=0; i--) p.lineTo(x[i], offsetY+e.y1[i]); p.closePath(); ctx.fillStyle = e.fillColor; ctx.fill(p); - if (focusedShape && e.arg?.key === focusedShape) { paths.push(p); } + if (focusedShape && e.arg?.key === focusedShape.key) { paths.push(p); } continue; } // contiguous rect @@ -448,7 +448,7 @@ async function renderProfiler() { e.preventDefault(); const foundRect = findRectAtPosition(e.clientX, e.clientY); if (foundRect?.step != null) return setCtxWithHistory(foundRect.ctx, foundRect.step); - if (foundRect?.key != focusedShape) { focusedShape = foundRect?.key; render(zoomLevel); } + if (foundRect?.key != focusedShape?.key) { focusedShape = foundRect; render(zoomLevel); } return document.querySelector(".metadata").replaceChildren(foundRect?.html ?? ""); });