/
yearcounts.html.twig
106 lines (93 loc) · 3.94 KB
/
yearcounts.html.twig
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
{% extends is_sub_request ? 'subrequest.html.twig' : 'base.html.twig' %}
{% import 'macros/wiki.html.twig' as wiki %}
{% import 'macros/layout.html.twig' as layout %}
{% block body %}
{% if not is_sub_request %}
<div class="panel panel-primary">
<header class="panel-heading">
<div class="text-center xt-heading-top">
<a class="back-to-search" href="{{ path('EditCounterResult', {project: project.domain, username:user.username}) }}">
<span class="glyphicon glyphicon-chevron-left"></span>
{{ msg('see-full-statistics') }}
</a>
{{ wiki.userLink(user, project) }}
<small> • {{ project.domain }} </small>
</div>
</header>
<div class="panel-body xt-panel-body">
<section class="panel panel-default clearfix">
<header class="panel-heading col-lg-12">
<h4>
{{ msg('year-counts') }}
<span class='pull-right text-muted xt-panel-description'>
{{ layout.downloadLink('EditCounterYearCounts', {project:project.domain, username:user.username}, ['wikitext', 'csv']) }}
</span>
</h4>
</header>
<div class="panel-body col-lg-12">
{% endif %}
{% if ec.yearTotals|length > 0 %}
<table class="sr-only">
<thead>
<tr>
<th>{{ msg('year') }}</th>
<th>{{ msg('count') }}</th>
{% for ns in ec.yearCounts.totals|keys %}
<th>{{ nsName(ns, project.namespaces) }}</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for year,namespaces in ec.yearCountsWithNamespaces %}
<tr>
<td>{{ year }}</td>
<td>{{ ec.yearTotals[year]|num_format }}</td>
{% for _ns,count in namespaces %}
<td>{{ count|num_format }}</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
{# Set height of chart based on how many years (horizontal rows) are being reported. #}
<div style="position:relative; height:{{ (25 * ec.yearCounts.yearLabels|length) + 30 }}px">
<canvas id="yearcounts-canvas"></canvas>
</div>
<script type="text/javascript">
$(function() {
/** @type {Array} To be passed into Chart.js */
var datasets = [];
/** @type {Array} The labels for the y-axis. */
var labels = {{ ec.monthCounts.yearLabels|json_encode|raw }};
/** @type {Number} Max value of the year totals */
var maxTotal = 0;
// Format data for use in charts.
{% for nsId,namespaceData in ec.yearCounts.totals %}
var dataset = {
label: "{{ nsName(nsId, project.namespaces) }}",
backgroundColor: "{{ color(nsId) }}",
data: []
};
{% for year,yearData in namespaceData %}
dataset.data.push({{ yearData }});
// Determine maximum value for the totals. This is needed
// so that we know how much spacing to add in the labels.
if ({{ yearData }} > maxTotal) {
maxTotal = {{ yearData }};
}
{%- endfor -%}
datasets.push(dataset);
{% endfor %}
var showLegend = {% if is_sub_request %}false{% else %}true{% endif %};
xtools.editcounter.setupMonthYearChart('year', datasets, labels, maxTotal, showLegend);
});
</script>
{% else %}
<div class="alert alert-info">
{{ msg('no-contribs') }}
</div>
{% endif %}
{% if not is_sub_request %}
</div></section></div></div>
{% endif %}
{% endblock %}