ctioga2 0.4 → 0.5
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/Changelog +16 -0
- data/lib/ctioga2/commands/arguments.rb +5 -2
- data/lib/ctioga2/commands/commands.rb +45 -13
- data/lib/ctioga2/commands/context.rb +9 -1
- data/lib/ctioga2/commands/doc/help.rb +2 -2
- data/lib/ctioga2/commands/doc/html.rb +8 -8
- data/lib/ctioga2/commands/doc/introspection.rb +7 -5
- data/lib/ctioga2/commands/parsers/file.rb +123 -120
- data/lib/ctioga2/commands/parsers/old-file.rb +191 -0
- data/lib/ctioga2/commands/strings.rb +2 -2
- data/lib/ctioga2/data/datacolumn.rb +5 -2
- data/lib/ctioga2/data/dataset.rb +3 -13
- data/lib/ctioga2/data/indexed-dtable.rb +43 -11
- data/lib/ctioga2/data/stack.rb +65 -8
- data/lib/ctioga2/graphics/elements.rb +2 -1
- data/lib/ctioga2/graphics/elements/containers.rb +22 -3
- data/lib/ctioga2/graphics/elements/primitive.rb +5 -5
- data/lib/ctioga2/graphics/elements/xyz-contour.rb +123 -0
- data/lib/ctioga2/graphics/generator.rb +31 -5
- data/lib/ctioga2/graphics/legends.rb +44 -3
- data/lib/ctioga2/graphics/legends/area.rb +28 -9
- data/lib/ctioga2/graphics/legends/items.rb +34 -23
- data/lib/ctioga2/graphics/legends/multicols.rb +132 -0
- data/lib/ctioga2/graphics/styles.rb +3 -1
- data/lib/ctioga2/graphics/styles/axes.rb +10 -4
- data/lib/ctioga2/graphics/styles/base.rb +65 -11
- data/lib/ctioga2/graphics/styles/colormap.rb +2 -1
- data/lib/ctioga2/graphics/styles/contour.rb +141 -0
- data/lib/ctioga2/graphics/styles/curve.rb +49 -67
- data/lib/ctioga2/graphics/styles/drawable.rb +17 -8
- data/lib/ctioga2/graphics/styles/factory.rb +79 -38
- data/lib/ctioga2/graphics/styles/legend.rb +49 -6
- data/lib/ctioga2/graphics/styles/plot.rb +10 -9
- data/lib/ctioga2/graphics/styles/sheet.rb +11 -11
- data/lib/ctioga2/graphics/styles/texts.rb +38 -9
- data/lib/ctioga2/graphics/types.rb +20 -1
- data/lib/ctioga2/graphics/types/dimensions.rb +7 -1
- data/lib/ctioga2/metabuilder/types/lists.rb +4 -4
- data/lib/ctioga2/metabuilder/types/numbers.rb +3 -3
- data/lib/ctioga2/metabuilder/types/styles.rb +2 -2
- data/lib/ctioga2/plotmaker.rb +12 -1
- data/lib/ctioga2/utils.rb +27 -3
- metadata +8 -4
@@ -18,7 +18,7 @@ require 'ctioga2/graphics/styles'
|
|
18
18
|
|
19
19
|
module CTioga2
|
20
20
|
|
21
|
-
Version::register_svn_info('$Revision:
|
21
|
+
Version::register_svn_info('$Revision: 386 $', '$Date: 2013-03-11 22:57:16 +0100 (Mon, 11 Mar 2013) $')
|
22
22
|
|
23
23
|
module Graphics
|
24
24
|
|
@@ -64,8 +64,31 @@ module CTioga2
|
|
64
64
|
|
65
65
|
# Returns the _y_ value for the baseline of the text in terms
|
66
66
|
# of figure coordinates.
|
67
|
+
#
|
68
|
+
# This is plain wrong, I think...
|
67
69
|
def get_baseline_y(t, legend_style, y)
|
68
|
-
|
70
|
+
w , h = size(t, legend_style)
|
71
|
+
return y - h # This is wrong, but not as bad ;-)...
|
72
|
+
end
|
73
|
+
|
74
|
+
# Computes the text size
|
75
|
+
def text_size(t, legend_style)
|
76
|
+
height = legend_style.dy_to_figure(t)
|
77
|
+
|
78
|
+
width = 0.0
|
79
|
+
|
80
|
+
info = t.get_text_size(legend_name)
|
81
|
+
|
82
|
+
if info.key? 'width'
|
83
|
+
width += t.convert_output_to_figure_dx(10*info['width'])
|
84
|
+
|
85
|
+
h = t.convert_output_to_figure_dy(10*info['height'])
|
86
|
+
if h > height
|
87
|
+
height = h
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
return [ width, height ]
|
69
92
|
end
|
70
93
|
|
71
94
|
|
@@ -98,17 +121,7 @@ module CTioga2
|
|
98
121
|
# Computes the size of the line. Height should always be
|
99
122
|
# accurate, but width can be 0 sometimes...
|
100
123
|
def size(t, legend_style)
|
101
|
-
|
102
|
-
|
103
|
-
width = 0.0
|
104
|
-
|
105
|
-
info = t.get_text_size(legend_name)
|
106
|
-
|
107
|
-
if info.key? 'width'
|
108
|
-
width += t.convert_output_to_figure_dx(10*info['width'])
|
109
|
-
end
|
110
|
-
|
111
|
-
return [ width, height ]
|
124
|
+
return text_size(t, legend_style)
|
112
125
|
end
|
113
126
|
|
114
127
|
end
|
@@ -155,23 +168,21 @@ module CTioga2
|
|
155
168
|
legend_style.picto_to_text.to_figure(t),
|
156
169
|
'y' => y, 'text' => @curve_style.legend,
|
157
170
|
'measure' => legend_name,
|
158
|
-
'justification' => Tioga::FigureConstants::LEFT_JUSTIFIED
|
171
|
+
'justification' => Tioga::FigureConstants::LEFT_JUSTIFIED,
|
172
|
+
'alignment' => Tioga::FigureConstants::ALIGNED_AT_BASELINE)
|
159
173
|
end
|
160
174
|
|
161
175
|
# Computes the size of the line. Height should always
|
162
176
|
# be accurate, but width can be 0 sometimes...
|
163
177
|
def size(t, legend_style)
|
164
|
-
height =
|
165
|
-
|
166
|
-
width = legend_style.picto_width.to_figure(t) +
|
178
|
+
width, height = text_size(t, legend_style)
|
179
|
+
width += legend_style.picto_width.to_figure(t) +
|
167
180
|
legend_style.picto_to_text.to_figure(t)
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
if info.key? 'width'
|
172
|
-
width += t.convert_output_to_figure_dx(10*info['width'])
|
181
|
+
lh = Types::Dimension.new(:dy, 1, :y).to_figure(t,:y)
|
182
|
+
if lh > height
|
183
|
+
height = lh
|
173
184
|
end
|
174
|
-
|
185
|
+
|
175
186
|
return [ width, height ]
|
176
187
|
end
|
177
188
|
|
@@ -0,0 +1,132 @@
|
|
1
|
+
# items.rb: individual legend items
|
2
|
+
# copyright (c) 2013 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
|
+
require 'ctioga2/utils'
|
15
|
+
require 'ctioga2/log'
|
16
|
+
|
17
|
+
require 'ctioga2/graphics/styles'
|
18
|
+
|
19
|
+
module CTioga2
|
20
|
+
|
21
|
+
Version::register_svn_info('$Revision$', '$Date$')
|
22
|
+
|
23
|
+
module Graphics
|
24
|
+
|
25
|
+
module Legends
|
26
|
+
|
27
|
+
# This class is an item that holds other items, and displays
|
28
|
+
# them in columns.
|
29
|
+
#
|
30
|
+
# @todo Add support for tiling on lines too ;-)...
|
31
|
+
#
|
32
|
+
# @todo Add support for filling up to some width/height.
|
33
|
+
#
|
34
|
+
# @todo Choose the order (vert first or horiz first)
|
35
|
+
class MultiColumnLegend < LegendItem
|
36
|
+
|
37
|
+
# The underlying storage
|
38
|
+
attr_accessor :storage
|
39
|
+
|
40
|
+
# The style
|
41
|
+
attr_accessor :style
|
42
|
+
|
43
|
+
def initialize(cols = 2)
|
44
|
+
super()
|
45
|
+
@storage = LegendStorage.new
|
46
|
+
@style = Styles::MultiColumnLegendStyle.new
|
47
|
+
end
|
48
|
+
|
49
|
+
# Adds an item to the underlying storage.
|
50
|
+
def add_item(item)
|
51
|
+
@storage.add_item(item)
|
52
|
+
end
|
53
|
+
|
54
|
+
# Draws all the legends
|
55
|
+
def draw(t, legend_style, x, y)
|
56
|
+
items = storage.harvest_contents()
|
57
|
+
size(t, legend_style)
|
58
|
+
|
59
|
+
index = 0
|
60
|
+
|
61
|
+
dy = 0
|
62
|
+
dx = 0
|
63
|
+
cur_height = legend_style.dy_to_figure(t)
|
64
|
+
|
65
|
+
for it in items
|
66
|
+
w, h = it.size(t, legend_style)
|
67
|
+
col = index % @style.columns
|
68
|
+
|
69
|
+
# Flush
|
70
|
+
if col == 0
|
71
|
+
dy -= cur_height unless index == 0
|
72
|
+
dx = 0
|
73
|
+
cur_height = h
|
74
|
+
else
|
75
|
+
dx += @column_widths[col - 1]
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
if cur_height < h
|
80
|
+
cur_height = h
|
81
|
+
end
|
82
|
+
|
83
|
+
it.draw(t, legend_style, x + dx, y + dy)
|
84
|
+
index += 1
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
# Computes the size of all the legends, and also update the
|
90
|
+
# @column_widths array.
|
91
|
+
def size(t, legend_style)
|
92
|
+
items = storage.harvest_contents()
|
93
|
+
|
94
|
+
# Always that much !
|
95
|
+
cur_height = legend_style.dy_to_figure(t)
|
96
|
+
widths = [0] * @style.columns
|
97
|
+
height = 0
|
98
|
+
index = 0
|
99
|
+
for it in items
|
100
|
+
w,h = it.size(t, legend_style)
|
101
|
+
col = index % @style.columns
|
102
|
+
|
103
|
+
# Flush
|
104
|
+
if col == 0
|
105
|
+
height += cur_height unless index == 0
|
106
|
+
cur_height = h
|
107
|
+
end
|
108
|
+
if widths[col] < w
|
109
|
+
widths[col] = w
|
110
|
+
end
|
111
|
+
if cur_height < h
|
112
|
+
cur_height = h
|
113
|
+
end
|
114
|
+
index += 1
|
115
|
+
end
|
116
|
+
|
117
|
+
height += cur_height
|
118
|
+
# Now add padding to the columns widths:
|
119
|
+
(widths.size()-1).times do |i|
|
120
|
+
widths[i] += @style.dx.to_figure(t, :x)
|
121
|
+
end
|
122
|
+
|
123
|
+
@column_widths = widths
|
124
|
+
width = widths.reduce(:+) # Do padding !
|
125
|
+
return [width, height]
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
end
|
@@ -19,10 +19,10 @@ require 'ctioga2/graphics/styles/box'
|
|
19
19
|
require 'ctioga2/graphics/styles/location'
|
20
20
|
require 'ctioga2/graphics/styles/texts'
|
21
21
|
require 'ctioga2/graphics/styles/carrays'
|
22
|
-
require 'ctioga2/graphics/styles/curve'
|
23
22
|
|
24
23
|
require 'ctioga2/graphics/styles/gradients'
|
25
24
|
require 'ctioga2/graphics/styles/colormap'
|
25
|
+
require 'ctioga2/graphics/styles/contour'
|
26
26
|
|
27
27
|
|
28
28
|
require 'ctioga2/graphics/styles/errorbar'
|
@@ -37,6 +37,8 @@ require 'ctioga2/graphics/styles/plot'
|
|
37
37
|
require 'ctioga2/graphics/styles/legend'
|
38
38
|
|
39
39
|
|
40
|
+
require 'ctioga2/graphics/styles/curve'
|
41
|
+
|
40
42
|
require 'ctioga2/graphics/styles/factory'
|
41
43
|
|
42
44
|
# Style sheets
|
@@ -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:
|
20
|
+
Version::register_svn_info('$Revision: 435 $', '$Date: 2013-08-26 22:03:19 +0200 (Mon, 26 Aug 2013) $')
|
21
21
|
|
22
22
|
module Graphics
|
23
23
|
|
@@ -72,6 +72,8 @@ module CTioga2
|
|
72
72
|
typed_attribute :minor_tick_length, 'float'
|
73
73
|
typed_attribute :minor_tick_width, 'float'
|
74
74
|
|
75
|
+
typed_attribute :ticks_side, 'ticks-side'
|
76
|
+
|
75
77
|
|
76
78
|
# Creates a new AxisStyle object at the given location with
|
77
79
|
# the given style.
|
@@ -80,8 +82,10 @@ module CTioga2
|
|
80
82
|
@decoration = decoration
|
81
83
|
|
82
84
|
@tick_label_style = FullTextStyle.new
|
85
|
+
@tick_label_style.scale = Types::Dimension.new(:dy, 0.8)
|
83
86
|
@axis_label = TextLabel.new(label)
|
84
87
|
@log = false
|
88
|
+
@ticks_side = {}
|
85
89
|
end
|
86
90
|
|
87
91
|
# Draws the axis within the current plot. Boundaries are the
|
@@ -96,7 +100,7 @@ module CTioga2
|
|
96
100
|
def draw_axis(t)
|
97
101
|
spec = get_axis_specification(t)
|
98
102
|
# Add tick label style:
|
99
|
-
spec.merge!(@tick_label_style.
|
103
|
+
spec.merge!(@tick_label_style.hash_for_tioga(t))
|
100
104
|
|
101
105
|
# Direct copy of attributes
|
102
106
|
for key in %w(stroke_color major_tick_length major_tick_width
|
@@ -106,6 +110,8 @@ minor_tick_length minor_tick_width)
|
|
106
110
|
spec[key] = val
|
107
111
|
end
|
108
112
|
end
|
113
|
+
|
114
|
+
spec.update(@ticks_side)
|
109
115
|
t.show_axis(spec)
|
110
116
|
@axis_label.loc = @location
|
111
117
|
default = vertical? ? 'ylabel' : 'xlabel'
|
@@ -213,8 +219,8 @@ minor_tick_length minor_tick_width)
|
|
213
219
|
def get_ticks_parameters(t)
|
214
220
|
i = t.axis_information({'location' => @location.tioga_location})
|
215
221
|
retval = []
|
216
|
-
retval << (@tick_label_style.
|
217
|
-
retval << (@tick_label_style.
|
222
|
+
retval << (@tick_label_style.shift_dy(t) || i['shift'])
|
223
|
+
retval << (@tick_label_style.scale_dy(t) || i['scale'])
|
218
224
|
|
219
225
|
retval[0] += 1
|
220
226
|
return retval
|
@@ -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:
|
19
|
+
Version::register_svn_info('$Revision: 433 $', '$Date: 2013-08-26 22:03:14 +0200 (Mon, 26 Aug 2013) $')
|
20
20
|
|
21
21
|
module Graphics
|
22
22
|
|
@@ -30,6 +30,12 @@ module CTioga2
|
|
30
30
|
|
31
31
|
OldAttrAccessor = method(:attr_accessor)
|
32
32
|
|
33
|
+
AllStyles = []
|
34
|
+
|
35
|
+
def self.inherited(cls)
|
36
|
+
AllStyles << cls
|
37
|
+
end
|
38
|
+
|
33
39
|
# This redefinition of attr_accessor allows to track for the
|
34
40
|
# names of the attributes, while still showing them up
|
35
41
|
# properly documented in rdoc.
|
@@ -37,10 +43,6 @@ module CTioga2
|
|
37
43
|
@attributes ||= []
|
38
44
|
@attributes << symbol
|
39
45
|
OldAttrAccessor.call(symbol)
|
40
|
-
# cl = caller()
|
41
|
-
# if not cl[0] =~ /typed_attribute/
|
42
|
-
# puts "old-style attribute: #{cl[0]}"
|
43
|
-
# end
|
44
46
|
end
|
45
47
|
|
46
48
|
# Returns the list of attributes.
|
@@ -53,6 +55,19 @@ module CTioga2
|
|
53
55
|
end
|
54
56
|
end
|
55
57
|
|
58
|
+
# Returns the type of all attributes (chaining to the parent
|
59
|
+
# when applicable)
|
60
|
+
def self.attribute_types
|
61
|
+
return ( @attribute_types || {} ).
|
62
|
+
merge(
|
63
|
+
if superclass.respond_to?(:attribute_types)
|
64
|
+
superclass.attribute_types
|
65
|
+
else
|
66
|
+
{}
|
67
|
+
end
|
68
|
+
)
|
69
|
+
end
|
70
|
+
|
56
71
|
# This function should be the main way now of declaring
|
57
72
|
# attributes, as it allows one to automatically generate an
|
58
73
|
# options hash for Command
|
@@ -70,21 +85,57 @@ module CTioga2
|
|
70
85
|
type = CmdArg.new(type) unless type.respond_to? :string_to_type
|
71
86
|
@attribute_types ||= {}
|
72
87
|
@attribute_types[sym] = type
|
88
|
+
return type
|
89
|
+
end
|
90
|
+
|
91
|
+
# Returns the type of an attribute, or _nil_ if there is no
|
92
|
+
# attribute of that name. Handles sub-styles correctly.
|
93
|
+
def self.attribute_type(symbol, fmt = "%s")
|
94
|
+
name = symbol.to_s
|
95
|
+
|
96
|
+
for k,v in attribute_types
|
97
|
+
if (fmt % k.to_s) == name
|
98
|
+
if v.respond_to? :type
|
99
|
+
return v.type
|
100
|
+
else
|
101
|
+
return v
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
if @sub_styles # Not always present too
|
107
|
+
for sub in @sub_styles
|
108
|
+
sym, cls, fmt2, fc = *sub
|
109
|
+
f = fmt % fmt2
|
110
|
+
ret = cls.attribute_type(symbol, f)
|
111
|
+
return ret if ret
|
112
|
+
end
|
113
|
+
end
|
114
|
+
return nil
|
115
|
+
end
|
116
|
+
|
117
|
+
# Adds a deprecated typed attribute
|
118
|
+
def self.deprecated_attribute(symbol, type, message = true)
|
119
|
+
type = self.typed_attribute(symbol, type)
|
120
|
+
type.option_deprecated = message
|
73
121
|
end
|
74
122
|
|
75
123
|
# Defines an accessor for an attribute which is a BasicStyle
|
76
124
|
# subclass in itself.
|
77
125
|
#
|
78
|
-
#
|
126
|
+
# _fmt_ is the thing fed to the subclass for the
|
79
127
|
# _from_hash_ function.
|
80
|
-
|
128
|
+
#
|
129
|
+
# if _force_create_ is on, then the corresponding sub-object
|
130
|
+
# is created even if no property we set within.
|
131
|
+
def self.sub_style(symbol, cls, fmt = nil, force_create = false)
|
81
132
|
@sub_styles ||= [] # A list of [symbol, cls, fmt]
|
82
133
|
|
83
134
|
if ! fmt
|
84
135
|
fmt = "#{symbol.to_s}_%s"
|
85
136
|
end
|
86
137
|
|
87
|
-
@sub_styles << [symbol, cls, fmt]
|
138
|
+
@sub_styles << [symbol, cls, fmt, force_create]
|
88
139
|
# Define the accessor
|
89
140
|
OldAttrAccessor.call(symbol)
|
90
141
|
end
|
@@ -107,7 +158,7 @@ module CTioga2
|
|
107
158
|
|
108
159
|
if @sub_styles # Not always present too
|
109
160
|
for sub in @sub_styles
|
110
|
-
sym, cls, fmt = *sub
|
161
|
+
sym, cls, fmt, fc = *sub
|
111
162
|
fmt = key % fmt
|
112
163
|
ret.merge!(cls.options_hash(fmt))
|
113
164
|
end
|
@@ -146,7 +197,7 @@ module CTioga2
|
|
146
197
|
|
147
198
|
if self.class.sub_styles
|
148
199
|
for sub in self.class.sub_styles
|
149
|
-
sym, cls, fmt = *sub
|
200
|
+
sym, cls, fmt, fc = *sub
|
150
201
|
cur_var = self.send(sym)
|
151
202
|
if ! cur_var # Create if not present
|
152
203
|
cur_var = cls.new
|
@@ -154,7 +205,10 @@ module CTioga2
|
|
154
205
|
end
|
155
206
|
fmt = name % fmt
|
156
207
|
nb = cur_var.set_from_hash(hash, fmt)
|
157
|
-
|
208
|
+
|
209
|
+
# Here, this means that missing attributes do not get
|
210
|
+
# created.
|
211
|
+
if (nb > 0 or fc) and set_after
|
158
212
|
self.send("#{sym}=", cur_var)
|
159
213
|
end
|
160
214
|
nb_set += nb
|
@@ -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:
|
20
|
+
Version::register_svn_info('$Revision: 377 $', '$Date: 2013-02-01 12:10:20 +0100 (Fri, 01 Feb 2013) $')
|
21
21
|
|
22
22
|
module Graphics
|
23
23
|
|
@@ -226,6 +226,7 @@ module CTioga2
|
|
226
226
|
return [t.create_colormap(dict), zvs.first, zvs.last]
|
227
227
|
end
|
228
228
|
|
229
|
+
|
229
230
|
protected
|
230
231
|
|
231
232
|
# Returns a Dvector holding z values corresponding to each of
|