diff options
| author | Alon Levy <alon@pobox.com> | 2015-04-05 17:06:03 +0300 |
|---|---|---|
| committer | Alon Levy <alon@pobox.com> | 2015-04-05 17:06:03 +0300 |
| commit | 9f21a23fd95dd77fbe5d87d02fc5b87ad2765c09 (patch) | |
| tree | 716d94d894cc99e71627b167b2069f40b4cad622 /src | |
| parent | f71a4bc132a252406b9e31d075e9fb12d365e154 (diff) | |
client/layouts: save+restore fixed property
Diffstat (limited to 'src')
| -rw-r--r-- | src/client/view/layouts.js | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/src/client/view/layouts.js b/src/client/view/layouts.js index f46c6793..b772b48f 100644 --- a/src/client/view/layouts.js +++ b/src/client/view/layouts.js @@ -39,27 +39,29 @@ function(consts, $, d3, _, rz_core) { function layout__empty(graph, base) { function save() { - layout.saved_nodes_position = layout.nodes().map(function (node) { - return [node.x, node.y, node.px, node.py]; - }); + layout.saved_nodes_position = _.object(layout.nodes().map(function (node) { + return [node.id, { + x: node.x, + y: node.y, + px: node.px, + py: node.py, + fixed: node.fixed + }]; + })); return layout; } function restore() { - if (layout.saved_nodes_position === undefined || - layout.saved_nodes_position.length != layout.nodes().length) { + if (layout.saved_nodes_position === undefined) { return layout; } - layout.nodes().forEach(function (node, i) { - var state = layout.saved_nodes_position[i]; - if (state[0] === undefined || state[1] === undefined || state[2] === undefined - || state[3] === undefined) { + layout.nodes().forEach(function (node) { + var state = layout.saved_nodes_position[node.id]; + + if (state === undefined) { return; } - node.x = state[0]; - node.y = state[1]; - node.px = state[2]; - node.py = state[3]; + _.extend(node, state); }); layout._saved_nodes_position = undefined; return layout; |
