Module: CTioga2::Graphics

Defined in:
lib/ctioga2/graphics/root.rb,
lib/ctioga2/graphics/types.rb,
lib/ctioga2/graphics/legends.rb,
lib/ctioga2/graphics/elements.rb,
lib/ctioga2/graphics/generator.rb,
lib/ctioga2/graphics/types/grid.rb,
lib/ctioga2/graphics/coordinates.rb,
lib/ctioga2/graphics/styles/axes.rb,
lib/ctioga2/graphics/styles/base.rb,
lib/ctioga2/graphics/styles/plot.rb,
lib/ctioga2/graphics/styles/sets.rb,
lib/ctioga2/graphics/types/boxes.rb,
lib/ctioga2/graphics/types/point.rb,
lib/ctioga2/graphics/legends/area.rb,
lib/ctioga2/graphics/styles/curve.rb,
lib/ctioga2/graphics/styles/texts.rb,
lib/ctioga2/graphics/legends/items.rb,
lib/ctioga2/graphics/styles/legend.rb,
lib/ctioga2/graphics/styles/carrays.rb,
lib/ctioga2/graphics/styles/factory.rb,
lib/ctioga2/graphics/types/location.rb,
lib/ctioga2/graphics/elements/region.rb,
lib/ctioga2/graphics/legends/storage.rb,
lib/ctioga2/graphics/styles/colormap.rb,
lib/ctioga2/graphics/styles/drawable.rb,
lib/ctioga2/graphics/styles/errorbar.rb,
lib/ctioga2/graphics/styles/location.rb,
lib/ctioga2/graphics/styles/map-axes.rb,
lib/ctioga2/graphics/types/bijection.rb,
lib/ctioga2/graphics/elements/contour.rb,
lib/ctioga2/graphics/elements/curve2d.rb,
lib/ctioga2/graphics/elements/element.rb,
lib/ctioga2/graphics/elements/subplot.rb,
lib/ctioga2/graphics/elements/tangent.rb,
lib/ctioga2/graphics/elements/xyz-map.rb,
lib/ctioga2/graphics/legends/provider.rb,
lib/ctioga2/graphics/styles/gradients.rb,
lib/ctioga2/graphics/subplot-commands.rb,
lib/ctioga2/graphics/types/boundaries.rb,
lib/ctioga2/graphics/types/dimensions.rb,
lib/ctioga2/graphics/styles/background.rb,
lib/ctioga2/graphics/elements/primitive.rb,
lib/ctioga2/graphics/elements/containers.rb,
lib/ctioga2/graphics/elements/parametric2d.rb,
lib/ctioga2/graphics/elements/gradient-region.rb,
lib/ctioga2/graphics/elements/redirecting-container.rb

Overview

This module contains all graphical elements of CTioga2

Defined Under Namespace

Modules: Elements, Legends, LineStyles, Styles, Types Classes: CoordinateTransforms, CurveGenerator, RootObject

Constant Summary collapse

ColorType =
CmdType.new('color', {
                              :type => :tioga_color,
                              :namespace => Tioga::ColorConstants
                            }, <<EOD)
