summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Levy <alon@pobox.com>2015-07-30 12:28:34 +0300
committerAlon Levy <alon@pobox.com>2015-07-30 18:05:06 +0300
commit37493ae16e0c1477f0991e5a04988a7204db6a2a (patch)
tree4e02204ef7cc12e5429efa1f7e16b9c51367cd6c /src
parent09a999fdabf1f415f8a33b318ccd3551e41654d3 (diff)
client/model/graph.nodes__update_positions: noop if change is too small (use configurable epsilon)
Diffstat (limited to 'src')
-rw-r--r--src/client/model/graph.js19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/client/model/graph.js b/src/client/model/graph.js
index a6f4f3a4..ab9b5902 100644
--- a/src/client/model/graph.js
+++ b/src/client/model/graph.js
@@ -641,6 +641,10 @@ function Graph(spec) {
}
this.layout_y_key = layout_y_key;
+ function close_to(a, b, eps) {
+ return Math.abs(a - b) < eps;
+ }
+
/**
* Do an attribute commit with x, y for the current layout
*/
@@ -648,13 +652,26 @@ function Graph(spec) {
// TODO: fix when attribute diff supports nested keys to use:
// layout.<layout_name>.{x,y}
var x_key = layout_x_key(layout_name),
- y_key = layout_y_key(layout_name);
+ y_key = layout_y_key(layout_name),
+ changes = 0;
// commit x, y to layout
_.values(id_to_node_map).forEach(function (node) {
+ var db_x = node[x_key],
+ db_y = node[y_key],
+ x = node.x,
+ y = node.y;
+
+ if (close_to(db_x, x, 0.0001) && close_to(db_y, y, 0.0001)) {
+ return;
+ }
node[x_key] = node.x;
node[y_key] = node.y;
+ changes += 1;
});
+ if (changes === 0) {
+ return;
+ }
// commit all current nodes
nodes__commit_attributes(function (node) {
var d = {};