summaryrefslogtreecommitdiff
path: root/src/client/buttons.js
diff options
context:
space:
mode:
authorAlon Levy <alon@pobox.com>2015-04-06 17:50:54 +0300
committerAlon Levy <alon@pobox.com>2015-04-06 17:50:54 +0300
commit2560ce1acb0ecb910cc8f9045b0019f04cbf63d8 (patch)
tree418750f7f4ca567fc3722a9f1aad12a5d72047ae /src/client/buttons.js
parent938e1ba26bf27c6bb8055baff5c1082a8a20d760 (diff)
client: return zoom buttons, make zoom conserve center point
Diffstat (limited to 'src/client/buttons.js')
-rw-r--r--src/client/buttons.js34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/client/buttons.js b/src/client/buttons.js
index 8a0b6b7d..00554c8b 100644
--- a/src/client/buttons.js
+++ b/src/client/buttons.js
@@ -214,5 +214,39 @@ $('#btn_rzdoc__open').click(function() {
cmd_bar.fadeToggle(400);
});
+function log_scale(max_in, min_out, max_out) {
+ var t = (min_out * max_out - 1) / (min_out + max_out - 2),
+ k = 1 / max_in * Math.log((max_out - t) / (1 - t));
+
+ return function (x) { return (1 - t) * Math.exp(x * k) + t; };
+}
+
+function exp_scale(max_in, min_out, max_out) {
+ var t = (min_out * max_out - 1) / (min_out + max_out - 2),
+ k = 1 / max_in * Math.log((max_out - t) / (1 - t));
+
+ return function (y) { return (1 / k) * Math.log((y - t) / (1 - t)); };
+}
+
+function clip(min, max, v) {
+ return Math.max(min, Math.min(max, v));
+}
+
+var zoom_range = 10,
+ zoom_min = 0.1,
+ zoom_max = 3,
+ zoom_exp_to_linear = exp_scale(zoom_range, zoom_min, zoom_max);
+
+$('#btn_zoom_in').asEventStream('click')
+ .map(1)
+ .merge($('#btn_zoom_out').asEventStream('click').map(-1))
+ .map(function (change) {
+ return clip(-zoom_range, zoom_range, zoom_exp_to_linear(rz_core.main_graph_view.zoom_obj.scale()) + change);
+ })
+ .map(log_scale(zoom_range, zoom_min, zoom_max))
+ .onValue(function (val) {
+ rz_core.main_graph_view.scale__absolute(val);
+ });
+
return {'buttons': 'nothing here'};
}); // define