class Scruffy::Layers::MultiArea

Scruffy::Layers::MulitArea

Author

Martyn Taylor

Date

July 30th 2010

Multi Area graph.

Attributes

area_colors[RW]
baselines[RW]

Public Class Methods

new(options = {}, &block) click to toggle source
# File lib/scruffy/layers/multi_area.rb, line 14
def initialize(options = {}, &block)
  super(options)
  @area_colors = options[:area_colors] ? options[:area_colors] : nil
  @baselines = options[:baselines] ? options[:baselines] : nil
end

Public Instance Methods

draw(svg, coords, options={}) click to toggle source

Render Multi Area graph.

# File lib/scruffy/layers/multi_area.rb, line 21
def draw(svg, coords, options={})
  # Check whether to use color from theme, or whether to use user defined colors from the area_colors array
  color_count = nil
  if @area_colors && @area_colors.size > 0
    area_color = @area_colors[0]
    color_count = 1
  else
    puts "Never Set Area Color"
    area_color = color
  end

  # Draw Bottom Level Polygons (Original Coords)
  draw_poly(svg, coords, area_color, options = {})

  # Draw Lower Area Polygons
  if @baselines
    # Get the Color of this Area
    puts "Drawing Baselines"
    @baselines.sort! {|x,y| y <=> x }
    @baselines.each do |baseline|
      if color_count
        area_color = area_colors[color_count]
        color_count = color_count + 1
        puts area_color.to_s
        if color_count >= area_colors.size
          color_count = 0
        end
      end

      lower_poly_coords = create_lower_polygon_coords(translate_number(baseline), coords, options)
      draw_poly(svg, lower_poly_coords, area_color, options = {})
    end
  end
end