Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ultimately I was not able to reproduce your problem! The only thing that caught me at first was when I defined my mouseover and mouseout functions after setting them in .on(...) In that case they were undefined for the call and no mouse handlers were set - so the functions were simply never called.</p> <p>Anyway, you can see what I tried <a href="http://jsfiddle.net/tjYTL/2" rel="nofollow">here</a>. The code:</p> <pre><code>var w = 400, h = 400; var vis = d3.select("svg").attr("width", 800).attr("height", 800); var nodes = []; var links = []; for (var i = 0; i &lt; 30; i++) { var node = { label: "node " + i, value: Math.random(), key: i }; nodes.push(node); }; for (var i = 0; i &lt; nodes.length; i++) { for (var j = 0; j &lt; i; j++) { if (Math.random() &gt; .95) links.push({ source: nodes[i], target: nodes[j], weight: Math.random() }); } }; var force = d3.layout.force().size([w, h]).nodes(nodes).links(links); force.start(); var link = vis.selectAll("line.link").data(links).enter().append("line").style("stroke", "#CCC").attr("class", function(d) { return "link source-" + d.source.key + " target-" + d.target.key; }); var mouseover = function(d) { txt.text(JSON.stringify(d)); //txt.text("line.link.target-" + d.key); vis.selectAll("line.link.target-" + d.key).classed("target", true).style("stroke", '#F00'); vis.selectAll("line.link.source-" + d.key).classed("source", true).style("stroke", '#F00'); } var mouseout = function(d) { vis.selectAll("line.link.target-" + d.key).classed("target", false).style("stroke", "#CCC"); vis.selectAll("line.link.source-" + d.key).classed("source", false).style("stroke", "#CCC"); } var node = vis.selectAll("circle.node").data(force.nodes()).enter().append("circle").attr("class", "node").attr("r", 5).style("fill", function(d) { return d3.rgb(55 * d.value, 255 * d.value, 155 * d.value) }).style("stroke", "#FFF").style("stroke-width", 3).on("mouseover", mouseover).on("mouseout", mouseout).call(force.drag); var txt = vis.append('text').attr({ transform: 'translate(5,400)' }).text("Node Info"); var updateLink = function() { this.attr("x1", function(d) { return d.source.x; }).attr("y1", function(d) { return d.source.y; }).attr("x2", function(d) { return d.target.x; }).attr("y2", function(d) { return d.target.y; }); } var updateNode = function() { this.attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; }); } force.on("tick", function() { node.call(updateNode); link.call(updateLink); });​ </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload