Debian Codegraph @

texmf-dist/tex/generic/pgfplots/pgfplotsstackedplots.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-2013 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 %
28 % This file contains the implementation for stacked plots.
29 %
30 % Stacked plots always keep record of the last plotted coordinates.
31 % Any new plot will be ADDED on top of the last plotted coordinates.
32 %
33 % Terminology: "last plotted coordinates" are called "zero levels"
34 % because they actually work like shifts.
35 %
36 % Programming Structure:
37 %
38 % 1. We keep TWO lists of coordinates: a list of CURRENT zero level
39 % coordinates and a list of NEXT zero level coordinates.
40 %
41 % The first one will be queried whenever a zero level coordinate is
42 % requested.
43 %
44 % The second one will be used to form zero levels for the next plot.
45 %
46 % 2. At the beginning and end of the survey phase of each plot, the lists in 1.) are
47 % initialised properly.
48 %
49 % 3.1 While plot coordinates are processed during the survey phase, the following methods
50 % interact with the stacked API:
51 % \pgfplots@stacked@preparepoint@inmacro
52 % -> compute the 'stacked' sum.
53 % This may need to be done with floating point arithmetics because
54 % the data scaling trafo is not yet initialised
55 % \pgfplots@stacked@rememberzerolevelpoint@for@next@plot
56 % \pgfplots@stacked@getnextzerolevelpoint
57 %
58 %
59 % 3.2 during the final visualization phase, we have
60 % \pgfplots@stacked@visphasepreparedatapoint
61 % -> takes coordinates as they will be given to Tikz. This method is
62 % used to
63 % - communicate zero level coordinates to Tikz
64 % - implement the 'closed paths' option (allows filled stacked plots).
65 %
66 % 4. Zero levels are communicated to Tikz by
67 % \pgfplots@stacked@initzerolevelhandler. This routine initialises an
68 % input stream for Tikz plot handlers which produces a sequence of
69 % zero levels. It is used by [xy]comb and [xy]bar.
70 %
71 %
72
73 \let\pgfplots@stacked@zerolevelpoint@x=\pgfutil@empty
74 \let\pgfplots@stacked@zerolevelpoint@y=\pgfutil@empty
75
76 % this value is populated during the survey phase. It will be copied
77 % to the visualization phase, i.e. it will be serialized along with
78 % the survey'ed state:
79 \newif\ifpgfplots@stacked@isfirstplot
80 \newif\ifpgfplots@stacked@isinitialised
81
82 % Pre-initialisation.
83 % Needs to be called before the first call to
84 % \pgfplots@stacked@beginplot.
85 \def\pgfplots@stacked@initialise{%
86 \gdef\pgfplots@stacked@coordcount{-1}%
87 \pgfplots@stacked@isfirstplottrue
88 \pgfplots@stacked@isinitialisedtrue
89 }%
90
91 % Cleanup method. Truncates any global variables to reduce string
92 % space.
93 \def\pgfplots@stacked@finalize{%
94 \global\pgfplotslistnewempty\pgfplots@stacked@zerolevellist
95 \global\pgfplotslistnewempty\pgfplots@stacked@zerolevellist@neg
96 \global\pgfplotslistnewempty\pgfplots@stacked@nextzerolevellist@pos
97 \global\pgfplotslistnewempty\pgfplots@stacked@nextzerolevellist@neg
98 \pgfplots@stacked@isinitialisedfalse
99 }%
100
101 % (Re)defines the macro \pgfplots@stacked@getnextzerolevelpoint
102 % at the beginning of each plot.
103 %
104 % The macro \pgfplots@stacked@getnextzerolevelpoint fills
105 % \pgfplots@stacked@zerolevelpoint@[xy].
106 %
107 % ATTENTION: call \pgfplots@stacked@initialise before the first call
108 % of beginplot!
109 %
110 % ATTENTION: install this before 'visualization depends on' - it
111 % modifies \pgfplotsaxisserializedatapoint@private
112 \def\pgfplots@stacked@beginplot{%
113 %\message{pgfplots@stacked@beginplot: PLOT STARTED.}%
114 \ifpgfplots@stacked@isinitialised
115 \else
116 \pgfplots@error{LOGIC ERROR: please call \string\pgfplots@stacked@initialise.}%
117 \fi
118 \def\pgfplots@stacked@zerolevel@current{}%
119 \def\pgfplots@stacked@zerolevel@current@pos{}%
120 \def\pgfplots@stacked@zerolevel@current@neg{}%
121 \pgfplots@stacked@prepare@value@serialization
122 % accumulate this command here for \closedcycle:
123 \ifpgfplots@stacked@isfirstplot
124 \global\pgfplotslistnewempty\pgfplots@stacked@zerolevellist
125 \global\pgfplotslistnewempty\pgfplots@stacked@zerolevellist@neg
126 % only work with float if its really necessary - for
127 % example if the scaling trafo which maps to pgfmath is
128 % not yet initialised.
129 \pgfplots@stacked@zerolevel@fallback x%
130 \pgfplots@stacked@zerolevel@fallback y%
131 \pgfplots@stacked@zerolevel@fallback z%
132 %
133 \def\pgfplots@stacked@getnextzerolevelpoint{%
134 % keep \pgfplots@stacked@zerolevel@current = {}
135 % there is special handling in place which will use the
136 % '0' level in this case
137 %
138 % omit this:
139 %\pgfplots@stacked@ensure{}%
140 %\let\pgfplots@stacked@zerolevel@current=\pgfplotsretval
141 }%
142 \else
143 {\globaldefs=1
144 \pgfplotslistcopy\pgfplots@stacked@nextzerolevellist@pos\to\pgfplots@stacked@zerolevellist
145 \pgfplotslistcopy\pgfplots@stacked@nextzerolevellist@neg\to\pgfplots@stacked@zerolevellist@neg
146 }%
147 \def\pgfplots@stacked@getnextzerolevelpoint{%
148 %
149 \pgfplots@stacked@getnextzerolevelpoint@pos
150 %
151 \if P\pgfplots@stacked@negative@mode
152 % stack negative=on previous:
153 % just use one list in order to remember the
154 % zerolevel:
155 \expandafter\pgfplots@stacked@parsezerolevelpoint\expandafter{\pgfplots@stacked@zerolevel@current@pos}%
156 \else
157 % stack negative=separate:
158 % use two levels, one for '+' and one for '-':
159 \pgfplots@stacked@getnextzerolevelpoint@neg
160 %
161 \if+\pgfplots@stacked@sign
162 \expandafter\pgfplots@stacked@parsezerolevelpoint\expandafter{\pgfplots@stacked@zerolevel@current@pos}%
163 \else
164 \expandafter\pgfplots@stacked@parsezerolevelpoint\expandafter{\pgfplots@stacked@zerolevel@current@neg}%
165 \fi
166 \fi
167 }%
168 \fi
169 \global\pgfplotslistnewempty\pgfplots@stacked@nextzerolevellist@pos
170 \global\pgfplotslistnewempty\pgfplots@stacked@nextzerolevellist@neg
171 }%
172
173 \def\pgfplots@stacked@getnextzerolevelpoint@pos{%
174 \pgfplotslistcheckempty\pgfplots@stacked@zerolevellist
175 \ifpgfplotslistempty
176 \pgfplots@stacked@wrong@count@error
177 \else
178 {\globaldefs=1
179 \pgfplotslistpopfront\pgfplots@stacked@zerolevellist\to\pgfplots@stacked@zerolevel@current@pos
180 }%
181 \fi
182 }%
183 \def\pgfplots@stacked@getnextzerolevelpoint@neg{%
184 \pgfplotslistcheckempty\pgfplots@stacked@zerolevellist@neg
185 \ifpgfplotslistempty
186 \pgfplots@stacked@wrong@count@error
187 \else
188 {\globaldefs=1
189 \pgfplotslistpopfront\pgfplots@stacked@zerolevellist@neg\to\pgfplots@stacked@zerolevel@current@neg
190 }%
191 \fi
192 }
193
194 \def\pgfplots@stacked@zerolevel@fallback#1{%
195 \pgfplots@stacked@zerolevel@fallback@{#1}%
196 \expandafter\let\csname pgfplots@stacked@zerolevelpoint@#1\endcsname=\pgfmathresult%
197 }%
198 \def\pgfplots@stacked@zerolevel@fallback@#1{%
199 \ifpgfplots@datascaletrafo@initialised % FIXME : should be '!ifsurvey'
200 \def\pgfmathresult{0}%
201 \else
202 % note that log plots are special: their "stacked zero" is
203 % computed with \pgfplotscoordmath{default}
204 %
205 \pgfplots@if{pgfplots@#1islinear}{\pgfplotscoordmath{#1}{zero}}{\pgfplotscoordmath{default}{zero}}%
206 \fi
207 }%
208
209 % ATTENTION: install this before 'visualization depends on' - it
210 % modifies \pgfplotsaxisserializedatapoint@private
211 \def\pgfplots@stacked@visphase@beginplot{%
212 %\message{pgfplots@stacked@beginplot: VISUALIZATION OF PLOT STARTED (phase = \pgfplots@visphase@name).^^J}%
213 \let\pgfplots@stacked@closedcycle@impl=\pgfutil@empty
214 \pgfplots@stacked@prepare@value@serialization
215 }%
216
217 \def\pgfplots@stacked@prepare@value@serialization{%
218 % This here is SIMILAR to 'visualization depends on'.
219 %
220 % The only difference is that 'visualization depends on' expands
221 % its arguments whereas this one here does not.
222 %
223 \pgfplotsset{%
224 visualization depends on=value \pgfplots@stacked@diff\as\pgfplots@stacked@diff
225 }%
226 %
227 %
228 % Modify the axis private parts such that a data point is
229 % serialized to the form
230 % {Z{<stacked zerolevel value>}{<point meta>};<x coordinate>,<y coordinate>,<z coordinate>}
231 %
232 % for example, a 2d data point (0,1) without point meta is serialized to
233 % {Z{}{};0Y0.0e0],1Y1.0e0],}
234 %
235 % The deserialization looks for the magic token 'Z'. The next
236 % parameter is the zero level of the data point, the following one
237 % the "old" private serialization stuff (typically just point
238 % meta).
239 %
240 % Note that the zero level of a data point might have its own zero
241 % level (grand father) ... this would be part here as well, even
242 % if it is useless (?). This causes recursive references to all
243 % zero levels... and more memory for stacked plots.
244 %
245 % The zero'th level has an empty zero level point.
246 \expandafter\def\expandafter\pgfplotsaxisserializedatapoint@private\expandafter{%
247 \pgfplotsaxisserializedatapoint@private
248 % at deserialization time, this will become \pgfplots@stacked@zerolevel :
249 \t@pgfplots@toka=\expandafter{\pgfplots@stacked@zerolevel@current}%
250 \t@pgfplots@tokb=\expandafter{\pgfplotsretval}%
251 \edef\pgfplotsretval{%
252 Z{\the\t@pgfplots@toka}%
253 {\the\t@pgfplots@tokb}%
254 }%
255 }%
256 %
257 \pgfutil@ifundefined{pgfplotsaxisdeserializedatapointfrom@private@backup@}{}{%
258 \pgfplots@error{Illegal internal state encountered: the stacked plots serialization preparation has been invoked twice}%
259 }%
260 \let\pgfplotsaxisdeserializedatapointfrom@private@backup@=\pgfplotsaxisdeserializedatapointfrom@private
261 \def\pgfplotsaxisdeserializedatapointfrom@private##1{%
262 \pgfplotsaxisdeserializedatapointfrom@private@stacked@##1%
263 }%
264 }%
265
266 \def\pgfplotsaxisdeserializedatapointfrom@private@stacked@ Z#1#2{%
267 \def\pgfplots@stacked@zerolevel{#1}%
268 \pgfplotsaxisdeserializedatapointfrom@private@backup@{#2}%
269 }%
270
271 % #1: the result of \pgfplotsaxisserializedatapointtostring
272 \def\pgfplots@stacked@parsezerolevelpoint#1{%
273 \begingroup
274 \pgfplotsaxisdeserializedatapointfrom#1% no braces here!
275 % \pgfplotsplothandlerdeserializepointfrom{#1}%
276 \pgfplots@stacked@smuggle
277 \endgroup
278 % the value of \pgfplots@stacked@zerolevel@current will be configured as
279 % "visualization depends on".
280 % In other words: it is available later-on.
281 \def\pgfplots@stacked@zerolevel@current{#1}%
282 }
283
284 \def\pgfplots@stacked@smuggle\endgroup{%
285 \xdef\pgfplots@glob@TMPb{%
286 \noexpand\def\noexpand\pgfplots@stacked@zerolevelpoint@x{\pgfplots@current@point@x}%
287 \noexpand\def\noexpand\pgfplots@stacked@zerolevelpoint@y{\pgfplots@current@point@y}%
288 \noexpand\def\noexpand\pgfplots@stacked@zerolevelpoint@z{\pgfplots@current@point@z}%
289 }%
290 \endgroup
291 \pgfplots@glob@TMPb
292 }%
293
294 \def\pgfplots@stacked@wrong@count@error{%
295 \pgfplots@error{Sorry, pgfplots expects stacked plots to have exactly the same number of coordinates. Unfortunately, I encountered at plot with DIFFERENT NUMBERS OF COORDINATES. Please verify that 1. no point has been dropped by coordinate filters (for example log(0) or so) and 2. all plots have the same number of coordinates.}%
296 }%
297
298 \def\pgfplots@stacked@survey@endplot{%
299 %\message{Stacked plot survey phase end: isfirst = \ifpgfplots@stacked@isfirstplot true \else false\fi^^J}%
300 \ifpgfplots@stacked@isfirstplot
301 \pgfplotslistcheckempty\pgfplots@stacked@zerolevellist
302 \ifpgfplotslistempty
303 \else
304 \pgfplots@stacked@wrong@count@error
305 \fi
306 \if P\pgfplots@stacked@negative@mode
307 % stack negative=on previous:
308 \else
309 % stack negative=separate:
310 \pgfplotslistcheckempty\pgfplots@stacked@zerolevellist@neg
311 \ifpgfplotslistempty
312 \else
313 \pgfplots@stacked@wrong@count@error
314 \fi
315 \fi
316 \fi
317 \ifpgfplots@stacked@isfirstplot
318 \def\pgfplots@stacked@serialized@commands{\noexpand\pgfplots@stacked@isfirstplottrue}%
319 \else
320 \def\pgfplots@stacked@serialized@commands{\noexpand\pgfplots@stacked@isfirstplotfalse}%
321 \fi
322 \global\pgfplots@stacked@isfirstplotfalse
323 }%
324
325 \def\pgfplots@stacked@visphase@endplot{%
326 %\message{Stacked plot vis phase end: isfirst = \ifpgfplots@stacked@isfirstplot true \else false\fi^^J}%
327 \ifpgfplots@stacked@isfirstplot
328 \let\pgfplots@stacked@closedcycle@impl=\pgfplots@path@closed@cycle@std
329 \else
330 \t@pgfplots@tokc=\expandafter{\pgfplots@stacked@closedcycle@impl}%
331 \edef\pgfplots@stacked@closedcycle@impl{%
332 [mark=none,/utils/exec=\noexpand\pgfplots@try@mirror@plot@handler]
333 --plot coordinates{\the\t@pgfplots@tokc}
334 --cycle
335 }%
336 \fi
337 \global\pgfplots@stacked@isfirstplotfalse
338 }%
339
340 % WARNING: when this method is called, NEITHER
341 % \ifpgfplots@stacked@isfirstplot NOR the zero level lists are
342 % initialised!
343 \def\pgfplots@stacked@initzerolevelhandler{%
344 \if\pgfplots@stacked@dir x
345 \pgfplotxzerolevelstream@@list
346 \pgfplotyzerolevelstreamconstant{\pgfplots@ZERO@y}%
347 \else
348 \pgfplotxzerolevelstreamconstant{\pgfplots@ZERO@x}%
349 \pgfplotyzerolevelstream@@list
350 \fi
351 }%
352
353 % Provides public access to zero levels into some key-value pairs.
354 % Returns the values into a set of keys in the /data point/ prefix.
355 %
356 % The values can be used in 'axis cs'.
357 \def\pgfplotspointgetzerolevelcoordinates{%
358 \pgfplotspointgetnormalizedzerolevelcoordinates
359 \pgfplotspointgetcoordinatesfromnormalized[path=/data point/zero]%
360 \pgfplotspointgetcoordinatesfromnormalized[path=/data point/diff]%
361 }
362
363 % Same as \pgfplotsgetzerolevelcoordinates, but the resulting values
364 % are for use in 'normalized axis cs'.
365 %
366 % This works for both stacked plots and normal plots.
367 \def\pgfplotspointgetnormalizedzerolevelcoordinates{%
368 \begingroup
369 \ifpgfplots@stackedmode
370 % STATE:
371 % * \pgfplots@stacked@diff is the diff of the CURRENT point.
372 % * \pgfplots@stacked@zerolevel is the ENTIRE point of the
373 % zerolevel (consisting of its recursive zerolevel, its own diff, and its x,y coords)
374 % -> we need both
375 \let\pgfplots@stacked@diff@cur=\pgfplots@stacked@diff
376 \ifx\pgfplots@stacked@zerolevel\pgfutil@empty
377 \pgfplotspointgetnormalizedcoordinates%
378 \pgfplotsutilforeachcommasep{x,y,z}\as\pgfplots@loc@TMPa{%
379 \pgfkeysgetvalue{/data point/\pgfplots@loc@TMPa}\pgfplots@loc@TMPb
380 \expandafter\let\csname pgfplots@current@point@\pgfplots@loc@TMPa\endcsname=\pgfplots@loc@TMPb
381 }%
382 \pgfplotscoordmath{\pgfplots@stacked@dir}{zero}%
383 \expandafter\let\csname pgfplots@current@point@\pgfplots@stacked@dir\endcsname\pgfmathresult%
384 %
385 \let\pgfplots@current@point@meta=\pgfutil@empty
386 \pgfkeyssetvalue{/data point/zero/auto}{1}%
387 \else
388 %
389 \expandafter\pgfplotsaxisdeserializedatapointfrom\pgfplots@stacked@zerolevel%
390 \pgfkeyssetvalue{/data point/zero/auto}{0}%
391 \fi
392 %
393 \pgfplotscoordmath{x}{zero}\let\pgfplots@stacked@diff@x=\pgfmathresult%
394 \pgfplotscoordmath{y}{zero}\let\pgfplots@stacked@diff@y=\pgfmathresult%
395 \pgfplotscoordmath{z}{zero}\let\pgfplots@stacked@diff@z=\pgfmathresult%
396 \pgfutil@namelet{pgfplots@stacked@diff@\pgfplots@stacked@dir}{pgfplots@stacked@diff@cur}%
397 \else
398 % Ah - no stacked plot!? Well, than do "something useful":
399 % ... note that we have to use 'pgfbasic' here as that is the
400 % "transformed" format.
401 \pgfplotscoordmath{pgfbasic}{zero}\let\pgfplots@current@point@x=\pgfmathresult%
402 \pgfplotscoordmath{pgfbasic}{zero}\let\pgfplots@current@point@y=\pgfmathresult%
403 \pgfplotscoordmath{pgfbasic}{zero}\let\pgfplots@current@point@z=\pgfmathresult%
404 %
405 \pgfplotspointgetnormalizedcoordinates%
406 \pgfplotsutilforeachcommasep{x,y,z}\as\pgfplots@loc@TMPa{%
407 \pgfkeysgetvalue{/data point/\pgfplots@loc@TMPa}\pgfplots@loc@TMPb
408 \expandafter\let\csname pgfplots@stacked@diff@\pgfplots@loc@TMPa\endcsname=\pgfplots@loc@TMPb
409 }%
410 \pgfkeyssetvalue{/data point/zero/auto}{1}%
411 \fi
412 %
413 \xdef\pgfplots@glob@TMPd{%
414 \noexpand\pgfkeyssetvalue{/data point/zero/x}{\pgfplots@current@point@x}%
415 \noexpand\pgfkeyssetvalue{/data point/zero/y}{\pgfplots@current@point@y}%
416 \noexpand\pgfkeyssetvalue{/data point/zero/z}{\pgfplots@current@point@z}%
417 \noexpand\pgfkeyssetvalue{/data point/zero/meta}{\pgfplots@current@point@meta}%
418 \noexpand\pgfkeyssetvalue{/data point/zero/auto}{\pgfkeysvalueof{/data point/zero/auto}}%
419 \noexpand\pgfkeyssetvalue{/data point/diff/x}{\pgfplots@stacked@diff@x}%
420 \noexpand\pgfkeyssetvalue{/data point/diff/y}{\pgfplots@stacked@diff@y}%
421 \noexpand\pgfkeyssetvalue{/data point/diff/z}{\pgfplots@stacked@diff@z}%
422 }%
423 \endgroup
424 \pgfplots@glob@TMPd
425 %
426 %\message{pgfplotsgetzerolevelcoordinates returned x=\pgfkeysvalueof{/data point/zero/x}, y=\pgfkeysvalueof{/data point/zero/y}, diffx=\pgfkeysvalueof{/data point/diff/x}; diffy=\pgfkeysvalueof{/data point/diff/y}, diff=\pgfkeysvalueof{/data point/diff}^^J}%
427 }%
428
429 % PRECONDITION:
430 % Is in invoked inside of a coord preparation routine, that means
431 % - \pgfplots@current@point@[xyz]
432 % - \ifpgfplots@curplot@threedim
433 % are all set properly.
434 %
435 % POSTCONDITION:
436 % - the zero level macro is set (for use in the visualizer)
437 % - the closed cycle impl is updated
438 % - the points as such are NOT touched
439 \def\pgfplots@stacked@visphasepreparedatapoint{%
440 \ifx\pgfplots@stacked@zerolevel\pgfutil@empty
441 % this here is the case if we have the first encountered plot,
442 % i.e. the one on which others are stacked.
443 %
444 % Note that it is not necessarily the first one which is
445 % processed (compare reverse stacked plots).
446 \begingroup
447 % FIXME : eliminate this special handling by recording the
448 % correct '0' values during the survey phase!
449 \pgfutil@namelet{pgfplots@current@point@\pgfplots@stacked@dir}{pgfplots@logical@ZERO@\pgfplots@stacked@dir}%
450 \pgfplotsaxis@toPGF@coords
451 \if\pgfplots@stacked@dir x
452 \edef\pgfplots@stacked@PGF@zerolevel{\the\pgf@x}%
453 \else
454 \edef\pgfplots@stacked@PGF@zerolevel{\the\pgf@y}%
455 \fi
456 \pgfmath@smuggleone\pgfplots@stacked@PGF@zerolevel
457 \endgroup
458 %
459 \else
460 \begingroup
461 %\expandafter\pgfplotsplothandlerdeserializepointfrom\expandafter{\pgfplots@stacked@zerolevel}%
462 \expandafter\pgfplotsaxisdeserializedatapointfrom\pgfplots@stacked@zerolevel%
463 %
464 \pgfplots@stacked@logarithm@if@needed
465 %
466 % avoid endless recursion:
467 \let\pgfplots@stacked@visphasepreparedatapoint=\relax
468 \pgfplotsaxisvisphasegetpoint
469 \edef\pgfplots@current@point@x{\the\pgf@x}%
470 \edef\pgfplots@current@point@y{\the\pgf@y}%
471 % this here merely communicates
472 % \pgfplots@stacked@zerolevelpoint@x and @y outside of the
473 % group:
474 \pgfplots@stacked@smuggle
475 \endgroup
476 %
477 \if\pgfplots@stacked@dir x
478 \let\pgfplots@stacked@PGF@zerolevel=\pgfplots@stacked@zerolevelpoint@x%
479 \else
480 \let\pgfplots@stacked@PGF@zerolevel=\pgfplots@stacked@zerolevelpoint@y%
481 \fi
482 \t@pgfplots@toka=\expandafter{\pgfplots@stacked@closedcycle@impl}%
483 \edef\pgfplots@stacked@closedcycle@impl{%
484 (\pgfplots@stacked@zerolevelpoint@x,\pgfplots@stacked@zerolevelpoint@y)%
485 \the\t@pgfplots@toka}%
486 \fi
487 }%
488
489 % A special hook which is executed early in the visualization phase.
490 % It will be invoked *before*
491 % \pgfplots@stacked@visphasepreparedatapoint!
492 %
493 % Its purpose is to clear the data if necessary, i.e. it implements
494 % /pgfplots/stacked ignores zero
495 \def\pgfplots@stacked@visphase@stream@coord@{%
496 \ifpgfplots@stacked@ignores@zero
497 \edef\pgfplots@loc@TMPa{\pgfkeysvalueof{/pgfplots/stacked ignores zero/\pgfplots@visphase@name}}%
498 \def\pgfplots@loc@TMPb{true}%
499 % apply this feature only if it is active for the current
500 % visualization phase:
501 \ifx\pgfplots@loc@TMPb\pgfplots@loc@TMPa
502 \ifx\pgfplots@current@point@x\pgfutil@empty% this implements `unbounded coords=jump', for example
503 \else
504 \pgfplotscoordmath{\pgfplots@stacked@dir}{if is}{\pgfplots@stacked@diff}{0}{%
505 \let\pgfplots@current@point@x=\pgfutil@empty
506 \let\pgfplots@current@point@y=\pgfutil@empty
507 \let\pgfplots@current@point@z=\pgfutil@empty
508 }{%
509 }%
510 \fi
511 \fi
512 \fi
513 }%
514
515 % PRECONDITION:
516 % Is in invoked inside of a coord preparation routine, that means
517 % - \pgfplots@current@point@[xyz]
518 % - \ifpgfplots@curplot@threedim
519 % are all set properly.
520 %
521 % POSTCONDITION:
522 % - \pgfplots@current@point@[xyz] are adjusted.
523 \def\pgfplots@stacked@preparepoint@inmacro{%
524 \ifpgfplots@stacked@plus
525 \def\pgfplots@stacked@op{add}%
526 \else
527 \def\pgfplots@stacked@op{subtract}%
528 \fi
529 %
530 \pgfutil@namelet{pgfplots@stacked@diff}{pgfplots@current@point@\pgfplots@stacked@dir}%
531 %
532 \pgfmathfloatparsenumber{\pgfplots@stacked@diff}%
533 \expandafter\pgfmathfloatifflags\expandafter{\pgfmathresult}{2}{%
534 \def\pgfplots@stacked@sign{-}%
535 }{%
536 \def\pgfplots@stacked@sign{+}%
537 }%
538 \pgfplots@stacked@getnextzerolevelpoint
539 %
540 %
541 \pgfplots@if{pgfplots@\pgfplots@stacked@dir islinear}{%
542 \pgfplotscoordmath{\pgfplots@stacked@dir}{op}{\pgfplots@stacked@op}{%
543 {\csname pgfplots@stacked@zerolevelpoint@\pgfplots@stacked@dir\endcsname}%
544 {\csname pgfplots@current@point@\pgfplots@stacked@dir\endcsname}}%
545 }{%
546 % LOG. we need to compute log(zerolevel + current):
547 % FIXME : this might work, but is is hackery - because the
548 % coordmath framework handles log bases in a very stupid way.
549 % improve it somehow!
550 \edef\pgfmathresult{\csname pgfplots@current@point@\pgfplots@stacked@dir\endcsname}%
551 \pgfplotscoordmath{\pgfplots@stacked@dir}{exp}{\pgfmathresult}%
552 \pgfplotscoordmath{default}{parsenumber}{\pgfmathresult}%
553 \expandafter\let\csname pgfplots@current@point@\pgfplots@stacked@dir\endcsname=\pgfmathresult
554 \pgfplotscoordmath{default}{op}{\pgfplots@stacked@op}{%
555 {\csname pgfplots@stacked@zerolevelpoint@\pgfplots@stacked@dir\endcsname}%
556 {\csname pgfplots@current@point@\pgfplots@stacked@dir\endcsname}%
557 }%
558 }%
559 %
560 % for logs, I remember just zerolevel+current; not its log.
561 \expandafter\let\csname pgfplots@current@point@\pgfplots@stacked@dir\endcsname=\pgfmathresult
562 %
563 % this here would also be ok, but it would only store the coords
564 % of the zero level...
565 %\pgfplotsplothandlerserializepointto\pgfplotsretval
566 %
567 \begingroup
568 %
569 % without this line, the "zerolevel" would also know all its zero
570 % levels recursively:
571 \pgfplots@stacked@strip@parents@zerolevel
572 %
573 \pgfplotsaxisserializedatapointtostring
574 %
575 %\message{Current value is '\pgfplots@stacked@sign'. Serializing: \meaning\pgfplotsretval^^J}%
576 \if P\pgfplots@stacked@negative@mode
577 % stack negative=on previous:
578 % just track one list
579 \expandafter\pgfplotslistpushbackglobal\expandafter{\pgfplotsretval}\to\pgfplots@stacked@nextzerolevellist@pos
580 \else
581 % stack negative=separate:
582 % keep track of both separate zerolevel lists:
583 \if+\pgfplots@stacked@sign
584 \expandafter\pgfplotslistpushbackglobal\expandafter{\pgfplotsretval}\to\pgfplots@stacked@nextzerolevellist@pos
585 %
586 \pgfplots@stacked@ensure\pgfplots@stacked@zerolevel@current@neg
587 \expandafter\pgfplotslistpushbackglobal\expandafter{\pgfplotsretval}\to\pgfplots@stacked@nextzerolevellist@neg
588 \else
589 \expandafter\pgfplotslistpushbackglobal\expandafter{\pgfplotsretval}\to\pgfplots@stacked@nextzerolevellist@neg
590 %
591 \pgfplots@stacked@ensure\pgfplots@stacked@zerolevel@current@pos
592 \expandafter\pgfplotslistpushbackglobal\expandafter{\pgfplotsretval}\to\pgfplots@stacked@nextzerolevellist@pos
593 \fi
594 \fi
595 %
596 \endgroup
597 %
598 %
599 %
600 \pgfplots@stacked@logarithm@if@needed
601 }
602
603 \def\pgfplots@stacked@ensure#1{%
604 \ifx#1\pgfutil@empty
605 \pgfplots@stacked@zerolevel@fallback@{\pgfplots@stacked@dir}%
606 \expandafter\let\csname pgfplots@current@point@\pgfplots@stacked@dir\endcsname=\pgfmathresult
607 \else
608 \expandafter\pgfplotsaxisdeserializedatapointfrom#1% no braces
609 \fi
610 \pgfplotsaxisserializedatapointtostring
611 %\message{UNUSED value serialized as \meaning\pgfplotsretval^^J}%
612 }%
613
614 %
615 % We store the normal values for zero levels. Consequently, we may
616 % need to (re)apply the log if we have a log axis.
617 %
618 % I am unsure of whether log+stacked is useful at all.
619 \def\pgfplots@stacked@logarithm@if@needed{%
620 \pgfplots@if{pgfplots@\pgfplots@stacked@dir islinear}{%
621 }{%
622 \pgfplotscoordmath{\pgfplots@stacked@dir}{log}{\csname pgfplots@current@point@\pgfplots@stacked@dir\endcsname}%
623 \expandafter\let\csname pgfplots@current@point@\pgfplots@stacked@dir\endcsname=\pgfmathresult
624 }%
625 }%
626
627 % you can \let this here to \relax if you want to gain access to all
628 % zero levels recursively:
629 \def\pgfplots@stacked@strip@parents@zerolevel{%
630 \def\pgfplots@stacked@zerolevel@current{}%
631 }
632
633 % This here is a re-implementation of the stored plot processing.
634 %
635 % The idea is simple, although it requires quite some work:
636 %
637 % If we stack plots on top of each other, early drawing commands
638 % (early plots) will be OVERDRAWN by later drawing commands (later
639 % plots). This is especially unfortunate if we use filled bar plots
640 % or comb plots.
641 %
642 % IDEA: draw plots in REVERSE order. The positioning, styles and
643 % whatever must not be affected, only the sequence of drawing commands
644 % shall change.
645 %
646 % So, this command here reverses the list.
647 \def\pgfplots@stacked@finalize@stored@plots{%
648 \pgfplotslistnewempty\pgfplots@stored@plotlist@reversed
649 \begingroup
650 \pgfplotslistforeachungrouped\pgfplots@stored@plotlist\as\pgfplots@loc@TMPa{%
651 % Reverse sequence:
652 \expandafter\pgfplotslistpushfront\pgfplots@loc@TMPa\to\pgfplots@stored@plotlist@reversed
653 }%
654 % Now, overwrite the original list:
655 \global\let\pgfplots@stored@plotlist=\pgfplots@stored@plotlist@reversed
656 \global\let\pgfplots@stored@plotlist@reversed=\relax
657 \endgroup
658 }%
659
660 \def\pgfplots@stacked@path@closed@cycle{%
661 \pgfplots@stacked@closedcycle@impl
662 }
663
664 % PGF interfaces:
665 %
666 % these are relatively simple right now: assuming that the zero-level
667 % streams are advanced if and only if the coordinate streams are
668 % advanced, we can simply inject the *correct* zero level rather than
669 % providing all at once.
670 \def\pgfplotxzerolevelstream@@list{%
671 \def\pgf@plotxzerolevelstreamstart{%
672 \gdef\pgf@plotxzerolevelstreamnext{%
673 \global\pgf@x=\pgfplots@stacked@PGF@zerolevel\relax
674 }%
675 }%
676 \def\pgf@plotxzerolevelstreamend{%
677 }%
678 }%
679
680 \def\pgfplotyzerolevelstream@@list{%
681 \def\pgf@plotyzerolevelstreamstart{%
682 \gdef\pgf@plotyzerolevelstreamnext{%
683 \global\pgf@x=\pgfplots@stacked@PGF@zerolevel\relax
684 }%
685 }%
686 \def\pgf@plotyzerolevelstreamend{%
687 }%
688 }%
689
690 % Initialize \pgfplots@stacked@diff to 0
691 % Otherwise, if the first point in a plot is NaN \pgfplots@stacked@diff will be
692 % undefined and an error is raised, see issue #219
693 \def\pgfplots@stacked@diff{0}