Class: CTioga2::Graphics::Types::Boundaries
- Inherits:
-
Object
- Object
- CTioga2::Graphics::Types::Boundaries
- Defined in:
- lib/ctioga2/graphics/types/boundaries.rb
Overview
An object representing boundaries for a plot.
todo Should be converted to using two SimpleRange objects. Will be more clear anyway.
Instance Attribute Summary collapse
-
#bottom ⇒ Object
Boundaries.
-
#left ⇒ Object
Boundaries.
-
#right ⇒ Object
Boundaries.
-
#top ⇒ Object
Boundaries.
Class Method Summary collapse
-
.bounds(x_values, y_values) ⇒ Object
Returns a boundary object that exactly contains all x_values and y_values (including error bars if applicable).
-
.from_ranges(horiz, vert) ⇒ Object
Creates a Boundaries object from two SimpleRange objects.
-
.overall_bounds(bounds) ⇒ Object
Takes an array of Boundaries and returns a Boundaries object that precisely encompasses them all.
Instance Method Summary collapse
-
#apply_margin!(margin) ⇒ Object
Apply a fixed margin on the Boundaries.
-
#extend(bounds) ⇒ Object
This function makes sures that the Boundaries object is big enough to encompass what it currently does and the bounds Boundaries object.
-
#extrema ⇒ Object
Converts to an [xmin, xmax, ymin, ymax] array.
-
#height ⇒ Object
The algebraic height of the boundaries.
-
#horizontal ⇒ Object
Returns a SimpleRange object corresponding to the horizontal range.
-
#initialize(left, right, top, bottom) ⇒ Boundaries
constructor
Creates a new Boundaries object with the given boundaries.
-
#override_boundaries(override) ⇒ Object
Override the Boundaries with the contents of override.
-
#set_from_range(range, which) ⇒ Object
Sets the values of the Boundaries for the which axis from the given range.
-
#to_a ⇒ Object
Converts to an array suitable for use with Tioga.
-
#vertical ⇒ Object
Returns a SimpleRange object corresponding to the vertical range.
-
#width ⇒ Object
The algebraic width of the boundaries.
-
#xmax ⇒ Object
Maximum x value.
-
#xmin ⇒ Object
Minimum x value.
-
#ymax ⇒ Object
Maxiumum y value.
-
#ymin ⇒ Object
Minimum y value.
Constructor Details
#initialize(left, right, top, bottom) ⇒ Boundaries
Creates a new Boundaries object with the given boundaries. A nil, false or NaN in one of those means unspecified.
153 154 155 156 157 158 |
# File 'lib/ctioga2/graphics/types/boundaries.rb', line 153 def initialize(left, right, top, bottom) @left = left @right = right @top = top @bottom = bottom end |
Instance Attribute Details
#bottom ⇒ Object
Boundaries
149 150 151 |
# File 'lib/ctioga2/graphics/types/boundaries.rb', line 149 def bottom @bottom end |
#left ⇒ Object
Boundaries
149 150 151 |
# File 'lib/ctioga2/graphics/types/boundaries.rb', line 149 def left @left end |
#right ⇒ Object
Boundaries
149 150 151 |
# File 'lib/ctioga2/graphics/types/boundaries.rb', line 149 def right @right end |
#top ⇒ Object
Boundaries
149 150 151 |
# File 'lib/ctioga2/graphics/types/boundaries.rb', line 149 def top @top end |
Class Method Details
.bounds(x_values, y_values) ⇒ Object
Returns a boundary object that exactly contains all x_values and y_values (including error bars if applicable)
277 278 279 280 |
# File 'lib/ctioga2/graphics/types/boundaries.rb', line 277 def self.bounds(x_values, y_values) return Boundaries.new(x_values.min, x_values.max, y_values.max, y_values.min) end |
.from_ranges(horiz, vert) ⇒ Object
Creates a Boundaries object from two SimpleRange objects.
294 295 296 297 |
# File 'lib/ctioga2/graphics/types/boundaries.rb', line 294 def self.from_ranges(horiz, vert) return Boundaries.new(horiz.first, horiz.last, vert.last, vert.first) end |
.overall_bounds(bounds) ⇒ Object
Takes an array of Boundaries and returns a Boundaries object that precisely encompasses them all. Invalid floats are simply ignored.
285 286 287 288 289 290 291 |
# File 'lib/ctioga2/graphics/types/boundaries.rb', line 285 def self.overall_bounds(bounds) retval = Boundaries.new(nil, nil, nil, nil) for b in bounds retval.extend(b) end return retval end |
Instance Method Details
#apply_margin!(margin) ⇒ Object
Apply a fixed margin on the Boundaries.
253 254 255 256 257 258 259 260 |
# File 'lib/ctioga2/graphics/types/boundaries.rb', line 253 def apply_margin!(margin) w = self.width @left = @left - margin * w @right = @right + margin * w h = self.height @top = @top + margin * h @bottom = @bottom - margin * h end |
#extend(bounds) ⇒ Object
This function makes sures that the Boundaries object is big enough to encompass what it currently does and the bounds Boundaries object.
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/ctioga2/graphics/types/boundaries.rb', line 216 def extend(bounds) # Left/right if (! @left.is_a? Float) or @left.nan? or (@left > bounds.left) @left = bounds.left end if (! @right.is_a? Float) or @right.nan? or (@right < bounds.right) @right = bounds.right end # Top/bottom if (! @top.is_a? Float) or @top.nan? or (@top < bounds.top) @top = bounds.top end if (! @bottom.is_a? Float) or @bottom.nan? or (@bottom > bounds.bottom) @bottom = bounds.bottom end return self end |
#extrema ⇒ Object
Converts to an [xmin, xmax, ymin, ymax] array
199 200 201 |
# File 'lib/ctioga2/graphics/types/boundaries.rb', line 199 def extrema return [xmin, xmax, ymin, ymax] end |
#height ⇒ Object
The algebraic height of the boundaries
209 210 211 |
# File 'lib/ctioga2/graphics/types/boundaries.rb', line 209 def height return @top - @bottom end |
#horizontal ⇒ Object
Returns a SimpleRange object corresponding to the horizontal range
187 188 189 |
# File 'lib/ctioga2/graphics/types/boundaries.rb', line 187 def horizontal return SimpleRange.new(@left, @right) end |
#override_boundaries(override) ⇒ Object
Override the Boundaries with the contents of override. All elements which are not nil or NaN from override precisely override those in self.
243 244 245 246 247 248 249 250 |
# File 'lib/ctioga2/graphics/types/boundaries.rb', line 243 def override_boundaries(override) for el in [ :left, :right, :top, :bottom] val = override.send(el) if val and (val == val) # Strip NaN on the property that NaN != NaN self.send("#{el}=", val) end end end |
#set_from_range(range, which) ⇒ Object
Sets the values of the Boundaries for the which axis from the given range.
264 265 266 267 268 269 270 271 272 273 |
# File 'lib/ctioga2/graphics/types/boundaries.rb', line 264 def set_from_range(range, which) case which when :x @left, @right = range.first, range.last when :y @bottom, @top = range.first, range.last else raise "What is this #{which} axis ? " end end |
#to_a ⇒ Object
Converts to an array suitable for use with Tioga.
161 162 163 |
# File 'lib/ctioga2/graphics/types/boundaries.rb', line 161 def to_a return [@left, @right, @top, @bottom] end |
#vertical ⇒ Object
Returns a SimpleRange object corresponding to the vertical range
193 194 195 |
# File 'lib/ctioga2/graphics/types/boundaries.rb', line 193 def vertical return SimpleRange.new(@bottom, @top) end |
#width ⇒ Object
The algebraic width of the boundaries
204 205 206 |
# File 'lib/ctioga2/graphics/types/boundaries.rb', line 204 def width return @right - @left end |
#xmax ⇒ Object
Maximum x value
171 172 173 |
# File 'lib/ctioga2/graphics/types/boundaries.rb', line 171 def xmax @left > @right ? @left : @right end |
#xmin ⇒ Object
Minimum x value
166 167 168 |
# File 'lib/ctioga2/graphics/types/boundaries.rb', line 166 def xmin @left < @right ? @left : @right end |
#ymax ⇒ Object
Maxiumum y value
181 182 183 |
# File 'lib/ctioga2/graphics/types/boundaries.rb', line 181 def ymax @bottom > @top ? @bottom : @top end |
#ymin ⇒ Object
Minimum y value
176 177 178 |
# File 'lib/ctioga2/graphics/types/boundaries.rb', line 176 def ymin @bottom < @top ? @bottom : @top end |