gosora/public/analytics.js
Azareal 0879f56893 Added per-forum analytics.
Added one week as a time range option.

Moved routeForum to routes.ViewForum
Renamed form_vars to formVars.
Moved the analytics chart JS into it's own file.
Changed the header text on the requests chart from Views to Requests.
Added simple hooks to global.js
Moved some of the in funcname prints to debug mode.
De-duplicated some of the back-end analytics logic.
2018-02-22 02:27:17 +00:00

39 lines
943 B
JavaScript

/*addHook(() => {
})*/
function buildStatsChart(rawLabels, seriesData, timeRange) {
let labels = [];
if(timeRange=="one-month") {
labels = ["today","01 days"];
for(let i = 2; i < 30; i++) {
let label = "0" + i + " days";
if(label.length > "01 days".length) label = label.substr(1);
labels.push(label);
}
} else if(timeRange=="one-week") {
labels = ["today"];
for(let i = 2; i < 14; i++) {
if (i%2==0) labels.push("");
else labels.push(Math.floor(i/2) + " days");
}
} else {
for(const i in rawLabels) {
let date = new Date(rawLabels[i]*1000);
console.log("date: ", date);
let minutes = "0" + date.getMinutes();
let label = date.getHours() + ":" + minutes.substr(-2);
console.log("label:", label);
labels.push(label);
}
}
labels = labels.reverse()
seriesData = seriesData.reverse();
Chartist.Line('.ct_chart', {
labels: labels,
series: [seriesData],
}, {
height: '250px',
});
}