1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

added length of bar to bargraph config

This commit is contained in:
Bill Keenan 2018-06-26 13:57:13 -04:00
parent 3140241a66
commit 9a31f95409
3 changed files with 16 additions and 14 deletions

View File

@ -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

View File

@ -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[:])
}

View File

@ -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)