Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show datapoints with 0 downloads #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions web/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,28 @@ function updateDatasets() {
});
}
}
// Insert additional "0" data points between non-zero data points
for (let arch of Object.keys(datasets)) {
let dataset = datasets[arch];
let dateInBetween = new Date(dataset.data[0].x);
let datasetIndex = 0;
// Don't show today and yesterday as 0. They might be zero because the data hasn't been updated yet.
const twoDaysAgo = new Date();
twoDaysAgo.setDate(twoDaysAgo.getDate() - 2);
while (dateInBetween < twoDaysAgo) {
// Is dateInBetween the next element in the dataset? If not, insert a new element, otherwise skip to the next date.
if (dataset.data.length > datasetIndex && dataset.data[datasetIndex].x.getTime() === dateInBetween.getTime()) {
datasetIndex += 1;
} else {
dataset.data.push({
x: new Date(dateInBetween),
y: 0
});
}
dateInBetween.setDate(dateInBetween.getDate() + 1);
}
dataset.data.sort((a, b) => a.x - b.x);
}
chart.data.datasets = Object.values(datasets);
chart.update();
updateBasicStats();
Expand Down