Class: Scruffy::Components::Graphs

Inherits:
Base
  • Object
show all
Defined in:
lib/scruffy/components/graphs.rb

Overview

Component for displaying Graphs layers.

Is passed all graph layers from the Graph object.

(This may change as the capability for Graph filtering and such fills out.)

Constant Summary collapse

STACKED_OPACITY =
0.85

Instance Attribute Summary

Attributes inherited from Base

#id, #options, #position, #size, #visible

Instance Method Summary collapse

Methods inherited from Base

#initialize, #process, #render

Constructor Details

This class inherits a constructor from Scruffy::Components::Base

Instance Method Details

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



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/scruffy/components/graphs.rb', line 12

def draw(svg, bounds, options={})
  # If Graph is limited to a category, reject layers outside of it's scope.
  applicable_layers = options[:layers].reject do |l| 
    if @options[:only]
      (l.options[:category].nil? && l.options[:categories].nil?) ||
      (!l.options[:category].nil? && l.options[:category] != @options[:only]) || 
      (!l.options[:categories].nil? && !l.options[:categories].include?(@options[:only]))
    else 
      false
    end
  end

  applicable_layers.each_with_index do |layer, idx|
    layer_options = {}
    layer_options[:index]       = idx
    layer_options[:min_value]   = options[:min_value]
    layer_options[:max_value]   = options[:max_value]
    layer_options[:min_key]     = options[:min_key]
    layer_options[:max_key]     = options[:max_key]
    layer_options[:complexity]  = options[:complexity]
    layer_options[:size]        = [bounds[:width], bounds[:height]]
    layer_options[:color]       = layer.preferred_color || layer.color || options[:theme].next_color
    layer_options[:outline]       = layer.preferred_outline || layer.outline || options[:theme].next_outline
    layer_options[:opacity]     = opacity_for(idx)
    layer_options[:theme]       = options[:theme]

    svg.g(:id => "component_#{id}_graph_#{idx}", :class => 'graph_layer') {
      layer.render(svg, layer_options)
    }
  end # applicable_layers
end