Class: Redmine::Helpers::Gantt

Inherits:
Object
  • Object
show all
Includes:
ERB::Util, I18n, Utils::DateCalculation
Defined in:
lib/redmine/helpers/gantt.rb

Overview

Simple class to handle gantt chart data

Defined Under Namespace

Classes: MaxLinesLimitReached, PDF

Constant Summary collapse

DRAW_TYPES =

Relation types that are rendered

{
  IssueRelation::TYPE_BLOCKS   => {:landscape_margin => 16, :color => '#F34F4F'},
  IssueRelation::TYPE_PRECEDES => {:landscape_margin => 20, :color => '#628FEA'}
}.freeze
UNAVAILABLE_COLUMNS =
[:tracker, :id, :subject]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils::DateCalculation

#add_working_days, #next_working_date, #non_working_week_days, #working_days

Methods included from I18n

#abbr_day_name, #current_language, #day_letter, #day_name, #find_language, #format_date, #format_hours, #format_time, included, #l, #l_hours, #l_hours_short, #l_or_humanize, #languages_options, #ll, #lu, #month_name, #normalize_float, #set_language_if_valid, #valid_languages

Constructor Details

#initialize(options = {}) ⇒ Gantt

Returns a new instance of Gantt.



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/redmine/helpers/gantt.rb', line 56

def initialize(options={})
  options = options.dup
  if options[:year] && options[:year].to_i >0
    @year_from = options[:year].to_i
    if options[:month] && options[:month].to_i >=1 && options[:month].to_i <= 12
      @month_from = options[:month].to_i
    else
      @month_from = 1
    end
  else
    @month_from ||= User.current.today.month
    @year_from ||= User.current.today.year
  end
  zoom = (options[:zoom] || User.current.pref[:gantt_zoom]).to_i
  @zoom = (zoom > 0 && zoom < 5) ? zoom : 2
  months = (options[:months] || User.current.pref[:gantt_months]).to_i
  @months = (months > 0 && months < Setting.gantt_months_limit.to_i + 1) ? months : 6
  # Save gantt parameters as user preference (zoom and months count)
  if User.current.logged? &&
       (@zoom   != User.current.pref[:gantt_zoom] ||
        @months != User.current.pref[:gantt_months])
    User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months
    User.current.preference.save
  end
  @date_from = Date.civil(@year_from, @month_from, 1)
  @date_to = (@date_from >> @months) - 1
  @subjects = +''
  @lines = +''
  @columns ||= {}
  @number_of_rows = nil
  @truncated = false
  if options.has_key?(:max_rows)
    @max_rows = options[:max_rows]
  else
    @max_rows = Setting.gantt_items_limit.blank? ? nil : Setting.gantt_items_limit.to_i
  end
end

Instance Attribute Details

#date_fromObject (readonly)

Returns the value of attribute date_from.



51
52
53
# File 'lib/redmine/helpers/gantt.rb', line 51

def date_from
  @date_from
end

#date_toObject (readonly)

Returns the value of attribute date_to.



51
52
53
# File 'lib/redmine/helpers/gantt.rb', line 51

def date_to
  @date_to
end

#max_rowsObject (readonly)

Returns the value of attribute max_rows.



51
52
53
# File 'lib/redmine/helpers/gantt.rb', line 51

def max_rows
  @max_rows
end

#month_fromObject (readonly)

Returns the value of attribute month_from.



51
52
53
# File 'lib/redmine/helpers/gantt.rb', line 51

def month_from
  @month_from
end

#monthsObject (readonly)

Returns the value of attribute months.



51
52
53
# File 'lib/redmine/helpers/gantt.rb', line 51

def months
  @months
end

#projectObject

Returns the value of attribute project.



53
54
55
# File 'lib/redmine/helpers/gantt.rb', line 53

def project
  @project
end

#queryObject

Returns the value of attribute query.



52
53
54
# File 'lib/redmine/helpers/gantt.rb', line 52

