       @right = @module.nodes.get @get('right')
       if @get('gquery')
         @gquery = new Gquery({key: @get('gquery')})
+      # let the nodes know about me
       @left.right_links.push this
       @right.left_links.push this
 
+    # returns the absolute y coordinate of the left anchor point
+    #
     left_y:  =>
       offset = 0
       for link in @left.right_links
         # push down the first link
-        offset += link.height() / 2 if offset == 0
+        offset += link.value() / 2 if offset == 0
         break if link == this
-        offset += link.height()
+        offset += link.value()
       @left.y_offset() + offset
-    
+
+    # see above
+    #
     right_y:  =>
       offset = 0
       for link in @right.left_links
         # push down the first link
-        offset += link.height() / 2 if offset == 0
+        offset += link.value() / 2 if offset == 0
         break if link == this
-        offset += link.height()
+        offset += link.value()
       @right.y_offset() + offset
-    
+
     left_x:  => @left.x_center() + @module.Node.width / 2
-    
+
     right_x: => @right.x_center() - @module.Node.width / 2
 
+    # Use 4 points and let D3 interpolate a smooth curve
+    #
     path_points: =>
       [
           x: @left_x()

  Node: class extends Backbone.Model
    @width: 170
    @horizontal_spacing: 400
    
    y_offset: =>
      offset = 0
      margin = 35
      for n in @siblings()
        break if n == this
        offset += n.height() + margin
      offset

    x_offset: => @get('column') * D3.sankey.Node.horizontal_spacing + 20
    x_center: => @x_offset() + D3.sankey.Node.width / 2
    y_center: => @y_offset() + @value() / 2

    value: =>
      _.max([
        _.inject(@left_links, ((memo, i) -> memo + i.height()), 0),
        _.inject(@right_links,((memo, i) -> memo + i.height()), 0)
      ])

    initialize: =>
      @module = D3.sankey
      if @get('gquery')
        @gquery = new Gquery({key: @get('gquery')})
      @right_links = []
      @left_links = []

    height: => @value()

    siblings: =>
      items = _.groupBy(@module.nodes.models, (node) -> node.get('column'))
      items[@get 'column']


  Link: class extends Backbone.Model

        attr("x", (d) => @x d.x_offset()).
        attr("y", (d) => @y(d.y_center() + 5)).
        attr("dx", 5).
        text((d) -> d.label()).
        style("color", "black")

    refresh: =>
      @nodes.data(@module.nodes.models, (d) -> d.get('id')).
        transition().duration(500).
        attr("height", (d) => @y d.value()).
        attr("y", (d) => @y d.y_offset())

      @labels.data(@module.nodes.models, (d) -> d.get('id')).
        transition().duration(500).
        attr("y", (d) => @y(d.y_center() + 5))

      @links.data(@module.links.models, (d) -> d.cid).
        transition().duration(500).
