ctioga2 0.3 → 0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog +18 -0
- data/lib/ctioga2/commands/arguments.rb +17 -2
- data/lib/ctioga2/commands/commands.rb +13 -5
- data/lib/ctioga2/commands/context.rb +53 -0
- data/lib/ctioga2/commands/doc/doc.rb +1 -1
- data/lib/ctioga2/commands/doc/documentation-commands.rb +1 -1
- data/lib/ctioga2/commands/doc/help.rb +1 -1
- data/lib/ctioga2/commands/doc/html.rb +1 -1
- data/lib/ctioga2/commands/doc/introspection.rb +16 -1
- data/lib/ctioga2/commands/doc/man.rb +1 -1
- data/lib/ctioga2/commands/doc/markup.rb +1 -1
- data/lib/ctioga2/commands/doc/wordwrap.rb +1 -1
- data/lib/ctioga2/commands/general-commands.rb +1 -1
- data/lib/ctioga2/commands/general-types.rb +1 -1
- data/lib/ctioga2/commands/groups.rb +1 -1
- data/lib/ctioga2/commands/interpreter.rb +22 -1
- data/lib/ctioga2/commands/parsers/command-line.rb +8 -1
- data/lib/ctioga2/commands/parsers/file.rb +2 -1
- data/lib/ctioga2/commands/strings.rb +1 -1
- data/lib/ctioga2/commands/type.rb +1 -1
- data/lib/ctioga2/commands/variables.rb +1 -1
- data/lib/ctioga2/data/backends/backend.rb +1 -1
- data/lib/ctioga2/data/backends/backends/gnuplot.rb +1 -1
- data/lib/ctioga2/data/backends/backends/math.rb +1 -1
- data/lib/ctioga2/data/backends/backends/text.rb +12 -2
- data/lib/ctioga2/data/backends/description.rb +1 -1
- data/lib/ctioga2/data/backends/factory.rb +1 -1
- data/lib/ctioga2/data/backends/parameter.rb +1 -1
- data/lib/ctioga2/data/datacolumn.rb +1 -1
- data/lib/ctioga2/data/dataset.rb +1 -1
- data/lib/ctioga2/data/filters.rb +1 -1
- data/lib/ctioga2/data/indexed-dtable.rb +1 -1
- data/lib/ctioga2/data/point.rb +1 -1
- data/lib/ctioga2/data/stack.rb +6 -6
- data/lib/ctioga2/graphics/coordinates.rb +1 -1
- data/lib/ctioga2/graphics/elements.rb +1 -1
- data/lib/ctioga2/graphics/elements/containers.rb +1 -1
- data/lib/ctioga2/graphics/elements/contour.rb +1 -1
- data/lib/ctioga2/graphics/elements/curve2d.rb +1 -1
- data/lib/ctioga2/graphics/elements/element.rb +1 -1
- data/lib/ctioga2/graphics/elements/gradient-region.rb +1 -1
- data/lib/ctioga2/graphics/elements/parametric2d.rb +1 -1
- data/lib/ctioga2/graphics/elements/primitive.rb +115 -69
- data/lib/ctioga2/graphics/elements/region.rb +1 -1
- data/lib/ctioga2/graphics/elements/subplot.rb +9 -3
- data/lib/ctioga2/graphics/elements/tangent.rb +1 -1
- data/lib/ctioga2/graphics/elements/xyz-map.rb +1 -1
- data/lib/ctioga2/graphics/generator.rb +1 -1
- data/lib/ctioga2/graphics/legends.rb +5 -7
- data/lib/ctioga2/graphics/legends/area.rb +8 -8
- data/lib/ctioga2/graphics/legends/items.rb +2 -2
- data/lib/ctioga2/graphics/legends/provider.rb +1 -1
- data/lib/ctioga2/graphics/legends/storage.rb +1 -1
- data/lib/ctioga2/graphics/root.rb +1 -1
- data/lib/ctioga2/graphics/styles.rb +5 -0
- data/lib/ctioga2/graphics/styles/arrows.rb +53 -0
- data/lib/ctioga2/graphics/styles/axes.rb +29 -23
- data/lib/ctioga2/graphics/styles/background.rb +12 -10
- data/lib/ctioga2/graphics/styles/base.rb +99 -5
- data/lib/ctioga2/graphics/styles/box.rb +67 -0
- data/lib/ctioga2/graphics/styles/carrays.rb +1 -1
- data/lib/ctioga2/graphics/styles/colormap.rb +1 -1
- data/lib/ctioga2/graphics/styles/curve.rb +7 -1
- data/lib/ctioga2/graphics/styles/drawable.rb +24 -11
- data/lib/ctioga2/graphics/styles/errorbar.rb +1 -1
- data/lib/ctioga2/graphics/styles/factory.rb +1 -1
- data/lib/ctioga2/graphics/styles/gradients.rb +3 -3
- data/lib/ctioga2/graphics/styles/legend.rb +20 -5
- data/lib/ctioga2/graphics/styles/location.rb +3 -3
- data/lib/ctioga2/graphics/styles/map-axes.rb +6 -7
- data/lib/ctioga2/graphics/styles/plot.rb +51 -26
- data/lib/ctioga2/graphics/styles/sets.rb +1 -1
- data/lib/ctioga2/graphics/styles/sheet.rb +348 -0
- data/lib/ctioga2/graphics/styles/texts.rb +45 -64
- data/lib/ctioga2/graphics/subplot-commands.rb +1 -1
- data/lib/ctioga2/graphics/types.rb +1 -3
- data/lib/ctioga2/graphics/types/bijection.rb +1 -1
- data/lib/ctioga2/graphics/types/boundaries.rb +1 -1
- data/lib/ctioga2/graphics/types/boxes.rb +1 -1
- data/lib/ctioga2/graphics/types/dimensions.rb +2 -2
- data/lib/ctioga2/graphics/types/grid.rb +1 -1
- data/lib/ctioga2/graphics/types/location.rb +2 -2
- data/lib/ctioga2/graphics/types/point.rb +1 -1
- data/lib/ctioga2/log.rb +10 -6
- data/lib/ctioga2/metabuilder/type.rb +1 -1
- data/lib/ctioga2/metabuilder/types/coordinates.rb +1 -1
- data/lib/ctioga2/metabuilder/types/data.rb +1 -1
- data/lib/ctioga2/metabuilder/types/dates.rb +1 -1
- data/lib/ctioga2/metabuilder/types/lists.rb +1 -1
- data/lib/ctioga2/metabuilder/types/numbers.rb +1 -1
- data/lib/ctioga2/metabuilder/types/strings.rb +1 -1
- data/lib/ctioga2/metabuilder/types/styles.rb +30 -3
- data/lib/ctioga2/plotmaker.rb +1 -1
- data/lib/ctioga2/postprocess.rb +1 -1
- data/lib/ctioga2/utils.rb +78 -3
- metadata +6 -5
- data/lib/ctioga2/git-fools-svn.rb +0 -7
- data/lib/ctioga2/graphics/elements/redirecting-container.rb~ +0 -123
- data/lib/ctioga2/metabuilder/types/generic.rb~ +0 -225
@@ -16,7 +16,7 @@ require 'ctioga2/log'
|
|
16
16
|
|
17
17
|
module CTioga2
|
18
18
|
|
19
|
-
Version::register_svn_info('$Revision$', '$Date$')
|
19
|
+
Version::register_svn_info('$Revision: 329 $', '$Date: 2012-12-11 00:13:17 +0100 (Tue, 11 Dec 2012) $')
|
20
20
|
|
21
21
|
module Graphics
|
22
22
|
|
@@ -103,8 +103,14 @@ module CTioga2
|
|
103
103
|
# Makes up a Boundaries object from two axes keys
|
104
104
|
def get_given_boundaries(horiz, vert)
|
105
105
|
if @computed_boundaries
|
106
|
-
|
107
|
-
|
106
|
+
if @computed_boundaries.key?(horiz) and
|
107
|
+
@computed_boundaries.key?(vert)
|
108
|
+
return Types::Boundaries.from_ranges(@computed_boundaries[horiz],
|
109
|
+
@computed_boundaries[vert])
|
110
|
+
else
|
111
|
+
error { "A subplot element doesn't have inner bounds -- which probably means that no curves were defined" }
|
112
|
+
return Types::Boundaries.new(0.0,1.0,0.0,1.0)
|
113
|
+
end
|
108
114
|
else
|
109
115
|
return nil
|
110
116
|
end
|
@@ -17,7 +17,7 @@ require 'ctioga2/graphics/elements/primitive'
|
|
17
17
|
# This module contains all the classes used by ctioga
|
18
18
|
module CTioga2
|
19
19
|
|
20
|
-
Version::register_svn_info('$Revision$', '$Date$')
|
20
|
+
Version::register_svn_info('$Revision: 171 $', '$Date: 2010-10-22 17:07:52 +0200 (Fri, 22 Oct 2010) $')
|
21
21
|
|
22
22
|
module Graphics
|
23
23
|
|
@@ -19,7 +19,7 @@ require 'ctioga2/graphics/legends/provider'
|
|
19
19
|
|
20
20
|
module CTioga2
|
21
21
|
|
22
|
-
Version::register_svn_info('$Revision$', '$Date$')
|
22
|
+
Version::register_svn_info('$Revision: 357 $', '$Date: 2012-12-26 00:49:11 +0100 (Wed, 26 Dec 2012) $')
|
23
23
|
|
24
24
|
module Graphics
|
25
25
|
|
@@ -54,6 +54,9 @@ EOH
|
|
54
54
|
Adds a line of text unrelated to any curve to the legend.
|
55
55
|
EOH
|
56
56
|
|
57
|
+
|
58
|
+
Commands::make_alias_for_option 'legend-line', 'alignment', 'align', true
|
59
|
+
|
57
60
|
AutoLegendCommand =
|
58
61
|
Cmd.new("auto-legend",nil,"--auto-legend",
|
59
62
|
[ CmdArg.new('boolean') ]) do |plotmaker, value|
|
@@ -66,12 +69,7 @@ When this option is in effect (off by default), all datasets get a legend,
|
|
66
69
|
their 'dataset name', unless another legend is manually specified.
|
67
70
|
EOH
|
68
71
|
|
69
|
-
LegendStyleOptions =
|
70
|
-
'dy' => CmdArg.new('dimension'),
|
71
|
-
'scale' => CmdArg.new('float'),
|
72
|
-
'text_scale' => CmdArg.new('float'),
|
73
|
-
}
|
74
|
-
|
72
|
+
LegendStyleOptions = Styles::LegendStorageStyle.options_hash()
|
75
73
|
|
76
74
|
LegendStyleCommand =
|
77
75
|
Cmd.new("legend-style",nil,"--legend-style",
|
@@ -16,7 +16,7 @@ require 'ctioga2/log'
|
|
16
16
|
|
17
17
|
module CTioga2
|
18
18
|
|
19
|
-
Version::register_svn_info('$Revision$', '$Date$')
|
19
|
+
Version::register_svn_info('$Revision: 359 $', '$Date: 2012-12-26 10:45:35 +0100 (Wed, 26 Dec 2012) $')
|
20
20
|
|
21
21
|
module Graphics
|
22
22
|
|
@@ -27,13 +27,6 @@ module CTioga2
|
|
27
27
|
#
|
28
28
|
# \todo
|
29
29
|
#
|
30
|
-
# * a legend can be plotted either inside a plot or outside the
|
31
|
-
# root object
|
32
|
-
#
|
33
|
-
# * in case it is plotted outside the root object, the user should
|
34
|
-
# be able to choose whether it should be counted in the
|
35
|
-
# real-size or not.
|
36
|
-
#
|
37
30
|
# * legends should provide all the kind of things that were in the
|
38
31
|
# first ctioga, such as background, frames, and so on...
|
39
32
|
#
|
@@ -88,6 +81,13 @@ module CTioga2
|
|
88
81
|
t.set_bounds([0, 1, 1, 0])
|
89
82
|
## \todo customize this !
|
90
83
|
x, y = initial_xy(t, container)
|
84
|
+
|
85
|
+
w,h = *size(t, container)
|
86
|
+
h /= @legend_style.scale * @legend_style.text_scale
|
87
|
+
@legend_style.frame.
|
88
|
+
draw_box_around(t, x, y,
|
89
|
+
x + w, y - h, @legend_style.frame_padding)
|
90
|
+
|
91
91
|
for item in items
|
92
92
|
## \todo transform the 0.0 for x into a negative
|
93
93
|
# user-specifiable stuff.
|
@@ -18,7 +18,7 @@ require 'ctioga2/graphics/styles'
|
|
18
18
|
|
19
19
|
module CTioga2
|
20
20
|
|
21
|
-
Version::register_svn_info('$Revision$', '$Date$')
|
21
|
+
Version::register_svn_info('$Revision: 345 $', '$Date: 2012-12-24 10:43:37 +0100 (Mon, 24 Dec 2012) $')
|
22
22
|
|
23
23
|
module Graphics
|
24
24
|
|
@@ -146,7 +146,7 @@ module CTioga2
|
|
146
146
|
t.subfigure(margin_specs) do
|
147
147
|
# We make the markers slightly smaller than the text
|
148
148
|
# around.
|
149
|
-
t.rescale_text(0.8)
|
149
|
+
t.rescale_text(0.8 * legend_style.symbol_scale)
|
150
150
|
@curve_style.draw_legend_pictogram(t)
|
151
151
|
end
|
152
152
|
end
|
@@ -21,7 +21,7 @@ require 'ctioga2/graphics/subplot-commands'
|
|
21
21
|
|
22
22
|
module CTioga2
|
23
23
|
|
24
|
-
Version::register_svn_info('$Revision$', '$Date$')
|
24
|
+
Version::register_svn_info('$Revision: 155 $', '$Date: 2010-06-21 21:41:32 +0200 (Mon, 21 Jun 2010) $')
|
25
25
|
|
26
26
|
# This module contains all graphical elements of CTioga2
|
27
27
|
module Graphics
|
@@ -14,6 +14,8 @@
|
|
14
14
|
require 'ctioga2/graphics/styles/base'
|
15
15
|
|
16
16
|
require 'ctioga2/graphics/styles/drawable'
|
17
|
+
require 'ctioga2/graphics/styles/arrows'
|
18
|
+
require 'ctioga2/graphics/styles/box'
|
17
19
|
require 'ctioga2/graphics/styles/location'
|
18
20
|
require 'ctioga2/graphics/styles/texts'
|
19
21
|
require 'ctioga2/graphics/styles/carrays'
|
@@ -36,3 +38,6 @@ require 'ctioga2/graphics/styles/legend'
|
|
36
38
|
|
37
39
|
|
38
40
|
require 'ctioga2/graphics/styles/factory'
|
41
|
+
|
42
|
+
# Style sheets
|
43
|
+
require 'ctioga2/graphics/styles/sheet'
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# arrows.rb: style objects for lines and arrows
|
2
|
+
# copyright (c) 2012 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$', '$Date$')
|
21
|
+
|
22
|
+
module Graphics
|
23
|
+
|
24
|
+
# All the styles
|
25
|
+
module Styles
|
26
|
+
|
27
|
+
# This class represents an arrow
|
28
|
+
|
29
|
+
class ArrowStyle < StrokeStyle
|
30
|
+
|
31
|
+
# This probably should end up being a marker_style sub_style
|
32
|
+
|
33
|
+
for e in [:head, :tail]
|
34
|
+
typed_attribute "#{e}_marker".to_sym, 'marker'
|
35
|
+
typed_attribute "#{e}_scale".to_sym, 'float'
|
36
|
+
typed_attribute "#{e}_angle".to_sym, 'float'
|
37
|
+
typed_attribute "#{e}_color".to_sym, 'color'
|
38
|
+
end
|
39
|
+
|
40
|
+
def draw_arrow(t, x1, y1, x2, y2)
|
41
|
+
dict = self.to_hash
|
42
|
+
dict.rename_key('width', 'line_width')
|
43
|
+
dict.rename_key('style', 'line_style')
|
44
|
+
dict['head'] = [x2,y2]
|
45
|
+
dict['tail'] = [x1,y1]
|
46
|
+
t.show_arrow(dict)
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
@@ -17,7 +17,7 @@ require 'ctioga2/log'
|
|
17
17
|
# This module contains all the classes used by ctioga
|
18
18
|
module CTioga2
|
19
19
|
|
20
|
-
Version::register_svn_info('$Revision$', '$Date$')
|
20
|
+
Version::register_svn_info('$Revision: 357 $', '$Date: 2012-12-26 00:49:11 +0100 (Wed, 26 Dec 2012) $')
|
21
21
|
|
22
22
|
module Graphics
|
23
23
|
|
@@ -33,36 +33,44 @@ module CTioga2
|
|
33
33
|
# AXIS_WITH_TICKS_ONLY,
|
34
34
|
# AXIS_WITH_MAJOR_TICKS_AND_NUMERIC_LABELS, and
|
35
35
|
# AXIS_WITH_TICKS_AND_NUMERIC_LABELS.
|
36
|
-
|
36
|
+
typed_attribute :decoration, 'axis-decoration'
|
37
37
|
|
38
38
|
# The position of the axis. Can be one of :left, :right, :top,
|
39
39
|
# :bottom, :at_y_origin or :at_x_origin.
|
40
|
-
|
40
|
+
typed_attribute :location, 'location'
|
41
41
|
|
42
42
|
# Offset of the axis with respect to its normal position. It
|
43
43
|
# is counted *away* from the graph. It is either a
|
44
44
|
# Types::Dimension object or _nil_.
|
45
|
-
|
45
|
+
typed_attribute :offset, 'dimension'
|
46
46
|
|
47
47
|
# The background lines for the given axis. _nil_ for nothing,
|
48
48
|
# or a StrokeStyle object if we want to draw something.
|
49
|
-
|
49
|
+
#
|
50
|
+
# @todo Use a sub-style for that when that is implemented.
|
51
|
+
sub_style :background_lines, StrokeStyle
|
50
52
|
|
51
53
|
# The style of the tick labels
|
52
|
-
|
54
|
+
sub_style :tick_label_style, FullTextStyle, "tick_label_%s"
|
53
55
|
|
54
56
|
# The label of the axis, if there is one
|
55
|
-
|
57
|
+
sub_style :axis_label, TextLabel
|
56
58
|
|
57
59
|
# Whether the axis should be log scale or not
|
58
|
-
|
60
|
+
typed_attribute :log, 'boolean'
|
59
61
|
|
60
62
|
# Transform: a Types::Bijection object specifying a coordinate
|
61
63
|
# transformation for the axis.
|
62
|
-
|
64
|
+
typed_attribute :transform, 'bijection'
|
63
65
|
|
64
66
|
# The color of the stroke for the lines of the axis
|
65
|
-
|
67
|
+
typed_attribute :stroke_color, 'color'
|
68
|
+
|
69
|
+
typed_attribute :major_tick_length, 'float'
|
70
|
+
typed_attribute :major_tick_width, 'float'
|
71
|
+
|
72
|
+
typed_attribute :minor_tick_length, 'float'
|
73
|
+
typed_attribute :minor_tick_width, 'float'
|
66
74
|
|
67
75
|
|
68
76
|
# Creates a new AxisStyle object at the given location with
|
@@ -89,8 +97,14 @@ module CTioga2
|
|
89
97
|
spec = get_axis_specification(t)
|
90
98
|
# Add tick label style:
|
91
99
|
spec.merge!(@tick_label_style.to_hash)
|
92
|
-
|
93
|
-
|
100
|
+
|
101
|
+
# Direct copy of attributes
|
102
|
+
for key in %w(stroke_color major_tick_length major_tick_width
|
103
|
+
minor_tick_length minor_tick_width)
|
104
|
+
val = self.send(key.to_sym)
|
105
|
+
if val
|
106
|
+
spec[key] = val
|
107
|
+
end
|
94
108
|
end
|
95
109
|
t.show_axis(spec)
|
96
110
|
@axis_label.loc = @location
|
@@ -258,17 +272,9 @@ module CTioga2
|
|
258
272
|
|
259
273
|
end
|
260
274
|
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
'log' => CmdArg.new('boolean'),
|
265
|
-
'stroke_color' => CmdArg.new('color')
|
266
|
-
}
|
267
|
-
|
268
|
-
FullAxisStyle = PartialAxisStyle.dup
|
269
|
-
FullAxisStyle['decoration'] = CmdArg.new('axis-decoration')
|
270
|
-
|
271
|
-
|
275
|
+
AxisStyleOptions = AxisStyle.options_hash()
|
276
|
+
PartialAxisStyle = AxisStyleOptions.without('decoration')
|
277
|
+
|
272
278
|
end
|
273
279
|
end
|
274
280
|
end
|
@@ -16,7 +16,7 @@ require 'ctioga2/log'
|
|
16
16
|
|
17
17
|
module CTioga2
|
18
18
|
|
19
|
-
Version::register_svn_info('$Revision$', '$Date$')
|
19
|
+
Version::register_svn_info('$Revision: 342 $', '$Date: 2012-12-23 21:34:48 +0100 (Sun, 23 Dec 2012) $')
|
20
20
|
|
21
21
|
module Graphics
|
22
22
|
|
@@ -28,16 +28,18 @@ module CTioga2
|
|
28
28
|
# * pictures (in a distant future ?)
|
29
29
|
class BackgroundStyle < BasicStyle
|
30
30
|
|
31
|
-
# The background color for a uniform fill.
|
32
|
-
|
31
|
+
# The background color for a uniform fill.
|
32
|
+
#
|
33
|
+
# @todo This should be turned into a full-scale fill style
|
34
|
+
typed_attribute :background_color, 'color-or-false'
|
33
35
|
|
34
36
|
# The text of the watermark, or _nil_ if there should be no
|
35
37
|
# watermark.
|
36
|
-
|
38
|
+
typed_attribute :watermark, 'text'
|
37
39
|
|
38
40
|
# A MarkerStringStyle object representing the style of the
|
39
41
|
# watermark.
|
40
|
-
|
42
|
+
sub_style :watermark_style, MarkerStringStyle, "watermark_%s"
|
41
43
|
|
42
44
|
# Creates a new AxisStyle object at the given location with
|
43
45
|
# the given style.
|
@@ -62,7 +64,7 @@ module CTioga2
|
|
62
64
|
end
|
63
65
|
|
64
66
|
def draw_watermark(t)
|
65
|
-
if @
|
67
|
+
if @watermark
|
66
68
|
x = t.convert_frame_to_figure_x(0.5)
|
67
69
|
y = t.convert_frame_to_figure_y(0.5)
|
68
70
|
|
@@ -70,7 +72,7 @@ module CTioga2
|
|
70
72
|
real_vertical_scale
|
71
73
|
|
72
74
|
# We split lines on \\, just like in standard LaTeX
|
73
|
-
lines = @
|
75
|
+
lines = @watermark.split(/\s*\\\\\s*/)
|
74
76
|
i = + (lines.size-1)/2.0
|
75
77
|
for text in lines
|
76
78
|
@watermark_style.
|
@@ -106,16 +108,16 @@ EOH
|
|
106
108
|
WatermarkCmd =
|
107
109
|
Cmd.new('watermark', nil, '--watermark',
|
108
110
|
[ CmdArg.new('text') ],
|
109
|
-
|
111
|
+
MarkerStringStyle.options_hash) do |plotmaker, text, opts|
|
110
112
|
bg = PlotStyle.current_plot_style(plotmaker).
|
111
113
|
background
|
112
|
-
bg.
|
114
|
+
bg.watermark = text
|
113
115
|
bg.watermark_style.set_from_hash(opts)
|
114
116
|
end
|
115
117
|
|
116
118
|
WatermarkCmd.describe("Sets a watermark for the current plot",
|
117
119
|
<<"EOH", BackgroundGroup)
|
118
|
-
|
120
|
+
Sets a watermark for the background of the current plot.
|
119
121
|
EOH
|
120
122
|
end
|
121
123
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# base.rb: the base of style objects
|
2
|
-
# copyright (c) 2009 by Vincent Fourmond
|
2
|
+
# copyright (c) 2009, 2012 by Vincent Fourmond
|
3
3
|
|
4
4
|
# This program is free software; you can redistribute it and/or modify
|
5
5
|
# it under the terms of the GNU General Public License as published by
|
@@ -16,7 +16,7 @@ require 'ctioga2/log'
|
|
16
16
|
# This module contains all the classes used by ctioga
|
17
17
|
module CTioga2
|
18
18
|
|
19
|
-
Version::register_svn_info('$Revision$', '$Date$')
|
19
|
+
Version::register_svn_info('$Revision: 370 $', '$Date: 2012-12-28 17:40:18 +0100 (Fri, 28 Dec 2012) $')
|
20
20
|
|
21
21
|
module Graphics
|
22
22
|
|
@@ -26,9 +26,6 @@ module CTioga2
|
|
26
26
|
# This style is the base class of a series of style objects that
|
27
27
|
# share one common feature: all their attributes can be set
|
28
28
|
# using the set_from_hash function.
|
29
|
-
#
|
30
|
-
# \todo maybe a basic MetaBuilder::Type should be associated to
|
31
|
-
# each attribute ???
|
32
29
|
class BasicStyle
|
33
30
|
|
34
31
|
OldAttrAccessor = method(:attr_accessor)
|
@@ -40,6 +37,10 @@ module CTioga2
|
|
40
37
|
@attributes ||= []
|
41
38
|
@attributes << symbol
|
42
39
|
OldAttrAccessor.call(symbol)
|
40
|
+
# cl = caller()
|
41
|
+
# if not cl[0] =~ /typed_attribute/
|
42
|
+
# puts "old-style attribute: #{cl[0]}"
|
43
|
+
# end
|
43
44
|
end
|
44
45
|
|
45
46
|
# Returns the list of attributes.
|
@@ -52,6 +53,73 @@ module CTioga2
|
|
52
53
|
end
|
53
54
|
end
|
54
55
|
|
56
|
+
# This function should be the main way now of declaring
|
57
|
+
# attributes, as it allows one to automatically generate an
|
58
|
+
# options hash for Command
|
59
|
+
#
|
60
|
+
# @todo There may be a reason to make some of the attributes
|
61
|
+
# private to some extent ?
|
62
|
+
#
|
63
|
+
# @todo Provide a function to make attributes "aliases" of
|
64
|
+
# others (but just on the hash side of the things), in order
|
65
|
+
# for instance to have halign and valign as aliases for the
|
66
|
+
# less intuitive alignment and justification.
|
67
|
+
def self.typed_attribute(symbol, type)
|
68
|
+
sym = symbol.to_sym
|
69
|
+
self.attr_accessor(sym)
|
70
|
+
type = CmdArg.new(type) unless type.respond_to? :string_to_type
|
71
|
+
@attribute_types ||= {}
|
72
|
+
@attribute_types[sym] = type
|
73
|
+
end
|
74
|
+
|
75
|
+
# Defines an accessor for an attribute which is a BasicStyle
|
76
|
+
# subclass in itself.
|
77
|
+
#
|
78
|
+
# _format_ is the thing fed to the subclass for the
|
79
|
+
# _from_hash_ function.
|
80
|
+
def self.sub_style(symbol, cls, fmt = nil)
|
81
|
+
@sub_styles ||= [] # A list of [symbol, cls, fmt]
|
82
|
+
|
83
|
+
if ! fmt
|
84
|
+
fmt = "#{symbol.to_s}_%s"
|
85
|
+
end
|
86
|
+
|
87
|
+
@sub_styles << [symbol, cls, fmt]
|
88
|
+
# Define the accessor
|
89
|
+
OldAttrAccessor.call(symbol)
|
90
|
+
end
|
91
|
+
|
92
|
+
# Returns a hash suitable for using as an options hash.
|
93
|
+
#
|
94
|
+
# _key_ provides tuning of the key names.
|
95
|
+
def self.options_hash(key = "%s")
|
96
|
+
ret = if superclass.respond_to?(:options_hash)
|
97
|
+
superclass.options_hash(key)
|
98
|
+
else
|
99
|
+
{}
|
100
|
+
end
|
101
|
+
|
102
|
+
if @attribute_types # Not always present
|
103
|
+
for k, v in @attribute_types
|
104
|
+
ret[key % k] = v
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
if @sub_styles # Not always present too
|
109
|
+
for sub in @sub_styles
|
110
|
+
sym, cls, fmt = *sub
|
111
|
+
fmt = key % fmt
|
112
|
+
ret.merge!(cls.options_hash(fmt))
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
return ret
|
117
|
+
end
|
118
|
+
|
119
|
+
def self.sub_styles
|
120
|
+
return @sub_styles
|
121
|
+
end
|
122
|
+
|
55
123
|
# Sets the values of the attributes from the given
|
56
124
|
# _hash_. Keys are looked under the form of
|
57
125
|
#
|
@@ -61,13 +129,39 @@ module CTioga2
|
|
61
129
|
#
|
62
130
|
# Unspecified attributes are not removed from the
|
63
131
|
# object. Extra keys are silently ignored.
|
132
|
+
#
|
133
|
+
# @todo Maybe there should be a way to detect extra attributes ?
|
134
|
+
#
|
135
|
+
# This function returns the number of properties that were
|
136
|
+
# effectively set (including those set in sub-styles)
|
64
137
|
def set_from_hash(hash, name = "%s")
|
138
|
+
nb_set = 0
|
65
139
|
for key_name in self.class.attributes
|
66
140
|
hash_key = name % key_name
|
67
141
|
if hash.key? hash_key
|
68
142
|
self.send("#{key_name}=", hash[hash_key])
|
143
|
+
nb_set += 1
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
if self.class.sub_styles
|
148
|
+
for sub in self.class.sub_styles
|
149
|
+
sym, cls, fmt = *sub
|
150
|
+
cur_var = self.send(sym)
|
151
|
+
if ! cur_var # Create if not present
|
152
|
+
cur_var = cls.new
|
153
|
+
set_after = true
|
154
|
+
end
|
155
|
+
fmt = name % fmt
|
156
|
+
nb = cur_var.set_from_hash(hash, fmt)
|
157
|
+
if nb > 0 and set_after
|
158
|
+
self.send("#{sym}=", cur_var)
|
159
|
+
end
|
160
|
+
nb_set += nb
|
69
161
|
end
|
70
162
|
end
|
163
|
+
return nb_set
|
164
|
+
|
71
165
|
end
|
72
166
|
|
73
167
|
# Creates a new object from a hash specification, just as in
|