Add multi-bucket support for tables and update reports

This commit is contained in:
Jordan Wages 2025-07-19 18:19:58 -05:00
commit 1d4e99c69b
4 changed files with 127 additions and 33 deletions

View file

@ -117,21 +117,24 @@
.then(r => r.json())
.then(data => {
if (token !== currentLoad) return;
const bucketField = rep.bucket || 'bucket';
const bucketFields = rep.buckets || [rep.bucket || 'bucket'];
const labels = Array.isArray(rep.bucket_label)
? rep.bucket_label
: [rep.bucket_label || 'Bucket'];
if (rep.chart === 'table') {
const rows = data.map(x => [x[bucketField], x.value]);
const rows = data.map(x => bucketFields.map(f => x[f]).concat(x.value));
const columns = labels.map(l => ({ title: l }));
columns.push({ title: 'Value' });
const table = new DataTable('#table-' + rep.name, {
data: rows,
columns: [
{ title: rep.bucket_label || 'Bucket' },
{ title: 'Value' }
]
columns: columns
});
registerChart(token, rep.name, table);
return;
}
const labels = data.map(x => x[bucketField]);
const bucketField = bucketFields[0];
const labelsArr = data.map(x => x[bucketField]);
const values = data.map(x => x.value);
const chartType = rep.chart === 'stackedBar' ? 'bar' : rep.chart;
const options = { scales: { y: { beginAtZero: true } } };
@ -158,7 +161,7 @@
const chart = new Chart(document.getElementById('chart-' + rep.name), {
type: chartType,
data: {
labels: labels,
labels: labelsArr,
datasets: [dataset]
},
options: options