ctioga2 0.6.1 → 0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -22,7 +22,7 @@ require 'shellwords'
22
22
  # This module contains all the classes used by ctioga
23
23
  module CTioga2
24
24
 
25
- Version::register_svn_info('$Revision: 391 $', '$Date: 2013-03-14 11:04:36 +0100 (Thu, 14 Mar 2013) $')
25
+ Version::register_svn_info('$Revision: 531 $', '$Date: 2013-09-29 00:07:44 +0200 (Sun, 29 Sep 2013) $')
26
26
 
27
27
  module Graphics
28
28
 
@@ -83,6 +83,22 @@ module CTioga2
83
83
  @options = options
84
84
  end
85
85
 
86
+ undef :clipped, :clipped=
87
+
88
+ def clipped
89
+ if @options.key? 'clipped'
90
+ return @options['clipped']
91
+ else
92
+ return true # Defaults to clipped
93
+ end
94
+ end
95
+
96
+ undef :depth, :depth=
97
+
98
+ def depth
99
+ @options['depth'] || 50
100
+ end
101
+
86
102
  @known_primitives = {}
87
103
 
88
104
  PrimitiveCommands = {}
@@ -111,7 +127,9 @@ module CTioga2
111
127
  CmdArg.new(v)
112
128
  end
113
129
  end
114
-
130
+
131
+ cmd_opts['clipped'] = CmdArg.new('boolean')
132
+ cmd_opts['depth'] = CmdArg.new('integer')
115
133
  cmd = Cmd.new("draw-#{name}",nil,"--draw-#{name}",
116
134
  cmd_args, cmd_opts) do |plotmaker, *rest|
117
135
  options = rest.pop
@@ -16,7 +16,7 @@ require 'ctioga2/log'
16
16
 
17
17
  module CTioga2
18
18
 
19
- Version::register_svn_info('$Revision: 329 $', '$Date: 2012-12-11 00:13:17 +0100 (Tue, 11 Dec 2012) $')
19
+ Version::register_svn_info('$Revision: 540 $', '$Date: 2013-10-04 00:05:23 +0200 (Fri, 04 Oct 2013) $')
20
20
 
21
21
  module Graphics
22
22
 
@@ -132,6 +132,24 @@ module CTioga2
132
132
  end
133
133
 
134
134
 
135
+ def clip_and_plot(t, elements)
136
+ clusters = Utils::cluster_by_value(elements, :clipped)
137
+
138
+ for clst in clusters
139
+ t.context do
140
+ if clst[0].clipped
141
+ t.clip_to_frame
142
+ end
143
+ for element in clst
144
+ t.context do
145
+ t.set_bounds(get_el_boundaries(element).to_a)
146
+ element.do(t)
147
+ end
148
+ end
149
+ end
150
+ end
151
+ end
152
+
135
153
 
136
154
  # Plots all the objects inside the plot.
137
155
  def real_do(t)
@@ -151,24 +169,44 @@ module CTioga2
151
169
  # Manually creating the plot:
152
170
  t.set_bounds(real_boundaries.to_a)
153
171
 
172
+ # First, gather up all elements by depth
173
+
174
+ els_by_depth = Utils::sort_by_value(@elements, :depth)
175
+
176
+ background = []
177
+ mid = []
178
+ fore = []
179
+
180
+ # Organize by depth
181
+ for depth in els_by_depth.keys.sort.reverse
182
+ v = els_by_depth[depth]
183
+ if depth && (depth >= 90)
184
+ background += v
185
+ elsif depth && depth <= 10
186
+ fore += v
187
+ else
188
+ mid += v
189
+ end
190
+ end
191
+
154
192
  # Drawing the background elements:
193
+
194
+ clip_and_plot(t, background)
195
+
155
196
  t.context do
156
197
  t.clip_to_frame
157
198
 
158
199
  @style.background.draw_background(t)
159
200
 
160
201
  @style.draw_all_background_lines(t)
161
- i = 0
162
- for element in @elements
163
- t.context do
164
- t.set_bounds(get_el_boundaries(element).to_a)
165
- element.do(t)
166
- end
167
- i += 1
168
- end
169
202
  end
203
+
204
+ clip_and_plot(t, mid)
205
+
170
206
  @style.draw_all_axes(t, @computed_boundaries)
171
207
 
208
+ clip_and_plot(t, fore)
209
+
172
210
  # Now drawing legends:
173
211
  if @legend_area
174
212
  a, b = @legend_area.partition_frame(t, self)
@@ -26,14 +26,11 @@ module CTioga2
26
26
  module Elements
27
27
 
28
28
  # This class displays a XYZ element using contour lines.
29
- class XYZContour < TiogaElement
29
+ class XYZContour < PlotBasedElement
30
30
 
31
31
  include Log
32
32
  include Dobjects
33
33
 
34
- # The Data::Dataset object that should get plotted.
35
- attr_accessor :dataset
36
-
37
34
  # A Styles::CurveStyle object saying how the curve should be
38
35
  # drawn.
39
36
  #
@@ -44,7 +41,6 @@ module CTioga2
44
41
  attr_accessor :table
45
42
 
46
43
 
47
- undef :location=, :location
48
44
 
49
45
  # Creates a new XYZContour object with the given _dataset_ and
50
46
  # _style_.
@@ -63,11 +59,6 @@ module CTioga2
63
59
 
64
60
  protected :prepare_data
65
61
 
66
- # Returns the LocationStyle object of the curve. Returns the
67
- # one from #curve_style.
68
- def location
69
- return @curve_style.location
70
- end
71
62
 
72
63
  # Returns the Types::Boundaries of this curve.
73
64
  def get_boundaries
@@ -19,7 +19,7 @@ require 'Dobjects/Function'
19
19
 
20
20
  module CTioga2
21
21
 
22
- Version::register_svn_info('$Revision: 198 $', '$Date: 2010-11-30 00:48:23 +0100 (Tue, 30 Nov 2010) $')
22
+ Version::register_svn_info('$Revision: 535 $', '$Date: 2013-10-02 20:31:21 +0200 (Wed, 02 Oct 2013) $')
23
23
 
24
24
  module Graphics
25
25
 
@@ -30,26 +30,15 @@ module CTioga2
30
30
  #
31
31
  # @todo There should be a way to automatically display level
32
32
  # lines, and possibly only that.
33
- class XYZMap < TiogaElement
33
+ class XYZMap < PlotBasedElement
34
34
 
35
35
  include Log
36
36
  include Dobjects
37
37
 
38
- # The Data::Dataset object that should get plotted.
39
- attr_accessor :dataset
40
-
41
- # A Styles::CurveStyle object saying how the curve should be
42
- # drawn.
43
- #
44
- # Some of the elements will be overridden.
45
- attr_accessor :curve_style
46
-
47
38
  # The IndexedTable object representing the underlying data
48
39
  attr_accessor :table
49
40
 
50
41
 
51
- undef :location=, :location
52
-
53
42
  # Creates a new XYZMap object with the given _dataset_ and
54
43
  # _style_.
55
44
  def initialize(dataset, style = nil)
@@ -65,12 +54,6 @@ module CTioga2
65
54
 
66
55
  protected :prepare_data
67
56
 
68
- # Returns the LocationStyle object of the curve. Returns the
69
- # one from #curve_style.
70
- def location
71
- return @curve_style.location
72
- end
73
-
74
57
  # Returns the Types::Boundaries of this curve.
75
58
  def get_boundaries
76
59
  return @table.xy_boundaries
@@ -16,9 +16,12 @@ require 'ctioga2/log'
16
16
 
17
17
  require 'ctioga2/graphics/coordinates'
18
18
 
19
+ require 'ctioga2/graphics/styles/base'
20
+ require 'ctioga2/graphics/styles/plot-types'
21
+
19
22
  module CTioga2
20
23
 
21
- Version::register_svn_info('$Revision: 481 $', '$Date: 2013-09-01 12:08:37 +0200 (Sun, 01 Sep 2013) $')
24
+ Version::register_svn_info('$Revision: 513 $', '$Date: 2013-09-19 00:43:28 +0200 (Thu, 19 Sep 2013) $')
22
25
 
23
26
  module Graphics
24
27
 
@@ -41,11 +44,22 @@ module CTioga2
41
44
  # The current kind of generated. It is a symbol
42
45
  attr_accessor :current_curves
43
46
 
47
+ # Information used for the various curve types. They are not
48
+ # strictly speaking curve styles or would simply clutter the
49
+ # overall curve styles with many meaningless
50
+ # parameters/options. They therefore belong here.
51
+
52
+ # A ParametricPlotStyle object handling the style of the
53
+ # parametric plots.
54
+ attr_accessor :xy_parametric_parameters
55
+
44
56
  # Creates a CurveGenerator object.
45
57
  def initialize
46
58
  @legend_provider = Legends::LegendProvider.new
47
59
  @style_factory = Styles::CurveStyleFactory.new
48
60
  @current_curves = :xy_plot
61
+
62
+ @xy_parametric_parameters = Styles::ParametricPlotStyle.new
49
63
  end
50
64
 
51
65
  PlotOptions = {
@@ -105,8 +119,8 @@ module CTioga2
105
119
  style.legend ||= legend # The legend specified as option to
106
120
  # the --plot command has precedence
107
121
  # over the one specified by --legend.
108
- curve = Graphics::Elements::Parametric2D.new(dataset, style)
109
- style
122
+ curve = Graphics::Elements::Parametric2D.
123
+ new(dataset, style, @xy_parametric_parameters.dup)
110
124
  return curve
111
125
  end
112
126
 
@@ -148,8 +162,11 @@ module CTioga2
148
162
 
149
163
 
150
164
  XYParametricPlotCommand =
151
- Cmd.new("xy-parametric",nil,"--xy-parametric") do |plotmaker|
165
+ Cmd.new("xy-parametric",nil,"--xy-parametric",
166
+ [], Styles::ParametricPlotStyle.options_hash) do |plotmaker, opts|
152
167
  plotmaker.curve_generator.current_curves = :xy_parametric
168
+ plotmaker.curve_generator.
169
+ xy_parametric_parameters.set_from_hash(opts)
153
170
  end
154
171
 
155
172
  XYParametricPlotCommand.describe('select XY parametric plots',
@@ -23,6 +23,18 @@ module CTioga2
23
23
 
24
24
  # All the styles
25
25
  module Styles
26
+ BoxShapeRE = {
27
+ /^square$/i => :square,
28
+ /^round(ed)?$/i => :round,
29
+ }
30
+
31
+ BoxShape =
32
+ CmdType.new('box-shape', {:type => :re_list,
33
+ :list => BoxShapeRE}, <<EOD)
34
+ The shape of a box. It can be:
35
+ * @square@ for a plain square box
36
+ * @round@ for a rounded box
37
+ EOD
26
38
 
27
39
  # This class represents styles attached to a box
28
40
  #
@@ -31,6 +43,55 @@ module CTioga2
31
43
 
32
44
  sub_style 'fill', FillStyle
33
45
 
46
+ typed_attribute 'shape', 'box-shape'
47
+
48
+ # Radius of rounded box
49
+ typed_attribute 'radius', 'dimension'
50
+
51
+ def initialize
52
+ @shape = :square
53
+ @radius = Types::Dimension::new(:dy, 1.0)
54
+ end
55
+
56
+ def prepare_path(t, x1, y1, x2, y2)
57
+ case @shape
58
+ when :square
59
+ t.append_rect_to_path(x1, y1, x2 - x1, y2 - y1)
60
+ when :round
61
+ dx = @radius.to_figure(t, :x)
62
+ dy = @radius.to_figure(t, :y)
63
+
64
+ xl = x1
65
+ xr = x2
66
+ xl,xr = xr, xl if xl > xr
67
+
68
+ yt = y1
69
+ yb = y2
70
+ yb,yt = yt,yb if yb > yt
71
+
72
+ t.move_to_point(xl, yt - dy)
73
+ t.append_curve_to_path(xl, yt - 0.5 * dy, # First control point
74
+ xl + 0.5 * dx, yt,
75
+ xl + dx, yt)
76
+ t.append_point_to_path(xr - dx, yt)
77
+ t.append_curve_to_path(xr - 0.5 * dx, yt,
78
+ xr, yt - 0.5 * dy,
79
+ xr, yt - dy)
80
+
81
+ t.append_point_to_path(xr, yb + dy)
82
+ t.append_curve_to_path(xr, yb + 0.5 * dy, # First control point
83
+ xr - 0.5 * dx, yb,
84
+ xr - dx, yb)
85
+ t.append_point_to_path(xl + dx, yb)
86
+ t.append_curve_to_path(xl + 0.5 * dx, yb, # First control point
87
+ xl, yb + 0.5 * dy,
88
+ xl, yb + dy)
89
+ t.close_path
90
+ else
91
+ raise "Unknown box shape: #{@shape}"
92
+ end
93
+ end
94
+
34
95
  def draw_box(t, x1, y1, x2, y2)
35
96
  t.context do
36
97
  t.discard_path
@@ -38,12 +99,12 @@ module CTioga2
38
99
  ## @todo Rounded rects!
39
100
  if fill && fill.color
40
101
  fill.setup_fill(t)
41
- t.append_rect_to_path(x1, y1, x2 - x1, y2 - y1)
102
+ prepare_path(t, x1, y1, x2, y2)
42
103
  fill.do_fill(t)
43
104
  end
44
105
  if color
45
106
  set_stroke_style(t)
46
- t.append_rect_to_path(x1, y1, x2 - x1, y2 - y1)
107
+ prepare_path(t, x1, y1, x2, y2)
47
108
  t.stroke
48
109
  end
49
110
  end
@@ -17,7 +17,7 @@ require 'ctioga2/log'
17
17
  # This module contains all the classes used by ctioga
18
18
  module CTioga2
19
19
 
20
- Version::register_svn_info('$Revision: 377 $', '$Date: 2013-02-01 12:10:20 +0100 (Fri, 01 Feb 2013) $')
20
+ Version::register_svn_info('$Revision: 540 $', '$Date: 2013-10-04 00:05:23 +0200 (Fri, 04 Oct 2013) $')
21
21
 
22
22
  module Graphics
23
23
 
@@ -255,7 +255,7 @@ module CTioga2
255
255
  if last_value + 1 < i
256
256
  (last_value+1).upto(i - 1) do |j|
257
257
  frac = (j - last_value)/(i - last_value + 1.0)
258
- p [last_value, j, i, frac]
258
+ # p [last_value, j, i, frac]
259
259
  z_values[j] = z_values[last_value] * frac +
260
260
  z_values[i] * (1 - frac)
261
261
  end
@@ -17,7 +17,7 @@ require 'ctioga2/log'
17
17
  # This module contains all the classes used by ctioga
18
18
  module CTioga2
19
19
 
20
- Version::register_svn_info('$Revision: 416 $', '$Date: 2013-08-23 00:35:49 +0200 (Fri, 23 Aug 2013) $')
20
+ Version::register_svn_info('$Revision: 531 $', '$Date: 2013-09-29 00:07:44 +0200 (Sun, 29 Sep 2013) $')
21
21
 
22
22
  module Graphics
23
23
 
@@ -52,6 +52,12 @@ module CTioga2
52
52
  # the filled region.
53
53
  typed_attribute :region_position, "region-side"
54
54
 
55
+ # Wether that element is clipped or not.
56
+ typed_attribute :clipped, 'boolean'
57
+
58
+ # The depth.
59
+ typed_attribute :depth, 'integer'
60
+
55
61
  # A path style.
56
62
  #
57
63
  # @todo Ideas for a path style include
@@ -79,6 +85,11 @@ module CTioga2
79
85
  # A colormap for markers (only for XYZ data)
80
86
  typed_attribute :marker_color_map, 'colormap'
81
87
 
88
+ # If this is specified when choosing the marker scale as a
89
+ # function of a given Z value, then the original Z segment is
90
+ # mapped to min_scale -> scale.
91
+ typed_attribute :marker_min_scale, 'float-or-false'
92
+
82
93
  # Whether the XY display should split on NaN values (wherever)
83
94
  typed_attribute :split_on_nan, 'boolean'
84
95
 
@@ -92,6 +103,11 @@ module CTioga2
92
103
  # Generator#curve_from_dataset
93
104
  attr_accessor :target
94
105
 
106
+ def initialize()
107
+ @clipped = true
108
+ @depth = 50
109
+ end
110
+
95
111
  # True if a line should be drawn.
96
112
  def has_line?
97
113
  return @line && @line.style
@@ -17,7 +17,7 @@ require 'ctioga2/log'
17
17
  # This module contains all the classes used by ctioga
18
18
  module CTioga2
19
19
 
20
- Version::register_svn_info('$Revision: 489 $', '$Date: 2013-09-03 01:03:12 +0200 (Tue, 03 Sep 2013) $')
20
+ Version::register_svn_info('$Revision: 531 $', '$Date: 2013-09-29 00:07:44 +0200 (Sun, 29 Sep 2013) $')
21
21
 
22
22
  module Graphics
23
23
 
@@ -246,7 +246,8 @@ module CTioga2
246
246
  'line_style' => LineStyles::Solid,
247
247
  'marker_marker' => false,
248
248
  'marker_scale' => 0.5,
249
- 'fill_color' => '=color'.to_sym
249
+ 'fill_color' => '=color'.to_sym,
250
+ 'error_bar_color' => '=marker_color'.to_sym
250
251
  }
251
252
  @parameters_carrays = {}
252
253
  for target, param in self.class.parameters
@@ -336,6 +337,8 @@ module CTioga2
336
337
 
337
338
  simple_parameter 'marker_scale', "marker scale", Sets::LineWidthSets
338
339
 
340
+ simple_parameter 'marker_min_scale', "marker scale", nil
341
+
339
342
  # Error bars:
340
343
  simple_parameter 'error_bar_color', "error bar color",
341
344
  Sets::ColorSets
@@ -353,6 +356,10 @@ module CTioga2
353
356
 
354
357
  simple_parameter 'fill_color', "fill color", Sets::ColorSets
355
358
 
359
+ simple_parameter 'clipped', "clipped", nil
360
+
361
+ simple_parameter 'depth', "depth", nil
362
+
356
363
  simple_parameter 'fill_transparency', 'fill transparency', {}
357
364
 
358
365
  # Region handling