Class: TaskJuggler::ReportTableLegend

Inherits:
Object
  • Object
show all
Defined in:
lib/taskjuggler/reports/ReportTableLegend.rb

Overview

The ReportTableLegend models an output format independent legend for the ReportTable. It lists the graphical symbols used in the table together with a short textual description.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeReportTableLegend

Create a new ReportTableLegend object.



24
25
26
27
28
# File 'lib/taskjuggler/reports/ReportTableLegend.rb', line 24

def initialize
  @showGanttItems = false
  @ganttItems = []
  @calendarItems = []
end

Instance Attribute Details

#showGanttItemsObject

Returns the value of attribute showGanttItems.



21
22
23
# File 'lib/taskjuggler/reports/ReportTableLegend.rb', line 21

def showGanttItems
  @showGanttItems
end

Instance Method Details

#addCalendarItem(text, color) ⇒ Object

Add another chart item to the legend. Make sure we don’t have any duplicates.



38
39
40
41
42
# File 'lib/taskjuggler/reports/ReportTableLegend.rb', line 38

def addCalendarItem(text, color)
  unless @calendarItems.include?([ text, color ])
    @calendarItems << [ text, color ]
  end
end

#addGanttItem(text, color) ⇒ Object

Add another Gantt item to the legend. Make sure we don’t have any duplicates.



32
33
34
# File 'lib/taskjuggler/reports/ReportTableLegend.rb', line 32

def addGanttItem(text, color)
  @ganttItems << [ text, color ] unless @ganttItems.include?([ text, color ])
end

#to_htmlObject

Convert the abstract description into HTML elements.



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/taskjuggler/reports/ReportTableLegend.rb', line 45

def to_html
  return nil if !@showGanttItems && @ganttItems.empty? &&
                @calendarItems.empty?

  frame = XMLElement.new('div', 'class' => 'tj_table_legend_frame')
  frame << (legend = XMLElement.new('table', 'class' => 'tj_table_legend',
                                             'cellspacing' => '1'))

  legend << headlineToHTML('Gantt Chart Symbols:')
  # Generate the Gantt chart symbols
  if @showGanttItems
    legend << (row = XMLElement.new('tr', 'class' => 'tj_legend_row'))

    row << ganttItemToHTML(GanttContainer.new(15, 10, 35, 0),
                           'Container Task', 40)
    row << ganttItemToHTML(GanttTaskBar.new(nil, 15, 5, 35, 0),
                           'Normal Task', 40)
    row << ganttItemToHTML(GanttMilestone.new(15, 10, 0), 'Milestone', 20)
    row << XMLElement.new('td', 'class' => 'tj_legend_spacer')
  end

  legend << itemsToHTML(@ganttItems)

  legend << headlineToHTML('Calendar Symbols:')
  legend << itemsToHTML(@calendarItems)

  frame
end