/**
* @ngdoc service
* @name ChartService
* @module s4c.services.ChartService
*
* @description Componente para acesso a api do backend e/ou comunicação entre controllers
*
*
*/
'use strict';
(function () {
/**
* @method ChartService
*/
function ChartService() {
/**
* @method appendChart
* @param {*} ctx
* @param {*} $q
* @param {*} tipo
*/
function appendChart(ctx, informacoes, tipo) {
new Chart(ctx, {
type: tipo,
data: {
labels: informacoes.legendas,
datasets: [{
label: "",
backgroundColor: informacoes.background,
data: informacoes.dados
},]
},
options: {
legend: {
display: false
},
responsive: true,
maintainAspectRatio: false,
// aspectRatio: 1.25,
title: {
display: true,
text: informacoes.titulo,
fontSize: 16
},
scales: {
yAxes: [{
ticks: {
beginAtZero: true,
fontColor: "white",
},
display: tipo !== 'pie' ? true : false
}],
xAxes: [{
ticks: {
fontColor: "white",
}
}]
}
}
});
Chart.defaults.global.animation.duration = 3000;
}
/**
* @method createColorArray
* @param {*} size
*/
function createColorArray(size) {
var array = [];
for (var index = 0; index < size; index++) {
array.push(getColor('rgb'));
}
return array;
}
/**
* @method getColor
* @param {*} format
*/
function getColor(format) {
var rint = Math.floor(0x100000000 * Math.random());
switch (format) {
case 'hex':
return '#' + ('00000' + rint.toString(16)).slice(-6).toUpperCase();
case 'hexa':
return '#' + ('0000000' + rint.toString(16)).slice(-8).toUpperCase();
case 'rgb':
return 'rgb(' + (rint & 255) + ',' + (rint >> 8 & 255) + ',' + (rint >> 16 & 255) + ')';
case 'rgba':
return 'rgba(' + (rint & 255) + ',' + (rint >> 8 & 255) + ',' + (rint >> 16 & 255) + ',' + (rint >> 24 & 255) / 255 + ')';
default:
return rint;
}
}
return {
appendChart: appendChart,
createColorArray: createColorArray
};
}
angular.module('s4c.services')
.factory('ChartService', ChartService);
ChartService.$inject = [];
}());