~ubuntu-branches/ubuntu/oneiric/ctioga2/oneiric

« back to all changes in this revision

Viewing changes to lib/ctioga2/graphics/types.rb

  • Committer: Bazaar Package Importer
  • Author(s): Vincent Fourmond
  • Date: 2011-01-24 21:36:06 UTC
  • Revision ID: james.westby@ubuntu.com-20110124213606-9ettx0ugl83z0bzp
Tags: upstream-0.1
ImportĀ upstreamĀ versionĀ 0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# types.rb: various useful types to interact with Tioga
 
2
# copyright (c) 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/graphics/types/dimensions'
 
15
require 'ctioga2/graphics/types/point'
 
16
require 'ctioga2/graphics/types/boundaries'
 
17
require 'ctioga2/graphics/types/boxes'
 
18
require 'ctioga2/graphics/types/bijection'
 
19
require 'ctioga2/graphics/types/location'
 
20
 
 
21
 
 
22
require 'ctioga2/graphics/types/grid'
 
23
 
 
24
# In addition to the former, here are some useful constants
 
25
# This module contains all the classes used by ctioga
 
26
module CTioga2
 
27
 
 
28
  Version::register_svn_info('$Revision: 249 $', '$Date: 2011-01-29 14:05:04 +0100 (Sat, 29 Jan 2011) $')
 
29
 
 
30
  module Graphics
 
31
 
 
32
    # A small convenience module for line styles
 
33
    module LineStyles
 
34
      include Tioga::FigureConstants
 
35
 
 
36
      Line_Type_Dash_Dot_Dot = [[5,2,1,2,1,2],0]
 
37
      Line_Type_Small_Dots = [[0.5,1],0]
 
38
 
 
39
      # Shortcut for line styles:
 
40
      Solid  = Line_Type_Solid
 
41
      Dots   = Line_Type_Dots
 
42
      Dashes = Line_Type_Dashes
 
43
      Small_Dots = Line_Type_Small_Dots
 
44
      Dot_Long_Dash = Line_Type_Dot_Long_Dash
 
45
      Dash_Dot_Dot = Line_Type_Dash_Dot_Dot
 
46
    end
 
47
 
 
48
 
 
49
    ColorType = CmdType.new('color', {
 
50
                              :type => :tioga_color,
 
51
                              :namespace => Tioga::ColorConstants
 
52
                            }, <<EOD)
 
53
A color. It can take three forms:
 
54
 * a named color, see 
 
