Skip to content
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

Merged
merged 19 commits into from
Dec 16, 2019

Conversation

etimberg
Copy link
Member

@etimberg etimberg commented Dec 8, 2019

Based on #2960
Resolves #2164

Center horizontal scales draw in the center of the chart area, rather than at the bottom.

center axis

To Do

  • Decide on the best implementation in the layout system for these boxes
  • Implement centerVertical mode
  • Sample file
  • Documentation
  • Testing

Center horizontal scales draw in the center of
the chart area, rather than at the bottom
Copy link
Member

@kurkle kurkle left a 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

src/core/core.layouts.js Outdated Show resolved Hide resolved
src/core/core.layouts.js Outdated Show resolved Hide resolved
@etimberg
Copy link
Member Author

etimberg commented Dec 8, 2019

I added support for center Y axes too

center both axes

Copy link
Member

@kurkle kurkle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some nits

src/core/core.controller.js Outdated Show resolved Hide resolved
src/core/core.scale.js Outdated Show resolved Hide resolved
@etimberg etimberg marked this pull request as ready for review December 8, 2019 21:33
@etimberg
Copy link
Member Author

etimberg commented Dec 8, 2019

@kurkle I have the position='y=..' mode working locally. You have to specify a positionAxisID so that the axis knows how to look up the position using the other axis. Results for position='y=-20' are below

y= positioning

Edit: Now have x= mode working for vertical axes
x= mode

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
@etimberg
Copy link
Member Author

etimberg commented Dec 9, 2019

I pushed up support for y=... and x=... modes. Includes documentation & samples. Not sure what kinds of tests are appropriate here. All the text would have to be turned off for an image test

@kurkle
Copy link
Member

kurkle commented Dec 9, 2019

The variable position: Maybe use object instead,
position: {y: 500}
It would allow position: {x: 10, y: 50} for radial scale.
We could require the key to be axisID, removing the need for extra option for that.
(I did not actually look at the code yet, just pondering the config format)

@etimberg
Copy link
Member Author

etimberg commented Dec 9, 2019

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

Copy link
Member

@kurkle kurkle left a 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') {
Copy link
Member

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.

Copy link
Member

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.

Copy link
Member Author

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

src/core/core.controller.js Outdated Show resolved Hide resolved
src/core/core.controller.js Outdated Show resolved Hide resolved
@kurkle
Copy link
Member

kurkle commented Dec 9, 2019

Another question, does the a centered scale still reduce chartArea?

@etimberg
Copy link
Member Author

I updated this to use this format for the complex positions

position: {
  y: 20
}

@kurkle
Copy link
Member

kurkle commented Dec 13, 2019

Some lint errors, but looks good!

@etimberg
Copy link
Member Author

Sweet, I fixed the lint warnings

Copy link
Member

@kurkle kurkle left a 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

docs/axes/cartesian/README.md Outdated Show resolved Hide resolved
@etimberg
Copy link
Member Author

Will look into the test failures. Not sure what I broke.

@etimberg
Copy link
Member Author

I fixed the test failures. The cause was defaulting the axis option based on id[0]. Because if its x and the axis has a default position of left the code doesn't reassign the scale to the bottom.

For now, I removed the id[0] default. We could try removing the axis position defaults from the scale defaults and rely on the default position setting

@etimberg
Copy link
Member Author

I've added fixture based tests for this so its good to review

@benmccann
Copy link
Contributor

Looks good to me. I still think it'd be nice if axis weren't required, but otherwise am happy with it

@etimberg
Copy link
Member Author

@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) {
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Member Author

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

@etimberg etimberg merged commit 374b749 into chartjs:master Dec 16, 2019
@etimberg etimberg deleted the scales-middle-pos branch December 16, 2019 23:17
@etimberg etimberg added this to the Version 3.0 milestone Dec 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

have all 4 quadrants shown in line chart
3 participants