ctioga2 0.5 → 0.6

Sign up to get free protection for your applications and to get access to all the features.
data/Changelog CHANGED
@@ -1,3 +1,20 @@
1
+ ctioga2 (0.6)
2
+
3
+ * Fix various problems related to file names and directories
4
+ * Using command files, path of data files are now taken to be relative
5
+ to the directory in which the command file is located
6
+ * It is now possible to use the ruby construct ( ? : ) in datasets/text
7
+ files
8
+ * Implement the impulses path style
9
+ * Greater control on how to close paths for filling
10
+ * Increase the default size of the text significantly + a
11
+ --set-global-font command to change the default text size
12
+ * Control the position of ticks and the text of tick labels
13
+ * It is now possible to use abs(x) in formulas, rather than the old
14
+ x.abs version (which is still usable !)
15
+
16
+ -- Vincent <vincent.fourmond@9online.fr> Wed 4 Sep 22:18:46 CEST 2013
17
+
1
18
  ctioga2 (0.5)
2
19
 
3
20
  * Choose the side of axis ticks
@@ -17,7 +17,7 @@ require 'ctioga2/commands/parsers/file'
17
17
 
18
18
  module CTioga2
19
19
 
20
- Version::register_svn_info('$Revision: 155 $', '$Date: 2010-06-21 21:41:32 +0200 (Mon, 21 Jun 2010) $')
20
+ Version::register_svn_info('$Revision: 497 $', '$Date: 2013-09-04 22:07:55 +0200 (Wed, 04 Sep 2013) $')
21
21
 
22
22
  module Commands
23
23
 
@@ -57,13 +57,23 @@ EOH
57
57
  # Includes a file
58
58
  RunCommandFile =
59
59
  Cmd.new("include", '-f', "--file",
60
- [ CmdArg.new('file'), ]) do |plotmaker, file|
60
+ [ CmdArg.new('file')],
61
+ {'log' => CmdArg.new('boolean') }
62
+ ) do |plotmaker, file, opts|
63
+ if opts['log']
64
+ tg = file.sub(/(\.ct2)?$/, '-log.txt')
65
+ Log::log_to(tg, "ctioga2 version '#{CTioga2::Version::version}' starting at #{Time.now} to process file: #{file}")
66
+ end
61
67
  plotmaker.interpreter.run_command_file(file)
62
68
  end
63
69
 
64
70
  RunCommandFile.describe("Runs given command file", <<EOH, GeneralGroup)
65
71
  Reads the file and runs commands found in them, using the ctioga language.
72
+
66
73
  > ctioga2 -f my_file.ct2
74
+
75
+ If the @/log@ is on, then all messages are written to a -log.txt file
76
+ instead of to the terminal.
67
77
  EOH
68
78
 
69
79
  # Evaluate a series of commands.
@@ -15,7 +15,7 @@ require 'ctioga2/utils'
15
15
 
16
16
  module CTioga2
17
17
 
18
- Version::register_svn_info('$Revision: 223 $', '$Date: 2011-01-11 01:07:48 +0100 (Tue, 11 Jan 2011) $')
18
+ Version::register_svn_info('$Revision: 484 $', '$Date: 2013-09-02 22:44:42 +0200 (Mon, 02 Sep 2013) $')
19
19
 
20
20
  module Commands
21
21
 
@@ -50,6 +50,29 @@ EOD
50
50
  A floating-point number.
51
51
  EOD
52
52
 
53
+
54
+ FloatList = CmdType.new('float-list',
55
+ {
56
+ :type => :array,
57
+ :subtype => :float,
58
+ :separator => /\s+|\s*,\s*/,
59
+ :separator_out => " "
60
+ }, <<EOD)
61
+ A list of space-separated or comma-separated floating point numbers.
62
+ EOD
63
+
64
+ TextList = CmdType.new('text-list',
65
+ {
66
+ :type => :array,
67
+ :subtype => :string,
68
+ :separator => /\s*,\s*/,
69
+ :alternative_separator => /\s*\|\|\s*/,
70
+ :separator_out => ","
71
+ }, <<EOD)
72
+ A list of comma-separated texts. If you must include a comma inside the
73
+ texts, then use @||@ as a separator.
74
+ EOD
75
+
53
76
  IntegerType = CmdType.new('integer', :integer, <<EOD)
