ctioga2 0.5 → 0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -19,7 +19,7 @@ require 'ctioga2/graphics/coordinates'
19
19
  # This module contains all the classes used by ctioga
20
20
  module CTioga2
21
21
 
22
- Version::register_svn_info('$Revision: 432 $', '$Date: 2013-08-23 19:06:36 +0200 (Fri, 23 Aug 2013) $')
22
+ Version::register_svn_info('$Revision: 488 $', '$Date: 2013-09-03 00:31:36 +0200 (Tue, 03 Sep 2013) $')
23
23
 
24
24
  module Graphics
25
25
 
@@ -368,7 +368,62 @@ EOH
368
368
  <<"EOH", AxisGroup)
369
369
  This command can be used to set various aspects of the style of the
370
370
  given axis, through its various options, which are documented in more details
371
- in the {command: define-axis-style} command.
371
+ in the {command: define-axis-style} command -- excepted for the @ticks@ bit
372
+ which are documented in the {command: ticks} command.
373
+ EOH
374
+
375
+ ClearAxesCommand =
376
+ Cmd.new("clear-axes",nil,"--clear-axes"
377
+ ) do |plotmaker, opts|
378
+ [:left, :right, :top, :bottom].each do |loc|
379
+ style = AxisStyle.current_axis_style(plotmaker, loc)
380
+ style.decoration = Tioga::FigureConstants::AXIS_HIDDEN
381
+ style.axis_label.text = ""
382
+ end
383
+ end
384
+ ClearAxesCommand.
385
+ describe("Clear all axes",
386
+ <<"EOH", AxisGroup)
387
+ Removes all the axes and their associated labels
388
+ EOH
389
+
390
+
391
+ TicksCommand =
392
+ Cmd.new("ticks",nil,"--ticks",
393
+ [
394
+ CmdArg.new('axis'),
395
+ ], Styles::AxisTicks.options_hash) do |plotmaker, which, opts|
396
+ style = AxisStyle.current_axis_style(plotmaker, which)
397
+ style.ticks.set_from_hash(opts)
398
+ end
399
+ TicksCommand.
400
+ describe("Sets the ticks of the given axis",
401
+ <<"EOH", AxisGroup)
402
+
403
+ This command can be used to control the location of major and minor
404
+ ticks and the text of their labels for the given axis. Options
405
+ available:
406
+
407
+ * @format@ the format of the tick labels, using a @sprintf@-like
408
+ syntax (see below)
409
+ * @format-last@ the format of the last of the tick labels (useful to
410
+ include an overall "power-of-ten" factor
411
+ * @major@ a space or comma-separated list of the positions of the
412
+ major (labeled) ticks
413
+ * @minor@ same for the minor ticks
414
+ * @label@ a comma-separated list of the tick labels (must be the same
415
+ number of elements as that of the @major@ list). If you must
416
+ include a comma inside, then use @||@ as a separator.
417
+
418
+ Format is a normal @sprintf@ format, with the following additional
419
+ special codes:
420
+
421
+ * @%p@ the "common power of 10": if you divide the tick values by 10
422
+ to the power @%p@, the smallest absolute value will be between 1
423
+ and 10 (excluding 0 of course)
424
+ * @%b...@ is the tick value divided by this common power of 10. You
425
+ *must* follow this spec by a usual @sprintf@ format: @%b.3g@ would
426
+ get you a number with 3 significant digits
372
427
  EOH
373
428
 
374
429
  BackgroundLinesCommand =
@@ -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: 161 $', '$Date: 2010-08-03 12:07:49 +0200 (Tue, 03 Aug 2010) $')
20
+ Version::register_svn_info('$Revision: 467 $', '$Date: 2013-08-31 14:10:52 +0200 (Sat, 31 Aug 2013) $')
21
21
 
22
22
  module Graphics
23
23
 
@@ -39,6 +39,8 @@ module CTioga2
39
39
  [DarkMagenta, DarkGreen, OrangeRed, DarkRed, DarkBlue ],
40
40
  "gradient2" =>
41
41
  [LightPlum, PaleGreen, Gold, RedBrown, SkyBlue ],
42
+ "gnuplot" =>
43
+ [Red, [0,1.0,0], Blue, Magenta, Cyan, Yellow, Black, Coral, Gray],
42
44
 
43
45
  }
