Debian Codegraph @

texmf-dist/doc/metapost/base/source-manual/charts.mp

raw
1 % Support package for drawing charts.
2
3 def _drawNode = drawboxed enddef;
4
5 %%% These paramaters determine the size of nodes and the grid distance.
6 newinternal applwidth; applwidth := 30bp;
7 newinternal applheight; applheight := 14bp;
8 newinternal extwidth; extwidth := 30bp;
9 newinternal extheight; extheight := 14bp;
10 newinternal rowscale; rowscale := 100bp;
11 newinternal colscale; colscale := 100bp;
12
13 %%% This macro builds and draws a rectangular node at a given location
14 %%% with text indicating an application.
15 %% @param i Node suffix.
16 %% @param row Row.
17 %% @param col Column.
18 %% @param text The text to render in the box node.
19 def appl(suffix i)(expr coor)(text t) =
20 boxit.i(t);
21 i.c = coor;
22 i.e = i.c + .5applwidth*right;
23 i.n = i.c + .5applheight*up;
24 _drawNode(i);
25 enddef;
26
27
28 %%% This macro builds and draws an oval node at a given location with
29 %%% text indicating a file name extension.
30 %% @param i Node suffix.
31 %% @param row Row.
32 %% @param col Column.
33 %% @param text The text to render in the oval node.
34 def ext(suffix i)(expr coor)(text t) =
35 circleit.i(t);
36 i.c = coor;
37 i.e = i.c + .5extwidth*right;
38 i.n = i.c + .5extheight*up;
39 _drawNode(i);
40 enddef;
41
42
43 %%% This macro builds and draws a rectangular node at a given location
44 %%% with text indicating an application.
45 %% @param i Node suffix.
46 %% @param row Row.
47 %% @param col Column.
48 %% @param text The text to render in the box node.
49 def appl_rc(suffix i)(expr coor)(text t) =
50 boxit.i(t);
51 i.c = (colscale * ypart coor, -rowscale * xpart coor);
52 i.e = i.c + .5applwidth*right;
53 i.n = i.c + .5applheight*up;
54 _drawNode(i);
55 enddef;
56
57
58 %%% This macro builds and draws an oval node at a given location with
59 %%% text indicating a file name extension.
60 %% @param i Node suffix.
61 %% @param row Row.
62 %% @param col Column.
63 %% @param text The text to render in the oval node.
64 def ext_rc(suffix i)(expr coor)(text t) =
65 circleit.i(t);
66 i.c = (colscale * ypart coor, -rowscale * xpart coor);
67 i.e = i.c + .5extwidth*right;
68 i.n = i.c + .5extheight*up;
69 _drawNode(i);
70 enddef;
71
72
73 %%% This macro draws a straight arrow between two nodes. Arrow length
74 %%% is corrected for the pen width, so that the arrow doesn't sink into
75 %%% the frame of the target node. If pen width is changed, the code
76 %%% "0.5bp" has to be replaced by half of the new pen width.
77 %% @param a Source node.
78 %% @param b Target node.
79 def line(suffix a,b) =
80 begingroup
81 save p;path p;
82 p := a.c--b.c cutbefore bpath(a) cutafter bpath(b);
83 drawarrow subpath (0, arctime (arclength p - 0.5bp) of p) of p;
84 endgroup
85 enddef;
86
87
88 %%% This macro draws a curved arrow between two nodes with determined
89 %%% leaving and entering angles. Arrow length is corrected for the pen
90 %%% width so that the arrow doesn't sink into the frame of the target
91 %%% node. If pen width is changed, the code "0.5bp" has to be replaced
92 %%% by half of the new pen width.
93 %% @param a Source node.
94 %% @param b Target node.
95 %% @param anga Leaving angle at (center of) node a.
96 %% @param angb Entering angle at (center of) node b.
97 def curve(suffix a,b)(expr anga,angb) =
98 begingroup
99 save p;path p;
100 p := a.c{dir anga}..{dir angb}b.c cutbefore bpath(a) cutafter bpath(b);
101 drawarrow subpath (0, arctime (arclength p - 0.5bp) of p) of p;
102 endgroup
103 enddef;
104
105
106 %%% This macro draws a curved arrow between two nodes with determined
107 %%% leaving and entering angles offset. Arrow length is corrected for
108 %%% the pen width so that the arrow doesn't sink into the frame of the
109 %%% target node. If pen width is changed, the code "0.5bp" has to be
110 %%% replaced by half of the new pen width.
111 %% @param a Source node.
112 %% @param b Target node.
113 %% @param angr Offset to entering and leaving angles at nodes a and b.
114 def curve_rel(suffix a,b)(expr angr) =
115 begingroup
116 save alpha;
117 alpha = angle(b.c-a.c);
118 curve(a, b, alpha+angr, alpha-angr);
119 endgroup
120 enddef;