summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 354fa3a)
raw | patch | inline | side by side (parent: 354fa3a)
author | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Sun, 27 Jul 2008 15:23:03 +0000 (17:23 +0200) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Sun, 27 Jul 2008 15:23:03 +0000 (17:23 +0200) |
Also you can now re-center the graph with a double click.
contrib/collection3/bin/index.cgi | patch | blob | history | |
contrib/collection3/share/navigate.js | patch | blob | history |
index d8769634624e5dc75329ca0e6b7bc0826c8b39da..927767e723a18730849ebd8f3792a8a9e5b962a1 100755 (executable)
<div class="graph_float">
<img id="${id}" class="graph_image"
alt="A graph"
- src="$url" />
+ src="$url"
+ ondblclick="nav_handle_dblclick (event);" />
<div class="controls zoom">
<div title="Earlier"
onclick="nav_move_earlier ('${id}');">←</div>
index 76deb5e52bb5c4ecf5e504828cb4d0232ba054b1..da47a6ac3c57fa6c5b6afc3b50afd55b2bc914e5 100644 (file)
all_images[i].navTimeEnd = new Number (time_end);
all_images[i].navBaseURL = all_images[i].src.replace (/;(begin|end)=[^;]*/g, '');
+
+ if (all_images[i].addEventListener) /* Mozilla */
+ all_images[i].addEventListener ('DOMMouseScroll', nav_handle_wheel,
+ false /* == bubbling */);
+ all_images[i].onmousewheel = nav_handle_wheel;
}
return (true);
} /* nav_init */
+function nav_image_repaint (img)
+{
+ if (!img || !img.navBaseURL
+ || !img.navTimeBegin || !img.navTimeEnd)
+ return;
+
+ img.src = img.navBaseURL + ";"
+ + "begin=" + img.navTimeBegin.toFixed (0) + ";"
+ + "end=" + img.navTimeEnd.toFixed (0);
+} /* nav_image_repaint */
+
function nav_time_reset (img_id ,diff)
{
var img;
img.navTimeEnd = new Number ((new Date ()).getTime () / 1000);
img.navTimeBegin = new Number (img.navTimeEnd - diff);
- img.src = img.navBaseURL + ";"
- + "begin=" + img.navTimeBegin.toFixed (0) + ";"
- + "end=" + img.navTimeEnd.toFixed (0);
+ nav_image_repaint (img);
return (true);
}
return (false);
diff = img.navTimeEnd - img.navTimeBegin;
- if (diff <= 300)
+
+ /* Prevent zooming in if diff is less than five minutes */
+ if ((diff <= 300) && (factor_begin > 0.0) && (factor_end < 0.0))
return (true);
img.navTimeBegin += (diff * factor_begin);
function nav_zoom_out (img_id)
{
return (nav_time_change (img_id, (-1.0 / 3.0), (1.0 / 3.0)));
-}
+} /* nav_zoom_in */
+
+function nav_recenter (e)
+{
+ var x;
+ var y;
+ var img;
+ var diff;
+ var time_old_center;
+ var time_new_center;
+ var width;
+
+ img = e.target;
+ if (!img || (img.className != "graph_image")
+ || !img.navTimeBegin || !img.navTimeEnd)
+ return;
+
+ width = img.width - 97;
+
+ x = e.layerX - 70;
+ if (!x || (x < 0) || (x > width))
+ return;
+
+ y = e.layerY;
+ if (!y || (y < 35) || (y > 135))
+ return;
+
+ diff = img.navTimeEnd - img.navTimeBegin;
+
+ time_old_center = img.navTimeBegin + (diff / 2.0);
+ time_new_center = img.navTimeBegin + (x * diff / width);
+
+ img.navTimeBegin += (time_new_center - time_old_center);
+ img.navTimeEnd += (time_new_center - time_old_center);
+} /* nav_recenter */
+
+function nav_handle_dblclick (e)
+{
+ var img;
+
+ /* M$IE */
+ if (!e)
+ e = window.event;
+
+ img = e.target;
+ if (!img || (img.className != "graph_image")
+ || !img.navTimeBegin || !img.navTimeEnd)
+ return;
+
+ nav_recenter (e);
+ nav_image_repaint (img);
+
+ // e.returnValue = false;
+} /* nav_handle_dblclick */
+
+/* Taken from <http://adomas.org/javascript-mouse-wheel/> */
+function nav_handle_wheel (e)
+{
+ var delta = 0;
+ var img;
+
+ /* M$IE */
+ if (!e)
+ e = window.event;
+
+ img = e.target;
+ if (!img || (img.className != "graph_image")
+ || !img.navTimeBegin || !img.navTimeEnd)
+ return;
+
+ /* Opera and M$IE */
+ if (e.wheelDelta)
+ {
+ delta = e.wheelDelta;
+ if (window.opera)
+ delta = delta * (-1);
+ }
+ else if (e.detail)
+ {
+ delta = e.detail * (-1);
+ }
+
+ if (!delta)
+ return;
+
+ nav_recenter (e);
+ if (delta > 0)
+ nav_zoom_in (img.id);
+ else
+ nav_zoom_out (img.id);
+
+ if (e.preventDefault)
+ e.preventDefault ();
+ e.returnValue = false;
+} /* function nav_handle_wheel */
+
/* vim: set sw=2 sts=2 et : */