fix: hover legend display now depends on datasize

This commit is contained in:
Christoph Kluge 2023-08-09 12:43:58 +02:00
parent e32042204b
commit f286872a33

View File

@ -57,6 +57,7 @@
// converts the legend into a simple tooltip // converts the legend into a simple tooltip
function legendAsTooltipPlugin({ className, style = { backgroundColor:"rgba(255, 249, 196, 0.92)", color: "black" } } = {}) { function legendAsTooltipPlugin({ className, style = { backgroundColor:"rgba(255, 249, 196, 0.92)", color: "black" } } = {}) {
let legendEl; let legendEl;
const dataSize = series.length
function init(u, opts) { function init(u, opts) {
legendEl = u.root.querySelector(".u-legend"); legendEl = u.root.querySelector(".u-legend");
@ -76,11 +77,14 @@
...style ...style
}); });
// hide series color markers // conditional hide series color markers:
if (useStatsSeries === true || // Min/Max/Avg Self-Explanatory
dataSize === 1 || // Only one Y-Dataseries
dataSize > 6 ){ // More than 6 Y-Dataseries
const idents = legendEl.querySelectorAll(".u-marker"); const idents = legendEl.querySelectorAll(".u-marker");
for (let i = 0; i < idents.length; i++) for (let i = 0; i < idents.length; i++)
idents[i].style.display = "none"; idents[i].style.display = "none";
}
const overEl = u.over; const overEl = u.over;
overEl.style.overflow = "visible"; overEl.style.overflow = "visible";
@ -102,12 +106,16 @@
legendEl.style.transform = "translate(" + (left - width - 15) + "px, " + (top + 15) + "px)"; legendEl.style.transform = "translate(" + (left - width - 15) + "px, " + (top + 15) + "px)";
} }
if (dataSize <= 12 || useStatsSeries === true) {
return { return {
hooks: { hooks: {
init: init, init: init,
setCursor: update, setCursor: update,
} }
}; }
} else { // Setting legend-opts show/live as object with false here will not work ...
return {}
}
} }
function backgroundColor() { function backgroundColor() {
@ -240,6 +248,10 @@
x: { time: false }, x: { time: false },
y: maxY ? { range: [0., maxY * 1.1] } : {} y: maxY ? { range: [0., maxY * 1.1] } : {}
}, },
legend : { // Display legend until max 12 Y-dataseries
show: (series.length <= 12 || useStatsSeries === true) ? true : false,
live: (series.length <= 12 || useStatsSeries === true) ? true : false
},
cursor: { drag: { x: true, y: true } } cursor: { drag: { x: true, y: true } }
} }