Parent

Included Modules

Files

Class Index [+]

Quicksearch

TaskJuggler::GanttLoadStack

The GanttLoadStack is a simple stack diagram that shows the relative shares of the values. The stack is always normed to the line height.

Public Class Methods

new(line, x, w, values, categories) click to toggle source

Create a GanttLoadStack object based on the following information: line is a reference to the GanttLine. x is the left edge in chart coordinates and w is the stack width. values are the values to be displayed and categories determines the color for each of the values.

    # File lib/reports/GanttLoadStack.rb, line 27
27:     def initialize(line, x, w, values, categories)
28:       @line = line
29:       @lineHeight = line.height
30:       @x = x
31:       @y = @line.y
32:       @w = w
33:       @drawFrame = false
34:       if values.length != categories.length
35:         raise "Values and categories must have the same number of entries!"
36:       end
37:       @categories = categories
38:       i = 0
39:       @categories.each do |cat|
40:         if cat.nil? && values[i] > 0
41:           @drawFrame = true
42:           break
43:         end
44:         i += 1
45:       end
46: 
47:       # Convert the values to chart Y coordinates and store them in yLevels.
48:       sum = 0
49:       values.each { |v| sum += v }
50:       # If the sum is 0, all yLevels values must be 0 as well.
51:       if sum == 0
52:         @yLevels = nil
53:         @drawFrame = true
54:       else
55:         @yLevels = []
56:         values.each do |v|
57:           # We leave 1 pixel to the top and bottom of the line and need 1 pixel
58:           # for the frame.
59:           @yLevels << (@lineHeight - 4) * v / sum
60:         end
61:       end
62:     end

Public Instance Methods

addBlockedZones(router) click to toggle source
    # File lib/reports/GanttLoadStack.rb, line 64
64:     def addBlockedZones(router)
65:       # Horizontal block
66:       router.addZone(@x - 2, @y, @w + 4, @lineHeight, true, false)
67:     end
to_html() click to toggle source

Convert the abstact representation of the GanttLoadStack into HTML elements.

     # File lib/reports/GanttLoadStack.rb, line 71
 71:     def to_html
 72:       # Draw nothing if all values are 0.
 73:       return nil unless @yLevels
 74: 
 75:       html = []
 76:       # Draw a background rectable to create a frame. In case the frame is not
 77:       # fully filled by the stack, we need to draw a real frame to keep the
 78:       # background.
 79:       if @drawFrame
 80:         # Top frame line
 81:         html << @line.lineToHTML(@x, 1, @x + @w - 1, 1, 'loadstackframe')
 82:         # Bottom frame line
 83:         html << @line.lineToHTML(@x, @lineHeight - 2, @x + @w - 1,
 84:                                  @lineHeight - 2, 'loadstackframe')
 85:         # Left frame line
 86:         html << @line.lineToHTML(@x, 1, @x, @lineHeight - 2, 'loadstackframe')
 87:         # Right frame line
 88:         html << @line.lineToHTML(@x + @w - 1, 1, @x + @w - 1, @lineHeight - 2,
 89:                                  'loadstackframe')
 90:       else
 91:         html << @line.rectToHTML(@x, 1, @w, @lineHeight - 2,
 92:                                  'loadstackframe')
 93:       end
 94: 
 95:       yPos = 2
 96:       # Than draw the slighly narrower bars as a pile ontop of it.
 97:       (@yLevels.length - 1).downto(0) do |i|
 98:         next if @yLevels[i] <= 0
 99:         if @categories[i]
100:           html << @line.rectToHTML(@x + 1, yPos.to_i, @w - 2,
101:                                    (yPos + @yLevels[i]).to_i - yPos.to_i,
102:                                    @categories[i])
103:         end
104:         yPos += @yLevels[i]
105:       end
106: 
107:       html
108:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.