title: The algorithm to draw and process the relationship coordinate between parent and child nodes as topology tree
body: <p>I have a data construction with the relationship of parent node and child node in JavaScript like this:</p>
  
  <pre><code>var data = {
      'name': 'A1',
      'children': [
          {
              'name': 'B1',
              'children': [
                  {'name': 'C1'},
                  {'name': 'C2'},
                  {'name': 'C3'},
                  {'name': 'C4'},
                  {'name': 'C5'}
              ]
          },
          {
              'name': 'B2',
              'children': [
                  {
                      'name': 'C6',
                      'children': [
                          {'name': 'D1'}
                      ]
                  },
                  {'name': 'C7'},
                  {'name': 'C8'}
              ]
          }
      ]
  };
  </code></pre>
  
  <p>What I need to do is to calculate the coordinate of each child node with topology. The final result will be probably like this - The topology tree:</p>
  
  <pre><code>┌─────────────────────────────────
  │                ┌C1[2,0]
  │                │C2[2,1]
  │       ┌B1[1,2]─┼C3[2,2]   
  │       │        │C4[2,3]
  │A1[0,4]┤        └C5[2,4]
  │       │        ┌C6[2,5]─D1[3,5]
  │       └B2[1,6]─┼C7[2,6]
  │                └C8[2,7]
  </code></pre>
  
  <p>Of course, the algorithm can be compatible with various situation, like if the final node is with too much child nodes, the Y coordinate of each parent will plus a offset.</p>
  
  <p>This is the demonstration of topology tree: <a href="http://mbostock.github.com/d3/talk/20111018/tree.html" rel="nofollow">http://mbostock.github.com/d3/talk/20111018/tree.html</a></p>
  
  <p>But yet, I just want to the core of the JavaScript code to calculate the coordinate like above. Any idea? Or maybe you can use other language to achieve it.</p>
  
  <p>Many thanks!</p>