asciigraph
asciigraph copied to clipboard
Print X-Axis values
Hi there, pretty awesome lib!
How complex would it be to add an option to print the x-axis in addition to the y-axis? I want to use your library in my fan2go project to print fan curve data to console, and it would be very helpful for users to see the x-axis values (0-255).
Thx!
I second this, I'd absolutely love to be able to use X axis too.
@guptarohit @medzernik Any updates on this issue? I need to have time values in the X-Axis.
@guptarohit @medzernik Any updates on this issue? I need to have time values in the X-Axis.
It's been a long while, but I remember going with my own date input. This is the code I used to sort of make it work with dates. I used this output in Discord and made sure the dates fit on various iOS devices as well as on the desktop:
package covid_slovakia
import (
"github.com/guptarohit/asciigraph"
)
// PrintLineASCII Prints the actual chart, gets the data as well as the labelstring to put in.
func PrintLineASCII(data []float64, dateStringStart, dateStringEnd string) string {
graphLabel := NormalizeXAxis(dateStringStart, dateStringEnd)
var chart string
// The length 22 is the magical number for correct formatting on iPhones (tested on iPhone 11 Pro and iPhone SE 2020)
// that's why we wrap it around when it's bigger than that. Height is 15
chart = asciigraph.Plot(data, asciigraph.Width(22), asciigraph.Height(15), asciigraph.Caption(graphLabel))
return chart
}
// NormalizeXAxis Inserts the X axis-like line at least, since there is no X axis...
func NormalizeXAxis(startDate, endDate string) string {
return "―――――――――――――――――――――\n\t" + startDate + " <-> " + endDate
}
// GetGraphReadyForDiscordPrint Simplifies the printout for reuse
func GetGraphReadyForDiscordPrint(input string) string {
return "**\n```go\n" + input + "```"
}