Javascript - d3.js: Uncaught Typerror
<p>I am totally new to javascript. To get going I thought about implementing a small python script that would update a graph drawn with <code>d3.js</code>. However I get two errors and the graph will not update without reloading the page. Errors in <code>d3.js</code>: <code>Cannot read property "weight" of undefined</code> and <code>Cannot read property "weight" of undefined</code>. What am I doing wrong?</p>

<pre><code>&lt;script src="http://cdn.socket.io/stable/socket.io.js"&gt;&lt;/script&gt;
&lt;script src="http://d3js.org/d3.v3.min.js"&gt;&lt;/script&gt;
&lt;script&gt;
var s = new io.Socket(window.location.hostname, {
            port: 8001,
            rememberTransport: false,
            transports: [
                'websocket',
                'flashsocket',
                'xhr-multipart',
                'xhr-polling'
            ]
        });
        s.connect();

var width = 960,
    height = 500;

var color = d3.scale.category20();

var force = d3.layout.force()
    .charge(-120)
    .linkDistance(30)
    .size([width, height]);

var svg = d3.select("body").append("svg")
    .attr("width", width)
    .attr("height", height);

s.addEvent('message', function(data) {
  force
      .nodes(data.nodes)
      .links(data.links)
      .start();

  var link = svg.selectAll("line.link")
      .data(data.links)
    .enter().append("line")
      .attr("class", "link")
      .style("stroke-width", function(d) { return Math.sqrt(d.value); });

  var node = svg.selectAll("circle.node")
      .data(data.nodes)
    .enter().append("circle")
      .attr("class", "node")
      .attr("r", 5)
      .style("fill", function(d) { return color(d.group); })
      .call(force.drag);

  node.append("title")
      .text(function(d) { return d.name; });

  force.on("tick", function() {
    link.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; });

    node.attr("cx", function(d) { return d.x; })
        .attr("cy", function(d) { return d.y; });
  });
});
&lt;/script&gt;
</code></pre>
