ctioga2 0.10.1 → 0.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +7 -0
  2. data/Changelog +18 -0
  3. data/bin/ctioga2 +28 -0
  4. data/lib/ctioga2/commands/commands.rb +1 -0
  5. data/lib/ctioga2/commands/doc/documentation-commands.rb +13 -0
  6. data/lib/ctioga2/commands/doc/help.rb +3 -2
  7. data/lib/ctioga2/commands/doc/html.rb +48 -0
  8. data/lib/ctioga2/commands/doc/introspection.rb +2 -2
  9. data/lib/ctioga2/commands/general-types.rb +10 -0
  10. data/lib/ctioga2/commands/parsers/file.rb +23 -2
  11. data/lib/ctioga2/data/backends/backends.rb +1 -2
  12. data/lib/ctioga2/data/backends/backends/smath.rb +129 -0
  13. data/lib/ctioga2/data/backends/backends/text.rb +1 -0
  14. data/lib/ctioga2/data/dataset.rb +1 -1
  15. data/lib/ctioga2/data/stack.rb +13 -3
  16. data/lib/ctioga2/graphics/elements.rb +2 -0
  17. data/lib/ctioga2/graphics/elements/containers.rb +3 -1
  18. data/lib/ctioga2/graphics/elements/element.rb +194 -5
  19. data/lib/ctioga2/graphics/elements/gradient-region.rb +5 -2
  20. data/lib/ctioga2/graphics/elements/histogram.rb +7 -2
  21. data/lib/ctioga2/graphics/elements/plot-elements.rb +88 -0
  22. data/lib/ctioga2/graphics/elements/primitive.rb +28 -12
  23. data/lib/ctioga2/graphics/elements/region.rb +6 -1
  24. data/lib/ctioga2/graphics/elements/style-lists.rb +2 -2
  25. data/lib/ctioga2/graphics/elements/subplot.rb +3 -3
  26. data/lib/ctioga2/graphics/elements/tangent.rb +5 -8
  27. data/lib/ctioga2/graphics/generator.rb +10 -0
  28. data/lib/ctioga2/graphics/geometry.rb +96 -0
  29. data/lib/ctioga2/graphics/legends.rb +4 -2
  30. data/lib/ctioga2/graphics/legends/area.rb +12 -4
  31. data/lib/ctioga2/graphics/root.rb +16 -14
  32. data/lib/ctioga2/graphics/styles.rb +5 -2
  33. data/lib/ctioga2/graphics/styles/arrows.rb +5 -0
  34. data/lib/ctioga2/graphics/styles/axes.rb +1 -1
  35. data/lib/ctioga2/graphics/styles/base.rb +95 -14
  36. data/lib/ctioga2/graphics/styles/curve.rb +8 -0
  37. data/lib/ctioga2/graphics/styles/drawable.rb +35 -48
  38. data/lib/ctioga2/graphics/styles/factory.rb +23 -23
  39. data/lib/ctioga2/graphics/styles/fill.rb +268 -0
  40. data/lib/ctioga2/graphics/styles/plot.rb +90 -46
  41. data/lib/ctioga2/graphics/styles/sets.rb +3 -0
  42. data/lib/ctioga2/graphics/styles/{sheet.rb → styles.rb} +70 -160
  43. data/lib/ctioga2/graphics/styles/stylesheet.rb +355 -0
  44. data/lib/ctioga2/graphics/styles/texts.rb +4 -2
  45. data/lib/ctioga2/graphics/styles/ticks.rb +44 -4
  46. data/lib/ctioga2/graphics/subplot-commands.rb +84 -9
  47. data/lib/ctioga2/graphics/types.rb +1 -1
  48. data/lib/ctioga2/graphics/types/dimensions.rb +40 -0
  49. data/lib/ctioga2/graphics/types/grid.rb +21 -5
  50. data/lib/ctioga2/graphics/types/point.rb +2 -1
  51. data/lib/ctioga2/log.rb +5 -1
  52. data/lib/ctioga2/metabuilder/types/styles.rb +11 -7
  53. data/lib/ctioga2/plotmaker.rb +2 -0
  54. data/lib/ctioga2/utils.rb +21 -6
  55. data/lib/ctioga2/version.rb +2 -2
  56. metadata +105 -108
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cf1d83cc2f6ff4a0a56457aaf1343632316fc54c
4
+ data.tar.gz: de6664912ac0b52b32dd6dc90520556a8a3408e1
5
+ SHA512:
6
+ metadata.gz: 658b6530f9b7a6b05159f779b6e2b82df15e22b05e75e7c61404212193c46044b622d9a9e68980225a116012004a79f7c92b62445fd1e2ebbc8322f3b83658c3
7
+ data.tar.gz: 8f4d59ab2aa53836d4bd74f30696cfc2f3d4eaaff3c138d85878619f89304cad620093ba2ecd54dc240933ecc93526156fa1934138a07a6e768b0c4864077f54
data/Changelog CHANGED
@@ -1,3 +1,21 @@
1
+ ctioga2 (0.11)
2
+
3
+ * Implemented patterned fills
4
+ * Implemented loops in command files
5
+ * Redesigned the styling system, with now fully-fledged CSS-like style
6
+ sheets
7
+ * A command to hide (and show again) elements (for step-by-step
8
+ construction of animations)
9
+ * A mathematical backend for 3D curves
10
+ * Multicolumn merge
11
+ * More flexibility in setting the frame margin
12
+ * Grid elements spanning several columns/rows
13
+ * An oriented-line primitive to draw a line of a given length in a
14
+ given direction
15
+ * Various bug-fixes and documentation updates
16
+
17
+ -- Vincent <vincent.fourmond@9online.fr> Thu 1 Jan 21:51:57 CET 2015
18
+
1
19
  ctioga2 (0.10.1)
