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 (finally) bug with tooltips when multiple charts on one page. #96

Closed
wants to merge 1 commit into from

Conversation

ralphwetzel
Copy link
Contributor

Hi!
I as well encountered #88, yet #89 hasn't solved the issue for me.
Therefore I created this minor mod to fix #88 finally.

Best Regards, Ralph

@drewnoakes
Copy link
Collaborator

Looks good. Can you explain why you renamed the callback properties?

@ralphwetzel
Copy link
Contributor Author

With the current implementation I've seen something best described as a scoping issue.

  1. mousemove is used to name a property as well as a function.
  2. this.canvas.addEventListener('mousemove', this.mousemove); was intended to provide the property as callback for the event. It yet provided the (raw) function.
  3. As a result, when the event called the callback function for the first time, var el = this.getTooltipEl(); found no associated this.tooltipEl and created an additional one.
  4. All the manipulations in SmoothieChart.prototype.mousemove were then affecting this wrongly created, additional tooltip item.

The easiest way - for me - to compensate for that misbehavior was to get rid of the potential ambiguity due to the scope by defining an explicit name for the callback properties.

@drewnoakes
Copy link
Collaborator

mousemove is a property, the value of which is a function. I don't believe there's any reason to rename it as such, though I might be missing something. Any issue around scoping likely applies to the value of this, which is why it we use .bind(this) when re-assigning it to itself.

The SmoothieChart.tooltipEl to this.tooltipEl change is definitely a bug fix though. I've merged that as 59521ce.

If you believe there's still a bug, please provide a repro for it.

@drewnoakes drewnoakes closed this Dec 29, 2017
@ralphwetzel
Copy link
Contributor Author

I am patching SmoothieChart ... and this definitely creates an issue with the scope of this.
Yet, as I found a way to solve this within my patch, there's no more need to alter your code.

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.

Tool tips not working when multiple charts used on a page
2 participants