Parent

Class Index [+]

Quicksearch

TaskJuggler::GanttHeader

This class stores output format independent information to describe a GanttChart header. A Gantt chart header consists of 2 lines. The top line holds the large scale (e. g. the year or month and year) and the lower line holds the small scale (e. g. week or day).

Attributes

gridLines[R]
nowLineX[R]
cellStartDates[R]
height[RW]

Public Class Methods

new(chart) click to toggle source

Create a GanttHeader object and generate the scales for the header.

    # File lib/reports/GanttHeader.rb, line 27
27:     def initialize(chart)
28:       @chart = chart
29: 
30:       @largeScale = []
31:       @smallScale = []
32: 
33:       # Positions where chart should be marked with vertical lines that match
34:       # the large scale.
35:       @gridLines = []
36: 
37:       # X coordinate of the "now" line. nil if "now" is off-chart.
38:       @nowLineX = nil
39: 
40:       # The x coordinates and width of the cells created by the small scale. The
41:       # values are stored as [ x, w ].
42:       @cellStartDates = []
43:       # The height of the header in pixels.
44:       @height = 39
45: 
46:       generate
47:     end

Public Instance Methods

to_html() click to toggle source

Convert the header into an HTML format.

    # File lib/reports/GanttHeader.rb, line 50
50:     def to_html
51:       div = XMLElement.new('div', 'class' => 'tabback',
52:                            'style' => "margin:0px; padding:0px; " +
53:                            "position:relative; " +
54:                            "width:#{@chart.width.to_i}px; " +
55:                            "height:#{@height.to_i}px; " +
56:                            "font-size:#{(@height / 4).to_i}px; ")
57:       @largeScale.each { |s| div << s.to_html }
58:       @smallScale.each { |s| div << s.to_html }
59:       div
60:     end

Private Instance Methods

genHeaderScale(scale, y, h, beginOfFunc, sameTimeNextFunc, nameFunc) click to toggle source

Generate the actual scale cells.

     # File lib/reports/GanttHeader.rb, line 104
104:     def genHeaderScale(scale, y, h, beginOfFunc, sameTimeNextFunc, nameFunc)
105:       # The beginOfWeek function needs a parameter, so we have to handle it as a
106:       # special case.
107:       if beginOfFunc == :beginOfWeek
108:         t = @chart.start.send(beginOfFunc, @chart.weekStartsMonday)
109:       else
110:         t = @chart.start.send(beginOfFunc)
111:       end
112: 
113:       # Now we iterate of the report period in steps defined by
114:       # sameTimeNextFunc. For each time slot we generate GanttHeaderScaleItem
115:       # object and append it to the scale.
116:       while t < @chart.end
117:         nextT = t.send(sameTimeNextFunc)
118:         # Determine the end of the cell. We keep 1 pixel for the boundary.
119:         w = (xR = @chart.dateToX(nextT).to_i - 1) - (x = @chart.dateToX(t).to_i)
120:         # We collect the positions of the large grid scale marks for later use
121:         # in the chart.
122:         if scale == @largeScale
123:           @gridLines << xR
124:         else
125:           @cellStartDates << t
126:         end
127:         # Again, nameFunc needs special handling for the week case due to the
128:         # extra parameter.
129:         name = nameFunc == :week ? t.send(nameFunc, @chart.weekStartsMonday) :
130:                                    t.send(nameFunc)
131:         scale << GanttHeaderScaleItem.new(name, x, y, w, h)
132:         t = nextT
133:       end
134:       # Add the end date of the last cell when generating the small scale.
135:       @cellStartDates << t if scale == @smallScale
136:     end
generate() click to toggle source

Call genHeaderScale with the right set of parameters (depending on the selected scale) for the lower and upper header line.

     # File lib/reports/GanttHeader.rb, line 66
 66:     def generate
 67:       # The 2 header lines are separated by a 1 pixel boundary.
 68:       h = ((@height - 1) / 2).to_i
 69:       case @chart.scale['name']
 70:       when 'hour'
 71:         genHeaderScale(@largeScale, 0, h, :midnight, :sameTimeNextDay,
 72:                        :weekdayAndDate)
 73:         genHeaderScale(@smallScale, h + 1, h, :beginOfHour, :sameTimeNextHour,
 74:                        :hour)
 75:       when 'day'
 76:         genHeaderScale(@largeScale, 0, h, :beginOfMonth, :sameTimeNextMonth,
 77:                        :monthAndYear)
 78:         genHeaderScale(@smallScale, h + 1, h, :midnight, :sameTimeNextDay, :day)
 79:       when 'week'
 80:         genHeaderScale(@largeScale, 0, h, :beginOfMonth, :sameTimeNextMonth,
 81:                        :monthAndYear)
 82:         genHeaderScale(@smallScale, h + 1, h, :beginOfWeek, :sameTimeNextWeek,
 83:                        :week)
 84:       when 'month'
 85:         genHeaderScale(@largeScale, 0, h, :beginOfYear, :sameTimeNextYear, :year)
 86:         genHeaderScale(@smallScale, h + 1, h, :beginOfMonth, :sameTimeNextMonth,
 87:                        :shortMonthName)
 88:       when 'quarter'
 89:         genHeaderScale(@largeScale, 0, h, :beginOfYear, :sameTimeNextYear, :year)
 90:         genHeaderScale(@smallScale, h + 1, h, :beginOfQuarter,
 91:                        :sameTimeNextQuarter, :quarterName)
 92:       when 'year'
 93:         genHeaderScale(@smallScale, h + 1, h, :beginOfYear, :sameTimeNextYear,
 94:                        :year)
 95:       else
 96:         raise "Unknown scale: #{@chart.scale['name']}"
 97:       end
 98: 
 99:       nlx = @chart.dateToX(@chart.now)
100:       @nowLineX = nlx if nlx
101:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.