44
46
 
@@ -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: 433 $', '$Date: 2013-08-26 22:03:14 +0200 (Mon, 26 Aug 2013) $')
20
+ Version::register_svn_info('$Revision: 478 $', '$Date: 2013-09-01 11:24:02 +0200 (Sun, 01 Sep 2013) $')
21
21
 
22
22
  module Graphics
23
23
 
@@ -259,11 +259,14 @@ module CTioga2
259
259
  return (@vertical_scale || 1.0) * (@scale || 1.0)
260
260
  end
261
261
  end
262
-
262
+
263
+
263
264
  # A LaTeX font. It should be applied to text using the function
264
265
  # #fontify.
265
266
  #
266
267
  # \todo add real font attributes (family, and so on...)
268
+ #
269
+ # @todo Deprecate in favor of the latter class
267
270
  class LaTeXFont
268
271
  # The font command (bf, sf...). Naive but effective !
269
272
  attr_accessor :font_command
@@ -289,6 +292,45 @@ module CTioga2
289
292
  end
290
293
 
291
294
  end
295
+
296
+ # Full font information
297
+ #
298
+ # @todo There is a whole bunch of work to be done on the Tioga
299
+ # side to make sure that things work.
300
+ class FullLatexFont < BasicStyle
301
+
302
+ # The size of the text
303
+ typed_attribute :size, 'float'
304
+
305
+ # I remove those since they don't work for the time being
306
+
307
+ # # Font family
308
+ # typed_attribute :family, 'text'
309
+
310
+ # # Font series
311
+ # typed_attribute :series, 'text'
312
+
313
+ # # Font shape
314
+ # typed_attribute :shape, 'text'
315
+
316
+
317
+ # Set global font information based on this style
318
+ #
319
+ # This only works from within a figure !
320
+ def set_global_font(t)
321
+ # for a in %w(family series shape)
322
+ # v = self.send(a)
323
+ # t.send("tex_font#{a}=", v) if v
324
+ # end
325
+
326
+
327
+ if @size
328
+ fact = @size/t.default_font_size
329
+ t.rescale_text(fact)
330
+ end
331
+ end
332
+
333
+ end
292
334
 
293
335
 
294
336
  end
