summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-09 07:30:18 +0200
committerPaul Buetow <paul@buetow.org>2026-03-09 07:30:18 +0200
commite43701561ddd4da60bee5cddbdc974d6811f3b79 (patch)
tree1fa85ee96f4736d3961c33bc5711dc82fd765754
parent3479c445f81cd3df9f0eda097f5b7503388dfc5d (diff)
tui: use full width for zoomed flame bars
-rw-r--r--internal/tui/flamegraph/model.go52
-rw-r--r--internal/tui/flamegraph/model_test.go35
2 files changed, 15 insertions, 72 deletions
diff --git a/internal/tui/flamegraph/model.go b/internal/tui/flamegraph/model.go
index 6f5411b..c001e98 100644
--- a/internal/tui/flamegraph/model.go
+++ b/internal/tui/flamegraph/model.go
@@ -468,17 +468,7 @@ func (m *Model) rebuildFrames(animate bool) {
} else {
root = m.snapshot
}
- layoutWidth := m.width
- if m.zoomPath != "" {
- fallbackLineWidth := m.zoomLineWidth
- if fallbackLineWidth <= 0 {
- fallbackLineWidth = layoutWidth
- }
- if _, gutter, ok := m.zoomLineageGeometry(fallbackLineWidth); ok {
- layoutWidth = m.width - gutter
- }
- }
- targetFrames := buildTerminalLayoutWithPath(root, layoutWidth, m.height, rootPath)
+ targetFrames := buildTerminalLayoutWithPath(root, m.width, m.height, rootPath)
if m.zoomPath != "" {
targetFrames = m.withZoomLineage(targetFrames)
}
@@ -1151,28 +1141,6 @@ func (m Model) frameIndexAt(x, y int) int {
return best
}
-func (m Model) zoomLineageGeometry(fallbackLineWidth int) (lineWidth, gutter int, ok bool) {
- if m.zoomPath == "" || m.width <= 0 {
- return 0, 0, false
- }
- lineWidth = m.zoomLineWidth
- if lineWidth <= 0 {
- lineWidth = fallbackLineWidth
- }
- if lineWidth <= 0 {
- lineWidth = m.width / 4
- }
- lineWidth = min(max(lineWidth, 3), max(3, m.width/3))
- if lineWidth >= m.width-2 {
- return 0, 0, false
- }
- gutter = lineWidth + 1
- if m.width-gutter < minFlameWidth/2 {
- return 0, 0, false
- }
- return lineWidth, gutter, true
-}
-
func (m Model) withZoomLineage(frames []tuiFrame) []tuiFrame {
if len(frames) == 0 || m.snapshot == nil {
return frames
@@ -1182,26 +1150,12 @@ func (m Model) withZoomLineage(frames []tuiFrame) []tuiFrame {
return frames
}
- fallbackLineWidth := 0
- if len(frames) > 0 {
- fallbackLineWidth = frames[0].Width
- }
- _, gutter, ok := m.zoomLineageGeometry(fallbackLineWidth)
- if !ok {
- return frames
- }
- lineageWidth := m.width - gutter
- if lineageWidth < 1 {
- return frames
- }
-
rowShift := len(parts) - 1
out := make([]tuiFrame, 0, len(frames)+len(parts))
for _, frame := range frames {
if frame.Path == m.zoomPath {
continue
}
- frame.Col += gutter
frame.Row += rowShift
frame.Depth += rowShift
out = append(out, frame)
@@ -1222,9 +1176,9 @@ func (m Model) withZoomLineage(frames []tuiFrame) []tuiFrame {
name := parts[depth]
out = append(out, tuiFrame{
Name: name,
- Col: gutter,
+ Col: 0,
Row: depth,
- Width: lineageWidth,
+ Width: m.width,
Total: total,
Percent: percent,
Fill: terminalFrameColor(name),
diff --git a/internal/tui/flamegraph/model_test.go b/internal/tui/flamegraph/model_test.go
index d87ae54..69c1387 100644
--- a/internal/tui/flamegraph/model_test.go
+++ b/internal/tui/flamegraph/model_test.go
@@ -276,12 +276,10 @@ func TestMouseClickOutsideBarsDoesNotChangeSelectionOrZoom(t *testing.T) {
}
}
-func TestZoomLineageSpansZoomViewportAndAlignsAtGutter(t *testing.T) {
+func TestZoomLineageSpansFullViewportWidth(t *testing.T) {
m := newZoomModel()
targetPath := "root" + pathSeparator + "A"
targetIdx := mustFrameIndex(t, m.frames, targetPath)
- selectedWidth := m.frames[targetIdx].Width
- expectedRailWidth := min(max(selectedWidth, 3), max(3, m.width/3))
m.selectedIdx = targetIdx
m = pressFlameKey(t, m, tea.KeyPressMsg{Code: tea.KeyEnter})
@@ -289,19 +287,14 @@ func TestZoomLineageSpansZoomViewportAndAlignsAtGutter(t *testing.T) {
rootIdx := mustFrameIndex(t, m.frames, "root")
zoomIdx := mustFrameIndex(t, m.frames, targetPath)
- _, gutter, ok := m.zoomLineageGeometry(expectedRailWidth)
- if !ok {
- t.Fatalf("expected lineage geometry to be enabled for zoomed view")
- }
- expectedLineageWidth := m.width - gutter
- if m.frames[rootIdx].Width != expectedLineageWidth {
- t.Fatalf("expected root lineage width %d, got %d", expectedLineageWidth, m.frames[rootIdx].Width)
+ if m.frames[rootIdx].Width != m.width {
+ t.Fatalf("expected root lineage width %d, got %d", m.width, m.frames[rootIdx].Width)
}
- if m.frames[zoomIdx].Width != expectedLineageWidth {
- t.Fatalf("expected zoom lineage width %d, got %d", expectedLineageWidth, m.frames[zoomIdx].Width)
+ if m.frames[zoomIdx].Width != m.width {
+ t.Fatalf("expected zoom lineage width %d, got %d", m.width, m.frames[zoomIdx].Width)
}
- if m.frames[rootIdx].Col != gutter || m.frames[zoomIdx].Col != gutter {
- t.Fatalf("expected lineage rail at column %d, got root=%d zoom=%d", gutter, m.frames[rootIdx].Col, m.frames[zoomIdx].Col)
+ if m.frames[rootIdx].Col != 0 || m.frames[zoomIdx].Col != 0 {
+ t.Fatalf("expected full-width lineage bars at column 0, got root=%d zoom=%d", m.frames[rootIdx].Col, m.frames[zoomIdx].Col)
}
}
@@ -318,7 +311,7 @@ func TestZoomLineageKeepsAllFramesWithinViewportWidth(t *testing.T) {
}
}
-func TestZoomLineageAlignsWithZoomedSubtreeColumn(t *testing.T) {
+func TestZoomLineageDoesNotShiftZoomedSubtreeHorizontally(t *testing.T) {
m := newZoomModel()
rootPath := "root" + pathSeparator + "A"
childPath := rootPath + pathSeparator + "A1"
@@ -328,15 +321,11 @@ func TestZoomLineageAlignsWithZoomedSubtreeColumn(t *testing.T) {
rootIdx := mustFrameIndex(t, m.frames, rootPath)
childIdx := mustFrameIndex(t, m.frames, childPath)
- _, gutter, ok := m.zoomLineageGeometry(m.zoomLineWidth)
- if !ok {
- t.Fatalf("expected lineage geometry to be enabled")
- }
- if got := m.frames[rootIdx].Col; got != gutter {
- t.Fatalf("expected zoom lineage root column %d, got %d", gutter, got)
+ if got := m.frames[rootIdx].Col; got != 0 {
+ t.Fatalf("expected zoom lineage root column 0, got %d", got)
}
- if got := m.frames[childIdx].Col; got != gutter {
- t.Fatalf("expected first child column to align at %d, got %d", gutter, got)
+ if got := m.frames[childIdx].Col; got != 0 {
+ t.Fatalf("expected first child column to stay aligned at 0, got %d", got)
}
}