Parent

Class Index [+]

Quicksearch

TaskJuggler::ReportTable

This class models the intermediate format of all report tables. The generators for all the table reports create the report in this intermediate format. The to_* member functions can then output the table in the appropriate format.

Constants

SCROLLBARHEIGHT

The height in pixels of a horizontal scrollbar on an HTML page. This value should be large enough to work for all browsers.

Attributes

maxIndent[R]
headerLineHeight[R]
headerFontSize[R]
equiLines[RW]
embedded[RW]

Public Class Methods

new() click to toggle source

Create a new ReportTable object.

    # File lib/taskjuggler/reports/ReportTable.rb, line 33
33:     def initialize
34:       # The height if the header lines in screen pixels.
35:       @headerLineHeight = 19
36:       # Size of the font used in the header
37:       @headerFontSize = 15
38:       # Array of ReportTableColumn objects.
39:       @columns = []
40:       # Array of ReportTableLine objects.
41:       @lines = []
42:       @maxIndent = 0
43:       # Whether or not all table lines must have same height.
44:       @equiLines = false
45:       # True if the table is embedded as a column of another ReportTable.
46:       @embedded = false
47:     end

Public Instance Methods

addColumn(col) click to toggle source

This function should only be called by the ReportTableColumn constructor.

    # File lib/taskjuggler/reports/ReportTable.rb, line 50
50:     def addColumn(col)
51:       @columns << col
52:     end
addLine(line) click to toggle source

This function should only be called by the ReportTableLine constructor.

    # File lib/taskjuggler/reports/ReportTable.rb, line 55
55:     def addLine(line)
56:       @lines << line
57:     end
lines() click to toggle source

Return the number of registered lines for this table.

    # File lib/taskjuggler/reports/ReportTable.rb, line 60
60:     def lines
61:       @lines.length
62:     end
minWidth() click to toggle source

Return the minimum required width for the table. If we don’t have a mininum with, nil is returned.

    # File lib/taskjuggler/reports/ReportTable.rb, line 66
66:     def minWidth
67:       width = 1
68:       @columns.each do |column|
69:         cw = column.minWidth
70:         width += cw + 1 if cw
71:       end
72:       width
73:     end
to_csv(csv = [[ ]], startColumn = 0) click to toggle source

Convert the intermediate representation into an Array of Arrays. csv is the destination Array of Arrays. It may contain columns already.

     # File lib/taskjuggler/reports/ReportTable.rb, line 135
135:     def to_csv(csv = [[ ]], startColumn = 0)
136:       # Generate the header line.
137:       columnIdx = startColumn
138:       @columns.each do |col|
139:         columnIdx += col.to_csv(csv, columnIdx)
140:       end
141: 
142:       if @embedded
143:         columnIdx - startColumn
144:       else
145:         # Content of embedded tables is inserted when generating the
146:         # respective Line.
147:         lineIdx = 1
148:         @lines.each do |line|
149:           # Insert a new Array for each line.
150:           csv[lineIdx] = []
151:           line.to_csv(csv, startColumn, lineIdx)
152:           lineIdx += 1
153:         end
154:         csv
155:       end
156:     end
to_html() click to toggle source

Output the table as HTML.

     # File lib/taskjuggler/reports/ReportTable.rb, line 76
 76:     def to_html
 77:       determineMaxIndents
 78: 
 79:       attr = { 'class' => 'tj_table',
 80:                'cellspacing' => '1' }
 81:       attr['style'] = 'width:100%; ' if @embedded
 82:       table = XMLElement.new('table', attr)
 83:       table << (tbody = XMLElement.new('tbody'))
 84: 
 85:       # Generate the 1st table header line.
 86:       allCellsHave2Rows = true
 87:       lineHeight = @headerLineHeight
 88:       @columns.each do |col|
 89:         if col.cell1.rows != 2 && !col.cell1.special
 90:           allCellsHave2Rows = false
 91:           break;
 92:         end
 93:       end
 94:       if allCellsHave2Rows
 95:         @columns.each { |col| col.cell1.rows = 1 }
 96:         lineHeight = @headerLineHeight * 2 + 1
 97:       end
 98: 
 99:       tbody << (tr =
100:                 XMLElement.new('tr', 'class' => 'tabhead',
101:                                'style' => "height:#{lineHeight}px; " +
102:                                           "font-size:#{@headerFontSize}px;"))
103:       @columns.each { |col| tr << col.to_html(1) }
104: 
105:       unless allCellsHave2Rows
106:         # Generate the 2nd table header line.
107:         tbody << (tr =
108:                   XMLElement.new('tr', 'class' => 'tabhead',
109:                                  'style' => "height:#{@headerLineHeight}px; " +
110:         "font-size:#{@headerFontSize}px;"))
111:         @columns.each { |col| tr << col.to_html(2) }
112:       end
113: 
114:       # Generate the rest of the table.
115:       @lines.each { |line| tbody << line.to_html }
116: 
117:       # In case we have columns with scrollbars, we generate an extra line with
118:       # cells for all columns that don't have a scrollbar. The scrollbar must
119:       # have a height of SCROLLBARHEIGHT pixels or less.
120:       if hasScrollbar?
121:         tbody << (tr = XMLElement.new('tr',
122:                                       'style' => "height:#{SCROLLBARHEIGHT}px"))
123:         @columns.each do |column|
124:           unless column.scrollbar
125:             tr << XMLElement.new('td')
126:           end
127:         end
128:       end
129: 
130:       table
131:     end

Private Instance Methods

determineMaxIndents() click to toggle source

Some columns need to be indented when the data is sorted in tree mode. This function determines the largest needed indentation of all lines. The result is stored in the _@maxIndent_ variable.

     # File lib/taskjuggler/reports/ReportTable.rb, line 163
163:     def determineMaxIndents
164:       @maxIndent = 0
165:       @lines.each do |line|
166:         @maxIndent = line.indentation if line.indentation > @maxIndent
167:       end
168:     end
hasScrollbar?() click to toggle source

Returns true if any of the columns has a scrollbar.

     # File lib/taskjuggler/reports/ReportTable.rb, line 171
171:     def hasScrollbar?
172:       @columns.each { |col| return true if col.scrollbar }
173:       false
174:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.