mirror of
https://github.com/chartjs/Chart.js.git
synced 2026-03-04 07:24:02 +01:00
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:
@@ -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');
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user