Skip to content

Conversation

@seven7seven
Copy link
Contributor

Fixes #3036

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;
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 this could be slightly simpler with:

if (maxBarThickness) {
  barWidth = Math.min(barWidth, maxBarThickness);
}

Copy link
Contributor Author

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);

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 that would also work 😄

Copy link
Member

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

@seven7seven
Copy link
Contributor Author

Weird, gulp coverage runs fine locally w/ the same node version. Also weird how it didn't fail on the test earlier, nothing related seems to have changed w/ the last commit.

@potatopeelings
Copy link
Contributor

@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 || Infinity to where maxBarThickness its initialised and the barWidth declaration to where its initialised.

Cheers!

@simonbrunel
Copy link
Member

simonbrunel commented Feb 28, 2017

I would also cache var options = xScale.options.

@seven7seven
Copy link
Contributor Author

@potatopeelings Agree with the || Infinity, but I reckon moving barWidth to where it's declared will be considerably slower in the case that xScale.options.barThickness is set, i.e. barWidth would be computed then discarded.

@potatopeelings
Copy link
Contributor

@seven7seven - sounds good. Cheers!

@seven7seven
Copy link
Contributor Author

@potatopeelings Any tips on how to refactor the duplicated code? How important do you feel that is?

@potatopeelings
Copy link
Contributor

@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.

@seven7seven
Copy link
Contributor Author

What's the release strategy with this one for example? Minor 2.5 release, or wait for 2.6?

@simonbrunel simonbrunel added this to the Version 2.6 milestone Mar 3, 2017
@etimberg etimberg merged commit 5234899 into chartjs:master Mar 4, 2017
roicos pushed a commit to roicos/Chart.js that referenced this pull request Aug 21, 2017
Added a `maxBarThickness` setting for bar charts xAxis
exwm pushed a commit to exwm/Chart.js that referenced this pull request Apr 30, 2021
Added a `maxBarThickness` setting for bar charts xAxis
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.

4 participants