summaryrefslogtreecommitdiff
path: root/internal/tui/dashboard/overview.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-02-26 22:14:49 +0200
committerPaul Buetow <paul@buetow.org>2026-02-26 22:14:49 +0200
commita5f53e8f5c90956f0aaed13aa79fc5ccb1d6bc15 (patch)
tree8b88dbb3b6a243b90c88882e4f4d2bc6f046657b /internal/tui/dashboard/overview.go
parentda547fb7a1654220a40d0b1dbed30d51b26bf485 (diff)
tui: align overview sparkline columns
Diffstat (limited to 'internal/tui/dashboard/overview.go')
-rw-r--r--internal/tui/dashboard/overview.go41
1 files changed, 38 insertions, 3 deletions
diff --git a/internal/tui/dashboard/overview.go b/internal/tui/dashboard/overview.go
index 990e36d..5b8fab8 100644
--- a/internal/tui/dashboard/overview.go
+++ b/internal/tui/dashboard/overview.go
@@ -34,9 +34,10 @@ func renderOverview(snap *statsengine.Snapshot, width, height int) string {
)
panelInner := panelInnerWidth(width)
- latencySpark := renderOverviewSparkline("Latency:", snap.LatencySeriesNs(), panelInner)
- gapSpark := renderOverviewSparkline("Gap:", snap.GapSeriesNs(), panelInner)
- throughputSpark := renderOverviewSparkline("Throughput:", snap.ThroughputSeriesB(), panelInner)
+ labelWidth := maxLabelWidth("Latency:", "Gap:", "Throughput:")
+ latencySpark := renderOverviewSparklineAligned("Latency:", snap.LatencySeriesNs(), panelInner, labelWidth)
+ gapSpark := renderOverviewSparklineAligned("Gap:", snap.GapSeriesNs(), panelInner, labelWidth)
+ throughputSpark := renderOverviewSparklineAligned("Throughput:", snap.ThroughputSeriesB(), panelInner, labelWidth)
topSyscalls := "Top syscalls: " + summarizeTopSyscalls(snap)
topFiles := "Top files: " + summarizeTopFiles(snap)
topProcesses := "Top processes: " + summarizeTopProcesses(snap)
@@ -221,12 +222,46 @@ func summaryBoxInnerWidth(width int) int {
func renderOverviewSparkline(label string, data []float64, panelInner int) string {
w := panelInner - utf8.RuneCountInString(label) - 1 - sparklineSafetyMargin
+ if w > sparklineMaxWidth {
+ w = sparklineMaxWidth
+ }
if w < 8 {
w = 8
}
return renderLabeledSparkline(label, data, w)
}
+func renderOverviewSparklineAligned(label string, data []float64, panelInner int, labelWidth int) string {
+ paddedLabel := padLabelRight(label, labelWidth)
+ w := panelInner - labelWidth - 1 - sparklineSafetyMargin
+ if w > sparklineMaxWidth {
+ w = sparklineMaxWidth
+ }
+ if w < 8 {
+ w = 8
+ }
+ return renderLabeledSparkline(paddedLabel, data, w)
+}
+
+func maxLabelWidth(labels ...string) int {
+ max := 0
+ for _, label := range labels {
+ w := utf8.RuneCountInString(label)
+ if w > max {
+ max = w
+ }
+ }
+ return max
+}
+
+func padLabelRight(label string, width int) string {
+ pad := width - utf8.RuneCountInString(label)
+ if pad <= 0 {
+ return label
+ }
+ return label + strings.Repeat(" ", pad)
+}
+
func panelInnerWidth(width int) int {
if width <= 0 {
width = 80