The GanttLoadStack is a simple stack diagram that shows the relative shares of the values. The stack is always normed to the line height.
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 28 28: def initialize(line, x, w, values, categories) 29: @line = line 30: @lineHeight = line.height 31: @x = x 32: @y = @line.y 33: @w = w 34: @drawFrame = false 35: if values.length != categories.length 36: raise "Values and categories must have the same number of entries!" 37: end 38: @categories = categories 39: i = 0 40: @categories.each do |cat| 41: if cat.nil? && values[i] > 0 42: @drawFrame = true 43: break 44: end 45: i += 1 46: end 47: 48: # Convert the values to chart Y coordinates and store them in yLevels. 49: sum = 0 50: values.each { |v| sum += v } 51: # If the sum is 0, all yLevels values must be 0 as well. 52: if sum == 0 53: @yLevels = nil 54: @drawFrame = true 55: else 56: @yLevels = [] 57: values.each do |v| 58: # We leave 1 pixel to the top and bottom of the line and need 1 pixel 59: # for the frame. 60: @yLevels << (@lineHeight - 4) * v / sum 61: end 62: end 63: end
# File lib/reports/GanttLoadStack.rb, line 65 65: def addBlockedZones(router) 66: # Horizontal block 67: router.addZone(@x - 2, @y, @w + 4, @lineHeight, true, false) 68: end
Convert the abstact representation of the GanttLoadStack into HTML elements.
# File lib/reports/GanttLoadStack.rb, line 72 72: def to_html 73: # Draw nothing if all values are 0. 74: return nil unless @yLevels 75: 76: html = [] 77: # Draw a background rectable to create a frame. In case the frame is not 78: # fully filled by the stack, we need to draw a real frame to keep the 79: # background. 80: if @drawFrame 81: # Top frame line 82: html << @line.lineToHTML(@x, 1, @x + @w - 1, 1, 'loadstackframe') 83: # Bottom frame line 84: html << @line.lineToHTML(@x, @lineHeight - 2, @x + @w - 1, 85: @lineHeight - 2, 'loadstackframe') 86: # Left frame line 87: html << @line.lineToHTML(@x, 1, @x, @lineHeight - 2, 'loadstackframe') 88: # Right frame line 89: html << @line.lineToHTML(@x + @w - 1, 1, @x + @w - 1, @lineHeight - 2, 90: 'loadstackframe') 91: else 92: html << @line.rectToHTML(@x, 1, @w, @lineHeight - 2, 93: 'loadstackframe') 94: end 95: 96: yPos = 2 97: # Than draw the slighly narrower bars as a pile ontop of it. 98: (@yLevels.length - 1).downto(0) do |i| 99: next if @yLevels[i] <= 0 100: if @categories[i] 101: html << @line.rectToHTML(@x + 1, yPos.to_i, @w - 2, 102: (yPos + @yLevels[i]).to_i - yPos.to_i, 103: @categories[i]) 104: end 105: yPos += @yLevels[i] 106: end 107: 108: html 109: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.