1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 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
|
#!/usr/bin/env ruby -w
# encoding: UTF-8
#
# = ColumnTable.rb -- The TaskJuggler III Project Management Software
#
# Copyright (c) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014
# by Chris Schlaeger <cs@taskjuggler.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#
require 'taskjuggler/reports/ReportTable'
class TaskJuggler
# This class is essentially a wrapper around ReportTable that allows us to
# embed a ReportTable object as a column of another ReportTable object. Both
# ReportTables must have the same number of lines.
class ColumnTable < ReportTable
attr_writer :viewWidth
# Create a new ColumnTable object.
def initialize
super
# The user requested width of the column (chart)
@viewWidth = nil
# The header will have 2 lines. So, use a smaller font. This should match
# the font size used for the GanttChart header.
@headerFontSize = 10
# This is an embedded table.
@embedded = true
end
def to_html
height = 2 * @headerLineHeight + 1
@lines.each do |line|
# Add line height plus 1 pixel padding
height += line.height + 1
end
# Since we don't know the resulting width of the column, we need to always
# add an extra space for the scrollbar.
td = XMLElement.new('td', 'rowspan' => "#{2 + @lines.length + 1}",
'style' => 'padding:0px; vertical-align:top;')
# Now we generate a 'div' that will contain the nested table. It has a
# height that fits all lines but has a maximum width. In case the embedded
# table is larger, a scrollbar will appear. We assume that the scrollbar
# has a height of SCROLLBARHEIGHT pixels or less.
# If there is a user specified with, use it. Otherwise use the
# calculated minimum with.
width = @viewWidth ? @viewWidth : minWidth
td << (scrollDiv = XMLElement.new('div', 'class' => 'tabback',
'style' => 'position:relative; overflow:auto; ' +
"width:#{width}px; " +
'margin-top:-1px; margin-bottom:-1px; ' +
"height:#{height + SCROLLBARHEIGHT + 2}px;"))
scrollDiv << (contentDiv = XMLElement.new('div',
'style' => 'margin: 0px; padding: 0px; position: absolute; top: 0px;' +
"left: 0px; width: #{@viewWidth}px; height: #{height}px; "))
contentDiv << super
td
end
end
end
|