Debian Codegraph @

texmf-dist/metapost/metaplot/metaplot.mp

raw
1 % METAPLOT: primary plot routines for the METAPLOT package.
2 % Copyright(C) 2004-2005, Brooks Moses
3 %
4 % This work may be distributed and/or modified under the
5 % conditions of the LaTeX Project Public License, either
6 % version 1.3 of this license or (at your option) any
7 % later version.
8 % The latest version of the license is in
9 % http://www.latex-project.org/lppl.txt
10 % and version 1.3 or later is part of all distributions of
11 % LaTeX version 2003/06/01 or later.
12 %
13 % This work has the LPPL maintenance status "author-maintained".
14 %
15 % Version 0.91.
16 %
17 % The n < 1.0 release number indicates that this is a beta release;
18 % the author at present makes no assurances that the command syntax
19 % will remain unchanged between this and the final Version 1.0
20 % release.
21 %
22 % Bug reports, feature requests, and all other suggestions should
23 % be directed to Brooks Moses via [email protected].
24
25
26 % Load MetaPlot axes macros
27 input axes
28
29 % plot_instantiate(suffix inst, suffix plot_object)
30 %
31 % Defines a page-instance of plot-object inst, and sets up the relevant
32 % correspondences between the page locations and the plot-object's scale
33 % locations.
34
35 def plot_instantiate(suffix inst)(suffix plot_object) =
36
37 % Define (unknown) parameters for plot-instance location on page
38
39 numeric inst.pagewidth, inst.pageheight;
40 numeric inst.pageleft, inst.pageright, inst.pagetop, inst.pagebottom;
41 pair inst.llft, inst.lrt, inst.ulft, inst.urt;
42
43 inst.pageleft + inst.pagewidth = inst.pageright;
44 inst.pagebottom + inst.pageheight = inst.pagetop;
45 inst.llft = (inst.pageleft, inst.pagebottom);
46 inst.lrt = (inst.pageright, inst.pagebottom);
47 inst.ulft = (inst.pageleft, inst.pagetop);
48 inst.urt = (inst.pageright, inst.pagetop);
49
50 % Define (known) parameters for plot's scaling
51
52 numeric inst.scalewidth, inst.scaleheight;
53 numeric inst.scaleleft, inst.scaleright, inst.scaletop, inst.scalebottom;
54
55 inst.scaleleft := plot_object.xleft;
56 inst.scaleright := plot_object.xright;
57 inst.scalebottom := plot_object.ybot;
58 inst.scaletop := plot_object.ytop;
59
60 inst.scalewidth := inst.scaleright - inst.scaleleft;
61 inst.scaleheight := inst.scaletop - inst.scalebottom;
62
63 % Pointer-function to plot_object's plots, scaled and positioned.
64
65 vardef inst.plot(suffix name) =
66 begingroup
67 save xleft; save xright; save ybot; save ytop;
68 xleft = min(xpart(llcorner plot_object.name), 0.0);
69 xright = max(xpart(urcorner plot_object.name), 1.0);
70 ybot = min(ypart(llcorner plot_object.name), 0.0);
71 ytop = max(ypart(urcorner plot_object.name), 1.0);
72 setbounds plot_object.name to
73 (xleft,ybot)--(xright,ybot)--(xright,ytop)--(xleft,ytop)--cycle;
74 endgroup;
75 plot_object.name xscaled inst.pagewidth yscaled inst.pageheight
76 shifted inst.llft
77 enddef;
78
79 enddef;
80
81 % plot_setequalaxes(suffix inst)
82 %
83 % Sets the axis-scales equal on plot inst.
84
85 def plot_setequalaxes(suffix inst) =
86 inst.pagewidth = inst.pageheight * (inst.scalewidth/inst.scaleheight);
87 enddef;
88
89
90 % plot_[x | y | x]pageloc(suffix inst,
91 % numeric [scalex | scaley | scalex, scaley])
92 %
93 % Scale-to-page conversion functions, which produce the value (or pair)
94 % for the page location that corresponds to the given x location, y
95 % location, or pair in plot-object inst's coordinates.
96
97 def plot_xpageloc(suffix inst)(expr scalex) =
98 inst.pageleft + (inst.pagewidth/inst.scalewidth) * (scalex - inst.scaleleft)
99 enddef;
100
101 def plot_ypageloc(suffix inst)(expr scaley) =
102 inst.pagebottom + (inst.pageheight/inst.scaleheight) * (scaley - inst.scalebottom)
103 enddef;
104
105 def plot_zpageloc(suffix inst)(expr scalex)(expr scaley) =
106 (plot_xpageloc(inst, scalex), plot_ypageloc(inst,scaley))
107 enddef;
108
109
110 % plot_[x | y]scaleloc(suffix inst,
111 % numeric [pagex | pagey])
112 %
113 % Page-to-scale conversion functions, which produce the value
114 % for the location in plot-object inst's coordinates that corresponds
115 % to the given x location or y location on the page.
116
117 def plot_xscaleloc(suffix inst)(expr pagex) =
118 inst.scaleleft + (inst.scalewidth/inst.pagewidth) * (pagex - inst.pageleft)
119 enddef;
120
121 def plot_yscaleloc(suffix inst)(expr pagey) =
122 inst.scalebottom + (inst.scaleheight/inst.pageheight) * (pagey - inst.pagebottom)
123 enddef;
124
125
126
127 % plot_xtickscale(suffix inst,
128 % pair startpoint,
129 % pair endpoint,
130 % numeric ticklength,
131 % numeric tickspace,
132 % pair tickdir,
133 % numeric tickzero,
134 % numeric tickstep,
135 % string ticklabelformat)
136 %
137 % Draws a row of x-axis grid ticks from startpoint to endpoint,
138 % with the values determined by the x-scale of plot-object inst,
139 % and the details of the tick location and format determined
140 % according to the axes_tickscale parameters.
141
142 def plot_xtickscale(suffix inst)
143 (expr startpoint, endpoint,
144 ticklength, tickspace, tickdir,
145 tickzero, tickstep, ticklabelformat) =
146 axes_tickscale(startpoint, endpoint,
147 ticklength, tickspace, tickdir,
148 plot_xscaleloc(inst)(xpart(startpoint)),
149 plot_xscaleloc(inst)(xpart(endpoint)),
150 tickzero, tickstep, ticklabelformat)
151 enddef;
152
153
154 % plot_ytickscale(suffix inst,
155 % pair startpoint,
156 % pair endpoint,
157 % numeric ticklength,
158 % numeric tickspace,
159 % pair tickdir,
160 % numeric tickzero,
161 % numeric tickstep,
162 % string ticklabelformat)
163 %
164 % Draws a row of y-axis grid ticks from startpoint to endpoint,
165 % with the values determined by the y-scale of plot-object inst,
166 % and the details of the tick location and format determined
167 % according to the axes_tickscale parameters.
168
169 def plot_ytickscale(suffix inst)
170 (expr startpoint, endpoint,
171 ticklength, tickspace, tickdir,
172 tickzero, tickstep, ticklabelformat) =
173 axes_tickscale(startpoint, endpoint,
174 ticklength, tickspace, tickdir,
175 plot_yscaleloc(inst)(ypart(startpoint)),
176 plot_yscaleloc(inst)(ypart(endpoint)),
177 tickzero, tickstep, ticklabelformat)
178 enddef;
179