Class: TaskJuggler::GanttLoadStack
- Includes:
- HTMLGraphics
- Defined in:
- lib/taskjuggler/reports/GanttLoadStack.rb
Overview
The GanttLoadStack is a simple stack diagram that shows the relative shares of the values. The stack is always normed to the line height.
Instance Method Summary collapse
- #addBlockedZones(router) ⇒ Object
-
#initialize(line, x, w, values, categories) ⇒ GanttLoadStack
constructor
Create a GanttLoadStack object based on the following information: line is a reference to the GanttLine.
-
#to_html ⇒ Object
Convert the abstact representation of the GanttLoadStack into HTML elements.
Methods included from HTMLGraphics
#arrowHeadToHTML, #diamondToHTML, #jagToHTML, #lineToHTML, #rectToHTML
Constructor Details
#initialize(line, x, w, values, categories) ⇒ GanttLoadStack
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.
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 |
# File 'lib/taskjuggler/reports/GanttLoadStack.rb', line 28 def initialize(line, x, w, values, categories) @line = line @lineHeight = line.height @x = x @y = @line.y @w = w <= 0 ? 1 : w @drawFrame = false if values.length != categories.length raise "Values and categories must have the same number of entries!" end @categories = categories i = 0 @categories.each do |cat| if cat.nil? && values[i] > 0 @drawFrame = true break end i += 1 end # Convert the values to chart Y coordinates and store them in yLevels. sum = 0 values.each { |v| sum += v } # If the sum is 0, all yLevels values must be 0 as well. if sum == 0 @yLevels = nil @drawFrame = true else @yLevels = [] values.each do |v| # We leave 1 pixel to the top and bottom of the line and need 1 pixel # for the frame. @yLevels << (@lineHeight - 4) * v / sum end end end |
Instance Method Details
#addBlockedZones(router) ⇒ Object
65 66 67 68 |
# File 'lib/taskjuggler/reports/GanttLoadStack.rb', line 65 def addBlockedZones(router) # Horizontal block router.addZone(@x - 2, @y, @w + 4, @lineHeight, true, false) end |
#to_html ⇒ Object
Convert the abstact representation of the GanttLoadStack into HTML elements.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/taskjuggler/reports/GanttLoadStack.rb', line 72 def to_html # Draw nothing if all values are 0. return nil unless @yLevels html = [] # Draw a background rectable to create a frame. In case the frame is not # fully filled by the stack, we need to draw a real frame to keep the # background. if @drawFrame # Top frame line html << @line.lineToHTML(@x, 1, @x + @w - 1, 1, 'loadstackframe') # Bottom frame line html << @line.lineToHTML(@x, @lineHeight - 2, @x + @w - 1, @lineHeight - 2, 'loadstackframe') # Left frame line html << @line.lineToHTML(@x, 1, @x, @lineHeight - 2, 'loadstackframe') # Right frame line html << @line.lineToHTML(@x + @w - 1, 1, @x + @w - 1, @lineHeight - 2, 'loadstackframe') else html << @line.rectToHTML(@x, 1, @w, @lineHeight - 2, 'loadstackframe') end yPos = 2 # Than draw the slighly narrower bars as a pile ontop of it. (@yLevels.length - 1).downto(0) do |i| next if @yLevels[i] <= 0 if @categories[i] html << @line.rectToHTML(@x + 1, yPos.to_i, @w - 2, (yPos + @yLevels[i]).to_i - yPos.to_i, @categories[i]) end yPos += @yLevels[i] end html end |