<div style="<%= style %>" class="burndown_chart" id="burndown_<%= release.id %>"><div class="loading">Generating chart...</div></div>

<style type="text/css" media="screen">
  .jqplot-axis {
  font-size: 0.85em;
  }
  .jqplot-title {
  font-size: 1.1em;
  }
  .jqplot-y6axis-tick {
  padding-right: 0px;
  }
</style>
<script type="text/javascript" language="javascript">
  <%-
    burndown = release.burndown
    series = burndown.series
    days = release.days

    chart = {
      # Add date to each value. Except trendlines which already carry date info.
      :series => [:closed_points, :backlog_points,:added_points,:trend_closed,:trend_scope,:planned].collect{|s|
		     burndown[s].each_with_index.collect{|d,i|
		       d.is_a?(Array) ? d : [days[i],d]
		     }},
      :mode => 'full',
      :options => {
        :stackSeries => true,
        :seriesDefaults => {
          # renderer set during javascript initialization. See below
          :rendererOptions => {
            :fillToZero => true,
            :useNegativeColors => false
          }
        },
        :axes => {
          :xaxis => {
            # renderer set during javascript initilization. See below
          },
          :yaxis => {
            :padMin => 0,
          },
        },
        :legend => { :show => true, :location => 'ne'},
        :series => [
          { :label => "Closed" },
          { :label => "Backlog" },
          { :label => "Backlog (added)" },
          { :disableStack => true,
            :label => "Trend closed"},
          { :disableStack => true,
            :label => "Trend scope"},
          { :disableStack => true,
            :label => "Planned velocity",
            :linePattern => "dotted"}
        ],
        :noDataIndicator => { :show => true, :indicator => 'No data' },
        :seriesColors => [ "#579575", "#c5b47f","#EAA228", "#4bb2c5", "#839557", "#958c12"]
      }
    }
  %>
RB.$(function() { // render when dom is ready
  RB.burndown.charts[<%= release.id %>] = <%= chart.to_json.html_safe %>;
  RB.burndown.charts[<%= release.id %>].options.seriesDefaults.renderer = RB.$.jqplot.BarRenderer;
  RB.burndown.charts[<%= release.id %>].options.axes.xaxis.renderer = RB.$.jqplot.DateAxisRenderer;
  RB.burndown.charts[<%= release.id %>].options.series[3].renderer = RB.$.jqplot.LineRenderer;
  RB.burndown.charts[<%= release.id %>].options.series[4].renderer = RB.$.jqplot.LineRenderer;
  RB.burndown.charts[<%= release.id %>].options.series[5].renderer = RB.$.jqplot.LineRenderer;
  var graph_width = $("#burndown_<%= release.id %>").innerWidth();
  //FIXME calculate bar width according to longest sprint vs. total period
  // covered by the graph including trend lines.
  RB.burndown.charts[<%= release.id %>].options.seriesDefaults.rendererOptions.barWidth = Math.round(graph_width / 60);
  RB.burndown.initialize();
});
</script>
