Skip to content

Commit

Permalink
Merge branch 'master' into gcal-format
Browse files Browse the repository at this point in the history
  • Loading branch information
senorprogrammer authored Jun 28, 2018
2 parents 52d5fd0 + 5caff0c commit b78893d
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ before_install:
- export TRAVIS_BUILD_DIR=$HOME/gopath/src/github.com/senorprogrammer/wtf
- cd $HOME/gopath/src/github.com/senorprogrammer/wtf

script: go get ./... && go get github.com/go-test/deep && go test -v github.com/senorprogrammer/wtf/wtf_tests
script: go get ./... && go get github.com/go-test/deep && go test -v github.com/senorprogrammer/wtf/wtf_tests/...
3 changes: 2 additions & 1 deletion _sample_configs/bargraph_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ wtf:
mods:
bargraph:
enabled: true
graphIcon: "🍎"
graphIcon: "💀"
graphStars: 25
position:
top: 2
left: 0
Expand Down
3 changes: 1 addition & 2 deletions bargraph/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -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[:])

}

Expand Down
25 changes: 16 additions & 9 deletions wtf/bargraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)),
}
Expand Down Expand Up @@ -99,8 +101,14 @@ 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) {

widget.View.SetText(BuildStars(data, widget.maxStars, widget.starChar))

}

//BuildStars build the string to display
func BuildStars(data [][2]int64, maxStars int, starChar string) string {
var buffer bytes.Buffer

//counter to inintialize min value
Expand Down Expand Up @@ -158,8 +166,7 @@ func (widget *BarGraph) BuildBars(maxStars int, starChar string, data [][2]int64
buffer.WriteString(fmt.Sprintf("%s -\t [red]%s[white] - (%d)\n", t.Format("Jan 02, 2006"), stars, val))
}

widget.View.SetText(buffer.String())

return buffer.String()
}

/* -------------------- Exported Functions -------------------- */
33 changes: 33 additions & 0 deletions wtf_tests/bargraph/bargraph_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package bargraphtests

import (
"testing"

. "github.com/senorprogrammer/wtf/wtf"
. "github.com/stretchr/testify/assert"
)

// MakeData - Create sample data
func makeData() [][2]int64 {

//this could come from config
const lineCount = 2
var stats [lineCount][2]int64

stats[0][1] = 1530122942
stats[0][0] = 100

stats[1][1] = 1530132942
stats[1][0] = 210

return stats[:]

}

//TestOutput of the bargraph make string (BuildStars) function
func TestOutput(t *testing.T) {

result := BuildStars(makeData(), 20, "*")

Equal(t, result, "Jan 18, 1970 -\t [red]*[white] - (100)\nJan 18, 1970 -\t [red]********************[white] - (210)\n")
}

0 comments on commit b78893d

Please sign in to comment.