2
20
 
3
21
  * Fix problems with Ruby1.8
@@ -19,8 +19,36 @@ along with this program; if not, write to the Free Software
19
19
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
20
  =end
21
21
 
22
+ # Coverage on demand
23
+ if ARGV[0] == '--coverage'
24
+ ARGV.shift
25
+ require 'simplecov'
26
+ nm = ARGV.shift
27
+ if nm =~ /%/ # Some formatting
28
+ id = begin
29
+ File.open(".cov") do |f|
30
+ f.read.to_i + 1
31
+ end
32
+ rescue
33
+ 0
34
+ end
35
+ nm = nm % id
36
+ File.open('.cov', 'w') do |f|
37
+ f.puts id.to_s
38
+ end
39
+ end
40
+ SimpleCov.command_name nm
41
+ SimpleCov.start do
42
+ filters.clear
43
+ add_filter do |src|
44
+ !(src.filename =~ /ctioga2/)
45
+ end
46
+ end
47
+ end
48
+
22
49
  require 'ctioga2/plotmaker'
23
50
 
24
51
  plot_maker = CTioga2::PlotMaker.new
52
+
25
53
  plot_maker.run(ARGV)
26
54
 
@@ -264,6 +264,7 @@ module CTioga2
264
264
  return @tg_op_names
265
265
  end
266
266
 
267
+
267
268
  # Returns a lowercase
268
269
  def normalize_option_name(opt)
269
270
  return opt.gsub(/_/,"-").downcase
@@ -89,6 +89,19 @@ EOH
89
89
  Prints the HTML documentation for all types.
90
90
  EOH
91
91
 
92
+ WriteHTMLStyles =
93
+ Cmd.new("write-html-styles", nil, "--write-html-styles",
94
+ [], WriteHTMLOptions) do |plotmaker, opts|
95
+ html = HTML.new(plotmaker.interpreter.doc)
96
+ html.write_styles(opts)
97
+ end
98
+
99
+ WriteHTMLStyles.describe("HTML documentation for styles",
100
+ <<EOH, DocumentationGenerationGroup)
101
+ Prints the HTML documentation for all styles.
102
+ EOH
103
+
104
+
92
105
  WriteHTMLBackends =
93
106
  Cmd.new("write-html-backends", nil, "--write-html-backends",
94
107
  [], WriteHTMLOptions) do |plotmaker, opts|
@@ -81,13 +81,14 @@ module CTioga2
81
81
  def print_commandline_options(cmds, groups)
