Previous: clip, Up: Drawing commands
void label(picture pic=currentpicture, Label L, pair position,
align align=NoAlign, pen p=nullpen, filltype filltype=NoFill)
Draw Label L on picture pic using pen p. If
align is NoAlign, the label will be centered at user
coordinate position; otherwise it will be aligned in the
direction of align and displaced from position by
the PostScript offset align*labelmargin(p).
If p is nullpen, the pen specified within the
Label, which defaults to currentpen, will be used.
The Label L can either be a string or the structure obtained by calling
one of the functions
Label Label(string s="", pair position, align align=NoAlign,
pen p=nullpen, embed embed=Rotate, filltype filltype=NoFill);
Label Label(string s="", align align=NoAlign,
pen p=nullpen, embed embed=Rotate, filltype filltype=NoFill);
Label Label(Label L, pair position, align align=NoAlign,
pen p=nullpen, embed embed=L.embed, filltype filltype=NoFill);
Label Label(Label L, align align=NoAlign,
pen p=nullpen, embed embed=L.embed, filltype filltype=NoFill);
The text of a Label can be scaled, slanted, rotated, or shifted by
multiplying it on the left by an affine transform (see Transforms).
For example, rotate(45)*xscale(2)*L first scales L in the
x direction and then rotates it counterclockwise by 45
degrees. The final position of a Label can also be shifted by a
PostScript coordinate translation: shift(10,0)*L.
The embed argument determines how the Label should transform with the
embedding picture:
ShiftRotateSlantScaleTo add a label to a path, use
void label(picture pic=currentpicture, Label L, path g, align align=NoAlign,
pen p=nullpen, filltype filltype=NoFill);
By default the label will be positioned at the midpoint of the path.
An alternative label location (an arctime value between 0 and
length(g) see arctime) may be specified as real value for
position in constructing the Label. The position
Relative(real) specifies a location relative to the total
arclength of the path. These convenient abbreviations are predefined:
position BeginPoint=Relative(0); position MidPoint=Relative(0.5); position EndPoint=Relative(1);
Path labels are aligned in the direction align, which may
be specified as an absolute compass direction (pair) or a direction
Relative(pair) measured relative to a north axis
in the local direction of the path. For convenience LeftSide,
Center, and RightSide are defined as Relative(W),
Relative((0,0)), and Relative(E), respectively.
Multiplying LeftSide, Center, RightSide on the
left by a real scaling factor will move the label further away from or
closer to the path.
A label with a fixed-size arrow of length arrowlength pointing
to b from direction dir can be produced with the routine
void arrow(picture pic=currentpicture, Label L="", pair b, pair dir,
real length=arrowlength, align align=NoAlign,
pen p=currentpen, arrowbar arrow=Arrow, margin margin=EndMargin);
If no alignment is specified (either in the Label or as an explicit
argument), the optional Label will be aligned in the direction dir,
using margin margin.
The function string graphic(string name, string options="")
returns a string that can be used to include an encapsulated
PostScript (EPS) file. Here, name is the name
of the file to include and options is a string containing a
comma-separated list of optional bounding box (bb=llx lly urx
ury), width (width=value), height (height=value),
rotation (angle=value), scaling (scale=factor), clipping
(clip=bool), and draft mode (draft=bool) parameters. The
layer() function can be used to force future objects to be
drawn on top of the included image:
label(graphic("file.eps","width=1cm"),(0,0),NE);
layer();
The string baseline(string s, align align=S, string template="M")
function can be used to enlarge the bounding box of letters aligned
below a horizontal line to match a given template, so that their
baselines lie on a horizontal line. See Pythagoras.asy for an
example.
One can prevent labels from overwriting one another with the
overwrite pen attribute (see overwrite).
The structure object defined in Label.asy allows Labels
and frames to be treated in a uniform manner.
A group of objects may be packed together into single frame with the routine
frame pack(pair align=2S ... object inset[]);
The string minipage(string s, width=100pt) function can be used
to format string s into a paragraph of width width, as
illustrated in the example advection.asy:
