refactoring

This commit is contained in:
frankknoll
2022-03-19 21:31:06 +01:00
parent b08da1c310
commit 4ee89f1989
3 changed files with 19 additions and 26 deletions

View File

@@ -80,7 +80,7 @@ class FreeBedsChartView {
},
tooltip: {
callbacks: {
label: UIUtils.labelWithPercentCallback
label: UIUtils.getLabelWithPercent
}
}
},
@@ -96,17 +96,7 @@ class FreeBedsChartView {
}
}
},
y: {
min: 0,
max: 100,
title: {
display: true,
text: label
},
ticks: {
callback: value => value + "%"
}
}
y: UIUtils.getPercentageScale(label)
},
parsing: {
xAxisKey: 'date'

View File

@@ -45,24 +45,13 @@ class MedianOfFreeBedsByKreisChartView {
},
tooltip: {
callbacks: {
label: UIUtils.labelWithPercentCallback
label: UIUtils.getLabelWithPercent
}
}
},
responsive: true,
scales: {
y: {
min: 0,
max: 100,
title: {
display: true,
text: label
},
// FK-TODO: DRY with FreeBedsChartView.js
ticks: {
callback: value => value + "%"
}
}
y: UIUtils.getPercentageScale(label)
},
parsing: {
xAxisKey: 'Kreis'

View File

@@ -17,7 +17,7 @@ class UIUtils {
return selectElement.options[selectElement.selectedIndex];
}
static labelWithPercentCallback(context) {
static getLabelWithPercent(context) {
let label = context.dataset.label || '';
if (label) {
@@ -28,4 +28,18 @@ class UIUtils {
}
return label;
}
static getPercentageScale(label) {
return {
min: 0,
max: 100,
title: {
display: true,
text: label
},
ticks: {
callback: value => value + "%"
}
}
}
}