summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Levy <alon@pobox.com>2015-03-16 21:08:20 +0200
committerAlon Levy <alon@pobox.com>2015-03-16 21:08:20 +0200
commitcb8304d24eefe57cd3ae35aa26275277af92d73d (patch)
tree9ac08205ff540258c1fce8cb676cd7bf15941b97 /src
parentbde034fb87784f42349b4527aa343b89d3999090 (diff)
client: plus/minus zoom implementation using log scale, state still in d3.behavior.zoom
Diffstat (limited to 'src')
-rw-r--r--src/client/buttons.js33
-rw-r--r--src/client/view/graph_view.js6
2 files changed, 39 insertions, 0 deletions
diff --git a/src/client/buttons.js b/src/client/buttons.js
index 2a77829f..7c3b25b6 100644
--- a/src/client/buttons.js
+++ b/src/client/buttons.js
@@ -88,5 +88,38 @@ $('a.save-history').click(function () {
}
rz_core.main_graph.history.save_to_file();
});
+
+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(rz_core.main_graph_view.scale__absolute);
+
return {'buttons': 'nothing here'};
}); // define
diff --git a/src/client/view/graph_view.js b/src/client/view/graph_view.js
index 1f43b634..9942e2d6 100644
--- a/src/client/view/graph_view.js
+++ b/src/client/view/graph_view.js
@@ -666,6 +666,12 @@ function GraphView(spec) {
}
gv.__set_scale_translate = set_scale_translate;
+ var scale__absolute = function (scale) {
+ set_scale_translate(scale, zoom_obj.translate());
+ }
+
+ gv.scale__absolute = scale__absolute;
+
gv.update_view = update_view;
function start_layout_animation() {
on_interval = function() {