Debian Codegraph @

texmf-dist/tex/generic/pgfplots/pgfplots.scaling.code.tex

raw
1 %--------------------------------------------
2 %
3 % Package pgfplots
4 %
5 % Provides a user-friendly interface to create function plots (normal
6 % plots, semi-logplots and double-logplots).
7 %
8 % It is based on Till Tantau's PGF package.
9 %
10 % Copyright 2007-2012 by Christian Feuersänger.
11 %
12 % This program is free software: you can redistribute it and/or modify
13 % it under the terms of the GNU General Public License as published by
14 % the Free Software Foundation, either version 3 of the License, or
15 % (at your option) any later version.
16 %
17 % This program is distributed in the hope that it will be useful,
18 % but WITHOUT ANY WARRANTY; without even the implied warranty of
19 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 % GNU General Public License for more details.
21 %
22 % You should have received a copy of the GNU General Public License
23 % along with this program. If not, see <http://www.gnu.org/licenses/>.
24 %
25 %--------------------------------------------
26
27 % PRECONDITION:
28 % - final axis limits are given in transformed range
29 % - \pgfplots@set@default@size@options has been invoked before
30 % POSTCONDITION:
31 % - the current x,y and z unit vectors are defined properly;
32 % - the fast-access registers are initialised for the axis limits,
33 % - the following macros are assigned:
34 % \pgfplots@[xyz]@veclength
35 % \pgfplots@[xyz]@inverseveclength
36 % \pgfplotspointxaxis
37 % \pgfplotspointyaxis
38 % \pgfplotspointzaxis
39 % \pgfplotspointcenter
40 % \pgfplotspointminminmin
41 %
42 \def\pgfplots@initsizes{%
43 % INIT.
44 %
45 %
46 \pgfplots@xmin@reg=\pgfplots@xmin pt %
47 \pgfplots@xmax@reg=\pgfplots@xmax pt %
48 \pgfplots@ymin@reg=\pgfplots@ymin pt %
49 \pgfplots@ymax@reg=\pgfplots@ymax pt %
50 \ifpgfplots@threedim
51 \pgfplots@zmin@reg=\pgfplots@zmin pt %
52 \pgfplots@zmax@reg=\pgfplots@zmax pt %
53 \fi
54 %
55 %-----------------------------------------
56 % PROCESS THE 'width' and 'height' options
57 %-----------------------------------------
58 %
59 %
60 \pgfkeysgetvalue{/pgfplots/view/az}{\pgfplots@view@az}%
61 \pgfkeysgetvalue{/pgfplots/view/el}{\pgfplots@view@el}%
62 \ifpgfplots@threedim
63 \else
64 \let\pgfplots@view@el=\pgfutil@empty
65 \let\pgfplots@view@az=\pgfutil@empty
66 \fi
67 \ifx\pgfplots@view@az\pgfutil@empty
68 % Note that in presence of "x,y,z" options, the
69 % \pgfplots@set@default@size@options RESETS /pgfplots/view/az.
70 %
71 %\let\pgfplots@rectangle@width=\pgfutil@empty
72 %\let\pgfplots@rectangle@height=\pgfutil@empty
73 \pgfplotsmathvectorfromstring{0,0,1}{default}%
74 \let\pgfplots@view@dir@threedim=\pgfplotsretval
75 %
76 \ifx\pgfplots@x\pgfutil@empty
77 \ifx\pgfplots@width\pgfutil@empty
78 \pgfplots@error{INTERNAL LOGIC ERROR! WIDTH NOT SET}%
79 \fi
80 \fi
81 %
82 \ifx\pgfplots@y\pgfutil@empty
83 \ifx\pgfplots@height\pgfutil@empty
84 \pgfplots@error{INTERNAL LOGIC ERROR! HEIGHT NOT SET}%
85 \fi
86 \fi
87 \ifpgfplots@threedim
88 \def\pgfplots@tmp@Zscale{1}%
89 \else
90 \def\pgfplots@tmp@Zscale{0}%
91 \fi
92 %
93 \pgfplots@initsizes@setunitvector{x}{0}{1}{\pgfplots@tmp@xisaxisparallel}%
94 \pgfplots@initsizes@setunitvector{y}{1}{1}{\pgfplots@tmp@yisaxisparallel}%
95 \pgfplots@initsizes@setunitvector{z}{2}{\pgfplots@tmp@Zscale}{\pgfplots@loc@TMPc}%
96 %
97 \pgfplots@scaling@changewidthheight@for@enlargelimits@by@dimension%
98 %
99 \pgfplots@scale@plotbox@to@widthheight
100 \else
101 % 3D case by `view':
102 \let\pgfplots@x=\pgfutil@empty
103 \let\pgfplots@y=\pgfutil@empty
104 \let\pgfplots@z=\pgfutil@empty
105 \pgfplotssetaxesfromazel{\pgfplots@view@az}{\pgfplots@view@el}{\pgfplots@tmp@xisaxisparallel}%
106 %
107 \pgfplots@scaling@changewidthheight@for@enlargelimits@by@dimension%
108 %
109 \pgfplots@scale@plotbox@to@widthheight
110 \if1\pgfplots@tmp@xisaxisparallel%
111 \def\pgfplots@tmp@yisaxisparallel{1}%
112 \fi
113 \fi
114 \pgfplots@computeunitvectorlengths
115 %
116 \pgfplots@scaling@apply@enlargelimits@by@dimension{x}%
117 \pgfplots@scaling@apply@enlargelimits@by@dimension{y}%
118 \ifpgfplots@threedim
119 \pgfplots@scaling@apply@enlargelimits@by@dimension{z}%
120 \fi
121 %
122 \ifpgfplots@threedim
123 \pgfplotsgetnormalforcurrentview
124 \fi
125 %\message{Pgfplots debug: initialised unit vectors to x=(\the\pgf@xx,\the\pgf@xy), y=(\the\pgf@yx,\the\pgf@yy), z=(\the\pgf@zx,\the\pgf@zy), n = (\pgfplots@view@dir@threedim). Limits are x=\pgfplots@xmin:\pgfplots@xmax, y=\pgfplots@ymin:\pgfplots@ymax^^J }%
126 %
127 \let\pgfplotsmathfloatviewdepthxyz@=\pgfplotsmathfloatviewdepthxyz@infigure
128 \let\pgfplotsmathviewdepthxyz@=\pgfplotsmathviewdepthxyz@infigure
129 %
130 \pgfplotsmath@ifzero{\pgfplots@x@veclength}{\pgfplots@hide@xtrue\pgfplots@shownothingof@xtrue}{}%
131 \pgfplotsmath@ifzero{\pgfplots@y@veclength}{\pgfplots@hide@ytrue\pgfplots@shownothingof@ytrue}{}%
132 \ifpgfplots@threedim
133 \pgfplotsmath@ifzero{\pgfplots@z@veclength}{\pgfplots@hide@ztrue\pgfplots@shownothingof@ztrue}{}%
134 \else
135 \if1\pgfplots@tmp@xisaxisparallel%
136 \if1\pgfplots@tmp@yisaxisparallel%
137 % Optimize for axis-parallel case!
138 % puh. Did not make any measurable difference!? Ok...
139 \let\pgfplotsqpointxy=\pgfplotsqpointxy@orthogonal
140 \fi
141 \fi
142 \fi
143 }
144
145 % Defines \pgfmathresult to be the desired width without axis labels.
146 %
147 \def\pgfplots@initsizes@get@width@withoutlabels{%
148 \pgfplots@initsizes@handle@label@const{\pgfplots@width}{45pt}{width}%
149 }
150
151 % Defines \pgfmathresult to be the desired height without axis labels.
152 \def\pgfplots@initsizes@get@height@withoutlabels{%
153 \pgfplots@initsizes@handle@label@const{\pgfplots@height}{45pt}{height}%
154 }
155
156 \def\pgfplots@initsizes@handle@label@const#1#2#3{%
157 \begingroup
158 \pgf@xa=#1\relax
159 % EXPECTED WIDTH = X = \pgfplots@width
160 % ACTUAL WIDTH = c + x * (xmax-xmin)
161 % where c is a CONSTANT (for the axis labels/tick labels).
162 % -> \pgfplots@tmpXscale = (X - c) / (x *(xmax-xmin))
163 %
164 % \pgf@xa := X-c:
165 \ifpgfplots@scale@only@axis
166 \else
167 \advance\pgf@xa by-#2 % FIXME determine 'c' correctly!
168 \fi
169 \ifdim\pgf@xa<0pt
170 \pgfplots@error{Error: Plot #3 `#1' is too small. This cannot be implemented while maintaining constant size for labels. Sorry, label sizes are only approximate. You will need to adjust your #3.}%
171 \pgf@xa=0pt
172 \fi
173 \edef\pgfmathresult{\the\pgf@xa}%
174 \pgfmath@smuggleone\pgfmathresult
175 \endgroup
176 }%
177
178 % #1: axis
179 \def\pgfplots@axis@apply@post@scale#1{%
180 %
181 \pgfkeysgetvalue{/pgfplots/#1 post scale}\pgfplots@loc@TMPd
182 \ifx\pgfplots@loc@TMPd\pgfutil@empty
183 \else
184 \pgfmathparse{\csname pgfplots@target@unit@scale@#1x\endcsname*\pgfplots@loc@TMPd}%
185 \expandafter\let\csname pgfplots@target@unit@scale@#1x\endcsname=\pgfmathresult
186 %
187 \pgfmathparse{\csname pgfplots@target@unit@scale@#1y\endcsname*\pgfplots@loc@TMPd}%
188 \expandafter\let\csname pgfplots@target@unit@scale@#1y\endcsname=\pgfmathresult
189 \fi
190 }
191
192 % Takes azimuth (horizontal angle) '#1' and elongation (vertical
193 % angle) '#2' (both in degrees) and computes
194 % x,y and z vectors which define the view in the direction
195 % defined by '#1' and '#2'.
196 %
197 % 'azimuth' means a rotation around the viewport's x axis. 'elongation' means
198 % a rotation around the original coordinate system's z axis.
199 %
200 % The method works by computing
201 % Az = [ cos(azimuth) -sin(azimuth) 0; ...
202 % sin(azimuth) cos(azimuth) 0; ...
203 % 0 0 1 ];
204 %
205 %
206 % Ax = [ 1 0 0; ...
207 % 0 cos(elevation) -sin(elevation) ;...
208 % 0 sin(elevation) cos(elevation) ];
209 %
210 % v= Ax * Az;
211 % = [ ...
212 % cosaz -sinaz cosel sinaz sinel; ...
213 % sinaz cosaz cosel -sinel cosaz; ...
214 % 0 sinel cosel ];
215 %
216 % Then, we use the rotated XZ plane as viewport, that means
217 % xvec = v * [1 0 0]' = <first column of v>
218 % zvec = v * [0 0 1]' = <third column of v>
219 % and we define the projection onto the twodimensional surface
220 % spanned by 'xvec' and 'zvec' as
221 % P( q ) = [ q^T xvec, q^T zvec ]'
222 % for q in R^3.
223 % As a consequence, we compute the three unit vectors as
224 % x = P( [1 0 0] )
225 % = [ cosaz, sinaz sinel ]'
226 % y = P( [0 1 0] )
227 % = [ sinaz, -sinel cosaz ]'
228 % z = P( [0 0 1] )
229 % = [ 0, cosel]'
230 %
231 % Furthermore, the 3D view vector which points into the direction of the view
232 % is
233 % n = v * [0 1 0 ]' = <second column of v> = [-sinaz cosel, cosaz cosel, sinel]'
234 % because the normal view point was the XZ plane with y as its normal
235 % vector.
236 % The 3D vector n is returned by this routine as well - it is
237 % necessary for some kind of z buffering (determining what is
238 % foreground and what is background).
239 %
240 % INPUT:
241 % - #1 : azimuth ("yaw")
242 % - #2 : elevation ("pitch")
243 % OUTPUT:
244 % - #3 : a macro which will be set to '1' if and only if
245 % the viewport is the standard XY axis (i.e. azimuth=0, elevation=90).
246 % - [xyz] vectors,
247 % \pgfplots@view@dir@threedim will contain the three components
248 % of 'n' (without the suffix 'pt', but in units of 'pt') (see
249 % \pgfplotsmathvectorfromstring).
250 \def\pgfplotssetaxesfromazel#1#2#3{%
251 \begingroup
252 \pgfmathparse{#1}%
253 \let\pgfplots@az=\pgfmathresult
254 \pgfmathparse{#2}%
255 \edef\pgfplots@el{-\pgfmathresult}%
256 \pgfmathsin@{\pgfplots@az}%
257 \let\sinaz=\pgfmathresult
258 \pgfmathcos@{\pgfplots@az}%
259 \let\cosaz=\pgfmathresult
260 \pgfmathsin@{\pgfplots@el}%
261 \let\sinel=\pgfmathresult
262 \pgfmathcos@{\pgfplots@el}%
263 \let\cosel=\pgfmathresult
264 % x:
265 \pgfmathmultiply@{\sinaz}{\sinel}%
266 \xdef\pgfplots@glob@TMPa{\noexpand\pgfqpoint{\cosaz pt}{\pgfmathresult pt}}%
267 % y:
268 \pgfmathmultiply@{-\sinel}{\cosaz}%
269 \xdef\pgfplots@glob@TMPb{\noexpand\pgfqpoint{\sinaz pt}{\pgfmathresult pt}}%
270 % z:
271 \xdef\pgfplots@glob@TMPc{\noexpand\pgfqpoint{0pt}{\cosel pt}}%
272 %
273 \pgfkeysgetvalue{/pgfplots/x dir/value}\pgfplots@loc@dirvalue@x
274 \pgfkeysgetvalue{/pgfplots/y dir/value}\pgfplots@loc@dirvalue@y
275 \pgfkeysgetvalue{/pgfplots/z dir/value}\pgfplots@loc@dirvalue@z
276 \if r\pgfplots@loc@dirvalue@x
277 \t@pgfplots@toka=\expandafter{\pgfplots@glob@TMPa}%
278 \xdef\pgfplots@glob@TMPa{\noexpand\pgfqpointscale{-1}{\the\t@pgfplots@toka}}%
279 \fi
280 \if r\pgfplots@loc@dirvalue@y
281 \t@pgfplots@toka=\expandafter{\pgfplots@glob@TMPb}%
282 \xdef\pgfplots@glob@TMPb{\noexpand\pgfqpointscale{-1}{\the\t@pgfplots@toka}}%
283 \fi
284 \if r\pgfplots@loc@dirvalue@z
285 \t@pgfplots@toka=\expandafter{\pgfplots@glob@TMPc}%
286 \xdef\pgfplots@glob@TMPc{\noexpand\pgfqpointscale{-1}{\the\t@pgfplots@toka}}%
287 \fi
288 %
289 % Process 'plot box ratio':
290 \def\pgfplots@extract@plot@box@ratio##1##2##3##4\pgfplots@EOI{%
291 \pgfmathparse{##1}\let\pgfplots@plotboxratio@x=\pgfmathresult
292 \pgfmathparse{##2}\let\pgfplots@plotboxratio@y=\pgfmathresult
293 \pgfmathparse{##3}\let\pgfplots@plotboxratio@z=\pgfmathresult
294 }%
295 \def\pgfplots@extract@plot@box@ratio@spaces##1 ##2 ##3 ##4\pgfplots@EOI{%
296 \pgfplots@extract@plot@box@ratio{##1}{##2}{##3}{##4}\pgfplots@EOI
297 }%
298 \pgfkeysgetvalue{/pgfplots/plot box ratio}\pgfplots@loc@TMPa
299 % Auto-determine input format which is either '{x}{y}{z}' or 'x y z'
300 \def\pgfplots@loc@TMPb{%
301 \pgfutil@ifnextchar\bgroup{%
302 \pgfplots@loc@tmptrue
303 \pgfplots@gobble@until@EOI
304 }{%
305 \pgfplots@loc@tmpfalse
306 \pgfplots@gobble@until@EOI
307 }%
308 }%
309 \expandafter\pgfplots@loc@TMPb\pgfplots@loc@TMPa\pgfplots@EOI
310 \ifpgfplots@loc@tmp
311 % Ah- braces format.
312 \edef\pgfplots@loc@TMPa{\pgfplots@loc@TMPa{1}{1}{1}}%
313 \expandafter\pgfplots@extract@plot@box@ratio\pgfplots@loc@TMPa\pgfplots@EOI
314 \else
315 % Ah- space-separated
316 \edef\pgfplots@loc@TMPa{\pgfplots@loc@TMPa\space 1 1 1}%
317 \expandafter\pgfplots@extract@plot@box@ratio@spaces\pgfplots@loc@TMPa\pgfplots@EOI
318 \fi
319 %
320 % process it:
321 \ifdim\pgfplots@plotboxratio@x pt=1pt
322 \else
323 \t@pgfplots@toka=\expandafter{\pgfplots@glob@TMPa}%
324 \xdef\pgfplots@glob@TMPa{\noexpand\pgfqpointscale{\pgfplots@plotboxratio@x}{\the\t@pgfplots@toka}}%
325 \fi
326 \ifdim\pgfplots@plotboxratio@y pt=1pt
327 \else
328 \t@pgfplots@toka=\expandafter{\pgfplots@glob@TMPb}%
329 \xdef\pgfplots@glob@TMPb{\noexpand\pgfqpointscale{\pgfplots@plotboxratio@y}{\the\t@pgfplots@toka}}%
330 \fi
331 \ifdim\pgfplots@plotboxratio@z pt=1pt
332 \else
333 \t@pgfplots@toka=\expandafter{\pgfplots@glob@TMPc}%
334 \xdef\pgfplots@glob@TMPc{\noexpand\pgfqpointscale{\pgfplots@plotboxratio@z}{\the\t@pgfplots@toka}}%
335 \fi
336 %
337 % n (3D!)
338 \pgfmathmultiply@{-\sinaz}{\cosel}%
339 \let\pgfmathresultNx=\pgfmathresult
340 \pgfmathmultiply@{\cosaz}{\cosel}%
341 \xdef\pgfplots@glob@TMPd{{\pgfmathresultNx}{\pgfmathresult}{\sinel}}%
342 \endgroup
343 %\message{Setting x,y and z from {#1}{#2} to^^J x = \meaning\pgfplots@glob@TMPa,^^J y = \meaning\pgfplots@glob@TMPb,^^J z = \meaning\pgfplots@glob@TMPc,^^J n = \pgfplots@glob@TMPd.^^J}%
344 \pgfsetxvec{\pgfplots@glob@TMPa}%
345 \pgfsetyvec{\pgfplots@glob@TMPb}%
346 \pgfsetzvec{\pgfplots@glob@TMPc}%
347 \def\pgfplots@loc@TMPa##1##2##3{%
348 \pgfplotsmathvectorfromstring{##1,##2,##3}{default}%
349 \let\pgfplots@view@dir@threedim=\pgfplotsretval
350 }%
351 \expandafter\pgfplots@loc@TMPa\pgfplots@glob@TMPd\relax
352 \def#3{0}%
353 }%
354
355 % Takes the current plot box, defined by the actual PGF x,y and z unit
356 % vectors, and re-scales it such that it fits into the
357 % width and height of the axis (as they have been provided by the
358 % user).
359 %
360 % @see \pgfplots@scale@axisbox@to@widthheight
361 % @see\pgfplots@scaleaxes@to@BB
362 \def\pgfplots@scale@plotbox@to@widthheight{%
363 \pgfplots@initsizes@get@width@withoutlabels
364 \let\pgfplots@loc@TMPa=\pgfmathresult
365 \pgfplots@initsizes@get@height@withoutlabels
366 %
367 \edef\pgfplots@loc@TMPa{{\pgfplots@loc@TMPa}{\pgfmathresult}}%
368 \expandafter\pgfplots@scaleaxes@to@BB\pgfplots@loc@TMPa
369 }
370
371
372 % Takes the current PGF x,y and z unit vectors and scales them such
373 % that the bounding box of the final image has width #1 and height #2.
374 %
375 % The relative length of the input vectors is important for the 3D case: it
376 % will be scaled as-is.
377 %
378 % PRECONDITION
379 % - the x, y and z unit vectors have been set to the proper
380 % DIRECTIONS. Their relative vector lengths are set-up properly
381 % (i.e. y is twice as large as x and half as large as z or so).
382 % - the \ifpgfplots@threedim boolean is set.
383 % - the data limits have been initialised and transformed according
384 % to the data transformation.
385 % - the data transformation has ONLY been applied to the axis limits
386 % (not other axis inputs). It may be changed by this method.
387 %
388 % POSTCONDITION
389 % - the unit vectors have been re-scaled such that the final plot
390 % has the desired dimensions.
391 % - the @veclength and @inverseveclength have been initialized
392 \def\pgfplots@scaleaxes@to@BB#1#2{%
393 \if0\pgfplots@scale@mode@choice
394 % scale mode=auto
395 \def\pgfplots@scale@mode@choice{2}% stretch to fill
396 \fi
397 \pgfplots@scaleaxes@to@BB@{#1}{#2}%
398 % NOTE: we have not yet computed the lengths of unit vectors. In
399 % addition, we have not yet updated the normal vector.
400 }%
401
402 % DEPRECATED:
403 \def\pgfplots@rescale@view@dir{%
404 \expandafter\ifx\csname pgfplots@view@dir@threedim\endcsname\relax
405 \else
406 % At this point, we ALREADY HAVE a normal vector. However, it
407 % might be skewed due to the scaling.
408 %
409 % -> recompute normal vector. In earlier versions, I tried to
410 % rescale it - but that was too complicated (for me). This
411 % here produces correct results, and it is a correct approach
412 % anyway.
413 \pgfplotsgetnormalforcurrentview
414 \fi
415 }%
416
417 % \pgfplots@BB@for@plotbox@get@unit@scales@for@limits{#1}{#2}{#3}:
418 % a helper tool which computes individual unit vector scales in order
419 % to respect the limits.
420 %
421 % This method ignores width/height; its purpose is only to make sure
422 % that [xmin,xmax] fits into the CURRENT plot box.
423 %
424 % In this context, each unit vector is supposed to be scaled such that
425 % width/height fit if xmin=0 and xmax=1.
426 %
427 % #1 [output] a macro name which will contain the INVERSE scale for x
428 % #2 [output] a macro name which will contain the INVERSE scale for y
429 % #3 [output] a macro name which will contain the INVERSE scale for z
430 %
431 \def\pgfplots@BB@for@plotbox@get@unit@scales@for@limits#1#2#3{%
432 \if1\b@pgfplots@plotbox@xisunit
433 % Consequently, we have to multiply with 1/(max-min):
434 % compute 1/(xmax - xmin) in float for more recent versions (see /pgfplots/compat/scaling).
435 % I observed that it is much more accurate
436 \pgfmathsubtract@{\pgfplots@xmax}{\pgfplots@xmin}%
437 \else
438 \def\pgfmathresult{1}%
439 \fi
440 \let#1=\pgfmathresult
441 %
442 \if1\b@pgfplots@plotbox@yisunit
443 \pgfmathsubtract@{\pgfplots@ymax}{\pgfplots@ymin}%
444 \else
445 \def\pgfmathresult{1}%
446 \fi
447 \let#2=\pgfmathresult
448 %
449 \ifpgfplots@threedim
450 \if1\b@pgfplots@plotbox@zisunit
451 \pgfmathsubtract@{\pgfplots@zmax}{\pgfplots@zmin}%
452 \else
453 \def\pgfmathresult{1}%
454 \fi
455 \else
456 \def\pgfmathresult{1}%
457 \fi
458 \let#3=\pgfmathresult
459 }%
460 \def\pgfplots@BB@for@plotbox{%
461 \ifpgfplots@threedim
462 \pgfpathmoveto{\pgfqpointxyz\pgfplots@plotbox@xmin\pgfplots@plotbox@ymin\pgfplots@plotbox@zmin}%
463 \pgfpathmoveto{\pgfqpointxyz\pgfplots@plotbox@xmin\pgfplots@plotbox@ymin\pgfplots@plotbox@zmax}%
464 \pgfpathmoveto{\pgfqpointxyz\pgfplots@plotbox@xmin\pgfplots@plotbox@ymax\pgfplots@plotbox@zmin}%
465 \pgfpathmoveto{\pgfqpointxyz\pgfplots@plotbox@xmin\pgfplots@plotbox@ymax\pgfplots@plotbox@zmax}%
466 \pgfpathmoveto{\pgfqpointxyz\pgfplots@plotbox@xmax\pgfplots@plotbox@ymin\pgfplots@plotbox@zmin}%
467 \pgfpathmoveto{\pgfqpointxyz\pgfplots@plotbox@xmax\pgfplots@plotbox@ymin\pgfplots@plotbox@zmax}%
468 \pgfpathmoveto{\pgfqpointxyz\pgfplots@plotbox@xmax\pgfplots@plotbox@ymax\pgfplots@plotbox@zmin}%
469 \pgfpathmoveto{\pgfqpointxyz\pgfplots@plotbox@xmax\pgfplots@plotbox@ymax\pgfplots@plotbox@zmax}%
470 \else
471 \pgfpathmoveto{\pgfqpointxy\pgfplots@plotbox@xmin\pgfplots@plotbox@ymin}%
472 \pgfpathmoveto{\pgfqpointxy\pgfplots@plotbox@xmin\pgfplots@plotbox@ymax}%
473 \pgfpathmoveto{\pgfqpointxy\pgfplots@plotbox@xmax\pgfplots@plotbox@ymin}%
474 \pgfpathmoveto{\pgfqpointxy\pgfplots@plotbox@xmax\pgfplots@plotbox@ymax}%
475 \fi
476 }%
477
478
479
480 % Returns width and height of the current plot box
481 % (the path produced by \pgfplots@BB@for@plotbox).
482 %
483 % PRECONDITION: \pgfplots@BB@for@plotbox is defined to produce a path
484 % for the plot box
485 %
486 % POSTCONDITION: \pgfplotsretval contains the with and
487 % \pgfplotsretvalb contains the height
488 \def\pgfplots@get@dimension@of@BB{%
489 \begingroup
490 \pgfinterruptboundingbox
491 %
492 % the result of this call will be used to scale to target
493 % dimensions. If we omit \pgftransformreset here, we might
494 % accidentally UNDO the PGF transformation matrix (compare by
495 % writing \tikzpicture[scale=0.5] before the axis).
496 \pgftransformreset
497 %
498 % STEP 1: compute the bounding box for the plot box.
499 \pgfplots@BB@for@plotbox
500 %
501 % TMPa = width
502 \pgf@xa=\pgf@pathmaxx
503 \advance\pgf@xa by-\pgf@pathminx
504 % TMPb = height
505 \pgf@xb=\pgf@pathmaxy
506 \advance\pgf@xb by-\pgf@pathminy
507 \xdef\pgfplots@glob@TMPa{%
508 \def\noexpand\pgfplotsretval{\the\pgf@xa}%
509 \def\noexpand\pgfplotsretvalb{\the\pgf@xb}%
510 }%
511 \pgfusepath{discard}%
512 \endpgfinterruptboundingbox
513 \endgroup
514 \pgfplots@glob@TMPa
515 }%
516
517 \def\pgfplots@scaleaxes@to@BB@prepare@plotbox@limits{%
518 \def\b@pgfplots@rescale@x{1}%
519 \def\b@pgfplots@rescale@y{1}%
520 \def\b@pgfplots@rescale@z{1}%
521 %
522 \pgfplots@scaleaxes@to@BB@prepare@plotbox@limits@ x%
523 \pgfplots@scaleaxes@to@BB@prepare@plotbox@limits@ y%
524 \pgfplots@scaleaxes@to@BB@prepare@plotbox@limits@ z%
525 }%
526
527 \def\pgfplots@scaleaxes@to@BB@prepare@plotbox@limits@#1{%
528 \expandafter\ifx\csname pgfplots@#1\endcsname\pgfutil@empty
529 % Ah - we have no unit vector in this direction.
530 \expandafter\def\csname pgfplots@plotbox@#1min\endcsname{0}%
531 \expandafter\def\csname pgfplots@plotbox@#1max\endcsname{1}%
532 \expandafter\def\csname b@pgfplots@plotbox@#1isunit\endcsname{1}%
533 \else
534 % we have a unit vector... prepare for limits. Note that the
535 % unit vector has been prepared for data scaling already.
536 \pgfutil@namelet{pgfplots@plotbox@#1min}{pgfplots@#1min}%
537 \pgfutil@namelet{pgfplots@plotbox@#1max}{pgfplots@#1max}%
538 \expandafter\def\csname b@pgfplots@plotbox@#1isunit\endcsname{0}%
539 \if2\pgfplots@scale@mode@choice
540 % scale mode=stretch to fill
541 % do NOT rescale unit vectors for stretch to fill :
542 \expandafter\def\csname b@pgfplots@rescale@#1\endcsname{0}%
543 \fi
544 \fi
545 \expandafter\def\csname b@pgfplots@unitvec@is@zero@#1\endcsname{0}%
546 \ifdim\csname pgf@#1x\endcsname=0pt %
547 \ifdim\csname pgf@#1y\endcsname=0pt %
548 \expandafter\def\csname b@pgfplots@unitvec@is@zero@#1\endcsname{1}%
549 \fi
550 \fi
551 }
552
553
554 \def\pgfplots@scaleaxes@to@BB@#1#2{%
555 \begingroup
556 %\message{SCALING: scale mode choice = \pgfplots@scale@mode@choice^^J}%
557 %
558 \pgfplots@scaleaxes@to@BB@prepare@plotbox@limits
559 \def\pgfplots@target@limitrescale@x{1}%
560 \def\pgfplots@target@limitrescale@y{1}%
561 \def\pgfplots@target@limitrescale@z{1}%
562 \if1\pgfplots@scale@mode@choice
563 % scale mode=none
564 \def\xscale{1}%
565 \def\yscale{1}%
566 \def\pgfplots@target@unit@scale@inv@x{1}%
567 \def\pgfplots@target@unit@scale@inv@y{1}%
568 \def\pgfplots@target@unit@scale@inv@z{1}%
569 \else
570 %
571 % This here CAN cause anisotropic (different) scaling factors.
572 \pgfplots@BB@for@plotbox@get@unit@scales@for@limits
573 {\pgfplots@target@unit@scale@inv@x}
574 {\pgfplots@target@unit@scale@inv@y}
575 {\pgfplots@target@unit@scale@inv@z}%
576 %
577 %\message{got scales to fit limits into BB: x=1/\pgfplots@target@unit@scale@inv@x, y=1/\pgfplots@target@unit@scale@inv@y, z=1/\pgfplots@target@unit@scale@inv@z^^J}%
578 %
579 \if3\pgfplots@scale@mode@choice
580 % scale mode=scale uniformly
581 %
582 % We need to recompensate in case the previous method chose
583 % different unit scaling scalings:
584 \pgfplots@BB@for@plotbox@get@unit@scales@compensated@axis@limits
585 {\pgfplots@target@unit@scale@inv@x}
586 {\pgfplots@target@unit@scale@inv@y}
587 {\pgfplots@target@unit@scale@inv@z}
588 {\pgfplots@target@limitrescale@x}{\pgfplots@target@limitrescale@y}{\pgfplots@target@limitrescale@z}%
589 %
590 %\pgfplots@BB@update@cumulative@limit@compensations
591 \fi
592 %\message{adjusted scales for 'scale mode': x=1/\pgfplots@target@unit@scale@inv@x, y=1/\pgfplots@target@unit@scale@inv@y, z=1/\pgfplots@target@unit@scale@inv@z; ^^J axis limit componsation scales x=\pgfplots@target@limitrescale@x, y=\pgfplots@target@limitrescale@y, z=\pgfplots@target@limitrescale@z^^J}%
593 %
594 % ATTENTION: this MODIFIES \pgfplots@target@limitrescale@x and its
595 % variants directly - and it needs the input values.
596 \pgfplots@get@scale@horiz@and@vert
597 {#1}%
598 {#2}%
599 {\xscale}%
600 {\yscale}% yscale
601 {\pgfplots@target@limitrescale@x}%
602 {\pgfplots@target@limitrescale@y}%
603 {\pgfplots@target@limitrescale@z}%
604 %\message{Got W/H scale for all x components: \xscale; for all y components: \xscale; ^^J axis limit componsation scales x=1/\pgfplots@target@limitrescale@x, y=1/\pgfplots@target@limitrescale@y, z=1/\pgfplots@target@limitrescale@z^^J}%
605 % Ok, we know the W,H scalings now.
606 %
607 %
608 %
609 \pgfplots@apply@unit@ratio
610 {\pgfplots@target@unit@scale@inv@x}
611 {\pgfplots@target@unit@scale@inv@y}
612 {\pgfplots@target@unit@scale@inv@z}
613 {\pgfplots@target@limitrescale@x@}{\pgfplots@target@limitrescale@y@}{\pgfplots@target@limitrescale@z@}%
614 \pgfplots@BB@update@cumulative@limit@compensations
615 %
616 %\message{adjusted scales for 'unit vector ratio': x=1/\pgfplots@target@unit@scale@inv@x, y=1/\pgfplots@target@unit@scale@inv@y, z=1/\pgfplots@target@unit@scale@inv@z; ^^J axis limit componsation scales x=\pgfplots@target@limitrescale@x, y=\pgfplots@target@limitrescale@y, z=\pgfplots@target@limitrescale@z^^J}%
617 \fi
618 %
619 %
620 \pgfplots@scaling@minimize@limitrescale%
621 %
622 %
623 \pgfplots@scaling@adjust@datascaling%
624 %\message{adjusted scales for data scale trafo: x=1/\pgfplots@target@unit@scale@inv@x, y=1/\pgfplots@target@unit@scale@inv@y, z=1/\pgfplots@target@unit@scale@inv@z; ^^J axis limit componsation scales x=\pgfplots@target@limitrescale@x, y=\pgfplots@target@limitrescale@y, z=\pgfplots@target@limitrescale@z;^^J data scale trafo exponents x=\pgfplots@target@datascaletrafo@x@exponent@old -> \pgfplots@target@datascaletrafo@x@exponent, y=\pgfplots@target@datascaletrafo@y@exponent@old -> \pgfplots@target@datascaletrafo@y@exponent, z=\pgfplots@target@datascaletrafo@z@exponent@old -> \pgfplots@target@datascaletrafo@z@exponent^^J}%
625 %
626 \pgfplots@scaling@compute@final@scales%
627 {\xscale}{\yscale}%
628 {\pgfplots@target@unit@scale@inv@x}%
629 {\pgfplots@target@unit@scale@inv@y}%
630 {\pgfplots@target@unit@scale@inv@z}%
631 %
632 \pgfplots@axis@apply@post@scale{x}%
633 \pgfplots@axis@apply@post@scale{y}%
634 \ifpgfplots@threedim
635 \pgfplots@axis@apply@post@scale{z}%
636 \fi
637 %
638 % and finally, resize limits appropriately and add all cumulative limit compensations:
639 \xdef\pgfplots@glob@TMPa{%
640 %
641 \pgf@xx=\pgfplots@target@unit@scale@xx\pgf@xx
642 \pgf@xy=\pgfplots@target@unit@scale@xy\pgf@xy
643 %
644 \pgf@yx=\pgfplots@target@unit@scale@yx\pgf@yx
645 \pgf@yy=\pgfplots@target@unit@scale@yy\pgf@yy
646 %
647 \ifpgfplots@threedim
648 \pgf@zx=\pgfplots@target@unit@scale@zx\pgf@zx
649 \pgf@zy=\pgfplots@target@unit@scale@zy\pgf@zy
650 \fi
651 %
652 \noexpand\pgfplots@apply@datascaletrafo@change@{x}{\pgfplots@target@datascaletrafo@x@exponent}%
653 \noexpand\pgfplots@apply@datascaletrafo@change@{y}{\pgfplots@target@datascaletrafo@y@exponent}%
654 \noexpand\pgfplots@apply@datascaletrafo@change@{z}{\pgfplots@target@datascaletrafo@z@exponent}%
655 %
656 \noexpand\pgfplots@apply@unit@vector@rescale@keep@size{x}{\pgfplots@target@limitrescale@x}%
657 \noexpand\pgfplots@apply@unit@vector@rescale@keep@size{y}{\pgfplots@target@limitrescale@y}%
658 \noexpand\pgfplots@apply@unit@vector@rescale@keep@size{z}{\pgfplots@target@limitrescale@z}%
659 %
660 \noexpand\pgfplots@notify@final@scalings{%
661 x unit scale=\pgfplots@target@unit@scale@x,%
662 y unit scale=\pgfplots@target@unit@scale@y,%
663 z unit scale=\pgfplots@target@unit@scale@z,%
664 x datatrafo exponent=\pgfplots@target@datascaletrafo@x@exponent,%
665 y datatrafo exponent=\pgfplots@target@datascaletrafo@y@exponent,%
666 z datatrafo exponent=\pgfplots@target@datascaletrafo@z@exponent,%
667 x limit rescale=\pgfplots@target@limitrescale@x,%
668 y limit rescale=\pgfplots@target@limitrescale@y,%
669 z limit rescale=\pgfplots@target@limitrescale@z,%
670 }%
671 }%
672 \endgroup
673 \pgfplots@glob@TMPa
674 }%
675
676 % Checks for the case the ALL (visible) limit compensation scales are
677 % bigger than one (for example x = 1.22, y = 2). In such a case, we
678 % want to MINIMIZE the rescaling. This can happen if unit vector ratio
679 % is active.
680 %
681 % In our example, we want to use limit rescaling factors x = 1, y = 2/1.22
682 % and, consequently, unit rescaling factors x *= 1.22, y *= 1.22 .
683 %
684 % This method checks for the case and applies the rescaling if
685 % necessary.
686 %
687 \def\pgfplots@scaling@minimize@limitrescale{%
688 % boolean allLimitScalesAreBiggerThanOne;
689 \pgfplots@loc@tmptrue
690 \if0\b@pgfplots@unitvec@is@zero@x
691 \ifdim\pgfplots@target@limitrescale@x pt<1.002pt %
692 \pgfplots@loc@tmpfalse
693 \fi
694 \fi
695 \if0\b@pgfplots@unitvec@is@zero@y
696 \ifdim\pgfplots@target@limitrescale@y pt<1.002pt %
697 \pgfplots@loc@tmpfalse
698 \fi
699 \fi
700 \if0\b@pgfplots@unitvec@is@zero@z
701 \ifdim\pgfplots@target@limitrescale@z pt<1.002pt %
702 \pgfplots@loc@tmpfalse
703 \fi
704 \fi
705 %
706 \ifpgfplots@loc@tmp
707 \begingroup
708 % Ah -- all non-vanishing limit rescaling factors are BIGGER
709 % THAN ONE.
710 % In this case, we can save some rescalings!
711 %
712 % Search for the smallest rescaling factor.
713 \let\pgfplots@smallest=\pgf@x
714 \pgfplots@smallest=16000pt %
715 \def\pgfplots@smallest@arg{}%
716 \if0\b@pgfplots@unitvec@is@zero@x
717 \pgf@xa=\pgfplots@target@limitrescale@x pt %
718 \ifdim\pgf@xa<\pgfplots@smallest%
719 \pgfplots@smallest=\pgf@xa
720 \def\pgfplots@smallest@arg{x}%
721 \fi
722 \fi
723 \if0\b@pgfplots@unitvec@is@zero@y
724 \pgf@xa=\pgfplots@target@limitrescale@y pt %
725 \ifdim\pgf@xa<\pgfplots@smallest%
726 \pgfplots@smallest=\pgf@xa
727 \def\pgfplots@smallest@arg{y}%
728 \fi
729 \fi
730 \if0\b@pgfplots@unitvec@is@zero@z
731 \pgf@xa=\pgfplots@target@limitrescale@z pt %
732 \ifdim\pgf@xa<\pgfplots@smallest%
733 \pgfplots@smallest=\pgf@xa
734 \def\pgfplots@smallest@arg{z}%
735 \fi
736 \fi
737 %
738 % OK. We have the smallest scaling factor. It is > 1.
739 \pgfplotscoordmath{default}{parsenumber}{\pgfplots@target@limitrescale@x}%
740 \let\pgfplots@target@limitrescale@x=\pgfmathresult
741 \pgfplotscoordmath{default}{parsenumber}{\pgfplots@target@limitrescale@y}%
742 \let\pgfplots@target@limitrescale@y=\pgfmathresult
743 %
744 %
745 \pgfplotscoordmath{default}{parsenumber}{\pgfplots@target@unit@scale@inv@x}%
746 \let\pgfplots@target@unit@scale@inv@x=\pgfmathresult
747 \pgfplotscoordmath{default}{parsenumber}{\pgfplots@target@unit@scale@inv@y}%
748 \let\pgfplots@target@unit@scale@inv@y=\pgfmathresult
749 %
750 \if0\b@pgfplots@unitvec@is@zero@z
751 \pgfplotscoordmath{default}{parsenumber}{\pgfplots@target@limitrescale@z}%
752 \let\pgfplots@target@limitrescale@z=\pgfmathresult
753 \pgfplotscoordmath{default}{parsenumber}{\pgfplots@target@unit@scale@inv@z}%
754 \let\pgfplots@target@unit@scale@inv@z=\pgfmathresult
755 \fi
756 %
757 \pgfplotscoordmath{default}{op}{reciprocal}{{\csname pgfplots@target@limitrescale@\pgfplots@smallest@arg\endcsname}}%
758 \let\scale=\pgfmathresult
759 %
760 \pgfplotsforeachentryinCSV\value{%
761 \pgfplots@target@unit@scale@inv@x,%
762 \pgfplots@target@unit@scale@inv@y,%
763 \pgfplots@target@limitrescale@x,%
764 \pgfplots@target@limitrescale@y%
765 }{%
766 \pgfplotscoordmath{default}{op}{multiply}{{\scale}{\value}}%
767 \pgfplotscoordmath{default}{tofixed}{\pgfmathresult}%
768 \expandafter\let\value=\pgfmathresult
769 }%
770 \if0\b@pgfplots@unitvec@is@zero@z
771 \pgfplotsforeachentryinCSV\value{%
772 \pgfplots@target@unit@scale@inv@z,%
773 \pgfplots@target@limitrescale@z%
774 }{%
775 \pgfplotscoordmath{default}{op}{multiply}{{\scale}{\value}}%
776 \pgfplotscoordmath{default}{tofixed}{\pgfmathresult}%
777 \expandafter\let\value=\pgfmathresult
778 }%
779 \fi
780 %
781 \xdef\pgfplots@glob@TMPa{%
782 \noexpand\def\noexpand\pgfplots@target@unit@scale@inv@x{\pgfplots@target@unit@scale@inv@x}%
783 \noexpand\def\noexpand\pgfplots@target@unit@scale@inv@y{\pgfplots@target@unit@scale@inv@y}%
784 \noexpand\def\noexpand\pgfplots@target@unit@scale@inv@z{\pgfplots@target@unit@scale@inv@z}%
785 \noexpand\def\noexpand\pgfplots@target@limitrescale@x{\pgfplots@target@limitrescale@x}%
786 \noexpand\def\noexpand\pgfplots@target@limitrescale@y{\pgfplots@target@limitrescale@y}%
787 \noexpand\def\noexpand\pgfplots@target@limitrescale@z{\pgfplots@target@limitrescale@z}%
788 }%
789 \endgroup
790 \pgfplots@glob@TMPa
791 %
792 %\message{adjusted scales by minimizing common scaling factors: x=1/\pgfplots@target@unit@scale@inv@x, y=1/\pgfplots@target@unit@scale@inv@y, z=1/\pgfplots@target@unit@scale@inv@z; ^^J axis limit componsation scales x=\pgfplots@target@limitrescale@x, y=\pgfplots@target@limitrescale@y, z=\pgfplots@target@limitrescale@z;^^J}%
793 \fi
794 }%
795
796 % Defines
797 % \pgfplots@target@unit@scale@xx
798 % \pgfplots@target@unit@scale@xy
799 % \pgfplots@target@unit@scale@yx
800 % \pgfplots@target@unit@scale@yy
801 % \pgfplots@target@unit@scale@zx
802 % \pgfplots@target@unit@scale@zy
803 % %
804 % \pgfplots@target@unit@scale@x
805 % \pgfplots@target@unit@scale@y
806 % \pgfplots@target@unit@scale@z
807 % by combining the input args.
808 %
809 % #1: the scale to be applied to ALL x components
810 % #2: the scale to be applied to ALL y components
811 % #3: the scale to be applied to x unit
812 % #4: the scale to be applied to y unit
813 % #5: the scale to be applied to z unit
814 \def\pgfplots@scaling@compute@final@scales#1#2#3#4#5{%
815 % ##1: the axis (x,y,or z)
816 % ##2: the horizontal scale
817 % ##3: the vertical scale
818 % ##4: the inverse unit scale for this axis
819 \def\pgfplots@loc@TMPa##1##2##3##4{%
820 \pgfplotscoordmath{\pgfplots@compat@scaling@coordmath}{parsenumber}{##2}%
821 \let\xscale@@=\pgfmathresult
822 \pgfplotscoordmath{\pgfplots@compat@scaling@coordmath}{parsenumber}{##3}%
823 \let\yscale@@=\pgfmathresult
824 \pgfplotscoordmath{\pgfplots@compat@scaling@coordmath}{parsenumber}{##4}%
825 \let\unitscale@inv@@=\pgfmathresult
826 %
827 % NOTE : it *would* be more efficient to use
828 % 1/\unitscale@inv@@ in the routines above. BUT THAT IS NOT BACKWARDS COMPATIBLE.
829 % Leave it this way!
830 \pgfplotscoordmath{\pgfplots@compat@scaling@coordmath}{op}{reciprocal}{{\unitscale@inv@@}}%
831 \let\unitscale@@=\pgfmathresult
832 \pgfplotscoordmath{\pgfplots@compat@scaling@coordmath}{tofixed}{\pgfmathresult}%
833 \expandafter\let\csname pgfplots@target@unit@scale@##1\endcsname=\pgfmathresult
834 %
835 %
836 \ifx\pgfplots@compat@scaling@coordmath@final\pgfplots@compat@scaling@coordmath
837 \else
838 % backwards compatibility is such a burden.... :-(
839 %
840 % earlier versions relied on TeX's dimen arithmetics to
841 % multiply the final scales. Make sure we do the same -
842 % rounding errors on unit vectors are instable, i.e. the
843 % errors add up considerably.
844 \pgfplotscoordmath{\pgfplots@compat@scaling@coordmath@final}{parsenumber}{\xscale@@}%
845 \let\xscale@@=\pgfmathresult
846 \pgfplotscoordmath{\pgfplots@compat@scaling@coordmath@final}{parsenumber}{\yscale@@}%
847 \let\yscale@@=\pgfmathresult
848 \pgfplotscoordmath{\pgfplots@compat@scaling@coordmath@final}{parsenumber}{\unitscale@@}%
849 \let\unitscale@@=\pgfmathresult
850 \pgfplotscoordmath{\pgfplots@compat@scaling@coordmath@final}{parsenumber}{\unitscale@inv@@}%
851 \let\unitscale@inv@@=\pgfmathresult
852 \fi
853 %
854 \ifpgfplots@threedim
855 % backw. compatibility: this is how it used to be in 3d
856 % axes:
857 \pgfplotscoordmath{\pgfplots@compat@scaling@coordmath@final}{op}{multiply}{{\xscale@@}{\unitscale@@}}%
858 \pgfplotscoordmath{\pgfplots@compat@scaling@coordmath@final}{tofixed}{\pgfmathresult}%
859 \expandafter\let\csname pgfplots@target@unit@scale@##1x\endcsname=\pgfmathresult
860 %
861 \pgfplotscoordmath{\pgfplots@compat@scaling@coordmath@final}{op}{multiply}{{\yscale@@}{\unitscale@@}}%
862 \pgfplotscoordmath{\pgfplots@compat@scaling@coordmath@final}{tofixed}{\pgfmathresult}%
863 \expandafter\let\csname pgfplots@target@unit@scale@##1y\endcsname=\pgfmathresult
864 \else
865 % backw. compatibility: 2d axes used divide in earlier
866 % versions, not reciprocal. Believe it or not; for
867 % \pgfplots@compat@scaling@coordmath=pgfbasic, it makes a
868 % visible difference of about 2-3pt in the complete figure
869 % size.
870 \pgfplotscoordmath{\pgfplots@compat@scaling@coordmath@final}{op}{divide}{{\xscale@@}{\unitscale@inv@@}}%
871 \pgfplotscoordmath{\pgfplots@compat@scaling@coordmath@final}{tofixed}{\pgfmathresult}%
872 \expandafter\let\csname pgfplots@target@unit@scale@##1x\endcsname=\pgfmathresult
873 %
874 \pgfplotscoordmath{\pgfplots@compat@scaling@coordmath@final}{op}{divide}{{\yscale@@}{\unitscale@inv@@}}%
875 \pgfplotscoordmath{\pgfplots@compat@scaling@coordmath@final}{tofixed}{\pgfmathresult}%
876 \expandafter\let\csname pgfplots@target@unit@scale@##1y\endcsname=\pgfmathresult
877 \fi
878 %
879 }%
880 \if1\b@pgfplots@rescale@x
881 \pgfplots@loc@TMPa{x}{\xscale}{\yscale}{#3}%
882 \else
883 \pgfplots@loc@TMPa{x}{1}{1}{#3}%
884 \fi
885 %
886 \if1\b@pgfplots@rescale@y
887 \pgfplots@loc@TMPa{y}{\xscale}{\yscale}{#4}%
888 \else
889 \pgfplots@loc@TMPa{y}{1}{1}{#4}%
890 \fi
891 %
892 \ifpgfplots@threedim
893 \if1\b@pgfplots@rescale@z
894 \pgfplots@loc@TMPa{z}{\xscale}{\yscale}{#5}%
895 \else
896 \pgfplots@loc@TMPa{z}{1}{1}{#5}%
897 \fi
898 \else
899 \def\pgfplots@target@unit@scale@z{0}%
900 \def\pgfplots@target@unit@scale@zx{0}%
901 \def\pgfplots@target@unit@scale@zy{0}%
902 \def\pgfplots@target@unit@scale@inv@z{inf}%
903 \fi
904 %
905 }%
906
907 \def\pgfplots@notify@final@scalings#1{%
908 \pgfkeys{/pgfplots/scaling/.cd,
909 .unknown/.code={%
910 %\message{setting key '\pgfkeyscurrentkey' to {##1}^^J}
911 \pgfkeyssetvalue{\pgfkeyscurrentkey}{##1}%
912 },
913 #1%
914 }%
915 }%
916
917 % #1: either x,y, or z
918 % #2: the new exponent
919 \def\pgfplots@apply@datascaletrafo@change@#1#2{%
920 \pgfplots@if{pgfplots@apply@datatrafo@#1}{%
921 \pgfplotscoordmath{#1}{datascaletrafo get params}%
922 \edef\pgfplots@loc@TMPa{\expandafter\pgfutil@firstoftwo\pgfmathresult}%
923 \edef\pgfplots@loc@TMPb{#2}%
924 \ifx\pgfplots@loc@TMPa\pgfplots@loc@TMPb
925 % ok; the data scale trafo did not change at all - we
926 % still have the same exponent.
927 \else
928 % Ah - we have a new data scale trafo!
929 \pgfplotscoordmath{#1}{datascaletrafo inverse}{\csname pgfplots@#1min\endcsname}%
930 \let\pgfplots@loc@TMPa=\pgfmathresult
931 \pgfplotscoordmath{#1}{datascaletrafo inverse}{\csname pgfplots@#1max\endcsname}%
932 \let\pgfplots@loc@TMPb=\pgfmathresult
933 %
934 % first: determine the optimal shift (which is the
935 % transformed lower limit):
936 \pgfplotscoordmath{#1}{datascaletrafo set params}{#2}{0}%
937 \pgfplotscoordmath{#1}{datascaletrafo}{\pgfplots@loc@TMPa}%
938 %
939 % ok, finalize the data trafo:
940 \pgfplotscoordmath{#1}{datascaletrafo set params}{#2}{\pgfmathresult}%
941 %
942 % ... and recompute axis limits:
943 \pgfplotscoordmath{#1}{datascaletrafo}{\pgfplots@loc@TMPa}%
944 \expandafter\let\csname pgfplots@#1min\endcsname=\pgfmathresult
945 \pgfplotscoordmath{#1}{datascaletrafo}{\pgfplots@loc@TMPb}%
946 \expandafter\let\csname pgfplots@#1max\endcsname=\pgfmathresult
947 \fi
948 }{}%
949 }%
950
951 % Inspects the limit enlargement factors and reinitializes the data
952 % scale transformations.
953 %
954 % The purpose of this method is to avoid "dimension too large" if the
955 % factors exceed certain limits.
956 %
957 % INPUT:
958 % \pgfplots@target@limitrescale@x and its variants for y and z
959 % \pgfplots@target@unit@scale@inv@x and its variants for y and z
960 %
961 % OUTPUT:
962 % \pgfplots@target@datascaletrafo@x@exponent and its variants for y and z
963 % -> contains NEW datascaletrafo exponents
964 % \pgfplots@target@datascaletrafo@x@exponent@old and its variants for y and z
965 % -> contains OLD datascaletrafo exponents
966 % \pgfplots@target@unit@scale@inv@x and its variants for y and z
967 % -> contains (modified) unit vector scales
968 \def\pgfplots@scaling@adjust@datascaling{%
969 \pgfplots@scaling@adjust@datascaling@for x%
970 \pgfplots@scaling@adjust@datascaling@for y%
971 \pgfplots@scaling@adjust@datascaling@for z%
972 }
973 \def\pgfplots@scaling@adjust@datascaling@for#1{%
974 \pgfplots@if{pgfplots@apply@datatrafo@#1}{%
975 \pgfplotscoordmath{#1}{datascaletrafo get params}%
976 \def\pgfplots@loc@TMPa##1##2{%
977 \expandafter\def\csname pgfplots@target@datascaletrafo@#1@exponent\endcsname{##1}%
978 \expandafter\def\csname pgfplots@target@datascaletrafo@#1@exponent@old\endcsname{##1}%
979 }%
980 \expandafter\pgfplots@loc@TMPa\pgfmathresult
981 \pgf@xa=\csname pgfplots@target@limitrescale@#1\endcsname pt
982 \ifdim\pgf@xa>5pt %
983 % We want to enlarge axis limits considerably!
984 %
985 \pgfplots@scaling@adjust@datascaling@for@get@compensation{\pgf@xa}%
986 %
987 % Ok, make sure that we do not get "dimension too large"
988 % by adjusting the data scale trafo.
989 %
990 % Note that the data scale trafo has (only) been applied
991 % to axis limits, so we have to reapply it before these
992 % changes can take effect:
993 \pgf@xa=\csname pgfplots@target@unit@scale@inv@#1\endcsname pt
994 \divide\pgf@xa by\pgfplotsretval\relax %
995 \expandafter\edef\csname pgfplots@target@unit@scale@inv@#1\endcsname{\pgf@sys@tonumber\pgf@xa}%
996 %
997 \c@pgf@countd=\csname pgfplots@target@datascaletrafo@#1@exponent\endcsname\relax
998 \advance\c@pgf@countd by-\pgfplotsretvalb\relax %
999 \expandafter\edef\csname pgfplots@target@datascaletrafo@#1@exponent\endcsname{\the\c@pgf@countd}%
1000 \fi
1001 }{%
1002 \expandafter\def\csname pgfplots@target@datascaletrafo@#1@exponent\endcsname{0}%
1003 \expandafter\def\csname pgfplots@target@datascaletrafo@#1@exponent@old\endcsname{0}%
1004 }%
1005 }
1006
1007 % Returns
1008 % \pgfplotsretval -> the absolute scaling
1009 % \pgfplotsretvalb -> the log10 of the scaling
1010 \def\pgfplots@scaling@adjust@datascaling@for@get@compensation#1{
1011 \ifdim#1<100pt %
1012 \def\pgfplotsretval{10}%
1013 \def\pgfplotsretvalb{1}%
1014 \else
1015 \ifdim#1<1000pt %
1016 \def\pgfplotsretval{100}%
1017 \def\pgfplotsretvalb{2}%
1018 \else
1019 \ifdim#1<10000pt %
1020 \def\pgfplotsretval{1000}%
1021 \def\pgfplotsretvalb{3}%
1022 \else
1023 % too much for this approach anyway... and probably no
1024 % use-case at all.
1025 \def\pgfplotsretval{1000}%
1026 \def\pgfplotsretvalb{3}%
1027 \fi
1028 \fi
1029 \fi
1030 }%
1031
1032 % Computes the initial scale from a plot box of unit size to the
1033 % desired with and height.
1034 %
1035 % #1 the desired width
1036 % #2 the desired height
1037 % #3 [output] a macro which will contain the horizontal (x) scale
1038 % #4 [output] a macro which will contain the vertical (y) scale
1039 % #5 [input/output] a macro which, on input, contains the x axis limit compensation scale
1040 % which is required to select a single unit vector scale without
1041 % reducing the plots dimension (without actually respecting the
1042 % final dimension). On output, the input has been multiplied by
1043 % some additional x limit componensation scale (selected by scale
1044 % uniformly strategy).
1045 % #6 [input/output] a macro which will contain a y axis limit
1046 % compensation scale; it works in the same way as #5
1047 % #7 [input/output] a macro which will contain a z axis limit
1048 % compensation scale; it works in the same way as #5
1049 \def\pgfplots@get@scale@horiz@and@vert#1#2#3#4#5#6#7{%
1050 \begingroup
1051 \edef\pgfplots@target@limitrescale@x{#5}%
1052 \edef\pgfplots@target@limitrescale@y{#6}%
1053 \edef\pgfplots@target@limitrescale@z{#7}%
1054 \pgfplots@get@dimension@of@BB
1055 \pgf@xa=\pgfplotsretval\relax
1056 \pgf@xb=\pgfplotsretvalb\relax
1057 \pgf@ya=#1\relax
1058 \pgf@yb=#2\relax
1059 \edef\w{\pgf@sys@tonumber\pgf@xa}%
1060 \edef\h{\pgf@sys@tonumber\pgf@xb}%
1061 \edef\W{\pgf@sys@tonumber\pgf@ya}%
1062 \edef\H{\pgf@sys@tonumber\pgf@yb}%
1063 %\message{PGFPLOTS: the current unit vectors result in a UNIT BB of (\the\pgf@xa,\the\pgf@xb). Scaling it to (\the\pgf@ya,\the\pgf@yb)...^^J}%
1064 \ifcase\pgfplots@scale@mode@choice
1065 % scale mode=auto does not happen here
1066 \or
1067 % scale mode=none does not happen here
1068 \or
1069 % scale mode=stretch to fill
1070 %
1071 % This is very simple:
1072 %
1073 % Compute individual scaling factors for X and Y
1074 % such that the UNIT-BB will have size #1,#2. Keep limits.
1075 \pgfmathdivide@{\W}{\w}%
1076 \let\scalex=\pgfmathresult
1077 %
1078 \pgfmathdivide@{\H}{\h}%
1079 \let\scaley=\pgfmathresult
1080 %
1081 % no changes to the axis limits - we only rescale units.
1082 \def\pgfplots@target@limitrescale@x@{1}%
1083 \def\pgfplots@target@limitrescale@y@{1}%
1084 \def\pgfplots@target@limitrescale@z@{1}%
1085 \pgfplots@BB@update@cumulative@limit@compensations
1086 \or
1087 % scale mode=scale uniformly
1088 % compute ONE common scale for both, X and Y - and satisfy
1089 % width/height constraints by adjusting the axis limits.
1090 %
1091 % The idea is as follows:
1092 % we WANT to have width W and height H.
1093 % The constraint is that each unit vector must get the same
1094 % scale -- but the axis limits can receive individual
1095 % compensation scales. But it should "look reasonable well".
1096 %
1097 % currently, we have
1098 % w = r_x e_xx + r_y e_yx + rz e_zx (with e_zx = 0 typically)
1099 % h = r_x e_xy + r_y e_yy + rz e_zy
1100 %
1101 % where r_x, r_y, r_z are the maximal range of the data in
1102 % x,y,z respectively. Depending on the context of this method,
1103 % they are either 1 (relative coords) or
1104 % (xmax-xmin) (absolute coords).
1105 %
1106 % Now, search for a set of real numbers
1107 % Rx, Ry, Rz, s
1108 % such that
1109 % W = (Rx r_x) (s e_xx) + (Ry r_y) (s e_yx) + (Rz r_z) (s e_zx)
1110 % H = (Rx r_x) (s e_xy) + (Ry r_y) (s e_yy) + (Rz r_z) (s e_zy)
1111 %
1112 % clearly, the solution is not unique.
1113 % ONE choice is to employ the fact that e_zx = 0 (or, for 2d
1114 % plots, e_zx=0, e_zy=0 and e_yx=0):
1115 %
1116 % in that case, we can compute s such that the equation for W
1117 % is satisfied and compensate only the limit r_z, i.e. to
1118 % choose
1119 % s := W / w, (scale to satisfy width constraint)
1120 % Rx := Ry := 1 (keep limits in X and Y)
1121 % Rz = ( H - s (w - r_z e_zy) ) / (s r_z e_zy) (adjust z limit to satisfy height constraint)
1122 %
1123 % This approach works well if W < H . If W > H, it will look
1124 % bad: Rz will be less than 1, causing the limit to become
1125 % smaller. This, in turn, will clip away parts of the image.
1126 %
1127 %
1128 %
1129 % Another solution is to make it the other way: to keep the
1130 % limit r_z, but to reduce the size and enlarge the other
1131 % limits to satisfy the size constraints. This solution is
1132 % considerably more involved; it requires to solve a nonlinear
1133 % set of equations.
1134 %
1135 % Formally, this second solution uses
1136 % Rz := 1 (no limit componensation scale for z -- keep z limit)
1137 % R:= Rx := Ry (same limit componensation scale for both X and Y)
1138 % R and s still need to be determined from the two equations for W
1139 % and H.
1140 %
1141 % Substituting the given choices into the equations for W and H, we find
1142 %
1143 % R = W / (s w)
1144 %
1145 % s = H * (R * (h-r_z e_zy) + r_z e_zy)^-1
1146 %
1147 % Here, we employed the definition of 'h', see above. The
1148 % equations are non-linear.
1149 %
1150 % ATTENTION: we assume that the datascaletrafo set params
1151 % method has been called with THE SAME SCALE IN EACH
1152 % DIRECTION.
1153 \if0\pgfplots@scaleuniformly@choice
1154 % scale uniformly strategy=auto
1155 \pgfplots@get@scale@horiz@and@vert@scaleuniformly@of@optimal@strategy
1156 \else
1157 \pgfplots@get@scale@horiz@and@vert@scaleuniformly
1158 \pgfplots@BB@update@cumulative@limit@compensations
1159 \fi
1160 \fi
1161 %
1162 \xdef\pgfplots@glob@TMPa{%
1163 \noexpand\def\noexpand#3{\scalex}%
1164 \noexpand\def\noexpand#4{\scaley}%
1165 \noexpand\def\noexpand#5{\pgfplots@target@limitrescale@x}%
1166 \noexpand\def\noexpand#6{\pgfplots@target@limitrescale@y}%
1167 \noexpand\def\noexpand#7{\pgfplots@target@limitrescale@z}%
1168 }%
1169 \endgroup
1170 \pgfplots@glob@TMPa
1171 }%
1172
1173 % This is the implementation for 'scale uniformly strategy=auto'.
1174 %
1175 % It works by finding the strategy which involves the minimal scaling
1176 % overhead.
1177 %
1178 % To this end, it computes the result for each 'scale uniformly
1179 % strategy', and computes a cost function. The one with optimal cost
1180 % function wins, and its results are returned.
1181 %
1182 % The cost function is the overall scaling which is applied to AXIS
1183 % LIMITS. It works as follows:
1184 % 1. if a choice requires to REDUCE the axis limits in order to
1185 % fulfill all constraints, it is neglected (using maximal cost 16000).
1186 % Reducing axis limits may clip away information.
1187 %
1188 % 2. if a choice requires to ENLARGE some axis limits, its cost is the
1189 % sum of the individual scaling factors (even if they are are one -
1190 % who cares).
1191 %
1192 % Note that this method *is* relevant and the optimization appears to
1193 % be necessary.
1194 % Examples are
1195 % unittest_scalemode_2d_standard_1.tex
1196 % and perhaps
1197 % unittest_scalemode_2d_standard_0.tex
1198 % and more involved 3d examples are also available.
1199 %
1200 % My first guess was that it is sufficient to decide the optimal
1201 % strategy in advance by comparing the target width and the target
1202 % height - but that proved to be insufficient: it leads to correct
1203 % results, but wastes too much space (i.e. enlarges limits too much).
1204 %
1205 % ATTENTION: the cost function INCLUDES RESULTS OF
1206 % \pgfplots@BB@for@plotbox@get@unit@scales@for@limits and its
1207 % corrector
1208 % \pgfplots@BB@for@plotbox@get@unit@scales@compensated@axis@limits.
1209 %
1210 % More precisely, it relies on already computes limit compensation
1211 % factors which do not depend on the target width/target height: both
1212 % \pgfplots@BB@for@plotbox@get@unit@scales@compensated@axis@limits and
1213 % this implementation of 'scale uniformly strategy' can be used to compute
1214 % the cost of a strategy.
1215 %
1216 \def\pgfplots@get@scale@horiz@and@vert@scaleuniformly@of@optimal@strategy{%
1217 \begingroup
1218 \def\mathclass{default}%
1219 \pgfplotscoordmath{\mathclass}{max limit}%
1220 \let\pgfplots@cost@for@choice@superhigh=\pgfmathresult%
1221 %
1222 % private helpers to compute the cost.
1223 \def\pgfplots@scalestrategy@compute@cost{%
1224 \begingroup
1225 % ATTENTION: this call changes
1226 % '\pgfplots@target@limitrescale@x' and its variants.
1227 % Restore its value after the iteration:
1228 \pgfplots@BB@update@cumulative@limit@compensations
1229 \pgfplotscoordmath{\mathclass}{one}%
1230 \let\ONE=\pgfmathresult
1231 \pgfplotscoordmath{\mathclass}{parsenumber}{\pgfplots@target@limitrescale@x}%
1232 \let\X=\pgfmathresult
1233 \pgfplotscoordmath{\mathclass}{parsenumber}{\pgfplots@target@limitrescale@y}%
1234 \let\Y=\pgfmathresult
1235 \ifpgfplots@threedim
1236 \pgfplotscoordmath{\mathclass}{parsenumber}{\pgfplots@target@limitrescale@z}%
1237 \let\Z=\pgfmathresult
1238 \else
1239 \let\Z=\pgfplots@target@limitrescale@z
1240 \fi
1241 %
1242 % If one of the resulting limit compensation scales is
1243 % less than 1, we can immediately skip it - we do not want
1244 % to risk to clip away image content.
1245 \pgfplotscoordmath{\mathclass}{if less than}{\X}{\ONE}{%
1246 \let\pgfplots@cost@for@choice=\pgfplots@cost@for@choice@superhigh
1247 }{%
1248 \pgfplotscoordmath{\mathclass}{if less than}{\Y}{\ONE}{%
1249 \let\pgfplots@cost@for@choice=\pgfplots@cost@for@choice@superhigh
1250 }{%
1251 \ifpgfplots@threedim
1252 \pgfplotscoordmath{\mathclass}{if less than}{\Z}{\ONE}{%
1253 \let\pgfplots@cost@for@choice=\pgfplots@cost@for@choice@superhigh
1254 }{%
1255 % ah - 3 limit scales >= 1. Good, assign cost:
1256 \pgfplots@scalestrategy@compute@cost@
1257 }%
1258 \else
1259 % ah - all limit scales >=1. Good, assign cost:
1260 \pgfplots@scalestrategy@compute@cost@
1261 \fi
1262 }%
1263 }%
1264 %\message{scale uniformly strategy=auto: '\pgfplots@tostring@scaleuniformlystrategy{\pgfplots@scaleuniformly@choice}' has cost \pgfplots@cost@for@choice\space(limit rescaling factors x=\X, y=\Y, z=\Z)^^J}%
1265 \xdef\pgfplots@glob@TMPa{%
1266 \noexpand\def\noexpand\pgfplots@scaleuniformly@choice{\pgfplots@scaleuniformly@choice}%
1267 \noexpand\def\noexpand\scalex{\scalex}%
1268 \noexpand\def\noexpand\scaley{\scaley}%
1269 \noexpand\def\noexpand\pgfplots@target@limitrescale@x{\pgfplots@target@limitrescale@x}%
1270 \noexpand\def\noexpand\pgfplots@target@limitrescale@y{\pgfplots@target@limitrescale@y}%
1271 \noexpand\def\noexpand\pgfplots@target@limitrescale@z{\pgfplots@target@limitrescale@z}%
1272 }%
1273 \pgfmath@smuggleone\pgfplots@cost@for@choice
1274 % keep in mind that this scope IS NECESSARY: we have
1275 % changed the target quantities
1276 % \pgfplots@target@limitrescale@x and its variants!
1277 \endgroup
1278 \let\pgfplots@scalestrategy@values=\pgfplots@glob@TMPa
1279 }%
1280 \def\pgfplots@scalestrategy@compute@cost@{%
1281 \pgfplotscoordmath{\mathclass}{op}{add}{{\X}{\Y}}%
1282 \ifpgfplots@threedim
1283 \pgfplotscoordmath{\mathclass}{op}{add}{{\pgfmathresult}{\Z}}%
1284 \fi
1285 \let\pgfplots@cost@for@choice=\pgfmathresult
1286 }%
1287 %
1288 % compute initial cost:
1289 \def\pgfplots@scaleuniformly@choice{3}% change horizontal limits
1290 \pgfplots@get@scale@horiz@and@vert@scaleuniformly
1291 \pgfplots@scalestrategy@compute@cost
1292 %
1293 % init minimum:
1294 \let\pgfplots@cost@for@choice@arg=\pgfplots@scalestrategy@values
1295 \let\pgfplots@cost@for@choice@sofar=\pgfplots@cost@for@choice%
1296 %
1297 % compute cost of next strategy:
1298 \def\pgfplots@scaleuniformly@choice{2}% change vertical limits
1299 \pgfplots@get@scale@horiz@and@vert@scaleuniformly
1300 \pgfplots@scalestrategy@compute@cost
1301 %
1302 % update minimum:
1303 \pgfplotscoordmath{\mathclass}{if less than}{\pgfplots@cost@for@choice}{\pgfplots@cost@for@choice@sofar}{%
1304 \let\pgfplots@cost@for@choice@arg=\pgfplots@scalestrategy@values
1305 \let\pgfplots@cost@for@choice@sofar=\pgfplots@cost@for@choice%
1306 }{%
1307 }%
1308 %
1309 \ifx\pgfplots@cost@for@choice@sofar\pgfplots@cost@for@choice@superhigh
1310 % the algorithm discarded every available strategy.
1311 \def\pgfplots@scaleuniformly@choice{1}% fall back to 'units only'
1312 \pgfplots@get@scale@horiz@and@vert@scaleuniformly
1313 \pgfplots@scalestrategy@compute@cost
1314 \let\pgfplots@cost@for@choice@arg=\pgfplots@scalestrategy@values
1315 \let\pgfplots@cost@for@choice@sofar=\pgfplots@cost@for@choice%
1316 \fi
1317 %
1318 %
1319 \global\let\pgfplots@glob@TMPa=\pgfplots@cost@for@choice@arg
1320 \endgroup
1321 \pgfplots@glob@TMPa
1322 %\message{scale uniformly strategy=auto: choosing '\pgfplots@tostring@scaleuniformlystrategy{\pgfplots@scaleuniformly@choice}'^^J}%
1323 }
1324
1325 \def\pgfplots@tostring@scaleuniformlystrategy#1{%
1326 % scale uniformly strategy:
1327 \ifcase#1\relax
1328 auto
1329 \or
1330 units only
1331 \or
1332 change vertical limits
1333 \or
1334 change horizontal limits
1335 \fi
1336 }
1337 % Does the work for 'scale mode=scale uniformly' inside of
1338 % \pgfplots@get@scale@horiz@and@vert.
1339 %
1340 % It returns its result into \pgfplots@target@limitrescale@x@ (i.e.
1341 % with an extra '@')
1342 \def\pgfplots@get@scale@horiz@and@vert@scaleuniformly{%
1343 \ifcase\pgfplots@scaleuniformly@choice\relax
1344 % scale uniformly strategy=auto does not happen here.
1345 \or
1346 % scale uniformly strategy=units only
1347 \pgfplots@scaleuniformly@onlyunits
1348 \or
1349 % scale uniformly strategy=change vertical limits
1350 %
1351 % first, scale to the width ...
1352 \pgfplots@scaleuniformly@onlyunits@{\w}{\W}%
1353 % ... and change (only) vertical limits to get the "correct"
1354 % height:
1355 \ifdim\pgf@zy=0pt
1356 \ifdim\pgf@yx=0pt
1357 \pgfplots@prepare@vertical@rescaling@for@scale@uniformly@in@dir{y}\returninto\pgfplots@target@limitrescale@y@
1358 \else
1359 \pgfplots@scale@uniformly@fallback
1360 \fi
1361 \else
1362 \ifdim\pgf@zx=0pt
1363 \pgfplots@prepare@vertical@rescaling@for@scale@uniformly@in@dir{z}\returninto\pgfplots@target@limitrescale@z@
1364 \else
1365 \pgfplots@scale@uniformly@fallback
1366 \fi
1367 \fi
1368 \or
1369 % scale uniformly strategy=change horizontal limits
1370 \ifdim\pgf@zy=0pt
1371 \ifdim\pgf@yx=0pt
1372 \ifdim\pgf@xy=0pt
1373 % special 2d routine with explicit solution
1374 \pgfplots@scaleuniformly@change@horizontal@limits@twodim
1375 {\scalex}
1376 {\pgfplots@target@limitrescale@x@}
1377 {\pgfplots@target@limitrescale@y@}
1378 {\pgfplots@target@limitrescale@z@}%
1379 \else
1380 \pgfplots@scale@uniformly@fallback
1381 \fi
1382 \else
1383 \pgfplots@scale@uniformly@fallback
1384 \fi
1385 \else
1386 \ifdim\pgf@zx=0pt
1387 \pgfplots@scaleuniformly@change@horizontal@limits
1388 {\scalex}
1389 {\pgfplots@target@limitrescale@x@}
1390 {\pgfplots@target@limitrescale@y@}
1391 {\pgfplots@target@limitrescale@z@}%
1392 \else
1393 \pgfplots@scale@uniformly@fallback
1394 \fi
1395 \fi
1396 \let\scaley=\scalex
1397 \fi
1398 }
1399
1400 \def\pgfplots@scaleuniformly@onlyunits{%
1401 % scale to the smaller target dimension:
1402 \ifdim\W pt<\H pt %
1403 \pgfplots@scaleuniformly@onlyunits@{\w}{\W}%
1404 \else
1405 \pgfplots@scaleuniformly@onlyunits@{\h}{\H}%
1406 \fi
1407 }%
1408
1409 % #1 : the actual dimension
1410 % #2 : the target dimension
1411 \def\pgfplots@scaleuniformly@onlyunits@#1#2{%
1412 \def\pgfplots@target@limitrescale@x@{1}%
1413 \def\pgfplots@target@limitrescale@y@{1}%
1414 \def\pgfplots@target@limitrescale@z@{1}%
1415 \pgfmathdivide@{#2}{#1}%
1416 \let\scalex=\pgfmathresult
1417 \let\scaley=\scalex % we *need* the same unit scale.
1418 }%
1419
1420 % Computes 'scale uniformly strategy=change horizontal limits'.
1421 % This is a complicated solution, see the documentation in the
1422 % implementation for
1423 % 'scale mode=scale uniformly'
1424 %
1425 % #1 [output] a macro which will contain the (uniform) scale for the
1426 % unit vectors
1427 % #2 [output] a macro which will contain a x axis limit compensation scale
1428 % #3 [output] a macro which will contain a x axis limit compensation scale
1429 % #4 [output] a macro which will contain a x axis limit compensation scale
1430 \def\pgfplots@scaleuniformly@change@horizontal@limits#1#2#3#4{%
1431 \begingroup
1432 %
1433 \pgfplots@BB@for@plotbox@getunitheight{\pgf@xc}{z}%
1434 %
1435 % compute the rest in floating point - intermediate results may
1436 % become too huge for TeX.
1437 \pgfplotscoordmath{default}{parsenumber}{\expandafter\pgf@sys@tonumber\csname pgf@xc\endcsname}%
1438 \let\M=\pgfmathresult
1439 %
1440 \pgfplotscoordmath{default}{parsenumber}{\w}%
1441 \let\w=\pgfmathresult
1442 \pgfplotscoordmath{default}{parsenumber}{\W}%
1443 \let\W=\pgfmathresult
1444 \pgfplotscoordmath{default}{parsenumber}{\h}%
1445 \let\h=\pgfmathresult
1446 \pgfplotscoordmath{default}{parsenumber}{\H}%
1447 \let\H=\pgfmathresult
1448 \pgfplotscoordmath{default}{op}{divide}{{\W}{\w}}%
1449 \let\Wwinv=\pgfmathresult
1450 \pgfplotscoordmath{default}{op}{subtract}{{\h}{\M}}%
1451 \let\hminusM=\pgfmathresult
1452 %
1453 \pgfplotscoordmath{default}{one}%
1454 \let\S=\pgfmathresult%
1455 \let\R=\pgfmathresult%
1456 \let\Rx=\pgfmathresult
1457 \def\Rz{1}%
1458 %
1459 \def\pgfplots@hold@S@get@R{%
1460 \pgfplotscoordmath{default}{op}{divide}{{\Wwinv}{\S}}%
1461 \let\R=\pgfmathresult
1462 %\message{updated R = \R\space ( S = \S ) ^^J}%
1463 }%
1464 \def\pgfplots@hold@R@get@S{%
1465 \pgfplotscoordmath{default}{op}{multiply}{{\R}{\hminusM}}%
1466 \pgfplotscoordmath{default}{op}{add}{{\pgfmathresult}{\M}}%
1467 \pgfplotscoordmath{default}{op}{divide}{{\H}{\pgfmathresult}}%
1468 \let\S=\pgfmathresult
1469 %\message{updated S = \S\space ( R = \R ) ^^J}%
1470 }%
1471 %
1472 % This is the (most stupid) nonlinear method which is at hand:
1473 % fix point iteration.
1474 % choose R arbitrarily (R=1 seems adequate), solve for s.
1475 % Then, fix s and solve for R. Then, fix R and
1476 % solve for s until convergence.
1477 \c@pgf@countc=0
1478 \pgfplotsloop{%
1479 \ifnum\c@pgf@countc<\pgfkeysvalueof{/pgfplots/scale uniformly strategy iter} %
1480 \pgfplotsloopcontinuetrue
1481 \else
1482 \pgfplotsloopcontinuefalse
1483 \fi
1484 }{%
1485 \pgfplots@hold@R@get@S \pgfplots@hold@S@get@R
1486 \advance\c@pgf@countc by1 %
1487 }%
1488 %
1489 \pgfplotscoordmath{default}{tofixed}{\R}\let\R=\pgfmathresult
1490 \pgfplotscoordmath{default}{tofixed}{\S}\let\S=\pgfmathresult
1491 \xdef\pgfplots@glob@TMPa{%
1492 \noexpand\def\noexpand#1{\S}%
1493 \noexpand\def\noexpand#2{\R}%
1494 \noexpand\def\noexpand#3{\R}%
1495 \noexpand\def\noexpand#4{\Rz}%
1496 }%
1497 \endgroup
1498 %
1499 \pgfplots@glob@TMPa
1500 }%
1501
1502 % Computes 'scale uniformly strategy=change horizontal limits'.
1503 %
1504 % This is a simplified closed solution assuming that e_xy=0 and e_yx = 0
1505 %
1506 % #1 [output] a macro which will contain the (uniform) scale for the
1507 % unit vectors
1508 % #2 [output] a macro which will contain a x axis limit compensation scale
1509 % #3 [output] a macro which will contain a x axis limit compensation scale
1510 % #4 [output] a macro which will contain a x axis limit compensation scale
1511 \def\pgfplots@scaleuniformly@change@horizontal@limits@twodim#1#2#3#4{%
1512 \begingroup
1513 % Assuming that we have a standard 2d axis, i.e.
1514 % e_zx = e_zy = 0, e_xy = 0, and e_yx =0,
1515 % we can immediately compute a solution.
1516 %
1517 % In this case, we have the actual width
1518 % w = r_x e_xx + r_y e_yx + rz e_zx
1519 % = r_x e_xx
1520 % and actual height
1521 % h = r_x e_xy + r_y e_yy + rz e_zy
1522 % = r_y e_yy
1523 % and, consequently, desired width
1524 % W = (Rx r_x) (s e_xx) + (Ry r_y) (s e_yx) + (Rz r_z) (s e_zx)
1525 % = (Rx r_x) (s e_xx)
1526 % and desired height
1527 % H = (Rx r_x) (s e_xy) + (Ry r_y) (s e_yy) + (Rz r_z) (s e_zy)
1528 % = (Ry r_y) (s e_yy).
1529 % since this strategy changes horizontal limits (only), we have
1530 % Ry := 1.
1531 % We find
1532 % s : = H/h
1533 % and
1534 % Rx : = W/w /s .
1535 %
1536 \pgfplotscoordmath{default}{parsenumber}{\w}%
1537 \let\w=\pgfmathresult
1538 \pgfplotscoordmath{default}{parsenumber}{\W}%
1539 \let\W=\pgfmathresult
1540 \pgfplotscoordmath{default}{parsenumber}{\h}%
1541 \let\h=\pgfmathresult
1542 \pgfplotscoordmath{default}{parsenumber}{\H}%
1543 \let\H=\pgfmathresult
1544 \pgfplotscoordmath{default}{op}{divide}{{\H}{\h}}%
1545 \let\S=\pgfmathresult
1546 \pgfplotscoordmath{default}{op}{divide}{{\W}{\w}}%
1547 \pgfplotscoordmath{default}{op}{divide}{{\pgfmathresult}{\S}}%
1548 \let\Rx=\pgfmathresult
1549 \def\Ry{1}%
1550 \def\Rz{1}%
1551 %
1552 \pgfplotscoordmath{default}{tofixed}{\Rx}\let\Rx=\pgfmathresult
1553 \pgfplotscoordmath{default}{tofixed}{\S}\let\S=\pgfmathresult
1554 \xdef\pgfplots@glob@TMPa{%
1555 \noexpand\def\noexpand#1{\S}%
1556 \noexpand\def\noexpand#2{\Rx}%
1557 \noexpand\def\noexpand#3{\Ry}%
1558 \noexpand\def\noexpand#4{\Rz}%
1559 }%
1560 \endgroup
1561 %
1562 \pgfplots@glob@TMPa
1563 }%
1564
1565 \def\pgfplots@BB@update@cumulative@limit@compensations{%
1566 %\message{ -> additional limit componensation scales x=\pgfplots@target@limitrescale@x@, y=\pgfplots@target@limitrescale@y@, z=\pgfplots@target@limitrescale@z@^^J}%
1567 % add limit compensation to what we have from earlier
1568 % operations:
1569 \pgfplotscoordmath{pgfbasic}{op}{multiply}{{\pgfplots@target@limitrescale@x@}{\pgfplots@target@limitrescale@x}}%
1570 \let\pgfplots@target@limitrescale@x=\pgfmathresult
1571 \pgfplotscoordmath{pgfbasic}{op}{multiply}{{\pgfplots@target@limitrescale@y@}{\pgfplots@target@limitrescale@y}}%
1572 \let\pgfplots@target@limitrescale@y=\pgfmathresult
1573 \pgfplotscoordmath{pgfbasic}{op}{multiply}{{\pgfplots@target@limitrescale@z@}{\pgfplots@target@limitrescale@z}}%
1574 \let\pgfplots@target@limitrescale@z=\pgfmathresult
1575 }%
1576
1577 \def\pgfplots@scale@uniformly@fallback{%
1578 \ifpgfplots@scaleuniformly@warning
1579 \pgfplotswarning{scale uniformly unsupported}\pgfeov%
1580 \fi
1581 \pgfplots@scaleuniformly@onlyunits
1582 }%
1583
1584 % This is part of the implementation of 'scale mode=scale uniformly'.
1585 %
1586 % Its purpose it to set up the initial scaling such that
1587 % 1. each unit vector gets the same scale
1588 % 2. the axis limits are resized (enlarged) to keep the plot box ratio
1589 % (as far as possible)
1590 %
1591 % It repairs the outcome of
1592 % \pgfplots@BB@for@plotbox@get@unit@scales@for@limits .
1593 %
1594 % The assumption is that on input #1, #2, and #3 are the factors which
1595 % would be used by stretch-to-fill in order to squeze the axis limits
1596 % into the plot box defined by e_x, e_y, and e_z (the unit vectors).
1597 %
1598 % On output, #1, #2, and #3 will be modified such that *each has the
1599 % same value*. The value will be chosen with care. More precisely, it
1600 % is the *minimum* of {#1,#2,#3}.
1601 %
1602 % Clearly, 'scale mode=scale uniformly' has less freedom than
1603 % strech-to-fill. In order to keep the plot box ratio intact (as far
1604 % as possible), the axis limits will be rescaled to componsate for the
1605 % ignored scaling factors. More precisely, if direction i is not the
1606 % extremal value (as discussed in the last paragraph), the axis limits
1607 % will be rescaled by #i/extremum .
1608 %
1609 %
1610 %
1611 % #1: on input, it contains the x unit scale which would be taken without the
1612 % compensation. On output, it contains the x unit scale which *will* be
1613 % used.
1614 % #2: same as #1, but for y
1615 % #3: same as #1, but for z
1616 % #4: [output] a scale for use as argument of \pgfplots@apply@unit@vector@rescale@keep@size{x}{<arg>}
1617 % #5: [output] a scale for use as argument of \pgfplots@apply@unit@vector@rescale@keep@size{y}{<arg>}
1618 % #6: [output] a scale for use as argument of \pgfplots@apply@unit@vector@rescale@keep@size{z}{<arg>}
1619 %
1620 % The output arguments need to be applied before they take effect.
1621 \def\pgfplots@BB@for@plotbox@get@unit@scales@compensated@axis@limits#1#2#3#4#5#6{%
1622 \begingroup
1623 % ATTENTION : this code ASSUMES that the datascaling trafo is
1624 % initialized with THE SAME SCALE IN EACH DIRECTION.
1625 % The data scaling also leads to (potentially non-uniform) scaling per component.
1626 %
1627 % Note that we could handle the datascaling here -- but we would
1628 % leave the supported number range easily. That's why that part of
1629 % the 'scale mode=scale uniformly' implementation has been moved
1630 % to \pgfplots@set@optimal@datatrafos@allaxes
1631 %
1632 % This here handles the limits only.
1633 \edef\pgfplots@scale@unitx{#1}%
1634 \edef\pgfplots@scale@unity{#2}%
1635 \edef\pgfplots@scale@unitz{#3}%
1636 %
1637 % compute extreme + arg extreme of these scales:
1638 \def\pgfplots@extreme@scale{-16300}%
1639 \def\pgfplots@extreme@scale@arg{NONE}%
1640 %
1641 \if0\b@pgfplots@unitvec@is@zero@x
1642 \ifdim\pgfplots@extreme@scale pt<\pgfplots@scale@unitx pt
1643 \let\pgfplots@extreme@scale=\pgfplots@scale@unitx
1644 \def\pgfplots@extreme@scale@arg{x}%
1645 \fi
1646 \fi
1647 \if0\b@pgfplots@unitvec@is@zero@y
1648 \ifdim\pgfplots@extreme@scale pt<\pgfplots@scale@unity pt
1649 \let\pgfplots@extreme@scale=\pgfplots@scale@unity
1650 \def\pgfplots@extreme@scale@arg{y}%
1651 \fi
1652 \fi
1653 \if0\b@pgfplots@unitvec@is@zero@z
1654 \ifdim\pgfplots@extreme@scale pt<\pgfplots@scale@unitz pt
1655 \let\pgfplots@extreme@scale=\pgfplots@scale@unitz
1656 \def\pgfplots@extreme@scale@arg{z}%
1657 \fi
1658 \fi
1659 %
1660 % Now, adjust axis limits to compensate for the effect: we still
1661 % want to have a plot box which is as close as possible to the
1662 % target plot box.
1663 \def\pgfplots@loc@TMPa##1##2{%
1664 \if0\csname b@pgfplots@unitvec@is@zero@##1\endcsname
1665 \if1\pgfplots@scaleuniformly@choice % FIXME : this appears to be too much. Disable this!?
1666 % ok, nothing to do for this direction.
1667 \pgfplotscoordmath{pgfbasic}{one}%
1668 \let##2=\pgfmathresult
1669 \else
1670 \if\pgfplots@extreme@scale@arg ##1%
1671 % ok, nothing to do for this direction.
1672 \pgfplotscoordmath{pgfbasic}{one}%
1673 \let##2=\pgfmathresult
1674 \else
1675 \pgfplotscoordmath{pgfbasic}{op}{divide}{{\pgfplots@extreme@scale}{\csname pgfplots@scale@unit##1\endcsname}}%
1676 % do not call apply@unit@rescale immediately because the
1677 % unit vectors may not be in their final state. Postpone until
1678 % they are final.
1679 \edef##2{\pgfmathresult}%
1680 \fi
1681 \fi
1682 \else
1683 \def##2{1}%
1684 \fi
1685 }%
1686 \pgfplots@loc@TMPa{x}{#4}%
1687 \pgfplots@loc@TMPa{y}{#5}%
1688 \pgfplots@loc@TMPa{z}{#6}%
1689 %
1690 \toks0=\expandafter{#4}%
1691 \toks1=\expandafter{#5}%
1692 \toks2=\expandafter{#6}%
1693 \xdef\pgfplots@glob@TMPa{%
1694 % same scale in each dir:
1695 \def\noexpand#1{\pgfplots@extreme@scale}%
1696 \def\noexpand#2{\pgfplots@extreme@scale}%
1697 \def\noexpand#3{\pgfplots@extreme@scale}%
1698 \def\noexpand#4{\the\toks0}%
1699 \def\noexpand#5{\the\toks1}%
1700 \def\noexpand#6{\the\toks2}%
1701 }%
1702 \endgroup
1703 \pgfplots@glob@TMPa
1704 }
1705
1706 % #1 : a dimen register
1707 % #2 : x, y, or z
1708 \def\pgfplots@BB@for@plotbox@getunitheight#1#2{%
1709 #1=\csname pgfplots@plotbox@#2max\endcsname\csname pgf@#2y\endcsname
1710 \advance#1 by -\csname pgfplots@plotbox@#2min\endcsname\csname pgf@#2y\endcsname
1711 \ifdim#1<0pt %
1712 % we want to return a height. It is also bigger than 0.
1713 % the difference above may be negative if the unit points
1714 % downward (special combinations of view/h and view/v)
1715 #1=-#1\relax
1716 \fi
1717 }%
1718
1719
1720 % Modifies the AXIS LIMITS to ensure that a suitable width/height is
1721 % achieved.
1722 %
1723 % This does NOT introduce a further scale to the unit vectors.
1724 %
1725 % #1: a direction (x,y, or z)
1726 % #2: a macro name. It will be assigned globally. It will contain
1727 % EXECUTABLE instructions which will modify the axis limits to fit the
1728 % scaling.
1729 %
1730 % PRECONDITION:
1731 % - \pgfplots@glob@TMPa contains the already computed
1732 % scaling factor for 'scale uniformly'
1733 % - \pgf@xb is the actual height and \pgf@yb is the desired height
1734 % (set as in the scaling routine)
1735 %
1736 % POSTCONDITION:
1737 % #2 will contain the argument <arg> for \pgfplots@apply@unit@vector@rescale@keep@size{#1}{<arg>}
1738 \def\pgfplots@prepare@vertical@rescaling@for@scale@uniformly@in@dir#1\returninto#2{%
1739 % The strategy is as follows:
1740 % 1. I want to fit the axis into width #1 (\pgf@ya) and
1741 % height #1 (\pgf@yb).
1742 % 2. I want to MAINTAIN the unit vector ratio.
1743 % 3. I want to MAINTAIN the unit vector directions.
1744 %
1745 % I already know the scaling factor to fit the width (it
1746 % is stored in \scalex = \scaley).
1747 % Let's call it "s".
1748 %
1749 % Consequently, a uniform scaling by "s" leads to the image
1750 % height
1751 % h = s* (r_x * e_xy + r_y * e_yy + r_z * e_zy)
1752 % where r_i = (imax - imin). This here is essentially the
1753 % same as the bounding box computation above (at least for
1754 % standard orthographic 3D axes).
1755 %
1756 % What I want now is to enlarge the limits such that I
1757 % have BOTH, width #1 AND height #2, without obscuring the
1758 % unit vector ratio. Recall that width #1 is already
1759 % given.
1760 %
1761 % This strategy achieves this goal by
1762 % modifying axis limits for an axis whose unit vector is
1763 % parallel to the canvas y axis, i.e. e_i = (0,*).
1764 %
1765 % That means I have to introduce a SECOND scale s_z which
1766 % applies only to the Z unit vector (since e_z = (0,*) ).
1767 % If H = #2 is the desired height, I find the target
1768 % equation for s_z,
1769 %
1770 % H = s* r_x e_xy + s * r_y e_yy + s_z * s * r_z * e_zy
1771 % =>
1772 % s_z = ( H- s*r_x e_xy - s*r_y e_yy) / ( s * r_z * e_zy).
1773 %
1774 % Remember that
1775 % s = \scalex
1776 % H = \H
1777 % h = r_x * e_xy + r_y * e_yy + r_z * e_zy = \h
1778 % =>
1779 % s_z = ( H- s*( h - r_z * e_zy) ) / ( s * r_z * e_zy).
1780 %
1781 \begingroup
1782 \pgfplots@BB@for@plotbox@getunitheight{\pgf@xc}{#1}%
1783 %
1784 % compute the rest in floating point - intermediate results may
1785 % become too huge for TeX.
1786 \pgfplotscoordmath{default}{parsenumber}{\expandafter\pgf@sys@tonumber\csname pgf@xc\endcsname}%
1787 \let\pgfplots@diff=\pgfmathresult
1788 %
1789 \pgfplotscoordmath{default}{parsenumber}{\scalex}%
1790 \let\pgfplots@s=\pgfmathresult
1791 %
1792 % this is a precondition of this method:
1793 \pgfplotscoordmath{default}{parsenumber}{\h}%
1794 \let\h=\pgfmathresult
1795 \pgfplotscoordmath{default}{parsenumber}{\H}%
1796 \let\H=\pgfmathresult
1797 %
1798 % compute counter := H - s * (h - (max-min))
1799 \pgfplotscoordmath{default}{op}{subtract}{{\h}{\pgfplots@diff}}%
1800 \pgfplotscoordmath{default}{op}{multiply}{{\pgfplots@s}{\pgfmathresult}}%
1801 \pgfplotscoordmath{default}{op}{subtract}{{\H}{\pgfmathresult}}%
1802 \let\pgfplots@counter=\pgfmathresult
1803 %
1804 % computer denom := s * (max-min)
1805 \pgfplotscoordmath{default}{op}{multiply}{{\pgfplots@s}{\pgfplots@diff}}%
1806 \let\pgfplots@denom=\pgfmathresult
1807 %
1808 \pgfplotscoordmath{default}{op}{divide}{{\pgfplots@counter}{\pgfplots@denom}}%
1809 \pgfplotscoordmath{default}{tofixed}{\pgfmathresult}%
1810 %
1811 % Now, s_z = \pgfmathresult .
1812 %
1813 % Now, adjust the z limits.
1814 % Note that \pgfplots@apply@unit@vector@rescale@keep@size
1815 % has a slightly different context; it assumes that the
1816 % unit vector has been rescaled, not the axis limits.
1817 % Consequently, the inverse of the scaling factor enters.
1818 % Since \pgfplots@apply@unit@vector@rescale@keep@size
1819 % expects the inverse of the scale, we can provide
1820 % \pgfmathresult:
1821 \pgfmath@smuggleone\pgfmathresult
1822 \endgroup
1823 \let#2=\pgfmathresult
1824 }
1825
1826 \def\pgfplots@computeunitvectorlengths{%
1827 \pgfplotsutil@edef@invoke\pgfmathveclen@{%
1828 {\pgf@sys@tonumber\pgf@xx}%
1829 {\pgf@sys@tonumber\pgf@xy}%
1830 }%
1831 \let\pgfplots@x@veclength=\pgfmathresult
1832 \pgfplotsmath@ifzero{\pgfplots@x@veclength}{%
1833 \def\pgfmathresult{infty}%
1834 % this case will be caught in \pgfplots@initsizes
1835 }{%
1836 \expandafter\pgfmath@basic@reciprocal@\expandafter{\pgfmathresult}%
1837 }%
1838 \let\pgfplots@x@inverseveclength=\pgfmathresult
1839 %
1840 \pgfplotsutil@edef@invoke\pgfmathveclen@{%
1841 {\pgf@sys@tonumber\pgf@yx}%
1842 {\pgf@sys@tonumber\pgf@yy}%
1843 }%
1844 \let\pgfplots@y@veclength=\pgfmathresult
1845 \pgfplotsmath@ifzero{\pgfplots@y@veclength}{%
1846 \def\pgfmathresult{infty}%
1847 % this case will be caught in \pgfplots@initsizes
1848 }{%
1849 \expandafter\pgfmath@basic@reciprocal@\expandafter{\pgfmathresult}%
1850 }%
1851 \let\pgfplots@y@inverseveclength=\pgfmathresult
1852 %
1853 \ifpgfplots@threedim
1854 \pgfplotsutil@edef@invoke\pgfmathveclen@{%
1855 {\pgf@sys@tonumber\pgf@zx}%
1856 {\pgf@sys@tonumber\pgf@zy}%
1857 }%
1858 \let\pgfplots@z@veclength=\pgfmathresult
1859 \pgfplotsmath@ifzero{\pgfplots@z@veclength}{%
1860 \def\pgfmathresult{infty}%
1861 % this case will be caught in \pgfplots@initsizes
1862 }{%
1863 \expandafter\pgfmath@basic@reciprocal@\expandafter{\pgfmathresult}%
1864 }%
1865 \let\pgfplots@z@inverseveclength=\pgfmathresult
1866 \else
1867 \def\pgfplots@z@veclength{0}%
1868 \def\pgfplots@z@inverseveclength{infty}%
1869 \fi
1870 }%
1871
1872 % Defines \pgfplots@view@dir@threedim according to the actual
1873 % configuration of x,y,z (2d) unit vectors, assuming the associated
1874 % unit vectors form a right-handed-system.
1875 %
1876 % The algorithm works for standard three dimensional axes. It works as
1877 % follows:
1878 %
1879 % First, observe that we have a normal direction N if all its
1880 % multiples are mapped onto the same point in 2D canvas
1881 % coordinates. In other words: all 3D coordinates which are mapped
1882 % onto an arbitrary point in 2D canvas coordinates (take, for example,
1883 % the origin (0,0) ) are on a line in direction of N.
1884 %
1885 % We use this observation to compute the normal axis, i.e. we search
1886 % for all points which are mapped onto the 2D canvas coordinate (0,0):
1887 % N_x e_xx + N_y e_yx + N_z e_zx = 0
1888 % N_x e_xy + N_y e_yy + N_z e_zy = 0.
1889 % All solutions make up a linear space of dimension 1 (up to special
1890 % cases). In the general case, we can chose an arbitrary N_z != 0
1891 % and reduce the linear system to
1892 % N_x e_xx + N_y e_yx = - N_z e_zx
1893 % N_x e_xy + N_y e_yy = - N_z e_zy.
1894 % Choosing *any* N_z != 0, say, N_z=-1 (which corresponds to view
1895 % from above) will lead to a vector parallel to the normal direction.
1896 % But it might have the wrong sign.
1897 %
1898 % FIXME : this fails if one of e_x or e_y is zero.
1899 %
1900 % To find the correct sign for N, I have made several case
1901 % distinctions to identify the cases when we have to multiply with -1.
1902 % The key idea is to assume a right-handed-system of unit vectors;
1903 % this is the condition which allows to determine the sign.
1904 %
1905 % Furthermore, I assume that e_z points to the top, i.e. that e_zy >0.
1906 % Then, there are (mainly) four conditions on the signs of e_x and e_y
1907 % which indicate that we are viewing from below and should switch the
1908 % sign of N (keep in mind that our initial choice was N_z =-1, see above).
1909 %
1910 % The conditions can be identified by drawing a 3D box and
1911 % identifying the corner which represents the lower left 3D limits.
1912 %
1913 % You can visualize these cases using
1914 %--------------------------------------------------
1915 % \pgfplotsset{
1916 % separate axis lines,
1917 % every outer x axis line/.append style= {-stealth},
1918 % every outer y axis line/.append style= {-stealth},
1919 % every outer z axis line/.append style= {-stealth},
1920 % samples=2,shader=interp,title={view=\h,\v},
1921 % domain=0:1,
1922 % enlargelimits=false,
1923 % view=\h\v,xlabel=x,ylabel=y,
1924 % extra description/.code={%
1925 % \node[draw,fill=white] at (axis cs:0,0,0) {};
1926 % },
1927 % }
1928 %
1929 % \def\v{30}
1930 % \foreach \h in {30,120,210,300} {
1931 % \message{VIEW={\h}{\v}^^J}
1932 % \begin{tikzpicture}
1933 % \begin{axis}
1934 % \addplot3[surf] {x};
1935 % \end{axis}
1936 % \end{tikzpicture}
1937 %
1938 % }
1939 %
1940 % \def\v{-30}
1941 % \foreach \h in {30,120,210,300} {
1942 % \message{VIEW={\h}{\v}^^J}
1943 % \begin{tikzpicture}
1944 % \begin{axis}
1945 % \addplot3[surf] {x};
1946 % \end{axis}
1947 % \end{tikzpicture}
1948 %
1949 % }
1950 %--------------------------------------------------
1951 % The precise formulas can be found below in the source code.
1952 %
1953 % You can override this function by the /pgfplots/view dir key.
1954 \def\pgfplotsgetnormalforcurrentview{%
1955 \pgfkeysgetvalue{/pgfplots/view dir}\pgfplots@loc@TMPc
1956 \ifx\pgfplots@loc@TMPc\pgfutil@empty
1957 \begingroup
1958 % temporarily undo the effects of reversed axes -- we *really*
1959 % need a right-handed-coordinate system here:
1960 \if r\pgfkeysvalueof{/pgfplots/x dir/value}%
1961 \pgf@xx=-\pgf@xx
1962 \pgf@xy=-\pgf@xy
1963 \fi
1964 \if r\pgfkeysvalueof{/pgfplots/y dir/value}%
1965 \pgf@yx=-\pgf@yx
1966 \pgf@yy=-\pgf@yy
1967 \fi
1968 \if r\pgfkeysvalueof{/pgfplots/z dir/value}%
1969 \pgf@zx=-\pgf@zx
1970 \pgf@zy=-\pgf@zy
1971 \fi
1972 % FIRST: check for special cases.
1973 \let\pgfplots@view@dir@threedim=\pgfutil@empty%
1974 % Special case:
1975 % e_xx = e_xy = 0
1976 %
1977 % i.e.:
1978 %
1979 % ^
1980 % | |---|
1981 % z | |
1982 % |---|
1983 % y->
1984 %
1985 % In this case, N must be the x axis.
1986 \ifdim\pgf@xx=0pt %
1987 \ifdim\pgf@xy=0pt %
1988 \def\pgfplots@view@dir@threedim{-1,0,0}%
1989 \fi
1990 \fi
1991 % Special case:
1992 % e_yx = e_yy = 0
1993 %
1994 % i.e.:
1995 %
1996 % ^
1997 % | |---|
1998 % z | |
1999 % |---|
2000 % x->
2001 %
2002 % In this case, N must be the y axis.
2003 \ifdim\pgf@yx=0pt %
2004 \ifdim\pgf@yy=0pt %
2005 \def\pgfplots@view@dir@threedim{0,1,0}%
2006 \fi
2007 \fi
2008 % Special case:
2009 % e_xy = e_yy = 0 (i.e. one row)
2010 %
2011 % that is hard to draw, use view={30}{0} to see it.
2012 %
2013 % In this case, N_z must be 0 and we have a different system.
2014 \ifdim\pgf@xy=0pt %
2015 \ifdim\pgf@yy=0pt %
2016 \ifx\pgfplots@view@dir@threedim\pgfutil@empty
2017 % we have N_x e_xx + N_y e_yx = 0
2018 % Note that e_xx != 0 and e_yx != 0 (otherwise one
2019 % of our other special cases above would have
2020 % caught the case)
2021 % -> we have N_x = -N_y e_yx / e_xx and N_y
2022 % arbitrary. only the sign needs to be fixed.
2023 \def\pgfplots@view@dir@threedim@z{0}%
2024 \def\pgfplots@view@dir@threedim@y{1}% fix it somehow. We correct the sign later.
2025 \edef\pgfplots@loc@TMPa{-(\pgfplots@view@dir@threedim@y) * \pgf@sys@tonumber\pgf@yx / (\pgf@sys@tonumber\pgf@xx)}%
2026 \pgfmathparse{\pgfplots@loc@TMPa}%
2027 \let\pgfplots@view@dir@threedim@x=\pgfmathresult
2028 %
2029 \def\pgfplots@scale{1}%
2030 % I identified these cases by comparing the
2031 % results with \pgfplots@scale{1} with those of
2032 % the view dir generated by
2033 % \pgfplotssetaxesfromazel (which has the correct quality of solution)
2034 \ifdim\pgf@zy>0pt %
2035 \ifdim\pgf@xx<0pt %
2036 \def\pgfplots@scale{-1}%
2037 \fi
2038 \else
2039 \ifdim\pgf@xx>0pt %
2040 \def\pgfplots@scale{-1}%
2041 \fi
2042 \fi
2043 \pgfmathmultiply@{\pgfplots@scale}{\pgfplots@view@dir@threedim@x}%
2044 \let\pgfplots@view@dir@threedim@x\pgfmathresult
2045 \pgfmathmultiply@{\pgfplots@scale}{\pgfplots@view@dir@threedim@y}%
2046 \let\pgfplots@view@dir@threedim@y\pgfmathresult
2047 \pgfmathmultiply@{\pgfplots@scale}{\pgfplots@view@dir@threedim@z}%
2048 \let\pgfplots@view@dir@threedim@z\pgfmathresult
2049 %
2050 \edef\pgfplots@view@dir@threedim{\pgfplots@view@dir@threedim@x,\pgfplots@view@dir@threedim@y,\pgfplots@view@dir@threedim@z}%
2051 \else
2052 % Ah - we already caught that special case above.
2053 \fi
2054 \fi
2055 \fi
2056 %
2057 % NOTE : the case e_xx = e_yx = 0 IS NO USE-CASE (would
2058 % require a rotated z axis which is forbidden currently)
2059 %
2060 \ifx\pgfplots@view@dir@threedim\pgfutil@empty
2061 \def\pgfplots@view@dir@threedim@z{-1}% hold it at some arbitrary value
2062 \pgf@xa=-\pgfplots@view@dir@threedim@z\pgf@zx
2063 \pgf@ya=-\pgfplots@view@dir@threedim@z\pgf@zy
2064 \edef\pgfplots@loc@TMPa{%
2065 {%
2066 {\pgf@sys@tonumber\pgf@xx}{\pgf@sys@tonumber\pgf@yx}%
2067 {\pgf@sys@tonumber\pgf@xy}{\pgf@sys@tonumber\pgf@yy}%
2068 }%
2069 {%
2070 {\pgf@sys@tonumber\pgf@xa}{\pgf@sys@tonumber\pgf@ya}%
2071 }%
2072 }%
2073 \expandafter\pgfutilsolvetwotwoleq\pgfplots@loc@TMPa
2074 \ifx\pgfmathresult\pgfutil@empty
2075 \pgfplots@error{Singular matrix encountered during view computation. Please choose different input values.}%
2076 \def\pgfmathresult{{0}{0}}%
2077 \fi
2078 \def\pgfplots@loc@TMPb##1##2{%
2079 \def\pgfplots@view@dir@threedim@x{##1}%
2080 \def\pgfplots@view@dir@threedim@y{##2}%
2081 }%
2082 \expandafter\pgfplots@loc@TMPb\pgfmathresult
2083 %
2084 % Identify if we need to switch the sign.
2085 % To verify that these cases are useful, I suggest visualizing
2086 % that stuff using the TeX code from above...
2087 %
2088 % I guess it is correct up to collapsing views (as you see, I
2089 % did not properly identify the cases with "=0" )
2090 \def\pgfplots@scale{1}%
2091 \ifdim\pgf@xx>0pt
2092 \ifdim\pgf@yx<0pt
2093 \else
2094 %
2095 \ifdim\pgf@xy<0pt
2096 \else
2097 \ifdim\pgf@yy<0pt
2098 \def\pgfplots@scale{-1}%
2099 \fi
2100 \fi
2101 %
2102 \fi
2103 \else
2104 \ifdim\pgf@xx<0pt
2105 \ifdim\pgf@yx>0pt
2106 \else
2107 %
2108 \ifdim\pgf@xy>0pt
2109 \else
2110 \ifdim\pgf@yy>0pt
2111 \def\pgfplots@scale{-1}%
2112 \fi
2113 \fi
2114 %
2115 \fi
2116 \fi
2117 \fi
2118 \ifdim\pgf@xy>0pt
2119 \ifdim\pgf@yy<0pt
2120 \else
2121 %
2122 \ifdim\pgf@xx>0pt
2123 \else
2124 \ifdim\pgf@yx>0pt
2125 \def\pgfplots@scale{-1}%
2126 \fi
2127 \fi
2128 %
2129 \fi
2130 \else
2131 \ifdim\pgf@xy<0pt
2132 \ifdim\pgf@yy>0pt
2133 \else
2134 %
2135 \ifdim\pgf@xx<0pt
2136 \else
2137 \ifdim\pgf@yx<0pt
2138 \def\pgfplots@scale{-1}%
2139 \fi
2140 \fi
2141 %
2142 \fi
2143 \fi
2144 \fi
2145 \pgfmathmultiply@{\pgfplots@scale}{\pgfplots@view@dir@threedim@x}%
2146 \let\pgfplots@view@dir@threedim@x\pgfmathresult
2147 \pgfmathmultiply@{\pgfplots@scale}{\pgfplots@view@dir@threedim@y}%
2148 \let\pgfplots@view@dir@threedim@y\pgfmathresult
2149 \pgfmathmultiply@{\pgfplots@scale}{\pgfplots@view@dir@threedim@z}%
2150 \let\pgfplots@view@dir@threedim@z\pgfmathresult
2151 %
2152 \pgfplotsmathvectorfromstring{\pgfplots@view@dir@threedim@x,\pgfplots@view@dir@threedim@y,\pgfplots@view@dir@threedim@z}{default}%
2153 \let\pgfplots@view@dir@threedim=\pgfplotsretval
2154 % normalize. This is not absolutely required -- but it is used
2155 % to accumulate point depth (for the mesh handler) in pgfmath
2156 % arithmetics. At least \pgfplotsmathviewdepthxyz should use
2157 % a properly scaled view dir.
2158 \pgfplotsmathvectorlength{\pgfplotsretval}{default}%
2159 \pgfplotscoordmath{default}{op}{reciprocal}{{\pgfplotsretval}}%
2160 \pgfplotsmathvectorscale{\pgfplots@view@dir@threedim}{\pgfmathresult}{default}%
2161 \else
2162 \pgfplotsmathvectorfromstring{\pgfplots@view@dir@threedim}{default}%
2163 \fi
2164 %
2165 \pgfmath@smuggleone\pgfplotsretval
2166 \endgroup
2167 \let\pgfplots@view@dir@threedim=\pgfplotsretval
2168 \else
2169 \def\pgfplots@loc@TMPb##1##2##3{%
2170 \pgfplotsmathvectorfromstring{##1,##2,##3}{default}%
2171 \let\pgfplots@view@dir@threedim=\pgfplotsretval
2172 }%
2173 \expandafter\pgfplots@loc@TMPb\pgfplots@loc@TMPc
2174 \fi
2175 }%
2176
2177 % PRECONDITION:
2178 % none
2179 % POSTCONDITION:
2180 % \pgfplots@default@aspect@ratio is set.
2181 \def\pgfplots@compute@default@aspect@ratio{%
2182 \expandafter\pgfmath@x\axisdefaultwidth
2183 \expandafter\pgfmath@y\axisdefaultheight
2184 \pgfmathlog@invoke@expanded\pgfmathdivide@{%
2185 {\pgf@sys@tonumber{\pgfmath@x}}%
2186 {\pgf@sys@tonumber{\pgfmath@y}}%
2187 }%
2188 \let\pgfplots@default@aspect@ratio=\pgfmathresult
2189 }
2190
2191 \def\pgfplots@ifneeds@one@uniform@datascale#1#2{%
2192 \if3\pgfplots@scale@mode@choice
2193 % scale mode=scale uniformly
2194 \def\pgfplots@loc@TMPa{1}%
2195 %
2196 % if we have at least one unit vector given explicitly, the
2197 % meaning changes: in that case, we can (and probably should)
2198 % use different data scale factors in each direction.
2199 \ifx\pgfplots@x\pgfutil@empty
2200 \else
2201 \def\pgfplots@loc@TMPa{0}%
2202 \fi
2203 \ifx\pgfplots@y\pgfutil@empty
2204 \else
2205 \def\pgfplots@loc@TMPa{0}%
2206 \fi
2207 \ifx\pgfplots@z\pgfutil@empty
2208 \else
2209 \def\pgfplots@loc@TMPa{0}%
2210 \fi
2211 \else
2212 \def\pgfplots@loc@TMPa{0}%
2213 \fi
2214 \if1\pgfplots@loc@TMPa
2215 #1%
2216 \else
2217 #2%
2218 \fi
2219 }%
2220
2221 \def\pgfplots@set@default@size@options{%
2222 % The axes 'x' and 'y' vectors will be scaled such that the total
2223 % size is (\axisdefaultwidth, \axisdefaultheight).
2224 %
2225 % If the user specifies ONE of width OR height,
2226 % the plot will be resized; keeping the aspect ratio.
2227 %
2228 \let\pgfplots@default@aspect@ratio=\pgfutil@empty
2229 \pgfkeysgetvalue{/pgfplots/x}{\pgfplots@x}%
2230 \pgfkeysgetvalue{/pgfplots/y}{\pgfplots@y}%
2231 \pgfkeysgetvalue{/pgfplots/z}{\pgfplots@z}%
2232 %\pgfkeysgetvalue{/pgfplots/viewdir}{\pgfplots@viewdir}%
2233 \pgfkeysgetvalue{/pgfplots/width}{\pgfplots@width}%
2234 \pgfkeysgetvalue{/pgfplots/height}{\pgfplots@height}%
2235 \ifx\pgfplots@width\pgfutil@empty
2236 \def\pgfplots@user@provided@width{0}%
2237 \else
2238 \def\pgfplots@user@provided@width{1}%
2239 \pgfmathparse{\pgfplots@width}%
2240 \edef\pgfplots@width{\pgfmathresult pt}%
2241 \fi
2242 \ifx\pgfplots@height\pgfutil@empty
2243 \def\pgfplots@user@provided@height{0}%
2244 \else
2245 \def\pgfplots@user@provided@height{1}%
2246 \pgfmathparse{\pgfplots@height}%
2247 \edef\pgfplots@height{\pgfmathresult pt}%
2248 \fi
2249 %
2250 % CASES:
2251 % W := 'width' option non-empty
2252 % H := 'height' option non-empty
2253 %
2254 % W H
2255 % 0 0 -> \axisdefaultwidth
2256 % 0 1 -> determine width out of H and the default aspect ratio
2257 % 1 X -> ok, use the user parameter.
2258 % -> KEEP ASPECT RATIO if just one W, or H is given!
2259 \ifx\pgfplots@width\pgfutil@empty
2260 \ifx\pgfplots@height\pgfutil@empty
2261 % The case W=0 H=0:
2262 \let\pgfplots@width=\axisdefaultwidth
2263 \let\pgfplots@height=\axisdefaultheight
2264 \else
2265 % The case W=0 H=1:
2266 \pgfplots@compute@default@aspect@ratio
2267 \expandafter\pgfmath@y\pgfplots@height
2268 \pgfmathlog@invoke@expanded\pgfmathmultiply@{%
2269 {\pgf@sys@tonumber{\pgfmath@y}}%
2270 {\pgfplots@default@aspect@ratio}%
2271 }%
2272 \edef\pgfplots@width{\pgfmathresult pt}%
2273 \fi
2274 \else
2275 \ifx\pgfplots@height\pgfutil@empty
2276 % The case W=1 H=0:
2277 \pgfplots@compute@default@aspect@ratio
2278 \expandafter\pgfmath@x\pgfplots@width
2279 \pgfmathlog@invoke@expanded\pgfmathdivide@{%
2280 {\pgf@sys@tonumber{\pgfmath@x}}%
2281 {\pgfplots@default@aspect@ratio}%
2282 }%
2283 \edef\pgfplots@height{\pgfmathresult pt}%
2284 \else
2285 % The case W=1 H=1:
2286 \fi
2287 \fi
2288 \pgfkeyslet{/pgfplots/width}{\pgfplots@width}%
2289 \pgfkeyslet{/pgfplots/height}{\pgfplots@height}%
2290 %
2291 \ifpgfplots@threedim
2292 \pgfplots@set@default@size@options@threedim
2293 \fi
2294 %
2295 \pgfplots@set@scale@mode
2296 }
2297
2298 % This method must be called BEFORE THE DATASCALING is initialized.
2299 \def\pgfplots@set@scale@mode{%
2300 \pgfkeysgetvalue{/pgfplots/unit vector ratio}\pgfplots@loc@TMPb
2301 \ifx\pgfplots@loc@TMPb\pgfutil@empty
2302 \else
2303 \ifcase\pgfplots@scale@mode@choice
2304 % 'scale mode'=auto
2305 \def\pgfplots@scale@mode@choice{3}% set to 'scale uniformly'
2306 %
2307 \if1\pgfplots@compat@scale@mode@compatible@mode
2308 % backwards compatibility mode...
2309 \ifpgfplots@threedim
2310 % ... for 3d: there is no backwards compatibility
2311 % mode here; it was plain wrong for 3d axes:
2312 % neither lengths nor angles have been correct.
2313 \pgfplots@compat@scale@mode@compatible@mode@warning
2314 \fi
2315 \fi
2316 \or
2317 % scale mode=none: keep it this way.
2318 \immediate\write-1{PGFPlots: scale mode=none and unit vector ratio is incompatible. Ignoring unit vector ratio.^^J}%
2319 \or
2320 % scale mode=stretch to fill
2321 \immediate\write-1{PGFPlots: scale mode=stretch to fill and unit vector ratio might produce unexpected results. Consider using scale mode=auto^^J}%
2322 \fi
2323 \fi
2324 %
2325 }
2326
2327 \def\pgfplots@compat@scale@mode@compatible@mode@warning{%
2328 \pgfplotswarning{axis equal incompatible change}\pgfeov%
2329 }%
2330
2331 \def\pgfplots@set@default@size@options@threedim{%
2332 \pgfplots@loc@tmpfalse
2333 \ifx\pgfplots@x\pgfutil@empty
2334 \else
2335 \pgfplots@loc@tmptrue
2336 \fi
2337 \ifx\pgfplots@y\pgfutil@empty
2338 \else
2339 \pgfplots@loc@tmptrue
2340 \fi
2341 \ifx\pgfplots@z\pgfutil@empty
2342 \else
2343 \pgfplots@loc@tmptrue
2344 \fi
2345 \ifpgfplots@loc@tmp
2346 % oh - we have at least one of the [xyz] unit vectors!
2347 % make sure all of them are there
2348 \ifx\pgfplots@x\pgfutil@empty
2349 \pgfplots@set@default@size@options@threedim@{x}{(1pt,0pt)}%
2350 \fi
2351 \ifx\pgfplots@y\pgfutil@empty
2352 \pgfplots@set@default@size@options@threedim@{y}{(0pt,1pt)}%
2353 \fi
2354 \ifx\pgfplots@z\pgfutil@empty
2355 \pgfplots@set@default@size@options@threedim@{z}{(0pt,1pt)}%
2356 \fi
2357 \pgfkeyslet{/pgfplots/view/az}\pgfutil@empty
2358 \pgfkeyslet{/pgfplots/view/el}\pgfutil@empty
2359 \fi
2360 }
2361 \def\pgfplots@set@default@size@options@threedim@#1#2{%
2362 \pgfplots@error{Sorry, a 3D axis needs either NONE or ALL of "x,y,z". I found partial information, but (at least) '#1' is lacking... please add '#1'}%
2363 \expandafter\def\csname pgfplots@#1\endcsname{#2}%
2364 }
2365
2366 % A helper method for \pgfplots@initsizes which
2367 % - applies the data scaling trafo to user arguments
2368 % - sets calls pgfset#1vec
2369 %
2370 % #1: the vector to set (either 'x' or 'y')
2371 % #2: the index of the vector to set (either 0 or 1)
2372 % #3: the already precomputed temporary scale (see pgfplots@initsizes)
2373 % #4: an output argument. It is a macro name which will be defined to
2374 % '1' if and only if the finally set vector is parallel to the #1 axis
2375 % of PGF, that means (x,0) for #1=x and (0,y) for #2=y.
2376 \def\pgfplots@initsizes@setunitvector#1#2#3#4{%
2377 \pgfkeysgetvalue{/pgfplots/#1 dir/value}\pgfplots@loc@dirvalue
2378 \expandafter\let\expandafter\pgfplots@loc@TMPb\csname pgfplots@#1\endcsname
2379 \ifx\pgfplots@loc@TMPb\pgfutil@empty
2380 \def#4{1}% we have (#1,0) or (0,#1)
2381 %
2382 %\message{Setting unitvector(#1) to auto-computed multiple of e_#2 ...}%
2383 \edef\pgfplots@loc@TMPa{#3}%
2384 \if r\pgfplots@loc@dirvalue
2385 \edef\pgfplots@loc@TMPa{-#3}%
2386 \fi
2387 \ifcase#2\relax
2388 \pgfsetxvec{\pgfqpoint{\pgfplots@loc@TMPa pt}{0pt}}%
2389 \or
2390 \pgfsetyvec{\pgfqpoint{0pt}{\pgfplots@loc@TMPa pt}}%
2391 \or
2392 \pgfsetzvec{\pgfqpoint{\pgfplots@loc@TMPa pt}{\pgfplots@loc@TMPa pt}}%
2393 \fi
2394 \else
2395 % Ok, we have a user-defined unit vector.
2396 %
2397 % That means we also need to apply the scaling trafo!
2398 %
2399 % 1. Check whether we have a complete vector of type (x,y):
2400 \expandafter\pgfutil@in@\expandafter(\expandafter{\pgfplots@loc@TMPb}%
2401 \ifpgfutil@in@
2402 % YES: we have (x,y):
2403 %
2404 \def#4{0}% we DON'T have (#1,0) or (0,#1). At least I think so.
2405 %
2406 %\message{Setting unitvector(#1) to non-standard \csname pgfplots@#1\endcsname ...}%
2407 \def\pgfplots@loc@TMPa(##1,##2){%
2408 \pgfplotscoordmath{default}{parse}{##1}%
2409 \pgfplotscoordmath{default}{tofixed}{\pgfmathresult}%
2410 \let\pgfplots@loc@TMPb=\pgfmathresult
2411 \pgfplotscoordmath{default}{parse}{##2}%
2412 \pgfplotscoordmath{default}{tofixed}{\pgfmathresult}%
2413 \let\pgfplots@loc@TMPc=\pgfmathresult
2414 %
2415 \pgfplots@if{pgfplots@apply@datatrafo@#1}{%
2416 \pgfplotscoordmath{#1}{datascaletrafo noshift inverse to fixed}{\pgfplots@loc@TMPb}%
2417 \let\pgfplots@loc@TMPb=\pgfmathresult
2418 \pgfplotscoordmath{#1}{datascaletrafo noshift inverse to fixed}{\pgfplots@loc@TMPc}%
2419 \let\pgfplots@loc@TMPc=\pgfmathresult
2420 }{}%
2421 \csname pgfset#1vec\endcsname{%
2422 \pgfqpoint
2423 {\if r\pgfplots@loc@dirvalue -\fi\pgfplots@loc@TMPb pt}
2424 {\if r\pgfplots@loc@dirvalue -\fi\pgfplots@loc@TMPc pt}}%
2425 }%
2426 \expandafter\pgfplots@loc@TMPa\pgfplots@loc@TMPb%
2427 %
2428 \else
2429 % NO we simply have a scalar value.
2430 \def#4{1}% we have (#1,0) or (0,#1)
2431 %\message{Setting unitvector(#1) to \csname pgfplots@#1\endcsname * e_{#2}...}%
2432 \pgfplots@if{pgfplots@apply@datatrafo@#1}{%
2433 \pgfplotscoordmath{default}{parse}{\csname pgfplots@#1\endcsname}%
2434 \pgfplotscoordmath{default}{tofixed}{\pgfmathresult}%
2435 \pgfplotscoordmath{#1}{datascaletrafo noshift inverse to fixed}{\pgfmathresult}%
2436 \edef\pgfplots@loc@TMPb{\pgfmathresult pt}%
2437 }{\relax}%
2438 \edef\pgfplots@loc@TMPb{\if r\pgfplots@loc@dirvalue -\fi\pgfplots@loc@TMPb}%
2439 \begingroup
2440 \pgf@xa=\pgfplots@loc@TMPb\relax
2441 \xdef\pgfplots@glob@TMPb{\pgf@sys@tonumber{\pgf@xa}}%
2442 \endgroup
2443 \ifcase#2\relax
2444 \pgfsetxvec{\pgfqpoint{\pgfplots@loc@TMPb}{0pt}}%
2445 \or
2446 \pgfsetyvec{\pgfqpoint{0pt}{\pgfplots@loc@TMPb}}%
2447 \or
2448 \pgfsetzvec{\pgfqpoint{\pgfplots@loc@TMPb}{\pgfplots@loc@TMPb}}%
2449 \fi
2450 \fi
2451 \fi
2452 %\message{-> got unitvector(#1) = (\the\csname pgf@#1x\endcsname, \the\csname pgf@#1y\endcsname).^^J}%
2453 }%
2454
2455 % Applies the 'axis equal' feature.
2456 %
2457 % PRECONDITION:
2458 % - #1, #2, #3 contains the current scaling
2459 % factors in x,y, z, resp. which are to be applied to unit vectors
2460 % - neither unit vectors nor limits are in their final shape
2461 % - \pgfplots@set@default@size@options has been invoked before
2462 %
2463 % POSTCONDITION:
2464 % - #1, #2, #3 have been changed to accommodate unit vector ratio
2465 % - #4, #5, #6 [output] contain axis limit compensation scales
2466 %
2467 % There is just one algorithmic difficulty: the data scaling
2468 % transformation. All unit vector length above are only meaningful in
2469 % the UNTRANSFORMED range, so we have to mingle with the scaling
2470 % transformation.
2471 \def\pgfplots@apply@unit@ratio#1#2#3#4#5#6{%
2472 \begingroup
2473 \edef\pgfplots@target@unit@scale@inv@x{#1}%
2474 \edef\pgfplots@target@unit@scale@inv@y{#2}%
2475 \edef\pgfplots@target@unit@scale@inv@z{#3}%
2476 \def\pgfplots@target@limitrescale@x@{1}%
2477 \def\pgfplots@target@limitrescale@y@{1}%
2478 \def\pgfplots@target@limitrescale@z@{1}%
2479 %
2480 \pgfkeysgetvalue{/pgfplots/unit vector ratio}\pgfplots@unit@vector@ratio
2481 \ifx\pgfplots@unit@vector@ratio\pgfutil@empty
2482 \else
2483 \edef\pgfplots@unit@vector@ratio{\pgfplots@unit@vector@ratio\space1 1 }%
2484 %
2485 \expandafter\pgfplots@unit@vector@ratio@check@nop\pgfplots@unit@vector@ratio\pgfplots@EOI
2486 \ifpgfplots@loc@tmp
2487 %
2488 % Step 1: compute the unit vector which STAYS CONSTANT.
2489 %
2490 \pgfkeysgetvalue{/pgfplots/unit vector ratio axis}\pgfplots@apply@unit@ratio@reference
2491 \ifx\pgfplots@apply@unit@ratio@reference\pgfutil@empty
2492 \pgfplots@apply@unit@ratio@find@reference%
2493 \fi
2494 %
2495 % FIXME : I could spent some attention here to save work:
2496 % both, unit ratios and the resulting scales are computed at
2497 % least twice (once in \pgfplots@apply@unit@ratio@find@reference and once in the
2498 % following).
2499 \expandafter\pgfplots@apply@unit@ratio@prepareratios\pgfplots@unit@vector@ratio\pgfplots@EOI
2500 %
2501 %\message{USING REFERENCE UNIT VECTOR FROM \pgfplots@apply@unit@ratio@reference; ratio \pgfplots@unit@ratio@x\space \pgfplots@unit@ratio@y\space \pgfplots@unit@ratio@z.^^J}%
2502 %
2503 % Step 2: apply the scaling:
2504 \pgfplots@rescale@unit@vector@reltoreference{x}{\pgfplots@unit@ratio@x}%
2505 \pgfplots@rescale@unit@vector@reltoreference{y}{\pgfplots@unit@ratio@y}%
2506 \ifpgfplots@threedim
2507 \pgfplots@rescale@unit@vector@reltoreference{z}{\pgfplots@unit@ratio@z}%
2508 \fi
2509 %
2510 \else
2511 %\message{Skipped application of 'unit vector ratio=\pgfkeysvalueof{/pgfplots/unit vector ratio}': it is already done by 'scale uniformly'.^^J}%
2512 \fi
2513 \fi
2514 \xdef\pgfplots@glob@TMPa{%
2515 \noexpand\def\noexpand#1{\pgfplots@target@unit@scale@inv@x}%
2516 \noexpand\def\noexpand#2{\pgfplots@target@unit@scale@inv@y}%
2517 \noexpand\def\noexpand#3{\pgfplots@target@unit@scale@inv@z}%
2518 \noexpand\def\noexpand#4{\pgfplots@target@limitrescale@x@}%
2519 \noexpand\def\noexpand#5{\pgfplots@target@limitrescale@y@}%
2520 \noexpand\def\noexpand#6{\pgfplots@target@limitrescale@z@}%
2521 }%
2522 \endgroup
2523 \pgfplots@glob@TMPa
2524 }%
2525
2526 \def\pgfplots@appy@unit@ratio@reciprocal#1{%
2527 \pgfplotscoordmath{default}{parsenumber}{#1}%
2528 \pgfplotscoordmath{default}{op}{reciprocal}{{\pgfmathresult}}%
2529 \pgfplotscoordmath{default}{tofixed}{\pgfmathresult}%
2530 }%
2531
2532 % Defines \ifpgfplots@loc@tmp := need to modify scaling factors
2533 \def\pgfplots@unit@vector@ratio@check@nop#1 #2 #3 #4\pgfplots@EOI{%
2534 \pgfplots@loc@tmptrue
2535 \if3\pgfplots@scale@mode@choice
2536 % scale mode=scale uniformly
2537 \ifpgfplots@threedim
2538 \ifdim#1pt=#2pt
2539 \ifdim#1pt=#3pt
2540 % 'axis equal' is implicitly done by 'scale mode=scale
2541 % uniformly' anyway
2542 \pgfplots@loc@tmpfalse
2543 \fi
2544 \fi
2545 \else
2546 \ifdim#1pt=#2pt
2547 % 'axis equal' is implicitly done by 'scale mode=scale
2548 % uniformly' anyway
2549 \pgfplots@loc@tmpfalse
2550 \fi
2551 \fi
2552 \fi
2553 % activate the following line to deactivate optimization: [FIXME]
2554 %\pgfplots@loc@tmpfalse
2555 }%
2556
2557 % This macro determines the reference axis for unit vector rescaling.
2558 % The reference axis remains unscaled (it gets scaling factor 1 if you
2559 % want it this way).
2560 %
2561 % The other axes are scaled such that the desired unit vector ratios
2562 % are fulfilled.
2563 %
2564 % The idea to select a reference axis is as follows:
2565 % 1. Every unit vector scaling factor s should fulfill s <= 1.
2566 % 2. Choose the reference axis such that the minimal amount of scaling
2567 % is performed.
2568 %
2569 % The motivation for (1) is: if all involved scaling factors are at
2570 % most 1, the resulting picture will only become *smaller*.
2571 % Consequently, we can simply enlarge axis limits to restore the
2572 % original width/height!
2573 %
2574 % The motivation for (2) is: a huge amount of scaling might reduce the
2575 % size of the image too much. Of course, the figure will be enlarged
2576 % to fit the original width/height, but most of it will be empty. So,
2577 % use the smallest scaling.
2578 %
2579 % @POSTCONDITION The reference axis is stored in
2580 % \pgfplots@apply@unit@ratio@reference .
2581 %
2582 % @see the key 'unit vector ratio axis=y' which allows to manually
2583 % select the reference axis. This will illustrate what happens here.
2584 \def\pgfplots@apply@unit@ratio@find@reference{%
2585 %
2586 \begingroup
2587 \let\pgfplots@ONE=\pgf@x
2588 \global\pgfplots@ONE=1.002pt
2589 %
2590 \def\pgfplots@optimum@sofar@axis{}%
2591 \let\pgfplots@optimum@sofar@value=\pgf@y
2592 \global\pgfplots@optimum@sofar@value=16000pt
2593 %
2594 %\pgfplots@apply@unit@ratio@find@reference@checkexplicitlimits
2595 %
2596 \ifx\pgfplots@optimum@sofar@axis\pgfutil@empty
2597 % set \pgfplots@loc@TMPa := 1 if and only if the axis is 3d
2598 \def\pgfplots@loc@TMPa{0}%
2599 \if0\b@pgfplots@unitvec@is@zero@z
2600 % ah, it IS 3d!
2601 \def\pgfplots@loc@TMPa{1}%
2602 \else
2603 % ok, 2d mode (includes view={0}{90})
2604 \def\pgfplots@loc@TMPa{0}%
2605 \fi
2606 \if1\pgfplots@loc@TMPa
2607 % 3D is more complicated than 2D:
2608 % for every fixed reference axis, we have to check *two*
2609 % scaling factors.
2610 %
2611 % Furthermore, the optimality condition (2) needs to be
2612 % performed on the maximum max{1-s_a, 1-s_b} provided both of
2613 % these numbers are positive.
2614 %
2615 \def\pgfplots@check@##1##2{%
2616 % PRECONDITION: \pgfplots@apply@unit@ratio@reference is defined.
2617 %
2618 % renormalize \pgfplots@unit@[xyz] :
2619 \expandafter\pgfplots@apply@unit@ratio@prepareratios\pgfplots@unit@vector@ratio\pgfplots@EOI
2620 %
2621 % compute s_a :
2622 \pgfplots@getscale@unit@vector@reltoreference ##1{\csname pgfplots@unit@ratio@##1\endcsname}%
2623 \let\pgfplots@scale@a=\pgfmathresult
2624 %
2625 % compute s_b :
2626 \pgfplots@getscale@unit@vector@reltoreference ##2{\csname pgfplots@unit@ratio@##2\endcsname}%
2627 \let\pgfplots@scale@b=\pgfmathresult
2628 %
2629 % check if the actual choice of
2630 % \pgfplots@apply@unit@ratio@reference is FEASIBLE.
2631 % That is the case if s_a <= 1 && s_b <= 1.
2632 % We check
2633 % (1 - s_a >= 0 ) && ( 1 - s_b >= 0 )
2634 % instead, since I need the value
2635 % max( 1-s_a, 1-s_b )
2636 % anyway.
2637 \def\pgfplots@ref@is@feasible{1}%
2638 \pgf@xa=\pgfplots@ONE \advance\pgf@xa by-\pgfplots@scale@a pt
2639 \ifdim\pgf@xa<0sp
2640 \def\pgfplots@ref@is@feasible{0}%
2641 \else
2642 \pgf@xb=\pgfplots@ONE \advance\pgf@xb by-\pgfplots@scale@b pt
2643 \ifdim\pgf@xb<0sp
2644 \def\pgfplots@ref@is@feasible{0}%
2645 \fi
2646 \fi
2647 % compute max(1-s_a,1-s_b) into \pgf@xa:
2648 % pgf@xa= max(pgf@xa,pgf@xb):
2649 \ifdim\pgf@xb>\pgf@xa \pgf@xa=\pgf@xb \fi
2650 \if1\pgfplots@ref@is@feasible
2651 \ifdim\pgf@xa<\pgfplots@optimum@sofar@value
2652 % Ah, ok. The actual choice is BETTER as it
2653 % involves less scaling.
2654 %
2655 % Remember it!
2656 \let\pgfplots@optimum@sofar@axis=\pgfplots@apply@unit@ratio@reference
2657 \global\pgfplots@optimum@sofar@value=\pgf@xa
2658 \fi
2659 \fi
2660 %\message{^^Junit vector ratio 3D searching reference: checking \pgfplots@apply@unit@ratio@reference. feasible=\pgfplots@ref@is@feasible. \if1\pgfplots@ref@is@feasible max=\the\pgf@xa. \fi Optimum so far: value =\the\pgfplots@optimum@sofar@value\space for axis \pgfplots@optimum@sofar@axis.^^J}%
2661 }%
2662 %
2663 % Check 'x' as reference :
2664 \def\pgfplots@apply@unit@ratio@reference{x}%
2665 \pgfplots@check@ yz%
2666 %
2667 % Check 'y' as reference :
2668 \def\pgfplots@apply@unit@ratio@reference{y}%
2669 \pgfplots@check@ xz%
2670 %
2671 % Check 'z' as reference :
2672 \def\pgfplots@apply@unit@ratio@reference{z}%
2673 \pgfplots@check@ xy%
2674 %
2675 \else
2676 % 2D is much simpler: find the scale s which fulfills s <= 1.
2677 % One of them MUST fulfill it.
2678 %
2679 % try 'x' axis as reference:
2680 \def\pgfplots@apply@unit@ratio@reference{x}%
2681 %
2682 % renormalize:
2683 \expandafter\pgfplots@apply@unit@ratio@prepareratios\pgfplots@unit@vector@ratio\pgfplots@EOI
2684 %
2685 % compute scaling factor:
2686 \pgfplots@getscale@unit@vector@reltoreference y\pgfplots@unit@ratio@y%
2687 %
2688 %\message{^^Junit vector ratio 2D searching reference: checking \pgfplots@apply@unit@ratio@reference. feasible=\pgfmathresult < 1: \ifdim\pgfmathresult pt <\pgfplots@ONE YES-> use x\else NO->use y\fi^^J}%
2689 % and check (1). The condition (2) is irrelevant; it is met
2690 % anyway.
2691 \ifdim\pgfmathresult pt<\pgfplots@ONE
2692 \def\pgfplots@optimum@sofar@axis{x}%
2693 \else
2694 \def\pgfplots@optimum@sofar@axis{y}%
2695 \fi
2696 \fi
2697 \else
2698 %\message{^^Junit vector ratio chose \pgfplots@optimum@sofar@axis\space to fulfill explicitly provided limits (at least partially).^^J}%
2699 \fi
2700 %
2701 \ifx\pgfplots@optimum@sofar@axis\pgfutil@empty
2702 \if1\b@pgfplots@unitvec@is@zero@z
2703 \def\pgfplots@optimum@sofar@axis{y}%
2704 \else
2705 \def\pgfplots@optimum@sofar@axis{z}%
2706 \fi
2707 \pgfplotswarning{unit vector ratio axis undetermined}{\pgfplots@optimum@sofar@axis}\pgfeov%
2708 \fi
2709 \let\pgfplots@apply@unit@ratio@reference=\pgfplots@optimum@sofar@axis
2710 \pgfmath@smuggleone\pgfplots@apply@unit@ratio@reference
2711 \endgroup
2712 }%
2713 \def\pgfplots@apply@unit@ratio@find@reference@checkexplicitlimits{%
2714 \ifpgfplots@autocompute@ymax \else \def\pgfplots@optimum@sofar@axis{y}\fi
2715 \ifpgfplots@autocompute@ymin \else \def\pgfplots@optimum@sofar@axis{y}\fi
2716 \ifpgfplots@autocompute@xmax \else \def\pgfplots@optimum@sofar@axis{x}\fi
2717 \ifpgfplots@autocompute@xmin \else \def\pgfplots@optimum@sofar@axis{x}\fi
2718 \ifpgfplots@threedim
2719 \ifpgfplots@autocompute@zmax \else \def\pgfplots@optimum@sofar@axis{z}\fi
2720 \ifpgfplots@autocompute@zmin \else \def\pgfplots@optimum@sofar@axis{z}\fi
2721 \fi
2722 }%
2723
2724 % This is ONLY applied to the value of 'unit vector ratio'. It does
2725 % not touch the current axis scaling factors.
2726 \def\pgfplots@apply@unit@ratio@prepareratios#1 #2 #3 #4\pgfplots@EOI{%
2727 \def\pgfplots@unit@ratio@x{#1}%
2728 \def\pgfplots@unit@ratio@y{#2}%
2729 \def\pgfplots@unit@ratio@z{#3}%
2730 %
2731 % 'unit vector ratio' is measured relative to the y axis for 2d
2732 % and relative to the z axis for 3d plots.
2733 % renormalize such that it is relative to
2734 % \pgfplots@apply@unit@ratio@reference.
2735 %
2736 % Furthermore, renormalize such that
2737 % unit@ratio@\pgfplots@apply@unit@ratio@reference is 1.
2738 \pgfmathreciprocal@{\csname pgfplots@unit@ratio@\pgfplots@apply@unit@ratio@reference\endcsname}%
2739 \let\pgfplots@loc@TMPa=\pgfmathresult
2740 \ifpgfplots@threedim
2741 \if z\pgfplots@apply@unit@ratio@reference
2742 \else
2743 \pgfmathmultiply@{\pgfplots@loc@TMPa}{\pgfplots@unit@ratio@z}%
2744 \let\pgfplots@loc@TMPa=\pgfmathresult
2745 \fi
2746 %
2747 \pgfmathmultiply@{\pgfplots@loc@TMPa}{\pgfplots@unit@ratio@x}%
2748 \let\pgfplots@unit@ratio@x=\pgfmathresult
2749 %
2750 \pgfmathmultiply@{\pgfplots@loc@TMPa}{\pgfplots@unit@ratio@y}%
2751 \let\pgfplots@unit@ratio@y=\pgfmathresult
2752 %
2753 \pgfmathmultiply@{\pgfplots@loc@TMPa}{\pgfplots@unit@ratio@z}%
2754 \let\pgfplots@unit@ratio@z=\pgfmathresult
2755 \else
2756 \if y\pgfplots@apply@unit@ratio@reference
2757 \else
2758 \pgfmathmultiply@{\pgfplots@loc@TMPa}{\pgfplots@unit@ratio@y}%
2759 \let\pgfplots@loc@TMPa=\pgfmathresult
2760 \fi
2761 %
2762 \pgfmathmultiply@{\pgfplots@loc@TMPa}{\pgfplots@unit@ratio@x}%
2763 \let\pgfplots@unit@ratio@x=\pgfmathresult
2764 %
2765 \pgfmathmultiply@{\pgfplots@loc@TMPa}{\pgfplots@unit@ratio@y}%
2766 \let\pgfplots@unit@ratio@y=\pgfmathresult
2767 %
2768 \def\pgfplots@unit@ratio@z{<unused>}%
2769 \fi
2770 %
2771 }%
2772
2773
2774 % Computes a new unit vector E_#1 for direction #1 such that
2775 % ||E_#1|| = #2 * ||e_reference||.
2776 % Here, #2 is a scaling factor and e_reference is a reference axis.
2777 % The reference axis is stored in
2778 % \pgfplots@apply@unit@ratio@reference, the macro contains one of
2779 % {x,y,z}.
2780 %
2781 % The data limits for '#1' will be enlarged as well (for 'unit rescale
2782 % keep size').
2783 %
2784 % #1 is the axis which should be scaled (i.e. #1 in {x,y,z}).
2785 % It is allowed if #1 = \pgfplots@apply@unit@ratio@reference. In this
2786 % case, you can provide a scale '#2' to rescale the axis.
2787 %
2788 % #2 is a desired scale, relative to
2789 % \pgfplots@apply@unit@ratio@reference. #2 should be a number without
2790 % unit.
2791 %
2792 % The parameter \pgfplots@apply@unit@ratio@reference is also one of
2793 % {x,y,z}.
2794 %
2795 \def\pgfplots@rescale@unit@vector@reltoreference#1#2{%
2796 \def\pgfplots@loc@TMPa{0}%
2797 \if#1\pgfplots@apply@unit@ratio@reference
2798 \pgfplotsmath@ifapproxequal@dim{#2pt}{1pt}{0.0002pt}{%
2799 }{%
2800 \def\pgfplots@loc@TMPa{1}%
2801 }%
2802 \else
2803 \def\pgfplots@loc@TMPa{1}%
2804 \fi
2805 \if1\csname b@pgfplots@unitvec@is@zero@#1\endcsname
2806 \def\pgfplots@loc@TMPa{0}%
2807 \fi
2808 \if1\pgfplots@loc@TMPa
2809 %
2810 \pgfplots@getscale@unit@vector@reltoreference{#1}{#2}%
2811 \global\let\pgfplots@glob@TMPa=\pgfmathresult
2812 %
2813 %\message{Rescaling '#1' by \pgfplots@glob@TMPa.^^J}%
2814 %
2815 \pgfmathdivide@{\csname pgfplots@target@unit@scale@inv@#1\endcsname}{\pgfplots@glob@TMPa}%
2816 \expandafter\let\csname pgfplots@target@unit@scale@inv@#1\endcsname=\pgfmathresult
2817 %
2818 \pgfmathreciprocal@\pgfplots@glob@TMPa
2819 \expandafter\let\csname pgfplots@target@limitrescale@#1@\endcsname=\pgfmathresult
2820 %
2821 \fi
2822 }
2823
2824 % Updates the #1 axis limits such that the axis' dimensions
2825 % stay the same after scaling the #1 unit vector by a scale 's'.
2826 %
2827 % PRECONDITION:
2828 % - the #1 unit vector has been rescaled by a factor s.
2829 % For example, e_xnew := e_x * 0.5 .
2830 %
2831 % POSTCONDITION:
2832 % - the axis limits are enlarged by a factor 1/s such that
2833 % 1/s (#1max - #1min) * e_xnew = (#1max- #1min) * e_x.
2834 %
2835 % In other words, the unit vector rescale is componensated by
2836 % modifying the axis limits: we want to add an absolute component 'd'
2837 % to the range:
2838 % 1/s (xmax - xmin ) = xmax - xmin +d
2839 % =>
2840 % d = (1/s - 1) * (xmax - xmin)
2841 %
2842 % The only remaining thing to do is to distribute 'd' to 'xmax' and
2843 % 'xmin'. Typically, 50% to each will be fine, I guess...
2844 %
2845 % #1: either x, y or z. It denotes the direction which has been
2846 % modified.
2847 % #2: the INVERSE of the scaling factor, #2 = 1/s .
2848 %
2849 \def\pgfplots@apply@unit@vector@rescale@keep@size#1#2{%
2850 \ifdim#2pt=1pt
2851 \else
2852 \if0\pgfplots@unit@vector@rescale@keep@size
2853 % unit rescale keep size=false : do nothing. Ignore the
2854 % scaling request.
2855 \else
2856 % unit rescale keep size=true|unless limits declared
2857 %
2858 %\message{'unit rescale keep size': Resizing data range for #1 by #2: from \csname pgfplots@#1min\endcsname:\csname pgfplots@#1max\endcsname\ to}%
2859 \pgfmathsubtract@{\csname pgfplots@#1max\endcsname}{\csname pgfplots@#1min\endcsname}%
2860 \begingroup
2861 \pgf@xa=\pgfmathresult pt
2862 \pgfmathsubtract@{#2}{1.0}%
2863 \pgf@xa=\pgfmathresult \pgf@xa% this is 'd'
2864 %
2865 % \pgfplots@glob@TMPb : will be subtracted from #1min
2866 % \pgfplots@glob@TMPc : will be added to #1max
2867 \pgfplots@if{pgfplots@autocompute@#1min}{%
2868 \pgfplots@if{pgfplots@autocompute@#1max}{%
2869 \pgf@xa=0.5 \pgf@xa
2870 \xdef\pgfplots@glob@TMPb{\pgf@sys@tonumber{\pgf@xa}}%
2871 \xdef\pgfplots@glob@TMPc{\pgfplots@glob@TMPb}%
2872 }{%
2873 \xdef\pgfplots@glob@TMPb{\pgf@sys@tonumber{\pgf@xa}}%
2874 \xdef\pgfplots@glob@TMPc{0.0}%
2875 }%
2876 }{%
2877 \pgfplots@if{pgfplots@autocompute@#1max}{%
2878 \xdef\pgfplots@glob@TMPb{0.0}%
2879 \xdef\pgfplots@glob@TMPc{\pgf@sys@tonumber{\pgf@xa}}%
2880 }{%
2881 \if1\pgfplots@unit@vector@rescale@keep@size
2882 % unit rescale keep size=true : FORCE
2883 % enlargement!
2884 \pgf@xa=0.5 \pgf@xa
2885 \xdef\pgfplots@glob@TMPb{\pgf@sys@tonumber{\pgf@xa}}%
2886 \xdef\pgfplots@glob@TMPc{\pgfplots@glob@TMPb}%
2887 \else
2888 % unit rescale keep size=unless limits declared:
2889 % do not scale - all limits are declared
2890 % explicitly
2891 \xdef\pgfplots@glob@TMPb{0.0}%
2892 \xdef\pgfplots@glob@TMPc{0.0}%
2893 \fi
2894 }%
2895 }%
2896 \endgroup
2897 \pgfmathsubtract@{\csname pgfplots@#1min\endcsname}{\pgfplots@glob@TMPb}%
2898 \expandafter\global\expandafter\let\csname pgfplots@#1min\endcsname=\pgfmathresult
2899 \pgfmathadd@{\csname pgfplots@#1max\endcsname}{\pgfplots@glob@TMPc}%
2900 \expandafter\global\expandafter\let\csname pgfplots@#1max\endcsname=\pgfmathresult
2901 %\message{\csname pgfplots@#1min\endcsname:\csname pgfplots@#1max\endcsname. [- \pgfplots@glob@TMPb; + \pgfplots@glob@TMPc]^^J}%
2902 %
2903 % Update auxiliary data members:
2904 \pgfplots@visphase@notify@changeofcanvaslimits{#1}%
2905 \fi
2906 \fi
2907 }%
2908
2909 % #1: an axis which should be scaled
2910 % #2: the desired final ratio ||e_#1||/||e_ref||
2911 \def\pgfplots@getscale@unit@vector@reltoreference#1#2{%
2912 %
2913 % If the datascaling transformation is active (which is almost
2914 % every time the case here), we have a transformation
2915 % T^{-1}(x)= 10^scale * x
2916 % with different scales for every axis.
2917 %
2918 % If the datascaling transformation is NOT active, scale is 0
2919 % and T^{-1} = Identity.
2920 %
2921 % Note that the datascaling transformation also has
2922 % translations (shifts). These are not important here.
2923 %
2924 % Goal:
2925 % compute E_#1 such that
2926 % #2* || T^{-1} e_ref || = || T^{-1} E_#1 ||
2927 % where T^{-1} is the data scaling transformation and e_ref the
2928 % reference unit vector. Keep in mind that there are
2929 % *different* data scaling transformations for each axis.
2930 %
2931 % We are given e_ref and e_#1 and the desired aspect ratio
2932 % between e_ref and E_#1, which is available as #2.
2933 %
2934 % So: T^{-1} E_#1 := s* T^{-1} e_#1 where
2935 % s = #2 * ||T^{-1} e_ref|| / || T^{-1} e_#1 ||
2936 % = |10^{scale_ref}| / |10^{scale_#1}| * #2 * || e_ref|| / ||e_#1||.
2937 %
2938 % Then, E_#1 = T ( T^{-1} E_#1 ) = s * e_#1.
2939 %
2940 % -> compute 's'!
2941 %
2942 % Part 1: compute
2943 % #2 * ||e_ref|| / ||e_#1||.
2944 %
2945 \def\pgfplots@loc@TMPa{1}%
2946 \if1\csname b@pgfplots@unitvec@is@zero@#1\endcsname
2947 \def\pgfplots@loc@TMPa{0}%
2948 \else
2949 \if1\csname b@pgfplots@unitvec@is@zero@\pgfplots@apply@unit@ratio@reference\endcsname
2950 \def\pgfplots@loc@TMPa{0}%
2951 \fi
2952 \fi
2953 \if0\pgfplots@loc@TMPa
2954 \def\pgfmathresult{16001}%
2955 \else
2956 % note that x^{-1} / y^{-1} == ( x/y )^{-1} == y/x .
2957 % consequently, we can use our @inv@[xyz] values here:
2958 \pgfmathdivide@
2959 {\csname pgfplots@target@unit@scale@inv@#1\endcsname}%
2960 {\csname pgfplots@target@unit@scale@inv@\pgfplots@apply@unit@ratio@reference\endcsname}
2961 \pgfmathmultiply@
2962 {\pgfmathresult}%
2963 {#2}%
2964 \global\let\pgfplots@glob@TMPa=\pgfmathresult
2965 %
2966 % also compute 1/s, required as temporary value:
2967 %\pgfmathmultiply@
2968 % {\csname pgfplots@\pgfplots@apply@unit@ratio@reference @inverseveclength\endcsname}
2969 % {\csname pgfplots@target@unit@scale@#1\endcsname}%
2970 %\ifdim#2pt=1pt
2971 %\else
2972 % \pgfmathdivide@{\pgfmathresult}{#2}%
2973 %\fi
2974 %\global\let\pgfplots@glob@TMPb=\pgfmathresult
2975 %
2976 % Part 2: handle data scaling trafo scales:
2977 \begingroup
2978 \def\pgfplots@tmp@exponentref{0}%
2979 \def\pgfplots@tmp@exponentK{0}%
2980 \pgfplots@if{pgfplots@apply@datatrafo@\pgfplots@apply@unit@ratio@reference }{%
2981 \pgfplots@letcsname{pgfplots@tmp@exponentref}={pgfplots@data@scale@trafo@EXPONENT@\pgfplots@apply@unit@ratio@reference }%
2982 }{}%
2983 \pgfplots@if{pgfplots@apply@datatrafo@#1}{%
2984 \pgfplots@letcsname{pgfplots@tmp@exponentK}={pgfplots@data@scale@trafo@EXPONENT@#1}%
2985 }{}%
2986 \c@pgf@counta=\pgfplots@tmp@exponentref\relax
2987 \advance\c@pgf@counta by-\pgfplots@tmp@exponentK\relax
2988 \ifnum\c@pgf@counta=0
2989 \else
2990 \pgfplotsmathmultiplypowten@{\pgfplots@glob@TMPa}{\c@pgf@counta}%
2991 \global\let\pgfplots@glob@TMPa=\pgfmathresult
2992 % \pgfplotsmathmultiplypowten@{\pgfplots@glob@TMPb}{-\c@pgf@counta}%
2993 % \global\let\pgfplots@glob@TMPb=\pgfmathresult
2994 \fi
2995 \xdef\pgfplots@glob@TMPc{\the\c@pgf@counta}%
2996 \endgroup
2997 \let\pgfmathresult=\pgfplots@glob@TMPa
2998 \fi
2999 %\message{\string\pgfplots@getscale@unit@vector@reltoreference{#1}{#2} (reference \pgfplots@apply@unit@ratio@reference) = \pgfmathresult.^^J}%
3000 }
3001
3002 % helper for \pgfplots@check@and@apply@datatrafo@for.
3003 \def\pgfplots@compute@number@order@for@trafo@isdimen#1\tocount#2{%
3004 \edef\pgfplots@loc@TMPa{\pgf@sys@tonumber{#1}}%
3005 \pgfmathfloatparsenumber{\pgfplots@loc@TMPa}%
3006 \expandafter\pgfmathfloat@decompose@E\pgfmathresult\relax#2
3007 \advance#2 by1\relax
3008 }
3009
3010 % helper for \pgfplots@check@and@apply@datatrafo@for.
3011 %
3012 \def\pgfplots@compute@number@order@for@trafo@isfloat#1\tocount#2{%
3013 \pgfmathfloatparsenumber{#1}%
3014 \expandafter\pgfmathfloat@decompose@E\pgfmathresult\relax#2\relax
3015 \advance#2 by1
3016 }
3017
3018 \def\pgfplots@if@is@float@zero#1#2#3{%
3019 \pgfmathfloatparsenumber{#1}%
3020 \pgfmathfloatgetflags{\pgfmathresult}{\c@pgf@countd}%
3021 \ifnum\c@pgf@countd=0 %
3022 % ah - it *is* 0.0:
3023 #2%
3024 \else
3025 #3%
3026 \fi
3027 }
3028
3029 % Initialises the data scale transformation such that it is optimal
3030 % for direction #1 (using its axis limits and the target scaling size).
3031 %
3032 % Note that it will not be applied in any way; and it may still be
3033 % modified.
3034 %
3035 % PRECONDITION:
3036 % - all axis limits are available in float representation
3037 % - \pgfplots@set@default@size@options has been called before
3038 % POSTCONDITION:
3039 % - the scaling transformation is set up,
3040 \def\pgfplots@set@optimal@datatrafo@for@#1{%
3041 \pgfplots@if{pgfplots@apply@datatrafo@#1}{%
3042 % initialise data scale transformation
3043 % T(x) = 10^{q-m} * x
3044 %
3045 \ifpgfplots@disabledatascaling
3046 % this here is a waste of time, because the NO-OP trafo
3047 % will be applied to all coordinates. One could really
3048 % safe a lot of CPU time when disabledatascaling is enabled...
3049 % but it requires so much extra cases; I really don't want
3050 % that!
3051 \gdef\pgfplots@glob@TMPa{0}%
3052 \gdef\pgfplots@glob@TMPb{0}%
3053 \else
3054 \begingroup
3055 \let\data@max@order=\c@pgf@counta
3056 \let\data@cur@order=\c@pgf@countb
3057 \let\data@dimen=\pgf@xa
3058 \let\data@tmp=\pgf@xb
3059 \let\data@dimen@order=\c@pgf@countc
3060 \let\data@EXPONENT=\c@pgf@countd
3061 \expandafter\let\expandafter\pgfplots@display@min@float\csname pgfplots@#1min\endcsname
3062 \expandafter\let\expandafter\pgfplots@display@max@float\csname pgfplots@#1max\endcsname
3063 \expandafter\let\expandafter\pgfplots@data@min@float\csname pgfplots@data@#1min\endcsname
3064 \expandafter\let\expandafter\pgfplots@data@max@float\csname pgfplots@data@#1max\endcsname
3065 \ifpgfplots@autocompute@all@limits
3066 \else
3067 \pgfplotscoordmath{#1}{max}{\pgfplots@display@max@float}{\pgfplots@data@max@float}%
3068 \let\pgfplots@data@max@float=\pgfmathresult
3069 \pgfplotscoordmath{#1}{min}{\pgfplots@display@min@float}{\pgfplots@data@min@float}%
3070 \let\pgfplots@data@min@float=\pgfmathresult
3071 \fi
3072 %
3073 %\message{minmax = [\pgfplots@data@min@float,\pgfplots@data@max@float]^^J}%
3074 % Step 1: compute 'm', the data order
3075 \pgfplots@if@is@float@zero{\pgfplots@data@min@float}{%
3076 \pgfplots@if@is@float@zero{\pgfplots@data@max@float}{%
3077 \data@max@order=1 % both are zero. ok.
3078 % Note that this is '1' due to backwards
3079 % compatibility.
3080 }{%
3081 % one of them is zero. Take the other one!
3082 \pgfplots@compute@number@order@for@trafo@isfloat
3083 \pgfplots@data@max@float
3084 \tocount\data@cur@order
3085 \data@max@order=\data@cur@order
3086 }%
3087 }{%
3088 \pgfplots@if@is@float@zero{\pgfplots@data@max@float}{%
3089 % one of them is zero. Take the other one!
3090 \pgfplots@compute@number@order@for@trafo@isfloat
3091 \pgfplots@data@min@float
3092 \tocount\data@cur@order
3093 \data@max@order=\data@cur@order
3094 }{%
3095 % none of them is zero. Compute MAX:
3096 \pgfplots@compute@number@order@for@trafo@isfloat
3097 \pgfplots@data@min@float
3098 \tocount\data@cur@order
3099 \data@max@order=\data@cur@order
3100 \pgfplots@compute@number@order@for@trafo@isfloat
3101 \pgfplots@data@max@float
3102 \tocount\data@cur@order
3103 \ifnum\data@cur@order>\data@max@order
3104 \data@max@order=\data@cur@order
3105 \fi
3106 }%
3107 }%
3108 %
3109 %
3110 %
3111 % Step 2: compute 'q', the #1-size of the axis.
3112 %\expandafter\ifx\csname pgfplots@#1\endcsname\pgfutil@empty
3113 % We have 'width' or 'height' (I always have them).
3114 %
3115 % Use the order of these parameters.
3116 \def\pgfplots@loc@TMPa{#1}%
3117 \def\pgfplots@loc@TMPb{x}%
3118 \ifx\pgfplots@loc@TMPa\pgfplots@loc@TMPb
3119 \data@dimen=\pgfplots@width\relax
3120 \else
3121 \if1\pgfplots@compat@scaling@zunitfix@enable
3122 \data@dimen=\pgfplots@height\relax
3123 \else
3124 % this code here belongs to versions up to
3125 % 1.3.1.
3126 % It is now deprecated and produces small
3127 % pixel differences.
3128 \def\pgfplots@loc@TMPb{y}%
3129 \ifx\pgfplots@loc@TMPa\pgfplots@loc@TMPb
3130 \data@dimen=\pgfplots@height\relax
3131 \else
3132 \data@dimen=42pt % this is actually different from 1.3.1: there, it was UNDEFINED.
3133 \fi
3134 \fi
3135 \fi
3136 \pgfplots@compute@number@order@for@trafo@isdimen
3137 \data@dimen
3138 \tocount\data@dimen@order
3139 % This here is to avoid inaccuracies in the final
3140 % axis rectangle size, see \pgfplots@initsizes:
3141 %\advance\data@dimen@order by-1
3142 %\else
3143 % FIXME:
3144 % we have either the 'x=1cm' or 'y=1cm' option!
3145 % How should I initialise the trafo!?
3146 % \data@dimen@order=3
3147 %\fi
3148 %
3149 %\message{Direction #1: data max order=\the\data@max@order; data dimen order=\the\data@dimen@order. ^^J}%
3150 \data@EXPONENT=\data@dimen@order
3151 \advance\data@EXPONENT by-\data@max@order
3152 % Now, I introduce a loop which shall avoid cancellation of
3153 % significant digits.
3154 %
3155 % Harmless Example:
3156 % if we have data shift = -3 and
3157 % max = 2e6, min = 1e6, then max-min = 1e6; T(max)-T(min) = 1e3 which is ok.
3158 % In this case, the loop won't change anything.
3159 %
3160 % Critical Example:
3161 % if we have data shift = -3 and
3162 % max = 1980, min = 1930 then
3163 % T(max) = 1.98 and T(min) = 1.93
3164 % and thus T(max)-T(min) = 0.05 .
3165 % Considering that this is the axis range
3166 % in which tick labels and plot points need to be computed, we
3167 % only have two or three digits left! That happens because the
3168 % prefix '19' is common and is cancelled in the subtraction.
3169 % Idea: while T(max)-T(min) < O(10^2) -> increase shift by +1
3170 % (and make sure that T(max) < MAX_VALID_TEX_NUMBER).
3171 %
3172 \def\pgfplotscoordmathnotifydatascalesetfor##1{}% disable temporarily. We are just testing it.
3173 \pgfplots@loop@CONTINUEtrue
3174 \pgfutil@loop
3175 \pgfplotscoordmath{#1}{datascaletrafo set params}{\the\data@EXPONENT}{0}%
3176 \pgfplotscoordmath{#1}{datascaletrafo}{\pgfplots@data@min@float}%
3177 \let\pgfplots@min@fixed=\pgfmathresult
3178 \ifpgfplots@loop@CONTINUE
3179 \pgfplotscoordmath{#1}{datascaletrafo}{\pgfplots@data@max@float}%
3180 \let\pgfplots@max@fixed=\pgfmathresult
3181 \data@tmp=\pgfplots@max@fixed pt
3182 %\message{Current trafo EXPONENT for #1 direction: \the\data@EXPONENT; original #1 data limits: [\pgfplots@data@min@float:\pgfplots@data@max@float]; current transformed #1 limits: [\pgfplots@min@fixed:\pgfplots@max@fixed]; cancellation check max-min running...^^J}%
3183 \ifdim\data@tmp<0pt
3184 % I need absolute values here:
3185 \multiply\data@tmp by-1\relax
3186 \fi
3187 \pgfmathsubtract@{\pgfplots@max@fixed}{\pgfplots@min@fixed}%
3188 \data@dimen=\pgfmathresult pt
3189 \pgfplots@loop@CONTINUEfalse
3190 \ifdim\data@tmp<1500pt % a multiplication with '10' results in max = 15000 which is the upper limit.
3191 \ifdim\data@dimen<100pt % I guess if max-min = O(100), we have quite good accuracy
3192 \ifdim\data@dimen<0.0001pt
3193 \else
3194 \advance\data@EXPONENT by1
3195 \pgfplots@loop@CONTINUEtrue
3196 \fi
3197 \fi
3198 \fi
3199 %--------------------------------------------------
3200 % \ifdim\data@dimen>1200pt% FIXME : is this here ok!? CHECK IT!
3201 % \ifdim\data@dimen>7999pt
3202 % \advance\data@EXPONENT by-2
3203 % \else
3204 % \advance\data@EXPONENT by-1
3205 % \fi
3206 % \pgfplots@loop@CONTINUEfalse
3207 % \fi
3208 %--------------------------------------------------
3209 \pgfutil@repeat
3210 \xdef\pgfplots@glob@TMPa{\the\data@EXPONENT}%
3211 \xdef\pgfplots@glob@TMPb{\pgfplots@min@fixed}%
3212 \endgroup
3213 \fi
3214 % COMPLETE INITIALISATION:
3215 %\message{Initialising the data scale transformation in direction #1 to 10^\pgfplots@glob@TMPa*#1 - \pgfplots@glob@TMPb...^^J}%
3216 \pgfplotscoordmath{#1}{datascaletrafo set params}{\pgfplots@glob@TMPa}{\pgfplots@glob@TMPb}%
3217 }{%
3218 % case apply trafo == false:
3219 \pgfplotscoordmath{#1}{datascaletrafo set params}{0}{0}%
3220 }%
3221 }
3222
3223
3224 \def\pgfplots@set@optimal@datatrafos@allaxes{%
3225 \pgfplots@letcsname pgfplots@xmin@unscaled@as@float={pgfplots@xmin}%
3226 \pgfplots@letcsname pgfplots@xmax@unscaled@as@float={pgfplots@xmax}%
3227 %
3228 \pgfplots@letcsname pgfplots@ymin@unscaled@as@float={pgfplots@ymin}%
3229 \pgfplots@letcsname pgfplots@ymax@unscaled@as@float={pgfplots@ymax}%
3230 %
3231 \pgfplots@letcsname pgfplots@zmin@unscaled@as@float={pgfplots@zmin}%
3232 \pgfplots@letcsname pgfplots@zmax@unscaled@as@float={pgfplots@zmax}%
3233 %
3234 \pgfplots@ifneeds@one@uniform@datascale{%
3235 % Ah - we have to ensure that there is ONE common scale for
3236 % each unit (x, y, and z have the same).
3237 %
3238 % In this case, we need to choose one of the transformations
3239 % and apply it to all axes -- such that each axis gets the
3240 % same scale.
3241 %
3242 % this mode is used for axis equal and its variants.
3243 %
3244 % The strategy to fix the transformation is as follows:
3245 % 1. we assume that axis limits will be enlarged in order to
3246 % satisfy 'scale uniformly'.
3247 % 2. we assume that the LARGEST axis limit dominates the
3248 % others.
3249 % 3. if one of the axes does not have datascaling (i.e. is
3250 % log scale), we disable all other datascalings.
3251 %
3252 % Consequently, we search for the axis with the largest limit
3253 % - and copy its data scaling to all other axes. If one of the
3254 % axes is log, that one overrules it and all data scaling
3255 % effects are disabled..
3256 \ifpgfplots@disabledatascaling
3257 \def\pgfplots@loc@TMPd##1{%
3258 \pgfplotscoordmath{##1}{datascaletrafo set params}{0}{0}%
3259 }%
3260 \else
3261 \begingroup
3262 \let\pgfplots@data@scale@trafo@EXPONENT@common=\pgfutil@empty
3263 \ifpgfplots@disabledatascaling
3264 \def\pgfplots@data@scale@trafo@EXPONENT@common{{0}{0}}% disable scaling!
3265 \fi
3266 \def\pgfplots@data@scale@trafo@EXPONENT@common@arg{-}% this should not match anything in this context.
3267 \pgfplots@if{pgfplots@apply@datatrafo@x}{%
3268 }{%
3269 \def\pgfplots@data@scale@trafo@EXPONENT@common{{0}{0}}% disable scaling!
3270 }%
3271 \pgfplots@if{pgfplots@apply@datatrafo@y}{%
3272 }{%
3273 \def\pgfplots@data@scale@trafo@EXPONENT@common{{0}{0}}% disable scaling!
3274 }%
3275 \ifpgfplots@threedim
3276 \pgfplots@if{pgfplots@apply@datatrafo@z}{%
3277 }{%
3278 \def\pgfplots@data@scale@trafo@EXPONENT@common{{0}{0}}% disable scaling!
3279 }%
3280 \fi
3281 \ifx\pgfplots@data@scale@trafo@EXPONENT@common\pgfutil@empty
3282 % ah - we still need to compute one. ok, search for the
3283 % largest limit.
3284 %
3285 \pgfplots@get@axis@with@largest@limits
3286 \let\pgfplots@data@scale@trafo@EXPONENT@common@arg=\pgfplotsretval
3287 %
3288 % ok, compute data scaling transformation for the target axis:
3289 \expandafter\pgfplots@set@optimal@datatrafo@for@\pgfplots@data@scale@trafo@EXPONENT@common@arg%
3290 %
3291 \pgfplotscoordmath{\pgfplots@data@scale@trafo@EXPONENT@common@arg}{datascaletrafo get params}%
3292 \let\pgfplots@data@scale@trafo@EXPONENT@common=\pgfmathresult%
3293 \else
3294 % hm. early-out - we already have the scaling trafo.
3295 % return it.
3296 \fi
3297 \global\let\pgfplots@glob@TMPa=\pgfplots@data@scale@trafo@EXPONENT@common
3298 \global\let\pgfplots@glob@TMPb=\pgfplots@data@scale@trafo@EXPONENT@common@arg
3299 \endgroup
3300 %
3301 \xdef\pgfplots@glob@TMPc{\expandafter\pgfutil@firstoftwo\pgfplots@glob@TMPa}%
3302 %
3303 \def\pgfplots@loc@TMPd##1{%
3304 \if ##1\pgfplots@glob@TMPb
3305 % we need to set the scaling trafo for the target direction
3306 % (was lost after \endgroup)
3307 \def\pgfplots@loc@TMPa{\pgfplotscoordmath{##1}{datascaletrafo set params}}%
3308 \expandafter\pgfplots@loc@TMPa\pgfplots@glob@TMPa%
3309 \else
3310 \pgfplotscoordmath{##1}{datascaletrafo set params}{\pgfplots@glob@TMPc}{0}%
3311 \pgfplotscoordmath{##1}{datascaletrafo}{\csname pgfplots@##1min\endcsname}%
3312 \pgfplotscoordmath{##1}{datascaletrafo set params}{\pgfplots@glob@TMPc}{\pgfmathresult}%
3313 \fi
3314 }%
3315 \fi
3316 \pgfplots@loc@TMPd x%
3317 \pgfplots@loc@TMPd y%
3318 \ifpgfplots@threedim
3319 \pgfplots@loc@TMPd z%
3320 \fi
3321 }{%
3322 % optimize individually:
3323 \pgfplots@set@optimal@datatrafo@for@ x%
3324 \pgfplots@set@optimal@datatrafo@for@ y%
3325 \ifpgfplots@threedim
3326 \pgfplots@set@optimal@datatrafo@for@ z%
3327 \fi
3328 }%
3329 %
3330 }%
3331
3332 % Defines \pgfplotsretval to be one of x, y, or z, such that the
3333 % return value indicates the axis with largest untransformed axis
3334 % limits.
3335 \def\pgfplots@get@axis@with@largest@limits{%
3336 \begingroup
3337 \let\pgfplotsretval@extreme=\pgfutil@empty
3338 \let\pgfplotsretval@extreme@arg=\pgfutil@empty
3339 \def\pgfplots@@##1{%
3340 % compute axis range for axis ##1 ...
3341 \pgfplotscoordmath{default}{parsenumber}{\csname pgfplots@##1min\endcsname}%
3342 \let\pgfplots@loc@TMPa=\pgfmathresult
3343 \pgfplotscoordmath{default}{parsenumber}{\csname pgfplots@##1max\endcsname}%
3344 \pgfplotscoordmath{default}{op}{subtract}{{\pgfmathresult}{\pgfplots@loc@TMPa}}%
3345 % ... ok, it is in \pgfmathresult.
3346 \let\candidate=\pgfmathresult
3347 \ifx\pgfplotsretval@extreme@arg\pgfutil@empty
3348 % ah: no extreme value so far. use ours.
3349 \def\pgfplotsretval@extreme@arg{##1}%
3350 \let\pgfplotsretval@extreme=\candidate
3351 \else
3352 \pgfplotscoordmath{default}{if less than}{\pgfplotsretval@extreme}{\candidate}{%
3353 % update extreme value:
3354 \def\pgfplotsretval@extreme@arg{##1}%
3355 \let\pgfplotsretval@extreme=\candidate
3356 }{%
3357 }%
3358 \fi
3359 }%
3360 \pgfplots@@ x%
3361 \pgfplots@@ y%
3362 \ifpgfplots@threedim
3363 \pgfplots@@ z%
3364 \fi
3365 \let\pgfplotsretval=\pgfplotsretval@extreme@arg
3366 \pgfmath@smuggleone\pgfplotsretval
3367 \endgroup
3368 }%
3369
3370 % Initialises the data scale transformation and applies it to any
3371 % user specified options.
3372 %
3373 % PRECONDITION:
3374 % - all axis limits are available in float representation
3375 % - \pgfplots@set@default@size@options has been called before
3376 % - the scaling transformation for direction x is set up
3377 % (\pgfplots@set@optimal@datatrafo@for@),
3378 % POSTCONDITION:
3379 % - all axis limits are transformed, but no other axis inputs.
3380 %
3381 % Unit vectors and other axis input parameters will be scaled later.
3382 %
3383 % @see \pgfplots@check@and@apply@datatrafo@for
3384 \def\pgfplots@apply@datatrafo@to@axis@limits#1{%
3385 \pgfplots@if{pgfplots@apply@datatrafo@#1}{%
3386 % Transform axis limits:
3387 %\message{#1- display limits BEFORE data transformation: [\csname pgfplots@#1min\endcsname:\csname pgfplots@#1max\endcsname]^^J}%
3388 \pgfplotscoordmath{#1}{datascaletrafo}{\csname pgfplots@#1min\endcsname}%
3389 \expandafter\global\expandafter\let\csname pgfplots@#1min\endcsname=\pgfmathresult
3390 %
3391 \pgfplotscoordmath{#1}{datascaletrafo}{\csname pgfplots@#1max\endcsname}%
3392 \expandafter\global\expandafter\let\csname pgfplots@#1max\endcsname=\pgfmathresult
3393 %\message{#1- display limits after data transformation: [\csname pgfplots@#1min\endcsname:\csname pgfplots@#1max\endcsname]^^J}%
3394 }{%
3395 % case apply trafo == false:
3396 \expandafter\let\csname pgfplots@#1min@unscaled@as@float\endcsname=\pgfutil@empty
3397 \expandafter\let\csname pgfplots@#1max@unscaled@as@float\endcsname=\pgfutil@empty
3398 }%
3399 }