class CTioga2::Graphics::CurveGenerator

This class is in charge of generating Elements::TiogaElement, such as Elements::Curve2D, from a dataset. It takes care of generating the appropriate style and of transforming the coordinates.

Constants

PlotOptions

Attributes

current_curves[RW]

The current kind of generated. It is a symbol

histogram_parameters[RW]

Style of histograms

legend_provider[RW]

The provider of legends, a Legends::LegendProvider object.

style_factory[RW]

A Styles::CurveStyleFactory object that handles the styles for every single curve that will be drawn.

xy_parametric_parameters[RW]

A ParametricPlotStyle object handling the style of the parametric plots.

Public Class Methods

new() click to toggle source

Creates a CurveGenerator object.

# File lib/ctioga2/graphics/generator.rb, line 60
def initialize
  @legend_provider = Legends::LegendProvider.new
  @style_factory = Styles::CurveStyleFactory.new
  @current_curves = :xy_plot

  @xy_parametric_parameters = Styles::ParametricPlotStyle.new
  @histogram_parameters = Styles::HistogramStyle.new
end

Public Instance Methods

curve_from_dataset(plot, dataset, options = {}) click to toggle source

Creates a Elements::TiogaElement representing the dataset and returns it.

todo

  • other kinds of coordinate transformations

  • other kinds of curves (pseudo-3D, surfaces, histograms…)

# File lib/ctioga2/graphics/generator.rb, line 80
def curve_from_dataset(plot, dataset, options = {})
  # Does coordinate transforms first ?
  # @todo copy datasets here rather than overwriting them !
  #   -> this should be an option !
  if ! options['bypass-transforms']
    plot.style.apply_transforms!(dataset)
  end

  old_opts = options.dup
  # Now, we trim options unrelated to the plotting
  options.delete_if { |k,v|
    ! Graphics::Styles::CurveStyleFactory::PlotCommandOptions.key?(k)
  }

  begin
    legend = @legend_provider.dataset_legend(dataset)
    style = @style_factory.next(options)
    style.legend ||= legend # The legend specified as option to
                            # the --plot command has precedence
                            # over the one specified by
                            # --legend.
    curve = send(@current_curves, dataset, style)

    # Here, we update the style from the stylesheet and then
    # again from the options, so that the options provided on
    # the command-line take precedence.
    curve.setup_style(plot, old_opts)
    curve.update_style(curve.curve_style)
    curve.curve_style.
      set_from_hash(@style_factory.hash_name_to_target(options))

    curve.curve_style.target = curve
  end
  return curve
end

Private Instance Methods

histogram(dataset, style) click to toggle source

The “classical” 2D plots.

# File lib/ctioga2/graphics/generator.rb, line 129
def histogram(dataset, style)
  return Graphics::Elements::Histogram.new(dataset, style, 
                                           @histogram_parameters.dup)
end
xy_parametric(dataset, style) click to toggle source

XYZ plots formerly known as “parametric plots”

# File lib/ctioga2/graphics/generator.rb, line 135
def xy_parametric(dataset, style)
  return Graphics::Elements::Parametric2D.
    new(dataset, style, @xy_parametric_parameters.dup)
end
xy_plot(dataset, style) click to toggle source

The “classical” 2D plots.

# File lib/ctioga2/graphics/generator.rb, line 124
def xy_plot(dataset, style)
  return Graphics::Elements::Curve2D.new(dataset, style)
end
xyz_contour(dataset, style) click to toggle source

XYZ maps

# File lib/ctioga2/graphics/generator.rb, line 147
def xyz_contour(dataset, style)
  style.legend = false    # No legend for XYZ contours
  return Graphics::Elements::XYZContour.new(dataset, style)
end
xyz_map(dataset, style) click to toggle source

XYZ maps

# File lib/ctioga2/graphics/generator.rb, line 141
def xyz_map(dataset, style)
  style.legend = false    # No legend for XYZ maps
  return Graphics::Elements::XYZMap.new(dataset, style)
end