         sums[column] = sums[column] || 0
         sums[column] += n.value()
       _.max _.values(sums)
+
+    number_of_columns: =>
+      @__column_number ?= d3.max(@node_list, (n) -> n.get 'column') + 1

        node = new D3.sankey.Node(_.extend n, view: this)
        @node_map[n.id] = node
        node
      @link_list = _.map D3.sankey.charts[k].data.links, (l) =>
        new D3.sankey.Link(_.extend l, view: this)
      @initialize_defaults()

  # cool but not flexible enough
  Node: class extends Backbone.Model
    width: 20
    vertical_margin: 10

    initialize: =>
      @right_links = []
      @left_links = []
      @view = @get 'view'

    # Returns an appropriate spacing given the number of columns. Some values
    # are manually set to squeeze every single pixel
    #
    horizontal_spacing: =>
      return @__horizontal_spacing if @__horizontal_spacing?
      cols = @view.number_of_columns()
      @__horizontal_spacing = switch cols
        when 3 then 170
        when 4 then 120
        else @view.width / cols
      @__horizontal_spacing

    # vertical position of the top left corner of the node. Adds some margin
    # between nodes
