summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-02-24 22:44:07 +0200
committerPaul Buetow <paul@buetow.org>2026-02-24 22:44:07 +0200
commit6a761bac0d866f2f3a3b224b603446630803e362 (patch)
tree83d6b16788d2494949480fed66b885bcd5e744a8 /internal
parentcf65e3f93e0565dda8f124b21b2c44b3a3ecaff5 (diff)
Make flamegraph SVG width responsive
Diffstat (limited to 'internal')
-rw-r--r--internal/flamegraph/svgwriter.go4
-rw-r--r--internal/flamegraph/svgwriter_test.go7
2 files changed, 7 insertions, 4 deletions
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, `<svg xmlns="http://www.w3.org/2000/svg" width="%d" height="%d" viewBox="0 0 %d %d">`+"\n",
- cfg.Width, height, cfg.Width, height)
+ _, err := fmt.Fprintf(bw, `<svg xmlns="http://www.w3.org/2000/svg" width="100%%" height="%d" viewBox="0 0 %d %d" preserveAspectRatio="xMinYMin meet">`+"\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)