Class: CTioga::LayoutPreferences

Inherits:
Object
  • Object
show all
Defined in:
lib/CTioga/layout.rb

Overview

This class merely stores various information about the layout, such as the desired mimimum amount of padding on the sides, the desired distance between plots and legends, the size and position of the legend…

For now, this class is hardly more than a Struct, but that is a very convenient way to carry across several objects and keep the documentation.

Every Container should have a LayoutPreference object in its layout_preferences attribute.

Constant Summary collapse

LayoutDefaults =
{
  :padding => [Dimension.new(0.05),
               Dimension.new(0.05),
               Dimension.new(0.05),
               Dimension.new(0.05)],
  :legend_size => Dimension.new(0.15),
  :legend_position => :right,
  :legend_glue => Dimension.new("2pt")
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLayoutPreferences

Returns a new instance of LayoutPreferences.



66
67
68
69
70
# File 'lib/CTioga/layout.rb', line 66

def initialize
  for key,val in LayoutDefaults
    self.send("#{key}=", val)
  end
end

Instance Attribute Details

#legend_glueObject

The minimum space between the graph and the legend, when the latter is on one of the sides of the graph.



64
65
66
# File 'lib/CTioga/layout.rb', line 64

def legend_glue
  @legend_glue
end

#legend_positionObject

The legend position: :left, :right, :top, :bottom or :inside



53
54
55
# File 'lib/CTioga/layout.rb', line 53

def legend_position
  @legend_position
end

#legend_sizeObject

The size of the legend. Not applicable in the case of an :inside legend specification.



57
58
59
# File 'lib/CTioga/layout.rb', line 57

def legend_size
  @legend_size
end

#legend_specObject

The full legend specification, in the case of an inside legend.



60
61
62
# File 'lib/CTioga/layout.rb', line 60

def legend_spec
  @legend_spec
end

#paddingObject

Padding: (left, right, top, bottom) An array of Dimensions specifiying the desired amount of padding around a given object.



50
51
52
# File 'lib/CTioga/layout.rb', line 50

def padding
  @padding
end

Class Method Details

.padding_relative_values(p, frames) ⇒ Object

Converts the padding to values relative to the given frames



75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/CTioga/layout.rb', line 75

def self.padding_relative_values(p, frames)
  ret_val = []
  4.times do |i|
    if p[i]
      ret_val[i] = p[i].to_relative(frames,
                                    i < 2 ? :horizontal : :vertical)
    else
      ret_val[i] = 0        # safely default to 0 ???
    end
  end
  return ret_val
end

Instance Method Details

#padding_relative_values(frames) ⇒ Object



88
89
90
# File 'lib/CTioga/layout.rb', line 88

def padding_relative_values(frames)
  return LayoutPreferences.padding_relative_values(@padding, frames)
end