Next: contour, Previous: featpost3D, Up: Base modules
flowchartThis package provides routines to assist in drawing flowcharts. The primary
structure is a block, which represents a single block on the
flowchart. The following eight functions return a position on the appropriate
edge of the block, given picture transform t:
pair block.top(transform t=identity()); pair block.left(transform t=identity()); pair block.right(transform t=identity()); pair block.bottom(transform t=identity()); pair block.topleft(transform t=identity()); pair block.topright(transform t=identity()); pair block.bottomleft(transform t=identity()); pair block.bottomright(transform t=identity());To obtain an arbitrary position along the boundary of the block in user coordinates, use:
pair block.position(real x, transform t=identity());The center of the block in user coordinates is stored in
block.center and the block size in PostScript coordinates
is given by block.size.
A frame containing the block is returned by
frame block.draw(pen p=currentpen);The following block generation routines accept a Label, string, or frame for their object argument:
dx around header and body):
block rectangle(object header, object body,
pen headerpen=mediumgray, pen bodypen=currentpen,
pair center=(0,0), real dx=3,
real minheaderwidth=0, real minheaderheight=0,
real minbodywidth=0, real minbodyheight=0);
block rectangle(object body, pen bodypen=currentpen,
pair center=(0,0), real dx=3,
real minwidth=0, real minheight=0);
block diamond(object body, pair center=(0,0), real ds=5,
real dw=1, real height=20,
real minwidth=0, real minheight=0);
block circle(object body, pair center=(0,0), real dr=3,
real mindiameter=0);
block roundrectangle(object body, pair center=(0,0),
real ds=5, real dw=0,
real minwidth=0, real minheight=0);
block bevel(object body, pair center=(0,0), real dh=5, real dw=5,
real minwidth=0, real minheight=0);
To draw paths joining the pairs in point with right-angled lines,
use the routine:
path path(pair point[] ... bool horizontal[]);The entries in
horizontal identify whether successive
segments between the pairs specified by point should be drawn
horizontal (true) or vertical (false).
Here is a simple flowchart example:
size(0,300);
import flowchart;
block block1=rectangle("Example",pack("Start:","","$A:=0$","$B:=1$"),(-0.5,3));
block block2=diamond("Choice?",(0,2));
block block3=roundrectangle("Do something",(-1,1));
block block4=bevel("Don't do something",(1,1));
block block5=circle("End",(0,0));
draw(block1);
draw(block2);
draw(block3);
draw(block4);
draw(block5);
add(new void(frame f, transform t) {
picture pic;
draw(pic,path(new pair[]{block1.right(t),block2.top(t)},Horizontal),
Arrow,PenMargin);
draw(pic,Label("Yes",0.5),path(new pair[]{block2.left(t),block3.top(t)},
Horizontal),Arrow,PenMargin);
draw(pic,Label("No",0.5,N),path(new pair[]{block2.right(t),block4.top(t)},
Horizontal),Arrow,PenMargin);
draw(pic,path(new pair[]{block3.bottom(t),block5.left(t)},Vertical),
Arrow,PenMargin);
draw(pic,path(new pair[]{block4.bottom(t),block5.right(t)},Vertical),
Arrow,PenMargin);
add(f,pic.fit());
});