ctioga2 0.9 → 0.10

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 (41) hide show
  1. data/Changelog +27 -0
  2. data/bin/ct2-make-movie +92 -45
  3. data/lib/ctioga2/commands/doc/html.rb +1 -1
  4. data/lib/ctioga2/commands/doc/introspection.rb +52 -0
  5. data/lib/ctioga2/commands/doc/markup.rb +4 -0
  6. data/lib/ctioga2/commands/general-commands.rb +19 -0
  7. data/lib/ctioga2/commands/general-functions.rb +8 -1
  8. data/lib/ctioga2/commands/general-types.rb +14 -3
  9. data/lib/ctioga2/commands/parsers/file.rb +20 -3
  10. data/lib/ctioga2/data/backends/backends/math.rb +1 -1
  11. data/lib/ctioga2/data/backends/backends/text.rb +3 -3
  12. data/lib/ctioga2/data/point.rb +1 -1
  13. data/lib/ctioga2/graphics/elements.rb +1 -0
  14. data/lib/ctioga2/graphics/elements/curve2d.rb +5 -0
  15. data/lib/ctioga2/graphics/elements/primitive.rb +16 -14
  16. data/lib/ctioga2/graphics/elements/style-lists.rb +353 -0
  17. data/lib/ctioga2/graphics/elements/subplot.rb +17 -2
  18. data/lib/ctioga2/graphics/elements/tangent.rb +16 -17
  19. data/lib/ctioga2/graphics/styles.rb +1 -0
  20. data/lib/ctioga2/graphics/styles/axes.rb +63 -0
  21. data/lib/ctioga2/graphics/styles/base.rb +13 -0
  22. data/lib/ctioga2/graphics/styles/colorbrewer.rb +316 -0
  23. data/lib/ctioga2/graphics/styles/colormap.rb +47 -7
  24. data/lib/ctioga2/graphics/styles/image.rb +83 -0
  25. data/lib/ctioga2/graphics/styles/plot.rb +43 -7
  26. data/lib/ctioga2/graphics/styles/sets.rb +47 -5
  27. data/lib/ctioga2/graphics/styles/sheet.rb +18 -3
  28. data/lib/ctioga2/graphics/styles/texts.rb +49 -8
  29. data/lib/ctioga2/graphics/subplot-commands.rb +13 -13
  30. data/lib/ctioga2/graphics/types.rb +42 -10
  31. data/lib/ctioga2/graphics/types/boundaries.rb +3 -2
  32. data/lib/ctioga2/graphics/types/boxes.rb +13 -0
  33. data/lib/ctioga2/graphics/types/dimensions.rb +4 -1
  34. data/lib/ctioga2/graphics/types/location.rb +13 -2
  35. data/lib/ctioga2/graphics/types/point.rb +86 -0
  36. data/lib/ctioga2/metabuilder/types/styles.rb +2 -2
  37. data/lib/ctioga2/plotmaker.rb +3 -0
  38. data/lib/ctioga2/ruby.rb +49 -0
  39. data/lib/ctioga2/utils.rb +34 -0
  40. data/lib/ctioga2/version.rb +2 -2
  41. metadata +8 -4
@@ -240,20 +240,20 @@ larger than the other ones, while the second row is four times larger
240
240
  than the first.
241
241
  EOH
242
242
 
243
- ZoomCommand =
244
- Cmd.new("zoom-inset",nil,"--zoom-inset",
245
- [
246
- CmdArg.new('box'),
247
- ]) do |plotmaker, box|
248
- subplot = plotmaker.root_object.subplot
249
- subplot.subframe = box
250
- raise YetUnimplemented.new("zooms are not yet implemented !")
251
- end
243
+ # ZoomCommand =
244
+ # Cmd.new("zoom-inset",nil,"--zoom-inset",
245
+ # [
246
+ # CmdArg.new('box'),
247
+ # ]) do |plotmaker, box|
248
+ # subplot = plotmaker.root_object.subplot
249
+ # subplot.subframe = box
250
+ # raise YetUnimplemented.new("zooms are not yet implemented !")
251
+ # end
252
252
 
253
- ZoomCommand.describe('Starts an inset ',
254
- <<EOD, SubplotsGroup)
255
- Zooms are currently not implemented yet.
256
- EOD
253
+ # ZoomCommand.describe('Starts an inset ',
254
+ # <<EOD, SubplotsGroup)
255
+ # Zooms are currently not implemented yet.
256
+ # EOD
257
257
 
