class TaskJuggler::ChartPlotter

Public Class Methods

new(width, height, data) click to toggle source
# File lib/taskjuggler/reports/ChartPlotter.rb, line 23
def initialize(width, height, data)
  # +------------------------------------------------
  # |             ^
  # |   topMargin |             legendGap
  # |             v             <->
  # |              |               -x- foo
  # |<-leftMargin->|               -x- bar
  # |              |               <-legend
  # |              |                 Width---->
  # |              +------------
  # |             ^             <-rightMargin->
  # | bottomMargin|
  # |             v
  # +------------------------------------------------
  # <-----------------canvasWidth-------------------->
  # The width of the canvas area
  @width = width
  # The height of the canvas area
  @height = height
  # The raw data to plot as loaded from the CSV file.
  @data = data

  # The margins between the graph plotting area and the canvas borders.
  @topMargin = 30
  @bottomMargin = 30
  @leftMargin = 70
  @rightMargin = (@width * 0.382).to_i

  @legendGap = 20
  @markerWidth = 20
  @markerX = @width - @rightMargin + @legendGap
  @markerGap = 5
  @labelX = @markerX + @markerWidth + @markerGap
  @labelHeight = 24

  # The location of the 0/0 point of the graph plotter.
  @x0 = @leftMargin
  @y0 = @height - @bottomMargin

  @labels = []
  @yData = []
  @xData = nil
  @dataType = nil
  @xMinDate = nil
  @xMaxDate = nil
  @yMinDate = nil
  @yMaxDate = nil
  @yMinVal = nil
  @yMaxVal = nil
end

Public Instance Methods

generate() click to toggle source

Create the chart as Painter object.

# File lib/taskjuggler/reports/ChartPlotter.rb, line 75
def generate
  analyzeData
  calcChartGeometry
  @painter = Painter.new(@width, @height) do |pa|
    drawGrid(pa)
    0.upto(@yData.length - 1) do |ci|
      # Compute a unique and distinguishable color for each data set. We
      # primarily use the hue value of the HSV color space for this. It
      # has 6 main colors each 60 degrees apart from each other. After the
      # first 360 round, we shift the angle by 60 / round so we get a
      # different color set than in the previous round. Additionally, the
      # saturation is decreased with each data set.
      color = Painter::Color.new(
        (60 * (ci % 6) + (60 / (1 + ci / 6))) % 360,
        255 - (ci / 8), 230, :hsv)

      drawDataGraph(pa, ci, color)
      drawLegendEntry(pa, ci, color)
    end
  end
end
to_svg() click to toggle source
# File lib/taskjuggler/reports/ChartPlotter.rb, line 97
def to_svg
  @painter.to_svg
end