use rolling average for trend line

This commit is contained in:
tmont 2020-05-01 17:09:19 -07:00
parent 0fe3817c20
commit b86ac75ffd
2 changed files with 4 additions and 2 deletions

View File

@ -312,6 +312,7 @@ const processGlobalDeaths = async () => {
record.timeSeriesDaily[record.timeSeriesDaily.length - 1].value : record.timeSeriesDaily[record.timeSeriesDaily.length - 1].value :
0; 0;
record.timeSeriesMonthly = monthlyTotals; record.timeSeriesMonthly = monthlyTotals;
record.rollingAverageDaily = getRollingAverage(record);
record.state = record['Province/State']; record.state = record['Province/State'];
record.country = record['Country/Region']; record.country = record['Country/Region'];

View File

@ -74,6 +74,7 @@ html
function makeSparkline(id, data) { function makeSparkline(id, data) {
const canvas = document.getElementById(id); const canvas = document.getElementById(id);
const maxValue = data.reduce((max, value) => Math.max(max, value), 0); const maxValue = data.reduce((max, value) => Math.max(max, value), 0);
const max = maxValue > 0 ? Math.pow(10, Math.ceil(Math.log10(maxValue))) : 0
const chart = new Chart(canvas.getContext('2d'), { const chart = new Chart(canvas.getContext('2d'), {
type: 'line', type: 'line',
data: { data: {
@ -107,7 +108,7 @@ html
precision: 0, precision: 0,
beginAtZero: true, beginAtZero: true,
min: 0, min: 0,
max: maxValue > 0 ? Math.pow(10, Math.ceil(Math.log10(maxValue))) : 0, max: Math.max(max, 2), // this is necessary for some reason
callback: value => Number(value.toString()), callback: value => Number(value.toString()),
} }
}, },
@ -388,7 +389,7 @@ html
script. script.
makeSparkline( makeSparkline(
"sparkline-#{i}", "sparkline-#{i}",
#{JSON.stringify(item.timeSeriesDaily.slice(-14).map(x => x.delta))}, #{JSON.stringify(item.rollingAverageDaily.slice(-14).map(x => x.delta))}
); );