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.
- data/COPYING +339 -0
- data/Changelog +6 -0
- data/bin/ctioga2 +26 -0
- data/lib/ctioga2/commands/arguments.rb +58 -0
- data/lib/ctioga2/commands/commands.rb +258 -0
- data/lib/ctioga2/commands/doc/doc.rb +118 -0
- data/lib/ctioga2/commands/doc/documentation-commands.rb +119 -0
- data/lib/ctioga2/commands/doc/help.rb +95 -0
- data/lib/ctioga2/commands/doc/html.rb +230 -0
- data/lib/ctioga2/commands/doc/introspection.rb +211 -0
- data/lib/ctioga2/commands/doc/man.rb +279 -0
- data/lib/ctioga2/commands/doc/markup.rb +359 -0
- data/lib/ctioga2/commands/general-commands.rb +119 -0
- data/lib/ctioga2/commands/general-types.rb +118 -0
- data/lib/ctioga2/commands/groups.rb +73 -0
- data/lib/ctioga2/commands/interpreter.rb +257 -0
- data/lib/ctioga2/commands/parsers/command-line.rb +187 -0
- data/lib/ctioga2/commands/parsers/file.rb +186 -0
- data/lib/ctioga2/commands/strings.rb +303 -0
- data/lib/ctioga2/commands/type.rb +100 -0
- data/lib/ctioga2/commands/variables.rb +101 -0
- data/lib/ctioga2/data/backends/backend.rb +260 -0
- data/lib/ctioga2/data/backends/backends.rb +39 -0
- data/lib/ctioga2/data/backends/backends/gnuplot.rb +140 -0
- data/lib/ctioga2/data/backends/backends/math.rb +121 -0
- data/lib/ctioga2/data/backends/backends/text.rb +335 -0
- data/lib/ctioga2/data/backends/description.rb +405 -0
- data/lib/ctioga2/data/backends/factory.rb +73 -0
- data/lib/ctioga2/data/backends/parameter.rb +109 -0
- data/lib/ctioga2/data/datacolumn.rb +245 -0
- data/lib/ctioga2/data/dataset.rb +233 -0
- data/lib/ctioga2/data/filters.rb +131 -0
- data/lib/ctioga2/data/merge.rb +43 -0
- data/lib/ctioga2/data/point.rb +72 -0
- data/lib/ctioga2/data/stack.rb +294 -0
- data/lib/ctioga2/graphics/coordinates.rb +73 -0
- data/lib/ctioga2/graphics/elements.rb +111 -0
- data/lib/ctioga2/graphics/elements/containers.rb +111 -0
- data/lib/ctioga2/graphics/elements/curve2d.rb +155 -0
- data/lib/ctioga2/graphics/elements/element.rb +90 -0
- data/lib/ctioga2/graphics/elements/primitive.rb +256 -0
- data/lib/ctioga2/graphics/elements/subplot.rb +140 -0
- data/lib/ctioga2/graphics/generator.rb +68 -0
- data/lib/ctioga2/graphics/legends.rb +108 -0
- data/lib/ctioga2/graphics/legends/area.rb +199 -0
- data/lib/ctioga2/graphics/legends/items.rb +183 -0
- data/lib/ctioga2/graphics/legends/provider.rb +58 -0
- data/lib/ctioga2/graphics/legends/storage.rb +65 -0
- data/lib/ctioga2/graphics/root.rb +209 -0
- data/lib/ctioga2/graphics/styles.rb +30 -0
- data/lib/ctioga2/graphics/styles/axes.rb +247 -0
- data/lib/ctioga2/graphics/styles/background.rb +122 -0
- data/lib/ctioga2/graphics/styles/base.rb +115 -0
- data/lib/ctioga2/graphics/styles/carrays.rb +53 -0
- data/lib/ctioga2/graphics/styles/curve.rb +101 -0
- data/lib/ctioga2/graphics/styles/drawable.rb +87 -0
- data/lib/ctioga2/graphics/styles/factory.rb +351 -0
- data/lib/ctioga2/graphics/styles/legend.rb +63 -0
- data/lib/ctioga2/graphics/styles/plot.rb +410 -0
- data/lib/ctioga2/graphics/styles/sets.rb +64 -0
- data/lib/ctioga2/graphics/styles/texts.rb +277 -0
- data/lib/ctioga2/graphics/subplot-commands.rb +141 -0
- data/lib/ctioga2/graphics/types.rb +188 -0
- data/lib/ctioga2/graphics/types/bijection.rb +79 -0
- data/lib/ctioga2/graphics/types/boundaries.rb +170 -0
- data/lib/ctioga2/graphics/types/boxes.rb +157 -0
- data/lib/ctioga2/graphics/types/dimensions.rb +157 -0
- data/lib/ctioga2/graphics/types/point.rb +247 -0
- data/lib/ctioga2/log.rb +97 -0
- data/lib/ctioga2/metabuilder/type.rb +316 -0
- data/lib/ctioga2/metabuilder/types.rb +39 -0
- data/lib/ctioga2/metabuilder/types/coordinates.rb +124 -0
- data/lib/ctioga2/metabuilder/types/dates.rb +43 -0
- data/lib/ctioga2/metabuilder/types/lists.rb +188 -0
- data/lib/ctioga2/metabuilder/types/numbers.rb +97 -0
- data/lib/ctioga2/metabuilder/types/strings.rb +93 -0
- data/lib/ctioga2/metabuilder/types/styles.rb +178 -0
- data/lib/ctioga2/plotmaker.rb +677 -0
- data/lib/ctioga2/postprocess.rb +115 -0
- data/lib/ctioga2/utils.rb +120 -0
- data/setup.rb +1586 -0
- metadata +144 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# element.rb: base class of all drawable elements
|
|
2
|
+
# copyright (c) 2006, 2007, 2008, 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, but
|
|
10
|
+
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
12
|
+
# General Public License for more details (in the COPYING file).
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
require 'ctioga2/utils'
|
|
16
|
+
require 'ctioga2/log'
|
|
17
|
+
|
|
18
|
+
# This module contains all the classes used by ctioga
|
|
19
|
+
module CTioga2
|
|
20
|
+
|
|
21
|
+
Version::register_svn_info('$Revision: 54 $', '$Date: 2009-05-20 20:21:11 +0200 (Wed, 20 May 2009) $')
|
|
22
|
+
|
|
23
|
+
# This module contains all graphical elements of CTioga2
|
|
24
|
+
module Graphics
|
|
25
|
+
|
|
26
|
+
# All elements that can be drawn onto a FigureMaker object
|
|
27
|
+
module Elements
|
|
28
|
+
|
|
29
|
+
# The base class for every single object that is drawn on
|
|
30
|
+
# Tioga's output.
|
|
31
|
+
class TiogaElement
|
|
32
|
+
include Log
|
|
33
|
+
|
|
34
|
+
# The parent Container.
|
|
35
|
+
attr_accessor :parent
|
|
36
|
+
|
|
37
|
+
# This function must be called with a FigureMaker object to
|
|
38
|
+
# draw the contents of the TiogaElement onto it. It calls
|
|
39
|
+
# #real_do, which should be redefined by the children. You can
|
|
40
|
+
# redefine _do_ too if you need another debugging output.
|
|
41
|
+
def do(f)
|
|
42
|
+
debug "plotting #{self.inspect}"
|
|
43
|
+
real_do(f)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# We plot everything but parent. If a prefix is given, it is prepended
|
|
47
|
+
# to all lines but the first (for indentation)
|
|
48
|
+
def inspect(prefix="")
|
|
49
|
+
ret = "#<#{self.class.name}:\n"
|
|
50
|
+
for i in instance_variables
|
|
51
|
+
next if i == "@parent"
|
|
52
|
+
var = instance_variable_get(i)
|
|
53
|
+
ret += "#{prefix} - #{i} -> "
|
|
54
|
+
if var.is_a? TiogaElement
|
|
55
|
+
ret += "#{var.inspect("#{prefix} ")}\n"
|
|
56
|
+
else
|
|
57
|
+
ret += "#{var.inspect}\n"
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
ret += "#{prefix}>"
|
|
61
|
+
return ret
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
protected
|
|
65
|
+
|
|
66
|
+
def real_do(t)
|
|
67
|
+
raise "Should be reimplemented by children"
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
# # A unique method call to a FigureMaker object.
|
|
73
|
+
# class TiogaFuncall < TiogaElement
|
|
74
|
+
|
|
75
|
+
# # _symbol_ is the symbol to be called, and the remainder will
|
|
76
|
+
# # be used as arguments for the call.
|
|
77
|
+
# def initialize(symbol, *args)
|
|
78
|
+
# @symbol = symbol
|
|
79
|
+
# @args = args
|
|
80
|
+
# end
|
|
81
|
+
|
|
82
|
+
# protected
|
|
83
|
+
|
|
84
|
+
# def real_do(f)
|
|
85
|
+
# f.send(@symbol, *@args)
|
|
86
|
+
# end
|
|
87
|
+
# end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
# primitive.rb: direct use of graphics primitives for tioga
|
|
2
|
+
# copyright (c) 2006, 2007, 2008, 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, but
|
|
10
|
+
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
12
|
+
# General Public License for more details (in the COPYING file).
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
require 'ctioga2/utils'
|
|
16
|
+
require 'ctioga2/log'
|
|
17
|
+
|
|
18
|
+
require 'ctioga2/graphics/types'
|
|
19
|
+
require 'shellwords'
|
|
20
|
+
|
|
21
|
+
# This module contains all the classes used by ctioga
|
|
22
|
+
module CTioga2
|
|
23
|
+
|
|
24
|
+
Version::register_svn_info('$Revision: 101 $', '$Date: 2009-07-21 23:29:59 +0200 (Tue, 21 Jul 2009) $')
|
|
25
|
+
|
|
26
|
+
module Graphics
|
|
27
|
+
|
|
28
|
+
module Elements
|
|
29
|
+
|
|
30
|
+
# A TiogaElement that represents a graphics primitive.
|
|
31
|
+
class TiogaPrimitiveCall < TiogaElement
|
|
32
|
+
|
|
33
|
+
# Some kind of reimplementation of Command for graphics
|
|
34
|
+
# primitives
|
|
35
|
+
class TiogaPrimitive
|
|
36
|
+
|
|
37
|
+
# A name (not very useful, but, well, we never know)
|
|
38
|
+
attr_accessor :name
|
|
39
|
+
|
|
40
|
+
# An array of compulsory arguments (type specifications)
|
|
41
|
+
attr_accessor :compulsory_arguments
|
|
42
|
+
|
|
43
|
+
# A hash of optional arguments
|
|
44
|
+
attr_accessor :optional_arguments
|
|
45
|
+
|
|
46
|
+
# A block that will receive a FigureMaker object, the
|
|
47
|
+
# compulsory arguments and a hash containing optional ones.
|
|
48
|
+
attr_accessor :funcall
|
|
49
|
+
|
|
50
|
+
# Creates a TiogaPrimitive object
|
|
51
|
+
def initialize(name, comp, opts = {}, &code)
|
|
52
|
+
@name = name
|
|
53
|
+
@compulsory_arguments = comp
|
|
54
|
+
@optional_arguments = opts
|
|
55
|
+
@funcall = code
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# A TiogaPrimitive object describing the current primitive
|
|
60
|
+
attr_accessor :primitive
|
|
61
|
+
|
|
62
|
+
# An array containing the values of the compulsory arguments
|
|
63
|
+
attr_accessor :arguments
|
|
64
|
+
|
|
65
|
+
# A hash containing the values of the optional arguments
|
|
66
|
+
attr_accessor :options
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
# Creates a new TiogaPrimitiveCall object.
|
|
70
|
+
def initialize(primitive, arguments, options)
|
|
71
|
+
@primitive = primitive
|
|
72
|
+
@arguments = arguments
|
|
73
|
+
@options = options
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
@known_primitives = {}
|
|
77
|
+
|
|
78
|
+
PrimitiveCommands = {}
|
|
79
|
+
|
|
80
|
+
PrimitiveGroup = CmdGroup.new('tioga-primitives',
|
|
81
|
+
"Graphics primitives",
|
|
82
|
+
"Tioga graphics primitives", 3)
|
|
83
|
+
|
|
84
|
+
# Creates a new primitive with the given parameters, and makes
|
|
85
|
+
# it immediately available as a command.
|
|
86
|
+
def self.primitive(name, long_name, comp, opts = {}, &code)
|
|
87
|
+
primitive = TiogaPrimitive.new(name, comp, opts, &code)
|
|
88
|
+
@known_primitives[name] = primitive
|
|
89
|
+
|
|
90
|
+
# Now, create the command
|
|
91
|
+
cmd_args = comp.map do |x|
|
|
92
|
+
CmdArg.new(x)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
cmd_opts = {}
|
|
96
|
+
for k,v in opts
|
|
97
|
+
cmd_opts[k] = CmdArg.new(v)
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
cmd = Cmd.new("draw-#{name}",nil,"--draw-#{name}",
|
|
101
|
+
cmd_args, cmd_opts) do |plotmaker, *rest|
|
|
102
|
+
options = rest.pop
|
|
103
|
+
call = Elements::
|
|
104
|
+
TiogaPrimitiveCall.new(primitive,
|
|
105
|
+
rest, options)
|
|
106
|
+
plotmaker.root_object.current_plot.
|
|
107
|
+
add_element(call)
|
|
108
|
+
end
|
|
109
|
+
cmd.describe("Draws #{long_name}",
|
|
110
|
+
"Directly draws #{long_name} on the current plot", PrimitiveGroup)
|
|
111
|
+
|
|
112
|
+
PrimitiveCommands[name] = cmd
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
# Returns a pair primitive/primitive command for the named
|
|
117
|
+
# primitive, or [ _nil_, _nil_ ]
|
|
118
|
+
def self.get_primitive(name)
|
|
119
|
+
return [@known_primitives[name], PrimitiveCommands[name]]
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
# Now, a list of primitives, along with their code.
|
|
123
|
+
|
|
124
|
+
primitive("text", "text", [ 'point', 'text' ],
|
|
125
|
+
{
|
|
126
|
+
'color' => 'color',
|
|
127
|
+
'scale' => 'float',
|
|
128
|
+
'angle' => 'float',
|
|
129
|
+
'justification' => 'justification',
|
|
130
|
+
'alignment' => 'alignment',
|
|
131
|
+
}
|
|
132
|
+
) do |t, point, string, options|
|
|
133
|
+
# TODO: add a way to specify fonts ???
|
|
134
|
+
options ||= {}
|
|
135
|
+
options['text'] = string
|
|
136
|
+
options['at'] = point.to_figure_xy(t)
|
|
137
|
+
t.show_text(options)
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
# TODO: add rendering mode !!
|
|
141
|
+
MarkerOptions = {
|
|
142
|
+
'color' => 'color',
|
|
143
|
+
'stroke_color' => 'color',
|
|
144
|
+
'fill_color' => 'color',
|
|
145
|
+
'scale' => 'float',
|
|
146
|
+
'horizontal_scale' => 'float',
|
|
147
|
+
'vertical_scale' => 'float',
|
|
148
|
+
'angle' => 'float',
|
|
149
|
+
'justification' => 'justification',
|
|
150
|
+
'alignment' => 'alignment',
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
primitive("marker", "marker", [ 'point', 'marker' ],
|
|
154
|
+
MarkerOptions) do |t, point, marker, options|
|
|
155
|
+
# TODO: add a way to specify fonts ???
|
|
156
|
+
options ||= {}
|
|
157
|
+
options['marker'] = marker
|
|
158
|
+
options['at'] = point.to_figure_xy(t)
|
|
159
|
+
t.show_marker(options)
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
primitive("string-marker", "marker", [ 'point', 'text' ],
|
|
163
|
+
{'font' => 'pdf-font' }.update(MarkerOptions)
|
|
164
|
+
) do |t, point, string, options|
|
|
165
|
+
# TODO: add a way to specify fonts ???
|
|
166
|
+
options ||= {}
|
|
167
|
+
options['text'] = string
|
|
168
|
+
options['at'] = point.to_figure_xy(t)
|
|
169
|
+
t.show_marker(options)
|
|
170
|
+
end
|
|
171
|
+
|
|
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|
|
|
185
|
+
options ||= {}
|
|
186
|
+
options['head'] = head.to_figure_xy(t)
|
|
187
|
+
options['tail'] = tail.to_figure_xy(t)
|
|
188
|
+
t.show_arrow(options)
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
primitive("line", "line", [ 'point', 'point' ],
|
|
192
|
+
{
|
|
193
|
+
'color' => 'color',
|
|
194
|
+
'line_width' => 'float',
|
|
195
|
+
'line_style' => 'line-style',
|
|
196
|
+
}
|
|
197
|
+
) do |t, tail,head, options|
|
|
198
|
+
options ||= {}
|
|
199
|
+
for a in ['head', 'tail']
|
|
200
|
+
options["#{a}_marker"] = "None"
|
|
201
|
+
end
|
|
202
|
+
options['head'] = head.to_figure_xy(t)
|
|
203
|
+
options['tail'] = tail.to_figure_xy(t)
|
|
204
|
+
t.show_arrow(options)
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
protected
|
|
209
|
+
|
|
210
|
+
# Draws the primitive
|
|
211
|
+
def real_do(t)
|
|
212
|
+
args = @arguments + [@options]
|
|
213
|
+
primitive.funcall.call(t, *args)
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
DrawingSpecType =
|
|
217
|
+
CmdType.new('drawing-spec', :string, <<EOD)
|
|
218
|
+
A ctioga 1 --draw specification.
|
|
219
|
+
EOD
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
# An emulation of the old ctioga behavior
|
|
224
|
+
CmdDraw = Cmd.new('draw', nil, '--draw',
|
|
225
|
+
[CmdArg.new('drawing-spec')]) do |plotmaker, spec|
|
|
226
|
+
spec =~ /^([^:]+):(.*)/
|
|
227
|
+
name = $1
|
|
228
|
+
args = Shellwords.shellwords($2)
|
|
229
|
+
primitive, cmd = TiogaPrimitiveCall.get_primitive(name)
|
|
230
|
+
if primitive
|
|
231
|
+
# We build the arguments based on the number of compulsory ones
|
|
232
|
+
comp = args.slice!(0,primitive.compulsory_arguments.size)
|
|
233
|
+
opts = {}
|
|
234
|
+
for a in args
|
|
235
|
+
if a =~ /^\s*([^=]+)=(.*)/
|
|
236
|
+
opts[$1] = $2
|
|
237
|
+
else
|
|
238
|
+
plotmaker.error "Argument found where a option= was expected: #{a}"
|
|
239
|
+
end
|
|
240
|
+
end
|
|
241
|
+
plotmaker.interpreter.run_command(cmd, comp, opts)
|
|
242
|
+
else
|
|
243
|
+
plotmaker.error "Unkown graphics primitive: #{name}"
|
|
244
|
+
end
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
CmdDraw.describe("Draws graphics primitives",
|
|
248
|
+
<<EOH, PrimitiveGroup)
|
|
249
|
+
Tries to emulate the old --draw behavior of ctioga. Don't use it for new things.
|
|
250
|
+
EOH
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
end
|
|
254
|
+
end
|
|
255
|
+
end
|
|
256
|
+
end
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# subplot.rb: a subplot
|
|
2
|
+
# copyright (c) 2006, 2007, 2008, 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: 95 $', '$Date: 2009-06-25 23:52:42 +0200 (Thu, 25 Jun 2009) $')
|
|
20
|
+
|
|
21
|
+
module Graphics
|
|
22
|
+
|
|
23
|
+
module Elements
|
|
24
|
+
|
|
25
|
+
# A subplot. It features:
|
|
26
|
+
# * inclusion of curves
|
|
27
|
+
# * legends
|
|
28
|
+
# * a way to set/get its figure boundaries.
|
|
29
|
+
class Subplot < Container
|
|
30
|
+
|
|
31
|
+
# A Boundaries object representing the boundaries imposed by
|
|
32
|
+
# the user.
|
|
33
|
+
attr_accessor :user_boundaries
|
|
34
|
+
|
|
35
|
+
# A Boundaries object representing the boundaries in
|
|
36
|
+
# effect. Only filled with meaningful values from within the
|
|
37
|
+
# real_do function.
|
|
38
|
+
attr_accessor :real_boundaries
|
|
39
|
+
|
|
40
|
+
# Various stylistic aspects of the plot, as a
|
|
41
|
+
# Styles::PlotStyle object.
|
|
42
|
+
attr_accessor :style
|
|
43
|
+
|
|
44
|
+
# Whether or not the parent object should take the boundaries
|
|
45
|
+
# into account or not for its own internal boundaries.
|
|
46
|
+
attr_accessor :count_boundaries
|
|
47
|
+
|
|
48
|
+
def initialize(parent, root, style)
|
|
49
|
+
super(parent, root)
|
|
50
|
+
|
|
51
|
+
@user_boundaries = Types::Boundaries.new(nil, nil, nil, nil)
|
|
52
|
+
@real_boundaries = nil
|
|
53
|
+
|
|
54
|
+
@subframe = Types::MarginsBox.new("2.8dy", "2.8dy",
|
|
55
|
+
"2.8dy", "2.8dy")
|
|
56
|
+
|
|
57
|
+
@subframe = nil # Automatic by default.
|
|
58
|
+
|
|
59
|
+
@style = style || Styles::PlotStyle.new
|
|
60
|
+
|
|
61
|
+
# By default, boundaries do not count for the parent
|
|
62
|
+
@count_boundaries = false
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Returns the boundaries of the SubPlot.
|
|
66
|
+
def get_boundaries
|
|
67
|
+
# raw boundaries
|
|
68
|
+
bounds = get_elements_boundaries
|
|
69
|
+
if @style.plot_margin
|
|
70
|
+
bounds.apply_margin!(@style.plot_margin)
|
|
71
|
+
end
|
|
72
|
+
bounds.override_boundaries(@user_boundaries)
|
|
73
|
+
return bounds
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
protected
|
|
77
|
+
|
|
78
|
+
# Plots all the objects inside the plot.
|
|
79
|
+
def real_do(t)
|
|
80
|
+
# First thing, we setup the boundaries
|
|
81
|
+
|
|
82
|
+
@real_boundaries = get_boundaries
|
|
83
|
+
|
|
84
|
+
frames = @subframe || @style.estimate_margins(t)
|
|
85
|
+
|
|
86
|
+
# We wrap the call within a subplot
|
|
87
|
+
t.subplot(frames.to_frame_margins(t)) do
|
|
88
|
+
|
|
89
|
+
# Setup various aspects of the figure maker object.
|
|
90
|
+
@style.setup_figure_maker(t)
|
|
91
|
+
|
|
92
|
+
# Manually creating the plot:
|
|
93
|
+
t.set_bounds(@real_boundaries.to_a)
|
|
94
|
+
|
|
95
|
+
# Drawing the background elements:
|
|
96
|
+
t.context do
|
|
97
|
+
t.clip_to_frame
|
|
98
|
+
|
|
99
|
+
@style.background.draw_background(t)
|
|
100
|
+
|
|
101
|
+
@style.draw_all_background_lines(t)
|
|
102
|
+
i = 0
|
|
103
|
+
for element in @elements
|
|
104
|
+
element.do(t)
|
|
105
|
+
i += 1
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
@style.draw_all_axes(t)
|
|
109
|
+
|
|
110
|
+
# Now drawing legends:
|
|
111
|
+
if @legend_area
|
|
112
|
+
a, b = @legend_area.partition_frame(t, self)
|
|
113
|
+
t.context do
|
|
114
|
+
t.set_subframe(b)
|
|
115
|
+
@legend_area.display_legend(t, self)
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
# Returns the boundaries of all the elements of this plot.
|
|
123
|
+
def get_elements_boundaries
|
|
124
|
+
elements_bounds = []
|
|
125
|
+
for el in @elements
|
|
126
|
+
if el.respond_to? :get_boundaries
|
|
127
|
+
if el.respond_to?(:count_boundaries) && ! (el.count_boundaries)
|
|
128
|
+
# Ignoring
|
|
129
|
+
else
|
|
130
|
+
elements_bounds << el.get_boundaries
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
return Types::Boundaries.overall_bounds(elements_bounds)
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
end
|