Only call custom tooltips when elements have changed. But be sure to call update internally any time that tooltips need to be redrawn.

This commit is contained in:
Tanner Linsley
2015-11-01 13:56:36 -07:00
parent cf587122da
commit f4a5a30451
3 changed files with 10 additions and 6 deletions

View File

@@ -42,10 +42,11 @@
<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');

View File

@@ -459,6 +459,7 @@
// The usual updates
this.tooltip.initialize();
this.tooltip._active = this.tooltipActive;
this.tooltip.update();
}
// Hover animations
@@ -484,11 +485,12 @@
(this.lastTooltipActive.length !== this.tooltipActive.length) ||
changed) {
if (this.options.tooltips.enabled || this.options.tooltips.custom) {
this.tooltip.update();
}
this.stop();
if (this.options.tooltips.enabled || this.options.tooltips.custom) {
this.tooltip.update(true);
}
// We only need to render at this point. Updating will cause scales to be recomputed generating flicker & using more
// memory than necessary.
this.render(this.options.hover.animationDuration, true);

View File

@@ -193,7 +193,7 @@
return lines;
},
update: function() {
update: function(changed) {
var ctx = this._chart.ctx;
@@ -262,7 +262,7 @@
this._model.opacity = 0;
}
if (this._options.tooltips.custom) {
if (changed && this._options.tooltips.custom) {
this._options.tooltips.custom.call(this, this._model);
}
@@ -270,6 +270,7 @@
},
draw: function() {
var ctx = this._chart.ctx;
var vm = this._view;