asciigraph icon indicating copy to clipboard operation
asciigraph copied to clipboard

Print X-Axis values

Open markusressel opened this issue 4 years ago • 4 comments

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!

markusressel avatar Aug 22 '21 15:08 markusressel

I second this, I'd absolutely love to be able to use X axis too.

medzernik avatar Oct 24 '21 14:10 medzernik

@guptarohit @medzernik Any updates on this issue? I need to have time values in the X-Axis.

neymarsabin avatar Feb 29 '24 10:02 neymarsabin

@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 + "```"
}

medzernik avatar Feb 29 '24 19:02 medzernik