ctop/cwidgets/single/cpu.go

33 lines
527 B
Go
Raw Normal View History

2017-08-05 11:28:20 +00:00
package single
2017-03-06 08:51:50 +00:00
import (
ui "github.com/gizak/termui"
)
type Cpu struct {
2017-03-06 08:51:50 +00:00
*ui.LineChart
hist FloatHist
}
func NewCpu() *Cpu {
cpu := &Cpu{ui.NewLineChart(), NewFloatHist(55)}
cpu.Mode = "dot"
2017-03-06 08:51:50 +00:00
cpu.BorderLabel = "CPU"
cpu.Height = 12
cpu.Width = colWidth[0]
2017-03-06 08:51:50 +00:00
cpu.X = 0
cpu.DataLabels = cpu.hist.Labels
// hack to force the default minY scale to 0
tmpData := []float64{20}
cpu.Data = tmpData
_ = cpu.Buffer()
cpu.Data = cpu.hist.Data
2017-03-06 08:51:50 +00:00
return cpu
}
func (w *Cpu) Update(val int) {
2017-03-06 08:51:50 +00:00
w.hist.Append(float64(val))
}