Skip to content

Commit df1ab65

Browse files
authored
Merge pull request #432 from TyOverby/graph-fix
fix data manipulation for download graph
2 parents 9c9b705 + ee798da commit df1ab65

File tree

1 file changed

+22
-25
lines changed

1 file changed

+22
-25
lines changed

app/components/download-graph.js

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,50 +20,47 @@ export default Ember.Component.extend({
2020

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

23-
let datapoints_count = (data[1] || []).length - 1;
24-
25-
// "on" is an array of booleans where each
26-
// element in the array says whether or not the
27-
// corresponding line in the data is being drawn or not.
28-
//
29-
// Each line starts as not being drawn, and can pick up and
30-
// be stopped arbitrarily many times before the graph is complete.
31-
let on = [];
32-
for (let i = 0; i < datapoints_count; i++) {
33-
on.push(false);
34-
}
23+
let subarray_length = (data[1] || []).length;
24+
25+
// Start at 1 to skip the date element in the 0th
26+
// location in the array.
27+
for (let k = 1; k < subarray_length; k++) {
28+
let on = false;
3529

36-
// Start at 1 because the 0th entry in the array
37-
// is an array of version numbers
38-
for (let i = 1; i < data.length; i++) {
39-
for (let k = 0; k < datapoints_count; k++) {
30+
// Start at 1 because the 0th entry in the array
31+
// is an array of version numbers.
32+
//
33+
// End before the last element is reached because we never
34+
// want to change the last element.
35+
for (let i = 1; i < data.length - 1; i++) {
4036
// k + 1 because the first entry in the array is the date
41-
let value = data[i][k + 1];
37+
let value = data[i][k];
4238

4339
// If we are "off" and are looking at a zero
4440
// replace the data at this point with `null`.
4541
//
4642
// Null tells google.visualization to stop drawing
4743
// the line altogether.
48-
if (!on[k] && value === 0) {
49-
data[i][k + 1] = null;
44+
if (!on && value === 0) {
45+
data[i][k] = null;
5046
}
47+
5148
// If we are off and the value is not zero, we
5249
// need to turn back on. (keep the value the same though)
53-
else if (!on[k] && value !== 0) {
54-
on[k] = true;
50+
else if (!on && value !== 0) {
51+
on = true;
5552

5653
// We previously wrote a null into data[i - 1][k + 1],
5754
// so to make the graph look pretty, we'll switch it back
5855
// to the zero that it was before.
59-
if (i > 1) {
60-
data[i - 1][k + 1] = 0;
56+
if (i >= 2) {
57+
data[i - 1][k] = 0;
6158
}
6259
}
6360
// If we are on and the value is zero, turn off
6461
// but keep the zero in the array
65-
else if (on[k] && value === 0) {
66-
on[k] = false;
62+
else if (on && value === 0) {
63+
on = false;
6764
}
6865
}
6966
}

0 commit comments

Comments
 (0)