Skip to content
This repository was archived by the owner on Jul 12, 2023. It is now read-only.

Commit 123f17e

Browse files
committed
When a date is clicked in the realm, highlight day in per-user data.
Fixes #799
1 parent d628881 commit 123f17e

File tree

1 file changed

+35
-20
lines changed

1 file changed

+35
-20
lines changed

cmd/server/assets/realmadmin/show.html

+35-20
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ <h1>Realm stats</h1>
3838
</tr>
3939
</thead>
4040
<tbody>
41-
{{range $stat := $stats}}
42-
<tr>
41+
{{range $i, $stat := $stats}}
42+
<tr onclick="highlightRow({{$i}})">
4343
<td>{{$stat.Date.Format "2006-01-02"}}</td>
4444
<td>{{$stat.CodesIssued}}</td>
4545
<td>{{$stat.CodesClaimed}}</td>
@@ -99,32 +99,47 @@ <h1>Realm stats</h1>
9999
{{end}}
100100
}
101101

102+
// fixDate converts the first element in an array to a Date.
103+
// This is just to properly munge types for Google Charts, and the
104+
// per-user-per-realm chart.
102105
function fixDate(arr) {
103106
arr[0] = new Date(arr[0])
104107
return arr
105108
}
106109

107-
function drawUsersChart() {
110+
// holds the per-user-per-realm chart & data created by Google Charts.
111+
var userChart, userChartData;
112+
113+
// highlightRow highlights a given row in the per-user-per-realm chart.
114+
function highlightRow(index) {
115+
var s = [];
116+
for (var i = 0; i < userChartData.getNumberOfColumns(); i++) {
117+
s = s.concat({row:index, column:i})
118+
}
119+
userChart.setSelection(s);
120+
}
121+
122+
function drawUsersChart() {
108123
{{if $userStats}}
109-
var data = new google.visualization.DataTable();
110-
111-
data.addColumn('date', 'Day');
112-
{{range $name := $names}}
113-
data.addColumn('number', '{{$name}}');
114-
{{end}}
115-
data.addRows([
116-
{{range $stat := $userStats}}
117-
fixDate({{$stat}}),
118-
{{end}}
119-
]);
124+
userChartData = new google.visualization.DataTable();
125+
126+
userChartData.addColumn('date', 'Day');
127+
{{range $name := $names}}
128+
userChartData.addColumn('number', '{{$name}}');
129+
{{end}}
130+
userChartData.addRows([
131+
{{range $stat := $userStats}}
132+
fixDate({{$stat}}),
133+
{{end}}
134+
]);
120135

121-
var options = {
122-
legend: {position: 'bottom'},
123-
tooltip: {trigger: 'focus'},
124-
};
136+
var options = {
137+
legend: {position: 'bottom'},
138+
tooltip: {trigger: 'focus'},
139+
};
125140

126-
var chart = new google.charts.Line(document.getElementById('per_user_chart'));
127-
chart.draw(data, google.charts.Line.convertOptions(options));
141+
userChart = new google.charts.Line(document.getElementById('per_user_chart'));
142+
userChart.draw(userChartData, google.charts.Line.convertOptions(options));
128143
{{end}}
129144
}
130145
</script>

0 commit comments

Comments
 (0)