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.



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
139
140
# File 'lib/ctioga2/graphics/types/grid.rb', line 114

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



99
100
101
# File 'lib/ctioga2/graphics/types/grid.rb', line 99

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.



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

def delta_y
  @delta_y
end

#hscalesObject

Horizontal scales



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

def hscales
  @hscales
end

#nupObject

The nup: an array nb horizontal, nb vertical



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

def nup
  @nup
end

#outer_marginsObject

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



95
96
97
# File 'lib/ctioga2/graphics/types/grid.rb', line 95

def outer_margins
  @outer_margins
end

#vscalesObject

Vertical scales



112
113
114
# File 'lib/ctioga2/graphics/types/grid.rb', line 112

def vscales
  @vscales
end

Class Method Details

.current_gridObject



149
150
151
# File 'lib/ctioga2/graphics/types/grid.rb', line 149

def self.current_grid
  return @current_grid
end

.current_grid=(grid) ⇒ Object



145
146
147
# File 'lib/ctioga2/graphics/types/grid.rb', line 145

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.



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

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