Skip to content

Commit

Permalink
fix #4869; custom tooltip can return html element
Browse files Browse the repository at this point in the history
  • Loading branch information
junedchhipa committed Dec 17, 2024
1 parent d214fe8 commit 17a15aa
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/modules/tooltip/Labels.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ export default class Labels {
if (typeof yLbTitleFormatter !== 'function') {
yLbTitleFormatter = function (label) {
// refrence used from line: 966 in Options.js
return label ? label + ': ' : ''
return label ? label + ': ' : ''
}
}

Expand Down Expand Up @@ -523,8 +523,7 @@ export default class Labels {
fn = fn[i]
}

// override everything with a custom html tooltip and replace it
tooltipEl.innerHTML = fn({
const customTooltip = fn({
ctx: this.ctx,
series: w.globals.series,
seriesIndex: i,
Expand All @@ -533,5 +532,15 @@ export default class Labels {
y2,
w,
})

if (typeof customTooltip === 'string') {
tooltipEl.innerHTML = customTooltip
} else if (
customTooltip instanceof Element ||
typeof customTooltip.nodeName === 'string'
) {
tooltipEl.innerHTML = ''
tooltipEl.appendChild(customTooltip)
}
}
}

0 comments on commit 17a15aa

Please sign in to comment.