()
| 248 | //updates the graph by updating links, nodes and binding them with DOM |
| 249 | //interface is defined through several events |
| 250 | function restart() { |
| 251 | edges = edges.data(links, function(d) { |
| 252 | return "v" + d.source.id + "-v" + d.target.id; |
| 253 | }); |
| 254 | edges.exit().remove(); |
| 255 | |
| 256 | var ed = edges |
| 257 | .enter() |
| 258 | .append("line") |
| 259 | .attr("class", "edge") |
| 260 | .on("mousedown", function() { |
| 261 | d3.event.stopPropagation(); |
| 262 | }) |
| 263 | .on("contextmenu", removeEdge); |
| 264 | |
| 265 | ed.append("title").text(function(d) { |
| 266 | return "v" + d.source.id + "-v" + d.target.id; |
| 267 | }); |
| 268 | |
| 269 | edges = ed.merge(edges); |
| 270 | |
| 271 | //vertices are known by id |
| 272 | vertices = vertices.data(nodes, function(d) { |
| 273 | return d.id; |
| 274 | }); |
| 275 | vertices.exit().remove(); |
| 276 | |
| 277 | vertices.selectAll("text").text(function(d) { |
| 278 | return d.degree; |
| 279 | }); |
| 280 | |
| 281 | var g = vertices |
| 282 | .enter() |
| 283 | .append("g") |
| 284 | .attr("class", "vertex") |
| 285 | //so that force.drag and addNode don't interfere |
| 286 | //mousedown is initiated on circle which is stopped at .vertex |
| 287 | .on("mousedown", function() { |
| 288 | d3.event.stopPropagation(); |
| 289 | }); |
| 290 | |
| 291 | g.append("circle") |
| 292 | .attr("r", rad) |
| 293 | .style("fill", function(d, i) { |
| 294 | return colors[d.id % 10]; |
| 295 | }) |
| 296 | .on("mousedown", beginDragLine) |
| 297 | .on("mouseup", endDragLine) |
| 298 | .on("contextmenu", removeNode) |
| 299 | .append("title") |
| 300 | .text(function(d) { |
| 301 | return "v" + d.id; |
| 302 | }); |
| 303 | |
| 304 | g.append("text") |
| 305 | .attr("x", 0) |
| 306 | .attr("y", 4) |
| 307 | .text(function(d) { |
no outgoing calls
no test coverage detected