     svg.attr 'width', w
     svg.attr 'height', h
 
+  $(window).on 'mousedown', (e) ->
+    sx = e.clientX
+    sy = e.clientY
+
+  $(window).on 'mouseup', (e) ->
+    sx = null
+    sy = null
+
+  $(window).on 'mousemove', (e) ->
+    if sx? and sy?
+      dx = e.clientX - sx
+      dy = e.clientY - sy
+      sx = e.clientX
+      sy = e.clientY
+      cx += dx
+      cy += dy
+
   head = new Node()
-  nodes = [head]
-
-  child = new Node()
-  child.setParent head
-  nodes.push child
-
   head.x = w / 2
   head.y = h / 2
 
-  child.x = head.x - 1
-  child.y = head.y - 1
+  link = null
+  node = null
 
   circles = null
   rects = null
   texts = null
 
-  # link = svg.selectAll('.link')
-  #   .data(links)
-  #   .enter().append('line')
+  new Node().setParent head
+  new Node().setParent head
+  new Node().setParent head
+  new Node().setParent head
+  new Node().setParent head
+  new Node().setParent head
+  new Node().setParent head
 
-  node = svg.selectAll('.node')
-    .data(nodes)
-    .enter().append('circle').classed('node', true)
+  refresh = ->
+    svg.selectAll('.link')
+      .data(links, (d) -> d.id)
+      .enter()
+        .insert('line', ':first-child')
+        .classed('link', true)
 
-  console.log node
+    svg.selectAll('.node')
+      .data(nodes, (d) -> d.id)
+      .enter()
+        .append('circle')
+        .classed('node', true)
+        .on('dblclick', (nodeClicked) ->
+          new Node().setParent nodeClicked
+          refresh()
+        )
+  refresh()
 
   update = ->
-    MAX = 100
+    MAX = 200
+    PUSH = 5
 
     for n1, i in nodes
       sum = V 0, 0

$(document).ready ->

  class Node

    @ids = 0

    constructor: () ->
      @id = Node.ids++
      @x = 0
      @y = 0
      @parent = null
      @text = ''
      @children = []

    setParent: (parent) ->
      if @parent
        @parent.remove @
      @parent = parent
      @

    remove: (child) ->
      @children.splice @children.indexOf child, 1
      child

  randomColor = ->
    '#'+Math.floor(Math.random()*16777215).toString(16);

    render()
    requestAnimationFrame recursiveAnim
  )()


# rects = nodes
