-
Notifications
You must be signed in to change notification settings - Fork 12k
Added a maxBarThickness setting for bar charts xAxis
#3963
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
Conversation
src/controllers/controller.bar.js
Outdated
| return xScale.options.stacked ? ruler.categoryWidth * xScale.options.barPercentage : ruler.barWidth; | ||
| barWidth = xScale.options.stacked ? ruler.categoryWidth * xScale.options.barPercentage : ruler.barWidth; | ||
| if (maxBarThickness && (barWidth > maxBarThickness)) { | ||
| return maxBarThickness; |
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 this could be slightly simpler with:
if (maxBarThickness) {
barWidth = Math.min(barWidth, maxBarThickness);
}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.
Cool. What about:
barWidth = xScale.options.stacked ? ruler.categoryWidth * xScale.options.barPercentage : ruler.barWidth;
return Math.min(barWidth, maxBarThickness || Infinity);
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 that would also work 😄
etimberg
left a comment
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 my one comment. Would love to get @potatopeelings to look at this too since he's done a lot of bar stuff
|
Weird, |
|
@seven7seven - you'll also need to change the horizontalBar equivalent (https://github.com/seven7seven/Chart.js/blob/9db4950b30a00d694c99fbd5e2bcb6b9e8842cc1/src/controllers/controller.bar.js#L469-L477) Also, mostly nitpicking, I'd move the Cheers! |
|
I would also cache |
|
@potatopeelings Agree with the |
|
@seven7seven - sounds good. Cheers! |
|
@potatopeelings Any tips on how to refactor the duplicated code? How important do you feel that is? |
|
@seven7seven - if you mean the duplication between bar and horizontalBar, that would be best done in a separate issue (perhaps #2466 or possibly a new one). Most of it can be refactored by making adding 2 more variables (the base axis and the measurement axis) that would be x and y for bar and y and x for horizontalBar and changing the method names to be orientation agnostic (eg. calculateBarThickness, instead of calculateBarWidth and calculateBarHeight). There are however a couple of places (eg. the rectangle properties) where this won't work. |
|
What's the release strategy with this one for example? Minor 2.5 release, or wait for 2.6? |
Added a `maxBarThickness` setting for bar charts xAxis
Added a `maxBarThickness` setting for bar charts xAxis
Fixes #3036