aboutsummaryrefslogtreecommitdiffstats
path: root/static/js/stats.js
diff options
context:
space:
mode:
authorFilipp Lepalaan <filipp@mac.com>2015-08-04 10:11:24 +0300
committerFilipp Lepalaan <filipp@mac.com>2015-08-04 10:11:24 +0300
commit63b0fc6269b38edf7234b9f151b80d81f614c0a3 (patch)
tree555de3068f33f8dddb4619349bbea7d9b7c822fd /static/js/stats.js
downloadServo-63b0fc6269b38edf7234b9f151b80d81f614c0a3.tar.gz
Servo-63b0fc6269b38edf7234b9f151b80d81f614c0a3.tar.bz2
Servo-63b0fc6269b38edf7234b9f151b80d81f614c0a3.zip
Initial commit
First public commit
Diffstat (limited to 'static/js/stats.js')
-rwxr-xr-xstatic/js/stats.js121
1 files changed, 121 insertions, 0 deletions
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) {
+ $("<div id='tooltip'>" + contents + "</div>").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 $('<div>' + label + '<br/>' + pct + '%</div>').css({
+ "font-size": '8pt',
+ "text-align": 'center',
+ padding: '2px',
+ color: 'white'
+ }).html();
+ //return "<div style='font-size:8pt; text-align:center; padding:2px; color:white;'>" + label + "<br/>" + Math.round(series.percent) + "%</div>";
+}
+
+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);
+
+ });
+});