2017-04-15 17:25:13 +02:00
|
|
|
var parseInputDate = function (inputDate) {
|
|
|
|
return moment(inputDate);
|
|
|
|
};
|
|
|
|
|
2016-12-28 06:18:17 +01:00
|
|
|
polr.controller('StatsCtrl', function($scope, $compile) {
|
|
|
|
$scope.dayChart = null;
|
|
|
|
$scope.refererChart = null;
|
|
|
|
$scope.countryChart = null;
|
|
|
|
|
|
|
|
$scope.dayData = dayData;
|
|
|
|
$scope.refererData = refererData;
|
|
|
|
$scope.countryData = countryData;
|
|
|
|
|
|
|
|
$scope.initDayChart = function () {
|
|
|
|
var ctx = $("#dayChart");
|
|
|
|
$scope.dayChart = new Chart(ctx, {
|
|
|
|
type: 'line',
|
|
|
|
data: {
|
|
|
|
datasets: [{
|
|
|
|
label: 'Clicks',
|
2017-01-26 23:03:07 +01:00
|
|
|
data: $scope.dayData,
|
|
|
|
pointHoverBackgroundColor: "rgba(75,192,192,1)",
|
|
|
|
pointHoverBorderColor: "rgba(220,220,220,1)",
|
|
|
|
backgroundColor: "rgba(75,192,192,0.4)",
|
|
|
|
borderColor: "rgba(75,192,192,1)",
|
2016-12-28 06:18:17 +01:00
|
|
|
}]
|
|
|
|
},
|
|
|
|
options: {
|
|
|
|
scales: {
|
|
|
|
xAxes: [{
|
|
|
|
type: 'time',
|
|
|
|
time: {
|
|
|
|
unit: 'day'
|
|
|
|
}
|
|
|
|
}],
|
|
|
|
yAxes: [{
|
|
|
|
ticks: {
|
|
|
|
min: 0
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
$scope.initRefererChart = function () {
|
|
|
|
// Traffic sources
|
|
|
|
var ctx = $("#refererChart");
|
|
|
|
|
|
|
|
var srcLabels = [];
|
|
|
|
// var bgColors = [];
|
|
|
|
var bgColors = [ '#003559', '#162955', '#2E4272', '#4F628E', '#7887AB', '#b9d6f2'];
|
|
|
|
var srcData = [];
|
|
|
|
|
|
|
|
_.each($scope.refererData, function (item) {
|
|
|
|
if (srcLabels.length > 6) {
|
|
|
|
// If more than 6 referers are listed, push the seventh and
|
|
|
|
// beyond into "other"
|
|
|
|
srcLabels[6] = 'Other';
|
|
|
|
srcData[6] += item.clicks;
|
|
|
|
bgColors[6] = 'brown';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
srcLabels.push(item.label);
|
|
|
|
srcData.push(item.clicks);
|
|
|
|
});
|
|
|
|
|
|
|
|
$scope.refererChart = new Chart(ctx, {
|
|
|
|
type: 'pie',
|
|
|
|
data: {
|
|
|
|
labels: srcLabels,
|
|
|
|
datasets: [{
|
|
|
|
data: srcData,
|
|
|
|
backgroundColor: bgColors
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#refererTable').DataTable();
|
|
|
|
};
|
|
|
|
$scope.initCountryChart = function () {
|
2016-12-28 06:44:06 +01:00
|
|
|
var parsedCountryData = {};
|
|
|
|
|
|
|
|
_.each($scope.countryData, function(country) {
|
|
|
|
parsedCountryData[country.label] = country.clicks;
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#mapChart').vectorMap({
|
|
|
|
map: 'world_mill',
|
|
|
|
series: {
|
|
|
|
regions: [{
|
|
|
|
values: parsedCountryData,
|
|
|
|
scale: ['#C8EEFF', '#0071A4'],
|
|
|
|
normalizeFunction: 'polynomial'
|
|
|
|
}]
|
|
|
|
},
|
2017-01-26 23:03:07 +01:00
|
|
|
onRegionTipShow: function(e, el, code) {
|
2016-12-28 06:44:06 +01:00
|
|
|
el.html(el.html()+' (' + (parsedCountryData[code] || 0) + ')');
|
|
|
|
}
|
|
|
|
});
|
2016-12-28 06:18:17 +01:00
|
|
|
|
|
|
|
};
|
2016-12-28 06:44:06 +01:00
|
|
|
|
2017-03-25 19:26:12 +01:00
|
|
|
$scope.initDatePickers = function () {
|
2017-04-15 17:25:13 +02:00
|
|
|
var $leftPicker = $('#left-bound-picker');
|
|
|
|
var $rightPicker = $('#right-bound-picker');
|
|
|
|
|
|
|
|
$leftPicker.datetimepicker();
|
|
|
|
$rightPicker.datetimepicker();
|
|
|
|
|
|
|
|
$leftPicker.data("DateTimePicker").parseInputDate(parseInputDate);
|
|
|
|
$rightPicker.data("DateTimePicker").parseInputDate(parseInputDate);
|
|
|
|
|
|
|
|
$leftPicker.data("DateTimePicker").date(datePickerLeftBound, Date, moment, null);
|
|
|
|
$rightPicker.data("DateTimePicker").date(datePickerRightBound, Date, moment, null);
|
2017-03-25 19:26:12 +01:00
|
|
|
}
|
|
|
|
|
2016-12-28 06:18:17 +01:00
|
|
|
$scope.init = function () {
|
|
|
|
$scope.initDayChart();
|
|
|
|
$scope.initRefererChart();
|
|
|
|
$scope.initCountryChart();
|
2017-03-25 19:26:12 +01:00
|
|
|
$scope.initDatePickers();
|
2016-12-28 06:18:17 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope.init();
|
|
|
|
|
|
|
|
});
|