summaryrefslogtreecommitdiff
path: root/p/scripts/stats.js
blob: 2e8ab6e274d0a8aa9239eff90267e0a8734557ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"use strict";
function initStats() {
	if (!window.Flotr) {
		if (window.console) {
			console.log('FreshRSS waiting for Flotr…');
		}
		window.setTimeout(initStats, 50);
		return;
	}
	var jsonStats = document.getElementById('jsonStats'),
		stats = JSON.parse(jsonStats.innerHTML);
	jsonStats.outerHTML = '';
	// Entry per day
	var avg = [];
	for (var i = -31; i <= 0; i++) {
		avg.push([i, stats.average]);
	}
	Flotr.draw(document.getElementById('statsEntryPerDay'),
		[{
			data: stats.dataCount,
			bars: {horizontal: false, show: true}
		},{
			data: avg,
			lines: {show: true},
			label: stats.average,
		}],
		{
			grid: {verticalLines: false},
			xaxis: {noTicks: 6, showLabels: false, tickDecimals: 0, min: -30.75, max: -0.25},
			yaxis: {min: 0},
			mouse: {relative: true, track: true, trackDecimals: 0, trackFormatter: function(obj) {return numberFormat(obj.y);}}
		});
	// Feed per category
	Flotr.draw(document.getElementById('statsFeedPerCategory'),
		stats.feedByCategory,
		{
			grid: {verticalLines: false, horizontalLines: false},
			pie: {explode: 10, show: true, labelFormatter: function(){return '';}},
			xaxis: {showLabels: false},
			yaxis: {showLabels: false},
			mouse: {relative: true, track: true, trackDecimals: 0, trackFormatter: function(obj) {return obj.series.label + ' - '+ numberFormat(obj.y) + ' ('+ (obj.fraction * 100).toFixed(1) + '%)';}},
			legend: {container: document.getElementById('statsFeedPerCategoryLegend'), noColumns: 3}
		});
	// Entry per category
	Flotr.draw(document.getElementById('statsEntryPerCategory'),
		stats.entryByCategory,
		{
			grid: {verticalLines: false, horizontalLines: false},
			pie: {explode: 10, show: true, labelFormatter: function(){return '';}},
			xaxis: {showLabels: false},
			yaxis: {showLabels: false},
			mouse: {relative: true, track: true, trackDecimals: 0, trackFormatter: function(obj) {return obj.series.label + ' - '+ numberFormat(obj.y) + ' ('+ (obj.fraction * 100).toFixed(1) + '%)';}},
			legend: {container: document.getElementById('statsEntryPerCategoryLegend'), noColumns: 3}
		});
}
initStats();