guptarohit / asciigraph

Go package to make lightweight ASCII line graph ╭┈╯ in command line apps with no other dependencies.
https://pkg.go.dev/github.com/guptarohit/asciigraph
BSD 3-Clause "New" or "Revised" License
2.64k stars 99 forks source link

Panic when no positive values provided #17

Closed 0x4c6565 closed 4 years ago

0x4c6565 commented 4 years ago

When no positive floats are provided to Plot(), a panic is observed:

Examples:

package main

import "github.com/guptarohit/asciigraph"

func main() {
    println(asciigraph.Plot([]float64{0}))
}
package main

import "github.com/guptarohit/asciigraph"

func main() {
    println(asciigraph.Plot([]float64{-1}))
}

Result:

PS C:\Users\Lee\test> go run .\main.go
panic: runtime error: index out of range

goroutine 1 [running]:
github.com/guptarohit/asciigraph.Plot(0xc00007df78, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0)
        C:/Users/Lee/go/pkg/mod/github.com/guptarohit/asciigraph@v0.4.1/asciigraph.go:92 +0x13aa
main.main()
        C:/Users/Lee/test/main.go:6 +0x67
exit status 2

Line 92 is as follows:

plot[rows-y0][config.Offset-1] = "┼" // first value
mrtvfuencxozd commented 4 years ago

Hi, In case you are still wondering, I just had a similar issue (in fact my problem was that there was no "range of values" but a single repeated one). Looking at it, I found that (for my case at least), this had been fixed in master.

Waiting for a new version, go get github.com/guptarohit/asciigraph@f9506970428c1d46 did it for me.

Pascal

guptarohit commented 4 years ago

@0x4c6565 this is fixed with the new release, please feel free to re-open if you still face the issue. :v:

0x4c6565 commented 4 years ago

Perfect, cheers @guptarohit !