ch/spanning-tree/app.js
//interface is defined through several events
interface is defined through several events
interface is defined through several events
function restart(al) {
  force.nodes(nodes);
  force.force("link").links(links);
  edges = edges.data(links, function(d) {
    return "v" + d.source.id + "-v" + d.target.id;
  });
  edges.exit().remove();
  var ed = edges
    .enter()
    .append("line")
    .attr("class", "edge")
    .on("contextmenu", removeEdge);
  ed.append("title").text(function(d) {
    return "v" + d.source.id + "-v" + d.target.id;
  });
  edges = ed.merge(edges);
  vertices = vertices.data(nodes, function(d) {
    return d.id;
  });
  vertices.exit().remove();
  var ve = vertices
    .enter()
    .append("circle")
    .attr("r", rad)
    .attr("class", "vertex")
    .style("fill", function(d, i) {
      return colors[d.id % 10];
    });
  ve.append("title").text(function(d) {
    return "v" + d.id;
  });
  vertices = ve.merge(vertices);
  force.alpha(al).restart();
}
function restart ( al ) { force . nodes ( nodes ) ; force . force ( "link" ) . links ( links ) ; edges = edges . data ( links , function ( d ) { return "v" + d . source . id + "-v" + d . target . id ; } ) ; edges . exit ( ) . remove ( ) ; var ed = edges . enter ( ) . append ( "line" ) . attr ( "class" , "edge" ) . on ( "contextmenu" , removeEdge ) ; ed . append ( "title" ) . text ( function ( d ) { return "v" + d . source . id + "-v" + d . target . id ; } ) ; edges = ed . merge ( edges ) ; vertices = vertices . data ( nodes , function ( d ) { return d . id ; } ) ; vertices . exit ( ) . remove ( ) ; var ve = vertices . enter ( ) . append ( "circle" ) . attr ( "r" , rad ) . attr ( "class" , "vertex" ) . style ( "fill" , function ( d , i ) { return colors [ d . id % 10 ] ; } ) ; ve . append ( "title" ) . text ( function ( d ) { return "v" + d . id ; } ) ; vertices = ve . merge ( vertices ) ; force . alpha ( al ) . restart ( ) ; }
interface is defined through several events
interface is defined through several events
//vertices are known by id