From b3dcd83155133fa786cc7ba272c82b430940ce7c Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Wed, 19 Sep 2012 17:13:11 +0530 Subject: [PATCH] Added code for plot zoom --- js/wn/views/grid_report.js | 53 +++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/js/wn/views/grid_report.js b/js/wn/views/grid_report.js index 69bd4453d1..4837c97943 100644 --- a/js/wn/views/grid_report.js +++ b/js/wn/views/grid_report.js @@ -349,8 +349,15 @@ wn.views.GridReport = Class.extend({ return; } wn.require('js/lib/flot/jquery.flot.js'); - $.plot(this.wrapper.find('.plot').toggle(true), plot_data, this.get_plot_options()); + + var plot_options = this.get_plot_options(); + var plot_area = this.wrapper.find('.plot'); + + $.plot(plot_area.toggle(true), plot_data, plot_options); this.setup_plot_hover(); + + // setup zoom if required + if(plot_options.zoom) this.setup_plot_zoom(plot_area); }, setup_plot_hover: function() { var me = this; @@ -386,6 +393,50 @@ wn.views.GridReport = Class.extend({ }); }, + setup_plot_zoom: function(plot_area) { + wn.require('js/lib/flot/jquery.flot.navigate.js'); + + // show pan/zoom messages to illustrate events + plot_area.bind('plotpan', function (event, plot) { + var axes = plot.getAxes(); + $(".message").html("Panning to x: " + axes.xaxis.min.toFixed(2) + + " – " + axes.xaxis.max.toFixed(2) + + " and y: " + axes.yaxis.min.toFixed(2) + + " – " + axes.yaxis.max.toFixed(2)); + }); + + plot_area.bind('plotzoom', function (event, plot) { + var axes = plot.getAxes(); + $(".message").html("Zooming to x: " + axes.xaxis.min.toFixed(2) + + " – " + axes.xaxis.max.toFixed(2) + + " and y: " + axes.yaxis.min.toFixed(2) + + " – " + axes.yaxis.max.toFixed(2)); + }); + + // add zoom out button + $('
zoom out
').appendTo(plot_area) + .click(function (e) { + e.preventDefault(); + plot.zoomOut(); + }); + + // and add panning buttons + + // little helper for taking the repetitive work out of placing + // panning arrows + function addArrow(dir, right, top, offset) { + $('') + .appendTo(plot_area).click(function (e) { + e.preventDefault(); + plot.pan(offset); + }); + } + + // addArrow('left', 55, 60, { left: -100 }); + // addArrow('right', 25, 60, { left: 100 }); + // addArrow('up', 40, 45, { top: -100 }); + // addArrow('down', 40, 75, { top: 100 }); + }, get_tooltip_text: function(label, x, y) { var date = dateutil.obj_to_user(new Date(x)); var value = fmt_money(y);