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
Better x axis label formatting [WIP] #7103
Conversation
Do days of the week come back as strings from the backend or are they mapped using moment? |
…xis.axis_enabled when they overlap
@salsakran they come back as numbers and we use |
Thanks. Yeah that’s the “don't rotate if not much vertical space” TODO |
693e439
to
5cbd5ad
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks reasonable. Main question was whether to leave the settings enabled in case we get something off.
@@ -316,6 +316,16 @@ export const GRAPH_AXIS_SETTINGS = { | |||
section: "Axes", | |||
title: t`Show x-axis line and marks`, | |||
widget: "toggle", | |||
// widget: "select", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this commented out? Thought we were going to leave it exposed.
chart.selectAll("g.x text").attr("transform", function() { | ||
const { width, height } = this.getBBox(); | ||
return `translate(-${width / | ||
2},${-height / 2}) rotate(${degrees}, ${width / 2}, ${height})`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
/^rotate-(\d+)$/, | ||
); | ||
if (match) { | ||
return -parseInt(match[1], 10); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just to state the obvious, this is because we want to read eg a 45 degree rotated label from lower left to upper right, rather than having it be read from upper left to lower right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it's rotating around the right edge of the label so we want to rotate it counter clockwise.
Actually i'm going to change this to return the un-negated rotation and negate it in onRenderRotateAxis
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add some comments too
const X_LABEL_MIN_SPACING = 2; // minimum space we want to leave between labels | ||
const X_LABEL_ROTATE_90_THRESHOLD = 24; // tick width breakpoint for switching from 45° to 90° | ||
const X_LABEL_HIDE_THRESHOLD = 12; // tick width breakpoint for hiding labels entirely | ||
const X_LABEL_MAX_LABEL_HEIGHT_RATIO = 0.7; // percent rotated labels are allowed to take |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My hunch is that 70% of the render area being taken up by labels is too high, but I'm down to wait until we see how this works on our internal instances before tweaking it further.
… causing integration test failure
23987b2
to
7b17309
Compare
Any reason we haven't closed out the issues that this PR resolves? |
Only that I got used to issues being autoclosed by PR merges. You're welcome to do the honors if you don't want to wait for me =) |
Hi guys, this feature is in v0.29.0-RC1? If yes, how can I test it? I'm using locally this version of Metabase (in docker) and I want to create a bar chart that has big strings in X axis (in a way they overlap) but I was not able to find where I can customize X axis labels' rotation. Is there some "control" of rotation? |
This PR resolves the following issues (which are all pretty much duplicates of each other):
TODO:
Ideas:
formatValue
with{ compact: true }
would prevent overlap?MIN_PIXELS_PER_TICK
for different date granularities?day
would be much larger thanyear
sinceJanuary 1, 2018
is much wider than2018