From 09e060eab5b71f2cfbcb9cf61c6ca7ebfd38f3e1 Mon Sep 17 00:00:00 2001 From: qazal <77887910+Qazalin@users.noreply.github.com> Date: Sun, 21 Dec 2025 17:45:06 +0900 Subject: [PATCH] simplify viz node labels (#13784) --- tinygrad/viz/js/index.js | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/tinygrad/viz/js/index.js b/tinygrad/viz/js/index.js index 58bbcbb122..2c40dad0ec 100644 --- a/tinygrad/viz/js/index.js +++ b/tinygrad/viz/js/index.js @@ -76,23 +76,18 @@ const drawGraph = (data) => { .attr("x", d => -d.width/2).attr("y", d => -d.height/2); const STROKE_WIDTH = 1.4; const labels = nodes.selectAll("g.label").data(d => [d]).join("g").attr("class", "label"); - const hasLabelDims = data.nodes[0]?.value.labelWidth != null; - if (hasLabelDims) labels.attr("transform", d => `translate(-${d.labelWidth/2}, -${d.labelHeight/2+STROKE_WIDTH*2})`); + labels.attr("transform", d => `translate(-${d.labelWidth/2}, -${d.labelHeight/2+STROKE_WIDTH*2})`); labels.selectAll("text").data(d => { const ret = [[]]; - for (const { st, color } of parseColors(d.label, defaultColor="initial")) { - const lines = st.split("\n"); + for (const s of parseColors(d.label, defaultColor="initial")) { + const color = darkenHex(s.color, 25); + const lines = s.st.split("\n"); ret.at(-1).push({ st:lines[0], color }); for (let i=1; i d).join("tspan").attr("x", "0").attr("dy", 14).selectAll("tspan").data(d => d).join("tspan") - .attr("fill", d => darkenHex(d.color, 25)).text(d => d.st).attr("xml:space", "preserve"); - // recenter after drawing texts if needed - if (!hasLabelDims) labels.attr("transform", (_,i,els) => { - const b = els[i].getBBox(); - return `translate(${-b.x-b.width/2}, ${-b.y-b.height/2})` - }); + .attr("fill", d => d.color).text(d => d.st).attr("xml:space", "preserve"); addTags(nodes.selectAll("g.tag").data(d => d.tag != null ? [d] : []).join("g").attr("class", "tag") .attr("transform", d => `translate(${-d.width/2+8}, ${-d.height/2+8})`).datum(e => e.tag)); // draw edges