| 1 |
(function () { |
| 2 |
function createTip() { |
| 3 |
var tip = document.createElement("div"); |
| 4 |
tip.className = "aibui-stats-tip"; |
| 5 |
tip.style.position = "fixed"; |
| 6 |
tip.style.zIndex = "99999"; |
| 7 |
tip.style.pointerEvents = "none"; |
| 8 |
tip.style.padding = "6px 8px"; |
| 9 |
tip.style.border = "1px solid #e5e7eb"; |
| 10 |
tip.style.background = "#111827"; |
| 11 |
tip.style.color = "#fff"; |
| 12 |
tip.style.fontSize = "12px"; |
| 13 |
tip.style.borderRadius = "6px"; |
| 14 |
tip.style.boxShadow = "0 4px 14px rgba(0,0,0,.15)"; |
| 15 |
tip.style.transform = "translate(-50%, -120%)"; |
| 16 |
tip.style.whiteSpace = "nowrap"; |
| 17 |
tip.style.display = "none"; |
| 18 |
document.body.appendChild(tip); |
| 19 |
return tip; |
| 20 |
} |
| 21 |
var tipEl = createTip(); |
| 22 |
function showTip(text, x, y) { |
| 23 |
tipEl.textContent = text; |
| 24 |
tipEl.style.left = x + "px"; |
| 25 |
tipEl.style.top = y + "px"; |
| 26 |
tipEl.style.display = "block"; |
| 27 |
} |
| 28 |
function hideTip() { |
| 29 |
tipEl.style.display = "none"; |
| 30 |
} |
| 31 |
|
| 32 |
function attach(root) { |
| 33 |
root.addEventListener("pointerover", function (e) { |
| 34 |
var t = e.target; |
| 35 |
if (!(t instanceof Element)) return; |
| 36 |
var label = t.getAttribute("data-label"); |
| 37 |
var value = t.getAttribute("data-value"); |
| 38 |
if (value == null) return; |
| 39 |
var series = t.getAttribute("data-series") || ""; |
| 40 |
var parts = []; |
| 41 |
if (series) parts.push(series); |
| 42 |
if (label) parts.push(label); |
| 43 |
parts.push(value); |
| 44 |
var text = value; |
| 45 |
var rect = t.getBoundingClientRect(); |
| 46 |
showTip(text, rect.left + rect.width / 2, rect.top); |
| 47 |
}); |
| 48 |
root.addEventListener("pointermove", function (e) { |
| 49 |
if (tipEl.style.display === "none") return; |
| 50 |
showTip(tipEl.textContent, e.clientX, e.clientY - 10); |
| 51 |
}); |
| 52 |
root.addEventListener("pointerout", function (e) { |
| 53 |
hideTip(); |
| 54 |
}); |
| 55 |
} |
| 56 |
|
| 57 |
function boot() { |
| 58 |
var roots = document.querySelectorAll(".aibui-stats .aibui-stats-svg"); |
| 59 |
for (var i = 0; i < roots.length; i++) { |
| 60 |
attach(roots[i]); |
| 61 |
} |
| 62 |
} |
| 63 |
if (document.readyState === "loading") { |
| 64 |
document.addEventListener("DOMContentLoaded", boot); |
| 65 |
} else { |
| 66 |
boot(); |
| 67 |
} |
| 68 |
})(); |
| 69 |
|