ctioga2 0.0 → 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. data/Changelog +25 -1
  2. data/lib/ctioga2/commands/commands.rb +13 -2
  3. data/lib/ctioga2/commands/doc/doc.rb +13 -17
  4. data/lib/ctioga2/commands/doc/documentation-commands.rb +14 -1
  5. data/lib/ctioga2/commands/doc/help.rb +136 -25
  6. data/lib/ctioga2/commands/doc/html.rb +56 -4
  7. data/lib/ctioga2/commands/doc/introspection.rb +45 -9
  8. data/lib/ctioga2/commands/doc/man.rb +7 -5
  9. data/lib/ctioga2/commands/doc/markup.rb +39 -12
  10. data/lib/ctioga2/commands/doc/wordwrap.rb +70 -0
  11. data/lib/ctioga2/commands/general-commands.rb +7 -4
  12. data/lib/ctioga2/commands/general-types.rb +27 -12
  13. data/lib/ctioga2/commands/interpreter.rb +2 -2
  14. data/lib/ctioga2/commands/parsers/command-line.rb +9 -5
  15. data/lib/ctioga2/commands/parsers/file.rb +5 -3
  16. data/lib/ctioga2/commands/type.rb +10 -3
  17. data/lib/ctioga2/commands/variables.rb +2 -2
  18. data/lib/ctioga2/data/backends/backend.rb +17 -15
  19. data/lib/ctioga2/data/backends/backends.rb +2 -2
  20. data/lib/ctioga2/data/backends/backends/gnuplot.rb +20 -5
  21. data/lib/ctioga2/data/backends/backends/math.rb +2 -2
  22. data/lib/ctioga2/data/backends/backends/text.rb +112 -17
  23. data/lib/ctioga2/data/backends/description.rb +10 -11
  24. data/lib/ctioga2/data/datacolumn.rb +73 -14
  25. data/lib/ctioga2/data/dataset.rb +305 -9
  26. data/lib/ctioga2/data/filters.rb +49 -1
  27. data/lib/ctioga2/data/indexed-dtable.rb +137 -0
  28. data/lib/ctioga2/data/point.rb +98 -7
  29. data/lib/ctioga2/data/stack.rb +98 -21
  30. data/lib/ctioga2/graphics/coordinates.rb +19 -2
  31. data/lib/ctioga2/graphics/elements.rb +12 -2
  32. data/lib/ctioga2/graphics/elements/containers.rb +14 -2
  33. data/lib/ctioga2/graphics/elements/contour.rb +67 -0
  34. data/lib/ctioga2/graphics/elements/curve2d.rb +103 -42
  35. data/lib/ctioga2/graphics/elements/element.rb +12 -2
  36. data/lib/ctioga2/graphics/elements/gradient-region.rb +94 -0
  37. data/lib/ctioga2/graphics/elements/parametric2d.rb +172 -0
  38. data/lib/ctioga2/graphics/elements/primitive.rb +37 -21
  39. data/lib/ctioga2/graphics/elements/region.rb +143 -0
  40. data/lib/ctioga2/graphics/elements/subplot.rb +92 -32
  41. data/lib/ctioga2/graphics/elements/tangent.rb +99 -0
  42. data/lib/ctioga2/graphics/elements/xyz-map.rb +126 -0
  43. data/lib/ctioga2/graphics/generator.rb +91 -6
  44. data/lib/ctioga2/graphics/legends.rb +26 -21
  45. data/lib/ctioga2/graphics/legends/area.rb +8 -8
  46. data/lib/ctioga2/graphics/legends/items.rb +5 -5
  47. data/lib/ctioga2/graphics/legends/storage.rb +4 -2
  48. data/lib/ctioga2/graphics/root.rb +24 -2
  49. data/lib/ctioga2/graphics/styles.rb +8 -0
  50. data/lib/ctioga2/graphics/styles/axes.rb +49 -23
  51. data/lib/ctioga2/graphics/styles/base.rb +2 -2
  52. data/lib/ctioga2/graphics/styles/carrays.rb +9 -2
  53. data/lib/ctioga2/graphics/styles/colormap.rb +272 -0
  54. data/lib/ctioga2/graphics/styles/curve.rb +64 -4
  55. data/lib/ctioga2/graphics/styles/drawable.rb +68 -9
  56. data/lib/ctioga2/graphics/styles/errorbar.rb +73 -0
  57. data/lib/ctioga2/graphics/styles/factory.rb +133 -17
  58. data/lib/ctioga2/graphics/styles/gradients.rb +60 -0
  59. data/lib/ctioga2/graphics/styles/location.rb +64 -0
  60. data/lib/ctioga2/graphics/styles/map-axes.rb +164 -0
  61. data/lib/ctioga2/graphics/styles/plot.rb +165 -62
  62. data/lib/ctioga2/graphics/styles/sets.rb +14 -1
  63. data/lib/ctioga2/graphics/styles/texts.rb +44 -34
  64. data/lib/ctioga2/graphics/subplot-commands.rb +94 -6
  65. data/lib/ctioga2/graphics/types.rb +113 -35
  66. data/lib/ctioga2/graphics/types/bijection.rb +3 -3
  67. data/lib/ctioga2/graphics/types/boundaries.rb +120 -1
  68. data/lib/ctioga2/graphics/types/dimensions.rb +8 -1
  69. data/lib/ctioga2/graphics/types/grid.rb +196 -0
  70. data/lib/ctioga2/graphics/types/location.rb +228 -0
  71. data/lib/ctioga2/graphics/types/point.rb +2 -2
  72. data/lib/ctioga2/log.rb +18 -18
  73. data/lib/ctioga2/metabuilder/type.rb +15 -3
  74. data/lib/ctioga2/metabuilder/types.rb +2 -2
  75. data/lib/ctioga2/metabuilder/types/coordinates.rb +13 -1
  76. data/lib/ctioga2/metabuilder/types/data.rb +50 -0
  77. data/lib/ctioga2/metabuilder/types/generic.rb +60 -0
  78. data/lib/ctioga2/metabuilder/types/lists.rb +53 -16
  79. data/lib/ctioga2/metabuilder/types/styles.rb +26 -45
  80. data/lib/ctioga2/plotmaker.rb +91 -20
  81. data/lib/ctioga2/postprocess.rb +8 -8
  82. data/lib/ctioga2/utils.rb +23 -4
  83. metadata +107 -75
  84. data/lib/ctioga2/data/merge.rb +0 -43
@@ -17,19 +17,36 @@ require 'ctioga2/log'
17
17
 
18
18
  module CTioga2
19
19
 
20
- Version::register_svn_info('$Revision: 2 $', '$Date: 2009-04-25 14:03:30 +0200 (Sat, 25 Apr 2009) $')
20
+ Version::register_svn_info('$Revision: 177 $', '$Date: 2010-10-25 13:22:39 +0200 (Mon, 25 Oct 2010) $')
21
21
 
22
22
  module Graphics
23
23
 
24
24
  # Deals with transforming the coordinates of all datasets
25
25
  #
26
- # TODO:
26
+ # \todo
27
27
  # * offsets
28
28
  # * scales
29
29
  # * x/y log
30
30
  # * non-linear transformations ?
31
31
  # * the possibility to provide locations using this.
32
32
  # * conversion of datasets.
33
+ #
34
+ # \todo Shouldn't this facility be axis-local ? Non-linear
35
+ # transformations definitely belong there as well (and that would
36
+ # be almost trivial to write !).
37
+ #
38
+ # @todo For now, this is a mess: these things completely mess up
39
+ # the data processing... This is a complex problem:
40
+ #
41
+ # * if the Dataset are modified in place, this is a nightmare for
42
+ # data processing
43
+ #
44
+ # * on the other hand, if they are not modified in place, this
45
+ # means that things that work on data sets and show things on
46
+ # the plot (think TangentPrimitive, for instance) will have to
47
+ # do additional things to get the target coordinates. This is
48
+ # probably the best way to go, though... This would need some
49
+ # functions to work directly on XY coordinates.
33
50
  class CoordinateTransforms
34
51
 
35
52
  # A scaling factor for coordinates:
@@ -16,12 +16,19 @@ require 'ctioga2/graphics/types'
16
16
  require 'ctioga2/graphics/elements/element'
17
17
  require 'ctioga2/graphics/elements/containers'
18
18
  require 'ctioga2/graphics/elements/subplot'
19
+ require 'ctioga2/graphics/elements/region'
20
+ require 'ctioga2/graphics/elements/gradient-region'
19
21
  require 'ctioga2/graphics/elements/curve2d'
22
+ require 'ctioga2/graphics/elements/parametric2d'
23
+ require 'ctioga2/graphics/elements/xyz-map'
20
24
  require 'ctioga2/graphics/elements/primitive'