A color. It can take three forms:
 * a named color, see 
{url: http://tioga.rubyforge.org/doc/classes/Tioga/ColorConstants.html}
for the list of color names.
 * an HTML color: for instance, @#f00@ or @#ff0000@ is red;
 * a list of three numbers between 0 and 1: @1,0,0@ is red too.
EOD
ColorOrFalseType =
CmdType.new('color-or-false', {
                    :type => :tioga_color,
                    :namespace => Tioga::ColorConstants,
                    :shortcuts => {'none' => false }
                  }, <<EOD)
A {type: color}, or false to say that nothing should be drawn.
EOD
CurveFillUntilType =
CmdType.new('fill-until', {
                                       :type => :float,
                                       :shortcuts => {
                                         /x?axis/i => 0.0,
                                         /b(?:ot(?:tom)?)?/i => :bottom,
                                         /t(?:op)?/i => :top,
                                         /no(?:ne)?/i => false
                                       }
                                     }, <<EOD)
The Y values until which a filled curve will be filled. Generally a number, 
but it can also be:
 * @axis@ (or @xaxis@), which means 0
 * @bottom@, to fill until the bottom of the graph
 * @top@, to fill until the top 
 * @none@, meaning no fill
EOD
RegionSideType =
CmdType.new('region-side', {
                    :type => :list,
                    :list => {},
                    :shortcuts => {
                      'above' => :above,
                      'below' => :below,
                      'ignore' => false,
                    }
                  }, <<EOD)
Within a {command: region}, designates the position of the curve with
respect to the region:
 * @above@
 * @below@
 * @ignore@ if this curve is not to be taken into account
EOD
LineStyleType =
CmdType.new('line-style', {
                    :type => :tioga_line_style,
                    :namespace => LineStyles,
                    :shortcuts => {
                      /no(ne)?|off/i => false,
                    }
                  }, <<EOD)
A line style, or @no@, @none@ or @off@ to mean no line.
EOD
MarkerType =
CmdType.new('marker', {
                    :type => :tioga_marker,
                    :namespace => Tioga::MarkerConstants,
                    :shortcuts => {
                      'None' => 'None',
                      'no' => 'None',
                      'none' => 'None',
                      'off' => 'None', 
                    },}, <<EOD)
A Tioga Marker.
EOD
PointType =
CmdType.new('point', :point, <<EOD)
A given point on a figure.
EOD
LevelType =

We need a very specific type for that as we want to have a reference to the level too !

CmdType.new('level', :level, <<EOD)
A level on a XYZ map (that is, just a Z value).
EOD
JustificationRE =
{
  /l(eft)?/i => Tioga::FigureConstants::LEFT_JUSTIFIED,
  /c(enter)?/i => Tioga::FigureConstants::CENTERED,
  /r(ight)?/i => Tioga::FigureConstants::RIGHT_JUSTIFIED
}
JustificationType =
CmdType.new('justification', {:type => :re_list,
                    :list => JustificationRE}, <<EOD)
Horizontal aligment for text. Can be one of:
 * @l@ or @left@
 * @c@, @center@
 * @r@, @right@
EOD
AlignmentRE =

Regular expression for vertical alignment

{
  /t(op)?/i => Tioga::FigureConstants::ALIGNED_AT_TOP,
  /c(enter)|m(idheight)/i => Tioga::FigureConstants::ALIGNED_AT_MIDHEIGHT,
  /B|Baseline|baseline/ => Tioga::FigureConstants::ALIGNED_AT_BASELINE,
  /b(ottom)?/ => Tioga::FigureConstants::ALIGNED_AT_BOTTOM
}
AlignmentType =
CmdType.new('alignment', {:type => :re_list,
                      :list => AlignmentRE}, 
                    <<EOD)
Vertical aligment for text. Can be one of:
 * @t@ or @top@
 * @c@, @center@, @m@ or @midheight@ (vertically centered)
 * @B@, @Baseline@ or @baseline@ to align at the baseline
 * @b@ or @bottom@
EOD
PDFFont =
CmdType.new('pdf-font', :integer, <<EOD)
A number between 1 and 14 that designates one of the 14 standard 
PDF fonts. (see for instance
{url: http://tioga.rubyforge.org/doc/classes/Tioga/MarkerConstants.html}
for more information).
EOD
AlignedPointType =
CmdType.new('aligned-point', {:type => :aligned_point, 
                    :default => :frame}, <<EOD)
A point together with alignment specifications.
EOD
FrameMarginsType =
CmdType.new('frame-margins', {:type => 
                    :frame_margins, :shortcuts => 
                    { /^\s*auto\s*$/i => nil}}, <<EOD)
Margins around a plot, ie the distance from the side of the plot to
the corresponding side of the container (most likely the whole
PDF). It can take three forms:
 * @dimension@ (applies to all sides)
 * @left_right, top_bottom@
 * @left, right, top, bottom@

Each of these elements is a valid {type: dimension}.

It can also be @auto@, in which case the position of the margins is
computed automatically to accomodate the various labels/ticks.
EOD
AxisDecorationType =

Now, axes stuff:

CmdType.new('axis-decoration', :tioga_axis_type, <<EOD)
Kinds of decoration on a axis line, such as nothing, lines, ticks, 
tick labels. Possible values:
 * @hidden@ or @off@: no axis at all
 * @line@: only a line
 * @ticks@: only ticks
 * @major@: only major ticks
 * @major-num@: major ticks along with their labels
 * @full@: major ticks and labels + minor ticks
EOD
DimensionType =

Dimensions

CmdType.new('dimension', { :type => :dimension, 
                    :default => :dy }, <<EOD)

A dimension, in absolute units, or in units of text height, figure,
frame or page coordinates. It is in the form 
@value unit@
where @value@ is a number and unit can be one of @pt@,
@bp@, @in@, @cm@ (absolute units, same meaning as in TeX), 
@dy@ (@1.0 dy@ is the height of a text
line), @figure@ or @f@ (for figure coordinates, i.e. the coordinates of the
plot), @frame@ or @F@ (@1.0 frame@ is the full size of the current subplot) and
@page@ or @p@ (@1.0 page@ is the whole height/width of the output file).
EOD
BoxType =

Boxes

CmdType.new('box', :box, <<EOD)
The specification for a box, such as an inset. Specifications vary for
now... 

@todo to be written later on.
EOD
BijectionType =

Coordinate transformations

CmdType.new('bijection', :bijection, <<EOD)
A pair of functions of x specifying a bidirectional coordinate
transformation separated by a double colon (@::@), in the order
@from::to@.

Each of the functions must be valid Ruby code - it is not exactly
mathematical functions, in particular Ruby does not like floats which
are missing digits on either side of the dot : for instance, @.3@ and
@1.@ are not valid. Sorry.

In most of the usual cases, the coordinate transform is an involution,
that is from and to is the same function (this is the case for
a/x). In this case, you can omit the second function.
EOD
LegendGroup =

Now, various commands pertaining to legends

CmdGroup.new('legends', "Legends", <<EOD, 1)
Commands to specify legends and tweak their look.
EOD
NextLegendCommand =
Cmd.new("legend",'-l',"--legend", 
          [ CmdArg.new('text') ]) do |plotmaker, legend|
  plotmaker.curve_generator.legend_provider.current_legend = legend
end
LegendLineCommand =
Cmd.new("legend-line",nil,"--legend-line", 
          [ CmdArg.new('text') ], 
          Styles::FullTextStyleOptions) do |plotmaker, legend, opts|
  l = Legends::LegendLine.new(legend, opts)
  plotmaker.root_object.current_plot.add_legend_item(l)
end
AutoLegendCommand =
Cmd.new("auto-legend",nil,"--auto-legend", 
          [ CmdArg.new('boolean') ]) do |plotmaker, value|
  plotmaker.curve_generator.legend_provider.auto_legend = value
end
LegendStyleOptions =
{
  'dy' => CmdArg.new('dimension'),
  'scale' => CmdArg.new('float'),
  'text_scale' => CmdArg.new('float'),
}
LegendStyleCommand =
Cmd.new("legend-style",nil,"--legend-style", 
          [], LegendStyleOptions) do |plotmaker, options|
  plotmaker.root_object.current_legend_area.
    legend_style.set_from_hash(options)
end
LegendInsideCommand =
Cmd.new("legend-inside", nil, "--legend-inside",
          [ CmdArg.new('aligned-point')],
          LegendStyleOptions) do |plotmaker, point, options|
  l = Legends::LegendArea.new(:inside)
  l.legend_position = point
  plotmaker.root_object.current_plot.legend_area = l
  l.legend_style.set_from_hash(options)
end
PlotCoordinatesGroup =

Now, various commands pertaining to various drawables

CmdGroup.new('coordinates',
"Plot coordinates",
"Plot coordinates", 2)
PlotMarginCommand =
Cmd.new("margin",nil,"--margin", 
          [ CmdArg.new('float') ]) do |plotmaker, margin|
  plotmaker.root_object.current_plot.style.plot_margin = margin
end
CoordinateRelatedCommands =
TODO:

All these commands should be axis-dependent, and not

Various coordinate-related commands:

plot-dependent.

[]
PlotTypesGroup =

The group for chosing plot types.

CmdGroup.new('plot-types',
"Switch between different kinds of plots",
"How to switch between different kinds of plot types", 01)
XYParametricPlotCommand =
Cmd.new("xy-parametric",nil,"--xy-parametric") do |plotmaker|
  plotmaker.curve_generator.current_curves = :xy_parametric
end
XYPlotCommand =
Cmd.new("xy-plot",nil,"--xy-plot") do |plotmaker|
  plotmaker.curve_generator.current_curves = :xy_plot
end
XYZMapCommand =
Cmd.new("xyz-map",nil,"--xyz-map") do |plotmaker|
  plotmaker.curve_generator.current_curves = :xyz_map
end
SubplotsGroup =

The group containing all commands linked to subplots and other insets, frame margin selections…

CmdGroup.new('subplots',
"Subplots and assimilated",
"Subplots and assimilated", 31)
SetFrameMarginsCommand =
Cmd.new("frame-margins",nil,"--frame-margins", 
          [
           CmdArg.new('frame-margins'),
          ]) do |plotmaker, margins|
  
  plotmaker.root_object.current_plot.subframe = margins
end
PaddingCommand =
Cmd.new("padding",nil,"--padding", 
          [
           CmdArg.new('dimension'),
          ]) do |plotmaker, dim|
  
  Styles::PlotStyle.current_plot_style(plotmaker).padding = dim
end
InsetCommand =
Cmd.new("inset",nil,"--inset", 
          [
           CmdArg.new('box'),
          ]) do |plotmaker, box|
  Log::debug { "Starting a subplot with specs #{box.inspect}" }
  subplot = plotmaker.root_object.subplot
  subplot.subframe = box
end
NextInsetCommand =
Cmd.new("next-inset",nil,"--next-inset", 
          [
           CmdArg.new('box'),
          ]) do |plotmaker, box|
  plotmaker.root_object.leave_subobject
  subplot = plotmaker.root_object.subplot
  subplot.subframe = box
end
EndCommand =
Cmd.new("end",nil,"--end", 
          []) do |plotmaker|
  plotmaker.root_object.leave_subobject
end
RegionOptions =
{
  'color' => CmdArg.new('color'),
  'transparency' => CmdArg.new('float'),
  'reversed_color' => CmdArg.new('color'),
  'reversed_transparency' => CmdArg.new('float'),
}
RegionCommand =
Cmd.new("region",nil,"--region", 
          [ ], RegionOptions) do |plotmaker, options|
  r = plotmaker.root_object.enter_region
  r.set_from_hash(options)
end
GradientCommand =
Cmd.new("gradient",nil,"--gradient", 
          [CmdArg.new('color'), CmdArg.new('color') ], {}) do |plotmaker, s, e, options|
  r = plotmaker.root_object.enter_gradient
  r.start_color = s
  r.end_color = e
  r.set_from_hash(options)
end
RescaleCommand =
Cmd.new("plot-scale",nil,"--plot-scale", 
          [CmdArg.new('float')], 
          {'what' => CmdArg.new('text')}) do |plotmaker, scale, options|
  what = options['what'] || 'text'
  case what
  when /text/i
    Styles::PlotStyle.current_plot_style(plotmaker).text_scale = scale
  when /lines/i
    Styles::PlotStyle.current_plot_style(plotmaker).lines_scale = scale
  when /both/i
    Styles::PlotStyle.current_plot_style(plotmaker).text_scale = scale
    Styles::PlotStyle.current_plot_style(plotmaker).lines_scale = scale
  else
    CTioga2::Log::error { "Unkown 'what' option for plot-scale: #{what}" }
  end
end
SetupGridOptions =

Options for the SetupGrid command:

{}
SetupGridCommand =
Cmd.new('setup-grid', nil, '--setup-grid', 
          [ CmdArg.new('text') ], SetupGridOptions
          ) do |plotmaker, nup, options|
  grd = Types::GridLayout.new(nup)
  for f in %w(left right top bottom)
    if options.key? f
      grd.outer_margins[f] = options[f]
    end
  end
  grd.delta_x = options['dx'] if options['dx']
  grd.delta_y = options['dy'] if options['dy']
  Types::GridLayout.current_grid = grd
end
ZoomCommand =
Cmd.new("zoom-inset",nil,"--zoom-inset", 
          [
           CmdArg.new('box'),
          ]) do |plotmaker, box|
  subplot = plotmaker.root_object.subplot
  subplot.subframe = box
  raise YetUnimplemented.new("zooms are not yet implemented !")
end