258
258
 
259
259
  end
@@ -43,7 +43,8 @@ module CTioga2
43
43
  Dot_Long_Dash = Line_Type_Dot_Long_Dash
44
44
  Dash_Dot_Dot = Line_Type_Dash_Dot_Dot
45
45
  end
46
-
46
+
47
+ NoRE = /no(ne)?|off/i
47
48
 
48
49
  ColorType = CmdType.new('color', {
49
50
  :type => :tioga_color,
@@ -61,7 +62,9 @@ EOD
61
62
  CmdType.new('color-or-false', {
62
63
  :type => :tioga_color,
63
64
  :namespace => Tioga::ColorConstants,
64
- :shortcuts => {'none' => false }
65
+ :shortcuts => {
66
+ NoRE => false
67
+ }
65
68
  }, <<EOD)
66
69
  A {type: color}, or none to say that nothing should be drawn.
67
70
  EOD
@@ -91,7 +94,7 @@ EOD
91
94
  :type => :tioga_line_style,
92
95
  :namespace => LineStyles,
93
96
  :shortcuts => {
94
- /no(ne)?|off/i => false,
97
+ NoRE => false,
95
98
  }
96
99
  }, <<EOD)
97
100
  A line style, which is one of @solid@, @dots@, @dashes@, @small_dots@,
@@ -104,11 +107,9 @@ EOD
104
107
  :type => :tioga_marker,
105
108
  :namespace => Tioga::MarkerConstants,
106
109
  :shortcuts => {
107
- 'None' => 'None',
108
- 'no' => 'None',
109
- 'none' => 'None',
110
- 'off' => 'None',
111
- },}, <<EOD)
110
+ NoRE => 'None'
111
+ }
112
+ }, <<EOD)
112
113
  A Tioga Marker, ie either a name from the list at {url:
113
114
  http://tioga.rubyforge.org/doc/Tioga/MarkerConstants.html}, such as
114
115
  @Box@, @Star@, @Spade@ or two or three comma-separated numbers,
@@ -140,12 +141,30 @@ EOD
140
141
  JustificationType =
141
142
  CmdType.new('justification', {:type => :re_list,
142
143
  :list => JustificationRE}, <<EOD)
143
- Horizontal aligment for text. Can be one of:
144
+ Horizontal aligment of the (with respect to its location). Can be one of:
144
145
  * @l@ or @left@
145
146
  * @c@, @center@
146
147
  * @r@, @right@
147
148
  EOD
148
149
 
150
+ TextAlignType =
151
+ CmdType.new('text-align',
152
+ {:type => :re_list,
153
+ :list => JustificationRE,
154
+ :shortcut => {
155
+ NoRE => :no
156
+ }
157
+ }, <<EOD)
158
+ Horizontal aligment for text within its box. Only of use
159
+ for texts with a given text width.
160
+ Can be one of:
161
+ * @l@ or @left@
162
+ * @c@, @center@
163
+ * @r@, @right@
164
+ * @no@ or @none@ to not issue aligning commands, in which case you get
165
+ full LaTeX-justified paragraphs (probably with a lot of hyphens).
166
+ EOD
167
+
149
168
  # Regular expression for vertical alignment
150
169
  AlignmentRE = {
151
170
  /t(op)?/i => Tioga::FigureConstants::ALIGNED_AT_TOP,
@@ -222,7 +241,7 @@ EOD
222
241
  CmdType.new('axis-decoration', :tioga_axis_type, <<EOD)
223
242
  Kinds of decoration on a axis line, such as nothing, lines, ticks,
224
243
  tick labels. Possible values:
225
- * @hidden@ or @off@: no axis at all
244
+ * @hidden@, @off@, @no@, @none@: no axis at all
226
245
  * @line@: only a line
227
246
  * @ticks@: only ticks
228
247
  * @major@: only major ticks
@@ -264,8 +283,21 @@ where @value@ is a number and unit can be one of @pt@,
264
283
  line), @figure@ or @f@ (for figure coordinates, i.e. the coordinates of the
265
284
  plot), @frame@ or @F@ (@1.0 frame@ is the full size of the current subplot) and
266
285
  @page@ or @p@ (@1.0 page@ is the whole height/width of the output file).
286
+
287
+ It can also be @auto@, which is 1.0 in frame units (ie the width or
288
+ the height of the current plot).
267
289
  EOD
268
290
 
291
+
292
+ DimensionOrNoType =
293
+ CmdType.new('dimension-or-no', { :type => :dimension,
294
+ :default => :dy,
295
+ :shortcuts => {
296
+ NoRE => false
297
+ }
298
+ }, <<EOD)
299
+ A {type: dimension}, or @no@ or @none@.
300
+ EOD
269
301
  # Boxes
270
302
 
271
303
  BoxType =
@@ -69,13 +69,14 @@ module CTioga2
69
69
  # Actually, it even works with normal Range elements !
70
70
  def extend(range)
71
71
  # Left/right
72
+
72
73
  if (! @first.is_a? Float) or @first.nan? or
73
- (@first > range.first)
74
+ (range.first && @first > range.first)
74
75
  @first = range.first
75
76
  end
76
77
 
77
78
  if (! @last.is_a? Float) or @last.nan? or
78
- (@last < range.last)
79
+ (range.last && @last < range.last)
79
80
  @last = range.last
80
81
  end
81
82
 
@@ -84,6 +84,19 @@ module CTioga2
84
84
  1 - @right.to_frame(t), @bottom.to_frame(t)]