21
25
 
26
+ require 'ctioga2/graphics/elements/tangent'
27
+ require 'ctioga2/graphics/elements/contour'
28
+
22
29
  module CTioga2
23
30
 
24
- Version::register_svn_info('$Revision: 55 $', '$Date: 2009-05-27 00:01:34 +0200 (Wed, 27 May 2009) $')
31
+ Version::register_svn_info('$Revision: 187 $', '$Date: 2010-11-07 11:02:25 +0100 (Sun, 07 Nov 2010) $')
25
32
 
26
33
  module Graphics
27
34
 
@@ -44,13 +51,16 @@ EOH
44
51
 
45
52
 
46
53
  # Various coordinate-related commands:
54
+ #
55
+ # @todo All these commands should be axis-dependent, and not
56
+ # plot-dependent.
47
57
  CoordinateRelatedCommands = []
48
58
  [:x, :y].each do |x|
49
59
  cmd =
50
60
  Cmd.new("#{x}range",nil,"--#{x}range",
51
61
  [ CmdArg.new('partial-float-range') ]) do |plotmaker, range|
52
62
  plotmaker.root_object.current_plot.
53
- user_boundaries.set_from_range(range, x)
63
+ set_user_boundaries(x.to_s,range)
54
64
  end
55
65
  cmd.describe("Sets the #{x.to_s.upcase} range",
56
66
  <<EOH, PlotCoordinatesGroup)
@@ -17,7 +17,7 @@ require 'ctioga2/log'
17
17
 
18
18
  module CTioga2
19
19
 
20
- Version::register_svn_info('$Revision: 38 $', '$Date: 2009-05-07 23:11:55 +0200 (Thu, 07 May 2009) $')
20
+ Version::register_svn_info('$Revision: 155 $', '$Date: 2010-06-21 21:41:32 +0200 (Mon, 21 Jun 2010) $')
21
21
 
22
22
  module Graphics
23
23
 
@@ -70,6 +70,13 @@ module CTioga2
70
70
  return @elements.size
71
71
  end
72
72
 
73
+ # Sometimes, the value of the subframe is _nil_ and determined
74
+ # during the plot. This function is guaranteed to return the
75
+ # correct value. It takes a reference to a FigureMaker object.
76
+ def actual_subframe(t)
77
+ return @subframe
78
+ end
79
+
73
80
  # Adds an element
74
81
  def add_element(element)
75
82
  element.parent = self
@@ -83,6 +90,11 @@ module CTioga2
83
90
  elsif element.is_a? Container
84
91
  add_legend_item(element)
85
92
  end
93
+
94
+ # We call LocationStyle#finalize! if possible
95
+ if(self.respond_to?(:style) and element.respond_to?(:location))
96
+ element.location.finalize!(self.style)
97
+ end
86
98
  end
87
99
 
88
100
 
@@ -91,7 +103,7 @@ module CTioga2
91
103
  @legend_storage.add_item(item)
92
104
  end
93
105
 
94
- # TODO: provide coordinate conversion facilities...
106
+ # \todo provide coordinate conversion facilities...
95
107
 
96
108
  protected
97
109
 
@@ -0,0 +1,67 @@
1
+ # contour.rb: contouring code for XYZ data
2
+ # copyright (c) 2009 by Vincent Fourmond
3
+
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.
8
+
9
+ # This program is distributed in the hope that it will be useful, but
10
+ # WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # General Public License for more details (in the COPYING file).
13
+
14
+
15
+ require 'ctioga2/graphics/elements/primitive'
16
+
17
+ # This module contains all the classes used by ctioga
18
+ module CTioga2
19
+
20
+ Version::register_svn_info('$Revision: 192 $', '$Date: 2010-11-07 18:07:01 +0100 (Sun, 07 Nov 2010) $')
21
+
22
+ module Graphics
23
+
24
+ module Elements
25
+
26
+ module Contours
27
+
28
+ ContoursOptions = {
29
+ 'width' => 'float',
30
+ 'color' => 'color',
31
+ 'style' => 'line-style',
32
+ 'closed' => 'boolean',
33
+ }
34
+
35
+ ## @todo Maybe this cumbersome level/point thing along with the
36
+ # $last_curve_style calls for a context for the primitive, ie
37
+ # which was the state of the dataset/curve stack at the moment
38
+ # when the primitive was drawn ?
39
+ TiogaPrimitiveCall.
40
+ primitive("contour", "contour", [ 'level'],
41
+ ContoursOptions) do |t, level,options|
42
+ options ||= {}
43
+ # table = PlotMaker.plotmaker.data_stack.last.indexed_table
44
+ l, d = *level
45
+ table = d.indexed_table
46
+ contour = table.make_contour(l)
47
+ contour << options['closed']
48
+
49
+ ## @todo This $last_curve_style isn't beautiful.
50
+ ##
51
+ ## Worse, it won't work !
52
+ options['color'] ||= $last_curve_style.line.color
53
+
54
+ stroke_style = Styles::StrokeStyle.from_hash(options, '%s')
55
+
56
+
57
+ t.context do
58
+ stroke_style.set_stroke_style(t)
59
+ t.append_points_with_gaps_to_path(*contour)
60
+ t.stroke
61
+ end
62
+ end
63
+ end
64
+
65
+ end
66
+ end
67
+ end
@@ -1,5 +1,5 @@
1
1
  # curve2d.rb: a 2D curve
2
- # copyright (c) 2006, 2007, 2008, 2009 by Vincent Fourmond
2
+ # copyright (c) 2006, 2007, 2008, 2009, 2010 by Vincent Fourmond
3
3
 
4
4
  # This program is free software; you can redistribute it and/or modify
5
5
  # it under the terms of the GNU General Public License as published by
@@ -19,14 +19,20 @@ require 'Dobjects/Function'
19
19
 
20
20
  module CTioga2
21
21
 
22
- Version::register_svn_info('$Revision: 55 $', '$Date: 2009-05-27 00:01:34 +0200 (Wed, 27 May 2009) $')
22
+ Version::register_svn_info('$Revision: 184 $', '$Date: 2010-11-07 00:44:40 +0100 (Sun, 07 Nov 2010) $')
23
23
 
24
24
  module Graphics
25
25
 
26
26
  module Elements
27
27
 
28
- # A Curve2D object represents a 2D curve, along with its style and so
29
- # on.
28
+ # A Curve2D object represents a 2D curve, along with its style
29
+ # and so on.
30
+ #
31
+ # \todo Put back various stylistic aspects that were present in
32
+ # the old ctioga, such as:
33
+ #
34
+ # * transparency
35
+ # * drawing order
30
36
  class Curve2D < TiogaElement
31
37
 
32
38
  include Log
@@ -36,6 +42,9 @@ module CTioga2
36
42
  # the sake of manipulations.
37
43
  attr_accessor :function
38
44
 
45
+ # Elements of the path, when there are more than one:
46
+ attr_accessor :path_elements
47
+
39
48
  # The Data::Dataset object that should get plotted.
40
49
  attr_accessor :dataset
41
50
 
@@ -43,24 +52,36 @@ module CTioga2
43
52
  # drawn.
44
53
  attr_accessor :curve_style
45
54
 
55
+ undef :location=, :location
56
+
46
57
  # Creates a new Curve2D object with the given _dataset_ and
47
58
  # _style_.
48
59
  def initialize(dataset, style = nil)
49
60
  @dataset = dataset
50
61
  if @dataset.size > 2
51
- warn "Columns Y2 and further were ignored for set #{dataset.name}"
62
+ warn { "Columns Y2 and further were ignored for set #{dataset.name}" }
52
63
  end
53
64
  # We build the function on a duplicate of the values ?
54
65
  @function = Function.new(@dataset.x.values.dup,
55
66
  @dataset.y.values.dup)
67
+ @curve_style = style
56
68
 
57
- # We remove NaN, as they are not very liked by Tioga...
58
- #
59
- # TODO: maybe there should be a way to *split* on NaN rather
60
- # than to ignore them ?
69
+ # Preparation of the subpath elements
70
+ if @curve_style.split_on_nan
71
+ # This requires Tioga r601 !
72
+ @path_elements = @function.split_on_nan(:xy)
73
+ info { "Dividing into #{@path_elements.size} subpaths" }
74
+ else
75
+ @path_elements = [@function]
76
+ end
61
77
  @function.strip_nan
62
78
 
63
- @curve_style = style
79
+ end
80
+
81
+ # Returns the LocationStyle object of the curve. Returns the
82
+ # one from #curve_style.
83
+ def location
84
+ return @curve_style.location
64
85
  end
65
86
 
66
87
  # Returns the Types::Boundaries of this curve.
@@ -74,16 +95,34 @@ module CTioga2
74
95
  # the current path, not attempt to create a new path or empty
75
96
  # what was done before.
76
97
  def make_path(t)
77
- bnds = parent.real_boundaries
78
- # if @style.interpolate
79
- # for f in @function.split_monotonic
80
- # new_f = f.bound_values(*bnds.to_a)
81
- # t.append_interpolant_to_path(f.make_interpolant)
82
- # end
83
- # else
84
- f = @function.bound_values(*bnds.extrema)
85
- t.append_points_to_path(f.x, f.y)
86
- # end
98
+ bnds = parent.get_el_boundaries(self)
99
+
100
+ for func in @path_elements
101
+ case @curve_style.path_style
102
+ when /splines/
103
+ for f in func.split_monotonic
104
+ new_f = f.bound_values(*bnds.extrema)
105
+ t.append_interpolant_to_path(new_f.make_interpolant)
106
+ end
107
+ else
108
+ f = func.bound_values(*bnds.extrema)
109
+ t.move_to_point(f.x.first, f.y.first)
110
+ t.append_points_to_path(f.x[1..-1], f.y[1..-1])
111
+ end
112
+ end
113
+
114
+ end
115
+
116
+
117
+ # Adds a closed path to the given FigureMaker object. The path
118
+ # is closed according to the specification given as _fv_,
119
+ # which is the same as the _y0_ attribute of a CurveFillStyle.
120
+ #
121
+ # It must not be _false_
122
+ def make_closed_path(t, fv)
123
+ y0 = fill_value_to_y(fv)
124
+ make_path(t)
125
+ close_path(t, y0)
87
126
  end
88
127
 
89
128
  # Strokes the path.
@@ -114,39 +153,61 @@ module CTioga2
114
153
  t.close_path
115
154
  end
116
155
 
156
+ # Returns the AxisSyle objects for the X and Y axes as an array.
157
+ def get_axes
158
+ return [
159
+ parent.style.get_axis_style(@curve_style.xaxis),
160
+ parent.style.get_axis_style(@curve_style.yaxis)
161
+ ]
162
+ end
163
+
117
164
  # Draws the filled region according to the :fill_type element
118
165
  # of the style pseudo-hash. It can be:
119
166
  def draw_fill(t)
120
- # y = y_value(@style.fill_type)
121
- # return unless y
122
-
123
- # t.fill_transparency = @style.fill_transparency || 0
124
- # # Now is the tricky part. To do the actual fill, we first make a
125
- # # path according to the make_path function.
126
- # make_path(t)
127
-
128
- # # Then we add two line segments that go from the end to the
129
- # # beginning.
130
- # close_path(t, y)
131
-
132
- # # Now the path is ready. Just strike -- or, rather, fill !
133
- # t.fill_color = @style.fill_color
134
- # t.fill
167
+ return unless @curve_style.fill.y0
168
+ t.context do
169
+ # Remember: first setup_fill, then draw path, then do_fill
170
+ @curve_style.fill.setup_fill(t)
171
+ make_closed_path(t,@curve_style.fill.y0)
172
+ @curve_style.fill.do_fill(t)
173
+ end
135
174
  end
136
175
 
176
+ def draw_errorbars(t)
177
+ return unless @dataset.has_xy_errors?
178
+ @dataset.each_values(true, true) do |*vals|
179
+ @curve_style.error_bar.show_error_bar(t, *(vals[1..6]))
180
+ end
181
+ end
182
+
183
+ ## Actually draws the curve
137
184
  def real_do(t)
138
- debug "Plotting curve #{inspect}"
185
+ debug { "Plotting curve #{inspect}" }
139
186
  t.context do
140
- # TODO reinstate the choice of the order of drawing ???
187
+ ## \todo allow customization of the order of drawing,
188
+ ## using a simple user-specificable array of path,
189
+ ## markers... and use the corresponding #draw_path or
190
+ ## #draw_markers... Ideally, any string could be used, and
191
+ ## warnings should be issued on missing symbols.
192
+
193
+ draw_fill(t)
194
+ draw_errorbars(t)
141
195
  draw_path(t)
142
196
  draw_markers(t)
143
- # # The fill is always first
144
- # draw_fill(t)
197
+ end
198
+ end
199
+
200
+ protected
145
201
 
146
- # for op in CurveStyle::DrawingOrder[@style[:drawing_order]]
147
- # self.send("draw_#{op}".to_sym, t)
148
- # end
202
+ # Converts the value of a fill value into a number (or nil)
203
+ def fill_value_to_y(fv)
204
+ return nil unless fv
205
+ case fv
206
+ when :bottom,:top
207
+ bnds = parent.get_el_boundaries(self)
208
+ return bnds.send(fv)
149
209
  end
210
+ return fv
150
211
  end
151
212
 
152
213
  end
@@ -18,7 +18,7 @@ require 'ctioga2/log'
18
18
  # This module contains all the classes used by ctioga
19
19
  module CTioga2
20
20
 
21
- Version::register_svn_info('$Revision: 54 $', '$Date: 2009-05-20 20:21:11 +0200 (Wed, 20 May 2009) $')
21
+ Version::register_svn_info('$Revision: 151 $', '$Date: 2010-06-19 23:45:20 +0200 (Sat, 19 Jun 2010) $')
22
22
 
23
23
  # This module contains all graphical elements of CTioga2
24
24
  module Graphics
@@ -34,12 +34,22 @@ module CTioga2
34
34
  # The parent Container.
35
35
  attr_accessor :parent
36
36
 
37
+ # Details pertaining to the location of the object, as a
38
+ # LocationStyle object
39
+ attr_writer :location
40
+
41
+ # Makes sure there is a location when one asks for it.
42
+ def location
43
+ @location ||= Styles::LocationStyle.new
44
+ return @location
45
+ end
46
+
37
47
  # This function must be called with a FigureMaker object to
38
48
  # draw the contents of the TiogaElement onto it. It calls
39
49
  # #real_do, which should be redefined by the children. You can
40
50
  # redefine _do_ too if you need another debugging output.
41
51
  def do(f)
42
- debug "plotting #{self.inspect}"
52
+ debug { "plotting #{self.inspect}" }
43
53
  real_do(f)
44
54
  end
45
55
 
@@ -0,0 +1,94 @@
1
+ # region.rb: draw curves-delimited fills
2
+ # copyright (c) 2010 by Vincent Fourmond
3
+
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.
8
+
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).
13
+
14
+
15
+ require 'ctioga2/utils'
16
+ require 'ctioga2/log'
17
+
18
+ module CTioga2
19
+
20
+ Version::register_svn_info('$Revision: 159 $', '$Date: 2010-07-26 17:29:47 +0200 (Mon, 26 Jul 2010) $')
21
+
22
+ module Graphics
23
+
24
+ module Elements
25
+
26
+ # A GradientRegion is an object that makes color gradient for
27
+ # the curves. Especially useful for a great number of curves,
28
+ # and when one doesn't want to compute...
29
+ #
30
+ #
31
+ #
32
+ # Like Region It is a fake container in the sense that all the
33
+ # elements are actually forwarded to the parent.
34
+ class GradientRegion < Container
35
+
36
+ undef :elements
37
+ undef :subframe
38
+
39
+ # The curves which delimit the region
40
+ attr_accessor :curves
41
+
42
+ # The start and end colors
43
+ attr_accessor :start_color, :end_color
44
+
45
+ # Creates a new empty region
46
+ def initialize(parent = nil, root = nil)
47
+ @parent = parent
48
+
49
+ # The curves whose color we should change
50
+ @curves = []
51
+
52
+ @root_object = root
53
+
54
+ @legend_area = nil
55
+
56
+ @start_color = Tioga::ColorConstants::Red
57
+ @end_color = Tioga::ColorConstants::Green
58
+
59
+ end
60
+
61
+ # Adds an element. Actually forwards it to the parent.
62
+ def add_element(element)
63
+ parent.add_element(element)
64
+ if element.respond_to?(:curve_style)
65
+ @curves << element
66
+ end
67
+ end
68
+
69
+ # Sets the various things from hash.
70
+ def set_from_hash(hash)
71
+ end
72
+
73
+ # Redirects to the parent's style
74
+ def style(*a)
75
+ return parent.style(*a)
76
+ end
77
+
78
+ protected
79
+
80
+ # Simply sets the color of the curves.
81
+ def real_do(t)
82
+ nb = @curves.size
83
+ i = 0
84
+ for c in @curves
85
+ c.curve_style.line.color =
86
+ Utils::mix_objects(@end_color,@start_color, i/(nb - 1.0))
87
+ i += 1
88
+ end
89
+ end
90
+
91
+ end
92
+ end
93
+ end
94
+ end