summaryrefslogtreecommitdiff
path: root/src/client/model/graph.js
diff options
context:
space:
mode:
authorAlon Levy <alon@pobox.com>2015-07-30 18:03:04 +0300
committerAlon Levy <alon@pobox.com>2015-07-30 18:03:06 +0300
commit1ea1f089d30cbae6884da4bef0d51b981c8d2e1b (patch)
treedfacb6ef4698d24a2a1d49609109b7ceeefca393 /src/client/model/graph.js
parentac9493adcba5e5d717ddaa1e95ae93a394f68d6a (diff)
client: record position to db when dragging + fixed
Record position when dragging. Record fixed status. this is still not clear - what fixed means exactly.
Diffstat (limited to 'src/client/model/graph.js')
-rw-r--r--src/client/model/graph.js35
1 files changed, 27 insertions, 8 deletions
diff --git a/src/client/model/graph.js b/src/client/model/graph.js
index 5e54d228..40df0896 100644
--- a/src/client/model/graph.js
+++ b/src/client/model/graph.js
@@ -641,6 +641,11 @@ function Graph(spec) {
}
this.layout_y_key = layout_y_key;
+ function layout_fixed_key(layout_name) {
+ return 'layouts_' + layout_name + '_fixed';
+ }
+ this.layout_fixed_key = layout_fixed_key;
+
function close_to(a, b, eps) {
return Math.abs(a - b) < eps;
}
@@ -650,16 +655,28 @@ function Graph(spec) {
/**
* Do an attribute commit with x, y for the current layout
*/
- this.nodes__update_positions = function(layout_name) {
+ this.nodes__store_layout_positions = function(layout_name, node_ids) {
// 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),
- changes = 0;
+ fixed_key = layout_fixed_key(layout_name),
+ changes = 0,
+ fixed = false;
+
+ if (node_ids && node_ids.forEach) {
+ node_ids = node_ids.filter(function (node_id) {
+ return id_to_node_map[node_id] !== undefined;
+ });
+ fixed = true;
+ } else {
+ node_ids = _.keys(id_to_node_map);
+ }
// commit x, y to layout
- _.values(id_to_node_map).forEach(function (node) {
- var db_x = node[x_key],
+ node_ids.forEach(function (node_id) {
+ var node = id_to_node_map[node_id],
+ db_x = node[x_key],
db_y = node[y_key],
x = node.x,
y = node.y;
@@ -676,19 +693,21 @@ function Graph(spec) {
}
console.log('sending ' + changes + ' nodes position for layout ' + layout_name);
// commit all current nodes
- nodes__commit_attributes(function (node) {
+ nodes__commit_attributes(node_ids, function (node) {
var d = {};
d[x_key] = node.x;
d[y_key] = node.y;
+ d[fixed_key] = fixed;
return d;
});
};
- function nodes__commit_attributes(getter) {
+ function nodes__commit_attributes(node_ids, getter) {
var attr_diff = model_diff.new_attr_diff();
- _.values(id_to_node_map).forEach(function (node) {
- var d = getter(node);
+ node_ids.forEach(function (node_id) {
+ var node = id_to_node_map[node_id],
+ d = getter(node);
_.keys(d).forEach(function (k) {
attr_diff.add_node_attr_write(node.id, k, d[k]);
});