From eeeea29171da62575630d20355d64bf9294092a1 Mon Sep 17 00:00:00 2001 From: qazal <77887910+Qazalin@users.noreply.github.com> Date: Sun, 17 Aug 2025 15:08:54 +0300 Subject: [PATCH] viz: device list refactor (#11700) * viz: device list refactor * paddingTop/padding-top --- tinygrad/viz/js/index.js | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/tinygrad/viz/js/index.js b/tinygrad/viz/js/index.js index 84e8a054f5..96c09f61a3 100644 --- a/tinygrad/viz/js/index.js +++ b/tinygrad/viz/js/index.js @@ -150,15 +150,13 @@ async function renderProfiler() { // layout once! if (data != null) return; const profiler = d3.select(".profiler").html(""); - const deviceList = profiler.append("div").attr("id", "device-list").node(); + const { layout, st, et } = await (await fetch("/get_profile")).json(); + // place devices on the y axis and set vertical positions + const [tickSize, padding] = [10, 8]; + const deviceList = profiler.append("div").attr("id", "device-list").style("padding-top", tickSize+padding+"px"); const canvas = profiler.append("canvas").attr("id", "timeline").node(); // NOTE: scrolling via mouse can only zoom the graph canvas.addEventListener("wheel", e => (e.stopPropagation(), e.preventDefault()), { passive:false }); - const profileRet = await (await fetch("/get_profile")).json() - const { layout, st, et } = profileRet; - // place devices on the y axis and set vertical positions - const [tickSize, padding] = [10, 8]; - deviceList.style.paddingTop = `${tickSize+padding}px`; const ctx = canvas.getContext("2d"); const canvasTop = rect(canvas).top; // color by key (name/category/device) @@ -167,9 +165,7 @@ async function renderProfiler() { const areaScale = d3.scaleLinear().domain([0, Object.entries(layout).reduce((peak, [_,d]) => Math.max(peak, d.mem.peak), 0)]).range([4,maxArea=100]); for (const [k, { timeline, mem }] of Object.entries(layout)) { if (timeline.shapes.length === 0 && mem.shapes.length == 0) continue; - const div = deviceList.appendChild(document.createElement("div")); - div.innerText = k; - div.style.padding = `${padding}px`; + const div = deviceList.append("div").attr("id", k).text(k).style("padding", padding+"px").node(); div.onclick = () => { // TODO: make this feature more visible const prevScroll = profiler.node().scrollTop; let newOffset = null;