def query
  @query
end

#truncatedObject (readonly)

Returns the value of attribute truncated.



51
52
53
# File 'lib/redmine/helpers/gantt.rb', line 51

def truncated
  @truncated
end

#viewObject

Returns the value of attribute view.



54
55
56
# File 'lib/redmine/helpers/gantt.rb', line 54

def view
  @view
end

#year_fromObject (readonly)

Returns the value of attribute year_from.



51
52
53
# File 'lib/redmine/helpers/gantt.rb', line 51

def year_from
  @year_from
end

#zoomObject (readonly)

Returns the value of attribute zoom.



51
52
53
# File 'lib/redmine/helpers/gantt.rb', line 51

def zoom
  @zoom
end

Class Method Details

.sort_issue_logic(issue) ⇒ Object



688
689
690
691
692
693
694
695
696
697
# File 'lib/redmine/helpers/gantt.rb', line 688

def sort_issue_logic(issue)
  julian_date = Date.new
  ancesters_start_date = []
  current_issue = issue
  begin
    ancesters_start_date.unshift([current_issue.start_date || julian_date, current_issue.id])
    current_issue = current_issue.parent
  end while (current_issue)
  ancesters_start_date
end

.sort_issues!(issues) ⇒ Object



684
685
686
# File 'lib/redmine/helpers/gantt.rb', line 684

def sort_issues!(issues)
  issues.sort_by! {|issue| sort_issue_logic(issue)}
end

.sort_versions!(versions) ⇒ Object



699
700
701
# File 'lib/redmine/helpers/gantt.rb', line 699

def sort_versions!(versions)
  versions.sort!
end

Instance Method Details

#column_content_for_issue(issue, options) ⇒ Object



345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
# File 'lib/redmine/helpers/gantt.rb', line 345

def column_content_for_issue(issue, options)
  if options[:format] == :html
    data_options = {}
    data_options[:collapse_expand] = "issue-#{issue.id}"
    data_options[:number_of_rows] = number_of_rows
    style = "position: absolute;top: #{options[:top]}px; font-size: 0.8em;"
    content =
      view.(
        :div, view.column_content(options[:column], issue),
        :style => style, :class => "issue_#{options[:column].name}",
        :id => "#{options[:column].name}_issue_#{issue.id}",
        :data => data_options
      )
    @columns[options[:column].name] << content if @columns.has_key?(options[:column].name)
    content
  end
end

#common_paramsObject



94
95
96
# File 'lib/redmine/helpers/gantt.rb', line 94

def common_params
  {:controller => 'gantts', :action => 'show', :project_id => @project}
end

#decrement_indent(options, factor = 1) ⇒ Object



298
299
300
# File 'lib/redmine/helpers/gantt.rb', line 298

def decrement_indent(options, factor=1)
  increment_indent(options, -factor)
end

#increment_indent(options, factor = 1) ⇒ Object



290
291
292
293
294
295
296
# File 'lib/redmine/helpers/gantt.rb', line 290

def increment_indent(options, factor=1)
  options[:indent] += options[:indent_increment] * factor
  if block_given?
    yield
    decrement_indent(options, factor)
  end
end

#issuesObject

Returns issues that will be rendered



153
154
155
156
157
158
# File 'lib/redmine/helpers/gantt.rb', line 153

def issues
  @issues ||= @query.issues(
    :order => ["#{Project.table_name}.lft ASC", "#{Issue.table_name}.id ASC"],
    :limit => @max_rows
  )
end

#line(start_date, end_date, done_ratio, markers, label, options, object = nil) ⇒ Object



367
368
369
370
371
372
# File 'lib/redmine/helpers/gantt.rb', line 367

def line(start_date, end_date, done_ratio, markers, label, options, object=nil)
  options[:zoom] ||= 1
  options[:g_width] ||= (self.date_to - self.date_from + 1) * options[:zoom]
  coords = coordinates(start_date, end_date, done_ratio, options[:zoom])
  send :"#{options[:format]}_task", options, coords, markers, label, object
