Source: directives/graficos/chartPie.js

  1. /**
  2. * @ngdoc directives
  3. * @name chartPie
  4. * @module s4c.directives.graficos.chartPie
  5. *
  6. * @description Componente para demonstração de gráficos no formato de Pizzas
  7. *
  8. *
  9. */
  10. (function() {
  11. 'use strict';
  12. chartPieController.$inject = [
  13. '$scope',
  14. '$timeout',
  15. 'Preset',
  16. 'DashboardService',
  17. 'ChartService'
  18. ];
  19. function chartPieController(
  20. $scope,
  21. $timeout,
  22. Preset,
  23. DashboardService,
  24. ChartService) {
  25. $scope.res = $scope.$root.res;
  26. $scope.canvas = {};
  27. $scope.canvas.id = Math.random().toString(36) + '_chart';
  28. /**
  29. * Método responsável pela montagem do gráfico
  30. *
  31. * @method buildChartPie
  32. *
  33. * @param informacoes {Object} Dados para montagem do gráfico
  34. *
  35. */
  36. function buildChartPie(informacoes) {
  37. var ctx = document.getElementById($scope.canvas.id).getElementsByTagName("canvas");
  38. ChartService.appendChart(ctx, informacoes, 'pie');
  39. Preset.salvar();
  40. }
  41. var modulos = Preset.obter().PresetModulos;
  42. $scope.presetId = Preset.obter().id;
  43. $timeout(function() {
  44. for (var index in modulos) {
  45. if ((modulos[index].template == 'app/components/modulos/modulo-chartPie.html' || (modulos[index].Face && modulos[index].Face.template == 'app/components/modulos/modulo-chartPie.html')) && !modulos[index].usado) {
  46. modulos[index].usado = true;
  47. modulos[index].index = 1;
  48. $scope.modulo = modulos[index];
  49. var filtro = modulos[index].Face.extras.filtro || {};
  50. /**
  51. * Faz o acesso ao backend que retornará com os dados da busca para serem exibidos no gráfico
  52. *
  53. * @method getInformations
  54. *
  55. * @param filtro {Object} Dados para filtrar a busca
  56. *
  57. */
  58. DashboardService.getInformations(filtro).then(function (result) {
  59. var informacoes = {
  60. legendas: result.legendas,
  61. dados: result.dados,
  62. background: ChartService.createColorArray(result.dados.length),
  63. titulo: modulos[index].Face.name
  64. }
  65. buildChartPie(informacoes);
  66. });
  67. break;
  68. }
  69. }
  70. }, 300);
  71. angular.extend($scope, {});
  72. }
  73. function s4cChartPie() {
  74. return {
  75. restrict: 'E',
  76. templateUrl: 'app/directives/graficos/chartPie.html',
  77. scope: {},
  78. controller: chartPieController
  79. };
  80. }
  81. angular.module('s4c.components.chartPie', [])
  82. .directive('s4cChartpie', s4cChartPie);
  83. })();