ctioga2 0.7 → 0.8

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 (107) hide show
  1. data/Changelog +8 -0
  2. data/lib/ctioga2/commands/arguments.rb +0 -2
  3. data/lib/ctioga2/commands/commands.rb +0 -2
  4. data/lib/ctioga2/commands/context.rb +0 -2
  5. data/lib/ctioga2/commands/doc/doc.rb +0 -2
  6. data/lib/ctioga2/commands/doc/documentation-commands.rb +0 -2
  7. data/lib/ctioga2/commands/doc/help.rb +0 -2
  8. data/lib/ctioga2/commands/doc/html.rb +0 -2
  9. data/lib/ctioga2/commands/doc/introspection.rb +0 -2
  10. data/lib/ctioga2/commands/doc/man.rb +0 -2
  11. data/lib/ctioga2/commands/doc/markup.rb +0 -2
  12. data/lib/ctioga2/commands/doc/wordwrap.rb +0 -2
  13. data/lib/ctioga2/commands/general-commands.rb +0 -2
  14. data/lib/ctioga2/commands/general-types.rb +0 -2
  15. data/lib/ctioga2/commands/groups.rb +0 -2
  16. data/lib/ctioga2/commands/interpreter.rb +0 -2
  17. data/lib/ctioga2/commands/parsers/command-line.rb +0 -2
  18. data/lib/ctioga2/commands/parsers/file.rb +0 -2
  19. data/lib/ctioga2/commands/parsers/old-file.rb +0 -2
  20. data/lib/ctioga2/commands/strings.rb +0 -2
  21. data/lib/ctioga2/commands/type.rb +0 -2
  22. data/lib/ctioga2/commands/variables.rb +0 -2
  23. data/lib/ctioga2/data/backends/backend.rb +0 -3
  24. data/lib/ctioga2/data/backends/backends/direct.rb +0 -3
  25. data/lib/ctioga2/data/backends/backends/gnuplot.rb +0 -3
  26. data/lib/ctioga2/data/backends/backends/math.rb +0 -2
  27. data/lib/ctioga2/data/backends/backends/text.rb +0 -3
  28. data/lib/ctioga2/data/backends/description.rb +0 -3
  29. data/lib/ctioga2/data/backends/factory.rb +18 -2
  30. data/lib/ctioga2/data/backends/parameter.rb +0 -2
  31. data/lib/ctioga2/data/datacolumn.rb +0 -2
  32. data/lib/ctioga2/data/dataset.rb +5 -3
  33. data/lib/ctioga2/data/filters.rb +0 -3
  34. data/lib/ctioga2/data/indexed-dtable.rb +0 -3
  35. data/lib/ctioga2/data/point.rb +0 -3
  36. data/lib/ctioga2/data/stack.rb +2 -4
  37. data/lib/ctioga2/graphics/coordinates.rb +0 -2
  38. data/lib/ctioga2/graphics/elements.rb +1 -2
  39. data/lib/ctioga2/graphics/elements/containers.rb +32 -2
  40. data/lib/ctioga2/graphics/elements/contour.rb +0 -2
  41. data/lib/ctioga2/graphics/elements/curve2d.rb +0 -2
  42. data/lib/ctioga2/graphics/elements/element.rb +4 -2
  43. data/lib/ctioga2/graphics/elements/gradient-region.rb +0 -2
  44. data/lib/ctioga2/graphics/elements/histogram.rb +298 -0
  45. data/lib/ctioga2/graphics/elements/parametric2d.rb +7 -3
  46. data/lib/ctioga2/graphics/elements/primitive.rb +0 -2
  47. data/lib/ctioga2/graphics/elements/redirecting-container.rb +21 -2
  48. data/lib/ctioga2/graphics/elements/region.rb +0 -2
  49. data/lib/ctioga2/graphics/elements/subplot.rb +0 -2
  50. data/lib/ctioga2/graphics/elements/tangent.rb +0 -2
  51. data/lib/ctioga2/graphics/elements/xyz-contour.rb +0 -2
  52. data/lib/ctioga2/graphics/elements/xyz-map.rb +0 -2
  53. data/lib/ctioga2/graphics/generator.rb +47 -42
  54. data/lib/ctioga2/graphics/legends.rb +0 -2
  55. data/lib/ctioga2/graphics/legends/area.rb +0 -2
  56. data/lib/ctioga2/graphics/legends/items.rb +0 -2
  57. data/lib/ctioga2/graphics/legends/multicols.rb +0 -2
  58. data/lib/ctioga2/graphics/legends/provider.rb +0 -2
  59. data/lib/ctioga2/graphics/legends/storage.rb +0 -2
  60. data/lib/ctioga2/graphics/root.rb +0 -2
  61. data/lib/ctioga2/graphics/styles/arrows.rb +0 -2
  62. data/lib/ctioga2/graphics/styles/axes.rb +0 -2
  63. data/lib/ctioga2/graphics/styles/background.rb +0 -2
  64. data/lib/ctioga2/graphics/styles/base.rb +4 -2
  65. data/lib/ctioga2/graphics/styles/box.rb +0 -2
  66. data/lib/ctioga2/graphics/styles/carrays.rb +0 -2
  67. data/lib/ctioga2/graphics/styles/colormap.rb +0 -2
  68. data/lib/ctioga2/graphics/styles/contour.rb +0 -2
  69. data/lib/ctioga2/graphics/styles/curve.rb +0 -2
  70. data/lib/ctioga2/graphics/styles/drawable.rb +0 -2
  71. data/lib/ctioga2/graphics/styles/errorbar.rb +0 -2
  72. data/lib/ctioga2/graphics/styles/factory.rb +0 -2
  73. data/lib/ctioga2/graphics/styles/gradients.rb +0 -2
  74. data/lib/ctioga2/graphics/styles/legend.rb +0 -2
  75. data/lib/ctioga2/graphics/styles/location.rb +0 -2
  76. data/lib/ctioga2/graphics/styles/map-axes.rb +0 -2
  77. data/lib/ctioga2/graphics/styles/plot-types.rb +51 -3
  78. data/lib/ctioga2/graphics/styles/plot.rb +0 -2
  79. data/lib/ctioga2/graphics/styles/sets.rb +0 -2
  80. data/lib/ctioga2/graphics/styles/sheet.rb +0 -2
  81. data/lib/ctioga2/graphics/styles/texts.rb +0 -2
  82. data/lib/ctioga2/graphics/styles/ticks.rb +0 -2
  83. data/lib/ctioga2/graphics/subplot-commands.rb +0 -2
  84. data/lib/ctioga2/graphics/types.rb +11 -4
  85. data/lib/ctioga2/graphics/types/bijection.rb +0 -2
  86. data/lib/ctioga2/graphics/types/boundaries.rb +0 -2
  87. data/lib/ctioga2/graphics/types/boxes.rb +0 -2
  88. data/lib/ctioga2/graphics/types/dimensions.rb +0 -2
  89. data/lib/ctioga2/graphics/types/fill.rb +27 -15
  90. data/lib/ctioga2/graphics/types/grid.rb +0 -2
  91. data/lib/ctioga2/graphics/types/location.rb +0 -2
  92. data/lib/ctioga2/graphics/types/point.rb +0 -2
  93. data/lib/ctioga2/log.rb +0 -2
  94. data/lib/ctioga2/metabuilder/type.rb +0 -2
  95. data/lib/ctioga2/metabuilder/types/coordinates.rb +0 -2
  96. data/lib/ctioga2/metabuilder/types/data.rb +0 -2
  97. data/lib/ctioga2/metabuilder/types/dates.rb +0 -1
  98. data/lib/ctioga2/metabuilder/types/generic.rb +0 -3
  99. data/lib/ctioga2/metabuilder/types/lists.rb +25 -3
  100. data/lib/ctioga2/metabuilder/types/numbers.rb +0 -2
  101. data/lib/ctioga2/metabuilder/types/strings.rb +0 -3
  102. data/lib/ctioga2/metabuilder/types/styles.rb +0 -2
  103. data/lib/ctioga2/plotmaker.rb +2 -4
  104. data/lib/ctioga2/postprocess.rb +0 -2
  105. data/lib/ctioga2/utils.rb +6 -64
  106. data/lib/ctioga2/version.rb +8 -0
  107. metadata +6 -4