54
77
  An integer.
55
78
  EOD
@@ -21,7 +21,7 @@ require 'ctioga2/commands/doc/doc'
21
21
 
22
22
  module CTioga2
23
23
 
24
- Version::register_svn_info('$Revision: 355 $', '$Date: 2012-12-26 00:19:04 +0100 (Wed, 26 Dec 2012) $')
24
+ Version::register_svn_info('$Revision: 492 $', '$Date: 2013-09-03 21:54:09 +0200 (Tue, 03 Sep 2013) $')
25
25
 
26
26
  # This module contains the real core of ctioga2: a set of classes
27
27
  # that implement the concept of commands. Each command translates
@@ -210,7 +210,12 @@ module CTioga2
210
210
  if ! @plotmaker_target.figure_name
211
211
  @plotmaker_target.figure_name = file.gsub(/\.[^.]+$/,'')
212
212
  end
213
- @file_parser.run_command_file(file, self)
213
+ dir = File::dirname(file)
214
+ base = File::basename(file)
215
+
216
+ Dir::chdir(dir) do
217
+ @file_parser.run_command_file(base, self)
218
+ end
214
219
  end
215
220
 
216
221
  # Parses and runs the given string.
@@ -21,7 +21,7 @@ require 'Dobjects/Function'
21
21
 
22
22
  module CTioga2
23
23
 
24
- Version::register_svn_info('$Revision: 155 $', '$Date: 2010-06-21 21:41:32 +0200 (Mon, 21 Jun 2010) $')
24
+ Version::register_svn_info('$Revision: 451 $', '$Date: 2013-08-29 01:28:30 +0200 (Thu, 29 Aug 2013) $')
25
25
 
26
26
  module Data
27
27
 
@@ -64,8 +64,10 @@ EOD
64
64
  set = $1
65
65
  range = $2
66
66
  end
67
- name = "math: #{set}"
68
- if set =~ /:/ # parametric
67
+ name = "#{set}"
68
+
69
+
70
+ if set.split_at_toplevel(/:/).size > 1 # parametric
69
71
  if range
70
72
  set_param_from_string(:t_range, range)
71
73
  end
@@ -25,7 +25,7 @@ require 'stringio'
25
25
 
26
26
  module CTioga2
27
27
 
28
- Version::register_svn_info('$Revision: 372 $', '$Date: 2012-12-28 18:13:15 +0100 (Fri, 28 Dec 2012) $')
28
+ Version::register_svn_info('$Revision: 493 $', '$Date: 2013-09-03 22:11:38 +0200 (Tue, 03 Sep 2013) $')
29
29
 
30
30
 
31
31
  module Data
@@ -183,10 +183,8 @@ EOD
183
183
  return IO.popen(method % file)
184
184
  end
185
185
  end
186
- return File::open(file)
187
186
  end
188
- error { "Could not open #{file}" }
189
- return nil
187
+ return File::open(file)
190
188
  end
191
189
 
192
190
  # A line is invalid if it is blank or starts
@@ -18,7 +18,7 @@ require 'ctioga2/data/indexed-dtable'
18
18
 
19
19
  module CTioga2
20
20
 
21
- Version::register_svn_info('$Revision: 406 $', '$Date: 2013-08-22 21:23:44 +0200 (Thu, 22 Aug 2013) $')
21
+ Version::register_svn_info('$Revision: 451 $', '$Date: 2013-08-29 01:28:30 +0200 (Thu, 29 Aug 2013) $')
22
22
 
23
23
 
24
24
  # \todo now, port the backend infrastructure...
@@ -87,7 +87,7 @@ module CTioga2
87
87
  def self.dataset_from_spec(name, spec)
88
88
  specs = []
89
89
  i = 0
