Skip to content

Commit

Permalink
Fix tooltip animation when target changes while animating (chartjs#5005)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jcopperfield authored and etimberg committed Dec 12, 2017
1 parent 170cdc7 commit bb5598a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
10 changes: 9 additions & 1 deletion src/core/core.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,15 @@ module.exports = function(Chart) {
me._bufferedRequest = null;

var changed = me.handleEvent(e);
changed |= tooltip && tooltip.handleEvent(e);
// for smooth tooltip animations issue #4989
// the tooltip should be the source of change
// Animation check workaround:
// tooltip._start will be null when tooltip isn't animating
if (tooltip) {
changed = tooltip._start
? tooltip.handleEvent(e)
: changed | tooltip.handleEvent(e);
}

plugins.notify(me, 'afterEvent', [e]);

Expand Down
32 changes: 13 additions & 19 deletions src/core/core.tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -852,25 +852,19 @@ module.exports = function(Chart) {
// Remember Last Actives
changed = !helpers.arrayEquals(me._active, me._lastActive);

// If tooltip didn't change, do not handle the target event
if (!changed) {
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);
// Only handle target event on tooltip change
if (changed) {
me._lastActive = me._active;

if (options.enabled || options.custom) {
me._eventPosition = {
x: e.x,
y: e.y
};

me.update(true);
me.pivot();
}
}

return changed;
Expand Down

0 comments on commit bb5598a

Please sign in to comment.