diff options
Diffstat (limited to 'Master/texmf-dist/tex/generic/pgf/modules/pgfmoduleplot.code.tex')
-rw-r--r-- | Master/texmf-dist/tex/generic/pgf/modules/pgfmoduleplot.code.tex | 260 |
1 files changed, 203 insertions, 57 deletions
diff --git a/Master/texmf-dist/tex/generic/pgf/modules/pgfmoduleplot.code.tex b/Master/texmf-dist/tex/generic/pgf/modules/pgfmoduleplot.code.tex index ea55ca8517b..8620a91e4de 100644 --- a/Master/texmf-dist/tex/generic/pgf/modules/pgfmoduleplot.code.tex +++ b/Master/texmf-dist/tex/generic/pgf/modules/pgfmoduleplot.code.tex @@ -7,7 +7,7 @@ % % See the file doc/generic/pgf/licenses/LICENSE for more details. -\ProvidesFileRCS $Header: /cvsroot/pgf/pgf/generic/pgf/modules/pgfmoduleplot.code.tex,v 1.8 2010/10/22 17:34:17 ludewich Exp $ +\ProvidesFileRCS $Header: /cvsroot/pgf/pgf/generic/pgf/modules/pgfmoduleplot.code.tex,v 1.12 2013/07/31 16:22:24 tantau Exp $ % PGF's plotting interface works as follows: @@ -16,26 +16,35 @@ % need to provide the coordinates (obviously) of the points that % should be plotted. The coordinates are given via a long stream of % commands. These commands are \pgfplotstreamstart, which is -% given exactly once at the beginning, \pgfplotstreampoint, of which there -% are numerous in the middle, \pgfplotstreamspecial, of which there may be -% numerous in the middle, and \pgfplotstreamend, which must be given -% at the end. Between these commands arbitrary other commands may be -% given. Here is an example: +% given exactly once at the beginning, the commands +% \pgfplotstreampoint, \pgfplotstreampointoutlier, +% \pgfplotstreampointundefined, \pgfplotstreamnewdataset, of which +% there are numerous in the middle, the special \pgfplotstreamspecial, +% of which there may be numerous in the middle, and \pgfplotstreamend, +% which must be given at the end. Between these commands arbitrary +% other commands may be given. Here is an example: % % ... % \pgfplotstreamstart % \pgfplotstreampoint{\pgfpointxy{0}{0}} % \pgfplotstreampoint{\pgfpointxy{1}{1}} +% \pgfplotstreamnewdataset % \pgfplotstreampoint{\pgfpointxy{2}{4}} % \relax -% \pgfplotstreampoint{\pgfpointxy{3}{9}} +% \pgfplotstreampointoutlier{\pgfpointxy{3}{9}} % \pgfplotstreamspecial{some handler-dependent special stuff} % \pgfplotstreamend % % By themselves, the \pgfplotstreamxxxx commands do not do anything by % default. Rather, to ``use'' such a stream, you must first install a % stream handler. For example, the ``lineto'' handler will simply -% translate every \pgfplotstreampoint into a \pgfpathlineto. +% basically every \pgfplotstreampoint into a \pgfpathlineto. +% +% One special things is the handling of "jumps" in a stream. For +% instance, when a lineto handler encounters an "outlier" or a new +% data set, the current line should end and a new subpath should start +% (unless configured otherwise). For this, the special jump handler is +% important. % % Example: % @@ -55,9 +64,111 @@ % are set by the handlers: \def\pgfplotstreamstart{\pgf@plotstreamstart} \def\pgfplotstreampoint#1{\gdef\pgfplotlastpoint{#1}\pgf@plotstreampoint{#1}} +\def\pgfplotstreampointoutlier#1{\pgfplot@outliers{}{\pgf@plotstreamjump}{\pgfplotstreampoint{#1}}}% +\def\pgfplotstreampointundefined{\pgfplot@outliers{}{\pgf@plotstreamjump}{}}% +\def\pgfplotstreamnewdataset{\pgfplot@outliers{}{\pgf@plotstreamjump}{}}% \def\pgfplotstreamspecial{\pgf@plotstreamspecial} \def\pgfplotstreamend{\pgf@plotstreamend} +\def\pgfplot@ignorer#1#2#3{#1} +\def\pgfplot@jumper#1#2#3{#2} +\def\pgfplot@plotter#1#2#3{#3} + +\let\pgfplot@outliers\pgfplot@jumper +\let\pgfplot@undefined\pgfplot@jumper +\let\pgfplot@newdata\pgfplot@jumper + +\pgfset{ + handle outlier points in plots/.is choice, + handle outlier points in plots/ignore/.code=\let\pgfplot@outliers\pgfplot@ignorer, + handle outlier points in plots/jump/.code=\let\pgfplot@outliers\pgfplot@jumper, + handle outlier points in plots/plot/.code=\let\pgfplot@outliers\pgfplot@plotter, + handle undefined points in plots/.is choice, + handle undefined points in plots/ignore/.code=\let\pgfplot@undefined\pgfplot@ignorer, + handle undefined points in plots/jump/.code=\let\pgfplot@undefined\pgfplot@jumper, + handle new data sets in plots/.is choice, + handle new data sets in plots/ignore/.code=\let\pgfplot@newdata\pgfplot@ignorer, + handle new data sets in plots/jump/.code=\let\pgfplot@newdata\pgfplot@jumper, +} + + +% Declares a new plot handler +% +% #1 = macro that should install the stream handler subsequently +% #2 = parameter list of said macro. +% #3 = keys as described below +% +% Description: +% +% When you declare a new plot handler, you provide, through keys, +% different "actions" that should be taken when the different stream +% commands are used: +% +% start = some code to be executed when \pgfplotstreamstart is called +% for this plothandler +% end = same for the end of the stream +% point = code to be executed for a point of the stream +% jump = code to be executed for a "jump" in the stream +% special = code to be executed for \pgfplotstreamspecial +% start macro = here and for the following keys, the to-be-executed +% code is stored in the given macro +% end macro = see above +% jump macro = see above +% point macro = see above +% special macro = see above +% +% Example: +% +% \pgfdeclareplothandler{\ultrasimplehandler}{}{ +% point=\pgfpathlineto{##1} +% } + +\def\pgfdeclareplothandler#1#2#3{% + \def#1#2{% + \pgfkeys{% + /pgf/plots/@handler options/.cd, + start=\relax, + end macro=\relax, + point macro=\pgfutil@gobble, + jump macro=\relax, + special macro=\pgfutil@gobble,% + #3% + }% + }% +} + +\pgfkeys{% + /pgf/plots/@handler options/.cd, + start/.code=% + \gdef\pgf@plotstreamstart{% + \global\pgf@plot@startedfalse% + \global\let\pgf@plotstreamend\pgf@plotstreamend@init% + \global\let\pgf@plotstreampoint\pgf@plotstreampoint@init% + \global\let\pgf@plotstreamjump\pgf@plotstreamjump@init% + \global\let\pgf@plotstreamspecial\pgf@plotstreamspecial@init% + #1% + },% + start macro/.code=% + \gdef\pgf@plotstreamstart{% + \global\pgf@plot@startedfalse% + \global\let\pgf@plotstreamend\pgf@plotstreamend@init% + \global\let\pgf@plotstreampoint\pgf@plotstreampoint@init% + \global\let\pgf@plotstreamjump\pgf@plotstreamjump@init% + \global\let\pgf@plotstreamspecial\pgf@plotstreamspecial@init% + #1% + },% + end/.code=\gdef\pgf@plotstreamend@init{#1}, + end macro/.code=\global\let\pgf@plotstreamend@init#1, + point/.code=\gdef\pgf@plotstreampoint@init##1{#1}, + point macro/.code=\global\let\pgf@plotstreampoint@init#1, + jump/.code=\gdef\pgf@plotstreamjump@init{#1}, + jump macro/.code=\global\let\pgf@plotstreamjump@init#1, + special/.code=\gdef\pgf@plotstreamspecial@init##1{#1}, + special macro/.code=\global\let\pgf@plotstreamspecial@init#1, +} + +\newif\ifpgf@plot@started + @@ -88,6 +199,7 @@ + % % Handlers % @@ -103,12 +215,9 @@ % \pgfplothandlerlineto % \pgfplotxyfile{mytable} -\def\pgfplothandlerlineto{% - \def\pgf@plotstreamstart{% - \global\let\pgf@plotstreampoint=\pgf@plot@line@handler% - \global\let\pgf@plotstreamspecial=\pgfutil@gobble% - \global\let\pgf@plotstreamend=\relax% - }% +\pgfdeclareplothandler{\pgfplothandlerlineto}{}{ + point macro=\pgf@plot@line@handler, + jump=\global\let\pgf@plotstreampoint\pgf@plot@line@handler@move% } \def\pgf@plot@line@handler#1{% @@ -116,29 +225,48 @@ \global\let\pgf@plotstreampoint=\pgfpathlineto% } +\def\pgf@plot@line@handler@move#1{% + \pgfpathmoveto{#1}% + \global\let\pgf@plotstreampoint=\pgfpathlineto% +} + % This handler turns creates a series of lineto commands, with the -% last command being a closepath, resulting in a closed path. +% last command being a closepath, resulting in a closed path. If a +% jump is encountered, the current subpath is closed and a new subpath +% is started. % % Example: % % \pgfplothandlerpolygon % \pgfplotxyfile{mytable} -\def\pgfplothandlerpolygon{% - \def\pgf@plotstreamstart{% - \global\let\pgf@plotstreampoint=\pgf@plot@line@handler@close% - \global\let\pgf@plotstreamspecial=\pgfutil@gobble% - \global\let\pgf@plotstreamend=\pgfpathclose% - }% -} +\pgfdeclareplothandler{\pgfplothandlerpolygon}{}{% + point macro=\pgf@plot@line@handler@close, + jump macro=\pgf@plot@next@close@and@moveto, + end macro=\pgf@plot@polygon@stop +}% \def\pgf@plot@line@handler@close#1{% \pgfpathmoveto{#1}% + \global\pgf@plot@startedtrue% \global\let\pgf@plotstreampoint=\pgfpathlineto% } +\def\pgf@plot@polygon@stop{% + \ifpgf@plot@started% + \pgfpathclose% + \fi% + \global\pgf@plot@startedfalse% +} + +\def\pgf@plot@next@close@and@moveto{% + \ifpgf@plot@started% + \pgfpathclose% + \fi% + \global\let\pgf@plotstreampoint\pgf@plot@line@handler@close% +} % More handlers are defined in pgflibraryplothandlers @@ -154,14 +282,7 @@ % \pgfplothandlerdiscard % \pgfplotxyfile{mytable} -\def\pgfplothandlerdiscard{% - \def\pgf@plotstreamstart{% - \global\let\pgf@plotstreampoint=\pgfutil@gobble% - \global\let\pgf@plotstreamspecial=\pgfutil@gobble% - \global\let\pgf@plotstreamend=\relax% - }% -} - +\pgfdeclareplothandler{\pgfplothandlerdiscard}{}{} @@ -178,14 +299,12 @@ % \pgftransformxshift{1cm} % \myplot -\def\pgfplothandlerrecord#1{% - \def\pgf@plot@recordto{#1}% - \gdef#1{\pgfplotstreamstart}% - \def\pgf@plotstreamstart{% - \gdef\pgf@plotstreampoint####1{\expandafter\gdef\expandafter#1\expandafter{#1\pgfplotstreampoint{####1}}}% - \gdef\pgf@plotstreamspecial####1{\expandafter\gdef\expandafter#1\expandafter{#1\pgfplotstreamspecial{####1}}}% - \gdef\pgf@plotstreamend{\expandafter\gdef\expandafter#1\expandafter{#1\pgfplotstreamend}}% - }% +\pgfdeclareplothandler{\pgfplothandlerrecord}{#1}{% + start=\gdef#1{\pgfplotstreamstart}, + point=\expandafter\gdef\expandafter#1\expandafter{#1\pgfplotstreampoint{##1}}, + jump=\expandafter\gdef\expandafter#1\expandafter{#1\pgf@plotstreamjump}, + special=\expandafter\gdef\expandafter#1\expandafter{#1\pgfplotstreamspecial{##1}}, + end=\expandafter\gdef\expandafter#1\expandafter{#1\pgfplotstreamend}, } @@ -212,9 +331,10 @@ \pgfplotstreamstart% \openin\r@pgf@reada=#1 \ifeof\r@pgf@reada - \PackageWarning{pgf}{Plot data file `#1' not found.} + \pgfwarning{Plot data file `#1' not found.} \else \catcode`\#=14 + \catcode`\^^M=5 \pgf@readxyfile% \fi \pgfplotstreamend% @@ -228,7 +348,9 @@ \let\par=\pgf@savedpar% \edef\pgf@temp{\pgf@temp}% \ifx\pgf@temp\pgfutil@empty% + \ifeof\r@pgf@reada\else\pgfplotstreamnewdataset\fi% \else\ifx\pgf@temp\pgf@partext% + \ifeof\r@pgf@reada\else\pgfplotstreamnewdataset\fi% \else% \expandafter\pgf@parsexyline\pgf@temp\pgf@stop% \fi\fi% @@ -236,9 +358,18 @@ } \def\pgf@parsexyline#1 #2 #3\pgf@stop{% - \pgfplotstreampoint{\pgfpointxy{#1}{#2}}% + \edef\pgf@xyline@flag@val{#3}% + \ifx\pgf@xyline@flag@val\pgf@xyline@flag@undef% + \pgfplotstreampointundefined% + \else\ifx\pgf@xyline@flag@val\pgf@xyline@flag@out% + \pgfplotstreampointoutlier{\pgfpointxy{#1}{#2}}% + \else% + \pgfplotstreampoint{\pgfpointxy{#1}{#2}}% + \fi\fi% } +\edef\pgf@xyline@flag@out{o\space}% +\edef\pgf@xyline@flag@undef{u\space}% @@ -261,9 +392,10 @@ \pgfplotstreamstart% \openin\r@pgf@reada=#1 \ifeof\r@pgf@reada - \PackageWarning{pgf}{Plot data file `#1' not found.} + \pgfwarning{Plot data file `#1' not found.} \else \catcode`\#=14 + \catcode`\^^M=5 \pgf@readxyzfile% \fi \pgfplotstreamend% @@ -273,7 +405,9 @@ \def\pgf@readxyzfile{% \pgfutil@read\r@pgf@reada to \pgf@temp% \ifx\pgf@temp\pgfutil@empty% + \ifeof\r@pgf@reada\else\pgfplotstreamnewdataset\fi% \else\ifx\pgf@temp\pgf@partext% + \ifeof\r@pgf@reada\else\pgfplotstreamnewdataset\fi% \else% \expandafter\pgf@parsexyzline\pgf@temp\pgf@stop% \fi\fi% @@ -281,7 +415,14 @@ } \def\pgf@parsexyzline#1 #2 #3 #4\pgf@stop{% - \pgfplotstreampoint{\pgfpointxyz{#1}{#2}{#3}}% + \edef\pgf@xyline@flag@val{#4}% + \ifx\pgf@xyline@flag@val\pgf@xyline@flag@undef% + \pgfplotstreampointundefined% + \else\ifx\pgf@xyline@flag@val\pgf@xyline@flag@out% + \pgfplotstreampointoutlier{\pgfpointxyz{#1}{#2}{#3}}% + \else% + \pgfplotstreampoint{\pgfpointxyz{#1}{#2}{#3}}% + \fi\fi% } @@ -314,6 +455,9 @@ \let\pgf@plotwrite=\w@pgf@writea \newif\ifpgf@resample@plot +\pgfkeys{% + /pgf/plot/gnuplot call/.initial={gnuplot}} + \def\pgfplotgnuplot{\pgfutil@ifnextchar[{\pgf@plotgnuplot}{\pgf@plotgnuplot[\jobname]}}%} \def\pgf@plotgnuplot[#1]#2{% \pgf@resample@plottrue% @@ -344,25 +488,27 @@ \immediate\pgfutil@write\pgf@plotwrite{\pgf@gnuplot@head}% \immediate\pgfutil@write\pgf@plotwrite{#2}% \immediate\closeout\pgf@plotwrite% - \immediate\pgfutil@write18{gnuplot \pgf@plotgnuplotfile}% + \immediate\pgfutil@write18{% + \pgfkeysvalueof{/pgf/plot/gnuplot call} \pgf@plotgnuplotfile}% \fi% - % temporarily redefine \pgf@parsexyline - \let\pgf@savedparsexyline=\pgf@parsexyline% - \let\pgf@parsexyline=\pgf@parsegnuplotxyline% +% \let\pgf@savedparsexyline=\pgf@parsexyline% +% \let\pgf@parsexyline=\pgf@parsegnuplotxyline% \pgfplotxyfile{\pgf@plottablefile}% - \let\pgf@parsexyline=\pgf@savedparsexyline% -} - -\def\pgf@parsegnuplotxyline#1 #2 #3\pgf@stop{% - \edef\pgf@xyline@flag@val{#3}% - \edef\pgf@xyline@flag@undef{u\space}% - \ifx\pgf@xyline@flag@val\pgf@xyline@flag@undef% - \else% - \pgfplotstreampoint{\pgfpointxy{#1}{#2}}% - \fi% +% \let\pgf@parsexyline=\pgf@savedparsexyline% } - +% \def\pgf@parsegnuplotxyline#1 #2 #3\pgf@stop{% +% \edef\pgf@xyline@flag@val{#3}% +% \edef\pgf@xyline@flag@out{o\space}% +% \edef\pgf@xyline@flag@undef{u\space}% +% \ifx\pgf@xyline@flag@val\pgf@xyline@flag@undef% +% \pgfplotstreampointundefined% +% \else\ifx\pgf@xyline@flag@val\pgf@xyline@flag@out% +% \pgfplotstreampointoutlier{\pgfpointxy{#1}{#2}}% +% \else% +% \pgfplotstreampoint{\pgfpointxy{#1}{#2}}% +% \fi\fi% +% } % This producer handler plots a function using pgf's mathematical engine. % |