mirror of
https://github.com/bcicen/ctop.git
synced 2024-08-30 18:23:19 +00:00
convert expanded mem widget to mbarchart, add innerlabel
This commit is contained in:
parent
d94aed1531
commit
8e995a37c6
@ -4,25 +4,31 @@ import (
|
||||
ui "github.com/gizak/termui"
|
||||
)
|
||||
|
||||
type ExpandedCpu struct {
|
||||
type Cpu struct {
|
||||
*ui.LineChart
|
||||
hist FloatHist
|
||||
}
|
||||
|
||||
func NewExpandedCpu() *ExpandedCpu {
|
||||
cpu := &ExpandedCpu{ui.NewLineChart(), NewFloatHist(60)}
|
||||
func NewCpu() *Cpu {
|
||||
cpu := &Cpu{ui.NewLineChart(), NewFloatHist(55)}
|
||||
cpu.Mode = "dot"
|
||||
cpu.BorderLabel = "CPU"
|
||||
cpu.Height = 10
|
||||
cpu.Height = 12
|
||||
cpu.Width = colWidth[0]
|
||||
cpu.X = 0
|
||||
cpu.Y = 6
|
||||
cpu.Data = cpu.hist.Data
|
||||
cpu.DataLabels = cpu.hist.Labels
|
||||
cpu.AxesColor = ui.ColorDefault
|
||||
cpu.LineColor = ui.ColorGreen
|
||||
|
||||
// hack to force the default minY scale to 0
|
||||
tmpData := []float64{20}
|
||||
cpu.Data = tmpData
|
||||
_ = cpu.Buffer()
|
||||
|
||||
cpu.Data = cpu.hist.Data
|
||||
return cpu
|
||||
}
|
||||
|
||||
func (w *ExpandedCpu) Update(val int) {
|
||||
func (w *Cpu) Update(val int) {
|
||||
w.hist.Append(float64(val))
|
||||
}
|
||||
|
@ -9,14 +9,14 @@ import (
|
||||
var (
|
||||
log = logging.Init()
|
||||
sizeError = termSizeError()
|
||||
colWidth = [2]int{60, 0} // left,right column width
|
||||
colWidth = [2]int{65, 0} // left,right column width
|
||||
)
|
||||
|
||||
type Expanded struct {
|
||||
Info *Info
|
||||
Net *ExpandedNet
|
||||
Cpu *ExpandedCpu
|
||||
Mem *ExpandedMem
|
||||
Net *Net
|
||||
Cpu *Cpu
|
||||
Mem *Mem
|
||||
Width int
|
||||
}
|
||||
|
||||
@ -26,9 +26,9 @@ func NewExpanded(id string) *Expanded {
|
||||
}
|
||||
return &Expanded{
|
||||
Info: NewInfo(id),
|
||||
Net: NewExpandedNet(),
|
||||
Cpu: NewExpandedCpu(),
|
||||
Mem: NewExpandedMem(),
|
||||
Net: NewNet(),
|
||||
Cpu: NewCpu(),
|
||||
Mem: NewMem(),
|
||||
Width: ui.TermWidth(),
|
||||
}
|
||||
}
|
||||
@ -56,6 +56,7 @@ func (e *Expanded) Align() {
|
||||
if e.Width > colWidth[0] {
|
||||
colWidth[1] = e.Width - (colWidth[0] + 1)
|
||||
}
|
||||
e.Mem.Align()
|
||||
log.Debugf("align: width=%v left-col=%v right-col=%v", e.Width, colWidth[0], colWidth[1])
|
||||
}
|
||||
|
||||
|
@ -1,41 +1,87 @@
|
||||
package expanded
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/bcicen/ctop/cwidgets"
|
||||
ui "github.com/gizak/termui"
|
||||
)
|
||||
|
||||
type ExpandedMem struct {
|
||||
*ui.BarChart
|
||||
hist *IntHist
|
||||
type Mem struct {
|
||||
*ui.Block
|
||||
Chart *ui.MBarChart
|
||||
InnerLabel *ui.Par
|
||||
valHist *IntHist
|
||||
limitHist *IntHist
|
||||
}
|
||||
|
||||
func NewExpandedMem() *ExpandedMem {
|
||||
mem := &ExpandedMem{
|
||||
ui.NewBarChart(),
|
||||
NewIntHist(10),
|
||||
func NewMem() *Mem {
|
||||
mem := &Mem{
|
||||
Block: ui.NewBlock(),
|
||||
Chart: newMemChart(),
|
||||
InnerLabel: newMemLabel(),
|
||||
valHist: NewIntHist(9),
|
||||
limitHist: NewIntHist(9),
|
||||
}
|
||||
mem.BorderLabel = "MEM"
|
||||
mem.Height = 10
|
||||
mem.Height = 13
|
||||
mem.Width = colWidth[0]
|
||||
mem.BarWidth = 5
|
||||
mem.BarGap = 1
|
||||
mem.X = 0
|
||||
mem.Y = 14
|
||||
mem.TextColor = ui.ColorDefault
|
||||
mem.Data = mem.hist.Data
|
||||
mem.BarColor = ui.ColorGreen
|
||||
mem.DataLabels = mem.hist.Labels
|
||||
mem.NumFmt = cwidgets.ByteFormatInt
|
||||
mem.BorderLabel = "MEM"
|
||||
|
||||
mem.Chart.Data[0] = mem.valHist.Data
|
||||
mem.Chart.Data[1] = mem.limitHist.Data
|
||||
mem.Chart.DataLabels = mem.valHist.Labels
|
||||
|
||||
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)
|
||||
func (w *Mem) Align() {
|
||||
y := w.Y + 1
|
||||
w.InnerLabel.SetY(y)
|
||||
w.Chart.SetY(y + w.InnerLabel.Height)
|
||||
|
||||
w.Chart.Height = w.Height - w.InnerLabel.Height - 2
|
||||
w.Chart.SetWidth(w.Width - 2)
|
||||
}
|
||||
|
||||
func (w *Mem) Buffer() ui.Buffer {
|
||||
buf := ui.NewBuffer()
|
||||
buf.Merge(w.Block.Buffer())
|
||||
buf.Merge(w.InnerLabel.Buffer())
|
||||
buf.Merge(w.Chart.Buffer())
|
||||
return buf
|
||||
}
|
||||
|
||||
func newMemLabel() *ui.Par {
|
||||
p := ui.NewPar("-")
|
||||
p.X = 1
|
||||
p.Border = false
|
||||
p.Height = 1
|
||||
p.Width = 20
|
||||
p.TextFgColor = ui.ColorDefault
|
||||
return p
|
||||
}
|
||||
|
||||
func newMemChart() *ui.MBarChart {
|
||||
mbar := ui.NewMBarChart()
|
||||
mbar.X = 1
|
||||
mbar.Border = false
|
||||
mbar.BarGap = 1
|
||||
mbar.BarWidth = 6
|
||||
mbar.TextColor = ui.ColorDefault
|
||||
|
||||
mbar.BarColor[0] = ui.ColorGreen
|
||||
|
||||
mbar.BarColor[1] = ui.ColorBlack
|
||||
mbar.NumColor[1] = ui.ColorBlack
|
||||
|
||||
mbar.NumFmt = cwidgets.ByteFormatInt
|
||||
//mbar.ShowScale = true
|
||||
return mbar
|
||||
}
|
||||
|
||||
func (w *Mem) Update(val int, limit int) {
|
||||
w.valHist.Append(val)
|
||||
w.limitHist.Append(limit - val)
|
||||
w.InnerLabel.Text = fmt.Sprintf("%v / %v", cwidgets.ByteFormatInt(val), cwidgets.ByteFormatInt(limit))
|
||||
//w.Data[0] = w.hist.data
|
||||
}
|
||||
|
@ -8,14 +8,14 @@ import (
|
||||
ui "github.com/gizak/termui"
|
||||
)
|
||||
|
||||
type ExpandedNet struct {
|
||||
type Net struct {
|
||||
*ui.Sparklines
|
||||
rxHist *DiffHist
|
||||
txHist *DiffHist
|
||||
}
|
||||
|
||||
func NewExpandedNet() *ExpandedNet {
|
||||
net := &ExpandedNet{ui.NewSparklines(), NewDiffHist(50), NewDiffHist(50)}
|
||||
func NewNet() *Net {
|
||||
net := &Net{ui.NewSparklines(), NewDiffHist(60), NewDiffHist(60)}
|
||||
net.BorderLabel = "NET"
|
||||
net.Height = 6
|
||||
net.Width = colWidth[0]
|
||||
@ -40,7 +40,7 @@ func NewExpandedNet() *ExpandedNet {
|
||||
return net
|
||||
}
|
||||
|
||||
func (w *ExpandedNet) Update(rx int64, tx int64) {
|
||||
func (w *Net) Update(rx int64, tx int64) {
|
||||
var rate string
|
||||
|
||||
w.rxHist.Append(int(rx))
|
||||
|
Loading…
Reference in New Issue
Block a user