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

bottom[RW]
left[RW]
right[RW]
top[RW]

Public Class Methods

bounds(x_values, y_values) click to toggle source

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
from_ranges(horiz, vert) click to toggle source

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
new(left, right, top, bottom) click to toggle source

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
overall_bounds(bounds) click to toggle source

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_margin!(margin) click to toggle source

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
extend(bounds) click to toggle source

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
extrema() click to toggle source

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
height() click to toggle source

The algebraic height of the boundaries

# File lib/ctioga2/graphics/types/boundaries.rb, line 209
def height
  return @top - @bottom
end
horizontal() click to toggle source

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_boundaries(override) click to toggle source

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
set_from_range(range, which) click to toggle source

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
to_a() click to toggle source

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
vertical() click to toggle source

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
width() click to toggle source

The algebraic width of the boundaries

# File lib/ctioga2/graphics/types/boundaries.rb, line 204
def width
  return @right - @left
end
xmax() click to toggle source

Maximum x value

# File lib/ctioga2/graphics/types/boundaries.rb, line 171
def xmax
  @left > @right ? @left : @right
end
xmin() click to toggle source

Minimum x value

# File lib/ctioga2/graphics/types/boundaries.rb, line 166
def xmin
  @left < @right ? @left : @right
end
ymax() click to toggle source

Maxiumum y value

# File lib/ctioga2/graphics/types/boundaries.rb, line 181
def ymax
  @bottom > @top ? @bottom : @top
end
ymin() click to toggle source

Minimum y value

# File lib/ctioga2/graphics/types/boundaries.rb, line 176
def ymin
  @bottom < @top ? @bottom : @top
end