85
85
  end
86
86
 
87
+ # Converts to output coordinates
88
+ def to_output(t, fact = 1.0)
89
+ a = to_frame_coordinates(t)
90
+ 4.times do |i|
91
+ a[i] = if (i % 2 == 0)
92
+ fact * t.convert_page_to_output_x(t.convert_frame_to_page_x(a[i]))
93
+ else
94
+ fact * t.convert_page_to_output_y(t.convert_frame_to_page_y(a[i]))
95
+ end
96
+ end
97
+ return a
98
+ end
99
+
87
100
  # Returns the dimensions composing the MarginsBox, in the
88
101
  # order _left_, _right_, _top_, _bottom_, suitable for feeding
89
102
  # to MarginsBox.new.
@@ -137,7 +137,10 @@ module CTioga2
137
137
  # _default_ parameter.
138
138
  def self.from_text(text, orientation, default = :figure)
139
139
  # Absolute or :dy dimension
140
- if text =~ DimensionRegexp
140
+
141
+ if text =~ /^\s*auto\s*$/i
142
+ Dimension.new(:frame, 1.0, orientation)
143
+ elsif text =~ DimensionRegexp
141
144
  value = Utils::txt_to_float($1)
142
145
  unit = $2
143
146
  if ! unit
@@ -197,8 +197,17 @@ module CTioga2
197
197
  #
198
198
  # So far, no real parsing
199
199
  def self.from_text(str)
200
- str = str.gsub(/-/,"_") # Avoid problems with frozen strings
201
- return PlotLocation.new(str.to_sym)
200
+ loc = nil
201
+ case str
202
+ when /^\s*(left|right|top|bottom|at_y_origin|at_x_origin)\s*$/i
203
+ loc = $1.downcase.to_sym
204
+ when /^s*(x|y)0\s*$/i
205
+ loc = "at_#{$1}_origin".downcase.to_sym
206
+ end
207
+ if ! loc
208
+ raise "Unkown spec for axis location: '#{str}'"
209
+ end
210
+ return PlotLocation.new(loc)
202
211
  end
203
212
 
204
213
 
@@ -213,6 +222,8 @@ A position on the plot, referenced with respect to the sides. Can be:
213
222
  * @right@
214
223
  * @top@
215
224
  * @bottom@
225
+ * @x0@, for the @x = 0@ position
226
+ * @y0@, for the @y = 0@ position
216
227
 
217
228
  In addition, there will one day be the possibility to specify an
218
229
  offset from these locations. But that is still something to do.
@@ -113,6 +113,92 @@ module CTioga2
113
113
  end
114
114
  end
115
115
 
