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.
Create a new ReportTableLegend object.
# File lib/reports/ReportTableLegend.rb, line 23 23: def initialize 24: @showGanttItems = false 25: @ganttItems = [] 26: @calendarItems = [] 27: end
Add another chart item to the legend. Make sure we don’t have any duplicates.
# File lib/reports/ReportTableLegend.rb, line 37 37: def addCalendarItem(text, color) 38: unless @calendarItems.include?([ text, color ]) 39: @calendarItems << [ text, color ] 40: end 41: end
Add another Gantt item to the legend. Make sure we don’t have any duplicates.
# File lib/reports/ReportTableLegend.rb, line 31 31: def addGanttItem(text, color) 32: @ganttItems << [ text, color ] unless @ganttItems.include?([ text, color ]) 33: end
Convert the abstract description into HTML elements.
# File lib/reports/ReportTableLegend.rb, line 44 44: def to_html 45: return nil if !@showGanttItems && @ganttItems.empty? && 46: @calendarItems.empty? 47: 48: frame = XMLElement.new('div', 'class' => 'tj_table_legend_frame') 49: frame << (legend = XMLElement.new('table', 'class' => 'tj_table_legend', 50: 'cellspacing' => '1')) 51: 52: legend << headlineToHTML('Gantt Chart Symbols:') 53: # Generate the Gantt chart symbols 54: if @showGanttItems 55: legend << (row = XMLElement.new('tr', 'class' => 'tj_legend_row')) 56: 57: row << ganttItemToHTML(GanttContainer.new(nil, 0, 15, 10, 35, 0), 58: 'Container Task', 40) 59: row << ganttItemToHTML(GanttTaskBar.new(nil, 0, 15, 5, 35, 0), 60: 'Normal Task', 40) 61: row << ganttItemToHTML(GanttMilestone.new(nil, 15, 10, 0), 62: 'Milestone', 20) 63: row << XMLElement.new('td', 'class' => 'tj_legend_spacer') 64: end 65: 66: legend << itemsToHTML(@ganttItems) 67: 68: legend << headlineToHTML('Calendar Symbols:') 69: legend << itemsToHTML(@calendarItems) 70: 71: frame 72: end
Turn the Gantt symbold descriptions into HTML elements.
# File lib/reports/ReportTableLegend.rb, line 90 90: def ganttItemToHTML(itemRef, name, width) 91: cells = [] 92: # Empty cell for margin first. 93: cells << (item = XMLElement.new('td', 'class' => 'tj_legend_spacer')) 94: # The symbol cell 95: cells << (item = XMLElement.new('td', 'class' => 'tj_legend_item')) 96: item << (symbol = XMLElement.new('div', 'class' => 'tj_legend_symbol', 97: 'style' => 'top:3px')) 98: symbol << itemRef.to_html 99: # The label cell 100: cells << (item = XMLElement.new('td', 'class' => 'tj_legend_item')) 101: item << (label = XMLElement.new('div', 'class' => 'tj_legend_label')) 102: label << XMLText.new(name) 103: 104: cells 105: end
In case we have both the calendar and the Gantt chart in the report element, we have to add description lines before the symbols. The two charts use the same colors for different meanings. This function generates the HTML version of the headlines.
# File lib/reports/ReportTableLegend.rb, line 80 80: def headlineToHTML(text) 81: unless @calendarItems.empty? || @ganttItems.empty? 82: div = XMLElement.new('tr', 'class' => 'tj_legend_headline') 83: div << XMLNamedText.new(text, 'td', 'colspan' => '10') 84: return div 85: end 86: nil 87: end
Turn a single color item into HTML elements.
# File lib/reports/ReportTableLegend.rb, line 108 108: def itemToHTML(itemRef) 109: cells = [] 110: # Empty cell for margin first. 111: cells << XMLElement.new('td', 'class' => 'tj_legend_spacer') 112: # The symbol cell 113: cells << (item = XMLElement.new('td', 'class' => 'tj_legend_item')) 114: item << (symbol = XMLElement.new('div', 'class' => 'tj_legend_symbol')) 115: symbol << (box = XMLElement.new('div', 116: 'style' => 'position:relative; ' + 117: 'top:2px;' + 118: 'width:20px; height:15px')) 119: box << (div = XMLElement.new('div', 'class' => 'loadstackframe', 120: 'style' => 'position:absolute; ' + 121: 'left:5px; width:16px; height:15px;')) 122: div << XMLElement.new('div', 'class' => "#{itemRef[1]}", 123: 'style' => 'position:absolute; ' + 124: 'left:1px; top:1px; ' + 125: 'width:14px; height:13px;') 126: # The label cell 127: cells << (item = XMLElement.new('td', 'class' => 'tj_legend_item')) 128: item << (label = XMLElement.new('div', 'class' => 'tj_legend_label')) 129: label << XMLText.new(itemRef[0]) 130: 131: cells 132: end
Turn the color items into HTML elements.
# File lib/reports/ReportTableLegend.rb, line 135 135: def itemsToHTML(items) 136: rows = [] 137: row = nil 138: gridCells = ((items.length / 3) + (items.length % 3 != 0 ? 1 : 0)) * 3 139: gridCells.times do |i| 140: # We show no more than 3 items in a row. 141: if i % 3 == 0 142: rows << (row = XMLElement.new('tr', 'class' => 'tj_legend_row')) 143: end 144: 145: # If we run out of items before the line is filled, we just insert 146: # empty cells to fill the line. 147: if i < items.length 148: row << itemToHTML(items[i]) 149: else 150: row << XMLElement.new('td', 'class' => 'tj_legend_item', 151: 'colspan' => '3') 152: end 153: if (i + 1) % 3 == 0 154: # Append an empty cell at the end of each row. 155: row << XMLElement.new('td', 'class' => 'tj_legend_spacer') 156: end 157: end 158: rows 159: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.