90
- for s in spec.split(/:/)
90
+ for s in spec.split_at_toplevel(/:/)
91
91
  if s =~ /^(x|y\d*|z)(#{DataColumn::ColumnSpecsRE})=(.*)/i
92
92
  which, mod, s = $1.downcase,($2 && $2.downcase) || "value",$3
93
93
 
@@ -19,7 +19,7 @@ require 'Dobjects/Function'
19
19
 
20
20
  module CTioga2
21
21
 
22
- Version::register_svn_info('$Revision: 184 $', '$Date: 2010-11-07 00:44:40 +0100 (Sun, 07 Nov 2010) $')
22
+ Version::register_svn_info('$Revision: 474 $', '$Date: 2013-08-31 15:05:39 +0200 (Sat, 31 Aug 2013) $')
23
23
 
24
24
  module Graphics
25
25
 
@@ -99,11 +99,17 @@ module CTioga2
99
99
 
100
100
  for func in @path_elements
101
101
  case @curve_style.path_style
102
- when /splines/
102
+ when /^splines/
103
103
  for f in func.split_monotonic
104
104
  new_f = f.bound_values(*bnds.extrema)
105
105
  t.append_interpolant_to_path(new_f.make_interpolant)
106
106
  end
107
+ when /^impulses/
108
+ # We draw lines from y = 0
109
+ for x,y in func
110
+ t.move_to_point(x, 0)
111
+ t.append_point_to_path(x, y)
112
+ end
107
113
  else
108
114
  f = func.bound_values(*bnds.extrema)
109
115
  t.move_to_point(f.x.first, f.y.first)
@@ -119,10 +125,15 @@ module CTioga2
119
125
  # which is the same as the _y0_ attribute of a CurveFillStyle.
120
126
  #
121
127
  # It must not be _false_
122
- def make_closed_path(t, fv)
123
- y0 = fill_value_to_y(fv)
128
+ #
129
+ # @todo Make sure this is called only on sub-plots when
130
+ # splitting on NaN !
131
+ def make_closed_path(t, close_type = nil)
124
132
  make_path(t)
125
- close_path(t, y0)
133
+ close_type ||= @curve_style.fill.close_type
134
+ bnds = parent.get_el_boundaries(self)
135
+ close_type.close_path(t, bnds, @function[0],
136
+ @function[@function.size - 1])
126
137
  end
127
138
 
128
139
  # Strokes the path.
@@ -145,14 +156,6 @@ module CTioga2
145
156
  end
146
157
  end
147
158
 
148
- # A function to close the path created by make_path.
149
- # Overridden in the histogram code.
150
- def close_path(t, y0)
151
- t.append_point_to_path(@function.x.last, y0)
152
- t.append_point_to_path(@function.x.first, y0)
153
- t.close_path
154
- end
155
-
156
159
  # Returns the AxisSyle objects for the X and Y axes as an array.
157
160
  def get_axes
158
161
  return [
@@ -164,11 +167,13 @@ module CTioga2
164
167
  # Draws the filled region according to the :fill_type element
165
168
  # of the style pseudo-hash. It can be:
166
169
  def draw_fill(t)
167
- return unless @curve_style.fill.y0
170
+ return unless (@curve_style.fill &&
171
+ @curve_style.fill.close_type &&
172
+ @curve_style.fill.close_type.fill?)
168
173
  t.context do
169
174
  # Remember: first setup_fill, then draw path, then do_fill
170
175
  @curve_style.fill.setup_fill(t)
171
- make_closed_path(t,@curve_style.fill.y0)
176
+ make_closed_path(t)
172
177
  @curve_style.fill.do_fill(t)
173
178
  end
174
179
  end
@@ -197,18 +202,6 @@ module CTioga2
197
202
  end
198
203
  end
199
204
 
200
- protected
201
-
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)
209
- end
210
- return fv
211
- end
212
205
 
213
206
  end
214
207
  end
@@ -17,7 +17,7 @@ require 'ctioga2/log'
17
17
 
18
18
  module CTioga2
19
19
 
20
- Version::register_svn_info('$Revision: 288 $', '$Date: 2011-02-22 21:12:58 +0100 (Tue, 22 Feb 2011) $')
20
+ Version::register_svn_info('$Revision: 474 $', '$Date: 2013-08-31 15:05:39 +0200 (Sat, 31 Aug 2013) $')
21
21
 
22
22
  module Graphics
23
23
 
@@ -122,14 +122,17 @@ module CTioga2
122
122
  :below => :bottom
123
123
  }
124
124
  end
125
+ closer = Types::FillUntil.new
125
126
  # We clip for the first ones...
126
127
  for c in @curves[0..-2]
127
- c.make_closed_path(t, conversion[c.curve_style.region_position])
128
+ closer.type = conversion[c.curve_style.region_position]
129
+ c.make_closed_path(t, closer)
128
130
  t.clip
129
131
  end
