diff --git a/ui.go b/ui.go index 341b016..38fb4c3 100644 --- a/ui.go +++ b/ui.go @@ -105,7 +105,6 @@ type display struct { rowH int cellH int cellR int - axisY int labelX int nowX int nowW int @@ -186,7 +185,7 @@ func (d *display) layout(w, h int) error { // Rows stretch to spend the whole band between the column headers and the // footer, cells riding along at their design proportion of the row. rowsTop := d.headerH + colHdrH - d.rowH = (d.resetBtn.y - uiMargin - d.small.lineH - 8 - rowsTop) / len(panelRows) + d.rowH = (d.resetBtn.y - uiMargin - rowsTop) / len(panelRows) if d.rowH < rowHMin { return fmt.Errorf("rows would be %dpx tall, under the %dpx minimum", d.rowH, rowHMin) } @@ -199,7 +198,6 @@ func (d *display) layout(w, h int) error { d.rowYs[i] = y y += d.rowH } - d.axisY = y + 8 d.versionSpot = rect{w - versionSpotSide, 0, versionSpotSide, versionSpotSide} return nil } @@ -424,11 +422,6 @@ func (d *display) drawColHeaders() { d.hairline(d.rowYs[0] - 1) } -func (d *display) drawAxis() { - d.small.draw(d.fb, d.cellsX, d.axisY-d.small.capTop, "90s ago", uiMuted) - d.textRightAt(d.small, d.cellsX+d.cellsW, d.axisY, "now", uiMuted) -} - // One row of history cells: na for a slot with nothing believable (never // sampled, or spent inside a measure), otherwise judged by the row. func (d *display) heatRow(rowY int, hv histView, judge func(histSlot) rgb) { @@ -538,14 +531,24 @@ func snrInk(m float64) rgb { return uiInk } +// The magnitude letter belongs to the unit, not the figure — split G from B +// and "GB" reads as two things — so it takes the unit's colour. +func (d *display) qty(v uint64, unit string) []seg { + val, mag, ok := strings.Cut(scaleCount(v), " ") + if ok { + unit = " " + mag + unit + } + return []seg{{d.small, val, uiInk2}, {d.small, unit, uiMuted}} +} + // One fact per line, stacked beside the reset button: short lines can never // crowd it, whatever the values grow to. func (d *display) drawFooter(v view, elapsed time.Duration) { const gap = 6 lines := [][]seg{ {{d.small, scaleTime(elapsed), uiInk2}}, - {{d.small, scaleCount(v.rxFrames), uiInk2}, {d.small, " pkts", uiMuted}}, - {{d.small, scaleCount(v.rxBytes), uiInk2}, {d.small, "B", uiMuted}}, + d.qty(v.rxFrames, " pkts"), + d.qty(v.rxBytes, "B"), } total := len(lines)*d.small.lineH + (len(lines)-1)*gap y := d.resetBtn.y + (btnH-total)/2 @@ -564,7 +567,6 @@ func (d *display) render(v view, elapsed time.Duration, phy phyDisplay, d.hairline(d.headerH - 1) d.drawColHeaders() d.drawRows(v, phy, measuring, hv, target) - d.drawAxis() d.drawFooter(v, elapsed) d.drawResetButton() return fb.flush() diff --git a/ui_test.go b/ui_test.go index de5a22f..dd82e8e 100644 --- a/ui_test.go +++ b/ui_test.go @@ -40,5 +40,5 @@ func TestPanelFitsScreen(t *testing.T) { t.Errorf("rows end at %d, past the footer at %d", last, d.resetBtn.y) } t.Logf("cells %dpx wide, rows end at %d, footer at %d", - d.cellW, d.axisY+d.small.lineH, d.resetBtn.y) + d.cellW, d.rowYs[len(d.rowYs)-1]+d.rowH, d.resetBtn.y) }