sangltdn / flot

Automatically exported from code.google.com/p/flot
MIT License
0 stars 0 forks source link

More control over zoom (enhancement) #274

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I need to dynamically change plot options/data when zooming in/out. For
instance, show/hide data points or normalize data depending on zoom level.
Below is a very minimalistic change to allow such a behavior.

--- /home/artem/jquery.flot.navigate.js 2009-12-09 20:06:46.000000000 +0300
+++ /home/artem/my_jquery.flot.navigate.js      2009-12-09
20:00:46.000000000 +0300
@@ -89,7 +89,8 @@
         zoom: {
             interactive: false,
             trigger: "dblclick", // or "click" for single click
-            amount: 1.5 // how much to zoom relative to current position,
2 = 200% (zoom in), 0.5 = 50% (zoom out)
+            amount: 1.5, // how much to zoom relative to current position,
2 = 200% (zoom in), 0.5 = 50% (zoom out)
+            beforeDraw: null //hook in dynamic zoom features here (e.g.
show points only after certain zoom level)
         },
         pan: {
             interactive: false
@@ -200,6 +201,10 @@
             scaleAxis(x1, x2, 'x2axis');
             scaleAxis(y1, y2, 'yaxis');
             scaleAxis(y1, y2, 'y2axis');
+
+            if (options.zoom.beforeDraw != undefined)    {
+                options.zoom.beforeDraw.apply(plot);
+            }

             plot.setupGrid();
             plot.draw();

------------

Hopefully this (or similar) will end up in flot.

Regards,
Artem.

Original issue reported on code.google.com by artem...@gmail.com on 9 Dec 2009 at 5:19

GoogleCodeExporter commented 9 years ago
pan feature probably needs the same hook

Original comment by artem...@gmail.com on 10 Dec 2009 at 9:48

GoogleCodeExporter commented 9 years ago
This ticket should be removed (sadly, I don't seem to be able to do it) in 
favor of
"Add processSetup hook"

Original comment by artem...@gmail.com on 11 Dec 2009 at 1:10

GoogleCodeExporter commented 9 years ago
Hi! I'm just going quickly reviewing opened tickets. Is there another ticket 
open or
do you think we should rename this? If so, please provide a little bit more 
info. :)

Original comment by olau%iol...@gtempaccount.com on 20 Jan 2010 at 3:22

GoogleCodeExporter commented 9 years ago
Hi! 

What a pleasant surprise! 
There is no other ticket, no.
Reason for the change: I need to interact with data upon zoom.
Demonstration:
Go to http://www.weatherdiff.com . Zoom in on overview tab of the graph. You 
will
notice that every time bar values are recalculated per current x-tick. Until, at
certain point of zoom, row values start showing instead of bars.

The proposed change is trivial:

artem:~/tmp/flot (master)$ diff -c jquery.flot.js
~/projects/weatherdiff/public/javascripts/jquery.flot.js
*** jquery.flot.js      Fri Oct 23 13:07:01 2009
--- /home/artem/projects/weatherdiff/public/javascripts/jquery.flot.js  Fri Dec 
18
20:45:17 2009
***************
*** 138,143 ****
--- 138,144 ----
              processOptions: [],
              processRawData: [],
              processDatapoints: [],
+             processSetup: [],
              draw: [],
              bindEvents: [],
              drawOverlay: []
***************
*** 725,730 ****
--- 726,733 ----
                  insertLabels();

              insertLegend();
+
+             executeHooks(hooks.processSetup, []);
          }

          function setRange(axis, axisOptions) {

If you are interested in how I then make use of it, check out
http://github.com/artemave/weatherdiff

Cheers,
Artem.

Original comment by artem...@gmail.com on 20 Jan 2010 at 4:02

GoogleCodeExporter commented 9 years ago
Here, to be more precise:
http://github.com/artemave/weatherdiff/blob/master/app/views/report/create.js.er
b

Original comment by artem...@gmail.com on 20 Jan 2010 at 6:10

GoogleCodeExporter commented 9 years ago

Original comment by dnsch...@gmail.com on 8 May 2012 at 11:30