130
132
  # We don't clip on the last one !
131
133
  c = @curves.last
132
- c.make_closed_path(t, conversion[c.curve_style.region_position])
134
+ closer.type = conversion[c.curve_style.region_position]
135
+ c.make_closed_path(t, closer)
133
136
  end
134
137
 
135
138
  end
@@ -18,7 +18,7 @@ require 'ctioga2/graphics/coordinates'
18
18
 
19
19
  module CTioga2
20
20
 
21
- Version::register_svn_info('$Revision: 412 $', '$Date: 2013-08-22 23:04:59 +0200 (Thu, 22 Aug 2013) $')
21
+ Version::register_svn_info('$Revision: 481 $', '$Date: 2013-09-01 12:08:37 +0200 (Sun, 01 Sep 2013) $')
22
22
 
23
23
  module Graphics
24
24
 
@@ -165,8 +165,9 @@ EOH
165
165
  end
166
166
 
167
167
  ContourPlotCommand.describe('select contour plots',
168
- <<EOH, PlotTypesGroup)
169
- ...
168
+ <<EOH, PlotTypesGroup)
169
+ Switch to contour plots for later curves. Contour plots need three
170
+ columns (X,Y,Z). They have major and minor lines.
170
171
  EOH
171
172
 
172
173
  XYPlotCommand =
@@ -16,7 +16,7 @@ require 'ctioga2/log'
16
16
 
17
17
  module CTioga2
18
18
 
19
- Version::register_svn_info('$Revision: 2 $', '$Date: 2009-04-25 14:03:30 +0200 (Sat, 25 Apr 2009) $')
19
+ Version::register_svn_info('$Revision: 471 $', '$Date: 2013-08-31 14:11:01 +0200 (Sat, 31 Aug 2013) $')
20
20
 
21
21
  module Graphics
22
22
 
@@ -45,7 +45,7 @@ module CTioga2
45
45
  @current_legend = nil
46
46
  return l
47
47
  elsif @auto_legend
48
- return dataset.name
48
+ return "\\texttt{#{Utils::tex_quote_string(dataset.name)}}"
49
49
  else
50
50
  return nil
51
51
  end
@@ -28,6 +28,7 @@ require 'ctioga2/graphics/styles/contour'
28
28
  require 'ctioga2/graphics/styles/errorbar'
29
29
 
30
30
  require 'ctioga2/graphics/styles/sets'
31
+ require 'ctioga2/graphics/styles/ticks'
31
32
 
32
33
  require 'ctioga2/graphics/styles/axes'
33
34
  require 'ctioga2/graphics/styles/map-axes'
@@ -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: 435 $', '$Date: 2013-08-26 22:03:19 +0200 (Mon, 26 Aug 2013) $')
20
+ Version::register_svn_info('$Revision: 483 $', '$Date: 2013-09-02 22:10:14 +0200 (Mon, 02 Sep 2013) $')
21
21
 
22
22
  module Graphics
23
23
 
@@ -56,6 +56,9 @@ module CTioga2
56
56
  # The label of the axis, if there is one
57
57
  sub_style :axis_label, TextLabel
58
58
 
59
+ # The axis ticks and labels
60
+ sub_style :ticks, AxisTicks
61
+
59
62
  # Whether the axis should be log scale or not
60
63
  typed_attribute :log, 'boolean'
61
64
 
@@ -74,6 +77,12 @@ module CTioga2
74
77
 
75
78
  typed_attribute :ticks_side, 'ticks-side'
76
79
 
80
+ # @todo Add a 'slave' attribute: axes would be created as
81
+ # slaves to another one until:
82
+ # * a curve is added to it
83
+ # * a transform is set
84
+ # * ticks are set
85
+
77
86
 
78
87
  # Creates a new AxisStyle object at the given location with
79
88
  # the given style.
@@ -86,6 +95,7 @@ module CTioga2
86
95
  @axis_label = TextLabel.new(label)
87
96
  @log = false
88
97
  @ticks_side = {}
98
+ @ticks = AxisTicks.new
89
99
  end
90
100
 
91
101
  # Draws the axis within the current plot. Boundaries are the
@@ -99,6 +109,12 @@ module CTioga2
99
109
  # a transformation)
100
110
  def draw_axis(t)
101
111
  spec = get_axis_specification(t)
