summaryrefslogtreecommitdiff
path: root/tex/context/base/m-graph.tex
blob: 6f71cca3c57c29b2e1d498cce6c35873ce86f5f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
%D \module
%D   [       file=m-graph,
%D        version=2000.08.06,
%D          title=\CONTEXT\ Extra Modules,
%D       subtitle=\METAPOST\ graph module support,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA / Hans Hagen \& Ton Otten}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\loadmarkfile{m-graph}

\doifnotmode {demo} {\endinput}

%D You need to have the data files in your path,
%D otherwise the run is aborted.

\doiffileelse {agepop91.d} {} {\writestatus{graph}{no data files found}\wait\end}

%D The test:

\starttext

\startMPpage
draw begingraph(3in,2in);
  gdraw "agepop91.d";
  endgraph;
\stopMPpage

\startMPpage
draw begingraph(3in,2in);
  gdraw "agepop91.d" plot btex$\bullet$etex;
  endgraph;
\stopMPpage

\startMPpage
draw begingraph(3in,2in);
  glabel.lft(btex \vbox{\hbox{Population} \hbox{in millions}} etex, OUT);
  glabel.bot(btex Age in years etex, OUT);
  gdraw "agepopm.d";
  endgraph;
\stopMPpage

\startMPpage
draw begingraph(3in,2in);
 glabel.lft(btex \vbox{\hbox{Population} \hbox{in millions}} etex, OUT);
 glabel.bot(btex Age in years etex, OUT);
 setrange(origin, whatever,whatever);
 gdraw "agepopm.d";
 endgraph;
\stopMPpage

\startMPpage
draw begingraph(2.3in,2in);
 setcoords(log,log);
 glabel.lft(btex Seconds etex,OUT);
 glabel.bot(btex Matrix size etex,
   OUT);
 gdraw "matmul.d" dashed evenly;
 glabel.ulft(btex Standard etex,8);
 gdraw "matmul.d";
 glabel.lrt(btex Strassen etex,7);
 endgraph;
\stopMPpage

\startMPpage
draw begingraph(6.5cm,4.5cm);
 setrange(80,0, 90,whatever);
 glabel.bot(btex Year etex, OUT);
 glabel.lft(btex \vbox{\hbox{Emissions in} \hbox{thousands of}
   \hbox{metric tons} \hbox{(heavy line)}}etex, OUT);
 gdraw "lead.d" withpen pencircle scaled 1.5pt;
 autogrid(,otick.lft);
 setcoords(linear,linear);
 setrange(80,0, 90,whatever);
 glabel.rt(btex \vbox{\hbox{Micrograms} \hbox{per cubic}
   \hbox{meter of air} \hbox{(thin line)}}etex, OUT);
 gdraw "lead.d";
 autogrid(otick.bot,otick.rt);
 endgraph;
\stopMPpage

\stoptext

% No longer needed, since John will fix it.
%
% %D For the moment we need the following patch. Adam T. Lindsay
% %D found out that the following code produced an error:
% %D
% %D \starttyping
% %D \startMPcode
% %D draw begingraph(130mm,35mm);
% %D   setrange(0,0,10,22000);
% %D   glabel.lft(btex  {correct 0--22000} etex rotated 90, OUT);
% %D   autogrid(itick.bot,grid.lft) withcolor .75white ;
% %D   endgraph;
% %D \stopMPcode
% %D
% %D \startMPcode
% %D draw begingraph(130mm,35mm);
% %D   setrange(0,50,10,22000);
% %D   glabel.lft(btex  {wrong 50--22000} etex rotated 90, OUT);
% %D    autogrid(itick.bot,grid.lft) withcolor .75white ;
% %D   endgraph;
% %D \stopMPcode
% %D
% %D \startMPcode
% %D draw begingraph(130mm,35mm);
% %D   setrange(0,110,10,30000);
% %D   glabel.lft(btex  {failed 110--22000} etex rotated 90, OUT);
% %D    autogrid(itick.bot,grid.lft) withcolor .75white ;
% %D   endgraph;
% %D \stopMPcode
% %D \stoptyping
% %D
% %D The bug is a rather nasty one and needs some tweaking in
% %D the low level graph code. John Hobby suggested for the
% %D moment to initialize \type {setrange} as follows:
% %D
% %D \starttyping
% %D  setrange(0,0,"22000","22000")
% %D \stoptyping
% %D
% %D Folowing this suggesion, I provide the following
% %D extension:

% def begingraph(expr w, h) =
%   begingroup
%   save X_, Y_, Gfin_, Gcur_, Gcbb_, Gneedgr_, Gneedfr_, Gdidsc_;
%   save Gdpic_, Gppic_, Ggl_, Garw_;
%   picture Gfin_, Gcur_, Gcbb_, Gdpic_, Gppic_, Ggl_[];
%   boolean Gneedgr_, Gneedfr_, Gdidsc_;
%   Gfin_ = nullpicture;
%   Gcur_ = nullpicture;
%   Gcbb_ = nullpicture;
%   X_.ctyp = Y_.ctyp = linear;
%   Z_.gdim = (w,h);
%   X_.sc = Y_.sc = 0;
%   Gneedgr_ = true;
%   Gneedfr_ = true;
%   Gdidsc_ = false;
%   Gdpic_ = nullpicture;
%   Garw_ = 0;
%   scantokens everybegingraph ;
% enddef;
%
% boolean fixsetrange ; fixsetrange := true ;
%
% vardef dosetrange(text t) =
%   interim warningcheck:=0;
%   save r_; r_=0;
%   string r_[]s;
%   for x_=
%       for p_=t: if pair p_: xpart p_, ypart fi p_, endfor:
%     r_[incr r_] if string x_: s fi = x_;
%     if r_>2:
%       Gsetr_ if r_=3: X_(Gxcvlin_) else: Y_(Gycvlin_) fi(
%           r_[r_-2] if unknown r_[r_-2]: s fi, x_);
%     fi
%     exitif r_=4;
%   endfor
% enddef;
%
% vardef setrange(text t) =
%   if fixsetrange : dosetrange(0,0,20000,20000) ; fi ;
%   dosetrange(t) ;
% enddef ;
%
% if unknown everybegingraph :
%   string everybegingraph ;
% % everybegingraph := "setrange(0,0,20000,20000)" ;
% fi ;