 
   NodeGroup: class extends Backbone.Model
       initialize: -> @nodes = []
-
-      total_value: =>
-        total = 0
-        total += n.val() for n in @nodes
-        total
+      total_value: => d3.sum @nodes, (n) -> n.val()
 
   View: class extends D3ChartView
     el: "body"

        carriers.push
          label: s.get('label')
          color: s.get('color')
      sectors  = _.uniq sectors
      carriers = _.uniq(carriers, false, (c) -> c.label)

      for sector in sectors
        @sector_list.add
          key: sector
      for carrier in carriers
        @carrier_list.add
          key: carrier.label
          label: carrier.label # used by the legend
          color: carrier.color

      for s in @series
        sector  = s.get('group_translated')

      for sector in @sector_list.pluck('key')
        offsets[sector] = 0

      @svg.selectAll(".carrier")
        .data(@node_list.models, (d) -> d.key())
        .transition().duration(500)
        .attr("width", (d) => @x d.sector.total_value() )
        .attr("height", (d) =>
          x = d.val() / d.sector.total_value() * @series_height
          if _.isNaN(x) then 0 else x
        )
        .attr("y", (d) =>
          old = offsets[d.get 'sector']
          x = d.val() / d.sector.total_value() * @series_height
          if _.isNaN(x) then x = 0
          offsets[d.get 'sector'] += x
          old
        )
        .attr("data-tooltip", (d) -> d.tooltip_text())

class D3.mekko.GroupCollection extends Backbone.Collection
  model: D3.mekko.NodeGroup

class D3.mekko.NodeList extends Backbone.Collection
  model: D3.mekko.Node
  grand_total: => d3.sum @models, (n) -> n.val()
