title: D3: Yet another "Cannot read property 'weight' of undefined"
body: <p>I'm trying to create a force-directed graph with one twist: the node and link data comes from externally defined classes.    When I run it, I get the dreaded and familiar message:</p>
  
  <pre><code>Uncaught TypeError: Cannot read property 'weight' of undefined
  </code></pre>
  
  <p>I've read <a href="https://stackoverflow.com/q/28558334/558639">d3: Cannot read property &#39;weight&#39; of undefined in d3.force implementation</a> and the excellent <a href="https://stackoverflow.com/a/15060978/558639">https://stackoverflow.com/a/15060978/558639</a>.  But no joy.  </p>
  
  <p>I've created a JSFiddle in <a href="https://jsfiddle.net/3xcaqaLc/8/" rel="nofollow noreferrer">https://jsfiddle.net/3xcaqaLc/8/</a> which faithfully replicates the error.</p>
  
  <h3>what I've tried</h3>
  
  <p>The docs mentions a 'weights' property on the links, but it wasn't particularly clear if I needed to provide that.</p>
  
  <p>I added a <code>weight: 1.0</code> property to each link.  No joy.</p>
  
  <p>I added a <code>weight: 1.0</code> property to each node.  No joy.</p>
  
  <h3>what I've not tried</h3>
  
  <p>All the examples I found show the links constructed with zero-based indexes into the nodes array.  Instead, I'm constructing the links with references to the nodes themselves.  But according to the documentation for <code>#force.nodes()</code>, this should work (note the use of the word 'may'):</p>
  
  <blockquote>
    <p>Note: the values of the source and target attributes may be initially
    specified as indexes into the nodes array; these will be replaced by
    references after the call to start.</p>
  </blockquote>
  
  <p>Perhaps the documents are inaccurate, but solutions will be welcome!</p>