summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Levy <alon@pobox.com>2014-11-18 23:37:14 +0200
committerAlon Levy <alon@pobox.com>2014-11-18 23:37:14 +0200
commit38ef8cd6581da0f192785f0db4a47f1757a409d1 (patch)
treec53fbb9323289fd1087c891f7e91c1763a0e51a5 /src
parent2153abe2a2e3b4bdbba5abd8bc85efc4cf13a1c6 (diff)
set selected class on selected elements
Diffstat (limited to 'src')
-rw-r--r--src/rz_core.js30
1 files changed, 21 insertions, 9 deletions
diff --git a/src/rz_core.js b/src/rz_core.js
index 3f43b99d..0fc2e2d3 100644
--- a/src/rz_core.js
+++ b/src/rz_core.js
@@ -159,6 +159,10 @@ function canvas_handler_dblclick(){
});
}
+var node_selected = function(node) {
+ return node.state == 'chosen' || node.state == 'enter' || node.state == 'exit';
+}
+
function update(no_relayout) {
var node,
link,
@@ -223,15 +227,16 @@ function update(no_relayout) {
});
link.attr("class", function(d,i){
- if(d.name && d.name.replace(/ /g,"")=="and" && d.state==="temp")
- return "graph link temp_and";
- else
- return "graph link";
+ var temp_and = (d.name && d.name.replace(/ /g,"")=="and" && d.state==="temp") ? " temp_and" : "",
+ selected = node_selected(d) ? " selected" : "";
+
+ return "graph link" + temp_and + selected;
});
link.selectAll('path.link')
.attr('class', function(d) {
- return d.state + " link graph";
+ var selected = node_selected(d) ? " selected" : "";
+ return d.state + selected + " link graph";
});
link.exit().remove();
@@ -245,7 +250,10 @@ function update(no_relayout) {
linktext = vis.selectAll(".linklabel").data(graph.links());
linktext.enter()
.append("text")
- .attr("class", "linklabel graph")
+ .attr("class", function(d) {
+ var selected = node_selected(d) ? " selected" : "";
+ return "linklabel graph" + selected;
+ })
.attr("text-anchor", "middle")
.on("click", function(d, i) {
if (d.state !== "temp") {
@@ -276,7 +284,7 @@ function update(no_relayout) {
});
var nodeEnter = node.enter()
- .append("g").attr('class', 'node')
+ .append("g")
.attr('id', function(d){ return d.id; }) // append node id to enable data->visual mapping
.attr('visibility', 'hidden') // made visible on first tick
.on("click", function(d, i) {
@@ -293,8 +301,12 @@ function update(no_relayout) {
.call(drag);
node.each(function (d) {
- this.node = d;
- });
+ this.node = d;
+ })
+ .attr('class', function(d) {
+ var selected = node_selected(d) ? " selected" : "";
+ return 'node' + selected;
+ });
nodetext = nodeEnter.insert("text")
.attr("class", "nodetext graph")