]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Fix tooltip animation when target changes while animating (#5005)
authorjcopperfield <33193571+jcopperfield@users.noreply.github.com>
Tue, 12 Dec 2017 23:43:17 +0000 (00:43 +0100)
committerEvert Timberg <evert.timberg+github@gmail.com>
Tue, 12 Dec 2017 23:43:17 +0000 (18:43 -0500)
* 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

src/core/core.controller.js
src/core/core.tooltip.js

index 17e6c3bfa6764c902a1f0edd2e3e3ed44635531c..6026e8620fb45ff91e695a8bfb847d93885ae487 100644 (file)
@@ -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]);
 
index 0072580dfbf1141ea046755a260990a56768d59a..9b09d76044369f649c03733115b23958f251abb8 100644 (file)
@@ -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;