end

#line_for_issue(issue, options) ⇒ Object



333
334
335
336
337
338
339
340
341
342
343
# File 'lib/redmine/helpers/gantt.rb', line 333

def line_for_issue(issue, options)
  # Skip issues that don't have a due_before (due_date or version's due_date)
  if issue.is_a?(Issue) && issue.due_before
    label = issue.status.name.dup
    unless issue.disabled_core_fields.include?('done_ratio')
      label << " #{issue.done_ratio}%"
    end
    markers = !issue.leaf?
    line(issue.start_date, issue.due_before, issue.done_ratio, markers, label, options, issue)
  end
end

#line_for_project(project, options) ⇒ Object



306
307
308
309
310
311
312
# File 'lib/redmine/helpers/gantt.rb', line 306

def line_for_project(project, options)
  # Skip projects that don't have a start_date or due date
  if project.is_a?(Project) && project.start_date && project.due_date
    label = project.name
    line(project.start_date, project.due_date, nil, true, label, options, project)
  end
end

#line_for_version(version, options) ⇒ Object



318
319
320
321
322
323
324
325
326
327
# File 'lib/redmine/helpers/gantt.rb', line 318

def line_for_version(version, options)
  # Skip versions that don't have a start_date
  if version.is_a?(Version) && version.due_date && version.start_date
    label = "#{h(version)} #{h(version.visible_fixed_issues.completed_percent.to_f.round)}%"
    label = h("#{version.project} -") + label unless @project && @project == version.project
    line(version.start_date, version.due_date,
         version.visible_fixed_issues.completed_percent,
         true, label, options, version)
  end
end

#lines(options = {}) ⇒ Object

Renders the lines of the Gantt chart, the right side



141
142
143
144
# File 'lib/redmine/helpers/gantt.rb', line 141

def lines(options={})
  render(options.merge(:only => :lines)) unless @lines_rendered
  @lines
end

#number_of_rowsObject

Returns the number of rows that will be rendered on the Gantt chart



116
117
118
119
120
121
# File 'lib/redmine/helpers/gantt.rb', line 116

def number_of_rows
  return @number_of_rows if @number_of_rows

  rows = projects.inject(0) {|total, p| total += number_of_rows_on_project(p)}
  [rows, @max_rows].min
end

#number_of_rows_on_project(project) ⇒ Object

Returns the number of rows that will be used to list a project on the Gantt chart. This will recurse for each subproject.



125
126
127
128
129
130
131
132
# File 'lib/redmine/helpers/gantt.rb', line 125

def number_of_rows_on_project(project)
  return 0 unless projects.include?(project)

  count = 1
  count += project_issues(project).size
  count += project_versions(project).size
  count
end

#paramsObject



98
99
100
101
# File 'lib/redmine/helpers/gantt.rb', line 98

def params
  common_params.merge({:zoom => zoom, :year => year_from,
                       :month => month_from, :months => months})
end

#params_nextObject



109
110
111
112
113
# File 'lib/redmine/helpers/gantt.rb', line 109

def params_next
  common_params.merge({:year => (date_from >> months).year,
                       :month => (date_from >> months).month,
                       :zoom => zoom, :months => months})
end

#params_previousObject



103
104
105
106
107
# File 'lib/redmine/helpers/gantt.rb', line 103

def params_previous
  common_params.merge({:year => (date_from << months).year,
                       :month => (date_from << months).month,
                       :zoom => zoom, :months => months})
end

#project_issues(project) ⇒ Object

Returns the issues that belong to project



194
195
196
197
# File 'lib/redmine/helpers/gantt.rb', line 194

def project_issues(project)
  @issues_by_project ||= issues.group_by(&:project)
  @issues_by_project[project] || []
end

#project_versions(project) ⇒ Object

Returns the distinct versions of the issues that belong to project



200
201
202
# File 'lib/redmine/helpers/gantt.rb', line 200

