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, filltype filltype=NoFill); Label Label(string s="", align align=NoAlign, pen p=nullpen, filltype filltype=NoFill); Label Label(Label L, pair position, align align=NoAlign, pen p=nullpen, filltype filltype=NoFill); Label Label(Label L, align align=NoAlign, pen p=nullpen, filltype filltype=NoFill);The text of a Label can be scaled horizontally and/or vertically by multiplying it on the left with
xscale(real)
,
yscale(real)
, or scale(real)
.
After optionally scaling a Label, it can be rotated by an angle by
multiplying it on the left with a rotation (in degrees): 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 like this: shift(10,0)*L
.
To 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.
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 includegraphics(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 (draftx=bool
) parameters. The
layer()
function can be used to force future objects to be
drawn on top of the included image:
label(includegraphics("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.
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 following example:
size(9cm,10cm,IgnoreAspect); pair d=(1,0.25); real s=1.6d.x; real y=0.6; defaultpen(fontsize(8)); picture box(string s, pair z=(0,0)) { picture pic; draw(pic,box(-d/2,d/2)); label(pic,s,(0,0)); return shift(z)*pic; } label("Birds",(0,y)); picture removed=box("Removed ($R_B$)"); picture infectious=box("Infectious ($I_B$)",(0,-1.5)); picture susceptible=box("Susceptible ($S_B$)",(0,-3)); add(removed); add(infectious); add(susceptible); label("Mosquitoes",(s,y)); picture larval=box("Larval ($L_M$)",(s,0)); picture susceptibleM=box("Susceptible ($S_M$)",(s,-1)); picture exposed=box("Exposed ($E_M$)",(s,-2)); picture infectiousM=box("Infectious ($I_M$)",(s,-3)); add(larval); add(susceptibleM); add(exposed); add(infectiousM); path ls=point(larval,S)--point(susceptibleM,N); path se=point(susceptibleM,S)--point(exposed,N); path ei=point(exposed,S)--point(infectiousM,N); path si=point(susceptible,N)--point(infectious,S); draw(minipage("\flushright{recovery rate ($g$) \& death rate from virus ($\mu_V$)}",40pt),point(infectious,N)--point(removed,S),LeftSide,Arrow, PenMargin); draw(si,LeftSide,Arrow,PenMargin); draw(minipage("\flushright{maturation rate ($m$)}",50pt),ls,RightSide, Arrow,PenMargin); draw(minipage("\flushright{viral incubation rate ($k$)}",40pt),ei, RightSide,Arrow,PenMargin); path ise=point(infectious,E)--point(se,0.5); draw("$(ac)$",ise,LeftSide,dashed,Arrow,PenMargin); label(minipage("\flushleft{biting rate $\times$ transmission probability}",50pt),point(infectious,SE),dir(-60)+S); path isi=point(infectiousM,W)--point(si,2.0/3); draw("$(ab)$",isi,LeftSide,dashed,Arrow,PenMargin); draw(se,LeftSide,Arrow,PenMargin); real t=2.0; draw("$\beta_M$", point(susceptibleM,E){right}..tension t..{left}point(larval,E), 2*(S+SE),red,Arrow(Fill,0.5)); draw(minipage("\flushleft{birth rate ($\beta_M$)}",20pt), point(exposed,E){right}..tension t..{left}point(larval,E),2SW,red, Arrow(Fill,0.5)); draw("$\beta_M$", point(infectiousM,E){right}..tension t..{left}point(larval,E),2SW, red,Arrow(Fill,0.5)); path arrow=(0,0)--0.75cm*dir(35); draw(point(larval,NNE), Label(minipage("\flushleft{larval death rate ($\mu_L$)}",45pt),1), arrow,blue,Arrow); draw(point(susceptibleM,NNE), Label(minipage("\flushleft{adult death rate ($\mu_A$)}",20pt),1), arrow,N,blue,Arrow); draw(point(exposed,NNE),Label("$\mu_A$",1),arrow,blue,Arrow); draw(point(infectiousM,NNE),Label("$\mu_A$",1),arrow,blue,Arrow);
One can prevent labels from overwriting one another with the
overwrite
pen attribute (see overwrite).