From 63b0fc6269b38edf7234b9f151b80d81f614c0a3 Mon Sep 17 00:00:00 2001 From: Filipp Lepalaan Date: Tue, 4 Aug 2015 10:11:24 +0300 Subject: Initial commit First public commit --- static/js/stats.js | 121 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100755 static/js/stats.js (limited to 'static/js/stats.js') diff --git a/static/js/stats.js b/static/js/stats.js new file mode 100755 index 0000000..d382814 --- /dev/null +++ b/static/js/stats.js @@ -0,0 +1,121 @@ +/** + * stats.js + */ + +function showTooltip(x, y, contents) { + $("
" + contents + "
").css({ + position: "absolute", + display: "none", + top: y - 35, + left: x, + border: "1px solid #fdd", + padding: "2px", + "background-color": "#F3F6FA", + opacity: 0.80 + }).appendTo("body").fadeIn(200); +} + +function pieLabelFormatter(label, series) { + var pct = Math.round(series.percent); + return $('
' + label + '
' + pct + '%
').css({ + "font-size": '8pt', + "text-align": 'center', + padding: '2px', + color: 'white' + }).html(); + //return "
" + label + "
" + Math.round(series.percent) + "%
"; +} + +var prevX = null, + prevY = null; + +$('.plot').on('plothover', function(e, pos, item) { + if (!item) { + return false; // hovering outside data + } + + var x = item.datapoint[0], + y = item.datapoint[1]; + + if (x == prevX && y == prevY) { + return false; // hovering over the same point + } + + $('#tooltip').remove(); + + prevX = x; + prevY = y; + + var label = item.series.label + ": " + y; + + if ($(this).is('.plot-bar')) { + label = y; + } + + showTooltip(item.pageX, item.pageY, label); + +}); + +$('.plot').each(function(){ + var el = $(this); + var source = $(this).data('source'); + + var options = { + xaxis: { + mode: 'time', + timeformat: "%d.%m", + minTickSize: [1, "day"] + }, + lines: { + show: true, + fill: false + }, + points: { + show: true, + fill: true + }, + legend: { + show: true, + noColumns: 9, + container: $(el).next('.legend-container') + }, + grid: { + hoverable: true, + tickColor: "#f9f9f9", + borderWidth: 0 + }, + }; + + $.getJSON(source, function(data) { + if(el.is(".plot-bar")) { + options.legend = { show: false }; + options.tooltip = false; + options.bars = { show: true }; + options.lines = { show: false }; + options.points = { show: false }; + options.xaxis = { + ticks: data[0].label + }; + } + + if(el.is(".plot-pie")) { + options.tooltip = false; + options.legend = { show: false }; + options.series = { + pie: { + show: true, + radius: 1, + label: { + show: true, + radius: 1, + formatter: pieLabelFormatter, + background: { opacity: 0.8 } + } + } + }; + } + + $.plot(el, data, options); + + }); +}); -- cgit v1.2.3