angular.directive.js 940 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. (function (angular) {
  2. 'use strict';
  3. return angular.module('easypiechart', [])
  4. .directive('easypiechart', [function() {
  5. return {
  6. restrict: 'A',
  7. require: '?ngModel',
  8. scope: {
  9. percent: '=',
  10. options: '='
  11. },
  12. link: function (scope, element, attrs) {
  13. scope.percent = scope.percent || 0;
  14. /**
  15. * default easy pie chart options
  16. * @type {Object}
  17. */
  18. var options = {
  19. barColor: '#ef1e25',
  20. trackColor: '#f9f9f9',
  21. scaleColor: '#dfe0e0',
  22. scaleLength: 5,
  23. lineCap: 'round',
  24. lineWidth: 3,
  25. size: 110,
  26. rotate: 0,
  27. animate: {
  28. duration: 1000,
  29. enabled: true
  30. }
  31. };
  32. scope.options = angular.extend(options, scope.options);
  33. var pieChart = new EasyPieChart(element[0], options);
  34. scope.$watch('percent', function(newVal, oldVal) {
  35. pieChart.update(newVal);
  36. });
  37. }
  38. };
  39. }]);
  40. })(angular);