def project_versions(project)
  project_issues(project).filter_map(&:fixed_version).uniq
end

#projectsObject

Return all the project nodes that will be displayed



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/redmine/helpers/gantt.rb', line 176

def projects
  return @projects if @projects

  ids = issues.collect(&:project).uniq.collect(&:id)
  if ids.any?
    # All issues projects and their visible ancestors
    @projects = Project.visible.
      joins("LEFT JOIN #{Project.table_name} child ON #{Project.table_name}.lft <= child.lft AND #{Project.table_name}.rgt >= child.rgt").
      where("child.id IN (?)", ids).
      order("#{Project.table_name}.lft ASC").
      distinct.
      to_a
  else
    @projects = []
  end
end

#relationsObject

Returns a hash of the relations between the issues that are present on the gantt and that should be displayed, grouped by issue ids.



162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/redmine/helpers/gantt.rb', line 162

def relations
  return @relations if @relations

  if issues.any?
    issue_ids = issues.map(&:id)
    @relations = IssueRelation.
      where(:issue_from_id => issue_ids, :issue_to_id => issue_ids, :relation_type => DRAW_TYPES.keys).
      group_by(&:issue_from_id)
  else
    @relations = {}
  end
end

#render(options = {}) ⇒ Object



209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/redmine/helpers/gantt.rb', line 209

def render(options={})
  options = {:top => 0, :top_increment => 20,
             :indent_increment => 20, :render => :subject,
             :format => :html}.merge(options)
  indent = options[:indent] || 4
  @subjects = +'' unless options[:only] == :lines || options[:only] == :selected_columns
  @lines = +'' unless options[:only] == :subjects || options[:only] == :selected_columns
  @columns[options[:column].name] = +'' if options[:only] == :selected_columns && @columns.has_key?(options[:column]) == false
  @number_of_rows = 0
  begin
    Project.project_tree(projects) do |project, level|
      options[:indent] = indent + level * options[:indent_increment]
      render_project(project, options)
    end
  rescue MaxLinesLimitReached
    @truncated = true
  end
  @subjects_rendered = true unless options[:only] == :lines || options[:only] == :selected_columns
  @lines_rendered = true unless options[:only] == :subjects || options[:only] == :selected_columns
  render_end(options)
end

#render_end(options = {}) ⇒ Object



283
284
285
286
287
288
# File 'lib/redmine/helpers/gantt.rb', line 283

def render_end(options={})
  case options[:format]
  when :pdf
    options[:pdf].Line(15, options[:top], PDF::TotalWidth, options[:top])
  end
end

#render_issues(issues, options = {}) ⇒ Object



254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/redmine/helpers/gantt.rb', line 254

def render_issues(issues, options={})
  self.class.sort_issues!(issues)
  ancestors = []
  issues.each do |issue|
    while ancestors.any? && !issue.is_descendant_of?(ancestors.last)
      ancestors.pop
      decrement_indent(options)
    end
    render_object_row(issue, options)
    unless issue.leaf?
      ancestors << issue
      increment_indent(options)
    end
  end
  decrement_indent(options, ancestors.size)
end

#render_object_row(object, options) ⇒ Object



271
272
273
274
275
276
277
278
279
280
281
# File 'lib/redmine/helpers/gantt.rb', line 271

def render_object_row(object, options)
  class_name = object.class.name.downcase
  send(:"subject_for_#{class_name}", object, options) unless options[:only] == :lines || options[:only] == :selected_columns
  send(:"line_for_#{class_name}", object, options) unless options[:only] == :subjects || options[:only] == :selected_columns
  column_content_for_issue(object, options) if options[:only] == :selected_columns && options[:column].present? && object.is_a?(Issue)
  options[:top] += options[:top_increment]
  @number_of_rows += 1
  if @max_rows && @number_of_rows >= @max_rows
    raise MaxLinesLimitReached
  end
end

#render_project(project, options = {}) ⇒ Object



