Skip to content

Commit 17a15aa

Browse files
committed
fix #4869; custom tooltip can return html element
1 parent d214fe8 commit 17a15aa

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/modules/tooltip/Labels.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ export default class Labels {
238238
if (typeof yLbTitleFormatter !== 'function') {
239239
yLbTitleFormatter = function (label) {
240240
// refrence used from line: 966 in Options.js
241-
return label ? label + ': ' : ''
241+
return label ? label + ': ' : ''
242242
}
243243
}
244244

@@ -523,8 +523,7 @@ export default class Labels {
523523
fn = fn[i]
524524
}
525525

526-
// override everything with a custom html tooltip and replace it
527-
tooltipEl.innerHTML = fn({
526+
const customTooltip = fn({
528527
ctx: this.ctx,
529528
series: w.globals.series,
530529
seriesIndex: i,
@@ -533,5 +532,15 @@ export default class Labels {
533532
y2,
534533
w,
535534
})
535+
536+
if (typeof customTooltip === 'string') {
537+
tooltipEl.innerHTML = customTooltip
538+
} else if (
539+
customTooltip instanceof Element ||
540+
typeof customTooltip.nodeName === 'string'
541+
) {
542+
tooltipEl.innerHTML = ''
543+
tooltipEl.appendChild(customTooltip)
544+
}
536545
}
537546
}

0 commit comments

Comments
 (0)