refactoring
This commit is contained in:
@@ -11,12 +11,13 @@ class FreeBedsChartView {
|
|||||||
if (this.#chart != null) {
|
if (this.#chart != null) {
|
||||||
this.#chart.destroy();
|
this.#chart.destroy();
|
||||||
}
|
}
|
||||||
|
const label = 'Anteil freier Betten';
|
||||||
this.#chart = new Chart(
|
this.#chart = new Chart(
|
||||||
this.#canvas,
|
this.#canvas,
|
||||||
{
|
{
|
||||||
type: 'line',
|
type: 'line',
|
||||||
data: this.#getData(data),
|
data: this.#getData(data, label),
|
||||||
options: this.#getOptions(title),
|
options: this.#getOptions(title, label),
|
||||||
plugins: [this.#getBackgroundTrafficLightsPlugin()]
|
plugins: [this.#getBackgroundTrafficLightsPlugin()]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -47,11 +48,11 @@ class FreeBedsChartView {
|
|||||||
return { beforeDraw: drawTrafficLights };
|
return { beforeDraw: drawTrafficLights };
|
||||||
}
|
}
|
||||||
|
|
||||||
#getData(data) {
|
#getData(data, label) {
|
||||||
return {
|
return {
|
||||||
datasets: [
|
datasets: [
|
||||||
{
|
{
|
||||||
label: 'Anteil freier Betten',
|
label: label,
|
||||||
data: data,
|
data: data,
|
||||||
parsing: {
|
parsing: {
|
||||||
yAxisKey: 'free_beds_divided_by_all_beds_in_percent'
|
yAxisKey: 'free_beds_divided_by_all_beds_in_percent'
|
||||||
@@ -70,7 +71,7 @@ class FreeBedsChartView {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#getOptions(title) {
|
#getOptions(title, label) {
|
||||||
return {
|
return {
|
||||||
plugins: {
|
plugins: {
|
||||||
title: {
|
title: {
|
||||||
@@ -110,7 +111,7 @@ class FreeBedsChartView {
|
|||||||
max: 100,
|
max: 100,
|
||||||
title: {
|
title: {
|
||||||
display: true,
|
display: true,
|
||||||
text: "Anteil freier Betten"
|
text: label
|
||||||
},
|
},
|
||||||
ticks: {
|
ticks: {
|
||||||
callback: value => value + "%"
|
callback: value => value + "%"
|
||||||
|
|||||||
Reference in New Issue
Block a user