diff options
| author | Alon Levy <alon@pobox.com> | 2015-07-26 00:26:35 +0300 |
|---|---|---|
| committer | Alon Levy <alon@pobox.com> | 2015-07-26 00:27:17 +0300 |
| commit | 02be1b488d0e2d24ee88bceb68dbc91af0a3663d (patch) | |
| tree | 5cb0473c8b28be21768e565de2b8564ba67a4dd8 /src/client/model/graph.js | |
| parent | 3ba06916b8122a6613412032056af50cb5c1fb43 (diff) | |
client: store positions in db instead of local storage
attributes used are currently a bit lame, since we don't support
nested attributes. So the attribute stored is:
layouts.<layout_name>.{x,y}
where layout_name is one of: force, user, ring.
Note that force layout still takes time initially, because alpha is
always set to 1 initially. This should probably be changed when a layout
is loaded.
Diffstat (limited to 'src/client/model/graph.js')
| -rw-r--r-- | src/client/model/graph.js | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/client/model/graph.js b/src/client/model/graph.js index f8253f7f..2c2bd89a 100644 --- a/src/client/model/graph.js +++ b/src/client/model/graph.js @@ -631,6 +631,47 @@ function Graph(spec) { rz_api_backend.commit_diff__attr(attr_diff, on_ajax_success, on_ajax_error); }; + /** + * Do an attribute commit with x, y for the current layout + */ + this.nodes__update_positions = function(layout_name) { + // TODO: fix when attribute diff supports nested keys to use: + // layout.<layout_name>.{x,y} + var x_key = 'layouts.' + layout_name + '.x', + y_key = 'layouts.' + layout_name + '.y'; + + // commit x, y to layout + _.values(id_to_node_map).forEach(function (node) { + node[x_key] = node.x; + node[y_key] = node.y; + }); + // commit all current nodes + nodes__commit_attributes(function (node) { + var d = {}; + + d[x_key] = node.x; + d[y_key] = node.y; + return d; + }); + }; + + function nodes__commit_attributes(getter) { + var attr_diff = model_diff.new_attr_diff(); + _.values(id_to_node_map).forEach(function (node) { + var d = getter(node); + _.keys(d).forEach(function (k) { + attr_diff.add_node_attr_write(node.id, k, d[k]); + }); + }); + var on_ajax_success = function() { + console.log('successfully committed x, y for current layout'); + }; + var on_ajax_error = function(){ + console.log('error with commit nodes properties to server'); + }; + rz_api_backend.commit_diff__attr(attr_diff, on_ajax_success, on_ajax_error); + } + this.update_node = function(node, new_node_spec) { util.assert(node instanceof model_core.Node); |