@@ -20,6 +20,7 @@ require 'ctioga2/graphics/elements/subplot'
20
20
  require 'ctioga2/graphics/elements/region'
21
21
  require 'ctioga2/graphics/elements/gradient-region'
22
22
  require 'ctioga2/graphics/elements/curve2d'
23
+ require 'ctioga2/graphics/elements/histogram'
23
24
  require 'ctioga2/graphics/elements/parametric2d'
24
25
  require 'ctioga2/graphics/elements/xyz-map'
25
26
  require 'ctioga2/graphics/elements/xyz-contour'
@@ -30,8 +31,6 @@ require 'ctioga2/graphics/elements/contour'
30
31
 
31
32
  module CTioga2
32
33
 
33
- Version::register_svn_info('$Revision: 405 $', '$Date: 2013-08-22 16:25:13 +0200 (Thu, 22 Aug 2013) $')
34
-
35
34
  module Graphics
36
35
 
37
36
  # Now, various commands pertaining to various drawables
@@ -17,8 +17,6 @@ require 'ctioga2/log'
17
17
 
18
18
  module CTioga2
19
19
 
20
- Version::register_svn_info('$Revision: 529 $', '$Date: 2013-09-25 18:23:27 +0200 (Wed, 25 Sep 2013) $')
21
-
22
20
  module Graphics