231
232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'lib/redmine/helpers/gantt.rb', line 231

def render_project(project, options={})
  render_object_row(project, options)
  increment_indent(options) do
    # render issue that are not assigned to a version
    issues = project_issues(project).select {|i| i.fixed_version.nil?}
    render_issues(issues, options)
    # then render project versions and their issues
    versions = project_versions(project)
    self.class.sort_versions!(versions)
    versions.each do |version|
      render_version(project, version, options)
    end
  end
end

#render_version(project, version, options = {}) ⇒ Object



246
247
248
249
250
251
252
# File 'lib/redmine/helpers/gantt.rb', line 246

def render_version(project, version, options={})
  render_object_row(version, options)
  increment_indent(options) do
    issues = version_issues(project, version)
    render_issues(issues, options)
  end
end

#selected_column_content(options = {}) ⇒ Object

Renders the selected column of the Gantt chart, the right side of subjects.



147
148
149
150
# File 'lib/redmine/helpers/gantt.rb', line 147

def selected_column_content(options={})
  render(options.merge(:only => :selected_columns)) unless @columns.has_key?(options[:column].name)
  @columns[options[:column].name]
end

#subject(label, options, object = nil) ⇒ Object



363
364
365
# File 'lib/redmine/helpers/gantt.rb', line 363

def subject(label, options, object=nil)
  send :"#{options[:format]}_subject", options, label, object
end

#subject_for_issue(issue, options) ⇒ Object



329
330
331
# File 'lib/redmine/helpers/gantt.rb', line 329

def subject_for_issue(issue, options)
  subject(issue.subject, options, issue)
end

#subject_for_project(project, options) ⇒ Object



302
303
304
# File 'lib/redmine/helpers/gantt.rb', line 302

def subject_for_project(project, options)
  subject(project.name, options, project)
end

#subject_for_version(version, options) ⇒ Object



314
315
316
# File 'lib/redmine/helpers/gantt.rb', line 314

def subject_for_version(version, options)
  subject(version.to_s_with_project, options, version)
end

#subjects(options = {}) ⇒ Object

Renders the subjects of the Gantt chart, the left side.



135
136
137
138
# File 'lib/redmine/helpers/gantt.rb', line 135

def subjects(options={})
  render(options.merge(:only => :subjects)) unless @subjects_rendered
  @subjects
end

#to_image(format = 'PNG') ⇒ Object

Generates a gantt image Only defined if MiniMagick is avalaible



376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
# File 'lib/redmine/helpers/gantt.rb', line 376

