mirror of
https://github.com/chartjs/Chart.js.git
synced 2024-10-06 04:09:08 +02:00
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:
parent
09128947d5
commit
43889f247c
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 |
@ -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) {
|
||||
|
@ -1797,8 +1797,8 @@ describe('Chart', function() {
|
||||
'beforeDatasetDraw',
|
||||
'afterDatasetDraw',
|
||||
'afterDatasetsDraw',
|
||||
'beforeTooltipDraw',
|
||||
'afterTooltipDraw',
|
||||
// 'beforeTooltipDraw',
|
||||
// 'afterTooltipDraw',
|
||||
'afterDraw',
|
||||
'afterRender',
|
||||
],
|
||||
|
Loading…
Reference in New Issue
Block a user