summaryrefslogtreecommitdiff
path: root/internal/flamegraph/svgwriter.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-02-24 21:15:20 +0200
committerPaul Buetow <paul@buetow.org>2026-02-24 21:15:20 +0200
commit93d587a6f5ae453907de3d5556866b60bac405cb (patch)
treee177a5758b486e75fc66552fb0874b95bb145726 /internal/flamegraph/svgwriter.go
parent8361fd22d45e4fbf6b24309aaa1b6d49d9010759 (diff)
flamegraph: improve interactive zoom and serve svg over embedded http
Diffstat (limited to 'internal/flamegraph/svgwriter.go')
-rw-r--r--internal/flamegraph/svgwriter.go16
1 files changed, 10 insertions, 6 deletions
diff --git a/internal/flamegraph/svgwriter.go b/internal/flamegraph/svgwriter.go
index 26e203e..5ab8e50 100644
--- a/internal/flamegraph/svgwriter.go
+++ b/internal/flamegraph/svgwriter.go
@@ -68,7 +68,7 @@ func writeSVGHeader(bw *bufio.Writer, cfg SVGConfig, height int) error {
if err != nil {
return err
}
- _, err = fmt.Fprintf(bw, `<g class="controls"><text x="10" y="42" onclick="fgSearch()">Search</text><text x="80" y="42" onclick="fgResetSearch()">Reset Search</text><text x="190" y="42" onclick="fgResetZoom()">Reset Zoom</text><text id="fg-info" x="320" y="42"></text></g>`+"\n")
+ _, err = fmt.Fprintf(bw, `<g class="controls"><text x="10" y="42" onclick="fgSearch()">Search</text><text x="80" y="42" onclick="fgResetSearch()">Reset Search</text><text x="190" y="42" onclick="fgUndoZoom()">Undo Zoom</text><text x="280" y="42" onclick="fgResetZoom()">Reset Zoom</text><text id="fg-info" x="390" y="42"></text></g>`+"\n")
return err
}
@@ -113,11 +113,14 @@ func writeFrame(bw *bufio.Writer, name, title, fill string, x, y, w, h float64,
svgEscape(title), x, y, w, h, fill); err != nil {
return err
}
- if w > float64(fontSize*2) {
- _, err = fmt.Fprintf(bw, `<text x="%.3f" y="%.3f">%s</text>`+"\n", x+3, y+float64(fontSize), svgEscape(name))
- if err != nil {
- return err
- }
+ labelStyle := ""
+ if w <= float64(fontSize*2) {
+ labelStyle = ` style="display:none"`
+ }
+ _, err = fmt.Fprintf(bw, `<text x="%.3f" y="%.3f"%s>%s</text>`+"\n",
+ x+3, y+float64(fontSize), labelStyle, svgEscape(name))
+ if err != nil {
+ return err
}
_, err = fmt.Fprintln(bw, "</g>")
return err
@@ -139,6 +142,7 @@ func flamegraphCSS(cfg SVGConfig) string {
.controls text { font-size: %dpx; font-family: monospace; cursor: pointer; fill: #444; }
.frame text { font-size: %dpx; font-family: monospace; pointer-events: none; fill: #111; }
.frame rect { stroke: rgba(0,0,0,0.18); stroke-width: 0.5; }
+.title, .controls text, .frame text { user-select: none; -webkit-user-select: none; }
`, cfg.FontSize+2, cfg.FontSize, cfg.FontSize-1)
}