From c8c63a4bfb1439c4cadf3e71c2d2fdaeded7eeab Mon Sep 17 00:00:00 2001 From: sqshq Date: Tue, 26 Feb 2019 23:23:56 -0500 Subject: [PATCH] gauge component enhancements --- component/barchart/barchart.go | 2 +- component/gauge/gauge.go | 2 +- component/layout.go | 2 +- config.yml | 73 ++++++++++++++++++++++------------ config/component.go | 2 +- console/symbol.go | 4 +- event/handler.go | 2 +- 7 files changed, 54 insertions(+), 33 deletions(-) diff --git a/component/barchart/barchart.go b/component/barchart/barchart.go index 692fdfc..0e0ccda 100644 --- a/component/barchart/barchart.go +++ b/component/barchart/barchart.go @@ -89,7 +89,7 @@ func (b *BarChart) reselectMaxValue() { func (b *BarChart) Draw(buf *ui.Buffer) { b.Block.Draw(buf) - barWidth := (b.Inner.Dx() - 2*barIndent - len(b.bars)) / len(b.bars) + barWidth := (b.Inner.Dx() - 2*barIndent) / len(b.bars) barXCoordinate := b.Inner.Min.X + barIndent labelStyle := ui.NewStyle(console.ColorWhite) diff --git a/component/gauge/gauge.go b/component/gauge/gauge.go index 6cfb76a..b7d8c19 100644 --- a/component/gauge/gauge.go +++ b/component/gauge/gauge.go @@ -60,7 +60,7 @@ func (g *Gauge) Draw(buf *ui.Buffer) { g.Block.Draw(buf) percent := 0.0 - if g.curValue != 0 { + if g.curValue != 0 && g.maxValue != g.minValue { percent = (100 * g.curValue) / (g.maxValue - g.minValue) } diff --git a/component/layout.go b/component/layout.go index 9c619e7..c7ac75c 100644 --- a/component/layout.go +++ b/component/layout.go @@ -30,7 +30,7 @@ const ( const ( columnsCount = 80 - rowsCount = 60 + rowsCount = 55 statusbarHeight = 1 ) diff --git a/config.yml b/config.yml index d15b80b..a32670e 100644 --- a/config.yml +++ b/config.yml @@ -4,8 +4,8 @@ runcharts: w: 0 h: 0 size: - w: 40 - h: 18 + w: 53 + h: 22 scale: 3 items: - label: GOOGLE @@ -17,11 +17,11 @@ runcharts: - title: SEARCH ENGINE RESPONSE TIME 2 (sec) refresh-rate-ms: 5000 position: - w: 40 + w: 53 h: 0 size: - w: 20 - h: 18 + w: 27 + h: 22 legend: enabled: true details: false @@ -34,11 +34,11 @@ runcharts: value: curl -o /dev/null -s -w '%{time_total}' https://www.bing.com - title: MONGO COLLECTIONS COUNT position: - w: 21 - h: 18 + w: 26 + h: 23 size: - w: 19 - h: 13 + w: 27 + h: 17 scale: 0 items: - label: ACTIVE @@ -50,10 +50,10 @@ barcharts: refresh-rate-ms: 1000 position: w: 0 - h: 18 + h: 23 size: - w: 21 - h: 13 + w: 26 + h: 17 scale: 0 items: - label: NEW @@ -67,33 +67,54 @@ barcharts: - label: FINISHED value: mongo --quiet --host=localhost blog --eval "db.getCollection('posts').find({status:'INACTIVE'}).itcount()" gauges: -- title: YEAR PROGRESS +- title: YEAR PROGRESS (TODO day progress) position: - w: 21 - h: 33 + w: 0 + h: 41 size: - w: 20 + w: 26 h: 3 values: - cur: echo 245 + cur: date +%j max: echo 365 min: echo 0 - items: [] +- title: HOUR PROGRESS + position: + w: 0 + h: 44 + size: + w: 26 + h: 3 + values: + cur: date +%M + max: echo 60 + min: echo 0 +- title: MINUTE PROGRESS + position: + w: 0 + h: 47 + size: + w: 26 + h: 3 + values: + cur: date +%S + max: echo 60 + min: echo 0 asciiboxes: - title: LOCAL TIME position: - w: 40 - h: 18 + w: 53 + h: 23 size: - w: 20 - h: 6 + w: 27 + h: 8 value: date +%r - title: UTC TIME position: - w: 40 - h: 24 + w: 53 + h: 31 size: - w: 20 - h: 7 + w: 27 + h: 9 value: env TZ=UTC date +%r font: 3d diff --git a/config/component.go b/config/component.go index 487ed59..4e23402 100644 --- a/config/component.go +++ b/config/component.go @@ -18,7 +18,7 @@ type GaugeConfig struct { Scale *int `yaml:"scale,omitempty"` Color *ui.Color `yaml:"color,omitempty"` Values map[string]string `yaml:"values"` - Items []data.Item + Items []data.Item `yaml:",omitempty"` } type BarChartConfig struct { diff --git a/console/symbol.go b/console/symbol.go index 8146e7e..d278539 100644 --- a/console/symbol.go +++ b/console/symbol.go @@ -2,6 +2,6 @@ package console const ( SymbolSelection rune = '▲' - SymbolVerticalBar rune = '⢸' - SymbolShade rune = '⣿' + SymbolVerticalBar rune = '▎' + SymbolShade rune = '⠿' ) diff --git a/event/handler.go b/event/handler.go index 2f37613..7fc5b40 100644 --- a/event/handler.go +++ b/event/handler.go @@ -9,7 +9,7 @@ import ( ) const ( - refreshRateToRenderRateRatio = 0.3 + refreshRateToRenderRateRatio = 0.5 ) type Handler struct {