ctioga 1.11.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. data/COPYING +340 -0
  2. data/ctioga/bin/ctable +28 -0
  3. data/ctioga/bin/ctioga +37 -0
  4. data/ctioga/doc/ctable.1 +156 -0
  5. data/ctioga/doc/ctioga.1 +2363 -0
  6. data/ctioga/examples/README +46 -0
  7. data/ctioga/examples/ctioga.gnuplot +4 -0
  8. data/ctioga/examples/ctioga_within_tioga.rb +53 -0
  9. data/ctioga/examples/ctiogarc.rb +24 -0
  10. data/ctioga/examples/include_1.rb +15 -0
  11. data/ctioga/examples/noise.dat +100 -0
  12. data/ctioga/examples/noise.rb +13 -0
  13. data/ctioga/examples/trig.csv +100 -0
  14. data/ctioga/examples/trig.dat +100 -0
  15. data/ctioga/examples/trig.rb +14 -0
  16. data/ctioga/examples/trigh.dat +100 -0
  17. data/ctioga/examples/trigh.rb +10 -0
  18. data/ctioga/examples/tutorial +763 -0
  19. data/ctioga/examples/tutorial.sh +269 -0
  20. data/ctioga/tests/README +14 -0
  21. data/ctioga/tests/axes.sh +40 -0
  22. data/ctioga/tests/basic.sh +11 -0
  23. data/ctioga/tests/draw.sh +24 -0
  24. data/ctioga/tests/histograms.sh +14 -0
  25. data/ctioga/tests/insets.sh +41 -0
  26. data/ctioga/tests/layouts.sh +29 -0
  27. data/ctioga/tests/legends.sh +113 -0
  28. data/ctioga/tests/styles.sh +43 -0
  29. data/ctioga/tests/test_style.sh +8 -0
  30. data/ctioga/tests/tests.sh +24 -0
  31. data/ctioga/tests/text_backend.sh +83 -0
  32. data/ctioga/tests/tioga_defaults.rb +18 -0
  33. data/lib/CTioga/axes.rb +904 -0
  34. data/lib/CTioga/backends.rb +88 -0
  35. data/lib/CTioga/boundaries.rb +224 -0
  36. data/lib/CTioga/ctable.rb +134 -0
  37. data/lib/CTioga/curve_style.rb +246 -0
  38. data/lib/CTioga/debug.rb +199 -0
  39. data/lib/CTioga/dimension.rb +133 -0
  40. data/lib/CTioga/elements.rb +17 -0
  41. data/lib/CTioga/elements/base.rb +84 -0
  42. data/lib/CTioga/elements/containers.rb +578 -0
  43. data/lib/CTioga/elements/curves.rb +368 -0
  44. data/lib/CTioga/elements/tioga_primitives.rb +440 -0
  45. data/lib/CTioga/layout.rb +595 -0
  46. data/lib/CTioga/legends.rb +29 -0
  47. data/lib/CTioga/legends/cmdline.rb +187 -0
  48. data/lib/CTioga/legends/item.rb +164 -0
  49. data/lib/CTioga/legends/style.rb +257 -0
  50. data/lib/CTioga/log.rb +73 -0
  51. data/lib/CTioga/movingarrays.rb +131 -0
  52. data/lib/CTioga/partition.rb +271 -0
  53. data/lib/CTioga/plot_style.rb +230 -0
  54. data/lib/CTioga/plotmaker.rb +1677 -0
  55. data/lib/CTioga/shortcuts.rb +69 -0
  56. data/lib/CTioga/structures.rb +82 -0
  57. data/lib/CTioga/styles.rb +140 -0
  58. data/lib/CTioga/themes.rb +581 -0
  59. data/lib/CTioga/themes/classical.rb +82 -0
  60. data/lib/CTioga/themes/demo.rb +63 -0
  61. data/lib/CTioga/themes/fits.rb +91 -0
  62. data/lib/CTioga/themes/mono.rb +33 -0
  63. data/lib/CTioga/tioga.rb +32 -0
  64. data/lib/CTioga/utils.rb +173 -0
  65. data/lib/MetaBuilder/Parameters/dates.rb +38 -0
  66. data/lib/MetaBuilder/Parameters/lists.rb +132 -0
  67. data/lib/MetaBuilder/Parameters/numbers.rb +69 -0
  68. data/lib/MetaBuilder/Parameters/strings.rb +86 -0
  69. data/lib/MetaBuilder/Parameters/styles.rb +75 -0
  70. data/lib/MetaBuilder/Qt4/Parameters/dates.rb +51 -0
  71. data/lib/MetaBuilder/Qt4/Parameters/numbers.rb +65 -0
  72. data/lib/MetaBuilder/Qt4/Parameters/strings.rb +106 -0
  73. data/lib/MetaBuilder/Qt4/parameter.rb +172 -0
  74. data/lib/MetaBuilder/Qt4/parameters.rb +9 -0
  75. data/lib/MetaBuilder/descriptions.rb +603 -0
  76. data/lib/MetaBuilder/factory.rb +101 -0
  77. data/lib/MetaBuilder/group.rb +57 -0
  78. data/lib/MetaBuilder/metabuilder.rb +10 -0
  79. data/lib/MetaBuilder/parameter.rb +374 -0
  80. data/lib/MetaBuilder/parameters.rb +11 -0
  81. data/lib/MetaBuilder/qt4.rb +8 -0
  82. data/lib/SciYAG/Backends/backend.rb +379 -0
  83. data/lib/SciYAG/Backends/binner.rb +168 -0
  84. data/lib/SciYAG/Backends/cache.rb +102 -0
  85. data/lib/SciYAG/Backends/dataset.rb +158 -0
  86. data/lib/SciYAG/Backends/descriptions.rb +469 -0
  87. data/lib/SciYAG/Backends/filters.rb +25 -0
  88. data/lib/SciYAG/Backends/filters/average.rb +134 -0
  89. data/lib/SciYAG/Backends/filters/cumulate.rb +37 -0
  90. data/lib/SciYAG/Backends/filters/filter.rb +70 -0
  91. data/lib/SciYAG/Backends/filters/norm.rb +39 -0
  92. data/lib/SciYAG/Backends/filters/smooth.rb +63 -0
  93. data/lib/SciYAG/Backends/filters/sort.rb +43 -0
  94. data/lib/SciYAG/Backends/filters/strip.rb +34 -0
  95. data/lib/SciYAG/Backends/filters/trim.rb +64 -0
  96. data/lib/SciYAG/Backends/gnuplot.rb +131 -0
  97. data/lib/SciYAG/Backends/math.rb +108 -0
  98. data/lib/SciYAG/Backends/mdb.rb +462 -0
  99. data/lib/SciYAG/Backends/multitext.rb +96 -0
  100. data/lib/SciYAG/Backends/source.rb +64 -0
  101. data/lib/SciYAG/Backends/text.rb +339 -0
  102. data/lib/SciYAG/backends.rb +16 -0
  103. metadata +191 -0
