ctop/widgets/hist.go
2017-01-06 14:46:30 -05:00

23 lines
374 B
Go

package widgets
type HistData struct {
data []int
labels []string
maxSize int
}
func NewHistData(max int) HistData {
return HistData{
data: make([]int, max),
labels: make([]string, max),
maxSize: max,
}
}
func (h HistData) Append(val int) {
if len(h.data) >= h.maxSize {
h.data = append(h.data[:0], h.data[1:]...)
}
h.data = append(h.data, val)
}