-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
Allow axes to be centered on the chart area #6818
Conversation
Center horizontal scales draw in the center of the chart area, rather than at the bottom
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 like this is going to be fairly easy
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.
Some nits
@kurkle I have the |
Vertical axes can be moved left and right by specifying a position of `x=...` Horizontal axes can be moved up and down by specifying a position of `y=...` Update sample to show multiple possible positions
I pushed up support for |
The variable position: Maybe use object instead, |
I'll have to look and see how that goes. It might work, but I can foresee some validation challenges. I won't get to this until tomorrow (Dec. 10) evening so I can ponder on it until then |
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.
quick read
borderValue = alignBorderValue(me.left); | ||
x1 = chartArea.left; | ||
x2 = alignBorderValue(chartArea.right) - axisHalfWidth; | ||
tx1 = borderValue + axisHalfWidth; | ||
tx2 = me.left + tl; | ||
} else if (axis === 'x') { |
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 think I'd rather put this logic in layouts
and set a variable, borderPixel
for example, to the scale (box). And use the variable here and in _computeLabelItems
.
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.
or just set the top/bottom correctly and use those here as if this was a bottom scale.
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 initial thought was to use the layout system as well. The reason I didn't was that it would mean that the layout system would have to differentiate scales from other boxes. I wasn't sure if that was going to work long-term or not
Another question, does the a centered scale still reduce chartArea? |
This avoids needing to parse a config string.
I updated this to use this format for the complex positions
|
Some lint errors, but looks good! |
Sweet, I fixed the lint warnings |
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.
Another quick look and not much to comment. Needs some tests, maybe couple image based without labels?
Edit: Oh, and some tests are failing
Will look into the test failures. Not sure what I broke. |
I fixed the test failures. The cause was defaulting the For now, I removed the |
I've added fixture based tests for this so its good to review |
Looks good to me. I still think it'd be nice if |
@benmccann I removed the axis defaults, and handled it correctly. Now we can use the first character of the axis ID to determine if its horizontal or vertical |
function positionIsHorizontal(position) { | ||
return position === 'top' || position === 'bottom'; | ||
const WELL_KNOWN_POSITIONS = ['top', 'bottom', 'left', 'right', 'chartArea']; | ||
function positionIsHorizontal(position, axis) { |
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.
can we just do axis === 'x'
instead?
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.
We might now that I removed default positions. Before I did that, it would override the fact that the position was wrong and the config would not be updated.
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.
Tried this. It breaks the default position fixing because it overrides the wrong axis position value. Lets leave as is for now
Based on #2960
Resolves #2164
Center horizontal scales draw in the center of the chart area, rather than at the bottom.
To Do