def to_image(format='PNG')
  date_to = (@date_from >> @months) - 1
  show_weeks = @zoom > 1
  show_days = @zoom > 2
  subject_width = 400
  header_height = 18
  # width of one day in pixels
  zoom = @zoom * 2
  g_width = (@date_to - @date_from + 1) * zoom
  g_height = 20 * number_of_rows + 30
  headers_height = (show_weeks ? 2 * header_height : header_height)
  height = g_height + headers_height
  # TODO: Remove rmagick_font_path in a later version
  unless Redmine::Configuration['rmagick_font_path'].nil?
    Rails.logger.warn(
      'rmagick_font_path option is deprecated. Use minimagick_font_path instead.'
    )
  end
  font_path =
    Redmine::Configuration['minimagick_font_path'].presence ||
      Redmine::Configuration['rmagick_font_path'].presence
  img = MiniMagick::Image.create(".#{format}")
  if Redmine::Configuration['imagemagick_convert_command'].present?
    MiniMagick.cli_path = File.dirname(Redmine::Configuration['imagemagick_convert_command'])
  end
  MiniMagick.convert do |gc|
    gc.size('%dx%d' % [subject_width + g_width + 1, height])
    gc.xc('white')
    gc.font(font_path) if font_path.present?
    # Subjects
    gc.stroke('transparent')
    subjects(:image => gc, :top => (headers_height + 20), :indent => 4, :format => :image)
    # Months headers
    month_f = @date_from
    left = subject_width
    @months.times do
      width = ((month_f >> 1) - month_f) * zoom
      gc.fill('white')
      gc.stroke('grey')
      gc.strokewidth(1)
      gc.draw('rectangle %d,%d %d,%d' % [
        left, 0, left + width, height
      ])
      gc.fill('black')
      gc.stroke('transparent')
      gc.strokewidth(1)
      gc.draw('text %d,%d %s' % [
        left.round + 8, 14, magick_text("#{month_f.year}-#{month_f.month}")
      ])
      left = left + width
      month_f = month_f >> 1
    end
    # Weeks headers
    if show_weeks
      left = subject_width
      height = header_height
      if @date_from.cwday == 1
        # date_from is monday
        week_f = date_from
      else
        # find next monday after date_from
        week_f = @date_from + (7 - @date_from.cwday + 1)
        width = (7 - @date_from.cwday + 1) * zoom
        gc.fill('white')
        gc.stroke('grey')
        gc.strokewidth(1)
        gc.draw('rectangle %d,%d %d,%d' % [
          left, header_height, left + width, 2 * header_height + g_height - 1
        ])
        left = left + width
      end
      while week_f <= date_to
        width = (week_f + 6 <= date_to) ? 7 * zoom : (date_to - week_f + 1) * zoom
        gc.fill('white')
        gc.stroke('grey')
        gc.strokewidth(1)
        gc.draw('rectangle %d,%d %d,%d' % [
          left.round, header_height, left.round + width, 2 * header_height + g_height - 1
        ])
        gc.fill('black')
        gc.stroke('transparent')
        gc.strokewidth(1)
        gc.draw('text %d,%d %s' % [
          left.round + 2, header_height + 14, magick_text(week_f.cweek.to_s)
        ])
        left = left + width
        week_f = week_f + 7
      end
    end
    # Days details (week-end in grey)
    if show_days
      left = subject_width
      height = g_height + header_height - 1
      (@date_from..date_to).each do |g_date|
        width =  zoom
        gc.fill(non_working_week_days.include?(g_date.cwday) ? '#eee' : 'white')
        gc.stroke('#ddd')
        gc.strokewidth(1)
        gc.draw('rectangle %d,%d %d,%d' % [
          left, 2 * header_height, left + width, 2 * header_height + g_height - 1
        ])
        left = left + width
      end
    end
    # border
    gc.fill('transparent')
    gc.stroke('grey')
    gc.strokewidth(1)
    gc.draw('rectangle %d,%d %d,%d' % [
      0, 0, subject_width + g_width, headers_height
    ])
    gc.stroke('black')
    gc.draw('rectangle %d,%d %d,%d' % [
      0, 0, subject_width + g_width, g_height + headers_height - 1
    ])
    # content
    top = headers_height + 20
    gc.stroke('transparent')
    lines(:image => gc, :top => top, :zoom => zoom,
          :subject_width => subject_width, :format => :image)
    # today red line
    if User.current.today >= @date_from and User.current.today <= date_to
      gc.stroke('red')
      x = (User.current.today - @date_from + 1) * zoom + subject_width
      gc.draw('line %g,%g %g,%g' % [
        x, headers_height, x, headers_height + g_height - 1
      ])
    end
    gc << img.path
  end
  img.to_blob
ensure
  img.destroy! if img
end

#to_pdfObject



511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
# File 'lib/redmine/helpers/gantt.rb', line 511