82
82
  @to_tty = false
83
83
  if STDOUT.tty?
84
+ @to_tty = true
84
85
  begin
85
86
  require 'curses'
86
87
  Curses.init_screen
87
88
  @total_width = Curses.cols
88
89
  Curses.close_screen
89
- @to_tty = true
90
- rescue
90
+ rescue LoadError => e
91
+ # We'll be missing the exact term size
91
92
  end
92
93
  end
93
94
  @total_width ||= 80 # 80 by default
@@ -206,6 +206,54 @@ module CTioga2
206
206
  end
207
207
  end
208
208
  end
209
+
210
+ # Write a summary list of all style items
211
+ def write_styles(opts, out = STDOUT)
212
+
213
+ styles = Graphics::Elements::TiogaElement::styled_classes
214
+
215
+ names = styles.keys.sort
216
+
217
+ write_page_menu(opts, out) do |out|
218
+ out.puts "<div class='quick-jump'>"
219
+ out.puts "<h3>Quick jump</h3>"
220
+ out.puts "<ul>\n"
221
+ for k in names
222
+ out.puts "<li><a href='#style-#{k}'>#{k}</a></li>\n"
223
+ end
224
+ out.puts "</ul>\n"
225
+ out.puts "</div>"
226
+ end
227
+
228
+ write_page(opts, out) do |out|
229
+ for n in names
230
+ out.puts "<h3 id='style-#{n}' class='style'><code>#{n}</code></h3>\n"
231
+ cls = styles[n].style_class
232
+ if cls
233
+ aliases = cls.defined_aliases
234
+ out.puts "<ul>\n"
235
+
236
+ opts = cls.options_hash
237
+ op_names = opts.keys.sort
238
+ for k in op_names
239
+ type = opts[k].type
240
+ extra = if aliases.key? k
241
+ " (alias for <code>#{cls.normalize_out(aliases[k])}</code>)"
242
+ else
243
+ ""
244
+ end
245
+
246
+ puts "<li><code>#{cls.normalize_out(k)}</code>#{extra}: <a href='#{@types_url}#type-#{type.name}'>#{type.name}</a></li>\n"
247
+ end
248
+ out.puts "</ul>\n"
249
+
250
+ else
251
+ out.puts "No specific style information"
252
+ end
253
+ end
254
+ end
255
+
256
+ end
209
257
 
210
258
 
211
259
  protected
@@ -135,7 +135,7 @@ module CTioga2
135
135
  def list_styles
136
136
 
137
137
  puts "Available color sets:"
138
- sets = Graphics::Styles::CurveStyleFactory::parameters['line_color'].sets
138
+ sets = Graphics::Styles::CurveStyleFactory::parameters['color'].sets
139
139
  set_names = sets.keys.sort
140
140
 
141
141
  sets_by_prefix = Utils.group_by_prefix(set_names, /(.*?)\d+$/)
@@ -147,7 +147,7 @@ module CTioga2
147
147
  end
148
148
 
149
149
  puts "\nAvailable marker sets:"
150
- sets = Graphics::Styles::CurveStyleFactory::parameters['marker_marker'].sets
150
+ sets = Graphics::Styles::CurveStyleFactory::parameters['marker'].sets
151
151
  set_names = sets.keys.sort
152
152
 
153
153
  sets_by_prefix = Utils.group_by_prefix(set_names, /(.*?)\d+$/)
@@ -80,6 +80,16 @@ EOD
80
80
 
81
81
  IntegerType = CmdType.new('integer', :integer, <<EOD)
82
82
  An integer.
83
+ EOD
84
+
85
+ IntegerList = CmdType.new('integer-list',
86
+ {
87
+ :type => :array,
88
+ :subtype => :integer,
89
+ :separator => /\s+|\s*,\s*/,
90
+ :separator_out => " "
91
+ }, <<EOD)
92
+ A list of space-separated or comma-separated integers
83
93
  EOD
84
94
 
