From 7c2c8d3905d8c7cc98be178c81ea3681e111b424 Mon Sep 17 00:00:00 2001 From: qazal <77887910+Qazalin@users.noreply.github.com> Date: Wed, 25 Mar 2026 20:18:25 +0200 Subject: [PATCH] viz: small ux improvements (#15483) * test * better * work --- tinygrad/viz/js/index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tinygrad/viz/js/index.js b/tinygrad/viz/js/index.js index 4209c95e8e..3295c8c47f 100644 --- a/tinygrad/viz/js/index.js +++ b/tinygrad/viz/js/index.js @@ -250,7 +250,7 @@ var data, focusedDevice, focusedShape, formatTime, canvasZoom, zoomLevel = d3.zo const canvasDims = () => { const sideRect = rect("#device-list"); - return [document.querySelector("#profiler").clientWidth-sideRect.width, Math.round(sideRect.height)]; + return [Math.round(document.querySelector("#profiler").clientWidth-sideRect.width), Math.round(sideRect.height)]; } function selectShape(key) { @@ -307,6 +307,8 @@ function setFocus(key) { const link = e?.arg.link ?? data.links.get(key); data.link = link == null ? null : [key, link]; focusedShape = key; d3.select("#timeline").call(canvasZoom.transform, zoomLevel); + const tooltip = document.getElementById("tooltip"); + if (tooltip.dataset.key !== key) tooltip.style.display = "none"; } const { eventType, e } = selectShape(key); if (metadata.querySelector(".info") == null) d3.select(metadata).html("").append("div").classed("info", true); @@ -601,7 +603,7 @@ async function renderProfiler(path, opts) { const canvasWidth = canvas.clientWidth; ctx.clearRect(0, 0, canvasWidth, canvas.clientHeight); // rescale to match current zoom - const xscale = d3.scaleLinear().domain([data.first, dur]).range([0, canvasWidth]); + const xscale = timelineScale(); const visibleX = xscale.range().map(zoomLevel.invertX, zoomLevel).map(xscale.invert, xscale); const st = visibleX[0], et = visibleX[1]; xscale.domain([st, et]); @@ -759,6 +761,7 @@ async function renderProfiler(path, opts) { tooltip.style.display = "block"; tooltip.style.left = (e.pageX+10)+"px"; tooltip.style.top = (e.pageY)+"px"; + tooltip.dataset.key = foundRect.key ?? ""; } else tooltip.style.display = "none"; }); canvas.addEventListener("mouseleave", () => document.getElementById("tooltip").style.display = "none");