class CTioga2::Graphics::Types::Boundaries
An object representing boundaries for a plot.
todo Should be converted to using two SimpleRange
objects. Will be more clear anyway.
Attributes
Public Class Methods
Returns a boundary object that exactly contains all x_values and y_values (including error bars if applicable)
# 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
Creates a Boundaries
object from two SimpleRange
objects.
# 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
Creates a new Boundaries
object with the given boundaries. A nil, false or NaN in one of those means unspecified.
# File lib/ctioga2/graphics/types/boundaries.rb, line 153 def initialize(left, right, top, bottom) @left = left @right = right @top = top @bottom = bottom end
Takes an array of Boundaries
and returns a Boundaries
object that precisely encompasses them all. Invalid floats are simply ignored.
# 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
Public Instance Methods
Apply a fixed margin on the Boundaries
.
# 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
This function makes sures that the Boundaries
object is big enough to encompass what it currently does and the bounds Boundaries
object.
# 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
Converts to an [xmin, xmax, ymin, ymax] array
# File lib/ctioga2/graphics/types/boundaries.rb, line 199 def extrema return [xmin, xmax, ymin, ymax] end
The algebraic height of the boundaries
# File lib/ctioga2/graphics/types/boundaries.rb, line 209 def height return @top - @bottom end
Returns a SimpleRange
object corresponding to the horizontal range
# File lib/ctioga2/graphics/types/boundaries.rb, line 187 def horizontal return SimpleRange.new(@left, @right) end
Override the Boundaries
with the contents of override. All elements which are not nil or NaN from override precisely override those in self.
# 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
Sets the values of the Boundaries
for the which axis from the given range.
# 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
Converts to an array suitable for use with Tioga.
# File lib/ctioga2/graphics/types/boundaries.rb, line 161 def to_a return [@left, @right, @top, @bottom] end
Returns a SimpleRange
object corresponding to the vertical range
# File lib/ctioga2/graphics/types/boundaries.rb, line 193 def vertical return SimpleRange.new(@bottom, @top) end
The algebraic width of the boundaries
# File lib/ctioga2/graphics/types/boundaries.rb, line 204 def width return @right - @left end
Maximum x value
# File lib/ctioga2/graphics/types/boundaries.rb, line 171 def xmax @left > @right ? @left : @right end
Minimum x value
# File lib/ctioga2/graphics/types/boundaries.rb, line 166 def xmin @left < @right ? @left : @right end
Maxiumum y value
# File lib/ctioga2/graphics/types/boundaries.rb, line 181 def ymax @bottom > @top ? @bottom : @top end
Minimum y value
# File lib/ctioga2/graphics/types/boundaries.rb, line 176 def ymin @bottom < @top ? @bottom : @top end