Skip to content

Commit

Permalink
Some-how I missed the last set of changes !?!?!
Browse files Browse the repository at this point in the history
  • Loading branch information
ciaranj committed Mar 9, 2009
1 parent f16d729 commit c2e6a6a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 55 deletions.
38 changes: 20 additions & 18 deletions app/models/burndown_chart.rb
@@ -1,6 +1,13 @@
class BurndownChart
attr_accessor :dates, :version, :start_date
attr_accessor :dates, :version, :start_date, :sprint_data, :ideal_data

class DateHoursPair
attr_accessor :date, :hours
def initialize(date, hours)
self.date= date
self.hours= hours
end
end
class CachedIssue
attr_accessor :issue, :ratio_details_map
def initialize(issue)
Expand All @@ -16,50 +23,45 @@ def initialize(version)
self.start_date = version.created_on.to_date
end_date = version.effective_date.to_date
@dates = (start_date..end_date).inject([]) { |accum, date| accum << date }
generate_sprint_data
end

def data
[ideal_data, sprint_data]
end

def sprint_data
def generate_sprint_data
cached_all_issues= all_issues.collect do |issue|
CachedIssue.new( issue )
end

@sprint_data ||= @dates.map do |date|
@sprint_data ||= @dates.inject([]) do |data_map, date|
issues = []
cached_all_issues.each do |cached_issue|
break if cached_issue.issue.created_on.to_date > date
issues<< cached_issue if cached_issue.issue.created_on.to_date <= date
end

issues.inject(0) do |total_hours_left, cached_issue|
total_hours= issues.inject(0) do |total_hours_left, cached_issue|
details_today_or_earlier = []
cached_issue.ratio_details_map.each do |a|
break if a.journal.created_on.to_date > date
details_today_or_earlier<< a if a.journal.created_on.to_date <= date
end

last_done_ratio_change = details_today_or_earlier.last

ratio = if last_done_ratio_change
last_done_ratio_change.value
elsif cached_issue.ratio_details_map.size > 0
0
else
cached_issue.issue.done_ratio.to_i
end

total_hours_left += (cached_issue.issue.estimated_hours.to_i * (100-ratio.to_i)/100)
end
data_map << DateHoursPair.new(date, total_hours)
end

@ideal_data= [@sprint_data.first, DateHoursPair.new(@sprint_data.last.date, 0)]
end

def ideal_data
[sprint_data.first, 0]
end


def all_issues
issues= version.fixed_issues.find(:all, :include => [{:journals => :details}, :relations_from, :relations_to])
issues.sort! {|a,b| a.created_on <=> b.created_on }
Expand Down
9 changes: 6 additions & 3 deletions app/views/burndowns/show.html.erb
@@ -1,7 +1,10 @@
<h2><%= @version.name %> <%= l(:burndown) %></h2>
<p><%= render_burndown @chart, :width=>750, :height=>400 %></p>


<p><div id="placeholder" style="width:750px;height:400px"></div>
<%= chart("placeholder", { "Est. Remaining Time"=> {:collection => @chart.sprint_data,:x=>:date, :y=>:hours},
"Ideal Burndown"=> {:collection => @chart.ideal_data,:x=>:date, :y=>:hours}
},
{"xaxis"=>{:mode=>:time}, :lines=>{:show=>true}, :points=>{:show=>true}, :grid=>{:markings=> "weekendAreas"}} ) %>
</p>
<% content_for :sidebar do -%>
<h3><%= l(:label_version_plural) %></h3>
<ul id="sprint_burndown_list">
Expand Down
21 changes: 0 additions & 21 deletions assets/javascripts/burndowns.js
@@ -1,4 +1,3 @@
//TODO: STick these methods into a prototype/namespace to avoid conflicts.


// Figure out FLOT markings to represent weekends in a graph
Expand All @@ -21,23 +20,3 @@ function weekendAreas(axes) {

return markings;
}

// Plot a FLOT chart passing a particular div element to base the canvas on
// and the real + ideal data to render.
function plotChart(elementId, real_data, ideal_data) {
var config= { xaxis: { mode: "time" },
lines: { show: true },
points: { show: true },
grid: { markings: weekendAreas }};
plotChartWithConfig(elementId,
[{ label:"Est. Remaining Time",
data: real_data}, {
label:"Ideal Burn-down",
data: ideal_data}],
config)

};

function plotChartWithConfig(elementId, data, config) {
jQuery.plot(jQuery("#" + elementId), data, config);
}
15 changes: 2 additions & 13 deletions lib/burndown_listener.rb
@@ -1,17 +1,6 @@
class BurndownListener < Redmine::Hook::ViewListener
def view_layouts_base_html_head(context={})
stylesheet_link_tag('burndowns', :plugin => 'redmine_burndown') + "\n"+
javascript_include_tag('jquery.js', :plugin => 'redmine_burndown') + "\n"+
javascript_include_tag('jquery.flot.pack.js', :plugin => 'redmine_burndown')+ "\n"+
javascript_include_tag('burndowns.js', :plugin => 'redmine_burndown') + "\n"+
<<EOS
<script language="JavaScript" type="text/javascript">
jQuery.noConflict();
</script>
<!--[if IE]>
#{javascript_include_tag "excanvas.pack"}
<![endif]-->
EOS

flot_graphs_includes + "\n" +
javascript_include_tag('burndowns', :plugin => 'redmine_burndown') + "\n"
end
end

0 comments on commit c2e6a6a

Please sign in to comment.