Do not loose graph item colors after sorting

This commit is contained in:
Johannes Zellner
2025-12-09 16:03:52 +01:00
parent 72970720d2
commit 1cac67d4c5
+4 -4
View File
@@ -44,20 +44,20 @@ function renderTooltip(context) {
const { title, body, labelColors, dataPoints } = tooltip; // these were computed in the "callback" in tooltip configuration
if (body) {
const titleLines = title || [];
const bodyLines = body.map(item => item.lines);
const bodyLines = body.map(item => { return { label: item.lines }; });
let innerHtml = `<div class="graphs-tooltip-title">${titleLines[0]}</div>`;
// first amend the value so we know the dataPoints index, then sort and render
bodyLines.forEach((body, i) => {
body.value = dataPoints[i].parsed?.y || 0;
body.color = labelColors[i].borderColor;
});
bodyLines.sort((a, b) => {
return b.value - a.value;
});
bodyLines.slice(0, 5).forEach((body, i) => {
const colors = labelColors[i];
innerHtml += `<div style="color: ${colors.borderColor}" class="graphs-tooltip-item">${body}</div>`;
bodyLines.slice(0, 5).forEach(body => {
innerHtml += `<div style="color: ${body.color}" class="graphs-tooltip-item">${body.label}</div>`;
});
if (bodyLines.length > 5) innerHtml += '<div>...</div>';