55
{url: http://tioga.rubyforge.org/doc/classes/Tioga/ColorConstants.html}
 
56
for the list of color names.
 
57
 * an HTML color: for instance, @#f00@ or @#ff0000@ is red;
 
58
 * a list of three numbers between 0 and 1: @1,0,0@ is red too.
 
59
EOD
 
60
 
 
61
    ColorOrFalseType = 
 
62
      CmdType.new('color-or-false', {
 
63
                    :type => :tioga_color,
 
64
                    :namespace => Tioga::ColorConstants,
 
65
                    :shortcuts => {'none' => false }
 
66
                  }, <<EOD)
 
67
A {type: color}, or false to say that nothing should be drawn.
 
68
EOD
 
69
 
 
70
    CurveFillUntilType = CmdType.new('fill-until', {
 
71
                                       :type => :float,
 
72
                                       :shortcuts => {
 
73
                                         /x?axis/i => 0.0,
 
74
                                         /b(?:ot(?:tom)?)?/i => :bottom,
 
75
                                         /t(?:op)?/i => :top,
 
76
                                         /no(?:ne)?/i => false
 
77
                                       }
 
78
                                     }, <<EOD)
 
79
The Y values until which a filled curve will be filled. Generally a number, 
 
80
but it can also be:
 
81
 * @axis@ (or @xaxis@), which means 0
 
82
 * @bottom@, to fill until the bottom of the graph
 
83
 * @top@, to fill until the top 
 
84
 * @none@, meaning no fill
 
85
EOD
 
86
 
 
87
    RegionSideType = 
 
88
      CmdType.new('region-side', {
 
89
                    :type => :list,
 
90
                    :list => {},
 
91
                    :shortcuts => {
 
92
                      'above' => :above,
 
93
                      'below' => :below,
 
94
                      'ignore' => false,
 
95
                    }
 
96
                  }, <<EOD)
 
97
Within a {command: region}, designates the position of the curve with
 
98
respect to the region:
 
99
 * @above@
 
100
 * @below@
 
101
 * @ignore@ if this curve is not to be taken into account
 
102
EOD
 
103
 
 
104
                    
 
105
                    
 
106
    LineStyleType = 
 
107
      CmdType.new('line-style', {
 
108
                    :type => :tioga_line_style,
 
109
                    :namespace => LineStyles,
 
110
                    :shortcuts => {
 
111
                      /no(ne)?|off/i => false,
 
112
                    }
 
113
                  }, <<EOD)
 
114
A line style, or @no@, @none@ or @off@ to mean no line.
 
115
EOD
 
116
 
 
117
    MarkerType = 
 
118
      CmdType.new('marker', {
 
119
                    :type => :tioga_marker,
 
120
                    :namespace => Tioga::MarkerConstants,
 
121
                    :shortcuts => {
 
122
                      'None' => 'None',
 
123
                      'no' => 'None',
 
124
                      'none' => 'None',
 
125
                      'off' => 'None', 
 
126
                    },}, <<EOD)
 
127
A Tioga Marker.
 
128
EOD
 
129
 
 
130
    PointType = 
 
131
      CmdType.new('point', :point, <<EOD)
 
132
A given point on a figure.
 
133
EOD
 
134
 
 
135
# We need a very specific type for that as we want to have a reference
 
136
# to the level too !
 
137
    LevelType = 
 
138
      CmdType.new('level', :level, <<EOD)
 
139
A level on a XYZ map (that is, just a Z value).
 
140
EOD
 
141
 
 
142
   JustificationRE = {
 
143
      /l(eft)?/i => Tioga::FigureConstants::LEFT_JUSTIFIED,
 
144
      /c(enter)?/i => Tioga::FigureConstants::CENTERED,
 
145
      /r(ight)?/i => Tioga::FigureConstants::RIGHT_JUSTIFIED
 
146
    }
 
147
 
 
148
    JustificationType = 
 
149
      CmdType.new('justification', {:type => :re_list,
 
150
                    :list => JustificationRE}, <<EOD)
 
151
Horizontal aligment for text. Can be one of:
 
152
 * @l@ or @left@
 
153
 * @c@, @center@
 
154
 * @r@, @right@
 
155
EOD
 
156
 
 
157
   # Regular expression for vertical alignment
 
158
   AlignmentRE = {
 
159
      /t(op)?/i => Tioga::FigureConstants::ALIGNED_AT_TOP,
 
160
      /c(enter)|m(idheight)/i => Tioga::FigureConstants::ALIGNED_AT_MIDHEIGHT,
 
161
      /B|Baseline|baseline/ => Tioga::FigureConstants::ALIGNED_AT_BASELINE,
 
162
      /b(ottom)?/ => Tioga::FigureConstants::ALIGNED_AT_BOTTOM
 
163
    }
 
164
 
 
165
    AlignmentType = 
 
166
        CmdType.new('alignment', {:type => :re_list,
 
167
                      :list => AlignmentRE}, 
 
168
                    <<EOD)
 
169
Vertical aligment for text. Can be one of:
 
170
 * @t@ or @top@
 
171
 * @c@, @center@, @m@ or @midheight@ (vertically centered)
 
172
 * @B@, @Baseline@ or @baseline@ to align at the baseline
 
173
 * @b@ or @bottom@
 
174
EOD
 
175
 
 
176
    PDFFont = 
 
177
      CmdType.new('pdf-font', :integer, <<EOD)
 
178
A number between 1 and 14 that designates one of the 14 standard 
 
179
PDF fonts. (see for instance
 
180
{url: http://tioga.rubyforge.org/doc/classes/Tioga/MarkerConstants.html}
 
181
for more information).
 
182
EOD
 
183
 
 
184
    AlignedPointType = 
 
185
      CmdType.new('aligned-point', {:type => :aligned_point, 
 
186
                    :default => :frame}, <<EOD)
 
187
A point together with alignment specifications.
 
188
EOD
 
189
 
 
190
    FrameMarginsType = 
 
191
      CmdType.new('frame-margins', {:type => 
 
192
                    :frame_margins, :shortcuts => 
 
193
                    { /^\s*auto\s*$/i => nil}}, <<EOD)
 
194
Margins around a plot, ie the distance from the side of the plot to
 
195
the corresponding side of the container (most likely the whole
 
196
PDF). It can take three forms:
 
197
 * @dimension@ (applies to all sides)
 
198
 * @left_right, top_bottom@
 
199
 * @left, right, top, bottom@
 
200
 
 
201
Each of these elements is a valid {type: dimension}.
 
202
 
 
203
It can also be @auto@, in which case the position of the margins is
 
204
computed automatically to accomodate the various labels/ticks.
 
205
EOD
 
206
 
 
207
    # Now, axes stuff:
 
208
 
 
209
    AxisDecorationType = 
 
210
      CmdType.new('axis-decoration', :tioga_axis_type, <<EOD)
 
211
Kinds of decoration on a axis line, such as nothing, lines, ticks, 
 
212
tick labels. Possible values:
 
213
 * @hidden@ or @off@: no axis at all
 
214
 * @line@: only a line
 
215
 * @ticks@: only ticks
 
216
 * @major@: only major ticks
 
217
 * @major-num@: major ticks along with their labels
 
218
 * @full@: major ticks and labels + minor ticks
 
219
EOD
 
220
 
 
221
    # Dimensions
 
222
 
 
223
    DimensionType = 
 
224
      CmdType.new('dimension', { :type => :dimension, 
 
225
                    :default => :dy }, <<EOD)
 
226
 
 
227
A dimension, in absolute units, or in units of text height, figure,
 
228
frame or page coordinates. It is in the form 
 
229
@value unit@
 
230
where @value@ is a number and unit can be one of @pt@,
 
231
@bp@, @in@, @cm@ (absolute units, same meaning as in TeX), 
 
232
@dy@ (@1.0 dy@ is the height of a text
 
233
line), @figure@ or @f@ (for figure coordinates, i.e. the coordinates of the
 
234
plot), @frame@ or @F@ (@1.0 frame@ is the full size of the current subplot) and
 
235
@page@ or @p@ (@1.0 page@ is the whole height/width of the output file).
 
236
EOD
 
237
 
 
238
    # Boxes
 
239
 
 
240
    BoxType = 
 
241
      CmdType.new('box', :box, <<EOD)
 
242
The specification for a box, such as an inset. Specifications vary for
 
243
now... 
 
244
 
 
245
@todo to be written later on.
 
246
EOD
 
247
 
 
248
    # Coordinate transformations
 
249
    BijectionType = 
 
250
      CmdType.new('bijection', :bijection, <<EOD)
 
251
A pair of functions of x specifying a bidirectional coordinate
 
252
transformation separated by a double colon (@::@), in the order
 
253
@from::to@.
 
254
 
 
255
Each of the functions must be valid Ruby code - it is not exactly
 
256
mathematical functions, in particular Ruby does not like floats which
 
257
are missing digits on either side of the dot : for instance, @.3@ and
 
258
@1.@ are not valid. Sorry.
 
259
 
 
260
In most of the usual cases, the coordinate transform is an involution,
 
261
that is from and to is the same function (this is the case for
 
262
a/x). In this case, you can omit the second function.
 
263
EOD
 
264
 
 
265
  end
 
266
end