comparison lib/redmine/helpers/.svn/text-base/gantt.rb.svn-base @ 119:8661b858af72

* Update to Redmine trunk rev 4705
author Chris Cannam
date Thu, 13 Jan 2011 14:12:06 +0000
parents 94944d00e43c
children 051f544170fe
comparison
equal deleted inserted replaced
39:150ceac17a8d 119:8661b858af72
32 def self.right_pane_width 32 def self.right_pane_width
33 TotalWidth - LeftPaneWidth 33 TotalWidth - LeftPaneWidth
34 end 34 end
35 end 35 end
36 36
37 attr_reader :year_from, :month_from, :date_from, :date_to, :zoom, :months 37 attr_reader :year_from, :month_from, :date_from, :date_to, :zoom, :months, :truncated, :max_rows
38 attr_accessor :query 38 attr_accessor :query
39 attr_accessor :project 39 attr_accessor :project
40 attr_accessor :view 40 attr_accessor :view
41 41
42 def initialize(options={}) 42 def initialize(options={})
65 User.current.preference.save 65 User.current.preference.save
66 end 66 end
67 67
68 @date_from = Date.civil(@year_from, @month_from, 1) 68 @date_from = Date.civil(@year_from, @month_from, 1)
69 @date_to = (@date_from >> @months) - 1 69 @date_to = (@date_from >> @months) - 1
70
71 @subjects = ''
72 @lines = ''
73 @number_of_rows = nil
74
75 @issue_ancestors = []
76
77 @truncated = false
78 if options.has_key?(:max_rows)
79 @max_rows = options[:max_rows]
80 else
81 @max_rows = Setting.gantt_items_limit.blank? ? nil : Setting.gantt_items_limit.to_i
82 end
70 end 83 end
71 84
72 def common_params 85 def common_params
73 { :controller => 'gantts', :action => 'show', :project_id => @project } 86 { :controller => 'gantts', :action => 'show', :project_id => @project }
74 end 87 end
86 end 99 end
87 100
88 ### Extracted from the HTML view/helpers 101 ### Extracted from the HTML view/helpers
89 # Returns the number of rows that will be rendered on the Gantt chart 102 # Returns the number of rows that will be rendered on the Gantt chart
90 def number_of_rows 103 def number_of_rows
91 if @project 104 return @number_of_rows if @number_of_rows
92 return number_of_rows_on_project(@project) 105
106 rows = if @project
107 number_of_rows_on_project(@project)
93 else 108 else
94 Project.roots.inject(0) do |total, project| 109 Project.roots.visible.has_module('issue_tracking').inject(0) do |total, project|
95 total += number_of_rows_on_project(project) 110 total += number_of_rows_on_project(project)
96 end 111 end
97 end 112 end
113
114 rows > @max_rows ? @max_rows : rows
98 end 115 end
99 116
100 # Returns the number of rows that will be used to list a project on 117 # Returns the number of rows that will be used to list a project on
101 # the Gantt chart. This will recurse for each subproject. 118 # the Gantt chart. This will recurse for each subproject.
102 def number_of_rows_on_project(project) 119 def number_of_rows_on_project(project)
117 project.versions.each do |version| 134 project.versions.each do |version|
118 count += version.fixed_issues.for_gantt.with_query(@query).count 135 count += version.fixed_issues.for_gantt.with_query(@query).count
119 end 136 end
120 137
121 # Subprojects 138 # Subprojects
122 project.children.each do |subproject| 139 project.children.visible.has_module('issue_tracking').each do |subproject|
123 count += number_of_rows_on_project(subproject) 140 count += number_of_rows_on_project(subproject)
124 end 141 end
125 142
126 count 143 count
127 end 144 end
128 145
129 # Renders the subjects of the Gantt chart, the left side. 146 # Renders the subjects of the Gantt chart, the left side.
130 def subjects(options={}) 147 def subjects(options={})
131 options = {:indent => 4, :render => :subject, :format => :html}.merge(options) 148 render(options.merge(:only => :subjects)) unless @subjects_rendered
132 149 @subjects
133 output = ''
134 if @project
135 output << render_project(@project, options)
136 else
137 Project.roots.each do |project|
138 output << render_project(project, options)
139 end
140 end
141
142 output
143 end 150 end
144 151
145 # Renders the lines of the Gantt chart, the right side 152 # Renders the lines of the Gantt chart, the right side
146 def lines(options={}) 153 def lines(options={})
147 options = {:indent => 4, :render => :line, :format => :html}.merge(options) 154 render(options.merge(:only => :lines)) unless @lines_rendered
148 output = '' 155 @lines
149 156 end
157
158 def render(options={})
159 options = {:indent => 4, :render => :subject, :format => :html}.merge(options)
160
161 @subjects = '' unless options[:only] == :lines
162 @lines = '' unless options[:only] == :subjects
163 @number_of_rows = 0
164
150 if @project 165 if @project
151 output << render_project(@project, options) 166 render_project(@project, options)
152 else 167 else
153 Project.roots.each do |project| 168 Project.roots.visible.has_module('issue_tracking').each do |project|
154 output << render_project(project, options) 169 render_project(project, options)
155 end 170 break if abort?
156 end 171 end
157 172 end
158 output 173
174 @subjects_rendered = true unless options[:only] == :lines
175 @lines_rendered = true unless options[:only] == :subjects
176
177 render_end(options)
159 end 178 end
160 179
161 def render_project(project, options={}) 180 def render_project(project, options={})
162 options[:top] = 0 unless options.key? :top 181 options[:top] = 0 unless options.key? :top
163 options[:indent_increment] = 20 unless options.key? :indent_increment 182 options[:indent_increment] = 20 unless options.key? :indent_increment
164 options[:top_increment] = 20 unless options.key? :top_increment 183 options[:top_increment] = 20 unless options.key? :top_increment
165 184
166 output = '' 185 subject_for_project(project, options) unless options[:only] == :lines
167 # Project Header 186 line_for_project(project, options) unless options[:only] == :subjects
168 project_header = if options[:render] == :subject
169 subject_for_project(project, options)
170 else
171 # :line
172 line_for_project(project, options)
173 end
174 output << project_header if options[:format] == :html
175 187
176 options[:top] += options[:top_increment] 188 options[:top] += options[:top_increment]
177 options[:indent] += options[:indent_increment] 189 options[:indent] += options[:indent_increment]
190 @number_of_rows += 1
191 return if abort?
178 192
179 # Second, Issues without a version 193 # Second, Issues without a version
180 issues = project.issues.for_gantt.without_version.with_query(@query) 194 issues = project.issues.for_gantt.without_version.with_query(@query).all(:limit => current_limit)
195 sort_issues!(issues)
181 if issues 196 if issues
182 issue_rendering = render_issues(issues, options) 197 render_issues(issues, options)
183 output << issue_rendering if options[:format] == :html 198 return if abort?
184 end 199 end
185 200
186 # Third, Versions 201 # Third, Versions
187 project.versions.sort.each do |version| 202 project.versions.sort.each do |version|
188 version_rendering = render_version(version, options) 203 render_version(version, options)
189 output << version_rendering if options[:format] == :html 204 return if abort?
190 end 205 end
191 206
192 # Fourth, subprojects 207 # Fourth, subprojects
193 project.children.each do |project| 208 project.children.visible.has_module('issue_tracking').each do |project|
194 subproject_rendering = render_project(project, options) 209 render_project(project, options)
195 output << subproject_rendering if options[:format] == :html 210 return if abort?
196 end 211 end unless project.leaf?
197 212
198 # Remove indent to hit the next sibling 213 # Remove indent to hit the next sibling
199 options[:indent] -= options[:indent_increment] 214 options[:indent] -= options[:indent_increment]
200
201 output
202 end 215 end
203 216
204 def render_issues(issues, options={}) 217 def render_issues(issues, options={})
205 output = '' 218 @issue_ancestors = []
219
206 issues.each do |i| 220 issues.each do |i|
207 issue_rendering = if options[:render] == :subject 221 subject_for_issue(i, options) unless options[:only] == :lines
208 subject_for_issue(i, options) 222 line_for_issue(i, options) unless options[:only] == :subjects
209 else 223
210 # :line
211 line_for_issue(i, options)
212 end
213 output << issue_rendering if options[:format] == :html
214 options[:top] += options[:top_increment] 224 options[:top] += options[:top_increment]
215 end 225 @number_of_rows += 1
216 output 226 break if abort?
227 end
228
229 options[:indent] -= (options[:indent_increment] * @issue_ancestors.size)
217 end 230 end
218 231
219 def render_version(version, options={}) 232 def render_version(version, options={})
220 output = ''
221 # Version header 233 # Version header
222 version_rendering = if options[:render] == :subject 234 subject_for_version(version, options) unless options[:only] == :lines
223 subject_for_version(version, options) 235 line_for_version(version, options) unless options[:only] == :subjects
224 else
225 # :line
226 line_for_version(version, options)
227 end
228
229 output << version_rendering if options[:format] == :html
230 236
231 options[:top] += options[:top_increment] 237 options[:top] += options[:top_increment]
232 238 @number_of_rows += 1
239 return if abort?
240
233 # Remove the project requirement for Versions because it will 241 # Remove the project requirement for Versions because it will
234 # restrict issues to only be on the current project. This 242 # restrict issues to only be on the current project. This
235 # ends up missing issues which are assigned to shared versions. 243 # ends up missing issues which are assigned to shared versions.
236 @query.project = nil if @query.project 244 @query.project = nil if @query.project
237 245
238 issues = version.fixed_issues.for_gantt.with_query(@query) 246 issues = version.fixed_issues.for_gantt.with_query(@query).all(:limit => current_limit)
239 if issues 247 if issues
248 sort_issues!(issues)
240 # Indent issues 249 # Indent issues
241 options[:indent] += options[:indent_increment] 250 options[:indent] += options[:indent_increment]
242 output << render_issues(issues, options) 251 render_issues(issues, options)
243 options[:indent] -= options[:indent_increment] 252 options[:indent] -= options[:indent_increment]
244 end 253 end
245 254 end
246 output 255
256 def render_end(options={})
257 case options[:format]
258 when :pdf
259 options[:pdf].Line(15, options[:top], PDF::TotalWidth, options[:top])
260 end
247 end 261 end
248 262
249 def subject_for_project(project, options) 263 def subject_for_project(project, options)
250 case options[:format] 264 case options[:format]
251 when :html 265 when :html
252 output = '' 266 subject = "<span class='icon icon-projects #{project.overdue? ? 'project-overdue' : ''}'>"
253 267 subject << view.link_to_project(project)
254 output << "<div class='project-name' style='position: absolute;line-height:1.2em;height:16px;top:#{options[:top]}px;left:#{options[:indent]}px;overflow:hidden;'><small> " 268 subject << '</span>'
255 if project.is_a? Project 269 html_subject(options, subject, :css => "project-name")
256 output << "<span class='icon icon-projects #{project.overdue? ? 'project-overdue' : ''}'>"
257 output << view.link_to_project(project)
258 output << '</span>'
259 else
260 ActiveRecord::Base.logger.debug "Gantt#subject_for_project was not given a project"
261 ''
262 end
263 output << "</small></div>"
264
265 output
266 when :image 270 when :image
267 271 image_subject(options, project.name)
268 options[:image].fill('black')
269 options[:image].stroke('transparent')
270 options[:image].stroke_width(1)
271 options[:image].text(options[:indent], options[:top] + 2, project.name)
272 when :pdf 272 when :pdf
273 options[:pdf].SetY(options[:top]) 273 pdf_new_page?(options)
274 options[:pdf].SetX(15) 274 pdf_subject(options, project.name)
275
276 char_limit = PDF::MaxCharactorsForSubject - options[:indent]
277 options[:pdf].Cell(options[:subject_width]-15, 5, (" " * options[:indent]) +"#{project.name}".sub(/^(.{#{char_limit}}[^\s]*\s).*$/, '\1 (...)'), "LR")
278
279 options[:pdf].SetY(options[:top])
280 options[:pdf].SetX(options[:subject_width])
281 options[:pdf].Cell(options[:g_width], 5, "", "LR")
282 end 275 end
283 end 276 end
284 277
285 def line_for_project(project, options) 278 def line_for_project(project, options)
286 # Skip versions that don't have a start_date or due date 279 # Skip versions that don't have a start_date or due date
287 if project.is_a?(Project) && project.start_date && project.due_date 280 if project.is_a?(Project) && project.start_date && project.due_date
288 options[:zoom] ||= 1 281 options[:zoom] ||= 1
289 options[:g_width] ||= (self.date_to - self.date_from + 1) * options[:zoom] 282 options[:g_width] ||= (self.date_to - self.date_from + 1) * options[:zoom]
290 283
284 coords = coordinates(project.start_date, project.due_date, nil, options[:zoom])
285 label = h(project)
291 286
292 case options[:format] 287 case options[:format]
293 when :html 288 when :html
294 output = '' 289 html_task(options, coords, :css => "project task", :label => label, :markers => true)
295 i_left = ((project.start_date - self.date_from)*options[:zoom]).floor
296
297 start_date = project.start_date
298 start_date ||= self.date_from
299 start_left = ((start_date - self.date_from)*options[:zoom]).floor
300
301 i_end_date = ((project.due_date <= self.date_to) ? project.due_date : self.date_to )
302 i_done_date = start_date + ((project.due_date - start_date+1)* project.completed_percent(:include_subprojects => true)/100).floor
303 i_done_date = (i_done_date <= self.date_from ? self.date_from : i_done_date )
304 i_done_date = (i_done_date >= self.date_to ? self.date_to : i_done_date )
305
306 i_late_date = [i_end_date, Date.today].min if start_date < Date.today
307 i_end = ((i_end_date - self.date_from) * options[:zoom]).floor
308
309 i_width = (i_end - i_left + 1).floor - 2 # total width of the issue (- 2 for left and right borders)
310 d_width = ((i_done_date - start_date)*options[:zoom]).floor - 2 # done width
311 l_width = i_late_date ? ((i_late_date - start_date+1)*options[:zoom]).floor - 2 : 0 # delay width
312
313 # Bar graphic
314
315 # Make sure that negative i_left and i_width don't
316 # overflow the subject
317 if i_end > 0 && i_left <= options[:g_width]
318 output << "<div style='top:#{ options[:top] }px;left:#{ start_left }px;width:#{ i_width }px;' class='task project_todo'>&nbsp;</div>"
319 end
320
321 if l_width > 0 && i_left <= options[:g_width]
322 output << "<div style='top:#{ options[:top] }px;left:#{ start_left }px;width:#{ l_width }px;' class='task project_late'>&nbsp;</div>"
323 end
324 if d_width > 0 && i_left <= options[:g_width]
325 output<< "<div style='top:#{ options[:top] }px;left:#{ start_left }px;width:#{ d_width }px;' class='task project_done'>&nbsp;</div>"
326 end
327
328
329 # Starting diamond
330 if start_left <= options[:g_width] && start_left > 0
331 output << "<div style='top:#{ options[:top] }px;left:#{ start_left }px;width:15px;' class='task project-line starting'>&nbsp;</div>"
332 output << "<div style='top:#{ options[:top] }px;left:#{ start_left + 12 }px;' class='task label'>"
333 output << "</div>"
334 end
335
336 # Ending diamond
337 # Don't show items too far ahead
338 if i_end <= options[:g_width] && i_end > 0
339 output << "<div style='top:#{ options[:top] }px;left:#{ i_end }px;width:15px;' class='task project-line ending'>&nbsp;</div>"
340 end
341
342 # DIsplay the Project name and %
343 if i_end <= options[:g_width]
344 # Display the status even if it's floated off to the left
345 status_px = i_end + 12 # 12px for the diamond
346 status_px = 0 if status_px <= 0
347
348 output << "<div style='top:#{ options[:top] }px;left:#{ status_px }px;' class='task label project-name'>"
349 output << "<strong>#{h project } #{h project.completed_percent(:include_subprojects => true).to_i.to_s}%</strong>"
350 output << "</div>"
351 end
352
353 output
354 when :image 290 when :image
355 options[:image].stroke('transparent') 291 image_task(options, coords, :label => label, :markers => true, :height => 3)
356 i_left = options[:subject_width] + ((project.due_date - self.date_from)*options[:zoom]).floor
357
358 # Make sure negative i_left doesn't overflow the subject
359 if i_left > options[:subject_width]
360 options[:image].fill('blue')
361 options[:image].rectangle(i_left, options[:top], i_left + 6, options[:top] - 6)
362 options[:image].fill('black')
363 options[:image].text(i_left + 11, options[:top] + 1, project.name)
364 end
365 when :pdf 292 when :pdf
366 options[:pdf].SetY(options[:top]+1.5) 293 pdf_task(options, coords, :label => label, :markers => true, :height => 0.8)
367 i_left = ((project.due_date - @date_from)*options[:zoom])
368
369 # Make sure negative i_left doesn't overflow the subject
370 if i_left > 0
371 options[:pdf].SetX(options[:subject_width] + i_left)
372 options[:pdf].SetFillColor(50,50,200)
373 options[:pdf].Cell(2, 2, "", 0, 0, "", 1)
374
375 options[:pdf].SetY(options[:top]+1.5)
376 options[:pdf].SetX(options[:subject_width] + i_left + 3)
377 options[:pdf].Cell(30, 2, "#{project.name}")
378 end
379 end 294 end
380 else 295 else
381 ActiveRecord::Base.logger.debug "Gantt#line_for_project was not given a project with a start_date" 296 ActiveRecord::Base.logger.debug "Gantt#line_for_project was not given a project with a start_date"
382 '' 297 ''
383 end 298 end
384 end 299 end
385 300
386 def subject_for_version(version, options) 301 def subject_for_version(version, options)
387 case options[:format] 302 case options[:format]
388 when :html 303 when :html
389 output = '' 304 subject = "<span class='icon icon-package #{version.behind_schedule? ? 'version-behind-schedule' : ''} #{version.overdue? ? 'version-overdue' : ''}'>"
390 output << "<div class='version-name' style='position: absolute;line-height:1.2em;height:16px;top:#{options[:top]}px;left:#{options[:indent]}px;overflow:hidden;'><small> " 305 subject << view.link_to_version(version)
391 if version.is_a? Version 306 subject << '</span>'
392 output << "<span class='icon icon-package #{version.behind_schedule? ? 'version-behind-schedule' : ''} #{version.overdue? ? 'version-overdue' : ''}'>" 307 html_subject(options, subject, :css => "version-name")
393 output << view.link_to_version(version)
394 output << '</span>'
395 else
396 ActiveRecord::Base.logger.debug "Gantt#subject_for_version was not given a version"
397 ''
398 end
399 output << "</small></div>"
400
401 output
402 when :image 308 when :image
403 options[:image].fill('black') 309 image_subject(options, version.to_s_with_project)
404 options[:image].stroke('transparent')
405 options[:image].stroke_width(1)
406 options[:image].text(options[:indent], options[:top] + 2, version.to_s_with_project)
407 when :pdf 310 when :pdf
408 options[:pdf].SetY(options[:top]) 311 pdf_new_page?(options)
409 options[:pdf].SetX(15) 312 pdf_subject(options, version.to_s_with_project)
410
411 char_limit = PDF::MaxCharactorsForSubject - options[:indent]
412 options[:pdf].Cell(options[:subject_width]-15, 5, (" " * options[:indent]) +"#{version.to_s_with_project}".sub(/^(.{#{char_limit}}[^\s]*\s).*$/, '\1 (...)'), "LR")
413
414 options[:pdf].SetY(options[:top])
415 options[:pdf].SetX(options[:subject_width])
416 options[:pdf].Cell(options[:g_width], 5, "", "LR")
417 end 313 end
418 end 314 end
419 315
420 def line_for_version(version, options) 316 def line_for_version(version, options)
421 # Skip versions that don't have a start_date 317 # Skip versions that don't have a start_date
422 if version.is_a?(Version) && version.start_date && version.due_date 318 if version.is_a?(Version) && version.start_date && version.due_date
423 options[:zoom] ||= 1 319 options[:zoom] ||= 1
424 options[:g_width] ||= (self.date_to - self.date_from + 1) * options[:zoom] 320 options[:g_width] ||= (self.date_to - self.date_from + 1) * options[:zoom]
321
322 coords = coordinates(version.start_date, version.due_date, version.completed_pourcent, options[:zoom])
323 label = "#{h version } #{h version.completed_pourcent.to_i.to_s}%"
324 label = h("#{version.project} -") + label unless @project && @project == version.project
425 325
426 case options[:format] 326 case options[:format]
427 when :html 327 when :html
428 output = '' 328 html_task(options, coords, :css => "version task", :label => label, :markers => true)
429 i_left = ((version.start_date - self.date_from)*options[:zoom]).floor
430 # TODO: or version.fixed_issues.collect(&:start_date).min
431 start_date = version.fixed_issues.minimum('start_date') if version.fixed_issues.present?
432 start_date ||= self.date_from
433 start_left = ((start_date - self.date_from)*options[:zoom]).floor
434
435 i_end_date = ((version.due_date <= self.date_to) ? version.due_date : self.date_to )
436 i_done_date = start_date + ((version.due_date - start_date+1)* version.completed_pourcent/100).floor
437 i_done_date = (i_done_date <= self.date_from ? self.date_from : i_done_date )
438 i_done_date = (i_done_date >= self.date_to ? self.date_to : i_done_date )
439
440 i_late_date = [i_end_date, Date.today].min if start_date < Date.today
441
442 i_width = (i_left - start_left + 1).floor - 2 # total width of the issue (- 2 for left and right borders)
443 d_width = ((i_done_date - start_date)*options[:zoom]).floor - 2 # done width
444 l_width = i_late_date ? ((i_late_date - start_date+1)*options[:zoom]).floor - 2 : 0 # delay width
445
446 i_end = ((i_end_date - self.date_from) * options[:zoom]).floor # Ending pixel
447
448 # Bar graphic
449
450 # Make sure that negative i_left and i_width don't
451 # overflow the subject
452 if i_width > 0 && i_left <= options[:g_width]
453 output << "<div style='top:#{ options[:top] }px;left:#{ start_left }px;width:#{ i_width }px;' class='task milestone_todo'>&nbsp;</div>"
454 end
455 if l_width > 0 && i_left <= options[:g_width]
456 output << "<div style='top:#{ options[:top] }px;left:#{ start_left }px;width:#{ l_width }px;' class='task milestone_late'>&nbsp;</div>"
457 end
458 if d_width > 0 && i_left <= options[:g_width]
459 output<< "<div style='top:#{ options[:top] }px;left:#{ start_left }px;width:#{ d_width }px;' class='task milestone_done'>&nbsp;</div>"
460 end
461
462
463 # Starting diamond
464 if start_left <= options[:g_width] && start_left > 0
465 output << "<div style='top:#{ options[:top] }px;left:#{ start_left }px;width:15px;' class='task milestone starting'>&nbsp;</div>"
466 output << "<div style='top:#{ options[:top] }px;left:#{ start_left + 12 }px;background:#fff;' class='task'>"
467 output << "</div>"
468 end
469
470 # Ending diamond
471 # Don't show items too far ahead
472 if i_left <= options[:g_width] && i_end > 0
473 output << "<div style='top:#{ options[:top] }px;left:#{ i_end }px;width:15px;' class='task milestone ending'>&nbsp;</div>"
474 end
475
476 # Display the Version name and %
477 if i_end <= options[:g_width]
478 # Display the status even if it's floated off to the left
479 status_px = i_end + 12 # 12px for the diamond
480 status_px = 0 if status_px <= 0
481
482 output << "<div style='top:#{ options[:top] }px;left:#{ status_px }px;' class='task label version-name'>"
483 output << h("#{version.project} -") unless @project && @project == version.project
484 output << "<strong>#{h version } #{h version.completed_pourcent.to_i.to_s}%</strong>"
485 output << "</div>"
486 end
487
488 output
489 when :image 329 when :image
490 options[:image].stroke('transparent') 330 image_task(options, coords, :label => label, :markers => true, :height => 3)
491 i_left = options[:subject_width] + ((version.start_date - @date_from)*options[:zoom]).floor
492
493 # Make sure negative i_left doesn't overflow the subject
494 if i_left > options[:subject_width]
495 options[:image].fill('green')
496 options[:image].rectangle(i_left, options[:top], i_left + 6, options[:top] - 6)
497 options[:image].fill('black')
498 options[:image].text(i_left + 11, options[:top] + 1, version.name)
499 end
500 when :pdf 331 when :pdf
501 options[:pdf].SetY(options[:top]+1.5) 332 pdf_task(options, coords, :label => label, :markers => true, :height => 0.8)
502 i_left = ((version.start_date - @date_from)*options[:zoom])
503
504 # Make sure negative i_left doesn't overflow the subject
505 if i_left > 0
506 options[:pdf].SetX(options[:subject_width] + i_left)
507 options[:pdf].SetFillColor(50,200,50)
508 options[:pdf].Cell(2, 2, "", 0, 0, "", 1)
509
510 options[:pdf].SetY(options[:top]+1.5)
511 options[:pdf].SetX(options[:subject_width] + i_left + 3)
512 options[:pdf].Cell(30, 2, "#{version.name}")
513 end
514 end 333 end
515 else 334 else
516 ActiveRecord::Base.logger.debug "Gantt#line_for_version was not given a version with a start_date" 335 ActiveRecord::Base.logger.debug "Gantt#line_for_version was not given a version with a start_date"
517 '' 336 ''
518 end 337 end
519 end 338 end
520 339
521 def subject_for_issue(issue, options) 340 def subject_for_issue(issue, options)
522 case options[:format] 341 while @issue_ancestors.any? && !issue.is_descendant_of?(@issue_ancestors.last)
342 @issue_ancestors.pop
343 options[:indent] -= options[:indent_increment]
344 end
345
346 output = case options[:format]
523 when :html 347 when :html
524 output = '' 348 css_classes = ''
525 output << "<div class='tooltip'>" 349 css_classes << ' issue-overdue' if issue.overdue?
526 output << "<div class='issue-subject' style='position: absolute;line-height:1.2em;height:16px;top:#{options[:top]}px;left:#{options[:indent]}px;overflow:hidden;'><small> " 350 css_classes << ' issue-behind-schedule' if issue.behind_schedule?
527 if issue.is_a? Issue 351 css_classes << ' icon icon-issue' unless Setting.gravatar_enabled? && issue.assigned_to
528 css_classes = [] 352
529 css_classes << 'issue-overdue' if issue.overdue? 353 subject = "<span class='#{css_classes}'>"
530 css_classes << 'issue-behind-schedule' if issue.behind_schedule? 354 if issue.assigned_to.present?
531 css_classes << 'icon icon-issue' unless Setting.gravatar_enabled? && issue.assigned_to 355 assigned_string = l(:field_assigned_to) + ": " + issue.assigned_to.name
532 356 subject << view.avatar(issue.assigned_to, :class => 'gravatar icon-gravatar', :size => 10, :title => assigned_string)
533 if issue.assigned_to.present? 357 end
534 assigned_string = l(:field_assigned_to) + ": " + issue.assigned_to.name 358 subject << view.link_to_issue(issue)
535 output << view.avatar(issue.assigned_to, :class => 'gravatar icon-gravatar', :size => 10, :title => assigned_string) 359 subject << '</span>'
536 end 360 html_subject(options, subject, :css => "issue-subject") + "\n"
537 output << "<span class='#{css_classes.join(' ')}'>"
538 output << view.link_to_issue(issue)
539 output << '</span>'
540 else
541 ActiveRecord::Base.logger.debug "Gantt#subject_for_issue was not given an issue"
542 ''
543 end
544 output << "</small></div>"
545
546 # Tooltip
547 if issue.is_a? Issue
548 output << "<span class='tip' style='position: absolute;top:#{ options[:top].to_i + 16 }px;left:#{ options[:indent].to_i + 20 }px;'>"
549 output << view.render_issue_tooltip(issue)
550 output << "</span>"
551 end
552
553 output << "</div>"
554 output
555 when :image 361 when :image
556 options[:image].fill('black') 362 image_subject(options, issue.subject)
557 options[:image].stroke('transparent')
558 options[:image].stroke_width(1)
559 options[:image].text(options[:indent], options[:top] + 2, issue.subject)
560 when :pdf 363 when :pdf
561 options[:pdf].SetY(options[:top]) 364 pdf_new_page?(options)
562 options[:pdf].SetX(15) 365 pdf_subject(options, issue.subject)
563 366 end
564 char_limit = PDF::MaxCharactorsForSubject - options[:indent] 367
565 options[:pdf].Cell(options[:subject_width]-15, 5, (" " * options[:indent]) +"#{issue.tracker} #{issue.id}: #{issue.subject}".sub(/^(.{#{char_limit}}[^\s]*\s).*$/, '\1 (...)'), "LR") 368 unless issue.leaf?
566 369 @issue_ancestors << issue
567 options[:pdf].SetY(options[:top]) 370 options[:indent] += options[:indent_increment]
568 options[:pdf].SetX(options[:subject_width]) 371 end
569 options[:pdf].Cell(options[:g_width], 5, "", "LR") 372
570 end 373 output
571 end 374 end
572 375
573 def line_for_issue(issue, options) 376 def line_for_issue(issue, options)
574 # Skip issues that don't have a due_before (due_date or version's due_date) 377 # Skip issues that don't have a due_before (due_date or version's due_date)
575 if issue.is_a?(Issue) && issue.due_before 378 if issue.is_a?(Issue) && issue.due_before
379 coords = coordinates(issue.start_date, issue.due_before, issue.done_ratio, options[:zoom])
380 label = "#{ issue.status.name } #{ issue.done_ratio }%"
381
576 case options[:format] 382 case options[:format]
577 when :html 383 when :html
578 output = '' 384 html_task(options, coords, :css => "task " + (issue.leaf? ? 'leaf' : 'parent'), :label => label, :issue => issue, :markers => !issue.leaf?)
579 # Handle nil start_dates, rare but can happen.
580 i_start_date = if issue.start_date && issue.start_date >= self.date_from
581 issue.start_date
582 else
583 self.date_from
584 end
585
586 i_end_date = ((issue.due_before && issue.due_before <= self.date_to) ? issue.due_before : self.date_to )
587 i_done_date = i_start_date + ((issue.due_before - i_start_date+1)*issue.done_ratio/100).floor
588 i_done_date = (i_done_date <= self.date_from ? self.date_from : i_done_date )
589 i_done_date = (i_done_date >= self.date_to ? self.date_to : i_done_date )
590
591 i_late_date = [i_end_date, Date.today].min if i_start_date < Date.today
592
593 i_left = ((i_start_date - self.date_from)*options[:zoom]).floor
594 i_width = ((i_end_date - i_start_date + 1)*options[:zoom]).floor - 2 # total width of the issue (- 2 for left and right borders)
595 d_width = ((i_done_date - i_start_date)*options[:zoom]).floor - 2 # done width
596 l_width = i_late_date ? ((i_late_date - i_start_date+1)*options[:zoom]).floor - 2 : 0 # delay width
597 css = "task " + (issue.leaf? ? 'leaf' : 'parent')
598
599 # Make sure that negative i_left and i_width don't
600 # overflow the subject
601 if i_width > 0
602 output << "<div style='top:#{ options[:top] }px;left:#{ i_left }px;width:#{ i_width }px;' class='#{css} task_todo'>&nbsp;</div>"
603 end
604 if l_width > 0
605 output << "<div style='top:#{ options[:top] }px;left:#{ i_left }px;width:#{ l_width }px;' class='#{css} task_late'>&nbsp;</div>"
606 end
607 if d_width > 0
608 output<< "<div style='top:#{ options[:top] }px;left:#{ i_left }px;width:#{ d_width }px;' class='#{css} task_done'>&nbsp;</div>"
609 end
610
611 # Display the status even if it's floated off to the left
612 status_px = i_left + i_width + 5
613 status_px = 5 if status_px <= 0
614
615 output << "<div style='top:#{ options[:top] }px;left:#{ status_px }px;' class='#{css} label issue-name'>"
616 output << issue.status.name
617 output << ' '
618 output << (issue.done_ratio).to_i.to_s
619 output << "%"
620 output << "</div>"
621
622 output << "<div class='tooltip' style='position: absolute;top:#{ options[:top] }px;left:#{ i_left }px;width:#{ i_width }px;height:12px;'>"
623 output << '<span class="tip">'
624 output << view.render_issue_tooltip(issue)
625 output << "</span></div>"
626 output
627
628 when :image 385 when :image
629 # Handle nil start_dates, rare but can happen. 386 image_task(options, coords, :label => label)
630 i_start_date = if issue.start_date && issue.start_date >= @date_from
631 issue.start_date
632 else
633 @date_from
634 end
635
636 i_end_date = (issue.due_before <= date_to ? issue.due_before : date_to )
637 i_done_date = i_start_date + ((issue.due_before - i_start_date+1)*issue.done_ratio/100).floor
638 i_done_date = (i_done_date <= @date_from ? @date_from : i_done_date )
639 i_done_date = (i_done_date >= date_to ? date_to : i_done_date )
640 i_late_date = [i_end_date, Date.today].min if i_start_date < Date.today
641
642 i_left = options[:subject_width] + ((i_start_date - @date_from)*options[:zoom]).floor
643 i_width = ((i_end_date - i_start_date + 1)*options[:zoom]).floor # total width of the issue
644 d_width = ((i_done_date - i_start_date)*options[:zoom]).floor # done width
645 l_width = i_late_date ? ((i_late_date - i_start_date+1)*options[:zoom]).floor : 0 # delay width
646
647
648 # Make sure that negative i_left and i_width don't
649 # overflow the subject
650 if i_width > 0
651 options[:image].fill('grey')
652 options[:image].rectangle(i_left, options[:top], i_left + i_width, options[:top] - 6)
653 options[:image].fill('red')
654 options[:image].rectangle(i_left, options[:top], i_left + l_width, options[:top] - 6) if l_width > 0
655 options[:image].fill('blue')
656 options[:image].rectangle(i_left, options[:top], i_left + d_width, options[:top] - 6) if d_width > 0
657 end
658
659 # Show the status and % done next to the subject if it overflows
660 options[:image].fill('black')
661 if i_width > 0
662 options[:image].text(i_left + i_width + 5,options[:top] + 1, "#{issue.status.name} #{issue.done_ratio}%")
663 else
664 options[:image].text(options[:subject_width] + 5,options[:top] + 1, "#{issue.status.name} #{issue.done_ratio}%")
665 end
666
667 when :pdf 387 when :pdf
668 options[:pdf].SetY(options[:top]+1.5) 388 pdf_task(options, coords, :label => label)
669 # Handle nil start_dates, rare but can happen. 389 end
670 i_start_date = if issue.start_date && issue.start_date >= @date_from
671 issue.start_date
672 else
673 @date_from
674 end
675
676 i_end_date = (issue.due_before <= @date_to ? issue.due_before : @date_to )
677
678 i_done_date = i_start_date + ((issue.due_before - i_start_date+1)*issue.done_ratio/100).floor
679 i_done_date = (i_done_date <= @date_from ? @date_from : i_done_date )
680 i_done_date = (i_done_date >= @date_to ? @date_to : i_done_date )
681
682 i_late_date = [i_end_date, Date.today].min if i_start_date < Date.today
683
684 i_left = ((i_start_date - @date_from)*options[:zoom])
685 i_width = ((i_end_date - i_start_date + 1)*options[:zoom])
686 d_width = ((i_done_date - i_start_date)*options[:zoom])
687 l_width = ((i_late_date - i_start_date+1)*options[:zoom]) if i_late_date
688 l_width ||= 0
689
690 # Make sure that negative i_left and i_width don't
691 # overflow the subject
692 if i_width > 0
693 options[:pdf].SetX(options[:subject_width] + i_left)
694 options[:pdf].SetFillColor(200,200,200)
695 options[:pdf].Cell(i_width, 2, "", 0, 0, "", 1)
696 end
697
698 if l_width > 0
699 options[:pdf].SetY(options[:top]+1.5)
700 options[:pdf].SetX(options[:subject_width] + i_left)
701 options[:pdf].SetFillColor(255,100,100)
702 options[:pdf].Cell(l_width, 2, "", 0, 0, "", 1)
703 end
704 if d_width > 0
705 options[:pdf].SetY(options[:top]+1.5)
706 options[:pdf].SetX(options[:subject_width] + i_left)
707 options[:pdf].SetFillColor(100,100,255)
708 options[:pdf].Cell(d_width, 2, "", 0, 0, "", 1)
709 end
710
711 options[:pdf].SetY(options[:top]+1.5)
712
713 # Make sure that negative i_left and i_width don't
714 # overflow the subject
715 if (i_left + i_width) >= 0
716 options[:pdf].SetX(options[:subject_width] + i_left + i_width)
717 else
718 options[:pdf].SetX(options[:subject_width])
719 end
720 options[:pdf].Cell(30, 2, "#{issue.status} #{issue.done_ratio}%")
721 end
722 else 390 else
723 ActiveRecord::Base.logger.debug "GanttHelper#line_for_issue was not given an issue with a due_before" 391 ActiveRecord::Base.logger.debug "GanttHelper#line_for_issue was not given an issue with a due_before"
724 '' 392 ''
725 end 393 end
726 end 394 end
744 imgl = Magick::ImageList.new 412 imgl = Magick::ImageList.new
745 imgl.new_image(subject_width+g_width+1, height) 413 imgl.new_image(subject_width+g_width+1, height)
746 gc = Magick::Draw.new 414 gc = Magick::Draw.new
747 415
748 # Subjects 416 # Subjects
417 gc.stroke('transparent')
749 subjects(:image => gc, :top => (headers_heigth + 20), :indent => 4, :format => :image) 418 subjects(:image => gc, :top => (headers_heigth + 20), :indent => 4, :format => :image)
750 419
751 # Months headers 420 # Months headers
752 month_f = @date_from 421 month_f = @date_from
753 left = subject_width 422 left = subject_width
803 height = g_height + header_heigth - 1 472 height = g_height + header_heigth - 1
804 wday = @date_from.cwday 473 wday = @date_from.cwday
805 (date_to - @date_from + 1).to_i.times do 474 (date_to - @date_from + 1).to_i.times do
806 width = zoom 475 width = zoom
807 gc.fill(wday == 6 || wday == 7 ? '#eee' : 'white') 476 gc.fill(wday == 6 || wday == 7 ? '#eee' : 'white')
808 gc.stroke('grey') 477 gc.stroke('#ddd')
809 gc.stroke_width(1) 478 gc.stroke_width(1)
810 gc.rectangle(left, 2*header_heigth, left + width, 2*header_heigth + g_height-1) 479 gc.rectangle(left, 2*header_heigth, left + width, 2*header_heigth + g_height-1)
811 left = left + width 480 left = left + width
812 wday = wday + 1 481 wday = wday + 1
813 wday = 1 if wday > 7 482 wday = 1 if wday > 7
822 gc.stroke('black') 491 gc.stroke('black')
823 gc.rectangle(0, 0, subject_width+g_width, g_height+ headers_heigth-1) 492 gc.rectangle(0, 0, subject_width+g_width, g_height+ headers_heigth-1)
824 493
825 # content 494 # content
826 top = headers_heigth + 20 495 top = headers_heigth + 20
827 496
497 gc.stroke('transparent')
828 lines(:image => gc, :top => top, :zoom => zoom, :subject_width => subject_width, :format => :image) 498 lines(:image => gc, :top => top, :zoom => zoom, :subject_width => subject_width, :format => :image)
829 499
830 # today red line 500 # today red line
831 if Date.today >= @date_from and Date.today <= date_to 501 if Date.today >= @date_from and Date.today <= date_to
832 gc.stroke('red') 502 gc.stroke('red')
934 pdf.SetX(15) 604 pdf.SetX(15)
935 pdf.Cell(subject_width+g_width-15, headers_heigth, "", 1) 605 pdf.Cell(subject_width+g_width-15, headers_heigth, "", 1)
936 606
937 # Tasks 607 # Tasks
938 top = headers_heigth + y_start 608 top = headers_heigth + y_start
939 pdf_subjects_and_lines(pdf, { 609 options = {
940 :top => top, 610 :top => top,
941 :zoom => zoom, 611 :zoom => zoom,
942 :subject_width => subject_width, 612 :subject_width => subject_width,
943 :g_width => g_width 613 :g_width => g_width,
944 }) 614 :indent => 0,
945 615 :indent_increment => 5,
946 616 :top_increment => 5,
947 pdf.Line(15, top, subject_width+g_width, top) 617 :format => :pdf,
618 :pdf => pdf
619 }
620 render(options)
948 pdf.Output 621 pdf.Output
949
950
951 end 622 end
952 623
953 private 624 private
954 625
955 # Renders both the subjects and lines of the Gantt chart for the 626 def coordinates(start_date, end_date, progress, zoom=nil)
956 # PDF format 627 zoom ||= @zoom
957 def pdf_subjects_and_lines(pdf, options = {}) 628
958 subject_options = {:indent => 0, :indent_increment => 5, :top_increment => 3, :render => :subject, :format => :pdf, :pdf => pdf}.merge(options) 629 coords = {}
959 line_options = {:indent => 0, :indent_increment => 5, :top_increment => 3, :render => :line, :format => :pdf, :pdf => pdf}.merge(options) 630 if start_date && end_date && start_date < self.date_to && end_date > self.date_from
960 631 if start_date > self.date_from
961 if @project 632 coords[:start] = start_date - self.date_from
962 render_project(@project, subject_options) 633 coords[:bar_start] = start_date - self.date_from
963 render_project(@project, line_options) 634 else
635 coords[:bar_start] = 0
636 end
637 if end_date < self.date_to
638 coords[:end] = end_date - self.date_from
639 coords[:bar_end] = end_date - self.date_from + 1
640 else
641 coords[:bar_end] = self.date_to - self.date_from + 1
642 end
643
644 if progress
645 progress_date = start_date + (end_date - start_date) * (progress / 100.0)
646 if progress_date > self.date_from && progress_date > start_date
647 if progress_date < self.date_to
648 coords[:bar_progress_end] = progress_date - self.date_from + 1
649 else
650 coords[:bar_progress_end] = self.date_to - self.date_from + 1
651 end
652 end
653
654 if progress_date < Date.today
655 late_date = [Date.today, end_date].min
656 if late_date > self.date_from && late_date > start_date
657 if late_date < self.date_to
658 coords[:bar_late_end] = late_date - self.date_from + 1
659 else
660 coords[:bar_late_end] = self.date_to - self.date_from + 1
661 end
662 end
663 end
664 end
665 end
666
667 # Transforms dates into pixels witdh
668 coords.keys.each do |key|
669 coords[key] = (coords[key] * zoom).floor
670 end
671 coords
672 end
673
674 # Sorts a collection of issues by start_date, due_date, id for gantt rendering
675 def sort_issues!(issues)
676 issues.sort! { |a, b| gantt_issue_compare(a, b, issues) }
677 end
678
679 # TODO: top level issues should be sorted by start date
680 def gantt_issue_compare(x, y, issues)
681 if x.root_id == y.root_id
682 x.lft <=> y.lft
964 else 683 else
965 Project.roots.each do |project| 684 x.root_id <=> y.root_id
966 render_project(project, subject_options) 685 end
967 render_project(project, line_options) 686 end
968 end 687
969 end 688 def current_limit
970 end 689 if @max_rows
971 690 @max_rows - @number_of_rows
691 else
692 nil
693 end
694 end
695
696 def abort?
697 if @max_rows && @number_of_rows >= @max_rows
698 @truncated = true
699 end
700 end
701
702 def pdf_new_page?(options)
703 if options[:top] > 180
704 options[:pdf].Line(15, options[:top], PDF::TotalWidth, options[:top])
705 options[:pdf].AddPage("L")
706 options[:top] = 15
707 options[:pdf].Line(15, options[:top] - 0.1, PDF::TotalWidth, options[:top] - 0.1)
708 end
709 end
710
711 def html_subject(params, subject, options={})
712 output = "<div class=' #{options[:css] }' style='position: absolute;line-height:1.2em;height:16px;top:#{params[:top]}px;left:#{params[:indent]}px;overflow:hidden;'>"
713 output << subject
714 output << "</div>"
715 @subjects << output
716 output
717 end
718
719 def pdf_subject(params, subject, options={})
720 params[:pdf].SetY(params[:top])
721 params[:pdf].SetX(15)
722
723 char_limit = PDF::MaxCharactorsForSubject - params[:indent]
724 params[:pdf].Cell(params[:subject_width]-15, 5, (" " * params[:indent]) + subject.to_s.sub(/^(.{#{char_limit}}[^\s]*\s).*$/, '\1 (...)'), "LR")
725
726 params[:pdf].SetY(params[:top])
727 params[:pdf].SetX(params[:subject_width])
728 params[:pdf].Cell(params[:g_width], 5, "", "LR")
729 end
730
731 def image_subject(params, subject, options={})
732 params[:image].fill('black')
733 params[:image].stroke('transparent')
734 params[:image].stroke_width(1)
735 params[:image].text(params[:indent], params[:top] + 2, subject)
736 end
737
738 def html_task(params, coords, options={})
739 output = ''
740 # Renders the task bar, with progress and late
741 if coords[:bar_start] && coords[:bar_end]
742 output << "<div style='top:#{ params[:top] }px;left:#{ coords[:bar_start] }px;width:#{ coords[:bar_end] - coords[:bar_start] - 2}px;' class='#{options[:css]} task_todo'>&nbsp;</div>"
743
744 if coords[:bar_late_end]
745 output << "<div style='top:#{ params[:top] }px;left:#{ coords[:bar_start] }px;width:#{ coords[:bar_late_end] - coords[:bar_start] - 2}px;' class='#{options[:css]} task_late'>&nbsp;</div>"
746 end
747 if coords[:bar_progress_end]
748 output << "<div style='top:#{ params[:top] }px;left:#{ coords[:bar_start] }px;width:#{ coords[:bar_progress_end] - coords[:bar_start] - 2}px;' class='#{options[:css]} task_done'>&nbsp;</div>"
749 end
750 end
751 # Renders the markers
752 if options[:markers]
753 if coords[:start]
754 output << "<div style='top:#{ params[:top] }px;left:#{ coords[:start] }px;width:15px;' class='#{options[:css]} marker starting'>&nbsp;</div>"
755 end
756 if coords[:end]
757 output << "<div style='top:#{ params[:top] }px;left:#{ coords[:end] + params[:zoom] }px;width:15px;' class='#{options[:css]} marker ending'>&nbsp;</div>"
758 end
759 end
760 # Renders the label on the right
761 if options[:label]
762 output << "<div style='top:#{ params[:top] }px;left:#{ (coords[:bar_end] || 0) + 8 }px;' class='#{options[:css]} label'>"
763 output << options[:label]
764 output << "</div>"
765 end
766 # Renders the tooltip
767 if options[:issue] && coords[:bar_start] && coords[:bar_end]
768 output << "<div class='tooltip' style='position: absolute;top:#{ params[:top] }px;left:#{ coords[:bar_start] }px;width:#{ coords[:bar_end] - coords[:bar_start] }px;height:12px;'>"
769 output << '<span class="tip">'
770 output << view.render_issue_tooltip(options[:issue])
771 output << "</span></div>"
772 end
773 @lines << output
774 output
775 end
776
777 def pdf_task(params, coords, options={})
778 height = options[:height] || 2
779
780 # Renders the task bar, with progress and late
781 if coords[:bar_start] && coords[:bar_end]
782 params[:pdf].SetY(params[:top]+1.5)
783 params[:pdf].SetX(params[:subject_width] + coords[:bar_start])
784 params[:pdf].SetFillColor(200,200,200)
785 params[:pdf].Cell(coords[:bar_end] - coords[:bar_start], height, "", 0, 0, "", 1)
786
787 if coords[:bar_late_end]
788 params[:pdf].SetY(params[:top]+1.5)
789 params[:pdf].SetX(params[:subject_width] + coords[:bar_start])
790 params[:pdf].SetFillColor(255,100,100)
791 params[:pdf].Cell(coords[:bar_late_end] - coords[:bar_start], height, "", 0, 0, "", 1)
792 end
793 if coords[:bar_progress_end]
794 params[:pdf].SetY(params[:top]+1.5)
795 params[:pdf].SetX(params[:subject_width] + coords[:bar_start])
796 params[:pdf].SetFillColor(90,200,90)
797 params[:pdf].Cell(coords[:bar_progress_end] - coords[:bar_start], height, "", 0, 0, "", 1)
798 end
799 end
800 # Renders the markers
801 if options[:markers]
802 if coords[:start]
803 params[:pdf].SetY(params[:top] + 1)
804 params[:pdf].SetX(params[:subject_width] + coords[:start] - 1)
805 params[:pdf].SetFillColor(50,50,200)
806 params[:pdf].Cell(2, 2, "", 0, 0, "", 1)
807 end
808 if coords[:end]
809 params[:pdf].SetY(params[:top] + 1)
810 params[:pdf].SetX(params[:subject_width] + coords[:end] - 1)
811 params[:pdf].SetFillColor(50,50,200)
812 params[:pdf].Cell(2, 2, "", 0, 0, "", 1)
813 end
814 end
815 # Renders the label on the right
816 if options[:label]
817 params[:pdf].SetX(params[:subject_width] + (coords[:bar_end] || 0) + 5)
818 params[:pdf].Cell(30, 2, options[:label])
819 end
820 end
821
822 def image_task(params, coords, options={})
823 height = options[:height] || 6
824
825 # Renders the task bar, with progress and late
826 if coords[:bar_start] && coords[:bar_end]
827 params[:image].fill('#aaa')
828 params[:image].rectangle(params[:subject_width] + coords[:bar_start], params[:top], params[:subject_width] + coords[:bar_end], params[:top] - height)
829
830 if coords[:bar_late_end]
831 params[:image].fill('#f66')
832 params[:image].rectangle(params[:subject_width] + coords[:bar_start], params[:top], params[:subject_width] + coords[:bar_late_end], params[:top] - height)
833 end
834 if coords[:bar_progress_end]
835 params[:image].fill('#00c600')
836 params[:image].rectangle(params[:subject_width] + coords[:bar_start], params[:top], params[:subject_width] + coords[:bar_progress_end], params[:top] - height)
837 end
838 end
839 # Renders the markers
840 if options[:markers]
841 if coords[:start]
842 x = params[:subject_width] + coords[:start]
843 y = params[:top] - height / 2
844 params[:image].fill('blue')
845 params[:image].polygon(x-4, y, x, y-4, x+4, y, x, y+4)
846 end
847 if coords[:end]
848 x = params[:subject_width] + coords[:end] + params[:zoom]
849 y = params[:top] - height / 2
850 params[:image].fill('blue')
851 params[:image].polygon(x-4, y, x, y-4, x+4, y, x, y+4)
852 end
853 end
854 # Renders the label on the right
855 if options[:label]
856 params[:image].fill('black')
857 params[:image].text(params[:subject_width] + (coords[:bar_end] || 0) + 5,params[:top] + 1, options[:label])
858 end
859 end
972 end 860 end
973 end 861 end
974 end 862 end