116
+ class Rect
117
+ attr_accessor :tl
118
+ attr_accessor :br
119
+
120
+ def initialize(tl, br)
121
+ @tl = tl
122
+ @br = br
123
+ end
124
+
125
+ # Returns the [height, width] of the rectangle in postscript points
126
+ def dimensions(t)
127
+ xl, yt = @tl.to_figure_xy(t)
128
+ xr, yb = @br.to_figure_xy(t)
129
+
130
+ return [t.convert_figure_to_output_dx(xr - xl) * 10,
131
+ t.convert_figure_to_output_dy(yb - yt) * 10]
132
+ end
133
+
134
+ # Returns an array of [ul, ll, lr] coordinates. If an aspect
135
+ # ratio is specified, the coordinates will be expanded or
136
+ # contracted to fit the aspect ratio (keeping the center
137
+ # identical).
138
+ def make_corners(t, swap = false, ratio_pol = :ignore,
139
+ ratio = nil)
140
+
141
+ ul = @tl.to_figure_xy(t)
142
+ lr = @br.to_figure_xy(t)
143
+
144
+ width, height = *dimensions(t)
145
+
146
+ # First, swap the coords
147
+ if swap
148
+ if width < 0
149
+ ul[0], lr[0] = lr[0], ul[0]
150
+ end
151
+ if height > 0
152
+ ul[1], lr[1] = lr[1], ul[1]
153
+ end
154
+ end
155
+
156
+ # Now, we take the aspect ratio into account
157
+ if ratio && ratio_pol != :ignore
158
+
159
+ xc = 0.5 * (ul[0] + lr[0])
160
+ yc = 0.5 * (ul[1] + lr[1])
161
+ dx = lr[0] - ul[0]
162
+ dy = lr[1] - ul[1]
163
+
164
+ fact = ((width/height) / ratio).abs
165
+
166
+ what = nil
167
+
168
+ if ratio_pol == :expand
169
+ if fact > 1 # must increase height
170
+ what = :y
171
+ else
172
+ fact = 1/fact
173
+ what = :x
174
+ end
175
+ elsif ratio_pol == :contract
176
+ if fact > 1 # must decrease width
177
+ what = :x
178
+ fact = 1/fact
179
+ else
180
+ what = :y
181
+ end
182
+ else
183
+ raise "Unkown aspect ratio policy: #{ratio_pol}"
184
+ end
185
+
186
+ if what == :y
187
+ lr[1] = yc + fact * 0.5 * dy
188
+ ul[1] = yc - fact * 0.5 * dy
189
+ else
190
+ lr[0] = xc + fact * 0.5 * dx
191
+ ul[0] = xc - fact * 0.5 * dx
192
+ end
193
+ end
194
+
195
+ ll = [ul[0], lr[1]]
196
+
197
+ return [ul, ll, lr]
198
+ end
199
+
200
+ end
201
+
116
202
  # A Point, but with alignment facilities.
117
203
  class AlignedPoint < Point
118
204
  # Vertical alignement (:top, :center, :bottom)
@@ -141,7 +141,7 @@ module CTioga2
141
141
  include Tioga::FigureConstants
142
142
 
