 
     ]
 
-  # Helper classes
-  #
+  # In this chart most positioning is calculated by us. The D3 sankey plugin is
+  # cool but not flexible enough
   Node: class extends Backbone.Model
     @width: 25
     @horizontal_spacing: 280
-
     vertical_margin: 8
 
     initialize: =>
-      # shortcut to access the collection objects
-      @module = D3.sankey
+      @view = D3.sankey.view
       @right_links = []
       @left_links = []
 
-    # vertical position of the node. Adds some margin between nodes
-    #
+    # vertical position of the top left corner of the node. Adds some margin
+    # between nodes
     y_offset: =>
       offset = 0
-      margin = @module.y.invert(@vertical_margin)
+      # since the value's going to be scaled, let's invert it to have always the
+      # same margin in absolute (=pixel) values
+      margin = @view.y.invert(@vertical_margin)
       for n in @siblings()
         break if n == this
         offset += n.value() + margin
       offset
 
     x_offset: => @get('column') * D3.sankey.Node.horizontal_spacing
+
+    # center point of the node. We use it as link anchor point
     x_center: => @x_offset() + D3.sankey.Node.width / 2
-    y_center: => @y_offset() + @value() / 2
 
     # The height of the node is the sum of the height of its link. Since links
     # are both inbound and outbound, let's use the max size. Ideally the values
     # should match
-    #
     value: =>
-      _.max([
+      _.max [
         _.inject(@left_links, ((memo, i) -> memo + i.value()), 0),
         _.inject(@right_links,((memo, i) -> memo + i.value()), 0)
-      ])
+      ]
 
     # returns an array of the other nodes that belong to the same column. This
     # is used by the +y_offset+ method to calculate the right node position
-    #
     siblings: =>
-      items = _.groupBy(@module.nodes.models, (node) -> node.get('column'))
+      items = _.groupBy(@view.node_list.models, (node) -> node.get('column'))
       items[@get 'column']
 
     label: => @get('label') || @get('id')
 
   Link: class extends Backbone.Model
     initialize: =>
-      @module = D3.sankey
-      @series = @module.series
-      @left = @module.nodes.get @get('left')
-      @right = @module.nodes.get @get('right')
+      @view = D3.sankey.view
+      @series = @view.series
+      @left = @view.node_list.get @get('left')
+      @right = @view.node_list.get @get('right')
       if @get('gquery')
         @gquery = new ChartSerie
           gquery_key: @get('gquery')

      return nodes

    # formats the value shown in the link labels
    #
    format_value: (x) -> "#{x.toFixed(2)} PJ"

    # callbacks

            offset += link.value()
      @right.y_offset() + offset

    left_x:  => @left.x_center()  + D3.sankey.Node.width / 2
    right_x: => @right.x_center() - D3.sankey.Node.width / 2

    # Use 4 points and let D3 interpolate a smooth curve
    #
