2016-03-25 13:24:40 -04:00
|
|
|
"use strict";
|
2016-07-29 19:31:48 +00:00
|
|
|
/*global define, ajaxify, utils */
|
2016-03-25 13:24:40 -04:00
|
|
|
|
2016-05-24 22:01:46 -04:00
|
|
|
define('admin/manage/category-analytics', ['Chart'], function(Chart) {
|
2016-03-25 13:24:40 -04:00
|
|
|
var CategoryAnalytics = {};
|
|
|
|
|
|
|
|
|
|
CategoryAnalytics.init = function() {
|
2016-07-29 19:31:48 +00:00
|
|
|
var hourlyCanvas = document.getElementById('pageviews:hourly');
|
|
|
|
|
var dailyCanvas = document.getElementById('pageviews:daily');
|
|
|
|
|
var topicsCanvas = document.getElementById('topics:daily');
|
|
|
|
|
var postsCanvas = document.getElementById('posts:daily');
|
|
|
|
|
var hourlyLabels = utils.getHoursArray().map(function(text, idx) {
|
2016-03-25 13:24:40 -04:00
|
|
|
return idx % 3 ? '' : text;
|
2016-07-29 19:31:48 +00:00
|
|
|
});
|
|
|
|
|
var dailyLabels = utils.getDaysArray().map(function(text, idx) {
|
2016-03-25 13:24:40 -04:00
|
|
|
return idx % 3 ? '' : text;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (utils.isMobile()) {
|
2016-07-29 19:31:48 +00:00
|
|
|
Chart.defaults.global.tooltips.enabled = false;
|
2016-03-25 13:24:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var data = {
|
|
|
|
|
'pageviews:hourly': {
|
|
|
|
|
labels: hourlyLabels,
|
|
|
|
|
datasets: [
|
|
|
|
|
{
|
|
|
|
|
label: "",
|
2016-07-29 19:31:48 +00:00
|
|
|
backgroundColor: "rgba(186,139,175,0.2)",
|
|
|
|
|
borderColor: "rgba(186,139,175,1)",
|
|
|
|
|
pointBackgroundColor: "rgba(186,139,175,1)",
|
|
|
|
|
pointHoverBackgroundColor: "#fff",
|
|
|
|
|
pointBorderColor: "#fff",
|
|
|
|
|
pointHoverBorderColor: "rgba(186,139,175,1)",
|
2016-03-25 13:24:40 -04:00
|
|
|
data: ajaxify.data.analytics['pageviews:hourly']
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
'pageviews:daily': {
|
|
|
|
|
labels: dailyLabels,
|
|
|
|
|
datasets: [
|
|
|
|
|
{
|
|
|
|
|
label: "",
|
2016-07-29 19:31:48 +00:00
|
|
|
backgroundColor: "rgba(151,187,205,0.2)",
|
|
|
|
|
borderColor: "rgba(151,187,205,1)",
|
|
|
|
|
pointBackgroundColor: "rgba(151,187,205,1)",
|
|
|
|
|
pointHoverBackgroundColor: "#fff",
|
|
|
|
|
pointBorderColor: "#fff",
|
|
|
|
|
pointHoverBorderColor: "rgba(151,187,205,1)",
|
2016-03-25 13:24:40 -04:00
|
|
|
data: ajaxify.data.analytics['pageviews:daily']
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
'topics:daily': {
|
|
|
|
|
labels: dailyLabels.slice(-7),
|
|
|
|
|
datasets: [
|
|
|
|
|
{
|
|
|
|
|
label: "",
|
2016-07-29 19:31:48 +00:00
|
|
|
backgroundColor: "rgba(171,70,66,0.2)",
|
|
|
|
|
borderColor: "rgba(171,70,66,1)",
|
|
|
|
|
pointBackgroundColor: "rgba(171,70,66,1)",
|
|
|
|
|
pointHoverBackgroundColor: "#fff",
|
|
|
|
|
pointBorderColor: "#fff",
|
|
|
|
|
pointHoverBorderColor: "rgba(171,70,66,1)",
|
2016-03-25 13:24:40 -04:00
|
|
|
data: ajaxify.data.analytics['topics:daily']
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
'posts:daily': {
|
|
|
|
|
labels: dailyLabels.slice(-7),
|
|
|
|
|
datasets: [
|
|
|
|
|
{
|
|
|
|
|
label: "",
|
2016-07-29 19:31:48 +00:00
|
|
|
backgroundColor: "rgba(161,181,108,0.2)",
|
|
|
|
|
borderColor: "rgba(161,181,108,1)",
|
|
|
|
|
pointBackgroundColor: "rgba(161,181,108,1)",
|
|
|
|
|
pointHoverBackgroundColor: "#fff",
|
|
|
|
|
pointBorderColor: "#fff",
|
|
|
|
|
pointHoverBorderColor: "rgba(161,181,108,1)",
|
2016-03-25 13:24:40 -04:00
|
|
|
data: ajaxify.data.analytics['posts:daily']
|
|
|
|
|
}
|
|
|
|
|
]
|
2016-05-24 21:14:14 -04:00
|
|
|
}
|
2016-03-25 13:24:40 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
hourlyCanvas.width = $(hourlyCanvas).parent().width();
|
|
|
|
|
dailyCanvas.width = $(dailyCanvas).parent().width();
|
|
|
|
|
topicsCanvas.width = $(topicsCanvas).parent().width();
|
|
|
|
|
postsCanvas.width = $(postsCanvas).parent().width();
|
2016-07-29 19:31:48 +00:00
|
|
|
|
|
|
|
|
new Chart(hourlyCanvas.getContext('2d'), {
|
|
|
|
|
type: 'line',
|
|
|
|
|
data: data['pageviews:hourly'],
|
|
|
|
|
options: {
|
|
|
|
|
responsive: true,
|
|
|
|
|
animation: false,
|
|
|
|
|
legend: {
|
|
|
|
|
display: false
|
|
|
|
|
},
|
|
|
|
|
scales: {
|
|
|
|
|
yAxes: [{
|
|
|
|
|
ticks: {
|
|
|
|
|
beginAtZero: true
|
|
|
|
|
}
|
|
|
|
|
}]
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-03-25 13:24:40 -04:00
|
|
|
});
|
2016-07-29 19:31:48 +00:00
|
|
|
|
|
|
|
|
new Chart(dailyCanvas.getContext('2d'), {
|
|
|
|
|
type: 'line',
|
|
|
|
|
data: data['pageviews:daily'],
|
|
|
|
|
options: {
|
|
|
|
|
responsive: true,
|
|
|
|
|
animation: false,
|
|
|
|
|
legend: {
|
|
|
|
|
display: false
|
|
|
|
|
},
|
|
|
|
|
scales: {
|
|
|
|
|
yAxes: [{
|
|
|
|
|
ticks: {
|
|
|
|
|
beginAtZero: true
|
|
|
|
|
}
|
|
|
|
|
}]
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-03-25 13:24:40 -04:00
|
|
|
});
|
2016-07-29 19:31:48 +00:00
|
|
|
|
|
|
|
|
new Chart(topicsCanvas.getContext('2d'), {
|
|
|
|
|
type: 'line',
|
|
|
|
|
data: data['topics:daily'],
|
|
|
|
|
options: {
|
|
|
|
|
responsive: true,
|
|
|
|
|
animation: false,
|
|
|
|
|
legend: {
|
|
|
|
|
display: false
|
|
|
|
|
},
|
|
|
|
|
scales: {
|
|
|
|
|
yAxes: [{
|
|
|
|
|
ticks: {
|
|
|
|
|
beginAtZero: true
|
|
|
|
|
}
|
|
|
|
|
}]
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-03-25 13:24:40 -04:00
|
|
|
});
|
2016-07-29 19:31:48 +00:00
|
|
|
|
|
|
|
|
new Chart(postsCanvas.getContext('2d'), {
|
|
|
|
|
type: 'line',
|
|
|
|
|
data: data['posts:daily'],
|
|
|
|
|
options: {
|
|
|
|
|
responsive: true,
|
|
|
|
|
animation: false,
|
|
|
|
|
legend: {
|
|
|
|
|
display: false
|
|
|
|
|
},
|
|
|
|
|
scales: {
|
|
|
|
|
yAxes: [{
|
|
|
|
|
ticks: {
|
|
|
|
|
beginAtZero: true
|
|
|
|
|
}
|
|
|
|
|
}]
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-03-25 13:24:40 -04:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return CategoryAnalytics;
|
|
|
|
|
});
|