class CTioga2::Graphics::Styles::MapAxisStyle

This class handles the display of a Z axis color map, in the form of a colored bar with ticks and a label.

Attributes

color_map[RW]

The actual color map

Public Class Methods

new() click to toggle source

Creates a new MapAxisStyle object at the given location with the given style.

# File lib/ctioga2/graphics/styles/map-axes.rb, line 47
def initialize()
  super()

  @bar_size = Types::Dimension.new(:dy, 2, :x)

  # Shifting away from the location.
  @bar_shift = Types::Dimension.new(:dy, 0.3, :x)

  ## @todo maybe use different padding for left and right ?
  @padding = Types::Dimension.new(:dy, 0.5, :x)

  @decoration = AXIS_WITH_TICKS_AND_NUMERIC_LABELS

  # To be implemented one day...
  @other_side_decoration = nil
end

Public Instance Methods

draw_axis(t, watcher = nil) click to toggle source
# File lib/ctioga2/graphics/styles/map-axes.rb, line 70
def draw_axis(t, watcher = nil)
  # Not beautiful at all
  size = Types::Dimension.new(:dy, extension(t), 
                              @location.orientation)
  label_size = 
    Types::Dimension.new(:dy, labels_only_extension(t, style = nil),
                         @location.orientation)

  @location.do_sub_frame(t, size) do
    # This is a necessary workaround for a small bug
    t.set_subframe([0,0,0,0])
    # Here, do the correct setup, using a MarginsBox:
    # * correctly setup the axes/edges
    # * handle the sides correctly.
    # * position the subplot within accordingly
    # * use draw_axis for the axis ?

    plot_box = Types::MarginsBox.
      new(*@location.reorient_margins(@bar_shift, label_size, 
                                      @padding, @padding))

    # We wrap the call within a subplot
    t.subplot(plot_box.to_frame_margins(t)) do
      bounds = if @location.vertical?
                 [0, 1, @bounds.last, @bounds.first]
               else
                 [@bounds.first, @bounds.last, 0, 1]
               end
      t.set_bounds(bounds)
      t.context do 
        t.clip_to_frame
        cmap, zmin, zmax = *@color_map.to_colormap(t, @bounds.first,
                                                  @bounds.last)

        sp = [0.5, zmin]
        ep = [0.5, zmax]
        if ! @location.vertical?
          sp.reverse!
          ep.reverse!
        end
        t.axial_shading(
                        'start_point' => sp,
                        'end_point' => ep,
                        'colormap' => cmap
                        )
      end
      ## @todo handle axis color ?
      t.stroke_frame
      ## @todo potentially handle decorations for the other
      ## side too.

      ## @todo This is a ugly hack, but Ruby doesn't allow a
      ## clean one. Though
      ## http://stackoverflow.com/questions/1251178/calling-another-method-in-super-class-in-ruby
      ## seems like the way to go ! To be implemented one day.
      self.class.superclass.instance_method(:draw_axis).
        bind(self).call(t)
      
    end

  end
end
draw_background_lines(t) click to toggle source

Draw the axis background lines:

# File lib/ctioga2/graphics/styles/map-axes.rb, line 138
def draw_background_lines(t)
  # Nothing to do
end
extension(t, style = nil) click to toggle source
# File lib/ctioga2/graphics/styles/map-axes.rb, line 142
def extension(t, style = nil)
  base = super(t, style)

  base += @bar_size.to_text_height(t, @location.orientation)
  base += @bar_shift.to_text_height(t, @location.orientation)
  return base
end
set_bounds_for_axis(t, range = nil) click to toggle source
# File lib/ctioga2/graphics/styles/map-axes.rb, line 133
def set_bounds_for_axis(t, range = nil)
  # Useless here
end
set_color_map(color_map, zmin, zmax) click to toggle source
# File lib/ctioga2/graphics/styles/map-axes.rb, line 64
def set_color_map(color_map, zmin, zmax)
  @bounds = [zmin, zmax]
  @color_map = color_map

end
vertical?() click to toggle source

Whether the axis is vertical or not

# File lib/ctioga2/graphics/styles/map-axes.rb, line 151
def vertical?
  return @location.vertical?
end