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.67k stars 100 forks source link

Number formatting #57

Open ripienaar opened 3 weeks ago

ripienaar commented 3 weeks ago

I often have to graph bytes or large numbers. It would be helpful if I could pass a function in that can be used to format the number shown, something like:

        memPlot := asciigraph.Plot(memUsed,
            asciigraph.Caption("Memory Storage"),
            asciigraph.FormatValue(func(v float64) string {
                        return humanize.IBytes(v)
            }),
            asciigraph.Width(width))

You'd call that when rendering the numbers

If you think this is a good idea I can try to contribute that, just wanted to sniff test the idea with you first @guptarohit

ripienaar commented 3 weeks ago

Something like https://github.com/guptarohit/asciigraph/pull/58

guptarohit commented 1 week ago

@ripienaar Thank you for bringing up this interesting use case and for submitting a pull request to address it. I'll review and merge it as soon as possible.