summaryrefslogtreecommitdiff
path: root/src/view
diff options
context:
space:
mode:
authorAlon Levy <alon@pobox.com>2014-11-24 20:30:09 +0200
committerAlon Levy <alon@pobox.com>2014-11-24 20:30:09 +0200
commitf2ce89be26456be0fba9b298a19e98b83482170d (patch)
treed4cc432d2f8023859bfa91278484b250fa8eaf50 /src/view
parent224b9b40ef7ac3b560c28eaef8dea0473d362e71 (diff)
add search
The added input lets you select by *oring* multiple space less expressions. i.e. 'a b' will find all nodes with name containing either 'a' or 'b'. Not the specification, will be remedied later (i.e. maybe tomorrow, who knows). excuse the bulk commit, this does 3 things: splits off selection logic into src/view/selection - handles setting state explicityl on Node's, still bad. - bad at least the 'selected' state (i.e. boolean) is in one place. - common point for clicking on nodes/edges and selecting view selection input makes graph.getConnectedNodesAndLinks accept an array and not just a single node implements the search functionality outlined in the first paragraph.
Diffstat (limited to 'src/view')
-rw-r--r--src/view/selection.js80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/view/selection.js b/src/view/selection.js
new file mode 100644
index 00000000..57f2443d
--- /dev/null
+++ b/src/view/selection.js
@@ -0,0 +1,80 @@
+define(['rz_core'],
+function(rz_core) {
+
+function get_rz_core()
+{
+ // circular dependency on rz_core, so require.js cannot solve it.
+ if (rz_core === undefined) {
+ rz_core = require('rz_core');
+ }
+ return rz_core;
+}
+
+var selection = false;
+
+function byVisitors(node_selector, link_selector) {
+ selection = true;
+ var selected_nodes = get_rz_core().graph.findByVisitors(node_selector, link_selector);
+
+ clear();
+ connectedComponent(selected_nodes);
+}
+
+function connectedComponent(nodes) {
+ var nodes,
+ connected = get_rz_core().graph.getConnectedNodesAndLinks(nodes, 1),
+ i,
+ node,
+ link,
+ data;
+
+ selection = true;
+ nodes.forEach(function (n) { n.state = 'chosen'; });
+
+ for (i = 0 ; i < connected.nodes.length ; ++i) {
+ data = connected.nodes[i];
+ node = data.node;
+ switch (data.type) {
+ case 'exit':
+ node.state = 'exit';
+ break;
+ case 'enter':
+ node.state = 'enter';
+ break;
+ };
+ }
+ for (i = 0 ; i < connected.links.length ; ++i) {
+ data = connected.links[i];
+ link = data.link;
+ switch (data.type) {
+ case 'exit':
+ link.state = 'exit';
+ break;
+ case 'enter':
+ link.state = 'enter';
+ break;
+ };
+ }
+}
+
+var node_selected = function(node) {
+ return node.state == 'chosen' || node.state == 'enter' || node.state == 'exit' || node.state == 'selected';
+}
+
+var selected_class = function(node) {
+ return selection ? (node_selected(node) ? "selected" : "notselected") : "";
+}
+
+var clear = function() {
+ selection = false;
+ get_rz_core().graph.setRegularState();
+}
+
+return {
+ 'byVisitors': byVisitors,
+ 'connectedComponent': connectedComponent,
+ 'clear': clear,
+ 'selected_class': selected_class,
+};
+
+});