Skip to content

Commit a0964ba

Browse files
committed
set cursor: pointer and fix tooltips after re-entry at edges of charts. close #749.
1 parent 15d42eb commit a0964ba

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

site/static/index.html

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,29 @@
9595

9696
const fmtDate = uPlot.fmtDate("{M}/{D}/{YY} {h}:{mm}:{ss} {AA}");
9797

98+
let over;
99+
100+
let tooltipVisible = false;
101+
102+
function showTooltip() {
103+
if (!tooltipVisible) {
104+
tooltip.style.display = "block";
105+
over.style.cursor = "pointer";
106+
tooltipVisible = true;
107+
}
108+
}
109+
110+
function hideTooltip() {
111+
if (tooltipVisible) {
112+
tooltip.style.display = "none";
113+
over.style.cursor = null;
114+
tooltipVisible = false;
115+
}
116+
}
117+
98118
function setTooltip(u) {
119+
showTooltip();
120+
99121
let top = u.valToPos(u.data[seriesIdx][dataIdx], 'y');
100122
let lft = u.valToPos(u.data[ 0][dataIdx], 'x');
101123

@@ -124,7 +146,8 @@
124146
hooks: {
125147
ready: [
126148
u => {
127-
let over = u.root.querySelector(".u-over");
149+
over = u.root.querySelector(".u-over");
150+
128151
tooltipLeftOffset = parseFloat(over.style.left);
129152
tooltipTopOffset = parseFloat(over.style.top);
130153
u.root.querySelector(".u-wrap").appendChild(tooltip);
@@ -151,11 +174,11 @@
151174
u => {
152175
let c = u.cursor;
153176

154-
if (c.idx != dataIdx) {
177+
if (dataIdx != c.idx) {
155178
dataIdx = c.idx;
156179

157180
if (seriesIdx != null)
158-
setTooltip(u, setTooltip);
181+
setTooltip(u);
159182
}
160183
}
161184
],
@@ -165,11 +188,9 @@
165188
seriesIdx = sidx;
166189

167190
if (sidx == null)
168-
tooltip.style.display = "none";
169-
else if (dataIdx != null) {
170-
tooltip.style.display = "block";
191+
hideTooltip();
192+
else if (dataIdx != null)
171193
setTooltip(u);
172-
}
173194
}
174195
}
175196
],

0 commit comments

Comments
 (0)