Skip to content

Commit

Permalink
remove workaround for asciigraph
Browse files Browse the repository at this point in the history
  • Loading branch information
0x4c6565 committed Mar 11, 2020
1 parent 39c2616 commit dc5d5ba
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
24 changes: 9 additions & 15 deletions cmd/loadtest_job_results.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,26 +96,20 @@ func loadtestJobResultsShow(service ltaas.LTaaSService, cmd *cobra.Command, args

// generateGraph returns an ASCII graph for given parameters
func generateGraph(graphWidth int, graphHeight int, graphCaption string, axisArray []ltaas.JobResultsAxis) string {
values, valid := getGraphValues(axisArray)
if !valid {
return ""
}

return asciigraph.Plot(values, asciigraph.Caption(graphCaption), asciigraph.Width(graphWidth), asciigraph.Height(graphHeight))
return asciigraph.Plot(getGraphValues(axisArray), asciigraph.Caption(graphCaption), asciigraph.Width(graphWidth), asciigraph.Height(graphHeight))
}

// getGraphValues returns the Y-axis values for provided axisArray, and a boolean indicating
// whether values are valid (contain at least 1 positive value), to workaround bug https://github.com/guptarohit/asciigraph/issues/17
func getGraphValues(axisArray []ltaas.JobResultsAxis) ([]float64, bool) {
// getGraphValues returns the Y-axis values for provided axisArray, or a single value of 0
// if no axis provided
func getGraphValues(axisArray []ltaas.JobResultsAxis) []float64 {
if len(axisArray) == 0 {
return []float64{0}
}

values := []float64{}
valid := false
for _, axis := range axisArray {
if axis.Y > 0 {
valid = true
}

values = append(values, axis.Y)
}

return values, valid
return values
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require (
github.com/blang/semver v3.5.1+incompatible
github.com/golang/mock v1.2.0
github.com/google/uuid v1.1.1
github.com/guptarohit/asciigraph v0.4.1
github.com/guptarohit/asciigraph v0.4.2-0.20191006150553-f9506970428c
github.com/iancoleman/strcase v0.0.0-20191112232945-16388991a334
github.com/mattn/go-runewidth v0.0.4 // indirect
github.com/mitchellh/go-homedir v1.1.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/guptarohit/asciigraph v0.4.1 h1:YHmCMN8VH81BIUIgTg2Fs3B52QDxNZw2RQ6j5pGoSxo=
github.com/guptarohit/asciigraph v0.4.1/go.mod h1:9fYEfE5IGJGxlP1B+w8wHFy7sNZMhPtn59f0RLtpRFM=
github.com/guptarohit/asciigraph v0.4.2-0.20191006150553-f9506970428c h1:lj/KuGMoYzVEYbzLoWLv7O4acsyH/K/qUxWbo/P70sU=
github.com/guptarohit/asciigraph v0.4.2-0.20191006150553-f9506970428c/go.mod h1:9fYEfE5IGJGxlP1B+w8wHFy7sNZMhPtn59f0RLtpRFM=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
Expand Down

0 comments on commit dc5d5ba

Please sign in to comment.