summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Levy <alon@pobox.com>2015-04-12 00:23:33 +0200
committerAlon Levy <alon@pobox.com>2015-04-12 00:23:44 +0200
commit3255529f9db0208f8e56689e31aa626251ba1e40 (patch)
tree365fd79e258513e21a7caa96627b499d071e8643 /src
parent72ada9fea8741c2a5eaa96bd28d70f322d6622bb (diff)
client: zoom to selection button instead of automatic on selection
Diffstat (limited to 'src')
-rw-r--r--src/client/buttons.js10
-rw-r--r--src/client/view/graph_view.js14
-rw-r--r--src/client/view/selection.js5
3 files changed, 17 insertions, 12 deletions
diff --git a/src/client/buttons.js b/src/client/buttons.js
index 514a94ba..59601762 100644
--- a/src/client/buttons.js
+++ b/src/client/buttons.js
@@ -1,7 +1,7 @@
"use strict"
-define(['jquery', 'FileSaver', 'rz_core', 'rz_api_backend'],
-function ($, saveAs, rz_core, rz_api_backend) {
+define(['jquery', 'FileSaver', 'rz_core', 'rz_api_backend', 'view/selection'],
+function ($, saveAs, rz_core, rz_api_backend, selection) {
$('.tutorial').click(function(){});
var key="#47989379";
@@ -249,5 +249,11 @@ $('#btn_zoom_in').asEventStream('click')
rz_core.main_graph_view.scale__absolute(val);
});
+$('#btn_zoom_to_selection').asEventStream('click')
+ .map(selection.selected_nodes)
+ .onValue(function (selected) {
+ rz_core.main_graph_view.nodes__user_visible(selected, true);
+ });
+
return {'buttons': 'nothing here'};
}); // define
diff --git a/src/client/view/graph_view.js b/src/client/view/graph_view.js
index e69bacc9..6c2efa3e 100644
--- a/src/client/view/graph_view.js
+++ b/src/client/view/graph_view.js
@@ -776,8 +776,7 @@ function GraphView(spec) {
in_view = segment_in_segment(scaled_low, scaled_high, screen_low, screen_high),
new_scale;
- new_scale = ((rect_high === rect_low || in_view) ?
- current_scale : (screen_high - screen_low) / (rect_high - rect_low) * percent);
+ new_scale = (screen_high - screen_low) / (rect_high - rect_low) * percent;
new_scale = Math.min(3, Math.max(0.1, new_scale));
return [
in_view
@@ -790,11 +789,12 @@ function GraphView(spec) {
];
}
- gv.nodes__user_visible = function(nodes) {
+ gv.nodes__user_visible = function(nodes, zoom_if_visible) {
if (nodes.length == 0) {
return;
}
- var xs = nodes.map(obj_take('x')),
+ var ratio_used = 0.8,
+ xs = nodes.map(obj_take('x')),
ys = nodes.map(obj_take('y')),
x_min = Math.min.apply(null, xs),
x_max = Math.max.apply(null, xs),
@@ -804,12 +804,12 @@ function GraphView(spec) {
current_translate = zoom_obj.translate(),
screen_width = $(document.body).innerWidth(),
screen_height = $(document.body).innerHeight(),
- x_data = scale_and_move(0, screen_width, x_min, x_max, 0.8,
+ x_data = scale_and_move(0, screen_width, x_min, x_max, ratio_used,
current_scale, current_translate[0]),
x_in_view = x_data[0],
x_scale = x_data[1],
x_translate_fn = x_data[2],
- y_data = scale_and_move(0, screen_height, y_min, y_max, 0.8,
+ y_data = scale_and_move(0, screen_height, y_min, y_max, ratio_used,
current_scale, current_translate[1]),
y_in_view = y_data[0],
y_scale = y_data[1],
@@ -818,7 +818,7 @@ function GraphView(spec) {
x_translate = x_translate_fn(min_scale),
y_translate = y_translate_fn(min_scale);
- if (!x_in_view || !y_in_view) {
+ if (zoom_if_visible || (!x_in_view || !y_in_view)) {
set_scale_translate(min_scale, [x_translate, y_translate]);
}
}
diff --git a/src/client/view/selection.js b/src/client/view/selection.js
index 7585b50f..6a7fa01f 100644
--- a/src/client/view/selection.js
+++ b/src/client/view/selection.js
@@ -245,7 +245,6 @@ var inner_select = function(new_root_nodes, new_selected_nodes)
// no change
return;
}
- get_main_graph_view().nodes__user_visible(new_selected_nodes);
updateSelectedNodesBus(new_root_nodes, new_selected_nodes);
}
@@ -338,8 +337,8 @@ return {
selectionChangedBus: selectionChangedBus,
setup_toolbar: setup_toolbar,
- __get_root_nodes: function() { return root_nodes; },
- __get_selected_nodes: function() { return selected_nodes; },
+ root_nodes: function() { return root_nodes; },
+ selected_nodes: function() { return selected_nodes; },
};
});