85
95
  PartialFloatRangeType = CmdType.new('partial-float-range',
@@ -24,7 +24,8 @@ module CTioga2
24
24
 
25
25
  module Parsers
26
26
 
27
- # This class parses a "new style" command file, delegating
27
+ # This class parses a "new style" command file, delegating to
28
+ # the old parser if this looks like an old style command file.
28
29
  class FileParser
29
30
 
30
31
  include Log
@@ -75,7 +76,7 @@ module CTioga2
75
76
  ## @todo line counting ?
76
77
  for l in lines
77
78
  idx += 1
78
- # If we find something that looks like a command at the
79
+ # If we find something that looks like an old command at the
79
80
  # beginning of a line, we say this is an old style file.
80
81
 
81
82
  ## @todo Find a way to disable this compatibility stuff --
@@ -116,6 +117,9 @@ module CTioga2
116
117
  # Now, we rearrange the lines...
117
118
  idx = -1
118
119
  ruby = false
120
+
121
+ # False, or a [var, values, code] triplet
122
+ loop = false
119
123
  for l in parsed_lines
120
124
  idx += 1
121
125
  interpreter.context.parsing_file(nil, io, lines_indices[idx])
@@ -132,6 +136,23 @@ module CTioga2
132
136
  else
133
137
  ruby << l
134
138
  end
139
+ elsif l =~ /^\s*for\s+(\w+)\s+in\s+(.*)/
140
+ v = $2
141
+ var = $1
142
+ v << "\n"
143
+ s = InterpreterString.parse_until_unquoted(StringIO.new(v),"\n")
144
+ vals = s.expand_and_split(/\s+/, interpreter)
145
+ loop = [var, vals, ""]
146
+ elsif loop
147
+ if l =~ /^\s*for\s+end\s*$/
148
+ for v in loop[1]
149
+ interpreter.variables.define_variable(loop[0], v)
150
+ run_commands(loop[2], interpreter)
151
+ end
152
+ loop = false
153
+ else
154
+ loop[2] << l
155
+ end
135
156
  elsif l =~ /^\s*([a-zA-Z0-9_-]+)\s*(\??)(=|:=)\s*(.*)/
136
157
  symbol = $1
137
158
  value = InterpreterString.parse_until_unquoted(StringIO.new($4),"\n", false)
@@ -34,7 +34,6 @@ for file in files.uniq
34
34
  begin
35
35
  require "ctioga2/data/backends/backends/#{file}"
36
36
  rescue Exception => e
37
- CTioga2::Log::warn { "There was a problem trying to load 'ctioga2/data/backends/backends/#{file}': " }
38
- CTioga2::Log::warn { "#{e.inspect}" }
37
+ CTioga2::Log::warn { "There was a problem trying to load 'ctioga2/data/backends/backends/#{file}':\n#{e.inspect}" }
39
38
  end
40
39
  end
@@ -0,0 +1,129 @@
1
+ # smath.rb :multi-dimensional math backend
2
+ # Copyright (C) 2014 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.
13
+
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program; if not, write to the Free Software
16
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
+
18
+
19
+ require 'Dobjects/Dvector'
20
+ require 'Dobjects/Function'
21
+
22
+ module CTioga2
23
+
24
+ module Data
25
+
26
+ module Backends
27
+
28
+ class SMathBackend < Backend
29
+
30
+ include Dobjects
31
+ include Math
32
+
33
+ describe 'smath', 'Mathematical functions (multi-D)', <<EOD
34
+ This backends computes mathematical formulas of two or more variables
35
+ EOD
36
+
37
+ param_accessor :samples, 'samples', "Sample number", 'integer',
38
+ "Number of samples (default, overriden by variable-specific specs)"
39
+
40
+
41
+ param_accessor :u_range, 'urange', "U Range", 'float-range',
42
+ "U range (a:b)"
43
+
44
+ param_accessor :u_samples, 'usamples', "U samples", 'integer',
45
+ "Number of U samples"
46
+
47
+ param_accessor :v_range, 'vrange', "V Range", 'float-range',
48
+ "V range (a:b)"
49
+
50
+ param_accessor :v_samples, 'vsamples', "V samples", 'integer',
51
+ "Number of V samples"
52
+
53
+ def initialize
54
+ super()
55
+ @samples = 30
56
+ @u_range = -10.0..10.0
57
+ @v_range = -10.0..10.0
58
+ end
59
+
60
+ # This is called by the architecture to get the data. It first
61
+ # splits the set name into func@range.
62
+ def query_dataset(set)
63
+ name = "#{set}"
64
+
65
+ u_values = make_dvector(@u_range, @u_samples || @samples)
66
+ v_values = make_dvector(@v_range, @v_samples || @samples)
67
+
68
+ if ! (set.split_at_toplevel(/:/).size > 1)
69
+ set = "u:v:#{set}"
70
+ end
71
+
72
+ val_u = Dvector.new
73
+ val_v = Dvector.new
74
+ for u in u_values
75
+ for v in v_values
76
+ val_u << u
77
+ val_v << v
78
+ end
79
+ end
80
+
81
+
82
+
83
+ return Dataset.dataset_from_spec(name, set) do |b|
84
+ get_data_column(b, [val_u, val_v])
85
+ end
86
+ end
87
+
88
+
89
+ protected
90
+
91
+ # Turns a Range and a number of points into a Dvector
92
+ def make_dvector(range, nb_points, log = @log)
93
+ n = nb_points -1
94
+ a = Dvector.new(nb_points) { |i|
95
+ i.to_f/(n.to_f)
96
+ }
97
+ # a is in [0:1] inclusive...
98
+ if log
99
+ delta = range.last/range.first
100
+ # delta is positive necessarily
101
+ a *= delta.log
102
+ a.exp!
103
+ a *= range.first
104
+ else
105
+ delta = range.last - range.first
106
+ a *= delta
107
+ a += range.first
108
+ end
109
+ return a
110
+ end
111
+
112
+ # Uses compute_formula to get data from
113
+ def get_data_column(column, values)
114
+ column.gsub!(/\b(u|v)\b/) do
115
+ cl = if $1 == 'u'
116
+ 0
117
+ else
118
+ 1
119
+ end
120
+ "(column[#{cl}])"
121
+ end
122
+ return Ruby.compute_formula(column, values)
123
+ end
124
+
125
+
126
+ end
127
+ end
128
+ end
129
+ end
@@ -149,6 +149,7 @@ EOD
149
149
  else
150
150
  m = Dir::glob(spec)
151
151
  if m.size > 0
152
+ m.sort!
152
153
  return m
153
154
  else
154
155
  return super
@@ -104,8 +104,8 @@ module CTioga2
104
104
  specs[idx][mod] = yield s
105
105
  else
106
106
  specs[i] = {"value" => yield(s)}
107
+ i += 1
107
108
  end
108
- i += 1
109
109
  end
110
110
  columns = []
111
111
  for s in specs
@@ -463,12 +463,20 @@ EOH
463
463
  [],
464
464
  {
465
465
  'number' => CmdArg.new('integer'),
466
- 'which' => CmdArg.new('stored-dataset')
466
+ 'precision' => CmdArg.new('float'),
467
+ 'which' => CmdArg.new('stored-dataset'),
468
+ 'columns' => CmdArg.new('integer-list')
467
469
  }
468
470
  ) do |plotmaker, opts|
469
471
  stack = plotmaker.data_stack
472
+ cols = if opts.key? 'columns'
473
+ opts['columns'].map { |x| x - 1 }
474
+ else
475
+ [0]
476
+ end
470
477
  datasets = stack.latest_datasets(opts)
471
- plotmaker.data_stack.merge_datasets_into_last(datasets)
478
+ plotmaker.data_stack.merge_datasets_into_last(datasets, cols,
479
+ opts['precision'])
472
480
  end
473
481
 
474
482
  MergeToLastCommand.describe("Merge datasets based on X column",
@@ -476,7 +484,9 @@ EOH
476
484
  This commands merges data with matching X values from a dataset (by
477
485
  default the one before the last) into the last one. Data points that
478
486
  have no corresponding X value in the current dataset are simply
479
- ignored.
487
+ ignored. If the @columns@ option is provided, the numbered columns are
488
+ use instead of the X columns (X is 1). More than one column can be
489
+ provided this way, in which case *all* values must match.
480
490
 
481
491
  This can be used to build 3D datasets for {command: xyz-map} or
482
492
  {command: xy-parametric}.