add custom label formatting, scale for expandedMem

This commit is contained in:
Bradley Cicenas 2017-01-08 18:07:56 +00:00
parent 72066aba6e
commit e73732ae98
5 changed files with 36 additions and 37 deletions

View File

@ -30,8 +30,8 @@ func NewCompact(id string, name string) *Compact {
Cid: compactPar(id), Cid: compactPar(id),
Net: compactPar("-"), Net: compactPar("-"),
Name: compactPar(name), Name: compactPar(name),
Cpu: mkGauge(), Cpu: slimGauge(),
Memory: mkGauge(), Memory: slimGauge(),
} }
} }
@ -82,3 +82,14 @@ func (w *Compact) SetMem(val int64, limit int64, percent int) {
} }
w.Memory.Percent = percent w.Memory.Percent = percent
} }
func slimGauge() *ui.Gauge {
g := ui.NewGauge()
g.Height = 1
g.Border = false
g.Percent = 0
g.PaddingBottom = 0
g.BarColor = ui.ColorGreen
g.Label = "-"
return g
}

View File

@ -27,7 +27,7 @@ func NewInfo(id, name string) *ui.Table {
[]string{"id", id}, []string{"id", id},
} }
p.Height = 4 p.Height = 4
p.Width = 40 p.Width = 50
p.FgColor = ui.ColorWhite p.FgColor = ui.ColorWhite
p.Seperator = false p.Seperator = false
return p return p

View File

@ -5,15 +5,13 @@ import (
) )
type ExpandedMem struct { type ExpandedMem struct {
*ui.MBarChart *ui.BarChart
valHist IntHistData hist IntHistData
limitHist IntHistData
} }
func NewExpandedMem() *ExpandedMem { func NewExpandedMem() *ExpandedMem {
mem := &ExpandedMem{ mem := &ExpandedMem{
ui.NewMBarChart(), ui.NewBarChart(),
NewIntHistData(8),
NewIntHistData(8), NewIntHistData(8),
} }
mem.BorderLabel = "MEM" mem.BorderLabel = "MEM"
@ -21,21 +19,22 @@ func NewExpandedMem() *ExpandedMem {
mem.Width = 50 mem.Width = 50
mem.BarWidth = 5 mem.BarWidth = 5
mem.BarGap = 1 mem.BarGap = 1
mem.X = 51 mem.X = 0
mem.Y = 4 mem.Y = 14
mem.TextColor = ui.ColorDefault mem.TextColor = ui.ColorDefault
mem.Data[0] = mem.valHist.data mem.Data = mem.hist.data
mem.Data[0] = mem.valHist.data mem.BarColor = ui.ColorGreen
mem.Data[1] = mem.limitHist.data mem.DataLabels = mem.hist.labels
mem.BarColor[0] = ui.ColorGreen mem.NumFmt = byteFormatInt
mem.BarColor[1] = ui.ColorBlack
mem.DataLabels = mem.valHist.labels
//mem.ShowScale = true
return mem return mem
} }
func (w *ExpandedMem) Update(val int, limit int) { func (w *ExpandedMem) Update(val int, limit int) {
w.valHist.Append(val) // implement our own scaling for mem graph
w.limitHist.Append(limit - val) if val*4 < limit {
//w.Data[0] = w.hist.data w.SetMax(val * 4)
} else {
w.SetMax(limit)
}
w.hist.Append(val)
} }

View File

@ -14,23 +14,23 @@ type ExpandedNet struct {
} }
func NewExpandedNet() *ExpandedNet { func NewExpandedNet() *ExpandedNet {
net := &ExpandedNet{ui.NewSparklines(), NewDiffHistData(30), NewDiffHistData(30)} net := &ExpandedNet{ui.NewSparklines(), NewDiffHistData(50), NewDiffHistData(50)}
net.BorderLabel = "NET" net.BorderLabel = "NET"
net.Height = 8 net.Height = 6
net.Width = 35 net.Width = 50
net.X = 0 net.X = 0
net.Y = 15 net.Y = 24
rx := ui.NewSparkline() rx := ui.NewSparkline()
rx.Title = "RX" rx.Title = "RX"
rx.Height = 2 rx.Height = 1
rx.Data = net.rxHist.data rx.Data = net.rxHist.data
rx.TitleColor = ui.ColorDefault rx.TitleColor = ui.ColorDefault
rx.LineColor = ui.ColorGreen rx.LineColor = ui.ColorGreen
tx := ui.NewSparkline() tx := ui.NewSparkline()
tx.Title = "TX" tx.Title = "TX"
tx.Height = 2 tx.Height = 1
tx.Data = net.txHist.data tx.Data = net.txHist.data
tx.TitleColor = ui.ColorDefault tx.TitleColor = ui.ColorDefault
tx.LineColor = ui.ColorYellow tx.LineColor = ui.ColorYellow

View File

@ -43,17 +43,6 @@ func compactPar(s string) *ui.Par {
return p return p
} }
func mkGauge() *ui.Gauge {
g := ui.NewGauge()
g.Height = 1
g.Border = false
g.Percent = 0
g.PaddingBottom = 0
g.BarColor = ui.ColorGreen
g.Label = "-"
return g
}
func colorScale(n int) ui.Attribute { func colorScale(n int) ui.Attribute {
if n > 70 { if n > 70 {
return ui.ColorRed return ui.ColorRed