This commit is contained in:
Julian Lam
2016-03-25 13:24:40 -04:00
parent 691802efad
commit 22f73a8f68
7 changed files with 177 additions and 145 deletions

View File

@@ -154,12 +154,6 @@ define('admin/manage/category', [
});
Category.setupPrivilegeTable();
if (window.location.hash === '#analytics') {
Category.setupGraphs();
} else {
$('a[href="#analytics"]').on('shown.bs.tab', Category.setupGraphs);
}
};
Category.setupPrivilegeTable = function() {
@@ -360,106 +354,5 @@ define('admin/manage/category', [
});
};
Category.setupGraphs = function() {
var hourlyCanvas = document.getElementById('pageviews:hourly'),
dailyCanvas = document.getElementById('pageviews:daily'),
topicsCanvas = document.getElementById('topics:daily'),
postsCanvas = document.getElementById('posts:daily'),
hourlyLabels = utils.getHoursArray().map(function(text, idx) {
return idx % 3 ? '' : text;
}),
dailyLabels = utils.getDaysArray().map(function(text, idx) {
return idx % 3 ? '' : text;
});
if (utils.isMobile()) {
Chart.defaults.global.showTooltips = false;
}
var data = {
'pageviews:hourly': {
labels: hourlyLabels,
datasets: [
{
label: "",
fillColor: "rgba(186,139,175,0.2)",
strokeColor: "rgba(186,139,175,1)",
pointColor: "rgba(186,139,175,1)",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(186,139,175,1)",
data: ajaxify.data.analytics['pageviews:hourly']
}
]
},
'pageviews:daily': {
labels: dailyLabels,
datasets: [
{
label: "",
fillColor: "rgba(151,187,205,0.2)",
strokeColor: "rgba(151,187,205,1)",
pointColor: "rgba(151,187,205,1)",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(151,187,205,1)",
data: ajaxify.data.analytics['pageviews:daily']
}
]
},
'topics:daily': {
labels: dailyLabels.slice(-7),
datasets: [
{
label: "",
fillColor: "rgba(171,70,66,0.2)",
strokeColor: "rgba(171,70,66,1)",
pointColor: "rgba(171,70,66,1)",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(171,70,66,1)",
data: ajaxify.data.analytics['topics:daily']
}
]
},
'posts:daily': {
labels: dailyLabels.slice(-7),
datasets: [
{
label: "",
fillColor: "rgba(161,181,108,0.2)",
strokeColor: "rgba(161,181,108,1)",
pointColor: "rgba(161,181,108,1)",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(161,181,108,1)",
data: ajaxify.data.analytics['posts:daily']
}
]
},
};
hourlyCanvas.width = $(hourlyCanvas).parent().width();
dailyCanvas.width = $(dailyCanvas).parent().width();
topicsCanvas.width = $(topicsCanvas).parent().width();
postsCanvas.width = $(postsCanvas).parent().width();
new Chart(hourlyCanvas.getContext('2d')).Line(data['pageviews:hourly'], {
responsive: true,
animation: false
});
new Chart(dailyCanvas.getContext('2d')).Line(data['pageviews:daily'], {
responsive: true,
animation: false
});
new Chart(topicsCanvas.getContext('2d')).Line(data['topics:daily'], {
responsive: true,
animation: false
});
new Chart(postsCanvas.getContext('2d')).Line(data['posts:daily'], {
responsive: true,
animation: false
});
};
return Category;
});