Skip to content

Conditional date formatting in time axis #85

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

Closed
Bascht74 opened this issue Oct 25, 2022 · 9 comments
Closed

Conditional date formatting in time axis #85

Bascht74 opened this issue Oct 25, 2022 · 9 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@Bascht74
Copy link

Bascht74 commented Oct 25, 2022

Hi,

Could the date be shown in the time axis as the normal historiy graph?
In the history graph the date is shown instead of "00:00" which is kind of nice as it saves one line.
image

Thx for your great work,

Sebastian

@dbuezas
Copy link
Owner

dbuezas commented Oct 28, 2022

Hey Sebastian!
All three are very good points. I'd indeed appreciate it if you did 3 entries, so I can tackle them independently :)

@Bascht74 Bascht74 changed the title show date in time axis, local time and use more space. show date in time axis Oct 28, 2022
@Bascht74
Copy link
Author

Hey Sebastian! All three are very good points. I'd indeed appreciate it if you did 3 entries, so I can tackle them independently :)

Done :-)

Thx again for fixing the title formatting.

Sebastian

@dbuezas
Copy link
Owner

dbuezas commented Oct 29, 2022

If you want to give it a try yourself, you can find a good template and other props from here https://plotly.com/javascript/reference/#layout-xaxis-tickformat
These can be tested directly from the yaml.
If you manage to get the output from the other card, I'll definitely adopt it!

@dbuezas
Copy link
Owner

dbuezas commented Oct 29, 2022

I investigated a bit and now think this won't work.
I see only two options:

  1. Modifying Plotly's source code and change their date formatter like this developer
  2. Implementing the tick algorithm from scratch and passing the array of ticks to show directly, like this

The downside of implementing the algorithm from scratch is that it will limit how configurable things are. Also, I think it is not a trivial task (except if one finds a good library, potentially a d3 formatter)

update: I now thing I was wrong here.
update: it is possible to format the ticks depending on the zoom level, but not to change only some to show the day instead of the hour.
I now think (2) is the only reasonable way

@dbuezas
Copy link
Owner

dbuezas commented Oct 29, 2022

After some trial and error, I got this, but it is too ugly to use.
Help welcomed :)
custom x axis formatting

The issue here, is that the axis labels can not be set while scrolling/zooming

@dbuezas dbuezas added the help wanted Extra attention is needed label Oct 29, 2022
@dbuezas
Copy link
Owner

dbuezas commented Oct 30, 2022

Here's an example using tickformatstops, but there seems to be no way to make it show the (for example) year in the tick where it changes, while only showing the month in subsequent ones

https://codepen.io/plotly/pen/roZORo

@dbuezas dbuezas added the enhancement New feature or request label Oct 31, 2022
@dbuezas dbuezas changed the title show date in time axis Conditional date formatting in time axis Dec 26, 2022
@wrowlands3
Copy link

After some trial and error, I got this, but it is too ugly to use. Help welcomed :) custom x axis formatting custom x axis formatting

The issue here, is that the axis labels can not be set while scrolling/zooming

@dbuezas How did you format the yaml for tickformatstops? I've tried to use the example you posted but cannot seem to get any tickformatstops to work.

@dbuezas
Copy link
Owner

dbuezas commented Jan 18, 2023

How did you format the yaml for tickformatstops?

master...experiment/custom-date-formatter#diff-c0352c6cdab9f9d6e1251e51657ccfc84873e2c7b361622d9aa4094c04c11093

At the moment it can't be done with yaml alone. Soon it will be possible, once #130 is finished.

@dbuezas
Copy link
Owner

dbuezas commented Jan 29, 2023

I gave up on this. I'll close it, but feel free to open it again if you have any new implementation idea :)

@dbuezas dbuezas closed this as completed Feb 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants