Class: TaskJuggler::ChartPlotter
- Defined in:
- lib/taskjuggler/reports/ChartPlotter.rb
Instance Method Summary collapse
-
#generate ⇒ Object
Create the chart as Painter object.
-
#initialize(width, height, data) ⇒ ChartPlotter
constructor
A new instance of ChartPlotter.
- #to_svg ⇒ Object
Constructor Details
#initialize(width, height, data) ⇒ ChartPlotter
Returns a new instance of ChartPlotter.
23 24 25 26 27 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 64 65 66 67 68 69 70 71 72 |
# 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 |
Instance Method Details
#generate ⇒ Object
Create the chart as Painter object.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# 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 ⇒ Object
97 98 99 |
# File 'lib/taskjuggler/reports/ChartPlotter.rb', line 97 def to_svg @painter.to_svg end |