summaryrefslogtreecommitdiffstats
path: root/modules-available/statistics/clientscript.js
diff options
context:
space:
mode:
Diffstat (limited to 'modules-available/statistics/clientscript.js')
-rw-r--r--modules-available/statistics/clientscript.js76
1 files changed, 76 insertions, 0 deletions
diff --git a/modules-available/statistics/clientscript.js b/modules-available/statistics/clientscript.js
new file mode 100644
index 00000000..3c166f64
--- /dev/null
+++ b/modules-available/statistics/clientscript.js
@@ -0,0 +1,76 @@
+'use strict';
+
+// All the pie chars
+function makePieChart($parent) {
+ var data = $parent.data('chart');
+ var chartData = {
+ datasets: [{
+ data: data.map(function(x) { return x.value; }),
+ backgroundColor: data.map(function(x) { return x.color; })
+ }]
+ };
+ var $canv = $('<canvas style="width:100%;height:250px">');
+ $parent.append($canv);
+ (function() {
+ var $dest = $parent.data('chart-dest');
+ var cur = null;
+ new Chart($canv[0].getContext('2d'), {
+ type: 'pie', data: chartData, options: {
+ animation: false,
+ onHover: function (_, list) {
+ if (list.length === 0 || list[0].index !== cur) {
+ if (cur !== null) {
+ $($dest + cur).removeClass('slx-bold');
+ cur = null;
+ }
+ }
+ if (list.length !== 0 && list[0].index !== cur) {
+ cur = list[0].index;
+ $($dest + cur).addClass('slx-bold');
+ }
+ },
+ plugins: {
+ tooltip: {enabled: false},
+ legend: {display: false}
+ }
+ }
+ });
+ $canv.mouseout(function() {
+ if (cur !== null) {
+ $($dest + cur).removeClass('slx-bold');
+ cur = null;
+ }
+ });
+ })();
+}
+
+function popupFilter(field) {
+ var $row = addFilter(field, null, null);
+ if ($row !== null) {
+ $row.find('.arg').focus();
+ $row.removeClass('slx-focus')
+ setTimeout(function() { $row.addClass('slx-focus'); }, 10);
+ }
+}
+
+function addFilter(field, op, argument) {
+ if (field === null)
+ return null;
+ var $row = $('#filter-' + field);
+ if ($row.length === 0)
+ return null;
+ if (argument !== null) {
+ $row.find('.op').val(op);
+ $row.find('.arg').val(argument);
+ }
+ // Enable checkbox only if we got a predefined value, or if argument is in a select, as the user might want the preselected item and doesn't notice the checkbox is unchecked
+ if (argument !== null || $row.find('select.arg').length !== 0) {
+ $row.find('.filter-enable').prop('checked', true);
+ }
+ $row.show();
+ return $row;
+}
+
+function refresh() {
+ $('#query-form').submit();
+} \ No newline at end of file