]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Only call custom tooltips when elements have changed. But be sure to call update... 1602/head
authorTanner Linsley <tannerlinsley@gmail.com>
Sun, 1 Nov 2015 20:56:36 +0000 (13:56 -0700)
committerTanner Linsley <tannerlinsley@gmail.com>
Sun, 1 Nov 2015 20:56:36 +0000 (13:56 -0700)
samples/line-customTooltips.html
src/core/core.controller.js
src/core/core.tooltip.js

index 193fa3b82314def98de2ce3e56173fcef4ee7539..75412d441012dd36f98d60c5217ae9b79512127d 100644 (file)
     <canvas id="chart1" width="300" height="100" />
   </div>
   <script>
+    window.count = 0;
     Chart.defaults.global.pointHitDetectionRadius = 1;
     var customTooltips = function(tooltip) {
 
-      console.log(tooltip);
+      console.log(window.count++, tooltip);
 
       // Tooltip Element
       var tooltipEl = $('#chartjs-tooltip');
index 6663229f9da943b2668a6e59abe3f5730766c42f..91592779a3ea09d3c8cc770362fb2304a98950bd 100644 (file)
                                // The usual updates
                                this.tooltip.initialize();
                                this.tooltip._active = this.tooltipActive;
+                               this.tooltip.update();
                        }
 
                        // Hover animations
                                        (this.lastTooltipActive.length !== this.tooltipActive.length) ||
                                        changed) {
 
+                                       this.stop();
+
                                        if (this.options.tooltips.enabled || this.options.tooltips.custom) {
-                                               this.tooltip.update();
+                                               this.tooltip.update(true);
                                        }
-                                       this.stop();
 
                                        // We only need to render at this point. Updating will cause scales to be recomputed generating flicker & using more
                                        // memory than necessary.
index b8ec75b3a74680ce90f7c547ffc480e49fd723a4..b93bbe17b01e86cd12974ee70ba18ad814f73395 100644 (file)
                        return lines;
                },
 
-               update: function() {
+               update: function(changed) {
 
                        var ctx = this._chart.ctx;
 
                                this._model.opacity = 0;
                        }
 
-                       if (this._options.tooltips.custom) {
+                       if (changed && this._options.tooltips.custom) {
                                this._options.tooltips.custom.call(this, this._model);
                        }
 
                },
                draw: function() {
 
+
                        var ctx = this._chart.ctx;
                        var vm = this._view;