Skip to content

Commit

Permalink
Apply aggregation for single-view charts (#121)
Browse files Browse the repository at this point in the history
Due to a mistake, the aggregation method was invoked only on the new
multiview charts but not on single-view charts. With this change,
single-view charts are handled like multiview charts with only one view.
This fixes the aggregation issue, makes things more consistent, and
cleans up the code.
  • Loading branch information
pluehne authored and larsxschneider committed Feb 26, 2018
1 parent e6a5b14 commit a24ed3c
Showing 1 changed file with 15 additions and 22 deletions.
37 changes: 15 additions & 22 deletions docs/assets/js/charts.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,39 +319,32 @@ function createHistoryChart(canvas, actionBar)
const context = canvas.getContext('2d');

// Collect the data for each view in an array
let views = readConfig($(canvas), 'views');
let views;

// Aggregate data for each view separately
if (views != undefined)
if (hasConfig($(canvas), 'views'))
{
views = readConfig($(canvas), 'views');

for (let i = 0; i < views.length; i++)
{
if ('aggregate' in views[i] && views[i].aggregate != false)
views[i].data = aggregateTimeData(data, views[i].aggregate);
else
views[i].data = data;
}
views[i].data = data;
}
else
{
views = [{'data': data, 'aggregate': false, 'default': true}];

// Compatibility with old format, to be removed after migrating all charts
if (hasConfig($(canvas), 'aggregate'))
views[0]['aggregate'] = readConfig($(canvas), 'aggregate');

if (hasConfig($(canvas), 'slice'))
views[0]['slice'] = readConfig($(canvas), 'slice');

if (hasConfig($(canvas), 'series'))
views[0]['series'] = readConfig($(canvas), 'series');
if ($(canvas).data('config') != undefined)
views = [$(canvas).data('config')];
else
views = [{}];

if (hasConfig($(canvas), 'visibleSeries'))
views[0]['visibleSeries'] = readConfig($(canvas), 'visibleSeries');
views[0].default = true;
views[0].data = data;
}

// Aggregate data for each view separately
for (let i = 0; i < views.length; i++)
{
if ('aggregate' in views[i] && views[i].aggregate != false)
views[i].data = aggregateTimeData(views[i].data, views[i].aggregate);

if ('slice' in views[i])
{
const sliceIndex0 = Math.max(0, Math.min(views[i].data.length,
Expand Down

0 comments on commit a24ed3c

Please sign in to comment.