143
143
  ValidTypes = {
144
- /hidden|off/i => AXIS_HIDDEN,
144
+ /hidden|off|no|none/i => AXIS_HIDDEN,
145
145
  /line/i => AXIS_LINE_ONLY,
146
146
  /ticks/i => AXIS_WITH_TICKS_ONLY,
147
147
  /major/i => AXIS_WITH_MAJOR_TICKS_ONLY,
@@ -157,7 +157,7 @@ module CTioga2
157
157
  return v
158
158
  end
159
159
  end
160
- raise IncorrectInput, "Not an axis type: '#{str}'"
160
+ raise IncorrectInput, "Not an axis decoration: '#{str}'"
161
161
  end
162
162
  end
163
163
 
@@ -112,6 +112,9 @@ require 'pathname'
112
112
  # Maybe, maybe, maybe... We need tioga ?
113
113
  require 'Tioga/FigureMaker'
114
114
 
115
+ # Interaction with Ruby code
116
+ require 'ctioga2/ruby'
117
+
115
118
 
116
119
  # Command interpreter
117
120
  require 'ctioga2/commands/interpreter'
@@ -0,0 +1,49 @@
1
+ # ruby.rb: interaction with user-supplied Ruby code
2
+ # copyright (c) 2014 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
+ module CTioga2
16
+
17
+ # The class in charge of the interaction with Ruby code
18
+ class Ruby
19
+
20
+ # Module where all instance methods declared become immediately
21
+ # class methods.
22
+ class MetaModule < Module
23
+
24
+ include Math
25
+
26
+ def method_added(meth)
27
+ module_function meth
28
+ end
29
+
30
+ end
31
+
32
+ @module = MetaModule.new
33
+
34
+ def self.run_code(str)
35
+ @module.send(:module_eval,str)
36
+ end
37
+
38
+ def self.run_file(file)
39
+ File.open(file) do |f|
40
+ run_code(f.read)
41
+ end
42
+ end
43
+
44
+ def self.compute_formula(col, vals, mods = [])
45
+ return Dobjects::Dvector.compute_formula(col, vals, [@module] + mods)
46
+ end
47
+ end
48
+ end
49
+
@@ -141,6 +141,40 @@ module CTioga2
141
141
  return formula
142
142
  end
143
143
 
144
+
145
+ def self.suffix_numeric_sort(strings)
146
+ strings.sort do |a,b|
147
+ a =~ /.*?(\d+)$/
148
+ a_i = $1 ? $1.to_i : nil
149
+ b =~ /.*?(\d+)$/
150
+ b_i = $1 ? $1.to_i : nil
151
+
152
+ if a_i && b_i
153
+ a_i <=> b_i
154
+ else
155
+ a <=> b
156
+ end
157
+ end
158
+ end
159
+
160
+
161
+ # Groups the given strings by prefixes
162
+
163
+ def self.group_by_prefix(strings, pref_re)
164
+ sets_by_prefix = {}
165
+ for s in strings
166
+ pref = s
167
+ if s =~ pref_re
168
+ pref = $1
169
+ end
170
+ sets_by_prefix[pref] ||= []
171
+ sets_by_prefix[pref] << s
172
+ end
173
+ return sets_by_prefix
174
+ end
175
+
176
+
177
+
144
178
  NaturalSubdivisions = [1.0, 2.0, 5.0, 10.0]
145
179
 
146
180
  # Returns the closest element of the correct power of ten of
@@ -2,7 +2,7 @@
2
2
  module CTioga2
3
3
 
4
4
  module Version
5
- GIT_VERSION = '0.9'
6
- GIT_DATE = 'Thu 6 Feb 22:05:21 CET 2014'
5
+ GIT_VERSION = '0.10'
6
+ GIT_DATE = 'Sun 16 Mar 18:22:35 CET 2014'
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ctioga2
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.9'
4
+ version: '0.10'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-06 00:00:00.000000000 Z
12
+ date: 2014-03-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: tioga
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: '1.17'
21
+ version: '1.18'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
- version: '1.17'
29
+ version: '1.18'
30
30
  description: ! 'ctioga2 is a command-driven plotting program that produces
31
31
 
32
32
  high quality PDF files. It can be used both from the command-line
@@ -89,12 +89,14 @@ files:
89
89
  - lib/ctioga2/graphics/elements/primitive.rb
90
90
  - lib/ctioga2/graphics/elements/element.rb
91
91
  - lib/ctioga2/graphics/elements/xyz-contour.rb
92
+ - lib/ctioga2/graphics/elements/style-lists.rb
92
93
  - lib/ctioga2/graphics/elements/curve2d.rb
93
94
  - lib/ctioga2/graphics/elements/subplot.rb
94
95
  - lib/ctioga2/graphics/elements/containers.rb
95
96
  - lib/ctioga2/graphics/styles/arrows.rb
96
97
  - lib/ctioga2/graphics/styles/colormap.rb
97
98
  - lib/ctioga2/graphics/styles/box.rb
99
+ - lib/ctioga2/graphics/styles/image.rb
98
100
  - lib/ctioga2/graphics/styles/carrays.rb
99
101
  - lib/ctioga2/graphics/styles/location.rb
100
102
  - lib/ctioga2/graphics/styles/contour.rb
@@ -106,6 +108,7 @@ files:
106
108
  - lib/ctioga2/graphics/styles/sheet.rb
107
109
  - lib/ctioga2/graphics/styles/axes.rb
108
110
  - lib/ctioga2/graphics/styles/base.rb
111
+ - lib/ctioga2/graphics/styles/colorbrewer.rb
109
112
  - lib/ctioga2/graphics/styles/gradients.rb
110
113
  - lib/ctioga2/graphics/styles/ticks.rb
111
114
  - lib/ctioga2/graphics/styles/legend.rb
@@ -153,6 +156,7 @@ files:
153
156
  - lib/ctioga2/metabuilder/type.rb
154
157
  - lib/ctioga2/metabuilder/types.rb
155
158
  - lib/ctioga2/plotmaker.rb
159
+ - lib/ctioga2/ruby.rb
156
160
  - COPYING
157
161
  - Changelog
158
162
  - setup.rb