Skip to content

Massage the data going into download graph #426

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

Merged
merged 3 commits into from
Aug 31, 2016
Merged
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
48 changes: 48 additions & 0 deletions app/components/download-graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,54 @@ export default Ember.Component.extend({

let data = this.get('data');

let datapoints_count = (data[1] || []).length - 1;

// "on" is an array of booleans where each
// element in the array says whether or not the
// corresponding line in the data is being drawn or not.
//
// Each line starts as not being drawn, and can pick up and
// be stopped arbitrarily many times before the graph is complete.
let on = [];
for (let i = 0; i < datapoints_count; i++) {
on.push(false);
}

// Start at 1 because the 0th entry in the array
// is an array of version numbers
for (let i = 1; i < data.length; i++) {
for (let k = 0; k < datapoints_count; k++) {
// k + 1 because the first entry in the array is the date
let value = data[i][k + 1];

// If we are "off" and are looking at a zero
// replace the data at this point with `null`.
//
// Null tells google.visualization to stop drawing
// the line altogether.
if (!on[k] && value === 0) {
data[i][k + 1] = null;
}
// If we are off and the value is not zero, we
// need to turn back on. (keep the value the same though)
else if (!on[k] && value !== 0) {
on[k] = true;

// We previously wrote a null into data[i - 1][k + 1],
// so to make the graph look pretty, we'll switch it back
// to the zero that it was before.
if (i > 1) {
data[i - 1][k + 1] = 0;
}
}
// If we are on and the value is zero, turn off
// but keep the zero in the array
else if (on[k] && value === 0) {
on[k] = false;
}
}
}

if (!data || !window.google || !window.googleChartsLoaded) {
this.$().hide();
return;
Expand Down