From 6a761bac0d866f2f3a3b224b603446630803e362 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Tue, 24 Feb 2026 22:44:07 +0200 Subject: Make flamegraph SVG width responsive --- internal/flamegraph/svgwriter.go | 4 ++-- internal/flamegraph/svgwriter_test.go | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'internal/flamegraph') diff --git a/internal/flamegraph/svgwriter.go b/internal/flamegraph/svgwriter.go index b68f6d8..a2bc3ed 100644 --- a/internal/flamegraph/svgwriter.go +++ b/internal/flamegraph/svgwriter.go @@ -67,8 +67,8 @@ func WriteSVG(w io.Writer, t *trie, cfg SVGConfig) error { } func writeSVGHeader(bw *bufio.Writer, cfg SVGConfig, height int) error { - _, err := fmt.Fprintf(bw, ``+"\n", - cfg.Width, height, cfg.Width, height) + _, err := fmt.Fprintf(bw, ``+"\n", + height, cfg.Width, height) if err != nil { return err } diff --git a/internal/flamegraph/svgwriter_test.go b/internal/flamegraph/svgwriter_test.go index 6fdbe3d..56f2c20 100644 --- a/internal/flamegraph/svgwriter_test.go +++ b/internal/flamegraph/svgwriter_test.go @@ -100,8 +100,11 @@ func TestWriteSVGInvalidConfigFallsBack(t *testing.T) { cfg := SVGConfig{Title: "x", Width: 0, FrameHeight: 0, FontSize: 0, MinWidthPx: 0} svg := renderSVGForTest(t, tr, cfg) - if !strings.Contains(svg, `width="1200"`) { - t.Fatalf("expected fallback width, got: %s", svg) + if !strings.Contains(svg, `width="100%"`) { + t.Fatalf("expected responsive svg width, got: %s", svg) + } + if !strings.Contains(svg, `viewBox="0 0 1200 `) { + t.Fatalf("expected fallback viewBox width, got: %s", svg) } if !strings.Contains(svg, "I/O Flame Graph") { t.Fatalf("expected fallback title, got: %s", svg) -- cgit v1.2.3