Panel cleanup: chip padding up a step and a tighter chip line gap, corrected/SNR numbers neutral until amber or red, dB margin casing, compound elapsed units (1m39s) ending the minutes/metres m collision, noise chip shows presence only
This commit is contained in:
@@ -101,15 +101,16 @@ func scaleCount(v uint64) string {
|
|||||||
|
|
||||||
// The same shape for time, whose magnitudes are sixties and twenty-fours.
|
// The same shape for time, whose magnitudes are sixties and twenty-fours.
|
||||||
func scaleTime(d time.Duration) string {
|
func scaleTime(d time.Duration) string {
|
||||||
|
s := int(d.Seconds())
|
||||||
switch {
|
switch {
|
||||||
case d < time.Minute:
|
case d < time.Minute:
|
||||||
return fmt.Sprintf("%.2f s", d.Seconds())
|
return fmt.Sprintf("%ds", s)
|
||||||
case d < time.Hour:
|
case d < time.Hour:
|
||||||
return fmt.Sprintf("%.2f m", d.Minutes())
|
return fmt.Sprintf("%dm%02ds", s/60, s%60)
|
||||||
case d < 24*time.Hour:
|
case d < 24*time.Hour:
|
||||||
return fmt.Sprintf("%.2f h", d.Hours())
|
return fmt.Sprintf("%dh%02dm", s/3600, (s/60)%60)
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("%.2f d", d.Hours()/24)
|
return fmt.Sprintf("%dd%02dh", s/86400, (s/3600)%24)
|
||||||
}
|
}
|
||||||
|
|
||||||
type colSpec struct {
|
type colSpec struct {
|
||||||
@@ -282,7 +283,7 @@ func snrCell(phy phyDisplay) string {
|
|||||||
s := fmt.Sprintf("%+.1f", phy.worstMargin)
|
s := fmt.Sprintf("%+.1f", phy.worstMargin)
|
||||||
switch snrClass(phy.worstMargin) {
|
switch snrClass(phy.worstMargin) {
|
||||||
case clsGood:
|
case clsGood:
|
||||||
return paint(s, cGreen)
|
return s
|
||||||
case clsWarn:
|
case clsWarn:
|
||||||
return paint(s, cYellow)
|
return paint(s, cYellow)
|
||||||
default:
|
default:
|
||||||
@@ -292,7 +293,7 @@ func snrCell(phy phyDisplay) string {
|
|||||||
|
|
||||||
func correctedCell(v uint64) string {
|
func correctedCell(v uint64) string {
|
||||||
if v == 0 {
|
if v == 0 {
|
||||||
return paint("0", cGreen)
|
return "0"
|
||||||
}
|
}
|
||||||
return paint(commas(v), cYellow)
|
return paint(commas(v), cYellow)
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -45,10 +45,10 @@ func TestScaleTime(t *testing.T) {
|
|||||||
in time.Duration
|
in time.Duration
|
||||||
want string
|
want string
|
||||||
}{
|
}{
|
||||||
{1500 * time.Millisecond, "1.50 s"},
|
{1500 * time.Millisecond, "1s"},
|
||||||
{90 * time.Second, "1.50 m"},
|
{90 * time.Second, "1m30s"},
|
||||||
{90 * time.Minute, "1.50 h"},
|
{90 * time.Minute, "1h30m"},
|
||||||
{36 * time.Hour, "1.50 d"},
|
{36 * time.Hour, "1d12h"},
|
||||||
} {
|
} {
|
||||||
if got := scaleTime(c.in); got != c.want {
|
if got := scaleTime(c.in); got != c.want {
|
||||||
t.Errorf("scaleTime(%v) = %q, want %q", c.in, got, c.want)
|
t.Errorf("scaleTime(%v) = %q, want %q", c.in, got, c.want)
|
||||||
|
|||||||
@@ -61,7 +61,8 @@ const (
|
|||||||
chipBorder = 2
|
chipBorder = 2
|
||||||
|
|
||||||
gridCols = 2
|
gridCols = 2
|
||||||
chipPadY = step * 3
|
chipPadY = step * 4
|
||||||
|
chipLineGap = step * 3
|
||||||
chipGap = spaceTight
|
chipGap = spaceTight
|
||||||
statRowGap = spaceRow
|
statRowGap = spaceRow
|
||||||
)
|
)
|
||||||
@@ -267,10 +268,11 @@ func (d *display) close() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// y is the top of the line as read, not the top of the cell, so text and a
|
// y is the top of the line as read, not the top of the cell, so text and a
|
||||||
// bordered box placed the same distance apart look it.
|
// bordered box placed the same distance apart look it. Returns the top of the
|
||||||
|
// next line, gapless — the caller owns the spacing below.
|
||||||
func (d *display) centerIn(f *textFace, x, w, y int, s string, col rgb) int {
|
func (d *display) centerIn(f *textFace, x, w, y int, s string, col rgb) int {
|
||||||
f.draw(d.fb, x+(w-len([]rune(s))*f.cellW)/2, y-f.capTop, s, col)
|
f.draw(d.fb, x+(w-len([]rune(s))*f.cellW)/2, y-f.capTop, s, col)
|
||||||
return y + f.lineH + pairGap
|
return y + f.lineH
|
||||||
}
|
}
|
||||||
|
|
||||||
type statCell struct {
|
type statCell struct {
|
||||||
@@ -306,7 +308,7 @@ func (d *display) stats(vf *textFace, x, w, y int, cells []statCell) int {
|
|||||||
}
|
}
|
||||||
cx, cw := gridCell(i, len(cells), gridCols, x, w)
|
cx, cw := gridCell(i, len(cells), gridCols, x, w)
|
||||||
cy := y + (i/gridCols)*(d.statPairH(vf)+statRowGap)
|
cy := y + (i/gridCols)*(d.statPairH(vf)+statRowGap)
|
||||||
ly := d.centerIn(vf, cx, cw, cy, c.value, c.col)
|
ly := d.centerIn(vf, cx, cw, cy, c.value, c.col) + pairGap
|
||||||
d.centerIn(d.grid, cx, cw, ly, c.label, uiDim)
|
d.centerIn(d.grid, cx, cw, ly, c.label, uiDim)
|
||||||
}
|
}
|
||||||
return y + d.statsH(vf, len(cells))
|
return y + d.statsH(vf, len(cells))
|
||||||
@@ -324,7 +326,7 @@ var errRows = []struct {
|
|||||||
|
|
||||||
func (d *display) chipH() int { return d.grid.lineH + 2*chipPadY }
|
func (d *display) chipH() int { return d.grid.lineH + 2*chipPadY }
|
||||||
|
|
||||||
func (d *display) countChipH() int { return d.chipH() + d.gridB.lineH + pairGap }
|
func (d *display) countChipH() int { return d.chipH() + d.gridB.lineH + chipLineGap }
|
||||||
|
|
||||||
// The error chips plus corrected and the noise cable's, which share their
|
// The error chips plus corrected and the noise cable's, which share their
|
||||||
// row grid.
|
// row grid.
|
||||||
@@ -350,8 +352,8 @@ func (d *display) chipAt(i, n, cols, x, w, y, h int, c rgb) (int, int, int) {
|
|||||||
|
|
||||||
// Whether rather than how many: over a window this short a count changes faster
|
// Whether rather than how many: over a window this short a count changes faster
|
||||||
// than it can be read. The noise chip rides along at the end, presence rather
|
// than it can be read. The noise chip rides along at the end, presence rather
|
||||||
// than health: red is the cable missing, not the cable failing, and a present
|
// than health: red is the cable missing, not the cable failing. The cycle
|
||||||
// cable names its cycle phase in green.
|
// phase stays off the panel (the console column still carries it).
|
||||||
func (d *display) errChips(x, w, y int, e errs, recentCorrected uint64, nv noiseView) int {
|
func (d *display) errChips(x, w, y int, e errs, recentCorrected uint64, nv noiseView) int {
|
||||||
n := len(errRows) + 2
|
n := len(errRows) + 2
|
||||||
for i, r := range errRows {
|
for i, r := range errRows {
|
||||||
@@ -366,15 +368,8 @@ func (d *display) errChips(x, w, y int, e errs, recentCorrected uint64, nv noise
|
|||||||
cx, cw, cy := d.chipAt(len(errRows), n, gridCols, x, w, y, d.chipH(), c)
|
cx, cw, cy := d.chipAt(len(errRows), n, gridCols, x, w, y, d.chipH(), c)
|
||||||
d.centerIn(d.grid, cx, cw, cy+chipPadY, "corrected", c)
|
d.centerIn(d.grid, cx, cw, cy+chipPadY, "corrected", c)
|
||||||
c = errColor(nv.missing)
|
c = errColor(nv.missing)
|
||||||
label := "noise"
|
|
||||||
if nv.missing == 0 {
|
|
||||||
label = "noise off"
|
|
||||||
if nv.on {
|
|
||||||
label = "noise on"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cx, cw, cy = d.chipAt(len(errRows)+1, n, gridCols, x, w, y, d.chipH(), c)
|
cx, cw, cy = d.chipAt(len(errRows)+1, n, gridCols, x, w, y, d.chipH(), c)
|
||||||
d.centerIn(d.grid, cx, cw, cy+chipPadY, label, c)
|
d.centerIn(d.grid, cx, cw, cy+chipPadY, "noise", c)
|
||||||
return y + d.chipsH()
|
return y + d.chipsH()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -383,7 +378,7 @@ func (d *display) errCounts(x, w, y int, e errs) int {
|
|||||||
n := r.get(e)
|
n := r.get(e)
|
||||||
c := errColor(n)
|
c := errColor(n)
|
||||||
cx, cw, cy := d.chipAt(i, len(errRows), gridCols, x, w, y, d.countChipH(), c)
|
cx, cw, cy := d.chipAt(i, len(errRows), gridCols, x, w, y, d.countChipH(), c)
|
||||||
ty := d.centerIn(d.gridB, cx, cw, cy+chipPadY, scaleCount(n), c)
|
ty := d.centerIn(d.gridB, cx, cw, cy+chipPadY, scaleCount(n), c) + chipLineGap
|
||||||
d.centerIn(d.grid, cx, cw, ty, r.label, c)
|
d.centerIn(d.grid, cx, cw, ty, r.label, c)
|
||||||
}
|
}
|
||||||
return y + d.countsH()
|
return y + d.countsH()
|
||||||
@@ -419,14 +414,17 @@ func errColor(n uint64) rgb {
|
|||||||
|
|
||||||
func snrStat(phy phyDisplay) statCell {
|
func snrStat(phy phyDisplay) statCell {
|
||||||
if !phy.haveSNR {
|
if !phy.haveSNR {
|
||||||
return statCell{"-", "db margin", uiDim}
|
return statCell{"-", "dB margin", uiDim}
|
||||||
}
|
}
|
||||||
return statCell{fmt.Sprintf("%+.1f", phy.worstMargin), "db margin",
|
col := uiFg
|
||||||
classColor(snrClass(phy.worstMargin))}
|
if c := snrClass(phy.worstMargin); c != clsGood {
|
||||||
|
col = classColor(c)
|
||||||
|
}
|
||||||
|
return statCell{fmt.Sprintf("%+.1f", phy.worstMargin), "dB margin", col}
|
||||||
}
|
}
|
||||||
|
|
||||||
func correctedStat(v uint64) statCell {
|
func correctedStat(v uint64) statCell {
|
||||||
col := uiGreen
|
col := uiFg
|
||||||
if v > 0 {
|
if v > 0 {
|
||||||
col = uiAmber
|
col = uiAmber
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user