From 9a31f95409625f749bdbdad85682a096da15e338 Mon Sep 17 00:00:00 2001 From: Bill Keenan Date: Tue, 26 Jun 2018 13:57:13 -0400 Subject: [PATCH] added length of bar to bargraph config --- _sample_configs/bargraph_config.yml | 7 ++++--- bargraph/widget.go | 3 +-- wtf/bargraph.go | 20 +++++++++++--------- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/_sample_configs/bargraph_config.yml b/_sample_configs/bargraph_config.yml index ffdf9fe5..3f77ac97 100644 --- a/_sample_configs/bargraph_config.yml +++ b/_sample_configs/bargraph_config.yml @@ -11,11 +11,12 @@ wtf: mods: bargraph: enabled: true - graphIcon: "🍎" + graphIcon: "👿" + graphStars: 25 position: - top: 2 + top: 3 left: 0 - height: 2 + height: 1 width: 2 refreshInterval: 30 updateInterval: 15 diff --git a/bargraph/widget.go b/bargraph/widget.go index b5b9d9ff..7863f81d 100644 --- a/bargraph/widget.go +++ b/bargraph/widget.go @@ -50,8 +50,7 @@ func MakeGraph(widget *Widget) { } - icon := wtf.Config.UString("wtf.mods.bargraph.graphIcon", "✭ ") - widget.BarGraph.BuildBars(20, icon, stats[:]) + widget.BarGraph.BuildBars(stats[:]) } diff --git a/wtf/bargraph.go b/wtf/bargraph.go index 977f526f..b7a6dae8 100644 --- a/wtf/bargraph.go +++ b/wtf/bargraph.go @@ -11,9 +11,10 @@ import ( //BarGraph lets make graphs type BarGraph struct { - enabled bool - focusable bool - + enabled bool + focusable bool + starChar string + maxStars int Name string RefreshedAt time.Time RefreshInt int @@ -27,9 +28,10 @@ type BarGraph struct { // NewBarGraph initialize your fancy new graph func NewBarGraph(name string, configKey string, focusable bool) BarGraph { widget := BarGraph{ - enabled: Config.UBool(fmt.Sprintf("wtf.mods.%s.enabled", configKey), false), - focusable: focusable, - + enabled: Config.UBool(fmt.Sprintf("wtf.mods.%s.enabled", configKey), false), + focusable: focusable, + starChar: Config.UString(fmt.Sprintf("wtf.mods.%s.graphIcon", configKey), name), + maxStars: Config.UInt(fmt.Sprintf("wtf.mods.%s.graphStars", configKey), 20), Name: Config.UString(fmt.Sprintf("wtf.mods.%s.title", configKey), name), RefreshInt: Config.UInt(fmt.Sprintf("wtf.mods.%s.refreshInterval", configKey)), } @@ -99,7 +101,7 @@ func (widget *BarGraph) addView() { // BuildBars will build a string of * to represent your data of [time][value] // time should be passed as a int64 -func (widget *BarGraph) BuildBars(maxStars int, starChar string, data [][2]int64) { +func (widget *BarGraph) BuildBars(data [][2]int64) { var buffer bytes.Buffer @@ -136,7 +138,7 @@ func (widget *BarGraph) BuildBars(maxStars int, starChar string, data [][2]int64 } // each number = how many stars? - var starRatio = float64(maxStars) / float64((maxValue - minValue)) + var starRatio = float64(widget.maxStars) / float64((maxValue - minValue)) //build the stars for i := range data { @@ -149,7 +151,7 @@ func (widget *BarGraph) BuildBars(maxStars int, starChar string, data [][2]int64 starCount = 1 } //build the actual string - var stars = strings.Repeat(starChar, starCount) + var stars = strings.Repeat(widget.starChar, starCount) //parse the time var t = time.Unix(int64(data[i][1]/1000), 0)