1
# types.rb: various useful types to interact with Tioga
2
# copyright (c) 2009 by Vincent Fourmond
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.
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).
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'
22
require 'ctioga2/graphics/types/grid'
24
# In addition to the former, here are some useful constants
25
# This module contains all the classes used by ctioga
28
Version::register_svn_info('$Revision: 249 $', '$Date: 2011-01-29 14:05:04 +0100 (Sat, 29 Jan 2011) $')
32
# A small convenience module for line styles
34
include Tioga::FigureConstants
36
Line_Type_Dash_Dot_Dot = [[5,2,1,2,1,2],0]
37
Line_Type_Small_Dots = [[0.5,1],0]
39
# Shortcut for line styles:
40
Solid = Line_Type_Solid
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
49
ColorType = CmdType.new('color', {
50
:type => :tioga_color,
51
:namespace => Tioga::ColorConstants
53
A color. It can take three forms:
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.
62
CmdType.new('color-or-false', {
63
:type => :tioga_color,
64
:namespace => Tioga::ColorConstants,
65
:shortcuts => {'none' => false }
67
A {type: color}, or false to say that nothing should be drawn.
70
CurveFillUntilType = CmdType.new('fill-until', {
74
/b(?:ot(?:tom)?)?/i => :bottom,
79
The Y values until which a filled curve will be filled. Generally a number,
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
88
CmdType.new('region-side', {
97
Within a {command: region}, designates the position of the curve with
98
respect to the region:
101
* @ignore@ if this curve is not to be taken into account
107
CmdType.new('line-style', {
108
:type => :tioga_line_style,
109
:namespace => LineStyles,
111
/no(ne)?|off/i => false,
114
A line style, or @no@, @none@ or @off@ to mean no line.
118
CmdType.new('marker', {
119
:type => :tioga_marker,
120
:namespace => Tioga::MarkerConstants,
131
CmdType.new('point', :point, <<EOD)
132
A given point on a figure.
135
# We need a very specific type for that as we want to have a reference
138
CmdType.new('level', :level, <<EOD)
139
A level on a XYZ map (that is, just a Z value).
143
/l(eft)?/i => Tioga::FigureConstants::LEFT_JUSTIFIED,
144
/c(enter)?/i => Tioga::FigureConstants::CENTERED,
145
/r(ight)?/i => Tioga::FigureConstants::RIGHT_JUSTIFIED
149
CmdType.new('justification', {:type => :re_list,
150
:list => JustificationRE}, <<EOD)
151
Horizontal aligment for text. Can be one of:
157
# Regular expression for vertical alignment
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
166
CmdType.new('alignment', {:type => :re_list,
167
:list => AlignmentRE},
169
Vertical aligment for text. Can be one of:
171
* @c@, @center@, @m@ or @midheight@ (vertically centered)
172
* @B@, @Baseline@ or @baseline@ to align at the baseline
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).
185
CmdType.new('aligned-point', {:type => :aligned_point,
186
:default => :frame}, <<EOD)
187
A point together with alignment specifications.
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@
201
Each of these elements is a valid {type: dimension}.
203
It can also be @auto@, in which case the position of the margins is
204
computed automatically to accomodate the various labels/ticks.
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
224
CmdType.new('dimension', { :type => :dimension,
225
:default => :dy }, <<EOD)
227
A dimension, in absolute units, or in units of text height, figure,
228
frame or page coordinates. It is in the form
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).
241
CmdType.new('box', :box, <<EOD)
242
The specification for a box, such as an inset. Specifications vary for
245
@todo to be written later on.
248
# Coordinate transformations
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
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.
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.