lib/reports/ReportTableLegend.rb in taskjuggler-0.0.4 vs lib/reports/ReportTableLegend.rb in taskjuggler-0.0.5

- old
+ new

@@ -43,123 +43,120 @@ # Convert the abstract description into HTML elements. def to_html return nil if !@showGanttItems && @ganttItems.empty? && @calendarItems.empty? - table = XMLElement.new('table', 'class' => 'legendback', - 'style' => 'width:100%', 'border' => '0', - 'cellspacing' => '1', 'align' => 'center') - table << (tbody = XMLElement.new('tbody')) - tbody << (tr = XMLElement.new('tr')) + frame = XMLElement.new('div', 'class' => 'tj_table_legend_frame') + frame << (legend = XMLElement.new('table', 'class' => 'tj_table_legend', + 'cellspacing' => '1')) - # Empty line to create a bit of a vertical gap. - tr << XMLElement.new('td', 'colspan' => '8', 'style' => 'height:5px') - - tbody << headlineToHTML('Gantt Chart Symbols:') + legend << headlineToHTML('Gantt Chart Symbols:') # Generate the Gantt chart symbols if @showGanttItems - tbody << (tr = XMLElement.new('tr')) + legend << (row = XMLElement.new('tr', 'class' => 'tj_legend_row')) - tr << ganttItemToHTML(GanttContainer.new(nil, 0, 15, 10, 35, 0), - 'Container Task', 40) - tr << spacerToHTML(8) - tr << ganttItemToHTML(GanttTaskBar.new(nil, 0, 15, 5, 35, 0), - 'Normal Task', 40) - tr << spacerToHTML - tr << ganttItemToHTML(GanttMilestone.new(nil, 15, 10, 0), - 'Milestone', 20) + row << ganttItemToHTML(GanttContainer.new(nil, 0, 15, 10, 35, 0), + 'Container Task', 40) + row << ganttItemToHTML(GanttTaskBar.new(nil, 0, 15, 5, 35, 0), + 'Normal Task', 40) + row << ganttItemToHTML(GanttMilestone.new(nil, 15, 10, 0), + 'Milestone', 20) + row << XMLElement.new('td', 'class' => 'tj_legend_spacer') end - tbody << itemsToHTML(@ganttItems) + legend << itemsToHTML(@ganttItems) - tbody << headlineToHTML('Calendar Symbols:') - tbody << itemsToHTML(@calendarItems) + legend << headlineToHTML('Calendar Symbols:') + legend << itemsToHTML(@calendarItems) - # Empty line to create a bit of a vertical gap. - tbody << (tr = XMLElement.new('tr')) - tr << XMLElement.new('td', 'colspan' => '8', 'style' => 'height:5px') - - table + frame end private # 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. def headlineToHTML(text) - tbody = [] unless @calendarItems.empty? || @ganttItems.empty? - tbody << (tr = XMLElement.new('tr')) - tr << (td = XMLElement.new('td', 'colspan' => '8', - 'style' => 'font-weight:bold; ' + - 'padding-left:10px')) - td << XMLText.new(text) - else - nil + div = XMLElement.new('tr', 'class' => 'tj_legend_headline') + div << XMLNamedText.new(text, 'td', 'colspan' => '10') + return div end - tbody + nil end # Turn the Gantt symbold descriptions into HTML elements. - def ganttItemToHTML(item, name, width) - tr = [] - tr << (td = XMLElement.new('td', 'style' => 'width:19%; ' + - 'padding-left:10px; ')) - td << XMLText.new(name) - tr << (td = XMLElement.new('td', 'style' => 'width:8%')) - td << (div = XMLElement.new('div', - 'style' => "position:relative; width:#{width}px; height:15px;")) - div << item.to_html - tr + def ganttItemToHTML(itemRef, name, width) + cells = [] + # Empty cell for margin first. + cells << (item = XMLElement.new('td', 'class' => 'tj_legend_spacer')) + # The symbol cell + cells << (item = XMLElement.new('td', 'class' => 'tj_legend_item')) + item << (symbol = XMLElement.new('div', 'class' => 'tj_legend_symbol', + 'style' => 'top:3px')) + symbol << itemRef.to_html + # The label cell + cells << (item = XMLElement.new('td', 'class' => 'tj_legend_item')) + item << (label = XMLElement.new('div', 'class' => 'tj_legend_label')) + label << XMLText.new(name) + + cells end + # Turn a single color item into HTML elements. + def itemToHTML(itemRef) + cells = [] + # Empty cell for margin first. + cells << XMLElement.new('td', 'class' => 'tj_legend_spacer') + # The symbol cell + cells << (item = XMLElement.new('td', 'class' => 'tj_legend_item')) + item << (symbol = XMLElement.new('div', 'class' => 'tj_legend_symbol')) + symbol << (box = XMLElement.new('div', + 'style' => 'position:relative; ' + + 'top:2px;' + + 'width:20px; height:15px')) + box << (div = XMLElement.new('div', 'class' => 'loadstackframe', + 'style' => 'position:absolute; ' + + 'left:5px; width:16px; height:15px;')) + div << XMLElement.new('div', 'class' => "#{itemRef[1]}", + 'style' => 'position:absolute; ' + + 'left:1px; top:1px; ' + + 'width:14px; height:13px;') + # The label cell + cells << (item = XMLElement.new('td', 'class' => 'tj_legend_item')) + item << (label = XMLElement.new('div', 'class' => 'tj_legend_label')) + label << XMLText.new(itemRef[0]) + + cells + end + # Turn the color items into HTML elements. def itemsToHTML(items) - tbody = [] - + rows = [] + row = nil gridCells = ((items.length / 3) + (items.length % 3 != 0 ? 1 : 0)) * 3 - tr = nil gridCells.times do |i| # We show no more than 3 items in a row. - tbody << (tr = XMLElement.new('tr')) if i % 3 == 0 + if i % 3 == 0 + rows << (row = XMLElement.new('tr', 'class' => 'tj_legend_row')) + end # If we run out of items before the line is filled, we just insert - # spacers to fill the line. + # empty cells to fill the line. if i < items.length - tr << itemToHTML(items[i]) + row << itemToHTML(items[i]) else - tr << spacerToHTML(19) - tr << spacerToHTML(8) + row << XMLElement.new('td', 'class' => 'tj_legend_item', + 'colspan' => '3') end - tr << spacerToHTML() if i % 3 != 2 + if (i + 1) % 3 == 0 + # Append an empty cell at the end of each row. + row << XMLElement.new('td', 'class' => 'tj_legend_spacer') + end end - - tbody - end - - # Turn a single color item into HTML elements. - def itemToHTML(item) - tr = [] - tr << (td = XMLElement.new('td', 'style' => 'width:19%; ' + - 'padding-left:10px; ')) - td << XMLText.new(item[0]) - tr << (td = XMLElement.new('td', 'style' => 'width:8%')) - td << (div = XMLElement.new('div', 'style' => 'position:relative; ' + - 'width:20px; height:15px') - div << XMLElement.new('div', 'class' => 'loadstackframe', - 'style' => 'position:absolute; ' + - 'left:5px; width:16px; height:15px;') - div << XMLElement.new('div', 'class' => "#{item[1]}", - 'style' => 'position:absolute; left:1px; top:1px; ' + - 'width:14px; height:13px;')) - tr - end - - # Generate an empty HTML cell. _width_ is the requested width in pixels. - def spacerToHTML(width = 9) - XMLElement.new('td', 'style' => "width:#{width}%") + rows end end end