Skip to content

Commit 052cd51

Browse files
author
Will
committed
Fixes jshint errors and removes unused timeout
1 parent 4f81a3f commit 052cd51

File tree

1 file changed

+64
-62
lines changed

1 file changed

+64
-62
lines changed

src/angular-dc.js

Lines changed: 64 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,17 @@ angular.module('angularDc', [])
5454
// Get additional options from chartElement's html attributes.
5555
// All options are prepended with 'dc-'' to avoid clashing with html own meaning (e.g width)
5656
// 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);
5858

5959
// we may have a dc-options attribute which contain a javascript object for stuff
6060
// not writtable in $parse language
61-
if ("options" in options) {
61+
if ('options' in options) {
6262
options = _.merge(options, options.options);
6363
options.options = undefined;
6464
}
6565
// If we have a dc-name attribute, we populate the scope with the chart
6666
// object dc-name
67-
if ("name" in options) {
67+
if ('name' in options) {
6868
scope[options.name] = chart;
6969
options.name = undefined;
7070
}
@@ -79,7 +79,7 @@ angular.module('angularDc', [])
7979
'postRedraw': options.onPostRedraw,
8080
'filtered': options.onFiltered,
8181
'zoomed': options.onZoomed,
82-
}).omit(_.isUndefined)
82+
}).omit(_.isUndefined);
8383

8484
// Register the eventHandlers with the chart (Dc.js)
8585
eventHandlers.each(function(handler, evt) {
@@ -100,7 +100,7 @@ angular.module('angularDc', [])
100100
return _(chart).functions()
101101
.extend(directiveOptions)
102102
.map(function(s) {
103-
return "dc" + s.charAt(0).toUpperCase() + s.substring(1)
103+
return 'dc' + s.charAt(0).toUpperCase() + s.substring(1);
104104
})
105105
.value();
106106
}
@@ -112,7 +112,7 @@ angular.module('angularDc', [])
112112
.map(function(key) {
113113
var value = scope.$eval(iAttrs[key]);
114114
// remove the dc- prefix if any
115-
if (key.substring(0, 2) === "dc") {
115+
if (key.substring(0, 2) === 'dc') {
116116
key = key.charAt(2).toLowerCase() + key.substring(3);
117117
}
118118
return [key, value];
@@ -126,66 +126,66 @@ angular.module('angularDc', [])
126126
var printExceptions = false;
127127
// add dc, d3 and commonly used Date method to the scope to allow snippets to be configured in
128128
// the templates
129-
scope.dc = dc
130-
scope.d3 = d3
129+
scope.dc = dc;
130+
scope.d3 = d3;
131131
scope.DateTime = function(a, b, c, d, e, f) {
132132
return new Date(a, b, c, d, e, f);
133-
}
133+
};
134134
scope.Date = function(a, b, c) {
135135
return new Date(a, b, c);
136-
}
136+
};
137137
// watch for the scope to settle until all the attributes are defined
138138
var unwatch = scope.$watch(function() {
139139
var options = _(iAttrs.$attr)
140140
.keys()
141141
.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';
143143
})
144144
.map(function(key) {
145145
try {
146146
// We ignore exception waiting for the data to be potentially loaded
147147
// by the controller
148148
var r = scope.$eval(iAttrs[key]);
149149
if (_.isUndefined(r)) {
150-
throw Error(iAttrs[key] + " is undefined")
150+
throw Error(iAttrs[key] + ' is undefined');
151151
}
152-
return r
152+
return r;
153153
} catch (e) {
154154
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;
157157
}
158-
return undefined
158+
return undefined;
159159
}
160160
});
161161
if (options.any(_.isUndefined)) {
162162
// return undefined if there is at least one undefined option
163163
// so that the $watch dont call us again at this $digest time
164-
return undefined
164+
return undefined;
165165
}
166-
return options.value()
166+
return options.value();
167167
}, function(options) {
168168
if (!_.isUndefined(options)) {
169169
// Stop the $watch, as we now created the charts
170-
unwatch()
170+
unwatch();
171171

172172
var chart = setupChart(scope, iElement, iAttrs);
173173
// 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() {
176176
chart.filterAll();
177177
dc.redrawAll();
178178
});
179-
a.attr("href", "javascript:;")
180-
a.css("display", "none")
179+
a.attr('href', 'javascript:;');
180+
a.css('display', 'none');
181181
// watching the attributes is costly, so we stop after first rendering
182182
chart.render();
183183
}
184184
});
185185
// if after 4 second we still get exceptions, we should raise them
186186
// to help debugging. $timeout will trigger another round of check.
187187
$timeout(function() {
188-
printExceptions = true
188+
printExceptions = true;
189189
}, 2000);
190190

191191
}
@@ -205,43 +205,45 @@ angular.module('angularDc', [])
205205
with same dimension. This is a limitation of the underlying lib dc.js
206206
*/
207207
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+
});
243246
}
244-
});
247+
};
245248
}
246-
};
247-
}]);
249+
]);

0 commit comments

Comments
 (0)