@@ -20,6 +20,54 @@ 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
+ }
35
+
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 ++ ) {
40
+ // k + 1 because the first entry in the array is the date
41
+ let value = data [ i ] [ k + 1 ] ;
42
+
43
+ // If we are "off" and are looking at a zero
44
+ // replace the data at this point with `null`.
45
+ //
46
+ // Null tells google.visualization to stop drawing
47
+ // the line altogether.
48
+ if ( ! on [ k ] && value === 0 ) {
49
+ data [ i ] [ k + 1 ] = null ;
50
+ }
51
+ // If we are off and the value is not zero, we
52
+ // need to turn back on. (keep the value the same though)
53
+ else if ( ! on [ k ] && value !== 0 ) {
54
+ on [ k ] = true ;
55
+
56
+ // We previously wrote a null into data[i - 1][k + 1],
57
+ // so to make the graph look pretty, we'll switch it back
58
+ // to the zero that it was before.
59
+ if ( i > 1 ) {
60
+ data [ i - 1 ] [ k + 1 ] = 0 ;
61
+ }
62
+ }
63
+ // If we are on and the value is zero, turn off
64
+ // but keep the zero in the array
65
+ else if ( on [ k ] && value === 0 ) {
66
+ on [ k ] = false ;
67
+ }
68
+ }
69
+ }
70
+
23
71
if ( ! data || ! window . google || ! window . googleChartsLoaded ) {
24
72
this . $ ( ) . hide ( ) ;
25
73
return ;
0 commit comments