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

Check for tooltip content before draw #4034

Merged
merged 2 commits into from
Mar 21, 2017

Conversation

samueljo
Copy link
Contributor

Tooltips without any content (i.e. no title, beforeBody, body, afterBody, footer) should not be drawn onto canvas as empty tooltips.

Add check for tooltip content in Core.Tooltip.draw.

@@ -789,7 +789,10 @@ module.exports = function(Chart) {
// IE11/Edge does not like very small opacities, so snap to 0
var opacity = Math.abs(vm.opacity < 1e-3) ? 0 : vm.opacity;

if (this._options.enabled) {
// Boolean for empty tooltip
var hasToolTipContent = Boolean(vm.title.length || vm.beforeBody.length || vm.body.length || vm.afterBody.length || vm.footer.length);
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 the explicit cast to a boolean is required here. Was this from your personal code style or am I missing something subtle?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not required but I thought it made the code a little bit more readable. I can remove it if it doesn't

Copy link
Member

Choose a reason for hiding this comment

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

Ok, lets leave it for now and see what @simonbrunel says. I have no real preference either way but I was leaning towards removing it just to keep the size down

Copy link
Member

Choose a reason for hiding this comment

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

I agree with @etimberg, I would remove it because it's obvious that's a boolean (a || b || c).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@etimberg @simonbrunel Okay sure thing, removed the boolean casting

@etimberg etimberg added this to the Version 2.6 milestone Mar 18, 2017
@samueljo
Copy link
Contributor Author

@etimberg Is there a recommended way to monkey patch the tooltip draw function until this is released in the next version?

@etimberg
Copy link
Member

@samueljo I think you can just override Chart.Tooltip.prototype.draw with the new function

@etimberg etimberg merged commit 8367f90 into chartjs:master Mar 21, 2017
roicos pushed a commit to roicos/Chart.js that referenced this pull request Aug 21, 2017
exwm pushed a commit to exwm/Chart.js that referenced this pull request Apr 30, 2021
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.

None yet

3 participants