Class | Scruffy::Layers::Base |
In: |
lib/scruffy/layers/base.rb
|
Parent: | Object |
Author: | Brasten Sager |
Date: | August 5th, 2006 |
Scruffy::Layers::Base contains the basic functionality needed by the various types of graphs. The Base class is responsible holding layer information such as the title and data points.
When the graph is rendered, the graph renderer calls Base#render. Base#render sets up some standard information, and calculates the x,y coordinates of each data point. The draw() method, which should have been overridden by the current instance, is then called. The actual rendering of the graph takes place there.
Assuming the information generated by Scruffy::Layers::Base is sufficient, you can create a new graph type simply by overriding the draw() method. See Base#draw for arguments.
color | [R] | |
complexity | [R] | |
height | [R] | The following attributes are set during the layer‘s render process, and act more as a record of what just happened for later processes. height, width, min_value, max_value, color, opacity, complexity |
max_value | [R] | |
min_value | [R] | |
opacity | [R] | |
options | [RW] | |
points | [RW] | |
preferred_color | [RW] | |
relevant_data | [RW] | |
title | [RW] | The following attributes are user-definable at any time. title, points, relevant_data, preferred_color, options |
width | [R] | The following attributes are set during the layer‘s render process, and act more as a record of what just happened for later processes. height, width, min_value, max_value, color, opacity, complexity |
Any options other that those specified below are stored in the @options variable for possible later use. This would be a good place to store options needed for a custom graph.
Options:
title: | Name/title of data group |
points: | Array of data points |
preferred_color: | Color used to render this graph, overrides theme color. |
relevant_data: | Rarely used - indicates the data on this graph should not included in any graph data aggregations, such as averaging data points. |
Returns a hash with information to be used by the legend.
Alternatively, returns nil if you don‘t want this layer to be in the legend, or an array of hashes if this layer should have multiple legend entries (stacked?)
By default, legend_data returns nil automatically if relevant_data is set to false or the @color attribute is nil. @color is set when the layer is rendered, so legends must be rendered AFTER layers.
Builds SVG code for this graph using the provided Builder object. This method actually generates data needed by this graph, then passes the rendering responsibilities to Base#draw.
svg: | a Builder object used to create SVG code. |
Optimistic generation of coordinates for layer to use. These coordinates are just a best guess, and can be overridden or thrown away (for example, this is overridden in pie charting and bar charts).
Converts a percentage into a pixel value, relative to the height.
Example:
relative(5) # On a 100px high layer, this returns 5. 200px high layer, this returns 10, etc.
Sets up several variables that almost every graph layer will need to render itself.