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,122 @@
1
+ # background.rb: the style of the background of a plot.
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: 75 $', '$Date: 2009-06-03 00:02:32 +0200 (Wed, 03 Jun 2009) $')
20
+
21
+ module Graphics
22
+
23
+ module Styles
24
+
25
+ # The style of the background of a plot. Handles:
26
+ # * uniform background colors (fine)
27
+ # * (text) watermark
28
+ # * pictures (in a distant future ?)
29
+ class BackgroundStyle < BasicStyle
30
+
31
+ # The background color for a uniform fill.
32
+ attr_accessor :background_color
33
+
34
+ # The text of the watermark, or _nil_ if there should be no
35
+ # watermark.
36
+ attr_accessor :watermark_text
37
+
38
+ # A MarkerStringStyle object representing the style of the
39
+ # watermark.
40
+ attr_accessor :watermark_style
41
+
42
+ # Creates a new AxisStyle object at the given location with
43
+ # the given style.
44
+ def initialize(location = nil, type = nil, label = nil)
45
+ @background_color = nil
46
+ @watermark_style = MarkerStringStyle.new
47
+ @watermark_style.color = [0.5,0.5,0.5]
48
+ end
49
+
50
+ # Draws the background of the current plot. Fills up the
51
+ # current frame.
52
+ def draw_background(t)
53
+ t.context do
54
+ xl, yb, xr, yt =
55
+ t.bounds_left, t.bounds_bottom, t.bounds_right, t.bounds_top
56
+ if @background_color
57
+ t.fill_color = @background_color
58
+ t.fill_frame
59
+ end
60
+ draw_watermark(t)
61
+ end
62
+ end
63
+
64
+ def draw_watermark(t)
65
+ if @watermark_text
66
+ x = t.convert_frame_to_figure_x(0.5)
67
+ y = t.convert_frame_to_figure_y(0.5)
68
+
69
+ delta_y = t.default_text_height_dy * @watermark_style.
70
+ real_vertical_scale
71
+
72
+ # We split lines on \\, just like in standard LaTeX
73
+ lines = @watermark_text.split(/\s*\\\\\s*/)
74
+ i = + (lines.size-1)/2.0
75
+ for text in lines
76
+ @watermark_style.
77
+ draw_string_marker(t, text, x, y + delta_y * i)
78
+ i -= 1
79
+ end
80
+ end
81
+ end
82
+
83
+
84
+ end
85
+
86
+
87
+ BackgroundGroup =
88
+ CmdGroup.new('background',
89
+ "Background", <<EOD, 40)
90
+ Commands dealing with the aspect of the background of a plot (excluding
91
+ background lines, which are linked to axes).
92
+ EOD
93
+
94
+ BackgroundColorCmd =
95
+ Cmd.new('background', nil, '--background',
96
+ [ CmdArg.new('color-or-false') ]) do |plotmaker, color|
97
+ PlotStyle.current_plot_style(plotmaker).
98
+ background.background_color = color
99
+ end
100
+
101
+ BackgroundColorCmd.describe("Background color for the plot",
102
+ <<"EOH", BackgroundGroup)
103
+ Sets the background color for the current (and subsequent?) plot.
104
+ EOH
105
+
106
+ WatermarkCmd =
107
+ Cmd.new('watermark', nil, '--watermark',
108
+ [ CmdArg.new('text') ],
109
+ StringMarkerOptions) do |plotmaker, text, opts|
110
+ bg = PlotStyle.current_plot_style(plotmaker).
111
+ background
112
+ bg.watermark_text = text
113
+ bg.watermark_style.set_from_hash(opts)
114
+ end
115
+
116
+ WatermarkCmd.describe("Sets a watermark for the current plot",
117
+ <<"EOH", BackgroundGroup)
118
+ Watermark...
119
+ EOH
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,115 @@
1
+ # base.rb: the base of style 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/log'
15
+
16
+ # This module contains all the classes used by ctioga
17
+ module CTioga2
18
+
19
+ Version::register_svn_info('$Revision: 32 $', '$Date: 2009-05-03 19:47:29 +0200 (Sun, 03 May 2009) $')
20
+
21
+ module Graphics
22
+
23
+ # All the styles
24
+ module Styles
25
+
26
+ # This style is the base class of a series of style objects that
27
+ # share one common feature: all their attributes can be set
28
+ # using the set_from_hash function.
29
+ #
30
+ # TODO: maybe a basic MetaBuilder::Type should be associated to
31
+ # each attribute ???
32
+ class BasicStyle
33
+
34
+ OldAttrAccessor = method(:attr_accessor)
35
+
36
+ # This redefinition of attr_accessor allows to track for the
37
+ # names of the attributes, while still showing them up
38
+ # properly documented in rdoc.
39
+ def self.attr_accessor(symbol)
40
+ @attributes ||= []
41
+ @attributes << symbol
42
+ OldAttrAccessor.call(symbol)
43
+ end
44
+
45
+ # Returns the list of attributes.
46
+ def self.attributes
47
+ return ( @attributes || [] ) +
48
+ if superclass.respond_to?(:attributes)
49
+ superclass.attributes
50
+ else
51
+ []
52
+ end
53
+ end
54
+
55
+ # Sets the values of the attributes from the given
56
+ # _hash_. Keys are looked under the form of
57
+ #
58
+ # name % key_name
59
+ #
60
+ # where _key_name_ takes all the values of the attributes.
61
+ #
62
+ # Unspecified attributes are not removed from the
63
+ # object. Extra keys are silently ignored.
64
+ def set_from_hash(hash, name = "%s")
65
+ for key_name in self.class.attributes
66
+ hash_key = name % key_name
67
+ if hash.key? hash_key
68
+ self.send("#{key_name}=", hash[hash_key])
69
+ end
70
+ end
71
+ end
72
+
73
+ # Creates a new object from a hash specification, just as in
74
+ # #set_from_hash.
75
+ def self.from_hash(hash, name = "%s")
76
+ obj = self.new
77
+ obj.set_from_hash(hash, name)
78
+ return obj
79
+ end
80
+
81
+ # We define instance_variable_defined? if Ruby does not have
82
+ # it... Old Ruby 1.8 versions don't - that is the case for
83
+ # those on MacOS.
84
+ if not self.respond_to?(:instance_variable_defined?)
85
+ def instance_variable_defined?(iv)
86
+ a = instance_variables.index(iv)
87
+ if a && a >= 0
88
+ return true
89
+ else
90
+ return false
91
+ end
92
+ end
93
+ end
94
+
95
+ # Converts to a hash. Does the reverse of #set_from_hash.
96
+ def to_hash(name = "%s")
97
+ retval = {}
98
+ for attr in self.class.attributes
99
+ if instance_variable_defined?("@#{attr}")
100
+ retval[name % attr] = instance_variable_get("@#{attr}")
101
+ end
102
+ end
103
+ return retval
104
+ end
105
+
106
+ # Updates information from another object.
107
+ def update_from_other(other_object)
108
+ set_from_hash(other_object.to_hash)
109
+ end
110
+
111
+ end
112
+ end
113
+ end
114
+ end
115
+
@@ -0,0 +1,53 @@
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
+ # A CirularArray, i.e an array from which one can extract
27
+ # successive elements in a fixed order, and that turns back to
28
+ # the first element once all have been used (hence 'circular').
29
+ class CircularArray
30
+
31
+ # The set through which we go
32
+ attr_accessor :set
33
+
34
+ def initialize(set)
35
+ @set = set
36
+ end
37
+
38
+ # Returns the next element in the array
39
+ def next
40
+ @value ||= 0
41
+ if @value >= @set.size
42
+ @value = 0
43
+ end
44
+ val = @set[@value]
45
+ @value += 1
46
+ return val
47
+ end
48
+ end
49
+
50
+ end
51
+ end
52
+ end
53
+
@@ -0,0 +1,101 @@
1
+ # curve.rb: style objects pertaining to curves and other line drawings.
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
+ # A class holding all the styles for a curve.
27
+ #
28
+ # TODO: maybe for objects different than Curve2D, a subclass of
29
+ # CurveStyle could be used ? This way, we could have clearly
30
+ # separated legends and the like ?
31
+ class CurveStyle
32
+
33
+ # The style of the line that is drawn, as a StrokeStyle.
34
+ attr_accessor :line
35
+
36
+ # The style of markers that should be drawn, as a MarkerStyle.
37
+ attr_accessor :marker
38
+
39
+ # The text of the legend, if there is one.
40
+ attr_accessor :legend
41
+
42
+ # True if a line should be drawn.
43
+ def has_line?
44
+ return @line && @line.style
45
+ end
46
+
47
+ # True if markers should be drawn
48
+ def has_marker?
49
+ return @marker && @marker.marker
50
+ end
51
+
52
+ # True if there is one legend to be drawn for this object.
53
+ def has_legend?
54
+ return @legend
55
+ end
56
+
57
+ # Sets the values of the different sub-objects from a 'flat'
58
+ # _hash_. Keys have the following meaning:
59
+ # * 'line_...': a StrokeStyle for the drawing the line
60
+ # * 'marker_...': a MarkerStyle for the drawing of markers
61
+ # * 'legend': the legend of the curve
62
+ #
63
+ # TODO: make @legend another object derived from BasicStyle ?
64
+ def set_from_hash(hash)
65
+ @line = StrokeStyle.from_hash(hash, 'line_%s')
66
+ @marker = MarkerStyle.from_hash(hash, 'marker_%s')
67
+ @legend = hash['legend']
68
+ end
69
+
70
+ # Creates a CurveStyle object straight from a hash
71
+ # description. See #set_from_hash for more information.
72
+ def self.from_hash(hash)
73
+ a = CurveStyle.new
74
+ a.set_from_hash(hash)
75
+ return a
76
+ end
77
+
78
+
79
+ # Draws a legend pictogram that fills up the whole current
80
+ # frame.
81
+ #
82
+ # TODO: add more elements to the pictogram in case of more
83
+ # complex things.
84
+ def draw_legend_pictogram(t)
85
+ t.context do
86
+ if has_line?
87
+ @line.set_stroke_style(t)
88
+ t.stroke_line(0.0, 0.5, 1.0, 0.5)
89
+ end
90
+ if has_marker?
91
+ @marker.draw_markers_at(t, [0.5], [0.5])
92
+ end
93
+ end
94
+ end
95
+
96
+
97
+ end
98
+ end
99
+ end
100
+ end
101
+
@@ -0,0 +1,87 @@
1
+ # drawable.rb: style objects pertaining to drawable 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: 61 $', '$Date: 2009-05-29 01:00:56 +0200 (Fri, 29 May 2009) $')
21
+
22
+ module Graphics
23
+
24
+ # All the styles
25
+ module Styles
26
+
27
+ # This class represents all the stylistic information to stroke
28
+ # a Tioga path.
29
+ class StrokeStyle < BasicStyle
30
+ # The color
31
+ attr_accessor :color
32
+
33
+ # The line style
34
+ attr_accessor :style
35
+
36
+ # The line width
37
+ attr_accessor :width
38
+
39
+ # Sets the stroke style to a FigureMaker object, _t_.
40
+ def set_stroke_style(t)
41
+ t.stroke_color = @color if @color
42
+ t.line_type = @style if @style
43
+ t.line_width = @width if @width
44
+ end
45
+ end
46
+
47
+ # This class represents all the stylistic information to draw a
48
+ # Marker.
49
+ #
50
+ # TODO: many things are still missing here...
51
+ class MarkerStyle < BasicStyle
52
+
53
+ # The color
54
+ attr_accessor :color
55
+
56
+ # The marker
57
+ attr_accessor :marker
58
+
59
+ # The marker scale
60
+ attr_accessor :scale
61
+
62
+ # Shows the marker at a given location/set of locations.
63
+ def draw_markers_at(t, x, y)
64
+ if x.is_a? Numeric
65
+ x = Dvector[x]
66
+ y = Dvector[y]
67
+ end
68
+ t.context do
69
+ # Always with line style solid (though that could change ?)
70
+ t.line_type = LineStyles::Solid
71
+ dict = {
72
+ 'Xs' => x, 'Ys' => y,
73
+ 'marker' => @marker,
74
+ 'color' => @color
75
+ }
76
+ if @scale
77
+ dict['scale'] = @scale
78
+ end
79
+ t.show_marker(dict)
80
+ end
81
+ end
82
+ end
83
+
84
+ end
85
+ end
86
+ end
87
+