Skip to content

Commit

Permalink
adheres more to angular style guides
Browse files Browse the repository at this point in the history
  • Loading branch information
hellsan631 committed Aug 12, 2015
1 parent 50985af commit 252f589
Show file tree
Hide file tree
Showing 7 changed files with 190 additions and 159 deletions.
60 changes: 32 additions & 28 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -1,37 +1,41 @@
{
"globals": {
"document": false,
"jQuery": false,
"angular": false,
"d3": false,
"jasmine": false,
"spyOn": false,
"inject": false,
"it": false,
"iit": false,
"xit": false,
"console": false,
"describe": false,
"expect": false,
"beforeEach": false,
"waits": false,
"waitsFor": false,
"runs": false
},
"bitwise": true,
"browser": true,
"node": true,
"es5": true,
"esnext": true,
"eqeqeq": true,
"bitwise": false,
"curly": false,
"esnext": false,
"camelcase": true,
"eqeqeq": true,
"eqnull": true,
"indent": 2,
"immed": true,
"latedef": true,
"maxlen": 100,
"quotmark": "single",
"newcap": true,
"nonew": true,
"noarg": true,
"regexp": true,
"undef": true,
"strict": false,
"unused": false,
"strict": true,
"eqnull": true,
"trailing": true,
"smarttabs": true
}
"sub": true,
"globals": {
"document": false,
"angular": true,
"d3": false,
"jasmine": false,
"spyOn": false,
"inject": false,
"it": false,
"iit": false,
"xit": false,
"console": false,
"describe": false,
"expect": false,
"beforeEach": false,
"waits": false,
"waitsFor": false,
"runs": false
}
}
5 changes: 3 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = function(grunt) {
files: ['lib/**/*.js', 'test/*.spec.js'],
tasks: ['jshint', 'concat', 'uglify', 'karma:continuous'],
options: {
livereload: true,
livereload: true
}
},

Expand Down Expand Up @@ -86,7 +86,8 @@ module.exports = function(grunt) {

jshint: {
options: {
jshintrc: '.jshintrc'
jshintrc: '.jshintrc',
reporter: require('jshint-stylish')
},
gruntfile: {
src: 'Gruntfile.js'
Expand Down
139 changes: 76 additions & 63 deletions dist/pie-chart.js
Original file line number Diff line number Diff line change
@@ -1,71 +1,84 @@
/*! pie-chart - v1.0.0 - 2015-04-16
/*! pie-chart - v1.0.0 - 2015-08-12
* https://github.com/n3-charts/pie-chart
* Copyright (c) 2015 n3-charts Licensed , */
angular.module('n3-pie-chart', ['n3-pie-utils'])

.directive('pieChart', ['$utils', function($utils) {
var link = function($scope, element, attrs, ctrl) {
var svg;
var dim = $utils.getDefaultMargins();

var updateDimensions = function(dimensions) {
dimensions.width = element[0].parentElement.offsetWidth || 900;
dimensions.height = element[0].parentElement.offsetHeight || 500;
};

var update = function(data, options) {
$utils
.updatePaths(svg, data, dim, options)
.updateLegend(svg, data, dim, options)
;
};

var hard_update = function(data, options) {
$utils.clean(element[0]);
updateDimensions(dim);
draw(data, options, dim);
};

var draw = function(data, options, dimensions) {
if (!data || !options) {
return;
}

options = $utils.sanitizeOptions(options);

svg = $utils.bootstrap(element[0], dimensions);

$utils
.draw(svg)
.updatePaths(svg, data, dimensions, options)
.addLegend(svg)
.updateLegend(svg, data, dimensions, options)
;
};

$scope.$watch('data', function(newValue, oldValue) {
newValue = $utils.addDataForGauge(newValue, $scope.options);
(function() {
'use strict';

angular
.module('n3-pie-chart', ['n3-pie-utils'])
.directive('pieChart', PieChart);

PieChart.$inject = ['$utils', '$timeout', '$window'];

function PieChart($utils, $timeout, $window) {

var directive = {
replace: true,
restrict: 'E',
scope: {data: '=', options: '='},
template: '<div></div>',
link: link
};

return directive;

function link($scope, element, attrs, ctrl) {
var dim = $utils.getDefaultMargins();
var svg;

var updateDimensions = function(dimensions) {
dimensions.width = element[0].parentElement.offsetWidth || 900;
dimensions.height = element[0].parentElement.offsetHeight || 500;
};

var update = function(data, options) {
$utils
.updatePaths(svg, data, dim, options)
.updateLegend(svg, data, dim, options);
};

var forceUpdate = function(data, options) {
$utils.clean(element[0]);
updateDimensions(dim);
draw(data, options, dim);
};

var draw = function(data, options, dimensions) {
if (!data || !options) {
return;
}

options = $utils.sanitizeOptions(options);

svg = $utils.bootstrap(element[0], dimensions);

$utils
.draw(svg)
.updatePaths(svg, data, dimensions, options)
.addLegend(svg)
.updateLegend(svg, data, dimensions, options);
};

$scope.$watch('data', function(newValue, oldValue) {
newValue = $utils.addDataForGauge(newValue, $scope.options);

if (svg) {
update(newValue, $scope.options);
} else {
forceUpdate(newValue, $scope.options);
}
}, true);

$scope.$watch('options', function(newValue) {
var data = $utils.addDataForGauge($scope.data, newValue);
forceUpdate(data, newValue);
}, true);

if (svg) {
update(newValue, $scope.options);
} else {
hard_update(newValue, $scope.options);
}
}, true);
$scope.$watch('options', function(newValue) {
var data = $utils.addDataForGauge($scope.data, newValue);
hard_update(data, newValue);
}, true);
};
}
}
)();

return {
replace: true,
restrict: 'E',
scope: {data: '=', options: '='},
template: '<div></div>',
link: link
};
}]);
angular.module('n3-pie-utils', [])

.factory('$utils', [function() {
Expand Down
4 changes: 2 additions & 2 deletions dist/pie-chart.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/pie-chart.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! pie-chart - v1.0.0 - 2015-04-16
/*! pie-chart - v1.0.0 - 2015-08-12
* https://github.com/n3-charts/pie-chart
* Copyright (c) 2015 n3-charts Licensed , */
'use strict';
Expand Down
Loading

0 comments on commit 252f589

Please sign in to comment.