title: Constructing Force Directed Graphs From Only Link Data
body: <p>I am a bit new to d3.js, but I'm having quite a bit of fun with it. So far, I have implemented a force-directed graph that is very close to many of the examples and tutorials out there.</p>
  
  <p><strong>Direct Concern</strong></p>
  
  <p>Like many of the examples, I have a JSON structure like this:</p>
  
  <pre><code>{"nodes": ["node1", "node2",  ... ],
   "links": [{source: 0, target: 1, "field1": 5, ...}, ... ]}
  </code></pre>
  
  <p>However, I think that it would be easier to construct my data sources like this:</p>
  
  <pre><code>{"links": [
      {source: "node1", target: "node2", "field1": 5, ...},
      {source: "node2", target: "node4", "field1": 1, ...},
      {source: "node3", target: "node4", "field1": 8, ...}
  ]}
  </code></pre>
  
  <p>Instead of explicitly defining the nodes in my graph, they are implicitly defined in the link structures.</p>
  
  <p><strong>The Reason</strong></p>
  
  <p>I wanted to list the eventual goal of the project in case someone had some specific example code or idiomatic way of doing this of which I am unaware.</p>
  
  <p>The goal for the project would eventually be a graph that is updating in real-time. The back-end is being developed and is subject to some change and revision.</p>
  
  <p>At the moment, I'm imagining pulling down an update JSON feed every X seconds and updating the structure of that graph with the new information. The pulled feed would only contain the updated structures of the graph, so the script would need to maintain the all of the already pulled nodes and links and add any new ones, if necessary.</p>
  
  <p><strong>Thanks!</strong></p>
  
  <p>I apologize if this has been asked before. I did some searching and didn't find anything. Feel free to insult and berate me if I missed it.</p>