23
21
 
24
22
  module Elements
@@ -51,6 +49,16 @@ module CTioga2
51
49
  # Defaults to the #legend_storage, but it can be changed
52
50
  attr_accessor :legend_item_target
53
51
 
52
+ # A general-purpose cache that objects may use.
53
+ #
54
+ # It is a hash, and its contents are reset at the beginning of
55
+ # each invocation of #do.
56
+ attr_accessor :gp_cache
57
+
58
+
59
+ # @todo Add an iterator over all leaf elements (including
60
+ # children or not ?)
61
+
54
62
  # Creates an empty new Container with the given _parent_.
55
63
  def initialize(parent = nil, root = nil)
56
64
  super()
@@ -72,6 +80,12 @@ module CTioga2
72
80
  @legend_area = nil
73
81
  end
74
82
 
83
+ def do(t)
84
+ # reset the cache
85
+ @gp_cache = {}
86
+ super
87
+ end
88
+
75
89
  # Returns the number of child elements
76
90
  def size
77
91
  return @elements.size
@@ -123,6 +137,22 @@ module CTioga2
123
137
  end
124
138
  end
125
139
 
140
+ def each_item(leaf_only = true, recursive = false, tl = true, &blk)
141
+ if (!recursive && !tl)
142
+ return # We're at the bottom level
143
+ end
144
+ for el in @elements
145
+ if el.respond_to? :each_item
146
+ if ! leaf_only
147
+ blk.call(el)
148
+ end
149
+ el.each_item(leaf_only, recursive, false, &blk)
150
+ else
151
+ blk.call(el)
152
+ end
153
+ end
154
+ end
155
+
126
156
  # \todo provide coordinate conversion facilities...
127
157
 
128
158
  protected
@@ -17,8 +17,6 @@ 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: 299 $', '$Date: 2011-03-15 11:22:20 +0100 (Tue, 15 Mar 2011) $')
21
-
22
20
  module Graphics
23
21
 
24
22
  module Elements
@@ -19,8 +19,6 @@ require 'Dobjects/Function'
19
19
 
20
20
  module CTioga2
21
21
 
