From 7dc78649f57f9cd7db25abf35fece19680a80a84 Mon Sep 17 00:00:00 2001 From: Alon Levy Date: Wed, 3 Dec 2014 19:11:50 +0200 Subject: selection: add update (reduces code in rz_core) --- src/view/selection.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'src/view') diff --git a/src/view/selection.js b/src/view/selection.js index bc1c38c0..dfc043e1 100644 --- a/src/view/selection.js +++ b/src/view/selection.js @@ -70,11 +70,24 @@ var clear = function() { get_rz_core().graph.setRegularState(); } +function all(arr, pred) +{ + return arr.length == arr.filter(pred).length; +} + +var update = function(nodes) { + clear(); + if (all(nodes, function(node) { return node.state != 'chosen'; })) { + connectedComponent(nodes); + } +} + return { - 'byVisitors': byVisitors, - 'connectedComponent': connectedComponent, - 'clear': clear, - 'selected_class': selected_class, + byVisitors: byVisitors, + connectedComponent: connectedComponent, + clear: clear, + update: update, + selected_class: selected_class, }; }); -- cgit v1.3.1