-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
[BUG] tooltip error with stacked (group) bar chart in demo pages #4989
Comments
Interesting that this is happening. I recall seeing this a while ago, but I thought it was fixed. My theory as to why this is happening:
|
I compared the handleEvent function in core.tooltip.js of version 2.5 and 2.7 and seems you added following code: // If tooltip didn't change, do not handle the target event
if (!changed) {
return false;
} And if i remove the code lines above the problem disappears. So I guess the code after that is still needed sometimes? Really hope this information helps. |
The problem is that the function Changing the order of execution resolves the problem codepen. // Remember Last Actives
changed = !helpers.arrayEquals(me._active, me._lastActive);
if (options.enabled || options.custom) {
me._eventPosition = {
x: e.x,
y: e.y
};
var model = me._model;
me.update(true);
me.pivot();
// See if our tooltip position changed
changed |= (model.x !== me._model.x) || (model.y !== me._model.y);
}
// If tooltip didn't change, do not handle the target event
if (!changed) {
return false;
}
me._lastActive = me._active; Unfortunately it fails one test due to calling |
I think the idea behind my original change was to avoid re-updating the model if the input elements have not changed since in theory the same input elements should lead to the same output model. Your proposed modification is probably safer though. I think any performance difference could be negligible but I’d have to profile and see. |
@etimberg I have to admit that I do not completely understand why it works, so maybe there is something else causing the weird behavior. |
@etimberg it turns out that only adding me._start = {};
// If tooltip didn't change, do not handle the target event
if (!changed) {
return false;
} |
|
@etimberg That I understood, however I don't understand why the when if (!changed) {
me.pivot();
return false;
} What is the task of the |
I think the bug is somewhere else. I think the current tooltip code is mostly correct in that we should only call One thought is perhaps https://github.com/chartjs/Chart.js/blob/master/src/core/core.tooltip.js#L853 is too simplistic. Maybe we need to sort the array in some way so that the comparison is true when the items are the same but the order is different. The downside is that if the order does change and the user wants that the tooltip wouldn't render. I'll try and do some debugging on this tonight and see where that gets me |
@etimberg an error on L853 cannot be the case, since the The following code resolves the problem and passes all tests; it only takes one extra call to /**
* Handle an event
* @private
* @param {IEvent} event - The event to handle
* @returns {Boolean} true if the tooltip changed
*/
handleEvent: function(e) {
var me = this;
var options = me._options;
var changed = false;
me._lastActive = me._lastActive || [];
// Find Active Elements for tooltips
if (e.type === 'mouseout') {
me._active = [];
} else {
me._active = me._chart.getElementsAtEventForMode(e, options.mode, options);
}
// Remember Last Actives
changed = !helpers.arrayEquals(me._active, me._lastActive);
// If tooltip didn't change, do not handle the target event
if (!changed) {
me.pivot(); // reset me._start for smooth animations issue #4989
return false;
}
me._lastActive = me._active;
if (options.enabled || options.custom) {
me._eventPosition = {
x: e.x,
y: e.y
};
var model = me._model;
me.update(true);
me.pivot();
// See if our tooltip position changed
changed |= (model.x !== me._model.x) || (model.y !== me._model.y);
}
return changed;
}
}); |
Good point @jcopperfield.
You're right! What's happening is that the hover state is changing which triggers a re-render because |
- tooltip in 'index' mode doesn't animate smoothly.
* Fix issue #4989 - tooltip in 'index' mode doesn't animate smoothly. * Change: different approach for smooth tooltip animation in 'index' mode, when target doesn't change. * Fix: jslint error * Fix: remove spyOn pivot from test * Add: setAnimating-flag in transition used to set on tooltip.transition to keep track of tooltip animation. * Decrease code complexity * Revert transition and complexity changes Add: use 'tooltip._start' as workaround check for tooltip animation status
* Fix issue chartjs#4989 - tooltip in 'index' mode doesn't animate smoothly. * Change: different approach for smooth tooltip animation in 'index' mode, when target doesn't change. * Fix: jslint error * Fix: remove spyOn pivot from test * Add: setAnimating-flag in transition used to set on tooltip.transition to keep track of tooltip animation. * Decrease code complexity * Revert transition and complexity changes Add: use 'tooltip._start' as workaround check for tooltip animation status
* Fix issue chartjs#4989 - tooltip in 'index' mode doesn't animate smoothly. * Change: different approach for smooth tooltip animation in 'index' mode, when target doesn't change. * Fix: jslint error * Fix: remove spyOn pivot from test * Add: setAnimating-flag in transition used to set on tooltip.transition to keep track of tooltip animation. * Decrease code complexity * Revert transition and complexity changes Add: use 'tooltip._start' as workaround check for tooltip animation status
Description
I noticed this bug [I think it would be a BUG] in the demo pages of the downloaded zip packages from GitHub, I tried 2.6.0/2.7.0/2.7.1 and they are the same. But this issue does not exists in 2.5.0
Expected Behavior
tooltip move back and forth smoothly when moving mouse pointer between bars
Current Behavior
the tooltip moves/shakes unexpectedly/unpredictably when moving mouse pointer between bars
Possible Solution
I tried setting the intersect to true and the problem was solved, so there might be some problem with this property?
Steps to Reproduce (for bugs)
Context
I just tried to use the stacked/stacked group bar chart and test it with the demos
Environment
Chartjs 2.6.0/2.7.0/2.7.1
Chrome 60.0.3112.78 64bit and IE 11.0.9600.18738
Windows 7 64bit
The text was updated successfully, but these errors were encountered: