feat: Show one decimal point for numbers atop bars on wide screens

This commit is contained in:
Paul Gauthier (aider) 2024-08-15 14:36:11 -07:00
parent 9a893c9a6e
commit 84e24bd5a2

View file

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