@@ -54,17 +54,17 @@ angular.module('angularDc', [])
54
54
// Get additional options from chartElement's html attributes.
55
55
// All options are prepended with 'dc-'' to avoid clashing with html own meaning (e.g width)
56
56
// All options are parsed in angular's $parse language, so beware, it is not javascript!
57
- var options = getOptionsFromAttrs ( scope , iAttrs , validOptions ) ;
57
+ options = getOptionsFromAttrs ( scope , iAttrs , validOptions ) ;
58
58
59
59
// we may have a dc-options attribute which contain a javascript object for stuff
60
60
// not writtable in $parse language
61
- if ( " options" in options ) {
61
+ if ( ' options' in options ) {
62
62
options = _ . merge ( options , options . options ) ;
63
63
options . options = undefined ;
64
64
}
65
65
// If we have a dc-name attribute, we populate the scope with the chart
66
66
// object dc-name
67
- if ( " name" in options ) {
67
+ if ( ' name' in options ) {
68
68
scope [ options . name ] = chart ;
69
69
options . name = undefined ;
70
70
}
@@ -79,7 +79,7 @@ angular.module('angularDc', [])
79
79
'postRedraw' : options . onPostRedraw ,
80
80
'filtered' : options . onFiltered ,
81
81
'zoomed' : options . onZoomed ,
82
- } ) . omit ( _ . isUndefined )
82
+ } ) . omit ( _ . isUndefined ) ;
83
83
84
84
// Register the eventHandlers with the chart (Dc.js)
85
85
eventHandlers . each ( function ( handler , evt ) {
@@ -100,7 +100,7 @@ angular.module('angularDc', [])
100
100
return _ ( chart ) . functions ( )
101
101
. extend ( directiveOptions )
102
102
. map ( function ( s ) {
103
- return "dc" + s . charAt ( 0 ) . toUpperCase ( ) + s . substring ( 1 )
103
+ return 'dc' + s . charAt ( 0 ) . toUpperCase ( ) + s . substring ( 1 ) ;
104
104
} )
105
105
. value ( ) ;
106
106
}
@@ -112,7 +112,7 @@ angular.module('angularDc', [])
112
112
. map ( function ( key ) {
113
113
var value = scope . $eval ( iAttrs [ key ] ) ;
114
114
// remove the dc- prefix if any
115
- if ( key . substring ( 0 , 2 ) === "dc" ) {
115
+ if ( key . substring ( 0 , 2 ) === 'dc' ) {
116
116
key = key . charAt ( 2 ) . toLowerCase ( ) + key . substring ( 3 ) ;
117
117
}
118
118
return [ key , value ] ;
@@ -126,66 +126,66 @@ angular.module('angularDc', [])
126
126
var printExceptions = false ;
127
127
// add dc, d3 and commonly used Date method to the scope to allow snippets to be configured in
128
128
// the templates
129
- scope . dc = dc
130
- scope . d3 = d3
129
+ scope . dc = dc ;
130
+ scope . d3 = d3 ;
131
131
scope . DateTime = function ( a , b , c , d , e , f ) {
132
132
return new Date ( a , b , c , d , e , f ) ;
133
- }
133
+ } ;
134
134
scope . Date = function ( a , b , c ) {
135
135
return new Date ( a , b , c ) ;
136
- }
136
+ } ;
137
137
// watch for the scope to settle until all the attributes are defined
138
138
var unwatch = scope . $watch ( function ( ) {
139
139
var options = _ ( iAttrs . $attr )
140
140
. keys ( )
141
141
. filter ( function ( s ) {
142
- return s . substring ( 0 , 2 ) === "dc" && s !== " dcChart" && s !== " dcChartGroup"
142
+ return s . substring ( 0 , 2 ) === 'dc' && s !== ' dcChart' && s !== ' dcChartGroup' ;
143
143
} )
144
144
. map ( function ( key ) {
145
145
try {
146
146
// We ignore exception waiting for the data to be potentially loaded
147
147
// by the controller
148
148
var r = scope . $eval ( iAttrs [ key ] ) ;
149
149
if ( _ . isUndefined ( r ) ) {
150
- throw Error ( iAttrs [ key ] + " is undefined" )
150
+ throw Error ( iAttrs [ key ] + ' is undefined' ) ;
151
151
}
152
- return r
152
+ return r ;
153
153
} catch ( e ) {
154
154
if ( printExceptions ) {
155
- console . log ( " unable to eval" + key + ":" + iAttrs [ key ] )
156
- throw e
155
+ console . log ( ' unable to eval' + key + ':' + iAttrs [ key ] ) ;
156
+ throw e ;
157
157
}
158
- return undefined
158
+ return undefined ;
159
159
}
160
160
} ) ;
161
161
if ( options . any ( _ . isUndefined ) ) {
162
162
// return undefined if there is at least one undefined option
163
163
// so that the $watch dont call us again at this $digest time
164
- return undefined
164
+ return undefined ;
165
165
}
166
- return options . value ( )
166
+ return options . value ( ) ;
167
167
} , function ( options ) {
168
168
if ( ! _ . isUndefined ( options ) ) {
169
169
// Stop the $watch, as we now created the charts
170
- unwatch ( )
170
+ unwatch ( ) ;
171
171
172
172
var chart = setupChart ( scope , iElement , iAttrs ) ;
173
173
// populate the .reset childrens with necessary reset callbacks
174
- var a = angular . element ( iElement [ 0 ] . querySelector ( " a.reset" ) ) ;
175
- a . on ( " click" , function ( ) {
174
+ var a = angular . element ( iElement [ 0 ] . querySelector ( ' a.reset' ) ) ;
175
+ a . on ( ' click' , function ( ) {
176
176
chart . filterAll ( ) ;
177
177
dc . redrawAll ( ) ;
178
178
} ) ;
179
- a . attr ( " href" , " javascript:;" )
180
- a . css ( " display" , " none" )
179
+ a . attr ( ' href' , ' javascript:;' ) ;
180
+ a . css ( ' display' , ' none' ) ;
181
181
// watching the attributes is costly, so we stop after first rendering
182
182
chart . render ( ) ;
183
183
}
184
184
} ) ;
185
185
// if after 4 second we still get exceptions, we should raise them
186
186
// to help debugging. $timeout will trigger another round of check.
187
187
$timeout ( function ( ) {
188
- printExceptions = true
188
+ printExceptions = true ;
189
189
} , 2000 ) ;
190
190
191
191
}
@@ -205,43 +205,45 @@ angular.module('angularDc', [])
205
205
with same dimension. This is a limitation of the underlying lib dc.js
206
206
*/
207
207
angular . module ( 'angularDc' )
208
- . directive ( 'dcSelect' , [ '$timeout' , function ( $timeout ) {
209
- return {
210
- restrict : 'E' ,
211
- scope : {
212
- dcDimension : "=" ,
213
- allLabel : "@"
214
- } ,
215
- template : "<select class='form-control' ng-model='selectModel' " + "ng-options='d.key for d in selectOptions'>" ,
216
- link : function ( scope , iElement , iAttrs ) {
217
- scope . $watch ( 'dcDimension' , function ( dimension ) {
218
- var allkeys , chart ;
219
- if ( dimension != null ) {
220
- // we make a fake chart so that the dimension is known by dc.filterAll()
221
- chart = dc . baseMixin ( { } ) ;
222
- chart . dimension ( dimension ) ;
223
- chart . group ( dimension ) ;
224
- chart . _doRender = function ( ) { } ;
225
- chart . _doRedraw = function ( ) { } ;
226
- scope . selectModel = {
227
- key : scope . allLabel
228
- } ;
229
- allkeys = dimension . group ( ) . orderNatural ( ) . all ( ) ;
230
- scope . selectOptions = [ scope . selectModel ] . concat ( allkeys ) ;
231
- }
232
- } ) ;
233
- return scope . $watch ( 'selectModel' , function ( sel ) {
234
- if ( scope . dcDimension != null ) {
235
- if ( sel !== null && sel . key !== scope . allLabel ) {
236
- scope . dcDimension . filter ( function ( d ) {
237
- return d === sel . key ;
238
- } ) ;
239
- } else {
240
- scope . dcDimension . filter ( null ) ;
241
- }
242
- dc . redrawAll ( ) ;
208
+ . directive ( 'dcSelect' , [
209
+ function ( ) {
210
+ return {
211
+ restrict : 'E' ,
212
+ scope : {
213
+ dcDimension : '=' ,
214
+ allLabel : '@'
215
+ } ,
216
+ template : '<select class="form-control" ng-model="selectModel" ' + 'ng-options="d.key for d in selectOptions">' ,
217
+ link : function ( scope , iElement , iAttrs ) {
218
+ scope . $watch ( 'dcDimension' , function ( dimension ) {
219
+ var allkeys , chart ;
220
+ if ( dimension !== null ) {
221
+ // we make a fake chart so that the dimension is known by dc.filterAll()
222
+ chart = dc . baseMixin ( { } ) ;
223
+ chart . dimension ( dimension ) ;
224
+ chart . group ( dimension ) ;
225
+ chart . _doRender = function ( ) { } ;
226
+ chart . _doRedraw = function ( ) { } ;
227
+ scope . selectModel = {
228
+ key : scope . allLabel
229
+ } ;
230
+ allkeys = dimension . group ( ) . orderNatural ( ) . all ( ) ;
231
+ scope . selectOptions = [ scope . selectModel ] . concat ( allkeys ) ;
232
+ }
233
+ } ) ;
234
+ return scope . $watch ( 'selectModel' , function ( sel ) {
235
+ if ( scope . dcDimension !== null ) {
236
+ if ( sel !== null && sel . key !== scope . allLabel ) {
237
+ scope . dcDimension . filter ( function ( d ) {
238
+ return d === sel . key ;
239
+ } ) ;
240
+ } else {
241
+ scope . dcDimension . filter ( null ) ;
242
+ }
243
+ dc . redrawAll ( ) ;
244
+ }
245
+ } ) ;
243
246
}
244
- } ) ;
247
+ } ;
245
248
}
246
- } ;
247
- } ] ) ;
249
+ ] ) ;
0 commit comments