ctioga2 0.0

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 (82) hide show
  1. data/COPYING +339 -0
  2. data/Changelog +6 -0
  3. data/bin/ctioga2 +26 -0
  4. data/lib/ctioga2/commands/arguments.rb +58 -0
  5. data/lib/ctioga2/commands/commands.rb +258 -0
  6. data/lib/ctioga2/commands/doc/doc.rb +118 -0
  7. data/lib/ctioga2/commands/doc/documentation-commands.rb +119 -0
  8. data/lib/ctioga2/commands/doc/help.rb +95 -0
  9. data/lib/ctioga2/commands/doc/html.rb +230 -0
  10. data/lib/ctioga2/commands/doc/introspection.rb +211 -0
  11. data/lib/ctioga2/commands/doc/man.rb +279 -0
  12. data/lib/ctioga2/commands/doc/markup.rb +359 -0
  13. data/lib/ctioga2/commands/general-commands.rb +119 -0
  14. data/lib/ctioga2/commands/general-types.rb +118 -0
  15. data/lib/ctioga2/commands/groups.rb +73 -0
  16. data/lib/ctioga2/commands/interpreter.rb +257 -0
  17. data/lib/ctioga2/commands/parsers/command-line.rb +187 -0
  18. data/lib/ctioga2/commands/parsers/file.rb +186 -0
  19. data/lib/ctioga2/commands/strings.rb +303 -0
  20. data/lib/ctioga2/commands/type.rb +100 -0
  21. data/lib/ctioga2/commands/variables.rb +101 -0
  22. data/lib/ctioga2/data/backends/backend.rb +260 -0
  23. data/lib/ctioga2/data/backends/backends.rb +39 -0
  24. data/lib/ctioga2/data/backends/backends/gnuplot.rb +140 -0
  25. data/lib/ctioga2/data/backends/backends/math.rb +121 -0
  26. data/lib/ctioga2/data/backends/backends/text.rb +335 -0
  27. data/lib/ctioga2/data/backends/description.rb +405 -0
  28. data/lib/ctioga2/data/backends/factory.rb +73 -0
  29. data/lib/ctioga2/data/backends/parameter.rb +109 -0
  30. data/lib/ctioga2/data/datacolumn.rb +245 -0
  31. data/lib/ctioga2/data/dataset.rb +233 -0
  32. data/lib/ctioga2/data/filters.rb +131 -0
  33. data/lib/ctioga2/data/merge.rb +43 -0
  34. data/lib/ctioga2/data/point.rb +72 -0
  35. data/lib/ctioga2/data/stack.rb +294 -0
  36. data/lib/ctioga2/graphics/coordinates.rb +73 -0
  37. data/lib/ctioga2/graphics/elements.rb +111 -0
  38. data/lib/ctioga2/graphics/elements/containers.rb +111 -0
  39. data/lib/ctioga2/graphics/elements/curve2d.rb +155 -0
  40. data/lib/ctioga2/graphics/elements/element.rb +90 -0
  41. data/lib/ctioga2/graphics/elements/primitive.rb +256 -0
  42. data/lib/ctioga2/graphics/elements/subplot.rb +140 -0
  43. data/lib/ctioga2/graphics/generator.rb +68 -0
  44. data/lib/ctioga2/graphics/legends.rb +108 -0
  45. data/lib/ctioga2/graphics/legends/area.rb +199 -0
  46. data/lib/ctioga2/graphics/legends/items.rb +183 -0
  47. data/lib/ctioga2/graphics/legends/provider.rb +58 -0
  48. data/lib/ctioga2/graphics/legends/storage.rb +65 -0
  49. data/lib/ctioga2/graphics/root.rb +209 -0
  50. data/lib/ctioga2/graphics/styles.rb +30 -0
  51. data/lib/ctioga2/graphics/styles/axes.rb +247 -0
  52. data/lib/ctioga2/graphics/styles/background.rb +122 -0
  53. data/lib/ctioga2/graphics/styles/base.rb +115 -0
  54. data/lib/ctioga2/graphics/styles/carrays.rb +53 -0
  55. data/lib/ctioga2/graphics/styles/curve.rb +101 -0
  56. data/lib/ctioga2/graphics/styles/drawable.rb +87 -0
  57. data/lib/ctioga2/graphics/styles/factory.rb +351 -0
  58. data/lib/ctioga2/graphics/styles/legend.rb +63 -0
  59. data/lib/ctioga2/graphics/styles/plot.rb +410 -0
  60. data/lib/ctioga2/graphics/styles/sets.rb +64 -0
  61. data/lib/ctioga2/graphics/styles/texts.rb +277 -0
  62. data/lib/ctioga2/graphics/subplot-commands.rb +141 -0
  63. data/lib/ctioga2/graphics/types.rb +188 -0
  64. data/lib/ctioga2/graphics/types/bijection.rb +79 -0
  65. data/lib/ctioga2/graphics/types/boundaries.rb +170 -0
  66. data/lib/ctioga2/graphics/types/boxes.rb +157 -0
  67. data/lib/ctioga2/graphics/types/dimensions.rb +157 -0
  68. data/lib/ctioga2/graphics/types/point.rb +247 -0
  69. data/lib/ctioga2/log.rb +97 -0
  70. data/lib/ctioga2/metabuilder/type.rb +316 -0
  71. data/lib/ctioga2/metabuilder/types.rb +39 -0
  72. data/lib/ctioga2/metabuilder/types/coordinates.rb +124 -0
  73. data/lib/ctioga2/metabuilder/types/dates.rb +43 -0
  74. data/lib/ctioga2/metabuilder/types/lists.rb +188 -0
  75. data/lib/ctioga2/metabuilder/types/numbers.rb +97 -0
  76. data/lib/ctioga2/metabuilder/types/strings.rb +93 -0
  77. data/lib/ctioga2/metabuilder/types/styles.rb +178 -0
  78. data/lib/ctioga2/plotmaker.rb +677 -0
  79. data/lib/ctioga2/postprocess.rb +115 -0
  80. data/lib/ctioga2/utils.rb +120 -0
  81. data/setup.rb +1586 -0
  82. metadata +144 -0
@@ -0,0 +1,64 @@
1
+ # carrays.rb: 'circular arrays'
2
+ # copyright (c) 2009 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
+ require 'ctioga2/utils'
15
+ require 'ctioga2/log'
16
+
17
+ # This module contains all the classes used by ctioga
18
+ module CTioga2
19
+
20
+ Version::register_svn_info('$Revision: 2 $', '$Date: 2009-04-25 14:03:30 +0200 (Sat, 25 Apr 2009) $')
21
+
22
+ module Graphics
23
+
24
+ module Styles
25
+
26
+ # Various arrays and hashes suitable for use with CircularArray and
27
+ # CurveStyleFactory
28
+ module Sets
29
+ include Tioga::FigureConstants
30
+
31
+ ColorSets = {
32
+ "default" =>
33
+ [Red, Green, Blue, Cyan, Magenta, Orange],
34
+ "pastel1" =>
35
+ [MediumSeaGreen, RoyalBlue, Pumpkin, DarkChocolate, Lilac, Crimson],
36
+ "colorblind" =>
37
+ [BrightBlue, Goldenrod, Coral, Lilac, FireBrick, RoyalPurple],
38
+ }
39
+
40
+ MarkerSets = {
41
+ "default" =>
42
+ [Bullet, TriangleUp, Square, Plus, Times],
43
+ "open" =>
44
+ [BulletOpen, TriangleUpOpen, SquareOpen, PlusOpen, TimesOpen],
45
+ }
46
+
47
+ LineWidthSets = {
48
+ 'default' => [1.0]
49
+ }
50
+
51
+ LineStyleSets = {
52
+ 'default' => [ LineStyles::Solid,
53
+ LineStyles::Dots,
54
+ LineStyles::Dashes,
55
+ LineStyles::Small_Dots,
56
+ LineStyles::Dot_Long_Dash,
57
+ LineStyles::Dash_Dot_Dot ]
58
+ }
59
+
60
+ end
61
+ end
62
+ end
63
+ end
64
+
@@ -0,0 +1,277 @@
1
+ # texts.rb: style for textual objects
2
+ # copyright (c) 2009 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
+ require 'ctioga2/utils'
15
+ require 'ctioga2/log'
16
+
17
+ # This module contains all the classes used by ctioga
18
+ module CTioga2
19
+
20
+ Version::register_svn_info('$Revision: 94 $', '$Date: 2009-06-25 23:37:13 +0200 (Thu, 25 Jun 2009) $')
21
+
22
+ module Graphics
23
+
24
+ module Styles
25
+
26
+ # Conversion between the #location attribute and the real
27
+ # constant used for Tioga
28
+ LocationToTiogaLocation = {
29
+ :left => Tioga::FigureConstants::LEFT,
30
+ :right => Tioga::FigureConstants::RIGHT,
31
+ :bottom => Tioga::FigureConstants::BOTTOM,
32
+ :top => Tioga::FigureConstants::TOP,
33
+ :at_x_origin => Tioga::FigureConstants::AT_X_ORIGIN,
34
+ :at_y_origin => Tioga::FigureConstants::AT_Y_ORIGIN
35
+ }
36
+
37
+ # Horizontal or vertical
38
+ LocationVertical = {
39
+ :left => true,
40
+ :right => true,
41
+ :bottom => false,
42
+ :top => false,
43
+ :at_x_origin => true,
44
+ :at_y_origin => false
45
+ }
46
+
47
+
48
+ # The style of a text object. This class is suitable for
49
+ # inclusion as a Hash to FigureMaker#show_axis, for the tick
50
+ # labels.
51
+ class BaseTextStyle < BasicStyle
52
+
53
+ # The angle of the text
54
+ attr_accessor :angle
55
+
56
+ # The 'shift' of the text. Only meaningful for axes and tick
57
+ # labels, where the position of the text is specified using a
58
+ # side rather than a precise position
59
+ attr_accessor :shift
60
+
61
+ # The scale of the text
62
+ attr_accessor :scale
63
+
64
+ # The vertical alignment
65
+ attr_accessor :alignement
66
+
67
+ # The horizontal alignment
68
+ attr_accessor :justification
69
+
70
+ # Draw the _text_ at the given location with the given style.
71
+ # If _y_ is _nil_, then _x_or_loc_ is taken to be a location
72
+ # (see FigureMaker#show_text).
73
+ def draw_text(t, text, x_or_loc, y = nil, measure = nil)
74
+ dict = prepare_show_text_dict(text, x_or_loc, y, measure)
75
+ t.show_text(dict)
76
+ end
77
+
78
+ protected
79
+
80
+ # Prepares the dictionnary for use with show_text
81
+ def prepare_show_text_dict(text, x_or_loc, y = nil, measure = nil)
82
+ dict = self.to_hash
83
+ dict['text'] = text
84
+ if y
85
+ dict['at'] = [x_or_loc, y]
86
+ else
87
+ # Perform automatic conversion on the location
88
+ if x_or_loc.is_a? Symbol
89
+ x_or_loc = LocationToTiogaLocation[x_or_loc]
90
+ end
91
+ dict['loc'] = x_or_loc
92
+ end
93
+ if measure
94
+ dict['measure'] = measure
95
+ end
96
+ return dict
97
+ end
98
+ end
99
+
100
+
101
+
102
+ # The style of a full text object.
103
+ class FullTextStyle < BaseTextStyle
104
+ # The color of the text
105
+ attr_accessor :color
106
+
107
+ # The (horizontal) position with respect to a location. You'll
108
+ # seldom need that.
109
+ attr_accessor :position
110
+ end
111
+
112
+ # A hash that can be used as a base for optional arguments to
113
+ # things that take texts.
114
+ FullTextStyleOptions = {
115
+ 'angle' => CmdArg.new('float'),
116
+ 'shift' => CmdArg.new('float'),
117
+ 'scale' => CmdArg.new('float'),
118
+ 'justification' => CmdArg.new('justification'),
119
+ 'color' => CmdArg.new('color'),
120
+ 'align' => CmdArg.new('alignment'),
121
+ }
122
+
123
+ # A label.
124
+ class TextLabel < FullTextStyle
125
+ # The text of the label. _nil_ or _false_ means there will be
126
+ # no text displayed
127
+ attr_accessor :text
128
+
129
+ # The location of the label.
130
+ attr_accessor :loc
131
+
132
+ def initialize(text = nil)
133
+ @text = text
134
+ end
135
+
136
+ # Draw the label, if #text is not _nil_ or _false_.
137
+ # Attributes such as scale, shift and angle are taken from the
138
+ # corresponding _default_ if _default_ isn't nil.
139
+ def draw(t, default = nil, measure = nil)
140
+ if @text
141
+ dict = prepare_label_dict(t, default, measure)
142
+ t.show_text(dict)
143
+ end
144
+ end
145
+
146
+ # Gets the extension of the label, in units of text height.
147
+ # Default values for the various parameters are taken from the
148
+ # _default_ parameter if they are not specified.
149
+ def label_extension(t, default = nil, side = nil)
150
+ if @text
151
+ dict = prepare_label_dict(t, default, nil)
152
+ case side
153
+ when :bottom, :right
154
+ extra = 0.5 # To account for baseline ?
155
+ when :top, :left
156
+ extra = 1
157
+ else # We take the safe side !
158
+ extra = 1
159
+ end
160
+ return (dict['shift'] + extra) * dict['scale']
161
+ else
162
+ return 0
163
+ end
164
+ end
165
+
166
+ protected
167
+
168
+ def prepare_label_dict(t, default = nil, measure = nil)
169
+ dict = prepare_show_text_dict(@text, @loc, nil, measure)
170
+ if default
171
+ for attribute in %w(scale angle shift)
172
+ if ! dict.key?(attribute)
173
+ dict[attribute] = t.send("#{default}_#{attribute}")
174
+ end
175
+ end
176
+ end
177
+ return dict
178
+ end
179
+
180
+ end
181
+
182
+ # Same thing as FullTextStyleOptions, but also permits to
183
+ # override the #text part of the whole stuff..
184
+ FullTextLabelOptions = FullTextStyleOptions.dup
185
+ FullTextLabelOptions['text'] = CmdArg.new('text')
186
+
187
+
188
+
189
+ # The style for a string marker. Hmmm, this is somewhat
190
+ # redundant with TiogaPrimitiveCall::MarkerOptions and I don't
191
+ # like that.
192
+ class MarkerStringStyle < BasicStyle
193
+
194
+ MarkerOptions = {
195
+ 'color' => 'color',
196
+ 'stroke_color' => 'color',
197
+ 'fill_color' => 'color',
198
+ 'scale' => 'float',
199
+ 'horizontal_scale' => 'float',
200
+ 'vertical_scale' => 'float',
201
+ 'angle' => 'float',
202
+ 'justification' => 'justification',
203
+ 'alignment' => 'alignment',
204
+ }
205
+
206
+
207
+ # The angle of the text
208
+ attr_accessor :angle
209
+
210
+ # The scale of the text
211
+ attr_accessor :scale
212
+
213
+ # The horizontal scale of the text
214
+ attr_accessor :horizontal_scale
215
+
216
+ # The vertical scale of the text
217
+ attr_accessor :vertical_scale
218
+
219
+ # The vertical alignment
220
+ attr_accessor :alignement
221
+
222
+ # The horizontal alignment
223
+ attr_accessor :justification
224
+
225
+ # Colors
226
+ attr_accessor :color
227
+ attr_accessor :stroke_color
228
+ attr_accessor :fill_color
229
+
230
+ # A number between 1 to 14 -- a PDF font
231
+ attr_accessor :font
232
+
233
+ # The rendering mode.
234
+ attr_accessor :mode
235
+
236
+ def initialize
237
+ # It make sense to use both by default, as it would be
238
+ # confusing to provide both fill_ and stroke_color that
239
+ # don't have effects by default...
240
+ @mode = Tioga::FigureConstants::FILL_AND_STROKE
241
+ end
242
+
243
+
244
+ # Draws the string marker at the given location
245
+ def draw_string_marker(t, text, x, y)
246
+ dict = self.to_hash
247
+ dict['text'] = text
248
+ dict['at'] = [x, y]
249
+ # TODO !
250
+ dict['mode'] =
251
+ t.show_marker(dict)
252
+ end
253
+
254
+ # Returns the true vertical scale of the marker
255
+ def real_vertical_scale
256
+ return (@vertical_scale || 1.0) * (@scale || 1.0)
257
+ end
258
+ end
259
+
260
+ StringMarkerOptions = {
261
+ 'color' => CmdArg.new('color'),
262
+ 'stroke_color' => CmdArg.new('color'),
263
+ 'fill_color' => CmdArg.new('color'),
264
+ 'scale' => CmdArg.new('float'),
265
+ 'horizontal_scale' => CmdArg.new('float'),
266
+ 'vertical_scale' => CmdArg.new('float'),
267
+ 'angle' => CmdArg.new('float'),
268
+ 'justification' => CmdArg.new('justification'),
269
+ 'alignment' => CmdArg.new('alignment'),
270
+ 'font' => CmdArg.new('pdf-font')
271
+ }
272
+
273
+
274
+ end
275
+ end
276
+ end
277
+
@@ -0,0 +1,141 @@
1
+ # subplot-commands.rb: commands for dealing with subplots
2
+ # copyright (c) 2009 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
+ require 'ctioga2/utils'
15
+ require 'ctioga2/log'
16
+
17
+ module CTioga2
18
+
19
+ Version::register_svn_info('$Revision: 97 $', '$Date: 2009-06-27 21:33:45 +0200 (Sat, 27 Jun 2009) $')
20
+
21
+ module Graphics
22
+
23
+ # The group containing all commands linked to subplots and other
24
+ # insets, frame margin selections...
25
+ SubplotsGroup =
26
+ CmdGroup.new('subplots',
27
+ "Subplots and assimilated",
28
+ "Subplots and assimilated", 31)
29
+
30
+ SetFrameMarginsCommand =
31
+ Cmd.new("frame-margins",nil,"--frame-margins",
32
+ [
33
+ CmdArg.new('frame-margins'),
34
+ ]) do |plotmaker, margins|
35
+
36
+ plotmaker.root_object.current_plot.subframe = margins
37
+ end
38
+
39
+ SetFrameMarginsCommand.describe('Sets the margins of the current plot',
40
+ <<EOH, SubplotsGroup)
41
+ Sets the margins for the current plot. Margins are the same things as the
42
+ position (such as specified for and inset). Using this within an inset or
43
+ more complex plots might produce unexpected results. The main use of this
44
+ function is to control the padding around simple plots.
45
+ EOH
46
+
47
+ PaddingCommand =
48
+ Cmd.new("padding",nil,"--padding",
49
+ [
50
+ CmdArg.new('dimension'),
51
+ ]) do |plotmaker, dim|
52
+
53
+ Styles::PlotStyle.current_plot_style(plotmaker).padding = dim
54
+ end
55
+
56
+ PaddingCommand.describe('Sets the padding for the current plot',
57
+ <<EOH, SubplotsGroup)
58
+ When the {command: frame-margins} is set to automatic, ctioga2 leaves
59
+ that much space around the plot on the sides where there are no labels.
60
+ EOH
61
+
62
+
63
+ InsetCommand =
64
+ Cmd.new("inset",nil,"--inset",
65
+ [
66
+ CmdArg.new('box'),
67
+ ]) do |plotmaker, box|
68
+ subplot = plotmaker.root_object.subplot
69
+ subplot.subframe = box
70
+ end
71
+
72
+ InsetCommand.describe('Begins a new inset',
73
+ <<EOD, SubplotsGroup)
74
+ Starts a new inset at the specified box. If no graphical commands have
75
+ been issued before this one, it starts a top-level box in a blank
76
+ background.
77
+
78
+ TODO: this surely could be clarified a little tiny bit.
79
+ EOD
80
+
81
+ NextInsetCommand =
82
+ Cmd.new("next-inset",nil,"--next-inset",
83
+ [
84
+ CmdArg.new('box'),
85
+ ]) do |plotmaker, box|
86
+ plotmaker.root_object.leave_subobject
87
+ subplot = plotmaker.root_object.subplot
88
+ subplot.subframe = box
89
+ end
90
+
91
+ NextInsetCommand.describe('Ends the previous inset and begins a new one',
92
+ <<EOD, SubplotsGroup)
93
+ Has the same effet as {command: end} followed by {command: inset}.
94
+ EOD
95
+
96
+ EndCommand =
97
+ Cmd.new("end",nil,"--end",
98
+ []) do |plotmaker|
99
+ plotmaker.root_object.leave_subobject
100
+ end
101
+
102
+ EndCommand.describe('Leaves the current subobject',
103
+ <<EOD, SubplotsGroup)
104
+ Leaves the current subobject.
105
+ EOD
106
+
107
+ RescaleCommand =
108
+ Cmd.new("plot-scale",nil,"--plot-scale",
109
+ [CmdArg.new('float')],
110
+ {'what' => CmdArg.new('text')}) do |plotmaker, scale, options|
111
+ what = options['what'] || 'text'
112
+ case what
113
+ when /text/i
114
+ Styles::PlotStyle.current_plot_style(plotmaker).text_scale = scale
115
+ when /lines/i
116
+ Styles::PlotStyle.current_plot_style(plotmaker).lines_scale = scale
117
+ when /both/i
118
+ Styles::PlotStyle.current_plot_style(plotmaker).text_scale = scale
119
+ Styles::PlotStyle.current_plot_style(plotmaker).lines_scale = scale
120
+ else
121
+ CTioga2::Log::error "Unkown 'what' option for plot-scale: #{what}"
122
+ end
123
+ end
124
+
125
+ RescaleCommand.describe('Rescales the current (sub)plot',
126
+ <<EOD, SubplotsGroup)
127
+ Applies a scaling factor to the whole current subplot. Depending on
128
+ the 'what' option (default text), the scale applies to:
129
+ * text ('text' or 'both')
130
+ * marker size ('text' or 'both')
131
+ * line widths ('lines' or 'both')
132
+ Scaling also applies to all elements of the plot that were added
133
+ before the call to plot-scale.
134
+ EOD
135
+
136
+
137
+
138
+ end
139
+
140
+ end
141
+