@@ -0,0 +1,88 @@
1
+ # backends.rb, copyright (c) 2006 by Vincent Fourmond:
2
+ # The module handling the communication with backends.
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
+ # The backend structure...
15
+ require 'SciYAG/backends'
16
+ require 'MetaBuilder/factory'
17
+ require 'CTioga/utils'
18
+
19
+ module CTioga
20
+
21
+ Version::register_svn_info('$Revision: 696 $', '$Date: 2007-12-06 20:59:20 +0100 (Thu, 06 Dec 2007) $')
22
+
23
+ # This module handles all manipulations of backends.
24
+ module Backends
25
+
26
+ include SciYAG
27
+
28
+ # Initializes the backend structure.
29
+ def init_backend_structure
30
+ @backend_factory =
31
+ MetaBuilder::Factories::UniqueFactory.new(SciYAG::Backends::Backend,
32
+ 'text')
33
+ SciYAG::Backends::Backend.logger = self.logger
34
+ end
35
+
36
+ def backend
37
+ @backend_factory.current
38
+ end
39
+
40
+ def backends
41
+ @backend_factory.instances
42
+ end
43
+
44
+ def set_backend(str)
45
+ @backend_factory.current = str
46
+ end
47
+
48
+
49
+ # Push a filter onto the current backend
50
+ def current_push_filter(filter)
51
+ backend.push_xy_filter(filter)
52
+ end
53
+
54
+ # Fills an OptionParser with the apppropriate stuff to
55
+ # deal with backends:
56
+ def prepare_backend_options(op)
57
+ op.separator "\nHow to select backends, and their options:"
58
+ @backend_factory.option_parser_factory(op)
59
+
60
+ op.separator "\nFilters to apply onto data:"
61
+ for filter_desc in SciYAG::Backends::Filter.description_list
62
+ filter_desc.parser_instantiate_option(op,
63
+ self,
64
+ :current_push_filter)
65
+ end
66
+ op.on("--filter-pop", "Removes the last filter pushed " +
67
+ "onto the current backend") do
68
+ backend.pop_xy_filter
69
+ end
70
+
71
+ op.on("--filter-clear", "Removes all filters applying " +
72
+ "to the current backend") do
73
+ backend.clear_xy_filters
74
+ end
75
+ end
76
+
77
+ # Interprets the +set+ with the current backend and returns the data
78
+ def xy_data_set(set)
79
+ return backend.xy_data(set)
80
+ end
81
+
82
+ # Expands the current set according to the current's backend rules
83
+ def expand_spec(spec)
84
+ backend.expand_sets(spec)
85
+ end
86
+
87
+ end
88
+ end
@@ -0,0 +1,224 @@
1
+ # boundaries.rb: Small class for manipulating boundaries
2
+ # Copyright (c) 2008 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 'CTioga/utils'
15
+
16
+ # A small add-on to the Array class, to make it easy to convert to
17
+ # frame specifications.
18
+ class Array
19
+
20
+ def to_frame(spec = "%s")
21
+ i = 0
22
+ h = {}
23
+ for side in %w(left right top bottom)
24
+ h[ spec % side] = self[i]
25
+ i += 1
26
+ end
27
+ return h
28
+ end
29
+
30
+ end
31
+
32
+
33
+ module CTioga
34
+
35
+ Version::register_svn_info('$Revision: 825 $', '$Date: 2008-07-23 14:36:18 +0200 (Wed, 23 Jul 2008) $')
36
+
37
+ module Utils
38
+
39
+
40
+ # Converting a boundary hash to an array
41
+ def self.frame_to_array(hash, format = '%s')
42
+ return %w(left right top bottom).map {|x| sprintf(format,x) }.map do |f|
43
+ hash[f]
44
+ end
45
+ end
46
+
47
+ # Compose two margins (in the form of arrays): you get the m2 expressed
48
+ # in the same frame as m1, but taken relative to m1.
49
+ def self.compose_margins(m1, m2)
50
+ width = 1 - m1[0] - m1[1]
51
+ height = 1 - m1[2] - m1[3]
52
+
53
+ return [ m1[0] + m2[0] * width,
54
+ m1[1] + m2[1] * width,
55
+ m1[2] + m2[2] * height,
56
+ m1[3] + m2[3] * height
57
+ ]
58
+ end
59
+
60
+
61
+ # A small class to handle boundaries
62
+ class Boundaries
63
+
64
+ attr_accessor :left, :right, :top, :bottom
65
+
66
+ def initialize(*args)
67
+ args.flatten!
68
+
69
+ @left = args[0]
70
+ @right = args[1]
71
+ @top = args[2]
72
+ @bottom = args[3]
73
+ end
74
+
75
+ def xmin
76
+ if @left <= @right
77
+ return @left
78
+ else
79
+ return @right
80
+ end
81
+ end
82
+
83
+ def xmax
84
+ if @left <= @right
85
+ return @right
86
+ else
87
+ return @left
88
+ end
89
+ end
90
+
91
+ def ymin
92
+ if @top <= @bottom
93
+ return @top
94
+ else
95
+ return @bottom
96
+ end
97
+ end
98
+
99
+ def ymax
100
+ if @top <= @bottom
101
+ return @bottom
102
+ else
103
+ return @top
104
+ end
105
+ end
106
+
107
+ # Returns [xmin, xmax, ymin, ymax]. Useful, for instance,
108
+ # for Function#bound_values
109
+ def real_bounds
110
+ return [xmin, xmax, ymin, ymax]
111
+ end
112
+
113
+ def to_a
114
+ return [@left, @right, @top, @bottom]
115
+ end
116
+
117
+ # Returns a 'left' => ..., 'right' => .... hash containg the
118
+ # boundaries.
119
+ def to_hash
120
+ return {
121
+ 'left' => @left,
122
+ 'right' => @right,
123
+ 'top' => @top,
124
+ 'bottom' => @bottom
125
+ }
126
+ end
127
+
128
+ # Returns true if the given X coordinate is within the bounds
129
+ def x_inside?(x)
130
+ return (x >= xmin && x <= xmax)
131
+ end
132
+
133
+ # Returns true if the given Y coordinate is within the bounds
134
+ def y_inside?(y)
135
+ return (y >= ymin && y <= ymax)
136
+ end
137
+
138
+ # The position of the given X coordinate with respect to the
139
+ # boundaries. Returns either :inside, :left or :right
140
+ def where_x?(x)
141
+ if x_inside?(x)
142
+ return :inside
143
+ elsif @left <= @right
144
+ if x < @left
145
+ return :left
146
+ else
147
+ return :right
148
+ end
149
+ else # Right-to-left order
150
+ if x < @right
151
+ return :right
152
+ else
153
+ return :left
154
+ end
155
+ end
156
+ end
157
+
158
+ # The position of the given Y coordinate with respect to the
159
+ # boundaries. Returns either :inside, :top or :bottom
160
+ def where_y?(y)
161
+ if y_inside?(y)
162
+ return :inside
163
+ elsif @top <= @bottom
164
+ if y < @top
165
+ return :top
166
+ else
167
+ return :bottom
168
+ end
169
+ else
170
+ if y < @top
171
+ return :bottom
172
+ else
173
+ return :top
174
+ end
175
+ end
176
+ end
177
+
178
+ end
179
+
180
+ # A function that transforms an inset/legend specification into
181
+ # margins. Specifications understood are:
182
+ # * x,y:w(xh) : box centered on x,y of size w x h (or w x w if
183
+ # h is omitted)
184
+ # * x1,y1;x2,y2 : the exact box
185
+ def self.inset_margins(spec)
186
+ case spec
187
+ when /(.*),(.*):([^x]*)(?:x(.*))?/
188
+ x = $1.to_f; y = $2.to_f; w = $3.to_f
189
+ h = ($4 || $3).to_f
190
+ margins = [x - w/2, 1 - (x + w/2), 1 - (y+h/2), y - h/2]
191
+ when /(.*),(.*);(.*),(.*)/
192
+ x1 = $1.to_f; y1 = $2.to_f;
193
+ x2 = $3.to_f; y2 = $4.to_f;
194
+ left = [x1, x2].min
195
+ right = [x1, x2].max
196
+ top = [y1, y2].max
197
+ bottom = [y1, y2].min
198
+ margins = [left, 1 - right, 1 - top, bottom]
199
+ when /(.*)x(.*)([+-])(.*)([+-])(.*)/ # X geometry-like specification
200
+ w = $1.to_f; h = $2.to_f
201
+ if $3 == '+' # Left
202
+ left = $4.to_f
203
+ right = left + w
204
+ else # Right
205
+ right = $4.to_f
206
+ left = right - w
207
+ end
208
+ if $5 == '+' # Top
209
+ top = $6.to_f
210
+ bottom = top - h
211
+ else # Bottom
212
+ bottom = $6.to_f
213
+ top = bottom + h
214
+ end
215
+ margins = [left, 1 - right, 1 - top, bottom]
216
+ else
217
+ raise "Incorrect inset specification #{spec}"
218
+ end
219
+ return margins
220
+ end
221
+
222
+ end
223
+
224
+ end
@@ -0,0 +1,134 @@
1
+ =begin rdoc
2
+
3
+ This program is copyright 2006 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,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with this program; if not, write to the Free Software
17
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
+ =end
19
+
20
+ # This program enables one to print out as text the data read by the
21
+ # backends. Can come in dead useful for debugging, or if you intend to plot
22
+ # with another data
23
+
24
+ require 'Dobjects/Dvector'
25
+ require 'CTioga/backends'
26
+ require 'CTioga/log'
27
+ require 'optparse'
28
+
29
+ module CTioga
30
+
31
+ Version::register_svn_info('$Revision: 753 $', '$Date: 2008-02-26 15:03:52 +0100 (Tue, 26 Feb 2008) $')
32
+
33
+ class CTable
34
+ include Log
35
+ include Backends
36
+
37
+ attr_accessor :block
38
+ attr_accessor :args
39
+ attr_accessor :print_banner
40
+
41
+ # This can be used by various scripts to add hooks on the parser.
42
+ # You can alternatively use your own parser beforehand, but you lose
43
+ # the benefits of the online help.
44
+ attr_accessor :parser
45
+
46
+ def initialize
47
+ init_logger
48
+ init_backend_structure
49
+ @args = []
50
+ @block = proc { |set,data,*a|
51
+ puts "# #{set}"
52
+ data.each do |x,y|
53
+ puts "#{x}\t#{y}"
54
+ end
55
+ }
56
+
57
+ @print_banner = true
58
+
59
+ @parser = OptionParser.new
60
+ prepare_backend_options(@parser)
61
+
62
+ @parser.separator ""
63
+ @parser.separator "Code execution"
64
+
65
+ @parser.on("-e", "--execute BLOCK",
66
+ "Executes the given ruby code for each set, " ,
67
+ "yielding the set name and its data for each." ,
68
+ "Use 'set' to refer to the set's name, and 'data' " ,
69
+ "for it's data"
70
+ ) do |code|
71
+ self.block = eval "proc { |set,data,*args| #{code}}"
72
+ end
73
+
74
+ @parser.on("-f", "--file FILE",
75
+ "Same as -e except it's specifying a file which is ",
76
+ "read an executed with the same parameters as the BLOCK"
77
+ ) do |file|
78
+ self.block = eval "proc { |set,data,*args| #{IO.readlines(file).join}}"
79
+ end
80
+
81
+ @parser.on("-r", "--require FILE",
82
+ "Ask ruby to require the file before data processing.",
83
+ "You can use it to declare some external functions."
84
+ ) do |file|
85
+ require file
86
+ end
87
+
88
+ @parser.on("-a", "--arg a",
89
+ "Provides additionnal arguments to your code") do |arg|
90
+ @args << arg
91
+ end
92
+
93
+ end
94
+
95
+ def process_data_set(set)
96
+ data = xy_data_set(set)
97
+ @block.call(set,data,*@args)
98
+ end
99
+
100
+ # Runs the program with the given command-line arguments. If a block
101
+ # is given, use this block rather than the default one. Be careful,
102
+ # though, as command-line arguments can still override this.
103
+ def run(cmd_line_args,*extra_args, &a)
104
+ $stderr.puts <<"EOBANNER" if @print_banner
105
+ This is ctable version #{Version.version},
106
+ copyright (C) 2006-2007 Vincent Fourmond.
107
+ ctable comes with absolutely NO WARRANTY. This is free software, you are
108
+ welcome to redistribute it under certain conditions. See the COPYING file
109
+ in the original tarball for details. You are also welcome to contribute if
110
+ you like it, see in the manual page where to ask.
111
+ EOBANNER
112
+
113
+ # Use the user-given block
114
+ if block_given?
115
+ @block = a
116
+ end
117
+ @args = extra_args
118
+
119
+ @parser.order(cmd_line_args) do |spec|
120
+ # We use Backend#expand to leave room for the backend to
121
+ # interpret the text as many different sets.
122
+ expand_spec(spec).each do |set|
123
+ process_data_set(set)
124
+ end
125
+ end
126
+ end
127
+
128
+ # A simple convenience function.
129
+ def self.run(args, &a)
130
+ self.new.run(args,&a)
131
+ end
132
+
133
+ end
134
+ end
@@ -0,0 +1,246 @@
1
+ # curves.rb, copyright (c) 2006 by Vincent Fourmond:
2
+ # The class describing a curve to be plotted.
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 'CTioga/elements'
15
+ require 'CTioga/utils'
16
+ require 'CTioga/boundaries'
17
+
18
+ module CTioga
19
+
20
+ Version::register_svn_info('$Revision: 873 $', '$Date: 2009-01-20 17:07:00 +0100 (Tue, 20 Jan 2009) $')
21
+
22
+ # This structure holds the different properties to be transmitted to
23
+ # a Curve object for appropriate drawing.
24
+
25
+ # TODO: create StrokeStyle and a FillStyle objects that would handle every
26
+ # place where there are fills and strokes (background, grids,
27
+ # legend frame and of course curves) !!!
28
+
29
+ class CurveStyle
30
+ ELEMENTS = [
31
+ :color, :marker, :marker_color,
32
+ :line_style, :legend, :linewidth,
33
+ :interpolate, :marker_scale,
34
+ :error_bar_color, :drawing_order,
35
+ :transparency, # Stroke transparency
36
+ :marker_transparency,
37
+ :error_bars_transparency,
38
+ # Now, fill information
39
+ :fill_type, # not false/nil => there will be
40
+ # some filling. See Curve2D#draw_fill for more info
41
+ :fill_color, :fill_transparency,
42
+ :hist_type, # See below
43
+ :hist_left, # the position of the left part of the step
44
+ :hist_right, # the position of the right part of the step
45
+ ]
46
+ attr_writer *ELEMENTS
47
+
48
+ # Special accessors: they implement the :"=>stuff" redirection. Beware
49
+ # of circular redirections !!!
50
+ for el in ELEMENTS
51
+ eval <<"EOE"
52
+ def #{el.to_s}
53
+ if @#{el.to_s}.is_a?(Symbol) && @#{el.to_s}.to_s =~ /^=>(.*)/
54
+ new_sym = $1.to_sym
55
+ if new_sym == :#{el.to_s}
56
+ return nil
57
+ end
58
+ return self[new_sym]
59
+ else
60
+ return @#{el.to_s}
61
+ end
62
+ end
63
+ EOE
64
+ end
65
+
66
+ # The order of the plotting operations. Default is 0
67
+ # (path then markers then error_bars)
68
+ DrawingOrder = [
69
+ [:path, :markers, :error_bars],
70
+ [:path, :error_bars, :markers],
71
+ [:markers, :path, :error_bars],
72
+ [:markers, :error_bars, :path ],
73
+ [:error_bars, :path, :markers],
74
+ [:error_bars, :markers, :path]
75
+ ]
76
+
77
+ Defaults = {
78
+ :marker_scale => 0.5,
79
+ :error_bar_color => :'=>color', # Defaults to the same as color
80
+ :drawing_order => 0,
81
+ :transparency => false,
82
+ :fill_type => false, # No fill by default.
83
+ :fill_color => :'=>color', # Defaults to the same as color
84
+ :hist_type => false, # old style by default...
85
+ :hist_left => 0.0, # joint lines by default
86
+ :hist_right => 1.0, # joint lines by default
87
+ }
88
+
89
+ # A hash to deal with fill types, to be used as an argument for
90
+ # the Utils::interpret_arg function.
91
+ FillTypeArguments = {
92
+ /no(ne)?/ => false,
93
+ /y[_-]ax(is)?/ => :to_y_axis,
94
+ /bottom/ => :to_bottom,
95
+ /top/ => :to_top,
96
+ /old-styke/ => :old_style, # essentially for histograms
97
+ }
98
+
99
+ # Creates a CurveStyle element. There are several ways to
100
+ # initialize:
101
+ # * no arguments (_args_ empty): a CurveStyle object is created
102
+ # with all its values set to nil
103
+ # * at least one argument: arguments are taken as values in the
104
+ # order given by the ELEMENTS array. In this case, arguments
105
+ # not present default to the value given in the Defaults
106
+ # hash. This behaviour is mainly to keep old things working.
107
+ # * The new and best way to do it is to feed it a hash, in which
108
+ # case elements not present in the hash get the values in
109
+ # Default.
110
+ def initialize(*args)
111
+ if args.length == 0
112
+ return # We don't set anything in this case
113
+ end
114
+
115
+ if (h = args[0]).is_a? Hash
116
+ for el in ELEMENTS
117
+ if h.key?(el)
118
+ self[el] = h[el]
119
+ elsif Defaults.key?(el)
120
+ self[el] = Defaults[el]
121
+ end
122
+ end
123
+ else
124
+ # If there is at least one argument, we consider them as
125
+ # values in the order of ELEMENTS
126
+ for el in ELEMENTS
127
+ if args.length > 0
128
+ self[el] = args.shift
129
+ else
130
+ if Defaults.key?(el)
131
+ self[el] = Defaults[el]
132
+ end
133
+ end
134
+ end
135
+ end
136
+
137
+ # This is not the place where to do this. It should be implemented
138
+ # as part of the attribute accessors.
139
+ # # Now, if there is any entry with a value of a symbol starting with
140
+ # # => , its value is replaced by the value for the pointed elements.
141
+ # # That is =>color means 'replace by the color'. Be careful however
142
+ # # with circular dependencies !!!
143
+ # for el in ELEMENTS
144
+ # if self[el].is_a?(Symbol) && self[el].to_s =~ /^=>(.*)/
145
+ # self[el] = self[$1.to_sym]
146
+ # end
147
+ # end
148
+ end
149
+
150
+ # Overrides the style entries with the ones found in _other_.
151
+ def override!(other)
152
+ for iv in ELEMENTS
153
+ if other.instance_variables.include?("@" + iv.to_s)
154
+ # We use instance_variables.include? rather
155
+ # than instance_variable_defined?, as the latter
156
+ # is present only in recent versions of Ruby 1.8
157
+ send(iv.to_s + "=", other.send(iv))
158
+ end
159
+ end
160
+ end
161
+
162
+ # Returns a hash suitable to pass on to save_legend_info, or return
163
+ # false if there was no legend specified in the style.
164
+ def legend_info
165
+ if legend
166
+ legend_info = {
167
+ 'text' => legend,
168
+ 'marker' => marker,
169
+ 'marker_color' => marker_color,
170
+ 'marker_scale' => marker_scale,
171
+ }
172
+ if color && line_style
173
+ legend_info['line_color'] = color
174
+ legend_info['line_type'] = line_style
175
+ else # Line drawing is disabled.
176
+ legend_info["line_width"] = -1
177
+ end
178
+ return legend_info
179
+ else
180
+ return false
181
+ end
182
+ end
183
+
184
+ # Returns true if the style element actually carries a legend
185
+ def has_legend?
186
+ return legend ? true : false
187
+ end
188
+
189
+
190
+ # Remove attributes. Can be used to 'unset' current default.
191
+ def delete(*vars)
192
+ for iv in vars
193
+ begin
194
+ remove_instance_variable('@' + iv.to_s)
195
+ rescue NameError
196
+ end
197
+ end
198
+ end
199
+
200
+ # Hash-like accessor:
201
+ def [](elem)
202
+ if ELEMENTS.include?(elem)
203
+ return self.send(elem)
204
+ else
205
+ raise NameError, "Unkown element of CurveStyle: #{elem}"
206
+ end
207
+ end
208
+
209
+ def []=(elem, value)
210
+ if ELEMENTS.include?(elem)
211
+ self.send(elem.to_s + '=', value)
212
+ else
213
+ raise NameError, "Unkown element of CurveStyle: #{elem}"
214
+ end
215
+ end
216
+
217
+ # A function to be used to output legend pictograms separately.
218
+ # It takes all the place available in the current context of the
219
+ # FigureMaker object _t_.
220
+ def output_legend_pictogram(t)
221
+ t.context do
222
+ # output line
223
+ if color && line_style
224
+ t.line_color = color
225
+ t.line_width = linewidth if linewidth
226
+ # t.line_cap = dict['line_cap']
227
+ t.line_type = line_style
228
+ t.stroke_line(0.0, 0.5, 1.0, 0.5)
229
+ end
230
+ if marker
231
+ t.line_type = Tioga::FigureConstants::Line_Type_Solid
232
+ t.show_marker( 'x' => 0.5,
233
+ 'y' => 0.5,
234
+ 'marker' => marker,
235
+ 'color' => marker_color,
236
+ 'scale' => marker_scale,
237
+ 'alignment' => Tioga::FigureConstants::ALIGNED_AT_MIDHEIGHT,
238
+ 'justification' => Tioga::FigureConstants::CENTERED
239
+ )
240
+ end
241
+ end
242
+ end
243
+
244
+ end
245
+
246
+ end