Giter Site home page Giter Site logo

Print X-Axis values about asciigraph HOT 4 OPEN

guptarohit avatar guptarohit commented on July 23, 2024 9
Print X-Axis values

from asciigraph.

Comments (4)

medzernik avatar medzernik commented on July 23, 2024 4

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

from asciigraph.

medzernik avatar medzernik commented on July 23, 2024 1

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

from asciigraph.

neymarsabin avatar neymarsabin commented on July 23, 2024 1

@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.

from asciigraph.

neymarsabin avatar neymarsabin commented on July 23, 2024

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

from asciigraph.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.