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

fix global configuration for hoverBorderWidth #5801

Closed
wants to merge 6 commits into from

Conversation

Niladri24dutta
Copy link
Contributor

Fixes #5775

  • fix global configuration for hoverBorderWidth, previously the hoverBorderWidth was not applied to chart if it was set at global elements level.

@@ -337,7 +337,7 @@ module.exports = function(Chart) {

model.backgroundColor = custom.hoverBackgroundColor || helpers.valueAtIndexOrDefault(dataset.pointHoverBackgroundColor, index, helpers.getHoverColor(model.backgroundColor));
model.borderColor = custom.hoverBorderColor || helpers.valueAtIndexOrDefault(dataset.pointHoverBorderColor, index, helpers.getHoverColor(model.borderColor));
model.borderWidth = custom.hoverBorderWidth || helpers.valueAtIndexOrDefault(dataset.pointHoverBorderWidth, index, model.borderWidth);
model.borderWidth = custom.hoverBorderWidth || helpers.valueAtIndexOrDefault(dataset.pointHoverBorderWidth, index, this.chart.options.elements.point.hoverBorderWidth);
Copy link
Contributor

@benmccann benmccann Oct 31, 2018

Choose a reason for hiding this comment

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

What if none of custom.hoverBorderWidth, dataset.pointHoverBorderWidth, this.chart.options.elements.point.hoverBorderWidth are set? Don't we still need to fall back to model.borderWidth in that case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@benmccann in this case can we use a ternary expression to fall back to model.borderWidth if both the conditions in || are 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.

as per this line of code https://github.com/chartjs/Chart.js/blob/master/src/helpers/helpers.core.js#L70 I was referring to something like this
model.borderWidth = custom.hoverBorderWidth || helpers.valueAtIndexOrDefault(dataset.pointHoverBorderWidth, index, this.chart.options.elements.point.hoverBorderWidth ? this.chart.options.elements.point.hoverBorderWidth : model.borderWidth);

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you could write that as:

model.borderWidth = custom.hoverBorderWidth || helpers.valueAtIndexOrDefault(dataset.pointHoverBorderWidth, index, helpers.valueOrDefault(this.chart.options.elements.point.hoverBorderWidth, model.borderWidth));

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, since there are two lines that now refer to this.chart.options.elements.point I would refactor that out and create a variable at the beginning of this method with something like: var pointOpts = this.chart.options.elements.point;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@benmccann I have made the suggested changes in my branch. Can you please let me know if I have missed anything?

@Niladri24dutta
Copy link
Contributor Author

@benmccann Can you please let me know if my proposed change looks fine, I will make the changes in my branch if it's matches the requirement.

@@ -327,6 +327,7 @@ module.exports = function(Chart) {
var index = element._index;
var custom = element.custom || {};
var model = element._model;
var pointOpts = this.chart.options.elements.point;
Copy link
Contributor

Choose a reason for hiding this comment

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

there's a trailing space on this line that's causing the build to fail

Copy link
Contributor

Choose a reason for hiding this comment

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

this PR looks good to me after the trailing space is fixed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@benmccann I have removed the extra space and the build is successful . Can you please check now?

@Niladri24dutta
Copy link
Contributor Author

@benmccann I have made the suggested changes , Can you please check and let me know if anything else required

@Niladri24dutta
Copy link
Contributor Author

@benmccann thank you for approving and merging my changes.

@Niladri24dutta
Copy link
Contributor Author

@benmccann Hi, I can see that the original issue is still open , is this PR already merged?

@simonbrunel simonbrunel added this to the Version 2.8 milestone Nov 18, 2018
@Niladri24dutta
Copy link
Contributor Author

@simonbrunel just curious ,will this be merged during the v 2.8 release ?

Copy link
Member

@simonbrunel simonbrunel left a comment

Choose a reason for hiding this comment

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

While you are fixing this behavior for borderWidth, can you also fix the surrounding code (I think that's the exact same issue for backgroundColor and borderColor)?

Also, can you update the associated unit tests to prevent regressions?

@benmccann
Copy link
Contributor

@Niladri24dutta can you rebase this PR and address Simon's comment?

@Niladri24dutta
Copy link
Contributor Author

Niladri24dutta commented Jan 2, 2019

@Niladri24dutta can you rebase this PR and address Simon's comment?

@benmccann @simonbrunel Yes sure . But I have some doubts regarding the unit test case update . Which unit test cases should I update? I am not able reproduce the same scenario in the unit test cases.

@benmccann
Copy link
Contributor

You could probably add it to this one: https://github.com/chartjs/Chart.js/blob/master/test/specs/controller.line.tests.js#L185

If that doesn't work then you could write a new one

@kurkle
Copy link
Member

kurkle commented Feb 4, 2019

Fixed in #5973

@kurkle kurkle closed this Feb 4, 2019
@simonbrunel simonbrunel removed this from the Version 2.8 milestone Mar 12, 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.

[BUG] elements.point.hoverBorderWidth is not applied
4 participants