112
+
113
+ info = t.axis_information(spec)
114
+
115
+ # Merge in the specs
116
+ spec.merge!(@ticks.ticks_specs(t, info, @transform))
117
+
102
118
  # Add tick label style:
103
119
  spec.merge!(@tick_label_style.hash_for_tioga(t))
104
120
 
@@ -143,6 +159,8 @@ minor_tick_length minor_tick_width)
143
159
  if @background_lines
144
160
  # First, getting major ticks location from tioga
145
161
  info = t.axis_information(get_axis_specification(t))
162
+
163
+ tick_info = @ticks.ticks_specs(t, info, @transform)
146
164
 
147
165
  if info['vertical']
148
166
  x0 = t.bounds_left
@@ -153,7 +171,7 @@ minor_tick_length minor_tick_width)
153
171
  end
154
172
  t.context do
155
173
  @background_lines.set_stroke_style(t)
156
- values = info['major_ticks'] || info['major']
174
+ values = tick_info['major_ticks']
157
175
  for val in values
158
176
  if info['vertical']
159
177
  t.stroke_line(x0, val, x1, val)
@@ -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: 419 $', '$Date: 2013-08-23 01:05:42 +0200 (Fri, 23 Aug 2013) $')
20
+ Version::register_svn_info('$Revision: 466 $', '$Date: 2013-08-31 13:10:38 +0200 (Sat, 31 Aug 2013) $')
21
21
 
22
22
  module Graphics
23
23
 
@@ -154,11 +154,7 @@ module CTioga2
154
154
  # how the fill should be applied to curves.
155
155
  class CurveFillStyle < FillStyle
156
156
 
157
- # At which Y value we should draw the horizontal line for the
158
- # fill ? A float, or:
159
- # * :top, :bottom
160
- # * false, nil to disable filling altogether
161
- typed_attribute :y0, 'fill-until'
157
+ typed_attribute :close_type, 'fill-until'
162
158
 
163
159
  end
164
160
 
@@ -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: 432 $', '$Date: 2013-08-23 19:06:36 +0200 (Fri, 23 Aug 2013) $')
20
+ Version::register_svn_info('$Revision: 489 $', '$Date: 2013-09-03 01:03:12 +0200 (Tue, 03 Sep 2013) $')
21
21
 
22
22
  module Graphics
23
23
 
@@ -105,16 +105,10 @@ module CTioga2
105
105
 
106
106
 
107
107
  # Creates a new parameter for the style factory.
108
- #
109
- # \todo add a way to add some more text to the description;
110
- # possibly a self.describe_parameter function ?
111
- #
112
- # @todo Remove completely the 'type' argument
113
108
  def self.define_parameter(target, name, sets, description,
114
109
  short_option = nil, disable_cmds = false)
115
110
  # We define two new types:
116
111
  # - first, the color-or-auto type:
117
- # base_type = Commands::CommandType.get_type(type)
118
112
  base_type = CurveStyle.attribute_type(target)
119
113
 
120
114
  if ! Commands::Interpreter.type("#{base_type.name}-or-auto")
@@ -251,7 +245,8 @@ module CTioga2
251
245
  @override_parameters = {
252
246
  'line_style' => LineStyles::Solid,
253
247
  'marker_marker' => false,
254
- 'marker_scale' => 0.5
248
+ 'marker_scale' => 0.5,
249
+ 'fill_color' => '=color'.to_sym
255
250
  }
256
251
  @parameters_carrays = {}
257
252
  for target, param in self.class.parameters
@@ -353,7 +348,7 @@ module CTioga2
353
348
  nil, "Y axis", nil, true
354
349
 
355
350
  # Now, fill style
356
- define_parameter 'fill_y0', 'fill',
351
+ define_parameter 'fill_close_type', 'fill',
357
352
  {}, "Fill until", nil
358
353
 
359
354
  simple_parameter 'fill_color', "fill color", Sets::ColorSets
@@ -454,6 +449,9 @@ module CTioga2
454
449
  for k,v in h
455
450
  v.to_s =~ /^(?:=|->)(\S+)/
456
451
  target = $1
452
+ if CurveStyleFactory.name_to_target[target]
453
+ target = CurveStyleFactory.name_to_target[target]
454
+ end
457
455
  if tv.key? target
458
456
  tv[k] = tv[target]
459
457
  h.delete(k)