22
- Version::register_svn_info('$Revision: 535 $', '$Date: 2013-10-02 20:31:21 +0200 (Wed, 02 Oct 2013) $')
23
-
24
22
  module Graphics
25
23
 
26
24
  module Elements
@@ -18,8 +18,6 @@ require 'ctioga2/log'
18
18
  # This module contains all the classes used by ctioga
19
19
  module CTioga2
20
20
 
21
- Version::register_svn_info('$Revision: 535 $', '$Date: 2013-10-02 20:31:21 +0200 (Wed, 02 Oct 2013) $')
22
-
23
21
  # This module contains all graphical elements of CTioga2
24
22
  module Graphics
25
23
 
@@ -38,6 +36,7 @@ module CTioga2
38
36
  # LocationStyle object
39
37
  attr_writer :location
40
38
 
39
+ # Whether the object is clipped by default or not.
41
40
  attr_accessor :clipped
42
41
 
43
42
 
@@ -48,6 +47,8 @@ module CTioga2
48
47
  @clipped = true
49
48
 
50
49
  @depth = 50 # Hey, like xfig
50
+
51
+ @gp_cache = {}
51
52
  end
52
53
 
53
54
  def depth
@@ -66,6 +67,7 @@ module CTioga2
66
67
  # redefine _do_ too if you need another debugging output.
67
68
  def do(f)
68
69
  debug { "plotting #{self.inspect}" }
70
+ @gp_cache = {}
69
71
  real_do(f)
70
72
  end
71
73
 
@@ -17,8 +17,6 @@ require 'ctioga2/log'
17
17
 
18
18
  module CTioga2
19
19
 
20
- Version::register_svn_info('$Revision: 288 $', '$Date: 2011-02-22 21:12:58 +0100 (Tue, 22 Feb 2011) $')
21
-
22
20
  module Graphics
23
21
 
24
22
  module Elements
