Class: Scruffy::Layers::Average

Inherits:
Base
  • Object
show all
Defined in:
lib/scruffy/layers/average.rb

Overview

Scruffy::Layers::Average

Author

Brasten Sager

Date

August 7th, 2006

An ‘average’ graph. This graph iterates through all the layers and averages all the data at each point, then draws a thick, translucent, shadowy line graph indicating the average values.

This only looks decent in SVG mode. ImageMagick doesn’t retain the transparency for some reason, creating a massive black line. Any help resolving this would be useful.

Instance Attribute Summary collapse

Attributes inherited from Base

#color, #complexity, #height, #max_value, #min_value, #opacity, #options, #points, #preferred_color, #relevant_data, #title, #width

Instance Method Summary collapse

Methods inherited from Base

#bottom_value, #legend_data, #relevant_data?, #render, #sum_values, #top_value

Constructor Details

#initialize(options = {}) ⇒ Average

Returns new Average graph.



18
19
20
21
22
23
24
25
# File 'lib/scruffy/layers/average.rb', line 18

def initialize(options = {})
  # Set self's relevant_data to false.  Otherwise we get stuck in a
  # recursive loop.
  super(options.merge({:relevant_data => false}))
  
  # The usual :points argument is actually layers for Average, name it as such
  @layers = options[:points] 
end

Instance Attribute Details

#layersObject (readonly)

Returns the value of attribute layers.



15
16
17
# File 'lib/scruffy/layers/average.rb', line 15

def layers
  @layers
end

Instance Method Details

#draw(svg, coords, options = {}) ⇒ Object

Render average graph.



28
29
30
31
# File 'lib/scruffy/layers/average.rb', line 28

def draw(svg, coords, options = {})
  svg.polyline( :points => coords.join(' '), :fill => 'none', :stroke => 'black',
                'stroke-width' => relative(5), 'opacity' => '0.4')
end