annotate .svn/pristine/02/026bb2d46eaa121e79862de3515bb99ff0827ca3.svn-base @ 1298:4f746d8966dd redmine_2.3_integration

Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author Chris Cannam
date Fri, 14 Jun 2013 09:28:30 +0100
parents 622f24f53b42
children
rev   line source
Chris@1295 1 # Redmine - project management software
Chris@1295 2 # Copyright (C) 2006-2013 Jean-Philippe Lang
Chris@1295 3 #
Chris@1295 4 # This program is free software; you can redistribute it and/or
Chris@1295 5 # modify it under the terms of the GNU General Public License
Chris@1295 6 # as published by the Free Software Foundation; either version 2
Chris@1295 7 # of the License, or (at your option) any later version.
Chris@1295 8 #
Chris@1295 9 # This program is distributed in the hope that it will be useful,
Chris@1295 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1295 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1295 12 # GNU General Public License for more details.
Chris@1295 13 #
Chris@1295 14 # You should have received a copy of the GNU General Public License
Chris@1295 15 # along with this program; if not, write to the Free Software
Chris@1295 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1295 17
Chris@1295 18 module Redmine
Chris@1295 19 module Helpers
Chris@1295 20 # Simple class to handle gantt chart data
Chris@1295 21 class Gantt
Chris@1295 22 include ERB::Util
Chris@1295 23 include Redmine::I18n
Chris@1295 24 include Redmine::Utils::DateCalculation
Chris@1295 25
Chris@1295 26 # Relation types that are rendered
Chris@1295 27 DRAW_TYPES = {
Chris@1295 28 IssueRelation::TYPE_BLOCKS => { :landscape_margin => 16, :color => '#F34F4F' },
Chris@1295 29 IssueRelation::TYPE_PRECEDES => { :landscape_margin => 20, :color => '#628FEA' }
Chris@1295 30 }.freeze
Chris@1295 31
Chris@1295 32 # :nodoc:
Chris@1295 33 # Some utility methods for the PDF export
Chris@1295 34 class PDF
Chris@1295 35 MaxCharactorsForSubject = 45
Chris@1295 36 TotalWidth = 280
Chris@1295 37 LeftPaneWidth = 100
Chris@1295 38
Chris@1295 39 def self.right_pane_width
Chris@1295 40 TotalWidth - LeftPaneWidth
Chris@1295 41 end
Chris@1295 42 end
Chris@1295 43
Chris@1295 44 attr_reader :year_from, :month_from, :date_from, :date_to, :zoom, :months, :truncated, :max_rows
Chris@1295 45 attr_accessor :query
Chris@1295 46 attr_accessor :project
Chris@1295 47 attr_accessor :view
Chris@1295 48
Chris@1295 49 def initialize(options={})
Chris@1295 50 options = options.dup
Chris@1295 51 if options[:year] && options[:year].to_i >0
Chris@1295 52 @year_from = options[:year].to_i
Chris@1295 53 if options[:month] && options[:month].to_i >=1 && options[:month].to_i <= 12
Chris@1295 54 @month_from = options[:month].to_i
Chris@1295 55 else
Chris@1295 56 @month_from = 1
Chris@1295 57 end
Chris@1295 58 else
Chris@1295 59 @month_from ||= Date.today.month
Chris@1295 60 @year_from ||= Date.today.year
Chris@1295 61 end
Chris@1295 62 zoom = (options[:zoom] || User.current.pref[:gantt_zoom]).to_i
Chris@1295 63 @zoom = (zoom > 0 && zoom < 5) ? zoom : 2
Chris@1295 64 months = (options[:months] || User.current.pref[:gantt_months]).to_i
Chris@1295 65 @months = (months > 0 && months < 25) ? months : 6
Chris@1295 66 # Save gantt parameters as user preference (zoom and months count)
Chris@1295 67 if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] ||
Chris@1295 68 @months != User.current.pref[:gantt_months]))
Chris@1295 69 User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months
Chris@1295 70 User.current.preference.save
Chris@1295 71 end
Chris@1295 72 @date_from = Date.civil(@year_from, @month_from, 1)
Chris@1295 73 @date_to = (@date_from >> @months) - 1
Chris@1295 74 @subjects = ''
Chris@1295 75 @lines = ''
Chris@1295 76 @number_of_rows = nil
Chris@1295 77 @issue_ancestors = []
Chris@1295 78 @truncated = false
Chris@1295 79 if options.has_key?(:max_rows)
Chris@1295 80 @max_rows = options[:max_rows]
Chris@1295 81 else
Chris@1295 82 @max_rows = Setting.gantt_items_limit.blank? ? nil : Setting.gantt_items_limit.to_i
Chris@1295 83 end
Chris@1295 84 end
Chris@1295 85
Chris@1295 86 def common_params
Chris@1295 87 { :controller => 'gantts', :action => 'show', :project_id => @project }
Chris@1295 88 end
Chris@1295 89
Chris@1295 90 def params
Chris@1295 91 common_params.merge({:zoom => zoom, :year => year_from,
Chris@1295 92 :month => month_from, :months => months})
Chris@1295 93 end
Chris@1295 94
Chris@1295 95 def params_previous
Chris@1295 96 common_params.merge({:year => (date_from << months).year,
Chris@1295 97 :month => (date_from << months).month,
Chris@1295 98 :zoom => zoom, :months => months})
Chris@1295 99 end
Chris@1295 100
Chris@1295 101 def params_next
Chris@1295 102 common_params.merge({:year => (date_from >> months).year,
Chris@1295 103 :month => (date_from >> months).month,
Chris@1295 104 :zoom => zoom, :months => months})
Chris@1295 105 end
Chris@1295 106
Chris@1295 107 # Returns the number of rows that will be rendered on the Gantt chart
Chris@1295 108 def number_of_rows
Chris@1295 109 return @number_of_rows if @number_of_rows
Chris@1295 110 rows = projects.inject(0) {|total, p| total += number_of_rows_on_project(p)}
Chris@1295 111 rows > @max_rows ? @max_rows : rows
Chris@1295 112 end
Chris@1295 113
Chris@1295 114 # Returns the number of rows that will be used to list a project on
Chris@1295 115 # the Gantt chart. This will recurse for each subproject.
Chris@1295 116 def number_of_rows_on_project(project)
Chris@1295 117 return 0 unless projects.include?(project)
Chris@1295 118 count = 1
Chris@1295 119 count += project_issues(project).size
Chris@1295 120 count += project_versions(project).size
Chris@1295 121 count
Chris@1295 122 end
Chris@1295 123
Chris@1295 124 # Renders the subjects of the Gantt chart, the left side.
Chris@1295 125 def subjects(options={})
Chris@1295 126 render(options.merge(:only => :subjects)) unless @subjects_rendered
Chris@1295 127 @subjects
Chris@1295 128 end
Chris@1295 129
Chris@1295 130 # Renders the lines of the Gantt chart, the right side
Chris@1295 131 def lines(options={})
Chris@1295 132 render(options.merge(:only => :lines)) unless @lines_rendered
Chris@1295 133 @lines
Chris@1295 134 end
Chris@1295 135
Chris@1295 136 # Returns issues that will be rendered
Chris@1295 137 def issues
Chris@1295 138 @issues ||= @query.issues(
Chris@1295 139 :include => [:assigned_to, :tracker, :priority, :category, :fixed_version],
Chris@1295 140 :order => "#{Project.table_name}.lft ASC, #{Issue.table_name}.id ASC",
Chris@1295 141 :limit => @max_rows
Chris@1295 142 )
Chris@1295 143 end
Chris@1295 144
Chris@1295 145 # Returns a hash of the relations between the issues that are present on the gantt
Chris@1295 146 # and that should be displayed, grouped by issue ids.
Chris@1295 147 def relations
Chris@1295 148 return @relations if @relations
Chris@1295 149 if issues.any?
Chris@1295 150 issue_ids = issues.map(&:id)
Chris@1295 151 @relations = IssueRelation.
Chris@1295 152 where(:issue_from_id => issue_ids, :issue_to_id => issue_ids, :relation_type => DRAW_TYPES.keys).
Chris@1295 153 group_by(&:issue_from_id)
Chris@1295 154 else
Chris@1295 155 @relations = {}
Chris@1295 156 end
Chris@1295 157 end
Chris@1295 158
Chris@1295 159 # Return all the project nodes that will be displayed
Chris@1295 160 def projects
Chris@1295 161 return @projects if @projects
Chris@1295 162 ids = issues.collect(&:project).uniq.collect(&:id)
Chris@1295 163 if ids.any?
Chris@1295 164 # All issues projects and their visible ancestors
Chris@1295 165 @projects = Project.visible.all(
Chris@1295 166 :joins => "LEFT JOIN #{Project.table_name} child ON #{Project.table_name}.lft <= child.lft AND #{Project.table_name}.rgt >= child.rgt",
Chris@1295 167 :conditions => ["child.id IN (?)", ids],
Chris@1295 168 :order => "#{Project.table_name}.lft ASC"
Chris@1295 169 ).uniq
Chris@1295 170 else
Chris@1295 171 @projects = []
Chris@1295 172 end
Chris@1295 173 end
Chris@1295 174
Chris@1295 175 # Returns the issues that belong to +project+
Chris@1295 176 def project_issues(project)
Chris@1295 177 @issues_by_project ||= issues.group_by(&:project)
Chris@1295 178 @issues_by_project[project] || []
Chris@1295 179 end
Chris@1295 180
Chris@1295 181 # Returns the distinct versions of the issues that belong to +project+
Chris@1295 182 def project_versions(project)
Chris@1295 183 project_issues(project).collect(&:fixed_version).compact.uniq
Chris@1295 184 end
Chris@1295 185
Chris@1295 186 # Returns the issues that belong to +project+ and are assigned to +version+
Chris@1295 187 def version_issues(project, version)
Chris@1295 188 project_issues(project).select {|issue| issue.fixed_version == version}
Chris@1295 189 end
Chris@1295 190
Chris@1295 191 def render(options={})
Chris@1295 192 options = {:top => 0, :top_increment => 20,
Chris@1295 193 :indent_increment => 20, :render => :subject,
Chris@1295 194 :format => :html}.merge(options)
Chris@1295 195 indent = options[:indent] || 4
Chris@1295 196 @subjects = '' unless options[:only] == :lines
Chris@1295 197 @lines = '' unless options[:only] == :subjects
Chris@1295 198 @number_of_rows = 0
Chris@1295 199 Project.project_tree(projects) do |project, level|
Chris@1295 200 options[:indent] = indent + level * options[:indent_increment]
Chris@1295 201 render_project(project, options)
Chris@1295 202 break if abort?
Chris@1295 203 end
Chris@1295 204 @subjects_rendered = true unless options[:only] == :lines
Chris@1295 205 @lines_rendered = true unless options[:only] == :subjects
Chris@1295 206 render_end(options)
Chris@1295 207 end
Chris@1295 208
Chris@1295 209 def render_project(project, options={})
Chris@1295 210 subject_for_project(project, options) unless options[:only] == :lines
Chris@1295 211 line_for_project(project, options) unless options[:only] == :subjects
Chris@1295 212 options[:top] += options[:top_increment]
Chris@1295 213 options[:indent] += options[:indent_increment]
Chris@1295 214 @number_of_rows += 1
Chris@1295 215 return if abort?
Chris@1295 216 issues = project_issues(project).select {|i| i.fixed_version.nil?}
Chris@1295 217 sort_issues!(issues)
Chris@1295 218 if issues
Chris@1295 219 render_issues(issues, options)
Chris@1295 220 return if abort?
Chris@1295 221 end
Chris@1295 222 versions = project_versions(project)
Chris@1295 223 versions.each do |version|
Chris@1295 224 render_version(project, version, options)
Chris@1295 225 end
Chris@1295 226 # Remove indent to hit the next sibling
Chris@1295 227 options[:indent] -= options[:indent_increment]
Chris@1295 228 end
Chris@1295 229
Chris@1295 230 def render_issues(issues, options={})
Chris@1295 231 @issue_ancestors = []
Chris@1295 232 issues.each do |i|
Chris@1295 233 subject_for_issue(i, options) unless options[:only] == :lines
Chris@1295 234 line_for_issue(i, options) unless options[:only] == :subjects
Chris@1295 235 options[:top] += options[:top_increment]
Chris@1295 236 @number_of_rows += 1
Chris@1295 237 break if abort?
Chris@1295 238 end
Chris@1295 239 options[:indent] -= (options[:indent_increment] * @issue_ancestors.size)
Chris@1295 240 end
Chris@1295 241
Chris@1295 242 def render_version(project, version, options={})
Chris@1295 243 # Version header
Chris@1295 244 subject_for_version(version, options) unless options[:only] == :lines
Chris@1295 245 line_for_version(version, options) unless options[:only] == :subjects
Chris@1295 246 options[:top] += options[:top_increment]
Chris@1295 247 @number_of_rows += 1
Chris@1295 248 return if abort?
Chris@1295 249 issues = version_issues(project, version)
Chris@1295 250 if issues
Chris@1295 251 sort_issues!(issues)
Chris@1295 252 # Indent issues
Chris@1295 253 options[:indent] += options[:indent_increment]
Chris@1295 254 render_issues(issues, options)
Chris@1295 255 options[:indent] -= options[:indent_increment]
Chris@1295 256 end
Chris@1295 257 end
Chris@1295 258
Chris@1295 259 def render_end(options={})
Chris@1295 260 case options[:format]
Chris@1295 261 when :pdf
Chris@1295 262 options[:pdf].Line(15, options[:top], PDF::TotalWidth, options[:top])
Chris@1295 263 end
Chris@1295 264 end
Chris@1295 265
Chris@1295 266 def subject_for_project(project, options)
Chris@1295 267 case options[:format]
Chris@1295 268 when :html
Chris@1295 269 html_class = ""
Chris@1295 270 html_class << 'icon icon-projects '
Chris@1295 271 html_class << (project.overdue? ? 'project-overdue' : '')
Chris@1295 272 s = view.link_to_project(project).html_safe
Chris@1295 273 subject = view.content_tag(:span, s,
Chris@1295 274 :class => html_class).html_safe
Chris@1295 275 html_subject(options, subject, :css => "project-name")
Chris@1295 276 when :image
Chris@1295 277 image_subject(options, project.name)
Chris@1295 278 when :pdf
Chris@1295 279 pdf_new_page?(options)
Chris@1295 280 pdf_subject(options, project.name)
Chris@1295 281 end
Chris@1295 282 end
Chris@1295 283
Chris@1295 284 def line_for_project(project, options)
Chris@1295 285 # Skip versions that don't have a start_date or due date
Chris@1295 286 if project.is_a?(Project) && project.start_date && project.due_date
Chris@1295 287 options[:zoom] ||= 1
Chris@1295 288 options[:g_width] ||= (self.date_to - self.date_from + 1) * options[:zoom]
Chris@1295 289 coords = coordinates(project.start_date, project.due_date, nil, options[:zoom])
Chris@1295 290 label = h(project)
Chris@1295 291 case options[:format]
Chris@1295 292 when :html
Chris@1295 293 html_task(options, coords, :css => "project task", :label => label, :markers => true)
Chris@1295 294 when :image
Chris@1295 295 image_task(options, coords, :label => label, :markers => true, :height => 3)
Chris@1295 296 when :pdf
Chris@1295 297 pdf_task(options, coords, :label => label, :markers => true, :height => 0.8)
Chris@1295 298 end
Chris@1295 299 else
Chris@1295 300 ''
Chris@1295 301 end
Chris@1295 302 end
Chris@1295 303
Chris@1295 304 def subject_for_version(version, options)
Chris@1295 305 case options[:format]
Chris@1295 306 when :html
Chris@1295 307 html_class = ""
Chris@1295 308 html_class << 'icon icon-package '
Chris@1295 309 html_class << (version.behind_schedule? ? 'version-behind-schedule' : '') << " "
Chris@1295 310 html_class << (version.overdue? ? 'version-overdue' : '')
Chris@1295 311 html_class << ' version-closed' unless version.open?
Chris@1295 312 if version.start_date && version.due_date && version.completed_pourcent
Chris@1295 313 progress_date = calc_progress_date(version.start_date,
Chris@1295 314 version.due_date, version.completed_pourcent)
Chris@1295 315 html_class << ' behind-start-date' if progress_date < self.date_from
Chris@1295 316 html_class << ' over-end-date' if progress_date > self.date_to
Chris@1295 317 end
Chris@1295 318 s = view.link_to_version(version).html_safe
Chris@1295 319 subject = view.content_tag(:span, s,
Chris@1295 320 :class => html_class).html_safe
Chris@1295 321 html_subject(options, subject, :css => "version-name",
Chris@1295 322 :id => "version-#{version.id}")
Chris@1295 323 when :image
Chris@1295 324 image_subject(options, version.to_s_with_project)
Chris@1295 325 when :pdf
Chris@1295 326 pdf_new_page?(options)
Chris@1295 327 pdf_subject(options, version.to_s_with_project)
Chris@1295 328 end
Chris@1295 329 end
Chris@1295 330
Chris@1295 331 def line_for_version(version, options)
Chris@1295 332 # Skip versions that don't have a start_date
Chris@1295 333 if version.is_a?(Version) && version.due_date && version.start_date
Chris@1295 334 options[:zoom] ||= 1
Chris@1295 335 options[:g_width] ||= (self.date_to - self.date_from + 1) * options[:zoom]
Chris@1295 336 coords = coordinates(version.start_date,
Chris@1295 337 version.due_date, version.completed_percent,
Chris@1295 338 options[:zoom])
Chris@1295 339 label = "#{h version} #{h version.completed_percent.to_i.to_s}%"
Chris@1295 340 label = h("#{version.project} -") + label unless @project && @project == version.project
Chris@1295 341 case options[:format]
Chris@1295 342 when :html
Chris@1295 343 html_task(options, coords, :css => "version task",
Chris@1295 344 :label => label, :markers => true, :version => version)
Chris@1295 345 when :image
Chris@1295 346 image_task(options, coords, :label => label, :markers => true, :height => 3)
Chris@1295 347 when :pdf
Chris@1295 348 pdf_task(options, coords, :label => label, :markers => true, :height => 0.8)
Chris@1295 349 end
Chris@1295 350 else
Chris@1295 351 ''
Chris@1295 352 end
Chris@1295 353 end
Chris@1295 354
Chris@1295 355 def subject_for_issue(issue, options)
Chris@1295 356 while @issue_ancestors.any? && !issue.is_descendant_of?(@issue_ancestors.last)
Chris@1295 357 @issue_ancestors.pop
Chris@1295 358 options[:indent] -= options[:indent_increment]
Chris@1295 359 end
Chris@1295 360 output = case options[:format]
Chris@1295 361 when :html
Chris@1295 362 css_classes = ''
Chris@1295 363 css_classes << ' issue-overdue' if issue.overdue?
Chris@1295 364 css_classes << ' issue-behind-schedule' if issue.behind_schedule?
Chris@1295 365 css_classes << ' icon icon-issue' unless Setting.gravatar_enabled? && issue.assigned_to
Chris@1295 366 css_classes << ' issue-closed' if issue.closed?
Chris@1295 367 if issue.start_date && issue.due_before && issue.done_ratio
Chris@1295 368 progress_date = calc_progress_date(issue.start_date,
Chris@1295 369 issue.due_before, issue.done_ratio)
Chris@1295 370 css_classes << ' behind-start-date' if progress_date < self.date_from
Chris@1295 371 css_classes << ' over-end-date' if progress_date > self.date_to
Chris@1295 372 end
Chris@1295 373 s = "".html_safe
Chris@1295 374 if issue.assigned_to.present?
Chris@1295 375 assigned_string = l(:field_assigned_to) + ": " + issue.assigned_to.name
Chris@1295 376 s << view.avatar(issue.assigned_to,
Chris@1295 377 :class => 'gravatar icon-gravatar',
Chris@1295 378 :size => 10,
Chris@1295 379 :title => assigned_string).to_s.html_safe
Chris@1295 380 end
Chris@1295 381 s << view.link_to_issue(issue).html_safe
Chris@1295 382 subject = view.content_tag(:span, s, :class => css_classes).html_safe
Chris@1295 383 html_subject(options, subject, :css => "issue-subject",
Chris@1295 384 :title => issue.subject, :id => "issue-#{issue.id}") + "\n"
Chris@1295 385 when :image
Chris@1295 386 image_subject(options, issue.subject)
Chris@1295 387 when :pdf
Chris@1295 388 pdf_new_page?(options)
Chris@1295 389 pdf_subject(options, issue.subject)
Chris@1295 390 end
Chris@1295 391 unless issue.leaf?
Chris@1295 392 @issue_ancestors << issue
Chris@1295 393 options[:indent] += options[:indent_increment]
Chris@1295 394 end
Chris@1295 395 output
Chris@1295 396 end
Chris@1295 397
Chris@1295 398 def line_for_issue(issue, options)
Chris@1295 399 # Skip issues that don't have a due_before (due_date or version's due_date)
Chris@1295 400 if issue.is_a?(Issue) && issue.due_before
Chris@1295 401 coords = coordinates(issue.start_date, issue.due_before, issue.done_ratio, options[:zoom])
Chris@1295 402 label = "#{issue.status.name} #{issue.done_ratio}%"
Chris@1295 403 case options[:format]
Chris@1295 404 when :html
Chris@1295 405 html_task(options, coords,
Chris@1295 406 :css => "task " + (issue.leaf? ? 'leaf' : 'parent'),
Chris@1295 407 :label => label, :issue => issue,
Chris@1295 408 :markers => !issue.leaf?)
Chris@1295 409 when :image
Chris@1295 410 image_task(options, coords, :label => label)
Chris@1295 411 when :pdf
Chris@1295 412 pdf_task(options, coords, :label => label)
Chris@1295 413 end
Chris@1295 414 else
Chris@1295 415 ''
Chris@1295 416 end
Chris@1295 417 end
Chris@1295 418
Chris@1295 419 # Generates a gantt image
Chris@1295 420 # Only defined if RMagick is avalaible
Chris@1295 421 def to_image(format='PNG')
Chris@1295 422 date_to = (@date_from >> @months) - 1
Chris@1295 423 show_weeks = @zoom > 1
Chris@1295 424 show_days = @zoom > 2
Chris@1295 425 subject_width = 400
Chris@1295 426 header_height = 18
Chris@1295 427 # width of one day in pixels
Chris@1295 428 zoom = @zoom * 2
Chris@1295 429 g_width = (@date_to - @date_from + 1) * zoom
Chris@1295 430 g_height = 20 * number_of_rows + 30
Chris@1295 431 headers_height = (show_weeks ? 2 * header_height : header_height)
Chris@1295 432 height = g_height + headers_height
Chris@1295 433 imgl = Magick::ImageList.new
Chris@1295 434 imgl.new_image(subject_width + g_width + 1, height)
Chris@1295 435 gc = Magick::Draw.new
Chris@1295 436 gc.font = Redmine::Configuration['rmagick_font_path'] || ""
Chris@1295 437 # Subjects
Chris@1295 438 gc.stroke('transparent')
Chris@1295 439 subjects(:image => gc, :top => (headers_height + 20), :indent => 4, :format => :image)
Chris@1295 440 # Months headers
Chris@1295 441 month_f = @date_from
Chris@1295 442 left = subject_width
Chris@1295 443 @months.times do
Chris@1295 444 width = ((month_f >> 1) - month_f) * zoom
Chris@1295 445 gc.fill('white')
Chris@1295 446 gc.stroke('grey')
Chris@1295 447 gc.stroke_width(1)
Chris@1295 448 gc.rectangle(left, 0, left + width, height)
Chris@1295 449 gc.fill('black')
Chris@1295 450 gc.stroke('transparent')
Chris@1295 451 gc.stroke_width(1)
Chris@1295 452 gc.text(left.round + 8, 14, "#{month_f.year}-#{month_f.month}")
Chris@1295 453 left = left + width
Chris@1295 454 month_f = month_f >> 1
Chris@1295 455 end
Chris@1295 456 # Weeks headers
Chris@1295 457 if show_weeks
Chris@1295 458 left = subject_width
Chris@1295 459 height = header_height
Chris@1295 460 if @date_from.cwday == 1
Chris@1295 461 # date_from is monday
Chris@1295 462 week_f = date_from
Chris@1295 463 else
Chris@1295 464 # find next monday after date_from
Chris@1295 465 week_f = @date_from + (7 - @date_from.cwday + 1)
Chris@1295 466 width = (7 - @date_from.cwday + 1) * zoom
Chris@1295 467 gc.fill('white')
Chris@1295 468 gc.stroke('grey')
Chris@1295 469 gc.stroke_width(1)
Chris@1295 470 gc.rectangle(left, header_height, left + width, 2 * header_height + g_height - 1)
Chris@1295 471 left = left + width
Chris@1295 472 end
Chris@1295 473 while week_f <= date_to
Chris@1295 474 width = (week_f + 6 <= date_to) ? 7 * zoom : (date_to - week_f + 1) * zoom
Chris@1295 475 gc.fill('white')
Chris@1295 476 gc.stroke('grey')
Chris@1295 477 gc.stroke_width(1)
Chris@1295 478 gc.rectangle(left.round, header_height, left.round + width, 2 * header_height + g_height - 1)
Chris@1295 479 gc.fill('black')
Chris@1295 480 gc.stroke('transparent')
Chris@1295 481 gc.stroke_width(1)
Chris@1295 482 gc.text(left.round + 2, header_height + 14, week_f.cweek.to_s)
Chris@1295 483 left = left + width
Chris@1295 484 week_f = week_f + 7
Chris@1295 485 end
Chris@1295 486 end
Chris@1295 487 # Days details (week-end in grey)
Chris@1295 488 if show_days
Chris@1295 489 left = subject_width
Chris@1295 490 height = g_height + header_height - 1
Chris@1295 491 wday = @date_from.cwday
Chris@1295 492 (date_to - @date_from + 1).to_i.times do
Chris@1295 493 width = zoom
Chris@1295 494 gc.fill(non_working_week_days.include?(wday) ? '#eee' : 'white')
Chris@1295 495 gc.stroke('#ddd')
Chris@1295 496 gc.stroke_width(1)
Chris@1295 497 gc.rectangle(left, 2 * header_height, left + width, 2 * header_height + g_height - 1)
Chris@1295 498 left = left + width
Chris@1295 499 wday = wday + 1
Chris@1295 500 wday = 1 if wday > 7
Chris@1295 501 end
Chris@1295 502 end
Chris@1295 503 # border
Chris@1295 504 gc.fill('transparent')
Chris@1295 505 gc.stroke('grey')
Chris@1295 506 gc.stroke_width(1)
Chris@1295 507 gc.rectangle(0, 0, subject_width + g_width, headers_height)
Chris@1295 508 gc.stroke('black')
Chris@1295 509 gc.rectangle(0, 0, subject_width + g_width, g_height + headers_height - 1)
Chris@1295 510 # content
Chris@1295 511 top = headers_height + 20
Chris@1295 512 gc.stroke('transparent')
Chris@1295 513 lines(:image => gc, :top => top, :zoom => zoom,
Chris@1295 514 :subject_width => subject_width, :format => :image)
Chris@1295 515 # today red line
Chris@1295 516 if Date.today >= @date_from and Date.today <= date_to
Chris@1295 517 gc.stroke('red')
Chris@1295 518 x = (Date.today - @date_from + 1) * zoom + subject_width
Chris@1295 519 gc.line(x, headers_height, x, headers_height + g_height - 1)
Chris@1295 520 end
Chris@1295 521 gc.draw(imgl)
Chris@1295 522 imgl.format = format
Chris@1295 523 imgl.to_blob
Chris@1295 524 end if Object.const_defined?(:Magick)
Chris@1295 525
Chris@1295 526 def to_pdf
Chris@1295 527 pdf = ::Redmine::Export::PDF::ITCPDF.new(current_language)
Chris@1295 528 pdf.SetTitle("#{l(:label_gantt)} #{project}")
Chris@1295 529 pdf.alias_nb_pages
Chris@1295 530 pdf.footer_date = format_date(Date.today)
Chris@1295 531 pdf.AddPage("L")
Chris@1295 532 pdf.SetFontStyle('B', 12)
Chris@1295 533 pdf.SetX(15)
Chris@1295 534 pdf.RDMCell(PDF::LeftPaneWidth, 20, project.to_s)
Chris@1295 535 pdf.Ln
Chris@1295 536 pdf.SetFontStyle('B', 9)
Chris@1295 537 subject_width = PDF::LeftPaneWidth
Chris@1295 538 header_height = 5
Chris@1295 539 headers_height = header_height
Chris@1295 540 show_weeks = false
Chris@1295 541 show_days = false
Chris@1295 542 if self.months < 7
Chris@1295 543 show_weeks = true
Chris@1295 544 headers_height = 2 * header_height
Chris@1295 545 if self.months < 3
Chris@1295 546 show_days = true
Chris@1295 547 headers_height = 3 * header_height
Chris@1295 548 end
Chris@1295 549 end
Chris@1295 550 g_width = PDF.right_pane_width
Chris@1295 551 zoom = (g_width) / (self.date_to - self.date_from + 1)
Chris@1295 552 g_height = 120
Chris@1295 553 t_height = g_height + headers_height
Chris@1295 554 y_start = pdf.GetY
Chris@1295 555 # Months headers
Chris@1295 556 month_f = self.date_from
Chris@1295 557 left = subject_width
Chris@1295 558 height = header_height
Chris@1295 559 self.months.times do
Chris@1295 560 width = ((month_f >> 1) - month_f) * zoom
Chris@1295 561 pdf.SetY(y_start)
Chris@1295 562 pdf.SetX(left)
Chris@1295 563 pdf.RDMCell(width, height, "#{month_f.year}-#{month_f.month}", "LTR", 0, "C")
Chris@1295 564 left = left + width
Chris@1295 565 month_f = month_f >> 1
Chris@1295 566 end
Chris@1295 567 # Weeks headers
Chris@1295 568 if show_weeks
Chris@1295 569 left = subject_width
Chris@1295 570 height = header_height
Chris@1295 571 if self.date_from.cwday == 1
Chris@1295 572 # self.date_from is monday
Chris@1295 573 week_f = self.date_from
Chris@1295 574 else
Chris@1295 575 # find next monday after self.date_from
Chris@1295 576 week_f = self.date_from + (7 - self.date_from.cwday + 1)
Chris@1295 577 width = (7 - self.date_from.cwday + 1) * zoom-1
Chris@1295 578 pdf.SetY(y_start + header_height)
Chris@1295 579 pdf.SetX(left)
Chris@1295 580 pdf.RDMCell(width + 1, height, "", "LTR")
Chris@1295 581 left = left + width + 1
Chris@1295 582 end
Chris@1295 583 while week_f <= self.date_to
Chris@1295 584 width = (week_f + 6 <= self.date_to) ? 7 * zoom : (self.date_to - week_f + 1) * zoom
Chris@1295 585 pdf.SetY(y_start + header_height)
Chris@1295 586 pdf.SetX(left)
Chris@1295 587 pdf.RDMCell(width, height, (width >= 5 ? week_f.cweek.to_s : ""), "LTR", 0, "C")
Chris@1295 588 left = left + width
Chris@1295 589 week_f = week_f + 7
Chris@1295 590 end
Chris@1295 591 end
Chris@1295 592 # Days headers
Chris@1295 593 if show_days
Chris@1295 594 left = subject_width
Chris@1295 595 height = header_height
Chris@1295 596 wday = self.date_from.cwday
Chris@1295 597 pdf.SetFontStyle('B', 7)
Chris@1295 598 (self.date_to - self.date_from + 1).to_i.times do
Chris@1295 599 width = zoom
Chris@1295 600 pdf.SetY(y_start + 2 * header_height)
Chris@1295 601 pdf.SetX(left)
Chris@1295 602 pdf.RDMCell(width, height, day_name(wday).first, "LTR", 0, "C")
Chris@1295 603 left = left + width
Chris@1295 604 wday = wday + 1
Chris@1295 605 wday = 1 if wday > 7
Chris@1295 606 end
Chris@1295 607 end
Chris@1295 608 pdf.SetY(y_start)
Chris@1295 609 pdf.SetX(15)
Chris@1295 610 pdf.RDMCell(subject_width + g_width - 15, headers_height, "", 1)
Chris@1295 611 # Tasks
Chris@1295 612 top = headers_height + y_start
Chris@1295 613 options = {
Chris@1295 614 :top => top,
Chris@1295 615 :zoom => zoom,
Chris@1295 616 :subject_width => subject_width,
Chris@1295 617 :g_width => g_width,
Chris@1295 618 :indent => 0,
Chris@1295 619 :indent_increment => 5,
Chris@1295 620 :top_increment => 5,
Chris@1295 621 :format => :pdf,
Chris@1295 622 :pdf => pdf
Chris@1295 623 }
Chris@1295 624 render(options)
Chris@1295 625 pdf.Output
Chris@1295 626 end
Chris@1295 627
Chris@1295 628 private
Chris@1295 629
Chris@1295 630 def coordinates(start_date, end_date, progress, zoom=nil)
Chris@1295 631 zoom ||= @zoom
Chris@1295 632 coords = {}
Chris@1295 633 if start_date && end_date && start_date < self.date_to && end_date > self.date_from
Chris@1295 634 if start_date > self.date_from
Chris@1295 635 coords[:start] = start_date - self.date_from
Chris@1295 636 coords[:bar_start] = start_date - self.date_from
Chris@1295 637 else
Chris@1295 638 coords[:bar_start] = 0
Chris@1295 639 end
Chris@1295 640 if end_date < self.date_to
Chris@1295 641 coords[:end] = end_date - self.date_from
Chris@1295 642 coords[:bar_end] = end_date - self.date_from + 1
Chris@1295 643 else
Chris@1295 644 coords[:bar_end] = self.date_to - self.date_from + 1
Chris@1295 645 end
Chris@1295 646 if progress
Chris@1295 647 progress_date = calc_progress_date(start_date, end_date, progress)
Chris@1295 648 if progress_date > self.date_from && progress_date > start_date
Chris@1295 649 if progress_date < self.date_to
Chris@1295 650 coords[:bar_progress_end] = progress_date - self.date_from
Chris@1295 651 else
Chris@1295 652 coords[:bar_progress_end] = self.date_to - self.date_from + 1
Chris@1295 653 end
Chris@1295 654 end
Chris@1295 655 if progress_date < Date.today
Chris@1295 656 late_date = [Date.today, end_date].min
Chris@1295 657 if late_date > self.date_from && late_date > start_date
Chris@1295 658 if late_date < self.date_to
Chris@1295 659 coords[:bar_late_end] = late_date - self.date_from + 1
Chris@1295 660 else
Chris@1295 661 coords[:bar_late_end] = self.date_to - self.date_from + 1
Chris@1295 662 end
Chris@1295 663 end
Chris@1295 664 end
Chris@1295 665 end
Chris@1295 666 end
Chris@1295 667 # Transforms dates into pixels witdh
Chris@1295 668 coords.keys.each do |key|
Chris@1295 669 coords[key] = (coords[key] * zoom).floor
Chris@1295 670 end
Chris@1295 671 coords
Chris@1295 672 end
Chris@1295 673
Chris@1295 674 def calc_progress_date(start_date, end_date, progress)
Chris@1295 675 start_date + (end_date - start_date + 1) * (progress / 100.0)
Chris@1295 676 end
Chris@1295 677
Chris@1295 678 # TODO: Sorts a collection of issues by start_date, due_date, id for gantt rendering
Chris@1295 679 def sort_issues!(issues)
Chris@1295 680 issues.sort! { |a, b| gantt_issue_compare(a, b) }
Chris@1295 681 end
Chris@1295 682
Chris@1295 683 # TODO: top level issues should be sorted by start date
Chris@1295 684 def gantt_issue_compare(x, y)
Chris@1295 685 if x.root_id == y.root_id
Chris@1295 686 x.lft <=> y.lft
Chris@1295 687 else
Chris@1295 688 x.root_id <=> y.root_id
Chris@1295 689 end
Chris@1295 690 end
Chris@1295 691
Chris@1295 692 def current_limit
Chris@1295 693 if @max_rows
Chris@1295 694 @max_rows - @number_of_rows
Chris@1295 695 else
Chris@1295 696 nil
Chris@1295 697 end
Chris@1295 698 end
Chris@1295 699
Chris@1295 700 def abort?
Chris@1295 701 if @max_rows && @number_of_rows >= @max_rows
Chris@1295 702 @truncated = true
Chris@1295 703 end
Chris@1295 704 end
Chris@1295 705
Chris@1295 706 def pdf_new_page?(options)
Chris@1295 707 if options[:top] > 180
Chris@1295 708 options[:pdf].Line(15, options[:top], PDF::TotalWidth, options[:top])
Chris@1295 709 options[:pdf].AddPage("L")
Chris@1295 710 options[:top] = 15
Chris@1295 711 options[:pdf].Line(15, options[:top] - 0.1, PDF::TotalWidth, options[:top] - 0.1)
Chris@1295 712 end
Chris@1295 713 end
Chris@1295 714
Chris@1295 715 def html_subject(params, subject, options={})
Chris@1295 716 style = "position: absolute;top:#{params[:top]}px;left:#{params[:indent]}px;"
Chris@1295 717 style << "width:#{params[:subject_width] - params[:indent]}px;" if params[:subject_width]
Chris@1295 718 output = view.content_tag(:div, subject,
Chris@1295 719 :class => options[:css], :style => style,
Chris@1295 720 :title => options[:title],
Chris@1295 721 :id => options[:id])
Chris@1295 722 @subjects << output
Chris@1295 723 output
Chris@1295 724 end
Chris@1295 725
Chris@1295 726 def pdf_subject(params, subject, options={})
Chris@1295 727 params[:pdf].SetY(params[:top])
Chris@1295 728 params[:pdf].SetX(15)
Chris@1295 729 char_limit = PDF::MaxCharactorsForSubject - params[:indent]
Chris@1295 730 params[:pdf].RDMCell(params[:subject_width] - 15, 5,
Chris@1295 731 (" " * params[:indent]) +
Chris@1295 732 subject.to_s.sub(/^(.{#{char_limit}}[^\s]*\s).*$/, '\1 (...)'),
Chris@1295 733 "LR")
Chris@1295 734 params[:pdf].SetY(params[:top])
Chris@1295 735 params[:pdf].SetX(params[:subject_width])
Chris@1295 736 params[:pdf].RDMCell(params[:g_width], 5, "", "LR")
Chris@1295 737 end
Chris@1295 738
Chris@1295 739 def image_subject(params, subject, options={})
Chris@1295 740 params[:image].fill('black')
Chris@1295 741 params[:image].stroke('transparent')
Chris@1295 742 params[:image].stroke_width(1)
Chris@1295 743 params[:image].text(params[:indent], params[:top] + 2, subject)
Chris@1295 744 end
Chris@1295 745
Chris@1295 746 def issue_relations(issue)
Chris@1295 747 rels = {}
Chris@1295 748 if relations[issue.id]
Chris@1295 749 relations[issue.id].each do |relation|
Chris@1295 750 (rels[relation.relation_type] ||= []) << relation.issue_to_id
Chris@1295 751 end
Chris@1295 752 end
Chris@1295 753 rels
Chris@1295 754 end
Chris@1295 755
Chris@1295 756 def html_task(params, coords, options={})
Chris@1295 757 output = ''
Chris@1295 758 # Renders the task bar, with progress and late
Chris@1295 759 if coords[:bar_start] && coords[:bar_end]
Chris@1295 760 width = coords[:bar_end] - coords[:bar_start] - 2
Chris@1295 761 style = ""
Chris@1295 762 style << "top:#{params[:top]}px;"
Chris@1295 763 style << "left:#{coords[:bar_start]}px;"
Chris@1295 764 style << "width:#{width}px;"
Chris@1295 765 html_id = "task-todo-issue-#{options[:issue].id}" if options[:issue]
Chris@1295 766 html_id = "task-todo-version-#{options[:version].id}" if options[:version]
Chris@1295 767 content_opt = {:style => style,
Chris@1295 768 :class => "#{options[:css]} task_todo",
Chris@1295 769 :id => html_id}
Chris@1295 770 if options[:issue]
Chris@1295 771 rels = issue_relations(options[:issue])
Chris@1295 772 if rels.present?
Chris@1295 773 content_opt[:data] = {"rels" => rels.to_json}
Chris@1295 774 end
Chris@1295 775 end
Chris@1295 776 output << view.content_tag(:div, '&nbsp;'.html_safe, content_opt)
Chris@1295 777 if coords[:bar_late_end]
Chris@1295 778 width = coords[:bar_late_end] - coords[:bar_start] - 2
Chris@1295 779 style = ""
Chris@1295 780 style << "top:#{params[:top]}px;"
Chris@1295 781 style << "left:#{coords[:bar_start]}px;"
Chris@1295 782 style << "width:#{width}px;"
Chris@1295 783 output << view.content_tag(:div, '&nbsp;'.html_safe,
Chris@1295 784 :style => style,
Chris@1295 785 :class => "#{options[:css]} task_late")
Chris@1295 786 end
Chris@1295 787 if coords[:bar_progress_end]
Chris@1295 788 width = coords[:bar_progress_end] - coords[:bar_start] - 2
Chris@1295 789 style = ""
Chris@1295 790 style << "top:#{params[:top]}px;"
Chris@1295 791 style << "left:#{coords[:bar_start]}px;"
Chris@1295 792 style << "width:#{width}px;"
Chris@1295 793 html_id = "task-done-issue-#{options[:issue].id}" if options[:issue]
Chris@1295 794 html_id = "task-done-version-#{options[:version].id}" if options[:version]
Chris@1295 795 output << view.content_tag(:div, '&nbsp;'.html_safe,
Chris@1295 796 :style => style,
Chris@1295 797 :class => "#{options[:css]} task_done",
Chris@1295 798 :id => html_id)
Chris@1295 799 end
Chris@1295 800 end
Chris@1295 801 # Renders the markers
Chris@1295 802 if options[:markers]
Chris@1295 803 if coords[:start]
Chris@1295 804 style = ""
Chris@1295 805 style << "top:#{params[:top]}px;"
Chris@1295 806 style << "left:#{coords[:start]}px;"
Chris@1295 807 style << "width:15px;"
Chris@1295 808 output << view.content_tag(:div, '&nbsp;'.html_safe,
Chris@1295 809 :style => style,
Chris@1295 810 :class => "#{options[:css]} marker starting")
Chris@1295 811 end
Chris@1295 812 if coords[:end]
Chris@1295 813 style = ""
Chris@1295 814 style << "top:#{params[:top]}px;"
Chris@1295 815 style << "left:#{coords[:end] + params[:zoom]}px;"
Chris@1295 816 style << "width:15px;"
Chris@1295 817 output << view.content_tag(:div, '&nbsp;'.html_safe,
Chris@1295 818 :style => style,
Chris@1295 819 :class => "#{options[:css]} marker ending")
Chris@1295 820 end
Chris@1295 821 end
Chris@1295 822 # Renders the label on the right
Chris@1295 823 if options[:label]
Chris@1295 824 style = ""
Chris@1295 825 style << "top:#{params[:top]}px;"
Chris@1295 826 style << "left:#{(coords[:bar_end] || 0) + 8}px;"
Chris@1295 827 style << "width:15px;"
Chris@1295 828 output << view.content_tag(:div, options[:label],
Chris@1295 829 :style => style,
Chris@1295 830 :class => "#{options[:css]} label")
Chris@1295 831 end
Chris@1295 832 # Renders the tooltip
Chris@1295 833 if options[:issue] && coords[:bar_start] && coords[:bar_end]
Chris@1295 834 s = view.content_tag(:span,
Chris@1295 835 view.render_issue_tooltip(options[:issue]).html_safe,
Chris@1295 836 :class => "tip")
Chris@1295 837 style = ""
Chris@1295 838 style << "position: absolute;"
Chris@1295 839 style << "top:#{params[:top]}px;"
Chris@1295 840 style << "left:#{coords[:bar_start]}px;"
Chris@1295 841 style << "width:#{coords[:bar_end] - coords[:bar_start]}px;"
Chris@1295 842 style << "height:12px;"
Chris@1295 843 output << view.content_tag(:div, s.html_safe,
Chris@1295 844 :style => style,
Chris@1295 845 :class => "tooltip")
Chris@1295 846 end
Chris@1295 847 @lines << output
Chris@1295 848 output
Chris@1295 849 end
Chris@1295 850
Chris@1295 851 def pdf_task(params, coords, options={})
Chris@1295 852 height = options[:height] || 2
Chris@1295 853 # Renders the task bar, with progress and late
Chris@1295 854 if coords[:bar_start] && coords[:bar_end]
Chris@1295 855 params[:pdf].SetY(params[:top] + 1.5)
Chris@1295 856 params[:pdf].SetX(params[:subject_width] + coords[:bar_start])
Chris@1295 857 params[:pdf].SetFillColor(200, 200, 200)
Chris@1295 858 params[:pdf].RDMCell(coords[:bar_end] - coords[:bar_start], height, "", 0, 0, "", 1)
Chris@1295 859 if coords[:bar_late_end]
Chris@1295 860 params[:pdf].SetY(params[:top] + 1.5)
Chris@1295 861 params[:pdf].SetX(params[:subject_width] + coords[:bar_start])
Chris@1295 862 params[:pdf].SetFillColor(255, 100, 100)
Chris@1295 863 params[:pdf].RDMCell(coords[:bar_late_end] - coords[:bar_start], height, "", 0, 0, "", 1)
Chris@1295 864 end
Chris@1295 865 if coords[:bar_progress_end]
Chris@1295 866 params[:pdf].SetY(params[:top] + 1.5)
Chris@1295 867 params[:pdf].SetX(params[:subject_width] + coords[:bar_start])
Chris@1295 868 params[:pdf].SetFillColor(90, 200, 90)
Chris@1295 869 params[:pdf].RDMCell(coords[:bar_progress_end] - coords[:bar_start], height, "", 0, 0, "", 1)
Chris@1295 870 end
Chris@1295 871 end
Chris@1295 872 # Renders the markers
Chris@1295 873 if options[:markers]
Chris@1295 874 if coords[:start]
Chris@1295 875 params[:pdf].SetY(params[:top] + 1)
Chris@1295 876 params[:pdf].SetX(params[:subject_width] + coords[:start] - 1)
Chris@1295 877 params[:pdf].SetFillColor(50, 50, 200)
Chris@1295 878 params[:pdf].RDMCell(2, 2, "", 0, 0, "", 1)
Chris@1295 879 end
Chris@1295 880 if coords[:end]
Chris@1295 881 params[:pdf].SetY(params[:top] + 1)
Chris@1295 882 params[:pdf].SetX(params[:subject_width] + coords[:end] - 1)
Chris@1295 883 params[:pdf].SetFillColor(50, 50, 200)
Chris@1295 884 params[:pdf].RDMCell(2, 2, "", 0, 0, "", 1)
Chris@1295 885 end
Chris@1295 886 end
Chris@1295 887 # Renders the label on the right
Chris@1295 888 if options[:label]
Chris@1295 889 params[:pdf].SetX(params[:subject_width] + (coords[:bar_end] || 0) + 5)
Chris@1295 890 params[:pdf].RDMCell(30, 2, options[:label])
Chris@1295 891 end
Chris@1295 892 end
Chris@1295 893
Chris@1295 894 def image_task(params, coords, options={})
Chris@1295 895 height = options[:height] || 6
Chris@1295 896 # Renders the task bar, with progress and late
Chris@1295 897 if coords[:bar_start] && coords[:bar_end]
Chris@1295 898 params[:image].fill('#aaa')
Chris@1295 899 params[:image].rectangle(params[:subject_width] + coords[:bar_start],
Chris@1295 900 params[:top],
Chris@1295 901 params[:subject_width] + coords[:bar_end],
Chris@1295 902 params[:top] - height)
Chris@1295 903 if coords[:bar_late_end]
Chris@1295 904 params[:image].fill('#f66')
Chris@1295 905 params[:image].rectangle(params[:subject_width] + coords[:bar_start],
Chris@1295 906 params[:top],
Chris@1295 907 params[:subject_width] + coords[:bar_late_end],
Chris@1295 908 params[:top] - height)
Chris@1295 909 end
Chris@1295 910 if coords[:bar_progress_end]
Chris@1295 911 params[:image].fill('#00c600')
Chris@1295 912 params[:image].rectangle(params[:subject_width] + coords[:bar_start],
Chris@1295 913 params[:top],
Chris@1295 914 params[:subject_width] + coords[:bar_progress_end],
Chris@1295 915 params[:top] - height)
Chris@1295 916 end
Chris@1295 917 end
Chris@1295 918 # Renders the markers
Chris@1295 919 if options[:markers]
Chris@1295 920 if coords[:start]
Chris@1295 921 x = params[:subject_width] + coords[:start]
Chris@1295 922 y = params[:top] - height / 2
Chris@1295 923 params[:image].fill('blue')
Chris@1295 924 params[:image].polygon(x - 4, y, x, y - 4, x + 4, y, x, y + 4)
Chris@1295 925 end
Chris@1295 926 if coords[:end]
Chris@1295 927 x = params[:subject_width] + coords[:end] + params[:zoom]
Chris@1295 928 y = params[:top] - height / 2
Chris@1295 929 params[:image].fill('blue')
Chris@1295 930 params[:image].polygon(x - 4, y, x, y - 4, x + 4, y, x, y + 4)
Chris@1295 931 end
Chris@1295 932 end
Chris@1295 933 # Renders the label on the right
Chris@1295 934 if options[:label]
Chris@1295 935 params[:image].fill('black')
Chris@1295 936 params[:image].text(params[:subject_width] + (coords[:bar_end] || 0) + 5,
Chris@1295 937 params[:top] + 1,
Chris@1295 938 options[:label])
Chris@1295 939 end
Chris@1295 940 end
Chris@1295 941 end
Chris@1295 942 end
Chris@1295 943 end