Fixed weekly stats graph bar height

This commit is contained in:
Claudio Maggioni (maggicl) 2019-04-28 13:44:52 +02:00
parent e2e543f7e9
commit 093c491cde

View file

@ -1,35 +1,43 @@
'use strict'; 'use strict';
// vim: set ts=2 sw=2 tw=80 et:
$(document).ready(function() { $(document).ready(function() {
var data = JSON.parse($('#data').text()), var data = JSON.parse($('#data').text()),
format = djangoToMomentFmt(django.get_format('SHORT_DATE_FORMAT')); format = djangoToMomentFmt(django.get_format('SHORT_DATE_FORMAT'));
var chart = $('#chart');
var labels = [], dataset = []; var labels = [], dataset = [];
// Set the chart height in em according to length of dataset
chart.css("height", "" + (2 * data.length) + "rem");
// Force height in pixels in order to fix infinite growth resizing bug of
// chart.js
chart.attr("height", chart.height());
data.forEach(function(d) { data.forEach(function(d) {
labels.push(moment(d.weekStarts).format(format) + ' - ' + labels.push(moment(d.weekStarts).format(format) + ' - ' +
moment(d.weekEnds).format(format)); moment(d.weekEnds).format(format));
dataset.push(d.sum_count); dataset.push(d.sum_count);
}); });
var chart = new Chart($('#chart'), { var chart = new Chart(chart, {
type: 'horizontalBar', type: 'horizontalBar',
data: { data: {
labels: labels, labels: labels,
datasets: [{ datasets: [{
label: '# of Arrows', label: '# of Arrows',
data: dataset, data: dataset,
borderWidth: 1 borderWidth: 1
}] }]
}, },
options: { options: {
scales: { scales: {
xAxes: [{ xAxes: [{
ticks: { ticks: {
beginAtZero: true beginAtZero: true
}
}]
} }
}]
} }
}
}); });
}); });