gauge display enhancements: added ability to show/hide current value
This commit is contained in:
parent
8d88f85f05
commit
afca419295
|
@ -105,6 +105,7 @@ gauges:
|
|||
- title: Minute progress
|
||||
rate-ms: 500 # sampling rate, default = 1000
|
||||
scale: 2 # number of digits after sample decimal point, default = 1
|
||||
percent-only: false # toggle display of the current value, default = false
|
||||
color: 178 # 8-bit color number, default one is chosen from a pre-defined palette
|
||||
cur:
|
||||
sample: date +%S # sample script for current value
|
||||
|
|
|
@ -20,22 +20,24 @@ const (
|
|||
type Gauge struct {
|
||||
*ui.Block
|
||||
*data.Consumer
|
||||
minValue float64
|
||||
maxValue float64
|
||||
curValue float64
|
||||
color ui.Color
|
||||
scale int
|
||||
palette console.Palette
|
||||
minValue float64
|
||||
maxValue float64
|
||||
curValue float64
|
||||
color ui.Color
|
||||
scale int
|
||||
percentOnly bool
|
||||
palette console.Palette
|
||||
}
|
||||
|
||||
func NewGauge(c config.GaugeConfig, palette console.Palette) *Gauge {
|
||||
|
||||
g := Gauge{
|
||||
Block: component.NewBlock(c.Title, true, palette),
|
||||
Consumer: data.NewConsumer(),
|
||||
scale: *c.Scale,
|
||||
color: *c.Color,
|
||||
palette: palette,
|
||||
Block: component.NewBlock(c.Title, true, palette),
|
||||
Consumer: data.NewConsumer(),
|
||||
color: *c.Color,
|
||||
scale: *c.Scale,
|
||||
percentOnly: *c.PercentOnly,
|
||||
palette: palette,
|
||||
}
|
||||
|
||||
go func() {
|
||||
|
@ -84,7 +86,12 @@ func (g *Gauge) Draw(buffer *ui.Buffer) {
|
|||
percent = (100 * g.curValue) / (g.maxValue - g.minValue)
|
||||
}
|
||||
|
||||
label := fmt.Sprintf("%v%% (%v)", util.FormatValue(percent, g.scale), g.curValue)
|
||||
var label string
|
||||
if g.percentOnly {
|
||||
label = fmt.Sprintf(" %v%% ", util.FormatValue(percent, g.scale))
|
||||
} else {
|
||||
label = fmt.Sprintf(" %v%% (%v) ", util.FormatValue(percent, g.scale), util.FormatValue(g.curValue, g.scale))
|
||||
}
|
||||
|
||||
// draw bar
|
||||
barWidth := int((percent / 100) * float64(g.Inner.Dx()))
|
||||
|
|
|
@ -58,6 +58,7 @@ type GaugeConfig struct {
|
|||
ComponentConfig `yaml:",inline"`
|
||||
Scale *int `yaml:"scale,omitempty"`
|
||||
Color *ui.Color `yaml:"color,omitempty"`
|
||||
PercentOnly *bool `yaml:"percent-only,omitempty"`
|
||||
Cur Item `yaml:"cur"`
|
||||
Max Item `yaml:"max"`
|
||||
Min Item `yaml:"min"`
|
||||
|
|
|
@ -178,6 +178,7 @@ func (c *Config) setDefaultItemSettings() {
|
|||
palette := console.GetPalette(*c.Theme)
|
||||
colorsCount := len(palette.ContentColors)
|
||||
defaultPty := false
|
||||
defaultPercentOnly := false
|
||||
|
||||
for _, ch := range c.RunCharts {
|
||||
for j, item := range ch.Items {
|
||||
|
@ -224,6 +225,9 @@ func (c *Config) setDefaultItemSettings() {
|
|||
if g.Color == nil {
|
||||
g.Color = &palette.ContentColors[i%colorsCount]
|
||||
}
|
||||
if g.PercentOnly == nil {
|
||||
g.PercentOnly = &defaultPercentOnly
|
||||
}
|
||||
c.Gauges[i] = g
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue