ctioga2 0.0 → 0.1

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -0,0 +1,172 @@
1
+ # -*- coding: undecided -*-
2
+ # parametric2d.rb: a 2D curve whose parameters depend on Z values
3
+ # copyright (c) 2006, 2007, 2008, 2009, 2010 by Vincent Fourmond
4
+
5
+ # This program is free software; you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation; either version 2 of the License, or
8
+ # (at your option) any later version.
9
+
10
+ # This program is distributed in the hope that it will be useful, but
11
+ # WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # General Public License for more details (in the COPYING file).
14
+
15
+ require 'ctioga2/utils'
16
+ require 'ctioga2/log'
17
+
18
+ require 'Dobjects/Function'
19
+
20
+
21
+ module CTioga2
22
+
23
+ Version::register_svn_info('$Revision: 229 $', '$Date: 2011-01-17 17:34:57 +0100 (Mon, 17 Jan 2011) $')
24
+
25
+ module Graphics
26
+
27
+ module Elements
28
+
29
+ # This class represents a 3D (or more, to be seen later) dataset
30
+ # as markers with various parameters parametrized (color,
31
+ # transparency, marker scale, marker type (discrete), possibly
32
+ # stroke and fill colors ?
33
+ #
34
+ # @todo What would be interesting here would be to have indexed
35
+ # plots, ie draw one curve for each value of Z, with a color
36
+ # indexed by Z.
37
+ class Parametric2D < TiogaElement
38
+
39
+ include Log
40
+ include Dobjects
41
+
42
+ # The Data::Dataset object that should get plotted.
43
+ attr_accessor :dataset
44
+
45
+ # A Styles::CurveStyle object saying how the curve should be
46
+ # drawn.
47
+ #
48
+ # Some of the elements will be overridden.
49
+ attr_accessor :curve_style
50
+
51
+ # For convenience only: xy functions
52
+ attr_accessor :function
53
+
54
+ # A hash Z value -> corresponding XY functions.
55
+ attr_accessor :planes
56
+
57
+
58
+
59
+ undef :location=, :location
60
+
61
+ # Creates a new Curve2D object with the given _dataset_ and
62
+ # _style_.
63
+ def initialize(dataset, style = nil)
64
+ @dataset = dataset
65
+ @curve_style = style
66
+ prepare_data
67
+ end
68
+
69
+ # Prepares the internal storage of the data, from the @dataset
70
+ def prepare_data
71
+ @function = Function.new(@dataset.x.values.dup,
72
+ @dataset.y.values.dup)
73
+
74
+ ## @todo this should eventually use Dataset::index_on_cols.
75
+ @planes = {}
76
+ @dataset.each_values do |i, x,y,*zs|
77
+ @planes[zs[0]] ||= Function.new(Dvector.new, Dvector.new)
78
+ @planes[zs[0]].x << x
79
+ @planes[zs[0]].y << y
80
+ end
81
+ end
82
+
83
+ protected :prepare_data
84
+
85
+ # Returns the LocationStyle object of the curve. Returns the
86
+ # one from #curve_style.
87
+ def location
88
+ return @curve_style.location
89
+ end
90
+
91
+ # Returns the Types::Boundaries of this curve.
92
+ def get_boundaries
93
+ return Types::Boundaries.bounds(@function.x, @function.y)
94
+ end
95
+
96
+ # Draws the markers, if applicable.
97
+ def draw_path(t)
98
+ min = @dataset.z.values.min
99
+ max = @dataset.z.values.max
100
+ if @curve_style.has_line?
101
+ # We use a default color map for the lines
102
+ @curve_style.color_map ||=
103
+ Styles::ColorMap.from_text("Red--Green")
104
+ cmap = @curve_style.color_map
105
+
106
+ for zs in @planes.keys.sort ## \todo have the sort
107
+ ## direction configurable.
108
+ f = @planes[zs]
109
+ color = cmap.z_color(zs, min, max)
110
+ t.context do
111
+ @curve_style.line.set_stroke_style(t)
112
+ t.stroke_color = color
113
+ t.show_polyline(f.x, f.y)
114
+ end
115
+ end
116
+ end
117
+ end
118
+
119
+
120
+ # Draws the markers, if applicable.
121
+ def draw_markers(t)
122
+ min = @dataset.z.values.min
123
+ max = @dataset.z.values.max
124
+ if @curve_style.has_marker?
125
+ # We use a default color map for the markers
126
+ @curve_style.marker_color_map ||=
127
+ Styles::ColorMap.from_text("Red--Green")
128
+ cmap = @curve_style.marker_color_map
129
+ for zs in @planes.keys.sort ## \todo have the sort
130
+ ## direction configurable.
131
+ f = @planes[zs]
132
+ color = cmap.z_color(zs, min, max)
133
+ @curve_style.marker.draw_markers_at(t, f.x, f.y,
134
+ { 'color' => color})
135
+ end
136
+ end
137
+ end
138
+
139
+ ## Actually draws the curve
140
+ def real_do(t)
141
+ debug { "Plotting curve #{inspect}" }
142
+ t.context do
143
+ ## \todo allow customization of the order of drawing,
144
+ ## using a simple user-specificable array of path,
145
+ ## markers... and use the corresponding #draw_path or
146
+ ## #draw_markers... Ideally, any string could be used, and
147
+ ## warnings should be issued on missing symbols.
148
+
149
+ # draw_fill(t)
150
+ # draw_errorbars(t)
151
+ draw_path(t)
152
+ draw_markers(t)
153
+
154
+ if @curve_style.zaxis
155
+ begin
156
+ @parent.style.get_axis_style(@curve_style.zaxis).
157
+ set_color_map(@curve_style.marker_color_map,
158
+ @dataset.z.values.min,
159
+ @dataset.z.values.max)
160
+ rescue
161
+ error { "Could not set Z info to non-existent axis #{@curve_style.zaxis}" }
162
+ end
163
+ end
164
+
165
+ # draw_error_bars(t) ??
166
+ end
167
+ end
168
+
169
+ end
170
+ end
171
+ end
172
+ end
@@ -21,7 +21,7 @@ require 'shellwords'
21
21
  # This module contains all the classes used by ctioga
22
22
  module CTioga2
23
23
 
24
- Version::register_svn_info('$Revision: 101 $', '$Date: 2009-07-21 23:29:59 +0200 (Tue, 21 Jul 2009) $')
24
+ Version::register_svn_info('$Revision: 151 $', '$Date: 2010-06-19 23:45:20 +0200 (Sat, 19 Jun 2010) $')
25
25
 
26
26
  module Graphics
27
27
 
@@ -54,6 +54,7 @@ module CTioga2
54
54
  @optional_arguments = opts
55
55
  @funcall = code
56
56
  end
57
+
57
58
  end
58
59
 
59
60
  # A TiogaPrimitive object describing the current primitive
@@ -65,6 +66,9 @@ module CTioga2
65
66
  # A hash containing the values of the optional arguments
66
67
  attr_accessor :options
67
68
 
69
+ # The last curve's style...
70
+ attr_accessor :last_curve_style
71
+
68
72
 
69
73
  # Creates a new TiogaPrimitiveCall object.
70
74
  def initialize(primitive, arguments, options)
@@ -103,6 +107,7 @@ module CTioga2
103
107
  call = Elements::
104
108
  TiogaPrimitiveCall.new(primitive,
105
109
  rest, options)
110
+ call.last_curve_style = plotmaker.curve_style_stack.last
106
111
  plotmaker.root_object.current_plot.
107
112
  add_element(call)
108
113
  end
@@ -128,16 +133,21 @@ module CTioga2
128
133
  'angle' => 'float',
129
134
  'justification' => 'justification',
130
135
  'alignment' => 'alignment',
136
+ 'font' => 'latex-font',
131
137
  }
132
138
  ) do |t, point, string, options|
133
- # TODO: add a way to specify fonts ???
139
+ # @todo add a way to specify fonts ???
134
140
  options ||= {}
141
+ if options['font']
142
+ string = options['font'].fontify(string)
143
+ options.delete('font')
144
+ end
135
145
  options['text'] = string
136
146
  options['at'] = point.to_figure_xy(t)
137
147
  t.show_text(options)
138
148
  end
139
149
 
140
- # TODO: add rendering mode !!
150
+ # @todo add rendering mode !!
141
151
  MarkerOptions = {
142
152
  'color' => 'color',
143
153
  'stroke_color' => 'color',
@@ -152,7 +162,7 @@ module CTioga2
152
162
 
153
163
  primitive("marker", "marker", [ 'point', 'marker' ],
154
164
  MarkerOptions) do |t, point, marker, options|
155
- # TODO: add a way to specify fonts ???
165
+ ## \todo add a way to specify fonts ???
156
166
  options ||= {}
157
167
  options['marker'] = marker
158
168
  options['at'] = point.to_figure_xy(t)
@@ -162,26 +172,30 @@ module CTioga2
162
172
  primitive("string-marker", "marker", [ 'point', 'text' ],
163
173
  {'font' => 'pdf-font' }.update(MarkerOptions)
164
174
  ) do |t, point, string, options|
165
- # TODO: add a way to specify fonts ???
175
+ ## \todo add a way to specify fonts ???
166
176
  options ||= {}
167
177
  options['text'] = string
168
178
  options['at'] = point.to_figure_xy(t)
169
179
  t.show_marker(options)
170
180
  end
171
181
 
172
- primitive("arrow", "arrow", [ 'point', 'point' ],
173
- {
174
- 'color' => 'color',
175
- 'head_scale' => 'float',
176
- 'head_marker' => 'marker',
177
- 'head_color' => 'color',
178
- 'tail_scale' => 'float',
179
- 'tail_marker' => 'marker',
180
- 'tail_color' => 'color',
181
- 'line_width' => 'float',
182
- 'line_style' => 'line-style',
183
- }
184
- ) do |t, tail,head, options|
182
+ # options for arrows (and therefore tangents)
183
+ ArrowOptions = {
184
+ 'color' => 'color',
185
+ 'head_scale' => 'float',
186
+ 'head_marker' => 'marker',
187
+ 'head_color' => 'color',
188
+ 'tail_scale' => 'float',
189
+ 'tail_marker' => 'marker',
190
+ 'tail_color' => 'color',
191
+ 'line_width' => 'float',
192
+ 'line_style' => 'line-style',
193
+ }
194
+
195
+ primitive("arrow", "arrow", [ 'point', 'point' ],
196
+ ArrowOptions) do |t, tail,head, options|
197
+ ## \todo a scale or marker_scale option that sets the scale
198
+ ## of both head and tail
185
199
  options ||= {}
186
200
  options['head'] = head.to_figure_xy(t)
187
201
  options['tail'] = tail.to_figure_xy(t)
@@ -210,6 +224,9 @@ module CTioga2
210
224
  # Draws the primitive
211
225
  def real_do(t)
212
226
  args = @arguments + [@options]
227
+ ## @todo this is a really ugly hack for passing
228
+ ## last_curve_style around
229
+ $last_curve_style = @last_curve_style
213
230
  primitive.funcall.call(t, *args)
214
231
  end
215
232
 
@@ -219,7 +236,6 @@ A ctioga 1 --draw specification.
219
236
  EOD
220
237
 
221
238
 
222
-
223
239
  # An emulation of the old ctioga behavior
224
240
  CmdDraw = Cmd.new('draw', nil, '--draw',
225
241
  [CmdArg.new('drawing-spec')]) do |plotmaker, spec|
@@ -235,12 +251,12 @@ EOD
235
251
  if a =~ /^\s*([^=]+)=(.*)/
236
252
  opts[$1] = $2
237
253
  else
238
- plotmaker.error "Argument found where a option= was expected: #{a}"
254
+ plotmaker.error { "Argument found where a option= was expected: #{a}" }
239
255
  end
240
256
  end
241
257
  plotmaker.interpreter.run_command(cmd, comp, opts)
242
258
  else
243
- plotmaker.error "Unkown graphics primitive: #{name}"
259
+ plotmaker.error { "Unkown graphics primitive: #{name}" }
244
260
  end
245
261
  end
246
262
 
@@ -0,0 +1,143 @@
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: 139 $', '$Date: 2010-01-22 00:12:17 +0100 (Fri, 22 Jan 2010) $')
21
+
22
+ module Graphics
23
+
24
+ module Elements
25
+
26
+ # A Region is an object that draws filled regions among its
27
+ # "elements". It is a fake container in the sense that all the
28
+ # elements are actually forwarded to the parent.
29
+ class Region < Container
30
+
31
+ undef :elements
32
+ undef :subframe
33
+
34
+ # The curves which delimit the region
35
+ attr_accessor :curves
36
+
37
+ # The fill style
38
+ attr_accessor :fill_style
39
+
40
+ # The fill style for reversed polarity
41
+ attr_accessor :reversed_fill_style
42
+
43
+ # Creates a new empty region
44
+ def initialize(parent = nil, root = nil)
45
+ @parent = parent
46
+
47
+ # elements to be given to tioga
48
+ @curves = []
49
+
50
+ @root_object = root
51
+
52
+ @legend_area = nil
53
+
54
+ @fill_style = Styles::FillStyle.new
55
+ @fill_style.color = [0.7,0.7,0.7]
56
+
57
+ # For reversed polarity
58
+ @reversed_fill_style = Styles::FillStyle.new
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
+ element.curve_style.region_position
66
+ @curves << element
67
+ end
68
+ end
69
+
70
+ # Sets the various things from hash.
71
+ def set_from_hash(hash)
72
+ @fill_style.set_from_hash(hash)
73
+ # Reversed isn't what I want...
74
+ @reversed_fill_style.set_from_hash(hash, 'reversed_%s')
75
+ end
76
+
77
+ # Redirects to the parent's style
78
+ def style(*a)
79
+ return parent.style(*a)
80
+ end
81
+
82
+ protected
83
+
84
+ # Creates the appropriate subfigure and draws all its elements
85
+ # within.
86
+ #
87
+ # \todo: attempt to work fine while mixing curves with
88
+ # different axes. That won't be easy.
89
+ #
90
+ # \todo: enable to do positive and negative. The only thing to
91
+ # do is to swap above for below and call again.
92
+ def real_do(t)
93
+ # This function will be called with the proper figure
94
+ # coordinates.
95
+
96
+ if @fill_style.color
97
+ t.context do
98
+ @fill_style.setup_fill(t)
99
+ prepare_path(t)
100
+ @fill_style.do_fill(t)
101
+ end
102
+ end
103
+
104
+ if @reversed_fill_style.color
105
+ t.context do
106
+ @reversed_fill_style.setup_fill(t)
107
+ prepare_path(t, :reversed)
108
+ @reversed_fill_style.do_fill(t)
109
+ end
110
+ end
111
+
112
+ end
113
+
114
+ # Prepares the path that will be filled, according to the
115
+ # given polarity.
116
+ def prepare_path(t, polarity = :normal)
117
+ # We clip the path for the given
118
+ case polarity
119
+ when :normal
120
+ conversion = {
121
+ :above => :bottom,
122
+ :below => :top
123
+ }
124
+ when :reversed
125
+ conversion = {
126
+ :above => :top,
127
+ :below => :bottom
128
+ }
129
+ end
130
+ # We clip for the first ones...
131
+ for c in @curves[0..-2]
132
+ c.make_closed_path(t, conversion[c.curve_style.region_position])
133
+ t.clip
134
+ end
135
+ # We don't clip on the last one !
136
+ c = @curves.last
137
+ c.make_closed_path(t, conversion[c.curve_style.region_position])
138
+ end
139
+
140
+ end
141
+ end
142
+ end
143
+ end