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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCurveGenerator

Creates a CurveGenerator object.



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

def initialize
  @legend_provider = Legends::LegendProvider.new
  @style_factory = Styles::CurveStyleFactory.new
end

Instance Attribute Details

#legend_providerObject

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



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

def legend_provider
  @legend_provider
end

#style_factoryObject

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



33
34
35
# File 'lib/ctioga2/graphics/generator.rb', line 33

def style_factory
  @style_factory
end

Instance Method Details

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

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

TODO:

  • coordinate transformations

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



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/ctioga2/graphics/generator.rb', line 51

def curve_from_dataset(plot, dataset, options = {})
  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.

  # TODO: copy datasets here !
  plot.style.transforms.transform_2d!(dataset)
  curve = Graphics::Elements::Curve2D.new(dataset, style)
  return curve
end