-
Notifications
You must be signed in to change notification settings - Fork 178
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
Multi-line tick labels #460
Comments
Datawrapper does this well (see multi-line axis ticks): |
The code is not a problem once we agree on a spec. It's not clear to me if datawrapper's format is the way to go, but I can see how we would extend tickFormat to support \n for multiline, and \n? for a non-repeating second line, enabling this:
thumb up, down, or provide alternative ideas :) I'll send the PR tomorrow because it's already too late in this time zone. This should arguably be done in d3-axis instead of Plot. Acting on a \n in tick formats might be considered as a breaking change (at least visually speaking)—but it seems like a highly useful change? |
I think supporting \n is probably the way to go, yeah. I don’t understand how \n? works in your example above. How does it know not to render the year outside of January? I think more likely we’d implement a “multi-scale” format that’s similar to what d3-scale does, but using new lines. |
Ah, I see! Neat. I like that. The repetition rule applies to each line distinctly, then (not to % fields)? |
Yes the rule applies separately to each line. I made it avoid repetitions (i.e. remove consecutive labels, rather than enforce unicity), so that we can, for example, use it to display half-years or quarters:
|
Related #393, when the ticks represent a (time) interval, it’d be nice if the tick label were aligned to the start of the interval, rather than centered around the interval. |
In this example the year is show at for Q1, Let's assume the axis starts rendering from mid of Q1 or Q2. Do we add the year at Q2 or omit it? The timeline below starts from middle of the month. Still would prefer month and year to be part of the axis. |
Thank you for the feedback! The "non-repeat" rule, which I'm exploring here, means that 2020 and Dec would show in your example, even thought the 1st day of the year (or month) isn't present. |
As this was closed with #1197: can we now use I am doing this right now, but the formatting stays the same as without the |
@glennDittmann No, the conditional formatting is implemented internally to the default axes. You can see the formatConditional implementation in the source for how it works. We could file a separate feature request if you want shorthand for a conditional format. |
Thanks for the quick reply! For now I am fine with as it is now, thanks anyways. :) |
It would be useful to be able to make axes like this:
One way would be to support multi-line text labels.
Another option would be to allow SVG nodes to be used as ticks rather than coercing the output of
tickFormat
to a string, which is the current behavior.Here is a notebook which "almost works": https://observablehq.com/d/7de079c962f419f8
The text was updated successfully, but these errors were encountered: