ctop/widgets/expanded_mem.go

41 lines
684 B
Go
Raw Normal View History

2017-01-07 20:37:11 +00:00
package widgets
import (
ui "github.com/gizak/termui"
)
type ExpandedMem struct {
*ui.BarChart
2017-01-12 15:06:35 +00:00
hist IntHist
2017-01-07 20:37:11 +00:00
}
func NewExpandedMem() *ExpandedMem {
mem := &ExpandedMem{
ui.NewBarChart(),
2017-01-12 15:06:35 +00:00
NewIntHist(8),
2017-01-07 20:37:11 +00:00
}
mem.BorderLabel = "MEM"
mem.Height = 10
mem.Width = 50
mem.BarWidth = 5
mem.BarGap = 1
mem.X = 0
mem.Y = 14
2017-01-07 20:37:11 +00:00
mem.TextColor = ui.ColorDefault
mem.Data = mem.hist.data
mem.BarColor = ui.ColorGreen
mem.DataLabels = mem.hist.labels
mem.NumFmt = byteFormatInt
2017-01-07 20:37:11 +00:00
return mem
}
func (w *ExpandedMem) Update(val int, limit int) {
// implement our own scaling for mem graph
if val*4 < limit {
w.SetMax(val * 4)
} else {
w.SetMax(limit)
}
w.hist.Append(val)
2017-01-07 20:37:11 +00:00
}