diff --git a/docs/FreeBedsChartView.js b/docs/FreeBedsChartView.js index e6d3923c431..a0f81418508 100644 --- a/docs/FreeBedsChartView.js +++ b/docs/FreeBedsChartView.js @@ -80,17 +80,7 @@ class FreeBedsChartView { }, tooltip: { callbacks: { - label: function (context) { - let label = context.dataset.label || ''; - - if (label) { - label += ': '; - } - if (context.parsed.y !== null) { - label += context.parsed.y.toFixed(1) + "%"; - } - return label; - } + label: UIUtils.labelWithPercentCallback } } }, diff --git a/docs/MedianOfFreeBedsByKreisChartView.js b/docs/MedianOfFreeBedsByKreisChartView.js index f2e8235d0d6..c0d5dbb89a8 100644 --- a/docs/MedianOfFreeBedsByKreisChartView.js +++ b/docs/MedianOfFreeBedsByKreisChartView.js @@ -44,19 +44,8 @@ class MedianOfFreeBedsByKreisChartView { text: 'some Title' }, tooltip: { - // FK-TODO: DRY with FreeBedsChartView.js callbacks: { - label: function (context) { - let label = context.dataset.label || ''; - - if (label) { - label += ': '; - } - if (context.parsed.y !== null) { - label += context.parsed.y.toFixed(1) + "%"; - } - return label; - } + label: UIUtils.labelWithPercentCallback } } }, diff --git a/docs/UIUtils.js b/docs/UIUtils.js index ca1bb40abf8..3c19414b7c5 100644 --- a/docs/UIUtils.js +++ b/docs/UIUtils.js @@ -16,4 +16,16 @@ class UIUtils { static getSelectedOption(selectElement) { return selectElement.options[selectElement.selectedIndex]; } + + static labelWithPercentCallback(context) { + let label = context.dataset.label || ''; + + if (label) { + label += ': '; + } + if (context.parsed.y !== null) { + label += context.parsed.y.toFixed(1) + "%"; + } + return label; + } }