@@ -20,50 +20,47 @@ export default Ember.Component.extend({
20
20
21
21
let data = this . get ( 'data' ) ;
22
22
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 ;
35
29
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 ++ ) {
40
36
// 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 ] ;
42
38
43
39
// If we are "off" and are looking at a zero
44
40
// replace the data at this point with `null`.
45
41
//
46
42
// Null tells google.visualization to stop drawing
47
43
// 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 ;
50
46
}
47
+
51
48
// If we are off and the value is not zero, we
52
49
// 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 ;
55
52
56
53
// We previously wrote a null into data[i - 1][k + 1],
57
54
// so to make the graph look pretty, we'll switch it back
58
55
// 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 ;
61
58
}
62
59
}
63
60
// If we are on and the value is zero, turn off
64
61
// 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 ;
67
64
}
68
65
}
69
66
}
0 commit comments