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

Bar options should not be defined on scale #6249

Merged
merged 4 commits into from Oct 25, 2019
Merged

Conversation

benmccann
Copy link
Contributor

@benmccann benmccann commented May 7, 2019

Moves the bar options barPercentage, barThickness, categoryPercentage, minBarLength, and maxBarThickness from scale defaults to bar dataset defaults.

Closes #5134 #4587 #4096

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.

I'd first merge #5621 and rebase / refactor this to utilize changes in that.

src/controllers/controller.bar.js Outdated Show resolved Hide resolved
docs/charts/bar.md Outdated Show resolved Hide resolved
@benmccann
Copy link
Contributor Author

I've rebased on to #5621 but I'm not sure it's really possible to use those changes to help much since this has to support reading the values from the scale options for backwards compatibility

@nagix
Copy link
Contributor

nagix commented May 11, 2019

My concern is that the "category width" is calculated per scale, and categoryPercentage and barThickness (when 'flex' or default) should be common between datasets on the same scale. So, it seems to be natural that those two options belong to a scale, and other options including barThickness with a number value belong to a dataset.

By the way, these options might be able to be indexable and scriptable. If they are dataset options, they can be resolved in _resolveDataElementOptions and used in calculateBarIndexPixels/calculateBarValuePixels . In order to support scale options for backward compatibility, we can override _resolveDataElementOptions to add extra logic like the bubble controller.

@benmccann
Copy link
Contributor Author

and categoryPercentage and barThickness (when 'flex' or default) should be common between datasets on the same scale

I actually like that this is more configurable and I'm not sure why they would have to be common. If you want one thick bar and one thin bar I don't see an issue with that. However, if you'd like to have them be common, you can still do that by setting options.datasets.bar.barPercentage

we can override _resolveDataElementOptions

Yeah, good idea. Done!

@nagix
Copy link
Contributor

nagix commented May 22, 2019

I actually like that this is more configurable and I'm not sure why they would have to be common. If you want one thick bar and one thin bar I don't see an issue with that.

It is completely fine to set barPercentage per dataset. But, if you have different categoryPercentage values in the datasets in the same group, the result will be corrupted (See barPercentage vs categoryPercentage). Similarly, if one dataset has barThickness: 'flex' and the other doesn't define it, the result will also be inconsistent.

I realized that both categoryPercentage and barThickness should be unique to neither a dataset nor a scale, but to a stack group.

Edit: The comment above was not correct. A stack group is used to group multiple bars into a stack but the group is nothing to do with categoryPercentage/barThickness.

However, if you'd like to have them be common, you can still do that by setting options.datasets.bar.barPercentage.

This may be acceptable, and it makes more sense than having these options in a scale.

Edit: So, these options are unique to a scale. I think they are still better to be dataset's options, though.

@benmccann benmccann force-pushed the bar-opts branch 2 times, most recently from 97f4a75 to 8d67984 Compare June 25, 2019 16:24
kurkle
kurkle previously approved these changes Sep 4, 2019
@benmccann
Copy link
Contributor Author

@kurkle thanks for approving this PR earlier. I just rebased it to fix merge conflicts with recent commits. Mind giving it another look?

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 good, one minimization thing can be fixed and I'd add some fixture tests for mixed configuration between datasets (if the results are acceptable).
If results are bad , just add note / issue / todo / comment

Comment on lines 71 to 73
var min = helpers.isNullOrUndef(options.barThickness)
? computeMinSampleSize(ruler.scale, ruler.pixels)
: -1;
Copy link
Member

@kurkle kurkle Oct 24, 2019

Choose a reason for hiding this comment

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

So after this barThickness can be changed between datasets?
I think a fixture test for this would be good addition.

thickness instead of options.barThickness

Also I'm curious what happens if datasets with mixed barThickness are stacked?

Copy link
Contributor Author

@benmccann benmccann Oct 24, 2019

Choose a reason for hiding this comment

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

I've fixed the minimization and added a test. Here's the image I added for the test:

download

Copy link
Member

@kurkle kurkle Oct 24, 2019

Choose a reason for hiding this comment

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

Thanks, but I don't see that test committed? I'd same without stacking too (if it works alright)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops. Looks like I forgot to push the commit earlier. Done now!

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if that other test provides anything new; I was thinking multiple unstacked datasets with mixed barThickness. (So same config as in stacked one, but just with stacked: false)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. I've made it so that there are multiple datasets now

etimberg
etimberg previously approved these changes Oct 24, 2019
@benmccann benmccann requested a review from kurkle October 25, 2019 05:04
exwm pushed a commit to exwm/Chart.js that referenced this pull request Apr 30, 2021
* Bar options should not be defined on scale

* Improve minimization

* Add tests

* Multiple datasets in test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants