Document tooltip draw hooks and only call hooks when the tooltip draws (#10276)

* Document tooltip draw hooks and only call hooks when the tooltip draws

* Update tests
This commit is contained in:
Evert Timberg 2022-04-03 10:09:46 -04:00 committed by GitHub
parent 09128947d5
commit 43889f247c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 12 deletions

File diff suppressed because one or more lines are too long

Binary file not shown.

Before

Width:  |  Height:  |  Size: 76 KiB

After

Width:  |  Height:  |  Size: 100 KiB

View File

@ -917,6 +917,14 @@ export class Tooltip extends Element {
}
}
/**
* Determine if the tooltip will draw anything
* @returns {boolean} True if the tooltip will render
*/
_willRender() {
return !!this.opacity;
}
draw(ctx) {
const options = this.options.setContext(this.getContext());
let opacity = this.opacity;
@ -1127,19 +1135,19 @@ export default {
afterDraw(chart) {
const tooltip = chart.tooltip;
const args = {
tooltip
};
if (tooltip && tooltip._willRender()) {
const args = {
tooltip
};
if (chart.notifyPlugins('beforeTooltipDraw', args) === false) {
return;
}
if (chart.notifyPlugins('beforeTooltipDraw', args) === false) {
return;
}
if (tooltip) {
tooltip.draw(chart.ctx);
}
chart.notifyPlugins('afterTooltipDraw', args);
chart.notifyPlugins('afterTooltipDraw', args);
}
},
afterEvent(chart, args) {

View File

@ -1797,8 +1797,8 @@ describe('Chart', function() {
'beforeDatasetDraw',
'afterDatasetDraw',
'afterDatasetsDraw',
'beforeTooltipDraw',
'afterTooltipDraw',
// 'beforeTooltipDraw',
// 'afterTooltipDraw',
'afterDraw',
'afterRender',
],