Class: CTioga2::Graphics::Types::GridLayout

Inherits:
Object
  • Object
show all
Defined in:
lib/ctioga2/graphics/types/grid.rb

Overview

This class provides a grid-like layout through the use of a grid setup command and a grid box specification.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nup = "2x2") ⇒ GridLayout

Returns a new instance of GridLayout.



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/ctioga2/graphics/types/grid.rb', line 112

def initialize(nup = "2x2")
  if nup.respond_to?(:split)
    if nup =~ /,/
      @hscales, @vscales = nup.split(/\s*x\s*/).map { |x| 
        x.split(/\s*,\s*/).map { |y| y.to_f }
      }
      @nup = [@hscales.size, @vscales.size]
    else
      @nup = nup.split(/\s*x\s*/).map { |s| s.to_i }
    end
  else
    @nup = nup.dup
  end

  # Initialize with the given
  @outer_margins = {
    'left' =>  Dimension.new(:dy, 2.5, :x),
    'right' => Dimension.new(:bp, 6, :x),
    'bottom' =>  Dimension.new(:dy, 2.5, :y),
    'top' => Dimension.new(:dy, 2.5, :y)
  }
  @delta_x = Dimension.new(:dy, 2.5, :x)
  @delta_y = Dimension.new(:dy, 2.5, :y)

  @hscales ||= [1] * @nup[0]
  @vscales ||= [1] * @nup[1]
end

Instance Attribute Details

#delta_xObject

The X offset to go from the right-hand side of one element to the left-hand-side of the next



97
98
99
# File 'lib/ctioga2/graphics/types/grid.rb', line 97

def delta_x
  @delta_x
end

#delta_yObject

The Y offset to go from the bottom of one element to the top of the next.



101
102
103
# File 'lib/ctioga2/graphics/types/grid.rb', line 101

def delta_y
  @delta_y
end

#hscalesObject

Horizontal scales



107
108
109
# File 'lib/ctioga2/graphics/types/grid.rb', line 107

def hscales
  @hscales
end

#nupObject

The nup: an array nb horizontal, nb vertical



104
105
106
# File 'lib/ctioga2/graphics/types/grid.rb', line 104

def nup
  @nup
end

#outer_marginsObject

The margins (left, right, top, bottom) around the whole grid



93
94
95
# File 'lib/ctioga2/graphics/types/grid.rb', line 93

def outer_margins
  @outer_margins
end

#vscalesObject

Vertical scales



110
111
112
# File 'lib/ctioga2/graphics/types/grid.rb', line 110

def vscales
  @vscales
end

Class Method Details

.current_gridObject



147
148
149
# File 'lib/ctioga2/graphics/types/grid.rb', line 147

def self.current_grid
  return @current_grid
end

.current_grid=(grid) ⇒ Object



143
144
145
# File 'lib/ctioga2/graphics/types/grid.rb', line 143

def self.current_grid=(grid)
  @current_grid = grid
end

Instance Method Details

#frame_coordinates(t, x, y) ⇒ Object

Compute the frame coordinates fo the x,y element of the grid. They are numbered from the top,left element.



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/ctioga2/graphics/types/grid.rb', line 153

def frame_coordinates(t, x, y)
  compute_lengths(t)
  xo = if x > 0
         @hscales[0..(x-1)].inject(0,:+) * @wbase
       else
         0
       end
  xl = @outer_margins['left'].to_frame(t, :x) + xo + 
    x * @delta_x.to_frame(t, :x)
  yo = if y > 0
         @vscales[0..(y-1)].inject(0,:+) * @hbase
       else
         0
       end
  yt = 1 - (@outer_margins['top'].to_frame(t, :y) + yo +
            y * @delta_y.to_frame(t, :y))
  return [xl, yt, 
          xl + @wbase * @hscales[x], 
          yt - @hbase * @vscales[y]]
end