@@ -0,0 +1,109 @@
1
+ # ticks.rb: all aspects of axis ticks
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,
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
+ require 'ctioga2/graphics/coordinates'
18
+
19
+ # This module contains all the classes used by ctioga
20
+ module CTioga2
21
+
22
+ Version::register_svn_info('$Revision$', '$Date$')
23
+
24
+ module Graphics
25
+
26
+ module Styles
27
+
28
+
29
+ # This class describes where to place ticks on the target axis
30
+ # and how to label them.
31
+ class AxisTicks < BasicStyle
32
+
33
+ include Log
34
+
35
+ # The format of the tick labels.
36
+ #
37
+ # It is either a standard sprintf format or composed of one or
38
+ # more of the following:
39
+ #
40
+ # * %b followed by any usual format specifier: the tick value
41
+ # divided by the common power of 10
42
+ # * %p the power of 10
43
+ typed_attribute :format, "text"
44
+
45
+ # The format of the last of the tick labels
46
+ typed_attribute :format_last, "text"
47
+
48
+ # The list of the position of major ticks
49
+ #
50
+ # @todo make it possible to provide a function to generate that ?
51
+ typed_attribute :major, 'float-list'
52
+
53
+ # The list of the position of minor ticks
54
+ typed_attribute :minor, 'float-list'
55
+
56
+ # The list of labels
57
+ typed_attribute :labels, 'text-list'
58
+
59
+ def self.tweak_format_string(str)
60
+ return str.gsub("%b", "%2$").gsub("%p", "%3$d")
61
+ end
62
+
63
+ # Returns the specifications that should be added to the
64
+ # information
65
+ def ticks_specs(t, info, transform)
66
+ ret = {}
67
+ for k in %w{major_ticks minor_ticks labels}
68
+ ret[k] = info[k]
69
+ end
70
+ if info['major']
71
+ ret['minor_ticks'] = info['minor']
72
+ ret['major_ticks'] = info['major']
73
+ end
74
+ fmt = @format
75
+
76
+ if @major
77
+ ret['minor_ticks'] = Dobjects::Dvector.new
78
+ ret['major_ticks'] = Dobjects::Dvector.new(@major)
79
+
80
+ fmt ||= "$%g$"
81
+ end
82
+
83
+ if @minor
84
+ ret['minor_ticks'] = Dobjects::Dvector.new(@minor)
85
+ end
86
+
87
+ fmt_last = @format_last || fmt
88
+
89
+ if @labels
90
+ ret['labels'] = @labels
91
+ elsif fmt
92
+ ret['labels'] = []
93
+ fmt = AxisTicks.tweak_format_string(fmt)
94
+ fmt_last = AxisTicks.tweak_format_string(fmt_last)
95
+ i = ret['major_ticks'].size
96
+ common = Utils::common_pow10(ret['major_ticks'])
97
+ fact = 10**(-common)
98
+ for v in ret['major_ticks']
99
+ i -= 1
100
+ ret['labels'] << (i > 0 ? fmt : fmt_last) % [v, v*fact, common]
101
+ end
102
+ end
103
+ return ret
104
+ end
105
+ end
106
+
107
+ end
108
+ end
109
+ end
@@ -17,6 +17,7 @@ require 'ctioga2/graphics/types/boundaries'
17
17
  require 'ctioga2/graphics/types/boxes'
18
18
  require 'ctioga2/graphics/types/bijection'
19
19
  require 'ctioga2/graphics/types/location'
20
+ require 'ctioga2/graphics/types/fill'
20
21
 
21
22
 
22
23
  require 'ctioga2/graphics/types/grid'
@@ -25,7 +26,7 @@ require 'ctioga2/graphics/types/grid'
25
26
  # This module contains all the classes used by ctioga
26
27
  module CTioga2
27
28
 
28
- Version::register_svn_info('$Revision: 376 $', '$Date: 2013-01-23 22:52:47 +0100 (Wed, 23 Jan 2013) $')
29
+ Version::register_svn_info('$Revision: 466 $', '$Date: 2013-08-31 13:10:38 +0200 (Sat, 31 Aug 2013) $')
29
30
 
30
31
  module Graphics
31
32
 
@@ -65,22 +66,6 @@ EOD
65
66
  A {type: color}, or false to say that nothing should be drawn.
66
67
  EOD
67
68
 
68
- CurveFillUntilType = CmdType.new('fill-until', {
69
- :type => :float,
70
- :shortcuts => {
71
- /x?axis/i => 0.0,
72
- /b(?:ot(?:tom)?)?/i => :bottom,
73
- /t(?:op)?/i => :top,
74
- /no(?:ne)?/i => false
75
- }
76
- }, <<EOD)
77
- The Y values until which a filled curve will be filled. Generally a number,
78
- but it can also be:
79
- * @axis@ (or @xaxis@), which means 0
80
- * @bottom@, to fill until the bottom of the graph
81
- * @top@, to fill until the top
82
- * @none@, meaning no fill
83
- EOD
84
69
 
85
70
  RegionSideType =
