/**
* @ngdoc directives
* @name chartPie
* @module s4c.directives.graficos.chartPie
*
* @description Componente para demonstração de gráficos no formato de Pizzas
*
*
*/
(function() {
'use strict';
chartPieController.$inject = [
'$scope',
'$timeout',
'Preset',
'DashboardService',
'ChartService'
];
function chartPieController(
$scope,
$timeout,
Preset,
DashboardService,
ChartService) {
$scope.res = $scope.$root.res;
$scope.canvas = {};
$scope.canvas.id = Math.random().toString(36) + '_chart';
/**
* Método responsável pela montagem do gráfico
*
* @method buildChartPie
*
* @param informacoes {Object} Dados para montagem do gráfico
*
*/
function buildChartPie(informacoes) {
var ctx = document.getElementById($scope.canvas.id).getElementsByTagName("canvas");
ChartService.appendChart(ctx, informacoes, 'pie');
Preset.salvar();
}
var modulos = Preset.obter().PresetModulos;
$scope.presetId = Preset.obter().id;
$timeout(function() {
for (var index in modulos) {
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) {
modulos[index].usado = true;
modulos[index].index = 1;
$scope.modulo = modulos[index];
var filtro = modulos[index].Face.extras.filtro || {};
/**
* Faz o acesso ao backend que retornará com os dados da busca para serem exibidos no gráfico
*
* @method getInformations
*
* @param filtro {Object} Dados para filtrar a busca
*
*/
DashboardService.getInformations(filtro).then(function (result) {
var informacoes = {
legendas: result.legendas,
dados: result.dados,
background: ChartService.createColorArray(result.dados.length),
titulo: modulos[index].Face.name
}
buildChartPie(informacoes);
});
break;
}
}
}, 300);
angular.extend($scope, {});
}
function s4cChartPie() {
return {
restrict: 'E',
templateUrl: 'app/directives/graficos/chartPie.html',
scope: {},
controller: chartPieController
};
}
angular.module('s4c.components.chartPie', [])
.directive('s4cChartpie', s4cChartPie);
})();