1## Copyright (C) 1998-2003 Joao Cardoso.
2##
3## This program is free software; you can redistribute it and/or modify it
4## under the terms of the GNU General Public License as published by the
5## Free Software Foundation; either version 2 of the License, or (at your
6## option) any later version.
7##
8## This program is distributed in the hope that it will be useful, but
9## WITHOUT ANY WARRANTY; without even the implied warranty of
10## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11## General Public License for more details.
12##
13## This file is part of plplot_octave.
14
15## __pl_plenv(xm, xM, ym, yM, scale, axis)
16##
17## this is equivalent to plenv, except that no padv(0) is performed.
18## this is important for multiplot, as pladv(i) advances the subwindow,
19## and pladv(0) advances the page, clearing all plots. However, not
20## calling pladv(0), keeps all plots in the plot buffer,
21## so "plreplot" replots all plots since the last call to
22## pladv(0)/plbop. Instead, the (sub)window is cleared, and the
23## subplot  position remains the same. Of course, it is not fast.
24## Changed: The above described behaviour is only valid in multiplot mode,
25## else, pladv(0) is issued.
26## x/y ticks can be disable.
27
28function __pl_plenv(xm, xM, ym, yM, scale, axis)
29
30  global __pl
31  strm = plgstrm + 1;
32
33  if (__pl.multi(strm) == 1)	# multiplot, erase current subwindow
34    plclear;
35  else
36    pladv(0);
37  endif
38
39  if (__pl.aspect(strm) == 2) ## square
40    scale = 2;
41  elseif (__pl.aspect(strm) == 1) ## equal
42    scale = 1;
43  endif
44
45  if (scale == 1 || scale == 2)
46    [t, chrht]= plgchr;
47    lb = 8.0 * chrht;
48    rb = 5.0 * chrht;
49    tb = 5.0 * chrht;
50    bb = 5.0 * chrht;
51    dx = abs(xM - xm);
52    dy = abs(yM - ym);
53    [spxmin, spxmax, spymin, spymax] = plgspa;
54    xsize = spxmax - spxmin;
55    ysize = spymax - spymin;
56
57    if (scale == 1 ) ## equal
58      xscale = dx / (xsize - lb - rb);
59      yscale = dy / (ysize - tb - bb);
60      scale = max([xscale, yscale]);
61      vpxmin = max([lb, 0.5 * (xsize - dx / scale)]);
62      vpxmax = vpxmin + (dx / scale);
63      vpymin = max([bb, 0.5 * (ysize - dy / scale)]);
64      vpymax = vpymin + (dy / scale);
65      plsvpa(vpxmin, vpxmax, vpymin, vpymax);
66    elseif (scale == 2) ## square
67      size = min([xsize-lb-rb, ysize-tb-bb]);
68      vpxmin = lb;
69      vpxmax = lb+size;
70      vpymin = bb;
71      vpymax = bb+size;
72      plsvpa(vpxmin, vpxmax, vpymin, vpymax);
73    endif
74  endif
75
76  if (scale == 0) ## normal
77    plvsta;
78  endif
79
80  xrg = yrg = 0;
81  if (__pl.margin(strm))
82    xrg = (xM-xm)/50; yrg = (yM-ym)/50;
83  endif
84
85  plwind(xm-xrg, xM+xrg, ym-yrg, yM+yrg);
86
87  ## axis=-2 : draw no box, axis or labels
88  ## axis=-1 : draw box only
89  ## axis= 0 : Draw box and label with coordinates
90  ## axis= 1 : Also draw the coordinate axes
91  ## axis= 2 : Draw a grid at major tick positions
92  ## axis=10 : Logarithmic X axis, Linear Y axis, No X=0 axis
93  ## axis=11 : + coordinate axis
94  ## axis=12 : + grid
95  ## axis=13 : + minor ticks grid
96  ## axis=20 : Linear X axis, Logarithmic Y axis, No Y=0 axis
97  ## axis=21 : + coordinate axis
98  ## axis=22 : + grid
99  ## axis=23 : + minor ticks grid
100  ## axis=30 : Logarithmic X and Y axes
101  ## axis=31 : + coordinate axes
102  ## axis=32 : + grid
103  ## axis=33 : + minor ticks grid
104
105  switch(axis)
106    case -2
107      xopt=""; yopt="";
108    case -1
109      xopt="bc"; yopt="bc";
110    case 0
111      xopt="bcnst"; yopt="bcnstv";
112    case 1
113      xopt="bcnsta"; yopt="bcnstva";
114    case 2
115      xopt="bcnstag"; yopt="bcnstvag";
116    case 3
117      xopt="bcnstagh"; yopt="bcnstvagh";
118    case 10
119      xopt="bcnstl"; yopt="bcnstv";
120    case 11
121      xopt="bcnstl"; yopt="bcnstva";
122    case 12
123      xopt="bcgnstl"; yopt="bcnstvag";
124    case 13
125      xopt="bcgnstlh"; yopt="bcnstvagh";
126    case 20
127      xopt="bcnst"; yopt="bcnstvl";
128    case 21
129      xopt="bcnst"; yopt="bcnstval";
130    case 22
131      xopt="bcnstg"; yopt="bcnstvagl";
132    case 23
133      xopt="bcnstgh"; yopt="bcnstvaglh";
134    case 30
135      xopt="bcnstl"; yopt="bcnstvl";
136    case 31
137      xopt="bcnstl"; yopt="bcnstval";
138    case 32
139      xopt="bcngstl"; yopt="abcnstvgl";
140    case 33
141      xopt="bcngstlh"; yopt="abcnstvglh";
142  endswitch
143
144  ## disable ticks
145  if (__pl.xticks(strm,3) == 0)
146    xopt = strrep (xopt, "t", "");
147  endif
148
149  ## disable tick labels
150  if (__pl.xticks(strm,4) == 0)
151    xopt = strrep (xopt, "n", "");
152  endif
153
154  if (__pl.yticks(strm,3) == 0)
155    yopt = strrep (yopt, "t", "");
156  endif
157
158  if (__pl.yticks(strm,4) == 0)
159    yopt = strrep (yopt, "n", "");
160  endif
161
162  plcol0(15); pllsty(1);
163  plbox(xopt, __pl.xticks(strm,1), __pl.xticks(strm,2),
164	yopt, __pl.yticks(strm,1), __pl.yticks(strm,2));
165
166endfunction
167