Class: CTioga2::Graphics::CurveGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/ctioga2/graphics/generator.rb

Overview

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.

Constant Summary collapse

PlotOptions =
{ 
  'bypass-transforms' => CmdArg.new('boolean')
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCurveGenerator

Creates a CurveGenerator object.



60
61
62
63
64
65
66
67
# 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

Instance Attribute Details

#current_curvesObject

The current kind of generated. It is a symbol



43
44
45
# File 'lib/ctioga2/graphics/generator.rb', line 43

def current_curves
  @current_curves
end

#histogram_parametersObject

Style of histograms



56
57
58
# File 'lib/ctioga2/graphics/generator.rb', line 56

def histogram_parameters
  @histogram_parameters
end

#legend_providerObject

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



40
41
42
# File 'lib/ctioga2/graphics/generator.rb', line 40

def legend_provider
  @legend_provider
end

#style_factoryObject

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



36
37
38
# File 'lib/ctioga2/graphics/generator.rb', line 36

def style_factory
  @style_factory
end

#xy_parametric_parametersObject

A ParametricPlotStyle object handling the style of the parametric plots.



52
53
54
# File 'lib/ctioga2/graphics/generator.rb', line 52

def xy_parametric_parameters
  @xy_parametric_parameters
end

Instance Method Details

#curve_from_dataset(plot, dataset, options = {}) ⇒ Object

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

todo

  • other kinds of coordinate transformations

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



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# 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