2017-08-05 11:28:20 +00:00
|
|
|
package single
|
2017-03-06 08:51:50 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
ui "github.com/gizak/termui"
|
|
|
|
)
|
|
|
|
|
2017-03-06 23:58:04 +00:00
|
|
|
type Cpu struct {
|
2017-03-06 08:51:50 +00:00
|
|
|
*ui.LineChart
|
|
|
|
hist FloatHist
|
|
|
|
}
|
|
|
|
|
2017-03-06 23:58:04 +00:00
|
|
|
func NewCpu() *Cpu {
|
|
|
|
cpu := &Cpu{ui.NewLineChart(), NewFloatHist(55)}
|
|
|
|
cpu.Mode = "dot"
|
2017-03-06 08:51:50 +00:00
|
|
|
cpu.BorderLabel = "CPU"
|
2017-03-06 23:58:04 +00:00
|
|
|
cpu.Height = 12
|
2017-03-06 22:05:04 +00:00
|
|
|
cpu.Width = colWidth[0]
|
2017-03-06 08:51:50 +00:00
|
|
|
cpu.X = 0
|
|
|
|
cpu.DataLabels = cpu.hist.Labels
|
2017-03-06 23:58:04 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
2017-03-06 23:58:04 +00:00
|
|
|
func (w *Cpu) Update(val int) {
|
2017-03-06 08:51:50 +00:00
|
|
|
w.hist.Append(float64(val))
|
|
|
|
}
|