Skip to content

Commit f73566c

Browse files
committed
Fix hero chart tooltip clipped by glass card overflow
Render tooltip on document.body with fixed positioning instead of inside u.over, preventing the .glass overflow:hidden from hiding it. Closes #190
1 parent 555c956 commit f73566c

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

app/static/js/hero-chart.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,14 @@
7676

7777
function heroTooltipPlugin(timestamps) {
7878
var tooltip;
79+
var overEl;
7980
function init(u) {
81+
overEl = u.over;
8082
tooltip = document.createElement('div');
8183
tooltip.className = 'uplot-tooltip';
8284
tooltip.style.display = 'none';
83-
u.over.appendChild(tooltip);
85+
tooltip.style.position = 'fixed';
86+
document.body.appendChild(tooltip);
8487
}
8588
function setCursor(u) {
8689
var idx = u.cursor.idx;
@@ -114,18 +117,22 @@
114117
tooltip.style.background = c.tooltipBg;
115118
tooltip.style.color = c.text;
116119
tooltip.style.border = '1px solid ' + c.tooltipBorder;
117-
var left = u.cursor.left;
118-
var top = u.cursor.top;
120+
var rect = overEl.getBoundingClientRect();
121+
var left = rect.left + u.cursor.left;
122+
var top = rect.top + u.cursor.top;
119123
var tw = tooltip.offsetWidth;
120124
var th = tooltip.offsetHeight;
121125
var x = left + 12;
122126
var y = top - th - 8;
123-
if (x + tw > u.over.offsetWidth) x = left - tw - 12;
127+
if (x + tw > window.innerWidth) x = left - tw - 12;
124128
if (y < 0) y = top + 12;
125129
tooltip.style.left = x + 'px';
126130
tooltip.style.top = y + 'px';
127131
}
128-
return { hooks: { init: [init], setCursor: [setCursor] } };
132+
function destroy() {
133+
if (tooltip && tooltip.parentNode) tooltip.parentNode.removeChild(tooltip);
134+
}
135+
return { hooks: { init: [init], setCursor: [setCursor], destroy: [destroy] } };
129136
}
130137

131138
function formatHeroDate(ts) {

0 commit comments

Comments
 (0)