From 72d85618a3b4e1411e8c1055c91fc811cccfb566 Mon Sep 17 00:00:00 2001 From: George Lacey Date: Mon, 10 May 2021 07:27:14 +0100 Subject: [PATCH] Add units to graph tooltip --- borgweb/borg/static/js/index.js | 40 +++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/borgweb/borg/static/js/index.js b/borgweb/borg/static/js/index.js index a89abc7..cd51bd1 100644 --- a/borgweb/borg/static/js/index.js +++ b/borgweb/borg/static/js/index.js @@ -9,35 +9,51 @@ function set_daily_graph(repoDict) { var datasets = [] repoDict.repos.forEach(function (repo) { - datasets.push({label: repo.label, + datasets.push({ + label: repo.label, data: repo.daily_size, fill: false, tension: 0.1, - borderColor: 'rgb(75, 192, 192)'}); + borderColor: 'rgb(75, 192, 192)' + }); }) const data = { - labels: labels, - datasets: datasets + labels: labels, + datasets: datasets }; const config = { type: 'line', data, options: { + plugins: { + tooltip: { + callbacks: { + label: function (context) { + var label = context.dataset.label || ''; + if (context.parsed.y !== null && y_units !== null) { + return `${context.parsed.y} ${y_units}` + } else { + return "" + } + } + } + } + }, scales: { - y: { - ticks: { - display: true, - grid: false, - callback: function(value, index, values) { - return value + " " + y_units; + y: { + ticks: { + display: true, + grid: false, + callback: function (value, index, values) { + return value + " " + y_units; + } } } } } - } - }; + } var myChart = new Chart( document.getElementById('backup_csize_hourly'),