Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print X-Axis values #28

Open
markusressel opened this issue Aug 22, 2021 · 4 comments
Open

Print X-Axis values #28

markusressel opened this issue Aug 22, 2021 · 4 comments
Labels
enhancement New feature or request

Comments

@markusressel
Copy link

markusressel commented Aug 22, 2021

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 markusressel changed the title Adding X-Axis values Print X-Axis values Aug 22, 2021
@medzernik
Copy link

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

@neymarsabin
Copy link

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

@medzernik
Copy link

medzernik commented Feb 29, 2024

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

@neymarsabin
Copy link

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

Thanks for the help @medzernik , I need to try this out, I am building a CLI app to plot my laptop's battery usage in the terminal. I am trying to visualize my battery level and cycle count with the help of the graph. https://github.com/neymarsabin/batterarch

I will try this implementation, but may write my own graph library if I need some other graphs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants