2017-01-31 23:26:29 +00:00
|
|
|
angular.module('portainer.services')
|
2017-06-01 08:14:55 +00:00
|
|
|
.factory('LineChart', [function LineChartFactory() {
|
2017-01-31 23:26:29 +00:00
|
|
|
'use strict';
|
|
|
|
return {
|
|
|
|
build: function (id, data, getkey) {
|
2017-05-23 18:56:10 +00:00
|
|
|
var chart = new Chart($(id).get(0).getContext('2d'));
|
2017-01-31 23:26:29 +00:00
|
|
|
var map = {};
|
|
|
|
|
|
|
|
for (var i = 0; i < data.length; i++) {
|
|
|
|
var c = data[i];
|
|
|
|
var key = getkey(c);
|
|
|
|
|
|
|
|
var count = map[key];
|
|
|
|
if (count === undefined) {
|
|
|
|
count = 0;
|
|
|
|
}
|
|
|
|
count += 1;
|
|
|
|
map[key] = count;
|
|
|
|
}
|
|
|
|
|
|
|
|
var labels = [];
|
|
|
|
data = [];
|
|
|
|
var keys = Object.keys(map);
|
|
|
|
var max = 1;
|
|
|
|
|
|
|
|
for (i = keys.length - 1; i > -1; i--) {
|
|
|
|
var k = keys[i];
|
|
|
|
labels.push(k);
|
|
|
|
data.push(map[k]);
|
|
|
|
if (map[k] > max) {
|
|
|
|
max = map[k];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var steps = Math.min(max, 10);
|
|
|
|
var dataset = {
|
2017-05-23 18:56:10 +00:00
|
|
|
fillColor: 'rgba(151,187,205,0.5)',
|
|
|
|
strokeColor: 'rgba(151,187,205,1)',
|
|
|
|
pointColor: 'rgba(151,187,205,1)',
|
|
|
|
pointStrokeColor: '#fff',
|
2017-01-31 23:26:29 +00:00
|
|
|
data: data
|
|
|
|
};
|
|
|
|
chart.Line({
|
|
|
|
labels: labels,
|
|
|
|
datasets: [dataset]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
scaleStepWidth: Math.ceil(max / steps),
|
|
|
|
pointDotRadius: 1,
|
|
|
|
scaleIntegersOnly: true,
|
|
|
|
scaleOverride: true,
|
|
|
|
scaleSteps: steps
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}]);
|