@@ -0,0 +1,298 @@
1
+ # histogram.rb: a histogram
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
+ require 'ctioga2/graphics/elements/curve2d'
17
+
18
+ require 'set'
19
+
20
+ require 'Dobjects/Function'
21
+
22
+
23
+ module CTioga2
24
+
25
+ module Graphics
26
+
27
+ module Elements
28
+
29
+ # A histogram
30
+ class Histogram < Curve2D
31
+
32
+
33
+ include Log
34
+ include Dobjects
35
+
36
+ # The histogram style at the moment of the creation of the
37
+ # object.
38
+ attr_accessor :histogram_style
39
+
40
+
41
+ def initialize(dataset, style, hstyle)
42
+ super(dataset, style)
43
+ @histogram_style = hstyle
44
+ end
45
+
46
+ def get_boundaries
47
+ ry = modified_yvalues
48
+ bnds = Types::Boundaries.bounds(@function.x, ry)
49
+ if ! @within_gb
50
+ base = get_base
51
+
52
+ nb = bnds.dup
53
+ nb.bottom = base
54
+ nb.top = base
55
+
56
+ # include the width ?
57
+
58
+
59
+ bnds.extend(nb)
60
+ end
61
+ return bnds
62
+ end
63
+
64
+
65
+ # First, a very naive way.
66
+
67
+ def make_path(t)
68
+ base = get_base
69
+
70
+ w, ho, yo = *get_properties(t)
71
+
72
+ org = get_cached_organization
73
+ h_o = org[:has_offsets][self]
74
+
75
+ for x,y in @function
76
+ xl = x + ho
77
+ xr = xl + w
78
+ b = yo[x]
79
+ t.move_to_point(xl, base+b)
80
+ t.append_point_to_path(xl, y+b)
81
+ t.append_point_to_path(xr, y+b)
82
+ t.append_point_to_path(xr, base+b)
83
+ if h_o # close !
84
+ t.move_to_point(xl, base+b)
85
+ end
86
+ end
87
+ end
88
+
89
+ # The algorithms for closing the path just look ugly for
90
+ # histograms that are offset from something. The reasoning
91
+ # does not apply here.
92
+ def make_closed_path(t, close_type = nil)
93
+ org = get_cached_organization
94
+ if org[:has_offsets][self]
95
+ make_path(t)
96
+ else
97
+ super
98
+ end
99
+ end
100
+
101
+ protected
102
+
103
+ def modified_yvalues
104
+ org = get_cached_organization
105
+ if org[:has_offsets][self]
106
+ vo = org[:y_offsets][self]
107
+ vc = @function.y.dup
108
+ vc.size.times do |i|
109
+ vc[i] += vo[@function.x[i]]
110
+ end
111
+ return vc
112
+ else
113
+ return @function.y
114
+ end
115
+ end
116
+
117
+ # The cache is setup in two bits:
118
+ # * one fully metric-independent (i.e. that does not need the
119
+ # FigureMaker object)
120
+ # * the metric cache, holding information about widths and the
121
+ # likes, that builds upon the first
122
+
123
+
124
+ # This first cache is the organization of the whole
125
+ # histograms. It is independent of the metrics.
126
+ def get_cached_organization
127
+ if ! parent.gp_cache.key?(:histograms)
128
+ cache = {}
129
+ parent.gp_cache[:histograms] = cache
130
+
131
+
132
+ hists = []
133
+
134
+ x_values = Set.new
135
+
136
+ parent.each_item do |el|
137
+ if el.is_a?(Histogram)
138
+ hists << el
139
+ x_values.merge(el.function.x.to_a)
140
+ end
141
+ end
142
+
143
+ cache[:list] = hists
144
+ cache[:xvalues] = x_values
145
+
146
+ # First, we must split the histograms in columns, based on
147
+ # the :cumulative attribute. If positive or null, then the
148
+ # index is that. If false, then, the next available index.
149
+ # if negative, then the next available index, unless it exists
150
+ # the index conversion here.
151
+ index_cnv = {}
152
+
153
+ columns = []
154
+ cache[:indices] = {}
155
+ for h in hists
156
+ cm = h.histogram_style.cumulative
157
+ if ! cm
158
+ cm = columns.size
159
+ elsif cm < 0
160
+ if ! index_cnv.key?(cm)
161
+ index_cnv[cm] = columns.size
162
+ end
163
+ cm = index_cnv[cm]
164
+ end
165
+ columns[cm] ||= []
166
+ columns[cm] << h
167
+ cache[:indices][h] = cm
168
+ end
169
+ cache[:columns] = columns
170
+
171
+ offsets = {}
172
+ isoff = {}
173
+ for ar in columns
174
+ base = {}
175
+ for x in x_values
176
+ base[x] = 0.0
177
+ end
178
+ next unless ar
179
+ index = 0
180
+ for h in ar
181
+ offsets[h] = base.dup
182
+ isoff[h] = (index > 0)
183
+ for x,y in h.function
184
+ base[x] += y
185
+ end
186
+ index += 1
187
+ end
188
+ end
189
+ cache[:y_offsets] = offsets
190
+ cache[:has_offsets] = isoff
191
+
192
+ end
193
+ return parent.gp_cache[:histograms]
194
+ end
195
+
196
+ # Returns the cached metrics of all the histograms,
197
+ # recomputing it in the process.
198
+ def get_cached_metrics(t)
199
+ if ! parent.gp_cache.key?(:histogram_metrics)
200
+ cache = {}
201
+ parent.gp_cache[:histogram_metrics] = cache
202
+
203
+ org = get_cached_organization
204
+ cols = org[:columns]
205
+ x_values = org[:xvalues]
206
+
207
+ # Overall size of intra seps, in figure coordinates. Only
208
+ # intra sep of the first element in a column counts !
209
+ intra_sep = 0
210
+ cols[0..-2].each do |col|
211
+ if col && col.first.histogram_style.intra_sep
212
+ intra_sep += col.first.histogram_style.intra_sep.to_figure(t, :x)
213
+ end
214
+ end
215
+
216
+ inter_sep = if @histogram_style.gap
217
+ @histogram_style.gap.to_figure(t, :x)
218
+ elsif @histogram_style.intra_sep
219
+ @histogram_style.intra_sep.to_figure(t, :x)
220
+ else
221
+ 0
222
+ end
223
+
224
+ # OK, now we have all the values. For now, we assume more
225
+ # or less that they are evenly spaced.
226
+ #
227
+ # Later, we'll have to use a conversion function for X
228
+ # values (which means in particular that they won't be
229
+ # positioned at the exact X value, but that's already the
230
+ # case anyway).
231
+ width = (x_values.max - x_values.min)/(x_values.size - 1)
232
+
233
+ # Available width
234
+ aw = width - intra_sep - inter_sep
235
+ if aw < 0
236
+ error { "Too much padding around the histograms leading to negative size. Try using smaller intra-sep or inter-sep. Ignoring them for now" }
237
+ aw = width
238
+ end
239
+
240
+ iw = aw/cols.size
241
+ offset = -0.5 * (width - inter_sep)
242
+
243
+ # @todo Add padding between the hists and around the
244
+ # groups of histograms.
245
+
246
+ for col in cols
247
+ c = {}
248
+ c[:width] = iw
249
+ c[:x_offset] = offset
250
+ offset += iw
251
+ next unless col
252
+ if col.first.histogram_style.intra_sep
253
+ offset += h.histogram_style.intra_sep.to_figure(t, :x)
254
+ end
255
+ for h in col
256
+ cache[h] = c
257
+ end
258
+ end
259
+ end
260
+ return parent.gp_cache[:histogram_metrics]
261
+ end
262
+
263
+ # Computes the horizontal offset and the width of the
264
+ # histogram. Relies on a cache installed onto the parent.
265
+ def get_properties(t)
266
+ metrics = get_cached_metrics(t)
267
+ s = metrics[self]
268
+ org = get_cached_organization
269
+ return [s[:width], s[:x_offset], org[:y_offsets][self] ]
270
+ end
271
+
272
+ def get_base
273
+ ct = @curve_style.fill.close_type
274
+ if ct
275
+ if ! ct.horizontal?
276
+ warning { "Cannot use fill types other than horizontal for histograms: #{ct.type}. Using default value" }
277
+ return 0
278
+ end
279
+
280
+ @within_gb = true
281
+ bnds = parent.get_el_boundaries(self)
282
+ @within_gb = false
283
+
284
+ begin
285
+ return ct.effective_value(bnds)
286
+ rescue
287
+ return @function.y.min # default value. Make sense ?
288
+ end
289
+ end
290
+
291
+ # @todo Horizontal histograms ??
292
+ return 0
293
+ end
294
+
295
+ end
296
+ end
297
+ end
298
+ end
@@ -19,8 +19,6 @@ require 'Dobjects/Function'
19
19
 
20
20
  module CTioga2
21
21
 
22
- Version::register_svn_info('$Revision: 535 $', '$Date: 2013-10-02 20:31:21 +0200 (Wed, 02 Oct 2013) $')
23
-
24
22
  module Graphics
25
23
 
26
24
  module Elements
@@ -122,7 +120,6 @@ module CTioga2
122
120
 
123
121
  # Draws the markers, if applicable.
124
122
  def draw_markers(t)
125
- @parametric_style.prepare
126
123
  if @curve_style.has_marker?
127
124
  # We use a default color map for the markers
128
125
  @curve_style.marker_color_map ||=
@@ -148,6 +145,13 @@ module CTioga2
148
145
 
149
146
  # draw_fill(t)
150
147
  # draw_errorbars(t)
148
+
149
+ @parametric_style.prepare
150
+ if @dataset.z_columns < @parametric_style.z_columns_needed
151
+ error { "Need #{@parametric_style.z_columns_needed} Z columns, but have only #{@dataset.z_columns} for dataset #{@dataset.name}" }
152
+ return
153
+ end
154
+
151
155
  draw_path(t)
152
156
  draw_markers(t)
153
157