fixing tooltips

This commit is contained in:
frankknoll
2022-04-01 11:40:57 +02:00
parent 950c6a70a9
commit 34edacc8d1
3 changed files with 13 additions and 5 deletions

View File

@@ -86,7 +86,7 @@ class FreeBedsChartView {
}, },
tooltip: { tooltip: {
callbacks: { callbacks: {
label: UIUtils.getLabelWithPercent label: UIUtils.getYLabelWithPercent
} }
} }
}, },

View File

@@ -51,7 +51,7 @@ class MedianOfFreeBedsByKreisChartView {
}, },
tooltip: { tooltip: {
callbacks: { callbacks: {
label: UIUtils.getLabelWithPercent label: UIUtils.getXLabelWithPercent
} }
} }
}, },

View File

@@ -17,14 +17,22 @@ class UIUtils {
return selectElement.options[selectElement.selectedIndex]; return selectElement.options[selectElement.selectedIndex];
} }
static getLabelWithPercent(context) { static getYLabelWithPercent(context) {
return UIUtils._getLabelWithPercent(context, context.parsed.y);
}
static getXLabelWithPercent(context) {
return UIUtils._getLabelWithPercent(context, context.parsed.x);
}
static _getLabelWithPercent(context, value) {
let label = context.dataset.label || ''; let label = context.dataset.label || '';
if (label) { if (label) {
label += ': '; label += ': ';
} }
if (context.parsed.y !== null) { if (value !== null) {
label += context.parsed.y.toFixed(1) + "%"; label += value.toFixed(1) + "%";
} }
return label; return label;
} }