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.68k stars 102 forks source link

Panics if data is flat #7

Closed xordspar0 closed 6 years ago

xordspar0 commented 6 years ago

If each data point in the input is the same, asciigraph panics. This can be demonstrated simply using the command line interface:

> echo 1 1 | asciigraph
panic: runtime error: index out of range

goroutine 1 [running]:
github.com/guptarohit/asciigraph.Plot(0xc420057c18, 0x2, 0x40, 0xc420057eb8, 0x4, 0x4, 0x17, 0x115f6c0)
        /home/me/go/src/github.com/guptarohit/asciigraph/asciigraph.go:92 +0x1525
main.main()
        /home/me/go/src/github.com/guptarohit/asciigraph/cmd/asciigraph/main.go:56 +0x5e0

I've also written a test that demonstrates it: https://github.com/xordspar0/asciigraph/commit/f02e7a51539d4db8dff95971007e1b208e30ff41

xordspar0 commented 6 years ago

There's a division by zero when calculating the ratio at asciigraph.go:35.