diff options
author | Karl Berry <karl@freefriends.org> | 2009-02-05 01:04:42 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2009-02-05 01:04:42 +0000 |
commit | ad23c1c436c3e031cc4b81849d0fa2b892851467 (patch) | |
tree | d04be182dbf5cdb14c1728b8f2edddc84f77df03 /Master/texmf-dist/tex/generic/pgfplots/util | |
parent | 4041df693bc0b66ecdf77e891e5ff1a60f1497fc (diff) |
pgfplots update (4feb09)
git-svn-id: svn://tug.org/texlive/trunk@12087 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/generic/pgfplots/util')
-rw-r--r-- | Master/texmf-dist/tex/generic/pgfplots/util/pgfplotscolormap.code.tex | 326 | ||||
-rw-r--r-- | Master/texmf-dist/tex/generic/pgfplots/util/pgfplotsutil.code.tex | 492 |
2 files changed, 791 insertions, 27 deletions
diff --git a/Master/texmf-dist/tex/generic/pgfplots/util/pgfplotscolormap.code.tex b/Master/texmf-dist/tex/generic/pgfplots/util/pgfplotscolormap.code.tex new file mode 100644 index 00000000000..077ca23c946 --- /dev/null +++ b/Master/texmf-dist/tex/generic/pgfplots/util/pgfplotscolormap.code.tex @@ -0,0 +1,326 @@ +%-------------------------------------------- +% $Header: /cvsroot/pgfplots/pgfplots/generic/pgfplots/util/pgfplotscolormap.code.tex,v 1.8 2008/11/30 22:59:31 ludewich Exp $ +% +% Package pgfplots +% +% Provides a user-friendly interface to create function plots (normal +% plots, semi-logplots and double-logplots). +% +% It is based on Till Tantau's PGF package. +% +% Copyright 2007/2008 by Christian Feuersänger. +% +% This program is free software: you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program. If not, see <http://www.gnu.org/licenses/>. +% +%-------------------------------------------- + +% This package relies on pgfplots temporary registers and its array +% data structure. + + +% Creates a new colormap. +% +% #1 : the name of the color map as string (not as macro). +% #2 : a <color specification> as is expected for a colormap. +% +% Example: \pgfplots@createcolormap{my map}{rgb(0cm)=(1,0,0); rgb(1cm)=(0,1,0); rgb(2cm)=(0,0,1); gray(3cm)=(3); color(4cm)=(green); } +\def\pgfplotscreatecolormap#{% + \pgfplots@createcolormap +} +\def\pgfplots@createcolormap#1#2{% + \edef\pgfplots@createcolormap@name{pgfpl@cm@#1}% + \expandafter\pgfplotsarraynewempty\expandafter{\pgfplots@createcolormap@name}% + \def\pgfplots@createcolormap@MIN{0}% NORMALIZATION: assume that lower-end is 0pt. + \let\pgfplots@createcolormap@H=\pgfutil@empty + \def\pgfplots@createcolormap@MAX{0}% To be computed. + \let\pgfplots@createcolormap@LAST=\pgfplots@createcolormap@MIN + % PARSE IT: + \pgfplots@createcolormap@#2] + \expandafter\pgfplotsarraycheckempty\expandafter{\pgfplots@createcolormap@name}% + % sanity checking: + \expandafter\pgfplotsarraysizetomacro\expandafter{\pgfplots@createcolormap@name}\to\pgfplots@loc@TMPa + \ifcase\pgfplots@loc@TMPa\relax + \pgfplots@error{Sorry, you need to provide at least the two end points of a colormap.}% + \or + \pgfplots@error{Sorry, you need to provide at least the two end points of a colormap.}% + \fi + % Map the input range [0pt,MAX] linearly to [0,1000] + \pgfmathdivide@{\pgfplotscolormaprange}{\pgfplots@createcolormap@MAX}% + \let\pgfplots@loc@TMPb=\pgfmathresult + \pgfmathmultiply@{\pgfplots@loc@TMPb}{\pgfplots@createcolormap@H}% + \let\pgfplots@createcolormap@H=\pgfmathresult + \expandafter\let\csname\pgfplots@createcolormap@name @h\endcsname=\pgfplots@createcolormap@H + \pgfmathreciprocal@{\pgfplots@createcolormap@H}% + \expandafter\let\csname\pgfplots@createcolormap@name @invh\endcsname=\pgfmathresult +%\pgfplots@colormap@showdebuginfofor{#1}% +} +\def\pgfplots@createcolormap@{% + \pgfutil@ifnextchar]{\pgfutil@gobble}%done! + {% + \pgfutil@ifnextchar;{\pgfplots@createcolormap@grabsemicolon}% + {% + \pgfutil@ifnextchar r{\pgfplots@createcolormap@grabrgb}% + {% + \pgfutil@ifnextchar g{\pgfplots@createcolormap@grabgray}% + {% + \pgfutil@ifnextchar c{\pgfplots@createcolormap@grabcolor}% + { + \expandafter\pgfutil@ifnextchar\pgfplots@activesemicolon{\pgfplots@createcolormap@grabsemicolon@active}% + {\pgfplots@error{Illformed colormap specification}}% + }% + }% + }% + }% + }% +} +\def\pgfplots@createcolormap@grabsemicolon;{\pgfplots@createcolormap@}% + +{ + \catcode`\;=\active + \gdef\pgfplots@createcolormap@grabsemicolon@active;{\pgfplots@createcolormap@}% +} + +\def\pgfplots@createcolormap@grabrgb rgb(#1)=(#2,#3,#4){% + \pgfplots@createcolormap@nextRGB{#1}{#2}{#3}{#4}% + \pgfplots@createcolormap@} +\def\pgfplots@createcolormap@grabgray gray(#1)=(#2){% + \pgfplots@createcolormap@nextRGB{#1}{#2}{#2}{#2}% + \pgfplots@createcolormap@} +\def\pgfplots@createcolormap@grabcolor color(#1)=(#2){% + \pgfutil@colorlet{pgf@tempcol}{#2}% + \pgfutil@extractcolorspec{pgf@tempcol}{\pgf@tempcolor}% + \expandafter\pgfutil@convertcolorspec\pgf@tempcolor{rgb}{\pgf@rgbcolor}% + \expandafter\pgfplots@createcolormap@grabcolor@\pgf@rgbcolor\relax{#1}}% +\def\pgfplots@createcolormap@grabcolor@#1,#2,#3\relax#4{% + \pgfplots@createcolormap@nextRGB{#4}{#1}{#2}{#3}% + \pgfplots@createcolormap@} +\def\pgfplots@createcolormap@rgbrangeexception#1#2#3{% + \pgfplots@error{Sorry, RGB[#1,#2,#3] is not supported. The allowed range is 0 <= r,g,b <= 1.}% +}% +% Ok, we parsed the next single spec. +% #1: the width +% #2,#3,#4 RGB values. +\def\pgfplots@createcolormap@nextRGB#1#2#3#4{% + \ifdim#2pt<0pt + \pgfplots@createcolormap@rgbrangeexception{#2}{#3}{#4}% + \fi + \ifdim#3pt<0pt + \pgfplots@createcolormap@rgbrangeexception{#2}{#3}{#4}% + \fi + \ifdim#4pt<0pt + \pgfplots@createcolormap@rgbrangeexception{#2}{#3}{#4}% + \fi + \ifdim#2pt>1pt + \pgfplots@createcolormap@rgbrangeexception{#2}{#3}{#4}% + \fi + \ifdim#3pt>1pt + \pgfplots@createcolormap@rgbrangeexception{#2}{#3}{#4}% + \fi + \ifdim#4pt>1pt + \pgfplots@createcolormap@rgbrangeexception{#2}{#3}{#4}% + \fi + % Process 'h': + \pgfmathparse{#1}% + \let\pgfplots@createcolormap@MAX=\pgfmathresult + \expandafter\pgfmathsubtract@\expandafter{\pgfmathresult}{\pgfplots@createcolormap@LAST}% + \let\pgfplots@createcolormap@LAST=\pgfplots@createcolormap@MAX + \let\pgfplots@createcolormap@H@cur=\pgfmathresult +%\message{found current diff = \pgfplots@createcolormap@H@cur\ ( from #1 - \pgfplots@createcolormap@LAST pt)}% + \ifx\pgfplots@createcolormap@H\pgfutil@empty + \expandafter\pgfplotsarraycheckempty\expandafter{\pgfplots@createcolormap@name}% + \ifpgfplotsarrayempty + \ifdim\pgfplots@createcolormap@MAX pt=0pt + \else + \pgfplots@error{Sorry, the left end of a colormap (at 0pt) must be provided explicitly. You cannot start with \pgfplots@createcolormap@MAX pt.}% + \def\pgfplots@createcolormap@MAX{0}% + \fi + \else + \let\pgfplots@createcolormap@H=\pgfplots@createcolormap@H@cur +%\message{H := \pgfplots@createcolormap@H( from #1).}% + \fi + \else + \pgfmathapproxequalto@{\pgfplots@createcolormap@H}{\pgfplots@createcolormap@H@cur}% + \ifpgfmathcomparison + \else + \pgfplots@error{Sorry, non-uniform colormaps are not yet implemented. Please maintain a uniform distance before offset #1 (in this case, I expected h = \pgfplots@createcolormap@H pt).}% + \fi + \fi + % + % Append values: + \def\pgfplots@loc@TMPa{\pgfplotsarraypushback{#2,#3,#4}\to}% + \expandafter\pgfplots@loc@TMPa\expandafter{\pgfplots@createcolormap@name}% +}% + +% Shows debug info about colormap #1 into the console. +\def\pgfplots@colormap@showdebuginfofor#1{% + \message{Debug info for color map '#1':}% + \message{(Transformed) Range: [0:\pgfplotscolormaprange]; }% + \message{H: \csname pgfpl@cm@#1@h\endcsname; }% + \message{H:^{-1}: \csname pgfpl@cm@#1@invh\endcsname; }% + \pgfplotsarraysizetomacro{pgfpl@cm@#1}\to\pgfplots@loc@TMPa + \message{Size: \pgfplots@loc@TMPa; }% + \message{RGB Values: }% + \begingroup + \c@pgf@counta=0 + \pgfplotsarrayforeachungrouped{pgfpl@cm@#1}\as\elem{% + \message{\#\the\c@pgf@counta: \elem; }% + \advance\c@pgf@counta by1 + }% + \endgroup +} + +% Convert a colormap into a PGF shading's color specification for use +% in \pgfdeclare*shading. +% +% #1: the colormap's name. +% #2: the PGF "size" of the shading. It is used to set the right end +% of the color specification. +% #3: a macro which will be filled with the result. +% +% Example: +% \pgfplotscolormaptoshadingspec{my colormap}{4cm}{\output} +% \def\tempb{\pgfdeclarehorizontalshading{myshadingA}{1cm}} +% \expandafter\tempb\expandafter{\temp} +% +% \pgfuseshading{myshadingA} +\def\pgfplotscolormaptoshadingspec#1#2#3{% + \begingroup + \pgfmathparse{#2}% + \expandafter\pgfmathdivide@\expandafter{\pgfmathresult}{\pgfplotscolormaprange}% + \let\pgfplots@loc@TMPb=\pgfmathresult + \pgfmathmultiply@{\csname pgfpl@cm@#1@h\endcsname}{\pgfplots@loc@TMPb}% + \pgf@ya=\pgfmathresult pt + \c@pgf@counta=0 + \let#3=\pgfutil@empty + \pgfplotsarrayforeachungrouped{pgfpl@cm@#1}\as\pgfplots@loc@TMPa{% + \ifnum\c@pgf@counta=0 + \edef\pgfplots@loc@TMPc{rgb(0pt)=(\pgfplots@loc@TMPa)}% + \else + \pgf@yb=\c@pgf@counta\pgf@ya + \edef\pgfplots@loc@TMPc{rgb(\the\pgf@yb)=(\pgfplots@loc@TMPa)}% + \fi + \ifx#3\pgfutil@empty + \t@pgfplots@toka={}% + \else + \t@pgfplots@toka=\expandafter{#3; }% + \fi + \t@pgfplots@tokb=\expandafter{\pgfplots@loc@TMPc}% + \edef#3{\the\t@pgfplots@toka \the\t@pgfplots@tokb }% + \advance\c@pgf@counta by1 + }% + \pgfmath@smuggleone#3% + \endgroup +}% + + +% Expands to the transformed range's right end of every colormap. The left +% end is fixed to '0'. +\def\pgfplotscolormaprange{1000} + +% Linearly maps the number #4 into the colormap #5 and returns the interpolated RGB triple +% into \pgfmathresult. +% +% [#1:#2] the number range of the data source. This is required to +% map into the colormap. +% [#3] (optional) the quantity +% s := \pgfplotscolormaprange / (#2-#1). +% Precomputing this quantity may save a lot of time because +% divisions are expensive in TeX. You can omit [#3] or +% provide an empty string here. +% #4 the number to map. +% #5 the colormap's name. Must be defined with +% \pgfplotscreatecolormap before. +% +% Example: +% \pgfplotscolormapfind[-1:1]{0.2}{my colormap} +\def\pgfplotscolormapfind[#1:#2]{% + \pgfutil@ifnextchar[{% + \pgfplotscolormapfind@precomputed[#1:#2]% + }{% + \pgfplotscolormapfind@precomputed[#1:#2][]% + }% +}% +\def\pgfplotscolormapfind@precomputed[#1:#2][#3]#4#5{% + \begingroup + % Step 0: compute #3 if it is missing and write it into + % \pgfplots@loc@TMPa. + \def\pgfplots@loc@TMPa{#3}% + \ifx\pgfplots@loc@TMPa\pgfutil@empty + \pgfmathsubtract@{#2}{#1}% + \let\pgfplots@loc@TMPb=\pgfmathresult + \pgfmathdivide@{\pgfplotscolormaprange}{\pgfplots@loc@TMPb}% + \let\pgfplots@loc@TMPa=\pgfmathresult + \fi +%\message{mapping '#4' into colormap '#5' ... }% + % Step 1: perform lookup. Map #4 into the colormap's range + % using the linear trafo + % phi(#4) = ( #4 - #1 ) / (#2-#1) * colormaprange(#5). + % This, determine the INTERVAL number into which #4 falls. + \pgfmathsubtract@{#4}{#1}% + \expandafter\pgfmathmultiply@\expandafter{\pgfmathresult}{\pgfplots@loc@TMPa}% + \let\pgfplotscolormapfind@transformedx=\pgfmathresult + \expandafter\pgfmathmultiply@\expandafter{\pgfmathresult}{\csname pgfpl@cm@#5@invh\endcsname}% + \let\pgfplotscolormapfind@transformedx@divh=\pgfmathresult + \expandafter\pgfmathfloor@\expandafter{\pgfmathresult}% + % assign \pgfplotscolormapfind@intervalno := \pgfmathresult + % without '.0' suffix: + \def\pgfplots@discardperiod##1.##2\relax{\def\pgfplotscolormapfind@intervalno{##1}}% + \expandafter\pgfplots@discardperiod\pgfmathresult\relax +%\message{mapping [#1,#2] -> [0,\pgfplotscolormaprange] yielded phi(#4) = \pgfplotscolormapfind@transformedx, situated in interval no \pgfplotscolormapfind@intervalno.}% + % Step 2: interpolate the desired RGB value using vector valued + % interpolation on the identified interval. + \c@pgf@counta=\pgfplotscolormapfind@intervalno\relax + \pgfplotsarrayselect\c@pgf@counta\of{pgfpl@cm@#5}\to\pgfplotscolormapfind@rgb@LEFT + \advance\c@pgf@counta by1 + \pgfplotsarrayselect\c@pgf@counta\of{pgfpl@cm@#5}\to\pgfplotscolormapfind@rgb@RIGHT +%\message{After lookup: the corresponding RGB interval boundaries are [\pgfplotscolormapfind@rgb@LEFT: \pgfplotscolormapfind@rgb@RIGHT].}% + \edef\pgfplots@loc@TMPa{\pgfplotscolormapfind@rgb@LEFT:\pgfplotscolormapfind@rgb@RIGHT}% + \expandafter\pgfplotscolormapfind@interpolate\pgfplots@loc@TMPa\relax + \pgfmath@smuggleone\pgfmathresult + \endgroup +%\message{-> got finally mapping(#4, #5) = RGB'\pgfmathresult'.}% +}% + +% internal helper method which computes +% +% color^m(x) = ( x/h - i ) * ( c_{i+1}^m - c_{i}^m ) + c_i^m +% for each m in {red,green,blue} and defines \pgfmathresult to be +% 'R,G,B' , the single results. +\def\pgfplotscolormapfind@interpolate#1,#2,#3:#4,#5,#6\relax{% + % R: + \pgfmathsubtract@{#4}{#1}% + \let\pgfplotscolormapfind@Cdiff=\pgfmathresult + \pgfmathsubtract@{\pgfplotscolormapfind@transformedx@divh}{\pgfplotscolormapfind@intervalno}% + \expandafter\pgfmathmultiply@\expandafter{\pgfmathresult}{\pgfplotscolormapfind@Cdiff}% + \expandafter\pgfmathadd@\expandafter{\pgfmathresult}{#1}% + \let\RED=\pgfmathresult + % G: + \pgfmathsubtract@{#5}{#2}% + \let\pgfplotscolormapfind@Cdiff=\pgfmathresult + \pgfmathsubtract@{\pgfplotscolormapfind@transformedx@divh}{\pgfplotscolormapfind@intervalno}% + \expandafter\pgfmathmultiply@\expandafter{\pgfmathresult}{\pgfplotscolormapfind@Cdiff}% + \expandafter\pgfmathadd@\expandafter{\pgfmathresult}{#2}% + \let\GREEN=\pgfmathresult + % B: + \pgfmathsubtract@{#6}{#3}% + \let\pgfplotscolormapfind@Cdiff=\pgfmathresult + \pgfmathsubtract@{\pgfplotscolormapfind@transformedx@divh}{\pgfplotscolormapfind@intervalno}% + \expandafter\pgfmathmultiply@\expandafter{\pgfmathresult}{\pgfplotscolormapfind@Cdiff}% + \expandafter\pgfmathadd@\expandafter{\pgfmathresult}{#3}% + \let\BLUE=\pgfmathresult + \edef\pgfmathresult{\RED,\GREEN,\BLUE}% +}% + + +\pgfplotscreatecolormap{hot}{color(0cm)=(blue); color(1cm)=(yellow); color(2cm)=(orange); color(3cm)=(red)} diff --git a/Master/texmf-dist/tex/generic/pgfplots/util/pgfplotsutil.code.tex b/Master/texmf-dist/tex/generic/pgfplots/util/pgfplotsutil.code.tex index e3094554af6..781f5e4937d 100644 --- a/Master/texmf-dist/tex/generic/pgfplots/util/pgfplotsutil.code.tex +++ b/Master/texmf-dist/tex/generic/pgfplots/util/pgfplotsutil.code.tex @@ -24,29 +24,11 @@ % %-------------------------------------------- -\def\pgfplots@EOI{\pgfplots@EOI}% - -\newtoks\t@pgfplots@toka -\newtoks\t@pgfplots@tokb -\newtoks\t@pgfplots@tokc -\newdimen\pgfplots@tmpa - -% use these macros for GLOBAL temporary assignments. -% you can NEVER rely on their values unless you know exactly what you are doing. -\gdef\pgfplots@glob@TMPa{}% -\gdef\pgfplots@glob@TMPb{}% -\gdef\pgfplots@glob@TMPc{}% - -% use these macros for LOCAL temporary assigments. -% you can NEVER rely on their values unless you know exactly what you are doing. -\def\pgfplots@loc@TMPa{}% -\def\pgfplots@loc@TMPb{}% -\def\pgfplots@loc@TMPc{}% - -\input pgfplotsliststructure.code.tex -\input pgfplotsliststructureext.code.tex -\input pgfplotsarray.code.tex -\input pgfplotstable.code.tex +\newif\ifpgfplots@usefpu +\pgfkeys{% + /pgfplots/use fpu/.is if=pgfplots@usefpu, + /pgfplots/use fpu=true, +} % Produces an \aftergroup statement for each single token in #1. % @@ -105,10 +87,18 @@ \fi }% -\def\pgfplots@error#1{\PackageError{pgfplots}{#1}{}}% -\def\pgfplots@warning#1{\pgfplots@message{! Package pgfplots Warning: #1}}% -\def\pgfplots@message#1{% - \immediate\write16{#1}% +% Issues an error message if the **LaTeX** package '#1' is not loaded +% (An error is also raised if the document is not a LaTeX document). +% #1: the required LaTeX package +% #2: the feature which requires this package +\def\pgfplots@assert@LaTeX@package@loaded#1#2{% + \pgfutil@ifundefined{@ifpackageloaded}{% + \pgfplots@error{Sorry, #2 only works with LaTeX (it relies on the LaTeX package #1)}% + }{% + \pgfutil@ifundefined{ver@#1.sty}% this here has been extracted from ltclass.dtx. \@ifpackageloaded is only usable in preamble. + {\pgfplots@error{Sorry, use need \string\usepackage{#1} in your preamble for '#2'}}% + {\relax}% + }% }% \def\pgfplots@assert@tikzinternal@exists#1{% \pgfutil@ifundefined{#1}{% @@ -192,6 +182,11 @@ \def#2{#1}% }% +{ +\catcode`\%=12 +\gdef\pgfplots@PERCENT@TEXT{%} +} + % Usage: % \pgfplots@if{pgfplots@scaled@ticks}{true-code}{false-code} % @@ -204,3 +199,446 @@ #3% \fi }% + +\def\pgfplotsmathmin#1#2{% + \ifdim#1 pt<#2 pt + \edef\pgfmathresult{#1}% + \else + \edef\pgfmathresult{#2}% + \fi +}% +\def\pgfplotsmathmax#1#2{% + \ifdim#1 pt>#2 pt + \edef\pgfmathresult{#1}% + \else + \edef\pgfmathresult{#2}% + \fi +}% +\def\pgfplotsmathlessthan#1#2{\ifdim#1 pt<#2 pt \pgfmathfloatcomparisontrue\else\pgfmathfloatcomparisonfalse\fi} + +% Re-define two-argument function for min and max. +% The pgfmath engine now uses a variable number of arguments. +\def\pgfplotsmathfloatmax#1#2{% + \pgfmathfloatlessthan{#1}{#2}% + \ifpgfmathfloatcomparison + \edef\pgfmathresult{#2}% + \else + \edef\pgfmathresult{#1}% + \fi +} +\def\pgfplotsmathfloatmin#1#2{% + \pgfmathfloatlessthan{#1}{#2}% + \ifpgfmathfloatcomparison + \edef\pgfmathresult{#1}% + \else + \edef\pgfmathresult{#2}% + \fi +} + +% Defines \pgfmathresult to be #1 * 10^{#2}. +% +% #1 a macro without unit suffix. +% #2 an integer number (may be a register) +\def\pgfplotsmathmultiplypowten@#1#2{% + \begingroup + \pgf@xa=#1pt + \ifnum#2<0 + \ifcase-#2 + \or\divide\pgf@xa by10 + \or\divide\pgf@xa by100 + \or\divide\pgf@xa by1000 + \or\divide\pgf@xa by10000 + \or\divide\pgf@xa by100000 + \fi + \else + \ifcase#2 + \or\multiply\pgf@xa by10 + \or\multiply\pgf@xa by100 + \or\multiply\pgf@xa by1000 + \or\multiply\pgf@xa by10000 + \or\multiply\pgf@xa by100000 + \fi + \fi + \edef\pgfmathresult{\pgf@sys@tonumber{\pgf@xa}}% + \pgfmath@smuggleone\pgfmathresult + \endgroup +}% + + +% converts a comma-separated list (PGF foreach) to my internal list +% structure. +\long\def\pgfplots@foreach@to@list#1\to#2{% + \global\pgfplotslistnewempty\pgfplots@glob@TMPa + \begingroup + \foreach \pgfplots@i in {#1} {% + \expandafter\pgfplotslistpushbackglobal\pgfplots@i\to\pgfplots@glob@TMPa + }% + \endgroup + \pgfplotslistcopy\pgfplots@glob@TMPa\to#2\relax +} + +% Simply invokes the code of PGF key #1 with value #2, that means +% #1#2\pgfeov +\def\pgfplots@invoke@pgfkeyscode#1#2{% + \pgfkeysgetvalue{#1}\pgfplots@invoke@pgfkeyscode@CODE + \pgfplots@invoke@pgfkeyscode@CODE#2\pgfeov +} + + +% Usage: +% \pgfplots@letcsname pgfplots@xtick={pgfplots@kram@x} +% -> invokes \csname ... \endcsname for both args. +\def\pgfplots@letcsname#1=#2{% + \expandafter\let\expandafter\pgfplots@loc@TMPc\csname #2\endcsname + \expandafter\let\csname #1\endcsname=\pgfplots@loc@TMPc +}% + +% I have introduced this macro to allow optimizations of (x,y) +% coordinate processing. Use it for everything which is directly plot +% related. +% +% @see \pgfplotsqpointxy@orthogonal +\let\pgfplotsqpointxy=\pgfqpointxy +\let\pgfplotsqpointxyz=\pgfqpointxyz + +% A "quick" quick variant of \pgfqpointxy which assumes that +% the X unit vector is ( e_xx,0 )^T and the Y unit vector is ( 0, +% e_yy)^T. +% +% In words, the unit vectors are orthogonal. This is the usual case +% for two-dimensional plots and shall be optimized. +\def\pgfplotsqpointxy@orthogonal#1#2{% + \pgf@x=#1\pgf@xx% + \pgf@y=#2\pgf@yy} + + +% Takes a domain as input and generates a foreach argument which +% samples from the domain. +% Writes the result to \pgfplotslocretval +% INPUT: +% #1:#2 the domain +% /pgfplots/samples the number of samples +% OUTPUT: +% \pgfplotslocretval a foreach specification. +\def\pgfplots@domain@to@foreach#1:#2\relax{% + \pgfmathparse{#1}% + \let\pgfplots@loc@TMPa=\pgfmathresult% + \pgfmathparse{#2}% + \let\pgfplots@loc@TMPb=\pgfmathresult% + \pgfmathparse{\pgfplots@loc@TMPa+(\pgfplots@loc@TMPb-\pgfplots@loc@TMPa)/(\pgfkeysvalueof{/pgfplots/samples}-1)}% + \edef\pgfplotslocretval{\pgfplots@loc@TMPa,\pgfmathresult,...,\pgfplots@loc@TMPb}% +} + +{ + \catcode`\;=\active + \catcode`\:=\active + \gdef\pgfplots@activesemicolon{;}% + \gdef\pgfplots@activecolon{:}% +} + +% checks whether ';' is active and replaces a sequence of commands +% accordingly. +% +% @see \pgfplots@appendto@activesemicolon@switcher +\def\pgfplots@checkandpreparefor@active@semicolon{% + \ifnum\the\catcode`\;=\active\relax + \pgfplots@checkandpreparefor@active@semicolon@ + \fi +}% +\def\pgfplots@checkandpreparefor@active@semicolon@{}% + +% Adds all commands '#1' to the sequence of commands which will be +% issued in case ';' is active. +\def\pgfplots@appendto@activesemicolon@switcher#1{% + \expandafter\def\expandafter\pgfplots@checkandpreparefor@active@semicolon@\expandafter{% + \pgfplots@checkandpreparefor@active@semicolon@ + #1% + }% +}% + + +% Usage: +% \pgfplotsforeachentryinCSV{\value}{1,2,3,4.5,6.7,10}{The value is \value\par} +% +% The loop is ungrouped. +\long\def\pgfplotsforeachentryinCSV#1#2#3{% + \def\pgfplotsforeachentryinCSV@{#1}% + \long\def\pgfplotsforeachentryinCSV@@{#3}% + \pgfplotsforeachentryinCSV@loop#2,\pgfplots@EOI +}% +% A variant of \pgfplotsforeachentryinCSV where a trailing comma +% indicates the end of input. +% Example: +% +% \pgfplotsforeachentryinCSV{\value}{1,2,3,4.5,6.7,10,}{The value is \value\par} +% ^ +% +% It is permissable to provide an empty list (without trailing comma) +\long\def\pgfplotsforeachentryinCSVisterminated#1#2#3{% + \def\pgfplotsforeachentryinCSV@{#1}% + \long\def\pgfplotsforeachentryinCSV@@{#3}% + \pgfplotsforeachentryinCSV@loop#2\pgfplots@EOI +}% +\def\pgfplotsforeachentryinCSV@loop{% + \pgfutil@ifnextchar\pgfplots@EOI{% + \pgfutil@gobble + }{% + \pgfplotsforeachentryinCSV@next + }% +}% +\def\pgfplotsforeachentryinCSV@next#1,{% + \expandafter\def\pgfplotsforeachentryinCSV@{#1}% + \pgfplotsforeachentryinCSV@@ + \pgfplotsforeachentryinCSV@loop +}% + + +% A (simple) replacement for \foreach which +% 1. does NOT scope the argument +% 2. allows to use PGF Math routines for loops ( '...' notation) +% instead of TeX registers. +% +% Usage: +% \pgfplotsforeachungrouped \x in {1,2,3,4,5} {<code>} +% +% Some details: +% - If #2 is a UNIFORM SAMPLING RANGE, the algorithm is supposed to be +% most effective. +% - If \pgfmathadd@ is the standard PGF math version of \pgfmathadd@, +% we use fast TeX dimensions for any loops. Otherwise, \pgfmathadd@ +% is used (assuming it has been replaced and should be used. +% +\def\pgfplotsforeachungrouped#1{\pgfplotsforeachungrouped@{#1}}% +\long\def\pgfplotsforeachungrouped@#1in #2#3{% + \pgfplotsforeachungrouped@isuniform{#2}% + \ifpgfplots@loc@tmp + \pgfplotsforeachungroupeduniform@#1{#2}{#3}% + \else + \pgfplotsforeachungroupednonuniform@#1{#2}{#3}% + \fi +} +\let\pgfplots@original@pgfmathadd@=\pgfmathadd@ + +\long\def\pgfplotsforeachungroupeduniform@#1#2#3{% + \pgfplotsforeachungroupeduniform@@{#1}#2\relax{#3}% +} +\long\def\pgfplotsforeachungroupeduniform@@#1#2,#3,...,#4\relax#5{% + % Compute mesh width! + \pgfmathparse{#2}% + \let\pgfplots@foreach@loc@TMPa=\pgfmathresult + \pgfmathparse{#3}% + \let\pgfplots@foreach@loc@TMPb=\pgfmathresult + \pgfmathsubtract@{\pgfplots@foreach@loc@TMPb}{\pgfplots@foreach@loc@TMPa}% + \ifx\pgfmathadd@\pgfplots@original@pgfmathadd@ + % perform manual restoration of local variables: + \edef\pgfplots@foreach@loc@TMPd{% + \noexpand\pgf@xa=\the\pgf@xa\noexpand\relax + \noexpand\pgf@xb=\the\pgf@xb\noexpand\relax + \noexpand\pgf@ya=\the\pgf@ya\noexpand\relax + }% + % mesh width: + \pgf@ya=\pgfmathresult pt + % the loop will run while ( NOT <cur> \pgfplots@foreach@loc@cmp <last> ) + \ifdim\pgf@ya<0pt + \def\pgfplots@foreach@loc@cmp{<}% + \else + \def\pgfplots@foreach@loc@cmp{>}% + \fi + % + \pgfmathparse{#4}% + \let\pgfplots@foreach@loc@TMPb=\pgfmathresult + \pgf@xa=\pgfplots@foreach@loc@TMPa pt + \pgf@xb=\pgfplots@foreach@loc@TMPb pt + \long\def\pgfplots@foreach@loc@TMPc{#5}% + % + \pgfutil@loop + \ifdim\pgf@xa \pgfplots@foreach@loc@cmp \pgf@xb\relax + \pgfplots@loc@tmpfalse + \else + \pgfplots@loc@tmptrue + \fi + \ifpgfplots@loc@tmp + \edef#1{\pgf@sys@tonumber{\pgf@xa}}% + \pgfplots@foreach@loc@TMPc\relax + \advance\pgf@xa by\pgf@ya\relax + \pgfutil@repeat + % ok, restore them: + \pgfplots@foreach@loc@TMPd + \else + % Use \pgfmath engine for the loop: + \edef\pgfplots@foreach@loc@TMPd{% + \noexpand\pgf@xa=\the\pgf@xa\noexpand\relax + }% + % mesh width: + \let\pgfplots@foreach@loc@meshwidth=\pgfmathresult + \pgfmathparse{0}% invoke the parser - in case the fpu is active. + \pgfmathlessthan@{\pgfplots@foreach@loc@meshwidth}{\pgfmathresult}% + \pgf@xa=\pgfmathresult pt + % the loop will run while ( NOT \pgfplots@foreach@loc@cmp{<cur>}{<last>} ) + \ifdim\pgf@xa=1pt + \let\pgfplots@foreach@loc@cmp=\pgfmathlessthan@ + \else + \let\pgfplots@foreach@loc@cmp=\pgfmathgreaterthan@ + \fi + % + \pgfmathparse{#4}% + \let\pgfplots@foreach@loc@TMPb=\pgfmathresult + \long\def\pgfplots@foreach@loc@TMPc{#5}% + % + \pgfutil@loop + \pgfplots@foreach@loc@cmp{\pgfplots@foreach@loc@TMPa}{\pgfplots@foreach@loc@TMPb}% + \pgf@xa=\pgfmathresult pt + \ifdim\pgf@xa=0pt + \let#1=\pgfplots@foreach@loc@TMPa% + \pgfplots@foreach@loc@TMPc\relax + \pgfmathadd@{\pgfplots@foreach@loc@TMPa}{\pgfplots@foreach@loc@meshwidth}% + \let\pgfplots@foreach@loc@TMPa=\pgfmathresult + \pgfutil@repeat + % ok, restore them: + \pgfplots@foreach@loc@TMPd + \fi +}% +\long\def\pgfplotsforeachungroupednonuniform@#1#2#3{% + \pgfplotsapplistXXglobalnewempty + \foreach\pgfplots@foreach@loc@TMPa in {#2} {% + \expandafter\pgfplotsapplistXXglobalpushback\expandafter{\pgfplots@foreach@loc@TMPa,}% + }% + \pgfplotsapplistXXgloballet\pgfplots@foreach@loc@TMPa + \pgfplotsapplistXXglobalclear + \expandafter\pgfplotsforeachentryinCSVisterminated\expandafter\pgfplots@foreach@loc@TMPa\expandafter{\pgfplots@foreach@loc@TMPa}{% + \let#1=\pgfplots@foreach@loc@TMPa + #3% + }% +} + +% Sets \ifpgfplots@loc@tmp to something true if and only if '#1' is of the form +% #1 = <number1>,<number2>,...,<number3>. +\def\pgfplotsforeachungrouped@isuniform#1{% + \edef\pgfplots@foreach@loc@TMPa{#1}% + \expandafter\pgfplotsforeachungrouped@isuniform@\pgfplots@foreach@loc@TMPa,,,,\relax +}% +\def\pgfplotsforeachungrouped@isuniform@#1,#2,#3,#4,#5\relax{% + \def\pgfplots@foreach@loc@TMPa{#5}% + \def\pgfplots@foreach@loc@TMPb{,,,}% + \pgfplots@loc@tmpfalse + \ifx\pgfplots@foreach@loc@TMPa\pgfplots@foreach@loc@TMPb + \def\pgfplots@foreach@loc@TMPa{#3}% + \def\pgfplots@foreach@loc@TMPb{...}% + \ifx\pgfplots@foreach@loc@TMPa\pgfplots@foreach@loc@TMPb + \pgfutil@in@,{#4}% + \ifpgfutil@in@ + \else + % ok, we REALLY have a uniform range! + \pgfplots@loc@tmptrue + \fi + \fi + \fi +}% + +% Allows to provide an output routine for +% \pgfplotsforeachlogarithmicungrouped which changes the number format +% of \pgfmathresult. +% +% Example: +% \pgfplotsforeachlogarithmicformatresultwith{\pgfmathfloattofixed{\pgfmathresult}} +% +% #1: is code which modifies \pgfmathresult. +\def\pgfplotsforeachlogarithmicformatresultwith#1{% + \def\pgfplotsforeachlogarithmicungrouped@finalizeresult{#1}% +} + +% \pgfplotsforeachlogarithmicungrouped \x/\logx in {a:b} {#3} +% +% samples \x between a and b using a logarithmic scale. +% +% During '#3', \x will contain the sample and \logx the logarithm of +% \x. +% +% Both, #1 and #2 will be provided as floating point numbers unless +% configured otherwise with \pgfplotsforeachlogarithmicsetoutput, +% see above. +% +\def\pgfplotsforeachlogarithmicungrouped#1/#2{\pgfplotsforeachlogarithmicungrouped@{#1}{#2}}% +\long\def\pgfplotsforeachlogarithmicungrouped@#1#2in #3#4{% + % define + % \pgfplots@foreach@loc@TMPd = N in fixed point + % \pgfplots@foreach@loc@TMPc = N-1 in float : + \pgfkeysgetvalue{/pgfplots/samples}{\pgfplots@plot@samples} + \pgfmathfloatcreate{1}{1.0}{0}% + \let\pgfplots@foreach@loc@TMPa=\pgfmathresult + \pgfmathfloatparsenumber{\pgfplots@plot@samples}% + \expandafter\pgfmathfloatsubtract@\expandafter{\pgfmathresult}{\pgfplots@foreach@loc@TMPa}% + \let\pgfplots@foreach@loc@TMPc=\pgfmathresult + % + \edef\pgfplots@loc@TMPb{#3}% + \expandafter\pgfplotsforeachlogarithmicungrouped@readdomain\pgfplots@loc@TMPb\relax + % compute mesh width into \pgfplots@foreach@loc@TMPc: + % \pgfplots@foreach@loc@TMPc := h := ( log(xmax) - log(xmin) ) / (N-1) + \pgfmathfloatsubtract@{\pgfplots@foreach@loc@TMPb}{\pgfplots@foreach@loc@TMPa}% + \pgfmathfloatdivide@{\pgfmathresult}{\pgfplots@foreach@loc@TMPc}% + \let\pgfplots@foreach@loc@TMPc=\pgfmathresult + % + % apply local scoping here: + \edef\pgfplots@foreach@loc@TMPd{% + \noexpand\c@pgf@counta=\the\c@pgf@counta\noexpand\relax + }% + \long\def\pgfplots@foreach@loc@TMPf{#4}% + \c@pgf@counta=0 + \pgfutil@loop + \ifnum\c@pgf@counta<\pgfplots@plot@samples + % compute exp(log(min) + i * h) + \expandafter\pgfmathfloatparsenumber\expandafter{\the\c@pgf@counta}% + \expandafter\pgfmathfloatmultiply@\expandafter{\pgfmathresult}{\pgfplots@foreach@loc@TMPc}% + \expandafter\pgfmathfloatadd@\expandafter{\pgfmathresult}{\pgfplots@foreach@loc@TMPa}% + \let\pgfplots@loc@TMPa=\pgfmathresult + \pgfplotsforeachlogarithmicungrouped@finalizeresult% + \let#2=\pgfmathresult + \pgfmathfloatexp@{\pgfplots@loc@TMPa}% + \pgfplotsforeachlogarithmicungrouped@finalizeresult% + \let#1=\pgfmathresult + % + % ok, invoke it! + % -> store \c@pgf@counta before doing so. We need to scope + % manually here. + \edef\pgfplots@foreach@loc@TMPe{\the\c@pgf@counta}% + \pgfplots@foreach@loc@TMPf\relax + \c@pgf@counta=\pgfplots@foreach@loc@TMPe\relax + \advance\c@pgf@counta by 1 + \pgfutil@repeat + % restore scoped variables: + \pgfplots@foreach@loc@TMPd +} +% can be used to convert the number format from float to something +% else. +\def\pgfplotsforeachlogarithmicungrouped@finalizeresult{}% + + +% defines +% \pgfplots@foreach@loc@TMPa := log(firstintervalpt) +% and +% \pgfplots@foreach@loc@TMPb := log(secondintervalpt) +\def\pgfplotsforeachlogarithmicungrouped@readdomain#1:#2\relax{% + \pgfmathfloatparsenumber{#1}% + \pgfmathfloatln@{\pgfmathresult}% + \let\pgfplots@foreach@loc@TMPa=\pgfmathresult + \pgfmathfloatparsenumber{#2}% + \pgfmathfloatln@{\pgfmathresult}% + \let\pgfplots@foreach@loc@TMPb=\pgfmathresult +} + +% invokes '#2' if #1 expands (\edef) to the empty string or '#3' if not. +\def\pgfplots@ifempty#1#2#3{% + \edef\pgfplots@loc@TMPa{#1}% + \ifx\pgfplots@loc@TMPa\pgfutil@empty #2\else #3\fi +}% + +\def\pgfplots@logfileopen#1{% + \immediate\write-1{PGFPlots: reading {#1}}% +}% + +\input pgfplotsliststructure.code.tex +\input pgfplotsliststructureext.code.tex +\input pgfplotsarray.code.tex +\input pgfplotstable.code.tex + +\endinput |