def to_pdf
  pdf = ::Redmine::Export::PDF::ITCPDF.new(current_language)
  pdf.SetTitle("#{l(:label_gantt)} #{project}")
  pdf.alias_nb_pages
  pdf.footer_date = format_date(User.current.today)
  pdf.AddPage("L")
  pdf.SetFontStyle('B', 12)
  pdf.SetX(15)
  pdf.RDMCell(PDF::LeftPaneWidth, 20, project.to_s)
  pdf.Ln
  pdf.SetFontStyle('B', 9)
  subject_width = PDF::LeftPaneWidth
  header_height = 5
  headers_height = header_height
  show_weeks = false
  show_days = false
  if self.months < 7
    show_weeks = true
    headers_height = 2 * header_height
    if self.months < 3
      show_days = true
      headers_height = 3 * header_height
      if self.months < 2
        show_day_num = true
        headers_height = 4 * header_height
      end
    end
  end
  g_width = PDF.right_pane_width
  zoom = g_width / (self.date_to - self.date_from + 1)
  g_height = 120
  t_height = g_height + headers_height
  y_start = pdf.GetY
  # Months headers
  month_f = self.date_from
  left = subject_width
  height = header_height
  self.months.times do
    width = ((month_f >> 1) - month_f) * zoom
    pdf.SetY(y_start)
    pdf.SetX(left)
    pdf.RDMCell(width, height, "#{month_f.year}-#{month_f.month}", "LTR", 0, "C")
    left = left + width
    month_f = month_f >> 1
  end
  # Weeks headers
  if show_weeks
    left = subject_width
    height = header_height
    if self.date_from.cwday == 1
      # self.date_from is monday
      week_f = self.date_from
    else
      # find next monday after self.date_from
      week_f = self.date_from + (7 - self.date_from.cwday + 1)
      width = (7 - self.date_from.cwday + 1) * zoom-1
      pdf.SetY(y_start + header_height)
      pdf.SetX(left)
      pdf.RDMCell(width + 1, height, "", "LTR")
      left = left + width + 1
    end
    while week_f <= self.date_to
      width = (week_f + 6 <= self.date_to) ? 7 * zoom : (self.date_to - week_f + 1) * zoom
      pdf.SetY(y_start + header_height)
      pdf.SetX(left)
      pdf.RDMCell(width, height, (width >= 5 ? week_f.cweek.to_s : ""), "LTR", 0, "C")
      left = left + width
      week_f = week_f + 7
    end
  end
  # Day numbers headers
  if show_day_num
    left = subject_width
    height = header_height
    day_num = self.date_from
    pdf.SetFontStyle('B', 7)
    (self.date_from..self.date_to).each do |g_date|
      width = zoom
      pdf.SetY(y_start + header_height * 2)
      pdf.SetX(left)
      pdf.SetTextColor(non_working_week_days.include?(g_date.cwday) ? 150 : 0)
      pdf.RDMCell(width, height, day_num.day.to_s, "LTR", 0, "C")
      left = left + width
      day_num = day_num + 1
    end
  end
  # Days headers
  if show_days
    left = subject_width
    height = header_height
    pdf.SetFontStyle('B', 7)
    (self.date_from..self.date_to).each do |g_date|
      width = zoom
      pdf.SetY(y_start + header_height * (show_day_num ? 3 : 2))
      pdf.SetX(left)
      pdf.SetTextColor(non_working_week_days.include?(g_date.cwday) ? 150 : 0)
      pdf.RDMCell(width, height, day_name(g_date.cwday).first, "LTR", 0, "C")
      left = left + width
    end
  end
  pdf.SetY(y_start)
  pdf.SetX(15)
  pdf.SetTextColor(0)
  pdf.RDMCell(subject_width + g_width - 15, headers_height, "", 1)
  # Tasks
  top = headers_height + y_start
  options = {
    :top => top,
    :zoom => zoom,
    :subject_width => subject_width,
    :g_width => g_width,
    :indent => 0,
    :indent_increment => 5,
    :top_increment => 5,
    :format => :pdf,
    :pdf => pdf
  }
  render(options)
  pdf.Output
end

#version_issues(project, version) ⇒ Object

Returns the issues that belong to project and are assigned to version



205
206
207
# File 'lib/redmine/helpers/gantt.rb', line 205

def version_issues(project, version)
  project_issues(project).select {|issue| issue.fixed_version == version}
end