tarkah / tickrs

Realtime ticker data in your terminal 📈
MIT License
1.17k stars 58 forks source link

Show x-axis time labels in charts #10

Closed daniel-j-h closed 3 years ago

daniel-j-h commented 3 years ago

Hey hey, this is a neat little tool - good stuff! :bow:

It would be immensly helpful to show not only the y-axis labels but also the x-axis time labels; this would make it much more useful.

tarkah commented 3 years ago

This is definitely something I've wanted to add. The API gives me the timestamps for each data point so that won't be too hard.

The challenge I see for this one will be figuring out how to format the date/times for each time frame and how many labels are able to fit within the view and make sense as to which column they are actually for.

Are you thinking just a start / middle / end label like on the Y axis?

tarkah commented 3 years ago

@daniel-j-h Hey, I pretty much have this finished! You can pass the following flag at runtime:

-x, --show-x-labels    Show x-axis labels

You can also press x inside the application to toggle the labels. Below are a couple screenshots. A couple things to note:

Let me know how you like it and if you'd prefer different formatting for the date/times displayed!

image image image

daniel-j-h commented 3 years ago

Amazing! :tada:

How do you come up with the labels? They look dynamically created and are sometimes hard to use for orientation. For example in the 5Y view it would be great to see start of the year for orientation :thinking:

Maybe a more natural and intuitive way could be to use for

What are your thoughts here? :hugs:

tarkah commented 3 years ago

I'm very limited with the library on how I can create labels. And if I create too many and the width of those labels is wider than the program, they just don't display :/

I have to pass an array of strings to use as the labels and the library renders them evenly from left to right. So if I pass an array of 2, it'll render at start and end. If I pass 3, it'll be start / middle / end. For 5, it'd be start, 25%, 50%, 75%, end.

So depending on how many labels I can make, I have to calculate which datapoints exist at those increments so they lineup somewhat accurately. Does this make sense? I honestly don't know how I can do it differently while guaranteeing the labels line up AND will display.

tarkah commented 3 years ago

I just had a thought on something I could try. I can push single space strings into the array to better control where the labels show up.

I can see if I can find a way to do that with the increments you recommended. I just don't know if it'll be possible to accurately calculate where to insert those labels at in the array to have them line up accurately with the datapoints that start each new increment.

tarkah commented 3 years ago

@daniel-j-h I'm not having any luck getting the labels to work any differently than I currently have them. This is the best solution I can come up with using the library I'm using.

Do you think this is good to merge in it's current state, or should this be held off until a better solution comes along? It's currently opt in (labels aren't shown by default), so I don't see any issue merging it in the current state and improving it down the road if possible.

Regardless, I'll create a new release later today to get out all the changes from this week.

daniel-j-h commented 3 years ago

:wave: Hey hey - not sure I can give you input here, I don't know the limitations of the underlying plotting lib :see_no_evil: I'm wondering if we have to show actual labels, or if we can just show a marker like a + or a | on the x axis for the "natural increments"?

tarkah commented 3 years ago

Yeah, I can't even do that unfortunately because I just can't guarantee placement of the labels line up with those "natural increments". I'm stuck just dividing up the dataset into equal chunks and creating a label for the first datapoint of each chunk since that's how the labels will get evenly rendered.

Ok, I'll go ahead and merge this. I think it's better to have it in its current state than not! Thanks for all your suggestions and feedback!!

tarkah commented 3 years ago

@daniel-j-h new release is published to the repo and to Crates.io

daniel-j-h commented 3 years ago

Checking it out! Thanks a lot, this is amazing! :bow: