feat: Omit numbers on narrow screens

This commit is contained in:
Paul Gauthier (aider) 2024-08-15 14:38:37 -07:00
parent 84e24bd5a2
commit 2054bef7f9

View file

@ -109,6 +109,7 @@ document.addEventListener('DOMContentLoaded', function () {
afterDraw: function(chart) { afterDraw: function(chart) {
var ctx = chart.ctx; var ctx = chart.ctx;
var isWideScreen = window.innerWidth > 768; // Assuming 768px as the breakpoint for wide screens var isWideScreen = window.innerWidth > 768; // Assuming 768px as the breakpoint for wide screens
if (isWideScreen) {
chart.data.datasets.forEach(function(dataset, i) { chart.data.datasets.forEach(function(dataset, i) {
var meta = chart.getDatasetMeta(i); var meta = chart.getDatasetMeta(i);
meta.data.forEach(function(bar, index) { meta.data.forEach(function(bar, index) {
@ -117,12 +118,13 @@ document.addEventListener('DOMContentLoaded', function () {
ctx.fillStyle = '#000000'; ctx.fillStyle = '#000000';
ctx.textAlign = 'center'; ctx.textAlign = 'center';
ctx.textBaseline = 'bottom'; ctx.textBaseline = 'bottom';
var displayText = isWideScreen ? data.toFixed(1) + '%' : Math.round(data) + '%'; var displayText = data.toFixed(1) + '%';
ctx.fillText(displayText, bar.x, bar.y - 5); ctx.fillText(displayText, bar.x, bar.y - 5);
} }
}); });
}); });
} }
}
}] }]
}; };