86
71
  CmdType.new('region-side', {
@@ -16,7 +16,7 @@ require 'ctioga2/log'
16
16
 
17
17
  module CTioga2
18
18
 
19
- Version::register_svn_info('$Revision: 433 $', '$Date: 2013-08-26 22:03:14 +0200 (Mon, 26 Aug 2013) $')
19
+ Version::register_svn_info('$Revision: 469 $', '$Date: 2013-08-31 14:10:56 +0200 (Sat, 31 Aug 2013) $')
20
20
 
21
21
  module Graphics
22
22
 
@@ -133,7 +133,7 @@ module CTioga2
133
133
  def self.from_text(text, orientation, default = :figure)
134
134
  # Absolute or :dy dimension
135
135
  if text =~ DimensionRegexp
136
- value = Float($1)
136
+ value = Utils::txt_to_float($1)
137
137
  unit = $2
138
138
  if ! unit
139
139
  unit = default
@@ -0,0 +1,126 @@
1
+ # fill.rb: fill-related types
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
+ module CTioga2
18
+
19
+ Version::register_svn_info('$Revision$', '$Date$')
20
+
21
+ module Graphics
22
+
23
+ module Types
24
+
25
+ # This class provides a way to close a path in order to fill a
26
+ # curve.
27
+ class FillUntil
28
+
29
+ # The type of closing: :top, :bottom, :left, :right, :x, :y,
30
+ # :close, :xy or :none
31
+ attr_accessor :type
32
+
33
+ # An accessory value (when necessary)
34
+ attr_accessor :value
35
+
36
+ # Builds from text
37
+ def self.from_text(str)
38
+ ret = FillUntil.new
39
+ case str
40
+ when /^\s*(left|right|top|bottom)\s*$/
41
+ ret.type = $1.downcase.to_sym
42
+ when /^\s*axis|xaxis\s*$/
43
+ ret.type = :y
44
+ ret.value = 0
45
+ when /^\s*yaxis\s*$/
46
+ ret.type = :x
47
+ ret.value = 0
48
+ when /^\s*(x|y)\s*[:=]\s*(.*)$/
49
+ ret.type = $1.downcase.to_sym
50
+ ret.value = $2.to_f
51
+ when /^\s*close\s*$/
52
+ ret.type = :close
53
+ when /^\s*xy\s*[:=]\s*(.*)$/
54
+ ret.type = :xy
55
+ ret.value = Point.from_text($1)
56
+ else
57
+ ret.type = :y
58
+ ret.value = str.to_f
59
+ end
60
+
61
+ return ret
62
+ end
63
+
64
+ # If there is actually a closing
65
+ def fill?
66
+ return @type != :none
67
+ end
68
+
69
+ # Closes the current path according to the current style, based on:
70
+ # * _bounds_, the boundaries of the plot
71
+ # * _first_, the first point ([x, y])
72
+ # * _last_, the last point
73
+ def close_path(t, bounds, first, last)
74
+ tp = @type
75
+ target = @value
76
+ case tp
77
+ when :none
78
+ raise "Close the path !"
79
+ when :bottom, :top
80
+ target = bounds.send(tp)
81
+ tp = :y
82
+ when :left, :right
83
+ target = bounds.send(tp)
84
+ tp = :x
85
+ end
86
+
87
+ case tp
88
+ when :x
89
+ t.append_point_to_path(target, last[1])
90
+ t.append_point_to_path(target, first[1])
91
+ when :y
92
+ t.append_point_to_path(last[0], target)
93
+ t.append_point_to_path(first[0], target)
94
+ when :xy
95
+ t.append_point_to_path(* @value.to_figure_xy(t))
96
+ when :close
97
+ else
98
+ raise "Should not be here"
99
+ end
100
+ t.close_path
101
+ end
102
+
103
+ end
104
+
105
+ # Something meant to be fed to PlotStyle#get_axis_style
106
+ FillType =
107
+ CmdType.new('fill-until', { :type => :function_based,
108
+ :class => Graphics::Types::FillUntil
109
+ }, <<EOD)
110
+ How to close the path of a curve to fill it. Can be:
111
+ * @bottom@, @top@, @left@, @right@ to fill until the named side of the
112
+ plot
113
+ * @axis@ or @xaxis@ to fill until the X axis (ie y = 0)
114
+ * @yaxis@ to fill until the Y axis (ie x = 0)
115
+ * @x:value@ or @x=value@ to fill until the given X value
116
+ * @y:value@ or @y=value@ to fill until the given Y value
117
+ * @close@ for just closing the path (doesn't look good in general)
118
+ * @none@ for no fill
119
+ EOD
120
+
121
+
122
+
123
+ end
124
+ end
125
+ end
126
+