Class: CTioga::EdgesAndAxes

Inherits:
Object
  • Object
show all
Includes:
Log, Tioga::FigureConstants
Defined in:
lib/CTioga/axes.rb

Overview

A class that holds the information about how to plot the edges. And the size they potentially take.

TODO: make sure the TickLabels and EdgesAndAxes talk to each other (for the #extension, essentially). They should be connected from the SubPlot class.

Defined Under Namespace

Classes: Axis

Constant Summary collapse

Edges =
[:left, :right, :top, :bottom]
Defaults =

The default values for the edges

{
  :left => AXIS_WITH_TICKS_AND_NUMERIC_LABELS,
  :right => AXIS_WITH_TICKS_ONLY,
  :top => AXIS_WITH_TICKS_ONLY,
  :bottom => AXIS_WITH_TICKS_AND_NUMERIC_LABELS
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Log

#identify, #init_logger, #logger, #logger_options, #spawn

Constructor Details

#initialize(xticks = nil, yticks = nil) ⇒ EdgesAndAxes

Returns a new instance of EdgesAndAxes.



780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
# File 'lib/CTioga/axes.rb', line 780

def initialize(xticks = nil, yticks = nil)
  @edge_specs = Defaults.dup
  @xaxis = Axis.new(:x, xticks)
  @xaxis.type = AXIS_WITH_TICKS_AND_NUMERIC_LABELS
  @yaxis = Axis.new(:y, yticks)
  @yaxis.type = AXIS_WITH_TICKS_AND_NUMERIC_LABELS

  # A handy shortcut
  @axis = {:x => @xaxis, :y => @yaxis}

  @edge_visibility = {}

  @axes = {
    'xaxis' => @xaxis,
    'yaxis' => @yaxis,
  }
end

Instance Attribute Details

#axesObject

Named axes:



777
778
779
# File 'lib/CTioga/axes.rb', line 777

def axes
  @axes
end

#edge_specsObject

A hash containing the edge type for each edge.



759
760
761
# File 'lib/CTioga/axes.rb', line 759

def edge_specs
  @edge_specs
end

#edge_visibilityObject

A hash containing the default visibility for the edges.



763
764
765
# File 'lib/CTioga/axes.rb', line 763

def edge_visibility
  @edge_visibility
end

#xaxisObject

The main axes



774
775
776
# File 'lib/CTioga/axes.rb', line 774

def xaxis
  @xaxis
end

#yaxisObject

The main axes



774
775
776
# File 'lib/CTioga/axes.rb', line 774

def yaxis
  @yaxis
end

Class Method Details

.parse_axis_position(str) ⇒ Object

This function parses an axes position specification from the command-line.



478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
# File 'lib/CTioga/axes.rb', line 478

def self.parse_axis_position(str)
  case str
  when /xori?g(in)?/i, /x=0/i
    return Tioga::FigureConstants::AT_X_ORIGIN
  when /yori?g(in)?/i, /y=0/i
    return Tioga::FigureConstants::AT_Y_ORIGIN
  when /l(eft)?/i
    return Tioga::FigureConstants::LEFT
  when /r(ight)?/i
    return Tioga::FigureConstants::RIGHT
  when /t(op)?/i
    return Tioga::FigureConstants::TOP
  when /b(ottom)?/i
    return Tioga::FigureConstants::BOTTOM
  else
    raise "Unkown axis position: #{str}"
  end
end

Instance Method Details

#axis(which) ⇒ Object

Returns either #xaxis or #yaxis depending on the value of which.



817
818
819
# File 'lib/CTioga/axes.rb', line 817

def axis(which)
  return @axis[which]
end

#disable(*which) ⇒ Object

Disable the given edges, or all if no arguments



806
807
808
# File 'lib/CTioga/axes.rb', line 806

def disable(*which)
  set_edges(AXIS_HIDDEN, *which)
end

#extension(t, scale = 1) ⇒ Object

This does not take ticks into account yet. No need !



856
857
858
859
860
861
862
# File 'lib/CTioga/axes.rb', line 856

def extension(t, scale = 1)
  f = [0,0,0,0]
  Dimension.update_extensions(f, @xaxis.extension(t))
  Dimension.update_extensions(f, @yaxis.extension(t))
  debug "Edges and axis #{self.inspect} extension #{f.inspect}"
  return f
end

#line_only(*which) ⇒ Object

Show only one line for the given edges.



811
812
813
# File 'lib/CTioga/axes.rb', line 811

def line_only(*which)
  set_edges(AXIS_LINE_ONLY, *which)
end

#set_axis_and_edges_style(axis, style) ⇒ Object

Sets the style for both the axis and the edges of the given side.



842
843
844
845
846
847
848
849
850
851
852
853
# File 'lib/CTioga/axes.rb', line 842

def set_axis_and_edges_style(axis, style)
  case axis
  when :x
    @xaxis.type = style
    set_edges(style, :top,:bottom)
  when :y
    @yaxis.type = style
    set_edges(style, :left,:right)
  else                      # for :left, :right, :top, :bottom
    set_edges(style, axis)
  end
end

#set_edges(value, *which) ⇒ Object



798
799
800
801
802
803
# File 'lib/CTioga/axes.rb', line 798

def set_edges(value, *which)
  which = Edges if which.empty?
  for edge in which
    @edge_specs[edge] = value
  end
end

#set_edges_visibility(which, what) ⇒ Object

Sets the edge visibility for the given sides



878
879
880
881
882
883
884
885
# File 'lib/CTioga/axes.rb', line 878

def set_edges_visibility(which, what)
  case which
  when :y
    @edge_visibility[:left] = @edge_visibility[:right] = what
  when :x
    @edge_visibility[:top] = @edge_visibility[:bottom] = what
  end
end

#setup(t, container) ⇒ Object

Sets up the edges for the given plot. Should probably be called just before the exit of the show_plot_with_legend block argument



824
825
826
827
828
829
830
831
832
833
834
835
836
837
# File 'lib/CTioga/axes.rb', line 824

def setup(t, container)
  # Send axes informations.
  @xaxis.setup(t, container)
  @yaxis.setup(t, container)
  for edge in Edges
    t.send("#{edge}_edge_type=", @edge_specs[edge]) if 
      @edge_specs.key? edge
    # Can only disable edges
    if (@edge_visibility.key?(edge) && !@edge_visibility[edge])
      t.send("#{edge}_edge_visible=", false)
    end
      
  end
end

#show_additional_axes(t, container) ⇒ Object

Draw all named non-standard axes



896
897
898
899
900
# File 'lib/CTioga/axes.rb', line 896

def show_additional_axes(t, container)
  for name in @axes.keys - %w(xaxis yaxis)
    @axes[name].show(t, container)
  end
end

#show_axis_lines(t, container) ⇒ Object

Called from PlotStyle#show_background to display axis lines.



889
890
891
892
893
# File 'lib/CTioga/axes.rb', line 889

def show_axis_lines(t, container)
  for axis in @axes.keys.sort
    @axes[axis].draw_lines(t, container)
  end
end