Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/plugins/plugin.tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -1203,9 +1203,29 @@ export class Tooltip extends Element {
active.reverse();
}

// When persistOnHover is enabled, keep the tooltip visible while the cursor
// is over the tooltip bounding box (even after leaving the data point).
if (options.persistOnHover && !active.length && lastActive.length && this._isMouseOverTooltip(e)) {
return lastActive;
}

return active;
}

/**
* Returns true when the event position is inside the tooltip's rendered bounding box.
* @param {ChartEvent} e
* @returns {boolean}
* @private
*/
_isMouseOverTooltip(e) {
const {x, y, width, height, opacity} = this;
if (!opacity || isNullOrUndef(x) || isNullOrUndef(y)) {
return false;
}
return e.x >= x && e.x <= x + width && e.y >= y && e.y <= y + height;
}

/**
* Determine if the active elements + event combination changes the
* tooltip position
Expand Down Expand Up @@ -1276,6 +1296,7 @@ export default {
enabled: true,
external: null,
position: 'average',
persistOnHover: false,
backgroundColor: 'rgba(0,0,0,0.8)',
titleColor: '#fff',
titleFont: {
Expand Down
6 changes: 6 additions & 0 deletions src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2798,6 +2798,12 @@ export interface TooltipOptions<TType extends ChartType = ChartType> extends Cor
* @default true
*/
enabled: Scriptable<boolean, ScriptableTooltipContext<TType>>;
/**
* Keep the tooltip visible when the cursor moves from the data point into
* the tooltip bounding box.
* @default false
*/
persistOnHover: boolean;
/**
* See external tooltip section.
*/
Expand Down