<div style="<%= style %>" class="burndown_chart" id="burndown_<%= sprint.id %>"><div class="loading">Generating chart...</div></div>
<% if mode == :full %>
<div class="burndown_information" style="border: 1px solid #ccc; padding: 4px; margin-top: 16px; width: 600px;">
<%
  zone = User.current.time_zone || Time.zone
  t1 = RbIssueHistory.burndown_timezone.local(2012, 1, 1, 0, 0, 0).in_time_zone(zone) #make a day start, in burndown day zone, then convert to user timezone
  t2 = t1 + 1.day - 1.second
%>
Sprints days are captured using server time zone: <%= RbIssueHistory.burndown_timezone %>.<br>
A Sprint day in your time zone <%= zone %> is from <%= t1.strftime("%T") %> to <%= t2.strftime("%T") %><br>
</div>
<% end %>
<script type="text/javascript" language="javascript">
  <%-
      burndown = sprint.burndown
      series = burndown.series.sort{|a, b| l("label_#{a}") <=> l("label_#{b}") }
      dates = sprint.days

      tz = RbIssueHistory.burndown_timezone
      ticks = dates.collect{|d| tz.local(d.year, d.mon, d.mday) }.collect{|t| t.strftime('%a')[0, 1].downcase + ' ' + t.strftime(::I18n.t('date.formats.short')) }
      ticks = (0..dates.size * 2).collect{|i| [i, (i % 2 == 0 ? ' ' : ticks[(i-1)/2] + ' ')] }

      chart = {
        :mode => mode,
        :series => series.collect{|s| burndown.data[s.intern].enum_for(:each_with_index).collect{|d,i| [i*2, d]}},
        :position => Hash[*(0.upto(series.size - 1).collect{|i| [series[i], i]}.flatten)],
        :options => {
          :series => series.collect{|s|
            axis = s.to_s.split('_')[0]
            {
              :label => l("label_#{s}"),
              :yaxis => {'hours' => 'yaxis', 'points' => 'y2axis', 'ideal' => 'y3axis'}[axis],
              :showHighlight => (axis != 'ideal'),
              :markerOptions => {:style => {'hours' => 'filledSquare', 'points' => 'filledCircle', 'ideal' => 'filledDiamond'}[axis]}
            }
          },
          :legend => {:show => (mode == :full), :location => 'sw'},
          :grid => {:shadow => false},
          :seriesDefaults => {:showMarker => (mode == :full), :shadow => false},
          :axesDefaults =>  {:pad => 1.05, :showTick => (mode == :full)},
          :axes => {
              :xaxis => {
                :min => 0,
                :max => dates.size * 2,
                :ticks => ticks,
                :tickOptions => {:angle => -90, :fontSize => '8pt'}
              },
              :yaxis => {:label => l("label_hours"), :min => 0, :autoscale => true, :tickOptions => {:formatString => '%d'}},
              :y2axis => {:label => l("label_points"), :min => 0, :autoscale => true, :tickOptions => {:formatString => '%d'}},
              :y3axis => {:min => 0, :autoscale => true, :showTicks => false, :showTickMarks => false, :tickOptions => {:showGridline => false, :show => false}}
          },
          :highlighter => { :bringSeriesToFront => true, :tooltipAxes => 'y', :formatString => '%s', :show => true }
        }
      }
  %>
  RB.burndown.charts[<%= sprint.id %>] = <%= chart.to_json.html_safe %>;
  // RB.burndown.charts[<%= sprint.id %>].options.axesDefaults.tickRenderer = RB.$.jqplot.CanvasAxisTickRenderer;
  RB.burndown.charts[<%= sprint.id %>].options.axes.xaxis.tickRenderer = RB.$.jqplot.CanvasAxisTickRenderer;
  RB.burndown.charts[<%= sprint.id %>].options.axes.yaxis.labelRenderer = RB.$.jqplot.CanvasAxisLabelRenderer;
  RB.burndown.charts[<%= sprint.id %>].options.axes.y2axis.labelRenderer = RB.$.jqplot.CanvasAxisLabelRenderer;
  RB.burndown.initialize();
</script>
