1
# root.rb: the root object for creating a plot.
2
# copyright (c) 2009 by Vincent Fourmond
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details (in the COPYING file).
14
require 'ctioga2/utils'
17
require 'ctioga2/graphics/coordinates'
21
Version::register_svn_info('$Revision: 244 $', '$Date: 2011-01-23 23:36:02 +0100 (Sun, 23 Jan 2011) $')
25
# This class is in charge of generating Elements::TiogaElement,
26
# such as Elements::Curve2D, from a dataset. It takes care of
27
# generating the appropriate style and of transforming the
31
# A Styles::CurveStyleFactory object that handles the
32
# styles for every single curve that will be drawn.
33
attr_accessor :style_factory
35
# The provider of legends, a Legends::LegendProvider
37
attr_accessor :legend_provider
39
# The current kind of generated. It is a symbol
40
attr_accessor :current_curves
42
# Creates a CurveGenerator object.
44
@legend_provider = Legends::LegendProvider.new
45
@style_factory = Styles::CurveStyleFactory.new
46
@current_curves = :xy_plot
49
# Creates a Elements::TiogaElement representing the _dataset_
53
# * (other kinds of) coordinate transformations
54
# * other kinds of curves (pseudo-3D, surfaces, histograms...)
55
def curve_from_dataset(plot, dataset, options = {})
56
# Does coordinate transforms first ?
57
# \todo copy datasets here rather than overwriting them !
58
plot.style.transforms.transform_2d!(dataset)
60
return send(@current_curves, plot, dataset, options)
65
## \name Available kinds of curves
69
# The "classical" 2D plots.
70
def xy_plot(plot, dataset, options = {})
71
legend = @legend_provider.dataset_legend(dataset)
72
style = @style_factory.next(options)
73
style.legend ||= legend # The legend specified as option to
74
# the --plot command has precedence
75
# over the one specified by --legend.
76
curve = Graphics::Elements::Curve2D.new(dataset, style)
80
# XYZ plots formerly known as "parametric plots"
81
def xy_parametric(plot, dataset, options = {})
82
legend = @legend_provider.dataset_legend(dataset)
83
style = @style_factory.next(options)
85
style.legend ||= legend # The legend specified as option to
86
# the --plot command has precedence
87
# over the one specified by --legend.
88
curve = Graphics::Elements::Parametric2D.new(dataset, style)
93
def xyz_map(plot, dataset, options = {})
94
legend = @legend_provider.dataset_legend(dataset)
95
style = @style_factory.next(options)
97
style.legend ||= legend # The legend specified as option to
98
# the --plot command has precedence
99
# over the one specified by --legend.
100
curve = Graphics::Elements::XYZMap.new(dataset, style)
110
# The group for chosing plot types.
112
CmdGroup.new('plot-types',
113
"Switch between different kinds of plots",
114
"How to switch between different kinds of plot types", 01)
117
XYParametricPlotCommand =
118
Cmd.new("xy-parametric",nil,"--xy-parametric") do |plotmaker|
119
plotmaker.curve_generator.current_curves = :xy_parametric
122
XYParametricPlotCommand.describe('select XY parametric plots',
123
<<EOH, PlotTypesGroup)
124
Switch to XY parametric plots, that is standard XY plots whose appearance
125
(such as color, marker color, and, potentially, marker kinds and more)
126
are governed by one (or more ?) Z values.
130
Cmd.new("xy-plot",nil,"--xy-plot") do |plotmaker|
131
plotmaker.curve_generator.current_curves = :xy_plot
134
XYPlotCommand.describe('select XY plots',
135
<<EOH, PlotTypesGroup)
136
Switch (back) to standard XY plots (ctioga\'s default)
140
Cmd.new("xyz-map",nil,"--xyz-map") do |plotmaker|
141
plotmaker.curve_generator.current_curves = :xyz_map
144
XYZMapCommand.describe('select XYZ maps',
145
<<EOH, PlotTypesGroup)
146
Switch to XYZ maps, ie plots where the color at a XY location is given by