|
62 | 62 |
|
63 | 63 | const fmtDate = uPlot.fmtDate("{M}/{D}/{YY} {h}:{mm}:{ss} {AA}"); |
64 | 64 |
|
| 65 | + let over; |
| 66 | + |
| 67 | + let tooltipVisible = false; |
| 68 | + |
| 69 | + function showTooltip() { |
| 70 | + if (!tooltipVisible) { |
| 71 | + tooltip.style.display = "block"; |
| 72 | + over.style.cursor = "pointer"; |
| 73 | + tooltipVisible = true; |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + function hideTooltip() { |
| 78 | + if (tooltipVisible) { |
| 79 | + tooltip.style.display = "none"; |
| 80 | + over.style.cursor = null; |
| 81 | + tooltipVisible = false; |
| 82 | + } |
| 83 | + } |
| 84 | + |
65 | 85 | function setTooltip(u) { |
| 86 | + showTooltip(); |
| 87 | + |
66 | 88 | let top = u.valToPos(u.data[seriesIdx][dataIdx], 'y'); |
67 | 89 | let lft = u.valToPos(u.data[ 0][dataIdx], 'x'); |
68 | 90 |
|
|
81 | 103 | hooks: { |
82 | 104 | ready: [ |
83 | 105 | u => { |
84 | | - let over = u.root.querySelector(".u-over"); |
| 106 | + over = u.root.querySelector(".u-over"); |
85 | 107 | tooltipLeftOffset = parseFloat(over.style.left); |
86 | 108 | tooltipTopOffset = parseFloat(over.style.top); |
87 | 109 | u.root.querySelector(".u-wrap").appendChild(tooltip); |
|
108 | 130 | u => { |
109 | 131 | let c = u.cursor; |
110 | 132 |
|
111 | | - if (c.idx != dataIdx) { |
| 133 | + if (dataIdx != c.idx) { |
112 | 134 | dataIdx = c.idx; |
113 | 135 |
|
114 | 136 | if (seriesIdx != null) |
115 | | - setTooltip(u, setTooltip); |
| 137 | + setTooltip(u); |
116 | 138 | } |
117 | 139 | } |
118 | 140 | ], |
|
122 | 144 | seriesIdx = sidx; |
123 | 145 |
|
124 | 146 | if (sidx == null) |
125 | | - tooltip.style.display = "none"; |
126 | | - else if (dataIdx != null) { |
127 | | - tooltip.style.display = "block"; |
| 147 | + hideTooltip(); |
| 148 | + else if (dataIdx != null) |
128 | 149 | setTooltip(u); |
129 | | - } |
130 | 150 | } |
131 | 151 | } |
132 | 152 | ], |
|
138 | 158 | const interpolatedColorWithAlpha = "#fcb0f17a"; |
139 | 159 |
|
140 | 160 | ctx.save(); |
| 161 | + |
| 162 | + let clip = new Path2D(); |
| 163 | + clip.rect(left, top, width, height); |
| 164 | + ctx.clip(clip); |
| 165 | + |
141 | 166 | ctx.strokeStyle = interpolatedColorWithAlpha; |
142 | 167 | ctx.beginPath(); |
143 | 168 |
|
|
0 commit comments