mirror of
https://github.com/bcicen/ctop.git
synced 2024-08-30 18:23:19 +00:00
rename histdata
This commit is contained in:
parent
a2b2ddcb8e
commit
3a0df1c490
@ -6,11 +6,11 @@ import (
|
|||||||
|
|
||||||
type ExpandedCpu struct {
|
type ExpandedCpu struct {
|
||||||
*ui.LineChart
|
*ui.LineChart
|
||||||
hist FloatHistData
|
hist FloatHist
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewExpandedCpu() *ExpandedCpu {
|
func NewExpandedCpu() *ExpandedCpu {
|
||||||
cpu := &ExpandedCpu{ui.NewLineChart(), NewFloatHistData(60)}
|
cpu := &ExpandedCpu{ui.NewLineChart(), NewFloatHist(60)}
|
||||||
cpu.BorderLabel = "CPU"
|
cpu.BorderLabel = "CPU"
|
||||||
cpu.Height = 10
|
cpu.Height = 10
|
||||||
cpu.Width = 50
|
cpu.Width = 50
|
||||||
|
@ -6,13 +6,13 @@ import (
|
|||||||
|
|
||||||
type ExpandedMem struct {
|
type ExpandedMem struct {
|
||||||
*ui.BarChart
|
*ui.BarChart
|
||||||
hist IntHistData
|
hist IntHist
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewExpandedMem() *ExpandedMem {
|
func NewExpandedMem() *ExpandedMem {
|
||||||
mem := &ExpandedMem{
|
mem := &ExpandedMem{
|
||||||
ui.NewBarChart(),
|
ui.NewBarChart(),
|
||||||
NewIntHistData(8),
|
NewIntHist(8),
|
||||||
}
|
}
|
||||||
mem.BorderLabel = "MEM"
|
mem.BorderLabel = "MEM"
|
||||||
mem.Height = 10
|
mem.Height = 10
|
||||||
|
@ -9,12 +9,12 @@ import (
|
|||||||
|
|
||||||
type ExpandedNet struct {
|
type ExpandedNet struct {
|
||||||
*ui.Sparklines
|
*ui.Sparklines
|
||||||
rxHist DiffHistData
|
rxHist DiffHist
|
||||||
txHist DiffHistData
|
txHist DiffHist
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewExpandedNet() *ExpandedNet {
|
func NewExpandedNet() *ExpandedNet {
|
||||||
net := &ExpandedNet{ui.NewSparklines(), NewDiffHistData(50), NewDiffHistData(50)}
|
net := &ExpandedNet{ui.NewSparklines(), NewDiffHist(50), NewDiffHist(50)}
|
||||||
net.BorderLabel = "NET"
|
net.BorderLabel = "NET"
|
||||||
net.Height = 6
|
net.Height = 6
|
||||||
net.Width = 50
|
net.Width = 50
|
||||||
|
@ -1,27 +1,27 @@
|
|||||||
package widgets
|
package widgets
|
||||||
|
|
||||||
type HistData struct {
|
type Hist struct {
|
||||||
maxLen int
|
maxLen int
|
||||||
labels []string
|
labels []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHistData(max int) HistData {
|
func NewHist(max int) Hist {
|
||||||
return HistData{
|
return Hist{
|
||||||
maxLen: max,
|
maxLen: max,
|
||||||
labels: make([]string, max),
|
labels: make([]string, max),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type IntHistData struct {
|
type IntHist struct {
|
||||||
HistData
|
Hist
|
||||||
data []int
|
data []int
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewIntHistData(max int) IntHistData {
|
func NewIntHist(max int) IntHist {
|
||||||
return IntHistData{NewHistData(max), make([]int, max)}
|
return IntHist{NewHist(max), make([]int, max)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h IntHistData) Append(val int) {
|
func (h IntHist) Append(val int) {
|
||||||
if len(h.data) >= h.maxLen {
|
if len(h.data) >= h.maxLen {
|
||||||
h.data = append(h.data[:0], h.data[1:]...)
|
h.data = append(h.data[:0], h.data[1:]...)
|
||||||
}
|
}
|
||||||
@ -29,42 +29,42 @@ func (h IntHistData) Append(val int) {
|
|||||||
h.data = append(h.data, val)
|
h.data = append(h.data, val)
|
||||||
}
|
}
|
||||||
|
|
||||||
type FloatHistData struct {
|
type FloatHist struct {
|
||||||
HistData
|
Hist
|
||||||
data []float64
|
data []float64
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFloatHistData(max int) FloatHistData {
|
func NewFloatHist(max int) FloatHist {
|
||||||
return FloatHistData{NewHistData(max), make([]float64, max)}
|
return FloatHist{NewHist(max), make([]float64, max)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h FloatHistData) Append(val float64) {
|
func (h FloatHist) Append(val float64) {
|
||||||
if len(h.data) >= h.maxLen {
|
if len(h.data) >= h.maxLen {
|
||||||
h.data = append(h.data[:0], h.data[1:]...)
|
h.data = append(h.data[:0], h.data[1:]...)
|
||||||
}
|
}
|
||||||
h.data = append(h.data, val)
|
h.data = append(h.data, val)
|
||||||
}
|
}
|
||||||
|
|
||||||
type DiffHistData struct {
|
type DiffHist struct {
|
||||||
HistData
|
Hist
|
||||||
data []int
|
data []int
|
||||||
srcData []int
|
srcData []int
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDiffHistData(max int) DiffHistData {
|
func NewDiffHist(max int) DiffHist {
|
||||||
return DiffHistData{
|
return DiffHist{
|
||||||
NewHistData(max),
|
NewHist(max),
|
||||||
make([]int, max),
|
make([]int, max),
|
||||||
make([]int, max),
|
make([]int, max),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// return most recent value
|
// return most recent value
|
||||||
func (h DiffHistData) Last() int {
|
func (h DiffHist) Last() int {
|
||||||
return h.data[len(h.data)-1]
|
return h.data[len(h.data)-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h DiffHistData) Append(val int) {
|
func (h DiffHist) Append(val int) {
|
||||||
if len(h.data) >= h.maxLen {
|
if len(h.data) >= h.maxLen {
|
||||||
h.data = append(h.data[:0], h.data[1:]...)
|
h.data = append(h.data[:0], h.data[1:]...)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user