Gantt: make the png looks more like html.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4525 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2010-12-17 14:53:30 +00:00
parent 88a802b25e
commit 74a94ed4ad
1 changed files with 47 additions and 58 deletions

View File

@ -307,16 +307,9 @@ module Redmine
@lines << output @lines << output
output output
when :image when :image
options[:image].stroke('transparent') coords = coordinates(project.start_date, project.due_date, project.completed_percent(:include_subprojects => true), options[:zoom])
i_left = options[:subject_width] + ((project.due_date - self.date_from)*options[:zoom]).floor label = "#{h project } #{h project.completed_percent(:include_subprojects => true).to_i.to_s}%"
image_task(options, coords, :label => label, :markers => true, :height => 3)
# Make sure negative i_left doesn't overflow the subject
if i_left > options[:subject_width]
options[:image].fill('blue')
options[:image].rectangle(i_left, options[:top], i_left + 6, options[:top] - 6)
options[:image].fill('black')
options[:image].text(i_left + 11, options[:top] + 1, project.name)
end
when :pdf when :pdf
coords = coordinates(project.start_date, project.due_date, project.completed_percent(:include_subprojects => true), options[:zoom]) coords = coordinates(project.start_date, project.due_date, project.completed_percent(:include_subprojects => true), options[:zoom])
label = "#{h project } #{h project.completed_percent(:include_subprojects => true).to_i.to_s}%" label = "#{h project } #{h project.completed_percent(:include_subprojects => true).to_i.to_s}%"
@ -379,16 +372,10 @@ module Redmine
@lines << output @lines << output
output output
when :image when :image
options[:image].stroke('transparent') coords = coordinates(version.fixed_issues.minimum('start_date'), version.due_date, version.completed_pourcent, options[:zoom])
i_left = options[:subject_width] + ((version.start_date - @date_from)*options[:zoom]).floor label = "#{h version } #{h version.completed_pourcent.to_i.to_s}%"
label = h("#{version.project} -") + label unless @project && @project == version.project
# Make sure negative i_left doesn't overflow the subject image_task(options, coords, :label => label, :markers => true, :height => 3)
if i_left > options[:subject_width]
options[:image].fill('green')
options[:image].rectangle(i_left, options[:top], i_left + 6, options[:top] - 6)
options[:image].fill('black')
options[:image].text(i_left + 11, options[:top] + 1, version.name)
end
when :pdf when :pdf
coords = coordinates(version.fixed_issues.minimum('start_date'), version.due_date, version.completed_pourcent, options[:zoom]) coords = coordinates(version.fixed_issues.minimum('start_date'), version.due_date, version.completed_pourcent, options[:zoom])
label = "#{h version } #{h version.completed_pourcent.to_i.to_s}%" label = "#{h version } #{h version.completed_pourcent.to_i.to_s}%"
@ -468,43 +455,8 @@ module Redmine
output output
when :image when :image
# Handle nil start_dates, rare but can happen. coords = coordinates(issue.start_date, issue.due_before, issue.done_ratio, options[:zoom])
i_start_date = if issue.start_date && issue.start_date >= @date_from image_task(options, coords, :label => "#{ issue.status.name } #{ issue.done_ratio }%")
issue.start_date
else
@date_from
end
i_end_date = (issue.due_before <= date_to ? issue.due_before : date_to )
i_done_date = i_start_date + ((issue.due_before - i_start_date+1)*issue.done_ratio/100).floor
i_done_date = (i_done_date <= @date_from ? @date_from : i_done_date )
i_done_date = (i_done_date >= date_to ? date_to : i_done_date )
i_late_date = [i_end_date, Date.today].min if i_start_date < Date.today
i_left = options[:subject_width] + ((i_start_date - @date_from)*options[:zoom]).floor
i_width = ((i_end_date - i_start_date + 1)*options[:zoom]).floor # total width of the issue
d_width = ((i_done_date - i_start_date)*options[:zoom]).floor # done width
l_width = i_late_date ? ((i_late_date - i_start_date+1)*options[:zoom]).floor : 0 # delay width
# Make sure that negative i_left and i_width don't
# overflow the subject
if i_width > 0
options[:image].fill('grey')
options[:image].rectangle(i_left, options[:top], i_left + i_width, options[:top] - 6)
options[:image].fill('red')
options[:image].rectangle(i_left, options[:top], i_left + l_width, options[:top] - 6) if l_width > 0
options[:image].fill('blue')
options[:image].rectangle(i_left, options[:top], i_left + d_width, options[:top] - 6) if d_width > 0
end
# Show the status and % done next to the subject if it overflows
options[:image].fill('black')
if i_width > 0
options[:image].text(i_left + i_width + 5,options[:top] + 1, "#{issue.status.name} #{issue.done_ratio}%")
else
options[:image].text(options[:subject_width] + 5,options[:top] + 1, "#{issue.status.name} #{issue.done_ratio}%")
end
when :pdf when :pdf
coords = coordinates(issue.start_date, issue.due_before, issue.done_ratio, options[:zoom]) coords = coordinates(issue.start_date, issue.due_before, issue.done_ratio, options[:zoom])
@ -537,6 +489,7 @@ module Redmine
gc = Magick::Draw.new gc = Magick::Draw.new
# Subjects # Subjects
gc.stroke('transparent')
subjects(:image => gc, :top => (headers_heigth + 20), :indent => 4, :format => :image) subjects(:image => gc, :top => (headers_heigth + 20), :indent => 4, :format => :image)
# Months headers # Months headers
@ -616,6 +569,7 @@ module Redmine
# content # content
top = headers_heigth + 20 top = headers_heigth + 20
gc.stroke('transparent')
lines(:image => gc, :top => top, :zoom => zoom, :subject_width => subject_width, :format => :image) lines(:image => gc, :top => top, :zoom => zoom, :subject_width => subject_width, :format => :image)
# today red line # today red line
@ -909,6 +863,41 @@ module Redmine
params[:pdf].Cell(30, 2, options[:label]) params[:pdf].Cell(30, 2, options[:label])
end end
end end
def image_task(params, coords, options={})
height = options[:height] || 6
# Renders the task bar, with progress and late
if coords[:bar_start] && coords[:bar_end]
params[:image].fill('grey')
params[:image].rectangle(params[:subject_width] + coords[:bar_start], params[:top], params[:subject_width] + coords[:bar_end], params[:top] - height)
if coords[:bar_late_end]
params[:image].fill('red')
params[:image].rectangle(params[:subject_width] + coords[:bar_start], params[:top], params[:subject_width] + coords[:bar_late_end], params[:top] - height)
end
if coords[:bar_progress_end]
params[:image].fill('green')
params[:image].rectangle(params[:subject_width] + coords[:bar_start], params[:top], params[:subject_width] + coords[:bar_progress_end], params[:top] - height)
end
end
# Renders the markers
if options[:markers]
if coords[:start]
params[:image].fill('blue')
params[:image].rectangle(params[:subject_width] + coords[:start], params[:top] + 1, params[:subject_width] + coords[:start] + 4, params[:top] - 4)
end
if coords[:end]
params[:image].fill('blue')
params[:image].rectangle(params[:subject_width] + coords[:end], params[:top] + 1, params[:subject_width] + coords[:end] + 4, params[:top] - 4)
end
end
# Renders the label on the right
if options[:label]
params[:image].fill('black')
params[:image].text(params[:subject_width] + (coords[:bar_end] || 0) + 5,params[:top] + 1, options[:label])
end
end
end end
end end
end end