diff options
Diffstat (limited to 'Master/texmf-dist/tex/generic/pgfplots/util')
4 files changed, 833 insertions, 318 deletions
diff --git a/Master/texmf-dist/tex/generic/pgfplots/util/pgfplotsbinary.code.tex b/Master/texmf-dist/tex/generic/pgfplots/util/pgfplotsbinary.code.tex index 6414f57a9a8..ca2c74c5f58 100644 --- a/Master/texmf-dist/tex/generic/pgfplots/util/pgfplotsbinary.code.tex +++ b/Master/texmf-dist/tex/generic/pgfplots/util/pgfplotsbinary.code.tex @@ -522,9 +522,9 @@ \def\pgfplotsbinaryencodesignedmaplinearly#1{% \begingroup \global\let\pgfplotsbinaryresult=\pgfplotsbinaryempty - \c@pgfplotsbin@input=#1 % + \c@pgfplotsbin@input=#1\relax% \pgfplotsbinaryencodesignedmaplinearly@prepare - \ifnum\c@pgfplotsbin@input<0 + \ifnum\c@pgfplotsbin@input<0 % % compute + 2^31 - 1 \pgfplotsbinary@add@signed@largest@absolute \else @@ -533,7 +533,7 @@ \let\pgfplotsbinary@ZERO@HIGHEST=\pgfplotsbinary@ZERO@LINEARMAP \let\pgfplotsbinary@hook=\pgfplotsbinary@hook@signed@linearmap % and compute the -1 explicitly here: - \advance\c@pgfplotsbin@input by-1 + \advance\c@pgfplotsbin@input by-1 % \fi \pgfplotsbinaryencode@badic@unsigned@% \endgroup diff --git a/Master/texmf-dist/tex/generic/pgfplots/util/pgfplotscolor.code.tex b/Master/texmf-dist/tex/generic/pgfplots/util/pgfplotscolor.code.tex new file mode 100644 index 00000000000..dc1a7a0aa78 --- /dev/null +++ b/Master/texmf-dist/tex/generic/pgfplots/util/pgfplotscolor.code.tex @@ -0,0 +1,631 @@ +%-------------------------------------------- +% +% 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-2013 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/>. +% +%-------------------------------------------- + +\pgfkeys{ + /pgfplots/color sequence/reset/.style={ + /pgfplots/color sequence/colorspace, + /pgfplots/color sequence/default input colorspace, + /pgfplots/color sequence/every input component/.code=, + /pgfplots/color sequence/context message, + }, + /pgfplots/color sequence/colorspace/.initial=auto, + /pgfplots/color sequence/colorspace/.default=auto, + /pgfplots/color sequence/default input colorspace/.initial=, + /pgfplots/color sequence/default input colorspace/.default=\pgfkeysvalueof{/pgfplots/color sequence/colorspace}, + % applied to every INPUT component, i.e. before transforming it to some target color space. + /pgfplots/color sequence/every input component/.code=, + /pgfplots/color sequence/context message/.code={\def\pgfplotscolornormalizesequence@context@message{#1}}, + /pgfplots/color sequence/context message/.default=\pgfplotscolornormalizesequence@context@message@default, + /pgfplots/color sequence/reset, +} + +\newif\ifpgfplotscolor@colorspaceknown + +% the beginning of a normalized color sequence. +% +% It is to be used like +% \pgfplotscolornormalizesequence[colorspace=rgb] +% +% \pgfplotscolornormalizesequencenext{1,1,1} +% -> \pgfplotsretval = {1,1,1} % uses default colorspace +% \pgfplotscolornormalizesequencenext{color=red} +% -> \pgfplotsretval = {1,0,0} +% \pgfplotscolornormalizesequencenext{color=blue} +% -> \pgfplotsretval = {0,0,1} +% \pgfplotscolornormalizesequencenext{rgb=1,0,0} +% -> \pgfplotsretval = {1,0,0} +% \pgfplotscolornormalizesequencenext{cmyk=1,0,0,1} +% -> \pgfplotsretval = {<converted value>} +% +% \endpgfplotscolornormalizesequence +% +% Every color provided in the sequence will be normalized by +% transforming it to the common color space and by computing the +% separate components representing the color in that space. +% +% These components are available for use in interpolation routines. +% +% #1 : keys in the /pgfplots/color sequence path +\def\pgfplotscolornormalizesequence[#1]{% + \pgfqkeys{/pgfplots/color sequence}{% + #1,% + }% + \pgfkeysgetvalue{/pgfplots/color sequence/colorspace}\pgfplots@loc@TMPa + \pgfkeysgetvalue{/pgfplots/color sequence/default input colorspace}\pgfplotscolornormalizesequence@colspace@input + \edef\pgfplotscolornormalizesequence@colspace@input{\pgfplotscolornormalizesequence@colspace@input} + \pgfkeysgetvalue{/pgfplots/color sequence/every input component/.@cmd}\pgfplotscolornormalizesequencenext@every@component + \edef\pgfplots@loc@TMPa{\pgfplots@loc@TMPa}% + \def\pgfplots@loc@TMPb{auto}% + \ifx\pgfplots@loc@TMPb\pgfplots@loc@TMPa + % colorspace=auto: same as empty. + \let\pgfplots@loc@TMPa=\pgfutil@empty + \fi + \ifx\pgfplots@loc@TMPa\pgfutil@empty + % colorspace=auto: + \def\pgfplotscolornormalizesequence@colspace{}% + \else + \def\pgfplots@loc@TMPb{rgb}% + \ifx\pgfplots@loc@TMPb\pgfplots@loc@TMPa + % colorspace=rgb: + \def\pgfplotscolornormalizesequence@colspace{rgb}% + \else + \def\pgfplots@loc@TMPb{cmyk}% + \ifx\pgfplots@loc@TMPb\pgfplots@loc@TMPa + % colorspace=cmyk: + \def\pgfplotscolornormalizesequence@colspace{cmyk}% + \else + \def\pgfplots@loc@TMPb{gray}% + \ifx\pgfplots@loc@TMPb\pgfplots@loc@TMPa + % colorspace=gray: + \def\pgfplotscolornormalizesequence@colspace{gray}% + \else + \pgfplots@error{Sorry, the choice colorspace=\pgfplots@loc@TMPa\space is unsupported as interpolation colorspace in pgfplots, please use one of 'auto,rgb,cmyk,gray'}% + \fi + \fi + \fi + \fi +}% + +% ends a normalized color sequence and returns the final colorspace +% and its number of components into \pgfplotsretval and +% \pgfplotsretvalb, respectively +\def\endpgfplotscolornormalizesequence{% + \let\pgfplotsretval=\pgfplotscolornormalizesequence@colspace + \pgfplotscolor@get@num@components{\pgfplotsretval}{\pgfplotsretvalb}% + \pgfqkeys{/pgfplots/color sequence}{reset}% +}% + +% accepts the next color in a sequence of colors. The color will be +% normalized and the normalized result written to \pgfplotsretval. +% +% SEE \pgfplotscolornormalizesequencenext -- it is MUCH more powerful! +% +% #1 the color space of the color. +% #2 the components of the color, separated by comma. +% +% POSTCONDITION: +% \pgfplotsretval contains '{<color space>}{<comma-separated-components>}' +% -> including the curly braces. +% +% \pgfplotsretvalb contains the number of input components in +% \pgfplotsretval +\def\pgfplotscolornormalizesequencenextbycomponents#1#2{% + \edef\pgfplotscolornormalizesequence@cur@colspace{#1}% + \pgfplotscolornormalizesequencenextbycomponents@normalize@components{#2}% + % + \ifx\pgfplotscolornormalizesequence@cur@colspace\pgfplotscolornormalizesequence@colspace + \else + \ifx\pgfplotscolornormalizesequence@colspace\pgfutil@empty + \pgfplotscolornormalizesequencenextbycomponents@assign@auto@colspace + \fi + % + \ifx\pgfplotscolornormalizesequence@colspace\pgfplotscolornormalizesequence@cur@colspace + % Ah, ok - the colorspace is NOW the correct one (because + % we chose it as the colorspace for this complete color + % sequence. + \else + % Oh. We need to convert the color space! + \edef\pgfplots@loc@TMPa{{\pgfplotscolornormalizesequence@cur@colspace}{\pgfplotsretval}}% + \expandafter\pgfutil@convertcolorspec\pgfplots@loc@TMPa + {\pgfplotscolornormalizesequence@colspace}% target color spaces + {\pgfplotsretval}% target macro + \fi + \fi + \edef\pgfplotsretval{\pgfplotsretval}% + \pgfplotscolor@get@num@components{\pgfplotscolornormalizesequence@colspace}{\pgfplotsretvalb}% +} + +\def\pgfplotscolornormalizesequencenextbycomponents@assign@auto@colspace{% + % Ah; we have '/pgfplots/color sequence/colorspace=auto'. + % Well, check if the current colorspace (stored in + % \pgfplotscolornormalizesequence@cur@colspace) is suitable. + % + % It is suitable if it is rgb or cmyk. In all other cases, + % we choose either rgb or cmyk. More precisely. 'cmy' is + % mapped to cmyk. All other cases are treated as rgb. + % + \def\pgfplots@loc@TMPa{cmyk}% + \ifx\pgfplotscolornormalizesequence@cur@colspace\pgfplots@loc@TMPa + \let\pgfplotscolornormalizesequence@colspace=\pgfplotscolornormalizesequence@cur@colspace + \else + \def\pgfplots@loc@TMPa{cmy}% + \ifx\pgfplotscolornormalizesequence@cur@colspace\pgfplots@loc@TMPa + \def\pgfplotscolornormalizesequence@colspace{cmyk}% + \else + % rgb appears to be the best choice: (1) it is backwards + % compatible and (2) gray or something like that might fit + % badly to any other colors in the sequence. + \def\pgfplotscolornormalizesequence@colspace{rgb}% + \fi + \fi +} + +% #1: color components +% +% PRECONDITION: \pgfplotscolornormalizesequence@cur@colspace is the +% current color space +% +% POSTCONDITION: \pgfplotsretval contains the normalized color +% components +\def\pgfplotscolornormalizesequencenextbycomponents@normalize@components#1{% + \pgfutil@ifundefined{pgfplots@colspace@name@\pgfplotscolornormalizesequence@cur@colspace}{% + \pgfplotscolor@colorspaceknownfalse + }{% + \pgfplotscolor@colorspaceknowntrue + }% + \edef\pgfplots@loc@TMPb{#1}% + \def\pgfplotsretval{}% + \c@pgf@counta=0 % + \expandafter\pgfplotscolornormalizesequencenext@prepare@loop\pgfplots@loc@TMPb,\pgfplots@EOI,% +}% + +% assigns the number of color components for the given colorspace to +% \pgfplotsretval +\def\pgfplotscolorspacegetcomponents#1{% + \pgfplotscolor@get@num@components{#1}{\pgfplotsretval}% +}% + +% Defines \pgfplotsretval to contain the number of components in the +% color space. +\def\pgfplotscolornormalizesequencegetnumcomponents{% + \ifx\pgfplotscolornormalizesequence@colspace\pgfutil@empty + \pgfplotsthrow{invalid argument}{\pgfplots@loc@TMPa}{Cannot create color with zero components: no colorspace set for the normalized color sequence.}\pgfeov% + \fi + \pgfplotscolorspacegetcomponents{\pgfplotscolornormalizesequence@colspace}% +}% + +\def\pgfplotscolor@get@num@components#1#2{% + \pgfutil@ifundefined{pgfplots@colspace@numcomp@#1}{% + \pgfplotsthrow{invalid argument}{\pgfplots@loc@TMPa}{The input color has an unsupported color space '#1'}\pgfeov% + }{% + \edef#2{\csname pgfplots@colspace@numcomp@#1\endcsname}% + }% +}% + + +\def\pgfplots@colspace@numcomp@gray{1}% +\def\pgfplots@colspace@name@gray{gray}% + +\def\pgfplots@colspace@numcomp@rgb{3}% +\def\pgfplots@colspace@name@rgb{rgb}% + +\def\pgfplots@colspace@numcomp@cmyk{4}% +\def\pgfplots@colspace@name@cmyk{cmyk}% + +\def\pgfplots@colspace@numcomp@cmy{3}% +\def\pgfplots@colspace@name@cmy{cmy}% + +\def\pgfplots@colspace@numcomp@wave{1}% +\def\pgfplots@colspace@name@wave{wave}% +\pgfutil@namedef{pgfplots@colspace@minaccept@wave@0}{362.998}% +\pgfutil@namedef{pgfplots@colspace@min@wave@0}{363}% +\pgfutil@namedef{pgfplots@colspace@maxaccept@wave@0}{814.001}% +\pgfutil@namedef{pgfplots@colspace@max@wave@0}{814}% + +\def\pgfplots@colspace@numcomp@Hsb{3}% +\def\pgfplots@colspace@name@Hsb{Hsb}% +\pgfutil@namedef{pgfplots@colspace@minaccept@Hsb@0}{-0.001}% +\pgfutil@namedef{pgfplots@colspace@min@Hsb@0}{0}% +\pgfutil@namedef{pgfplots@colspace@maxaccept@Hsb@0}{\rangeHsb}% +\pgfutil@namedef{pgfplots@colspace@max@Hsb@0}{\rangeHsb}% + +\def\pgfplotscolornormalizesequencenext@prepare@loop#1,{% + \def\pgfmathresult{#1}% + \ifx\pgfmathresult\pgfplots@EOI + \else + \begingroup + \pgfkeyslet{/pgf/fpu/handlers/invalid number/.@cmd}\pgfplotscolornormalizesequencenextbycomponents@parsenumber@error + \expandafter\pgfplotscolornormalizesequencenext@every@component\expandafter{\pgfmathresult}\pgfeov% + \ifpgfplotscolor@colorspaceknown + \expandafter\pgfplotscolornormalizesequencenextbycomponents@parsenumber\expandafter{\pgfmathresult}% + \fi + \pgfmath@smuggleone\pgfmathresult + \endgroup + \ifpgfplotscolor@colorspaceknown + \expandafter\pgfplotscolornormalizesequencenextbycomponents@sanitize\expandafter{\pgfmathresult}% + \fi + \ifx\pgfplotsretval\pgfutil@empty + \edef\pgfplotsretval{\pgfmathresult}% + \else + \edef\pgfplotsretval{\pgfplotsretval,\pgfmathresult}% + \fi + \advance\c@pgf@counta by1 % + \expandafter\pgfplotscolornormalizesequencenext@prepare@loop + \fi +} + +\def\pgfplotscolornormalizesequencenextbycomponents@parsenumber#1{% + \pgfmathfloatparsenumber{#1}% + \pgfmathfloattofixed\pgfmathresult +} + +\def\pgfplotscolornormalizesequencenextbycomponents@parsenumber@error#1#2\pgfeov{% + \pgfplotsthrow{invalid color component}{\pgfmathresult}{Sorry, the color component value '#1' is no number. Did you mean 'color=#1'? The error occured near `\pgfplotscolornormalizesequence@context@message'}\pgfeov% + \pgfmathfloatcreate{0}{0.0}{0}% +}% + +% #1 the color component value +\def\pgfplotscolornormalizesequencenextbycomponents@sanitize#1{% + \pgf@xa=#1pt % + % + % check if we have something like + % \csname pgfplots@colspace@minaccept@<colorspace name>@2\endcsname where 2 is component index: + \edef\pgfplots@loc@TMPc{@\pgfplotscolornormalizesequence@cur@colspace @\the\c@pgf@counta}% + \pgfutil@ifundefined{pgfplots@colspace@minaccept\pgfplots@loc@TMPc}{% + % NO - implicitly defined to [0,1] + \def\pgfplots@colspace@minaccept@@{-0.001}% + \def\pgfplots@colspace@min@@{-0.001}% + \def\pgfplots@colspace@maxaccept@@{1.001}% + \def\pgfplots@colspace@max@@{1}% + }{% + % YES - expect all four values: + \edef\pgfplots@colspace@minaccept@@{\csname pgfplots@colspace@minaccept\pgfplots@loc@TMPc\endcsname}% + \edef\pgfplots@colspace@min@@{\csname pgfplots@colspace@min\pgfplots@loc@TMPc\endcsname}% + \edef\pgfplots@colspace@maxaccept@@{\csname pgfplots@colspace@maxaccept\pgfplots@loc@TMPc\endcsname}% + \edef\pgfplots@colspace@max@@{\csname pgfplots@colspace@max\pgfplots@loc@TMPc\endcsname}% + }% + \ifdim\pgf@xa<\pgfplots@colspace@minaccept@@ pt % + \edef\pgfmathresult{\pgfplots@colspace@min@@}% + \pgfplotscolor@rangeexception{#1}% + \else + \ifdim\pgf@xa>\pgfplots@colspace@maxaccept@@ pt % + \edef\pgfmathresult{\pgfplots@colspace@max@@}% + \pgfplotscolor@rangeexception{#1}% + \else + % Ah - the common case! + \edef\pgfmathresult{\pgf@sys@tonumber\pgf@xa}% normalize number (strip trailing zeros etc). + \fi + \fi +} + +\def\pgfplotscolor@rangeexception#1{% + \pgfplotsthrow{invalid color component}{\pgfmathresult}{Sorry, the color component value #1 (no. \the\c@pgf@counta) is out of range. The allowed range is 0 <= value <= 1. The error occured near `\pgfplotscolornormalizesequence@context@message'}\pgfeov% +} + + +% Same as \pgfplotscolornormalizesequencenextbycomponents but with +% more freedom in the input. +% +% #1 some color. +% Accepted formats: +% 'color=<xcolor value>' +% <xcolor value> is any valid expression of the xcolor package. +% +% 'rgb=R,G,B' +% R,G,B are numbers in [0,1] +% +% 'rgb255=R,G,B' +% R,G,B are numbers in [0,255] +% +% 'cmyk=C,M,Y,K' +% C, M, Y, and K are numbers in [0,1] +% +% 'cmyk255=C,M,Y,K' +% C, M, Y, and K are numbers in [0,255] +% +% 'gray=G' +% G is a gray scale number in [0,1] +% +% 'C1,C2,C3' +% any number of Ci can folow, each is interpreted in the default +% colorspace (i.e. the one set before at the beginning of the +% sequence) +% +% +% Example: +% \pgfplotscolornormalizesequencenext{color=blue} +% \pgfplotscolornormalizesequencenext{rgb=1,0,0} +% \pgfplotscolornormalizesequencenext{cmyk=1,0,0,1} +% \pgfplotscolornormalizesequencenext{1,0,0} (interpreted in the +% colorspace set at \pgfplotscolornormalizesequence) +% +% POSTCONDITION: see \pgfplotscolornormalizesequencenextbycomponents +\def\pgfplotscolornormalizesequencenext#1{% + \edef\pgfplotscolornormalizesequence@context@message@default{#1}% + \expandafter\pgfplotscolornormalizesequencenext@\pgfplotscolornormalizesequence@context@message@default\pgfplots@EOI +} +\def\pgfplotscolornormalizesequencenext@{% + \pgfutil@ifnextchar c{% + \pgfplotscolornormalizesequencenext@c + }{% + \pgfutil@ifnextchar r{% + \pgfplotscolornormalizesequencenext@rgb + }{% + \pgfutil@ifnextchar g{% + \pgfplotscolornormalizesequencenext@gray + }{% + \pgfplotscolornormalizesequencenext@defaultcolspace + }% + }% + }% +} + +\def\pgfplotscolornormalizesequencenext@gray gray=#1\pgfplots@EOI{% + % FIXME : we might be better off with real support for a gray + % colorspace! + \pgfplotscolornormalizesequencenextbycomponents{rgb}{#1,#1,#1}% +} + +\def\pgfplotscolornormalizesequencenext@defaultcolspace#1\pgfplots@EOI{% + \edef\pgfplotsretval{#1}% + \ifx\pgfplotsretval\pgfutil@empty + % hm. Ok, simply return the empty input. + % + % ... and the number of components. + \pgfplotscolor@get@num@components{\pgfplotscolornormalizesequence@colspace}{\pgfplotsretvalb}% + % + \else + \expandafter\pgfutil@in@\expandafter=\expandafter{\pgfplotsretval}% + \ifpgfutil@in@ + \expandafter\pgfplotscolornormalizesequencenext@unknown@colspace\pgfplotsretval\pgfplots@EOI + \else + \ifx\pgfplotscolornormalizesequence@colspace@input\pgfutil@empty + \pgfplotsthrow{invalid argument}{\pgfplots@loc@TMPa}{The input color #1 cannot be interpreted; please assign a default color space first}\pgfeov% + \fi + \pgfplotscolornormalizesequencenextbycomponents{\pgfplotscolornormalizesequence@colspace@input}{#1}% + \fi + \fi +} + +\def\pgfplotscolornormalizesequencenext@unknown@colspace#1=#2\pgfplots@EOI{% + \pgfplotscolornormalizesequencenextbycomponents{#1}{#2}% +} + +\def\pgfplotscolornormalizesequencenext@rgb rgb{% + \pgfutil@ifnextchar2{% + \pgfplotscolornormalizesequencenext@rgb@two@five@five + }{% + \pgfplotscolornormalizesequencenext@rgb@plain + }% +} +\def\pgfplotscolornormalizesequencenext@rgb@plain=#1\pgfplots@EOI{% + \pgfplotscolornormalizesequencenextbycomponents{rgb}{#1}% +} + +\def\pgfplotscolorsequence@two@five@five@rescale#1{% + \pgfmath@basic@multiply@{0.003921568}{#1}% +}% +\def\pgfplotscolornormalizesequencenext@rgb@two@five@five255=#1,#2,#3\pgfplots@EOI{% + \pgfplotscolorsequence@two@five@five@rescale{#1}% + \let\pgfplots@loc@TMPa=\pgfmathresult + \pgfplotscolorsequence@two@five@five@rescale{#2}% + \let\pgfplots@loc@TMPb=\pgfmathresult + \pgfplotscolorsequence@two@five@five@rescale{#3}% + \edef\pgfplots@loc@TMPc{{rgb}{\pgfplots@loc@TMPa,\pgfplots@loc@TMPb,\pgfmathresult}}% + \expandafter\pgfplotscolornormalizesequencenextbycomponents\pgfplots@loc@TMPc% +} + +\def\pgfplotscolornormalizesequencenext@c c{% + \pgfutil@ifnextchar m{% + \pgfplotscolornormalizesequencenext@cmyk + }{% + \pgfplotscolornormalizesequencenext@color + }% +}% + +\def\pgfplotscolornormalizesequencenext@cmyk myk{% + \pgfutil@ifnextchar2{% + \pgfplotscolornormalizesequencenext@cmyk@two@five@five + }{% + \pgfplotscolornormalizesequencenext@cmyk@plain + }% +}% + +\def\pgfplotscolornormalizesequencenext@cmyk@plain=#1\pgfplots@EOI{% + \pgfplotscolornormalizesequencenextbycomponents{cmyk}{#1}% +}% +\def\pgfplotscolornormalizesequencenext@cmyk@two@five@five255=#1,#2,#3,#4\pgfplots@EOI{% + \pgfplotscolorsequence@two@five@five@rescale{#1}% + \let\pgfplots@loc@TMPa=\pgfmathresult + \pgfplotscolorsequence@two@five@five@rescale{#2}% + \let\pgfplots@loc@TMPb=\pgfmathresult + \pgfplotscolorsequence@two@five@five@rescale{#3}% + \let\pgfplots@loc@TMPc=\pgfmathresult + \pgfplotscolorsequence@two@five@five@rescale{#4}% + \edef\pgfplots@loc@TMPc{{cmyk}{\pgfplots@loc@TMPa,\pgfplots@loc@TMPb,\pgfplots@loc@TMPc,\pgfmathresult}}% + \expandafter\pgfplotscolornormalizesequencenextbycomponents\pgfplots@loc@TMPc% +} + +% The implementation of \pgfutil@extractcolorspec for plain tex and +% context is ... strange. I prefer one which does the same as the +% xcolor version (which is also what pgf does for latex): +\def\pgfplotsutil@extractcolorspec@xcolor@substitute#1#2{% + \begingroup + % this here relies on PGF's emulation of color in plain tex and + % context. Let's hope it works in the future... + \def\xcolor@##1##2##3##4{% + \edef#2{{##3}{##4}}% + }% + \csname\string\color@#1\endcsname + \global\let\pgfutil@extractcolorspec@@temp=#2% + \endgroup + \let#2=\pgfutil@extractcolorspec@@temp +}% + +\def\pgfplots@glob@TMPa#1#2{% + \def#2{{#1}}% +}% + +\pgfutil@IfUndefined{extractcolorspec}{% + % Ah. We do not have a suitable implementation of + % \extractcolorspec -- \pgfutil@extractcolorspec does not yield + % the colorspec on context and plain tex. + \def\pgfplotsutil@extractcolorspec{\pgfplotsutil@extractcolorspec@xcolor@substitute}% +}{% + \ifx\extractcolorspec\pgfplots@glob@TMPa + % Same problem as above: pgfutil-plain.def says + % \let\extractcolorspec=\pgfutil@extractcolorspec and that one + % is broken. + % Use my substitute: + \def\pgfplotsutil@extractcolorspec{\pgfplotsutil@extractcolorspec@xcolor@substitute}% + \else + \def\pgfplotsutil@extractcolorspec{\extractcolorspec}% + \fi +}% + +\def\pgfplotscolornormalizesequencenext@color olor=#1\pgfplots@EOI{% + \pgfutil@colorlet{pgf@tempcol}{#1}% + \pgfplotsutil@extractcolorspec{pgf@tempcol}{\pgf@tempcolor}% + \edef\pgfplots@loc@TMPa{\expandafter\pgfutil@firstoftwo\pgf@tempcolor}% + \edef\pgfplots@loc@TMPb{\expandafter\pgfutil@secondoftwo\pgf@tempcolor}% + % + % I expect that \pgf@tempcolor is of the form + % {<colorspace>}{<comma-separated components>} + % + % unfortunately, the <colorspace> has strange catcodes such that + % we cannot easily compare it by means of \ifx. I normalize it + % here: + \pgfutil@ifundefined{pgfplots@colspace@name@\pgfplots@loc@TMPa}{% + % ohoh. we cannot normalize the name. Let's hope that works out. + % note that we cannot throw an exception here as we might very well be able + % to convert the color to some suitable color space! + }{% + \edef\pgfplots@loc@TMPa{% + \csname pgfplots@colspace@name@\pgfplots@loc@TMPa\endcsname% + }% + }% + \edef\pgf@tempcolor{% + {\pgfplots@loc@TMPa}% + {\pgfplots@loc@TMPb}% + }% + \expandafter\pgfplotscolornormalizesequencenextbycomponents\pgf@tempcolor% + % +}% + +% Defines \pgfplotsretval to be a "neutral" color, i.e. one in which +% all components are zero. +% @see \pgfplotscolorzero +% @see \pgfplotscoloraddweighted +\def\pgfplotscolornormalizesequencezero{% + \pgfplotscolornormalizesequencegetnumcomponents + \pgfplotscolorzero{\pgfplotsretval}% +} + +% Defines \pgfplotsretval to be a "neutral" color, i.e. one in which +% all components are zero. +% +% #1: the number of color components to be used (like 3 for rgb) +% @see \pgfplotscoloraddweighted +\def\pgfplotscolorzero#1{% + \c@pgf@countb=#1\relax + % + \c@pgf@counta=1 % + \def\pgfplotsretval{0}% + \pgfutil@loop + \ifnum\c@pgf@counta<\c@pgf@countb + \edef\pgfplotsretval{\pgfplotsretval,0}% + \advance\c@pgf@counta by1 % + \pgfutil@repeat +}% + +% Defines \pgfplotsretval to be the interpolated color #1 + #2*#3. +% #1 the first color (like 0,0,0) +% #2 a scaling factor (like 4) +% #3 the second color (like 1,0,0.5) +% +% POSTCONDITION: \pgfplotsretval contains the result +% +% @see \pgfplotscolorzero +% @see \pgfplotscoloraddweighted +\def\pgfplotscolornormalizesequenceaddweighted#1#2#3{% + \begingroup + \pgfplotscolornormalizesequencegetnumcomponents + \global\let\pgfplots@glob@TMPd\pgfplotsretval + \endgroup + \pgfplotscoloraddweighted{\pgfplots@glob@TMPd}{#1}{#2}{#3}% +} + +% Defines \pgfplotsretval to be the interpolated color #2 + #3*#4. +% #1 the number of color components to be used (3 for rgb) +% #2 the first color (like 0,0,0) +% #3 a scaling factor (like 4) +% #4 the second color (like 1,0,0.5) +% +% POSTCONDITION: \pgfplotsretval contains the result +% +% @see \pgfplotscolorzero +\def\pgfplotscoloraddweighted#1#2#3#4{% + \begingroup + \expandafter\global + \expandafter\let + \expandafter\pgfplots@glob@TMPd\csname pgfplotscolornormalizesequencegetnumcomponents@#1\endcsname + \endgroup + \edef\pgfplots@loc@TMPa{#2:#4\noexpand\relax{#3}}% + \expandafter\pgfplots@glob@TMPd\pgfplots@loc@TMPa% +}% + +\def\pgfplotscolornormalizesequenceaddweighted@single#1#2#3{% + \pgf@xa=#1pt % + \pgf@xb=#3pt % + \advance\pgf@xa by#2\pgf@xb + \edef\pgfplotsretval{\pgf@sys@tonumber\pgf@xa}% +}% + +\expandafter\def\csname pgfplotscolornormalizesequencegetnumcomponents@1\endcsname#1:#2\relax#3{% + \pgfplotscolornormalizesequenceaddweighted@single{#1}{#3}{#2}% +}% +\expandafter\def\csname pgfplotscolornormalizesequencegetnumcomponents@3\endcsname#1,#2,#3:#4,#5,#6\relax#7{% + \pgfplotscolornormalizesequenceaddweighted@single{#1}{#7}{#4}% + \let\pgfplots@loc@TMPa=\pgfplotsretval + \pgfplotscolornormalizesequenceaddweighted@single{#2}{#7}{#5}% + \let\pgfplots@loc@TMPb=\pgfplotsretval + \pgfplotscolornormalizesequenceaddweighted@single{#3}{#7}{#6}% + \let\pgfplots@loc@TMPc=\pgfplotsretval + \edef\pgfplotsretval{\pgfplots@loc@TMPa,\pgfplots@loc@TMPb,\pgfplots@loc@TMPc}% +}% +\expandafter\def\csname pgfplotscolornormalizesequencegetnumcomponents@4\endcsname#1,#2,#3,#4:#5,#6,#7,#8\relax#9{% + \pgfplotscolornormalizesequenceaddweighted@single{#1}{#9}{#5}% + \let\pgfplots@loc@TMPa=\pgfplotsretval + \pgfplotscolornormalizesequenceaddweighted@single{#2}{#9}{#6}% + \let\pgfplots@loc@TMPb=\pgfplotsretval + \pgfplotscolornormalizesequenceaddweighted@single{#3}{#9}{#7}% + \let\pgfplots@loc@TMPc=\pgfplotsretval + \pgfplotscolornormalizesequenceaddweighted@single{#4}{#9}{#8}% + \let\pgfplots@loc@TMPd=\pgfplotsretval + \edef\pgfplotsretval{\pgfplots@loc@TMPa,\pgfplots@loc@TMPb,\pgfplots@loc@TMPc,\pgfplots@loc@TMPd}% +}% + +\endinput diff --git a/Master/texmf-dist/tex/generic/pgfplots/util/pgfplotscolormap.code.tex b/Master/texmf-dist/tex/generic/pgfplots/util/pgfplotscolormap.code.tex index 838e0393e2e..4e369084a29 100644 --- a/Master/texmf-dist/tex/generic/pgfplots/util/pgfplotscolormap.code.tex +++ b/Master/texmf-dist/tex/generic/pgfplots/util/pgfplotscolormap.code.tex @@ -8,7 +8,7 @@ % % It is based on Till Tantau's PGF package. % -% Copyright 2007/2008 by Christian Feuersänger. +% Copyright 2007-2013 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 @@ -25,6 +25,8 @@ % %-------------------------------------------- +\input pgfplotscolor.code.tex + \pgfkeyssetvalue{/pgfplots/colormap default colorspace}{auto} % This package relies on pgfplots temporary registers and its array @@ -78,39 +80,19 @@ \expandafter\let\csname\pgfplots@createcolormap@name @h\endcsname=\pgfplots@createcolormap@H \pgfmathreciprocal@{\pgfplots@createcolormap@H}% \expandafter\let\csname\pgfplots@createcolormap@name @invh\endcsname=\pgfmathresult - \expandafter\let\csname\pgfplots@createcolormap@name @col@comps\endcsname=\pgfplots@createcolormap@col@comps - \expandafter\let\csname\pgfplots@createcolormap@name @colspace\endcsname=\pgfplots@createcolormap@colspace + % + \endpgfplotscolornormalizesequence% + \expandafter\let\csname\pgfplots@createcolormap@name @colspace\endcsname=\pgfplotsretval + \expandafter\let\csname\pgfplots@createcolormap@name @col@comps\endcsname=\pgfplotsretvalb %\pgfplots@colormap@showdebuginfofor{#1}% } + + \def\pgfplots@createcolormap@initcolorspace{% - \pgfkeysgetvalue{/pgfplots/colormap default colorspace}\pgfplots@loc@TMPa - \edef\pgfplots@loc@TMPa{\pgfplots@loc@TMPa}% - \def\pgfplots@loc@TMPb{auto}% - \ifx\pgfplots@loc@TMPb\pgfplots@loc@TMPa - % colormap default colorspace=auto: same as empty. - \let\pgfplots@loc@TMPa=\pgfutil@empty - \fi - \ifx\pgfplots@loc@TMPa\pgfutil@empty - % colormap default colorspace=auto: - \def\pgfplots@createcolormap@col@comps{}% to be filled from first point - \def\pgfplots@createcolormap@colspace{}% - \else - \def\pgfplots@loc@TMPb{rgb}% - \ifx\pgfplots@loc@TMPb\pgfplots@loc@TMPa - % colormap default colorspace=rgb: - \def\pgfplots@createcolormap@colspace{rgb}% - \def\pgfplots@createcolormap@col@comps{3}% - \else - \def\pgfplots@loc@TMPb{cmyk}% - \ifx\pgfplots@loc@TMPb\pgfplots@loc@TMPa - % colormap default colorspace=cmyk: - \def\pgfplots@createcolormap@colspace{cmyk}% - \def\pgfplots@createcolormap@col@comps{4}% - \else - \pgfplots@error{Sorry, the choice 'colormap default colorspace=\pgfplots@loc@TMPa' is unknown to pgfplots, please use one of 'auto,rgb,cmyk'}% - \fi - \fi - \fi + \pgfplotscolornormalizesequence[ + colorspace=\pgfkeysvalueof{/pgfplots/colormap default colorspace}, + context message=\pgfplots@createcolormap@context, + ]% }% \def\pgfplots@createcolormap@seth[#1]{% \def\pgfplots@createcolormap@context{[#1]}% @@ -132,16 +114,9 @@ {% \pgfutil@ifnextchar;{\pgfplots@createcolormap@grabsemicolon}% {% - \pgfutil@ifnextchar r{\pgfplots@createcolormap@grabrgb}% + \expandafter\pgfutil@ifnextchar\pgfplots@activesemicolon{\pgfplots@createcolormap@grabsemicolon@active}% {% - \pgfutil@ifnextchar g{\pgfplots@createcolormap@grabgray}% - {% - \pgfutil@ifnextchar c{\pgfplots@createcolormap@grabc}% - { - \expandafter\pgfutil@ifnextchar\pgfplots@activesemicolon{\pgfplots@createcolormap@grabsemicolon@active}% - {\pgfplots@createcolormap@error}% - }% - }% + \pgfplots@createcolormap@grabnext }% }% }% @@ -153,230 +128,129 @@ \pgfplots@error{Illformed colormap specification: I could not read the substring `\the\t@pgfplots@toka' starting at `\the\t@pgfplots@tokb'}% }% }% -\def\pgfplots@createcolormap@grabsemicolon;{\pgfplots@createcolormap@}% -{ - \catcode`\;=13 - \gdef\pgfplots@createcolormap@grabsemicolon@active;{\pgfplots@createcolormap@}% +\def\pgfplots@createcolormap@grabnext#1({% + \pgfplots@createcolormap@grabnext@{#1}% } +\def\pgfplots@createcolormap@grabnext@#1#2){% + \pgfutil@in@={#1}% + \ifpgfutil@in@ + % Ah. we do not have a position, i.e. we have + % color=(green) + % or something like this. + % + % this here defines \pgfplots@loc@TMPa to contain the + % colorspace: + \pgfplots@createcolormap@grabnext@remove@equal@sign#1\pgfplots@EOI + % + \pgfplots@createcolormap@grabnext@computenextposition + \let\pgfplots@loc@TMPb=\pgfmathresult% posisiton + \def\pgfplots@loc@TMPc{#2}% color data + \let\pgfplots@loc@TMPd=\pgfplots@createcolormap@grabnext@complete + \else + % Ah. We have something like 'color(1cm)' and we did not see + % the equal sign so far. + \def\pgfplots@loc@TMPa{#1}% colorspace + \def\pgfplots@loc@TMPb{#2}% position + % + % and collect the color data: + \def\pgfplots@loc@TMPd{% + \pgfutil@ifnextchar={% + \pgfplots@createcolormap@grabnext@@ + }{% + \pgfplots@createcolormap@error#1(#2)% + }% + }% + \fi + \pgfplots@loc@TMPd +}% -\def\pgfplots@createcolormap@next{% - \pgfutil@ifnextchar({% - \pgfplots@createcolormap@next@ - }{% - % determine next step size automatically: - \ifx\pgfplots@createcolormap@H\pgfutil@empty - \expandafter\pgfplotsarraycheckempty\expandafter{\pgfplots@createcolormap@name}% - \ifpgfplotsarrayempty - % first: - \def\pgfmathresult{0sp}% - \else - % second: - \def\pgfmathresult{1cm}% - \fi - \else - % not first: - \pgfmathadd@\pgfplots@createcolormap@LAST\pgfplots@createcolormap@H - \fi - \expandafter\pgfplots@createcolormap@next@\expandafter(\pgfmathresult)% - }% +\def\pgfplots@createcolormap@grabnext@remove@equal@sign#1=#2\pgfplots@EOI{% + \def\pgfplots@loc@TMPa{#1}% + % + % FIXME : what if #2 is not empty!? }% -\def\pgfplots@createcolormap@grabrgb rgb{ - \pgfutil@ifnextchar2{% - \pgfplots@createcolormap@grabrgb@two@five@five +\def\pgfplots@createcolormap@grabnext@@={% + \pgfutil@ifnextchar({% + \pgfplots@createcolormap@grabnext@@@ }{% - \let\pgfplots@createcolormap@next@\pgfplots@createcolormap@grabrgb@ - \pgfplots@createcolormap@next + \pgfplots@createcolormap@error=% }% -} -\def\pgfplots@createcolormap@grabrgb@(#1)=(#2,#3,#4){% - \def\pgfplots@createcolormap@context{rgb(#1)=(#2,#3,#4)}% - \pgfplots@createcolormap@nextRGB{#1}{#2}{#3}{#4}% - \pgfplots@createcolormap@} -\def\pgfplots@createcolormap@grabrgb@two@five@five@rescale#1{% - \pgfmath@basic@multiply@{0.003921568}{#1}% }% -\def\pgfplots@createcolormap@grabrgb@two@five@five255{% - \let\pgfplots@createcolormap@next@\pgfplots@createcolormap@grabrgb@two@five@five@ - \pgfplots@createcolormap@next -} -\def\pgfplots@createcolormap@grabrgb@two@five@five@(#1)=(#2,#3,#4){% - \def\pgfplots@createcolormap@context{rgb255(#1)=(#2,#3,#4)}% - \pgfplots@createcolormap@grabrgb@two@five@five@rescale{#2}% - \let\pgfplots@loc@TMPa=\pgfmathresult - \pgfplots@createcolormap@grabrgb@two@five@five@rescale{#3}% - \let\pgfplots@loc@TMPb=\pgfmathresult - \pgfplots@createcolormap@grabrgb@two@five@five@rescale{#4}% - \def\pgfplots@loc@TMPc{\pgfplots@createcolormap@nextRGB{#1}}% - \edef\pgfplots@loc@TMPa{{\pgfplots@loc@TMPa}{\pgfplots@loc@TMPb}{\pgfmathresult}}% - \expandafter\pgfplots@loc@TMPc\pgfplots@loc@TMPa - \pgfplots@createcolormap@} - - -\def\pgfplots@createcolormap@grabcmyk myk{ - \def\pgfplots@createcolormap@colspace@actual{cmyk}% - \def\pgfplots@createcolormap@col@comps@actual{4}% - \pgfutil@ifnextchar2{% - \pgfplots@createcolormap@grabcmyk@two@five@five - }{% - \let\pgfplots@createcolormap@next@\pgfplots@createcolormap@grabcmyk@ - \pgfplots@createcolormap@next - }% -} -\def\pgfplots@createcolormap@grabcmyk@(#1)=(#2,#3,#4,#5){% - \def\pgfplots@createcolormap@context{cmyk(#1)=(#2,#3,#4,#5)}% - \pgfplots@createcolormap@nextcolor{#1}{#2}{#3}{#4}{#5}% - \pgfplots@createcolormap@} -\def\pgfplots@createcolormap@grabcmyk@two@five@five255{% - \let\pgfplots@createcolormap@next@\pgfplots@createcolormap@grabcmyk@two@five@five@ - \pgfplots@createcolormap@next -} -\def\pgfplots@createcolormap@grabcmyk@two@five@five@(#1)=(#2,#3,#4,#5){% - \def\pgfplots@createcolormap@context{cmyk255(#1)=(#2,#3,#4,#5)}% - \pgfplots@createcolormap@grabcmyk@two@five@five@rescale{#2}% - \let\pgfplots@loc@TMPa=\pgfmathresult - \pgfplots@createcolormap@grabcmyk@two@five@five@rescale{#3}% - \let\pgfplots@loc@TMPb=\pgfmathresult - \pgfplots@createcolormap@grabcmyk@two@five@five@rescale{#4}% - \let\pgfplots@loc@TMPc=\pgfmathresult - \pgfplots@createcolormap@grabcmyk@two@five@five@rescale{#5}% - \def\pgfplots@loc@TMPd{\pgfplots@createcolormap@nextcolor{#1}}% - \edef\pgfplots@loc@TMPa{{\pgfplots@loc@TMPa}{\pgfplots@loc@TMPb}{\pgfplots@loc@TMPc}{\pgfmathresult}}% - \expandafter\pgfplots@loc@TMPd\pgfplots@loc@TMPa - \pgfplots@createcolormap@} - - -\def\pgfplots@createcolormap@grabgray gray{% - \let\pgfplots@createcolormap@next@\pgfplots@createcolormap@grabgray@ - \pgfplots@createcolormap@next +\def\pgfplots@createcolormap@grabnext@@@(#1){% + \def\pgfplots@loc@TMPc{#1}% + \pgfplots@createcolormap@grabnext@complete }% -\def\pgfplots@createcolormap@grabgray@(#1)=(#2){% - \def\pgfplots@createcolormap@context{gray(#1)=(#2)}% - \pgfplots@createcolormap@nextRGB{#1}{#2}{#2}{#2}% - \pgfplots@createcolormap@} - -\def\pgfplots@createcolormap@grabc c{% - \pgfutil@ifnextchar m{% - \pgfplots@createcolormap@grabcmyk - }{% - \pgfplots@createcolormap@grabcolor + +\def\pgfplots@createcolormap@grabnext@complete{% + \edef\pgfplots@loc@TMPa{% + {\pgfplots@loc@TMPb}% position + {% + \pgfplots@loc@TMPa% colorspace + =\pgfplots@loc@TMPc% color data + }% }% -}% -\def\pgfplots@createcolormap@grabcolor olor{% - \let\pgfplots@createcolormap@next@\pgfplots@createcolormap@grabcolor@ - \pgfplots@createcolormap@next -}% -\def\pgfplots@createcolormap@grabcolor@(#1)=(#2){% - \def\pgfplots@createcolormap@context{color(#1)=(#2)}% - \pgfutil@colorlet{pgf@tempcol}{#2}% - \pgfutil@extractcolorspec{pgf@tempcol}{\pgf@tempcolor}% - \ifx\pgfplots@createcolormap@colspace\pgfutil@empty - % This here is mainly for backwards compatibility... in older - % versions, rgb was the only choice. This should still work - % unless overruled explicitly. - \def\pgfplots@createcolormap@colspace{rgb}% - \def\pgfplots@createcolormap@col@comps{3}% - \fi - % convert the colorspace (if needed): - \expandafter\pgfutil@convertcolorspec\pgf@tempcolor{\pgfplots@createcolormap@colspace}{\pgf@rgbcolor}% - % - \let\pgfplots@createcolormap@colspace@actual=\pgfplots@createcolormap@colspace - \let\pgfplots@createcolormap@col@comps@actual=\pgfplots@createcolormap@col@comps + \expandafter\pgfplots@createcolormap@nextcolor\pgfplots@loc@TMPa % - \if4\pgfplots@createcolormap@col@comps - \let\pgfplots@loc@TMPa=\pgfplots@createcolormap@grabcolor@@@ + % continue loop: + \pgfplots@createcolormap@ +}% + +\def\pgfplots@createcolormap@grabnext@computenextposition{% + % determine next step size automatically: + \expandafter\pgfplotsarraycheckempty\expandafter{\pgfplots@createcolormap@name}% + \ifpgfplotsarrayempty + % first: must be at 0. + \def\pgfmathresult{0sp}% \else - \let\pgfplots@loc@TMPa=\pgfplots@createcolormap@grabcolor@@ + % not first: + \ifx\pgfplots@createcolormap@H\pgfutil@empty + % ah; we really have to deduce something. We are at the + % second node: + \def\pgfmathresult{1cm}% + \else + \pgfmathadd@\pgfplots@createcolormap@LAST\pgfplots@createcolormap@H + \fi \fi - \expandafter\pgfplots@loc@TMPa\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@grabcolor@@@#1,#2,#3,#4\relax#5{% - \pgfplots@createcolormap@nextcolor{#5}{#1}{#2}{#3}{#4}% - \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. The error occured near `\pgfplots@createcolormap@context'}% }% -\def\pgfplots@createcolormap@rangeexception#1#2{% - \pgfplots@error{Sorry, the color component at index #1 (value #2) is out of range. The allowed range is 0 <= value <= 1. The error occured near `\pgfplots@createcolormap@context'}% + +\def\pgfplots@createcolormap@grabsemicolon;{\pgfplots@createcolormap@}% + +{ + \catcode`\;=13 + \gdef\pgfplots@createcolormap@grabsemicolon@active;{\pgfplots@createcolormap@}% } -% Ok, we parsed the next single spec. -% #1: the width -% #2,#3,#4 RGB values. -\def\pgfplots@createcolormap@nextRGB#1#2#3#4{% - \def\pgfplots@createcolormap@colspace@actual{rgb}% - \def\pgfplots@createcolormap@col@comps@actual{3}% - \pgfplots@createcolormap@nextcolor{#1}{#2}{#3}{#4}{}% +\def\pgfplots@createcolormap@nextcolor@tostring#1=#2\pgfplots@EOI#3{% + #1(#3)=(#2)% }% % #1: h -% #2...#5: the color components (at least 3 non-empty, can be 4). -\def\pgfplots@createcolormap@nextcolor#1#2#3#4#5{% - \ifdim#2pt<0pt - \pgfplots@createcolormap@rangeexception0{#2}% - \fi - \ifdim#3pt<0pt - \pgfplots@createcolormap@rangeexception1{#3}% - \fi - \ifdim#4pt<0pt - \pgfplots@createcolormap@rangeexception2{#4}% - \fi - \ifdim#2pt>1pt - \pgfplots@createcolormap@rangeexception0{#2}% - \fi - \ifdim#3pt>1pt - \pgfplots@createcolormap@rangeexception1{#3}% - \fi - \ifdim#4pt>1pt - \pgfplots@createcolormap@rangeexception2{#4}% - \fi - \if4\pgfplots@createcolormap@col@comps@actual - \ifdim#5pt<0pt - \pgfplots@createcolormap@rangeexception3{#5}% - \fi - \ifdim#5pt>1pt - \pgfplots@createcolormap@rangeexception3{#5}% - \fi - \fi - \def\pgfplots@loc@TMPb{\pgfplots@createcolormap@nextcolor@{#1}{#2}{#3}{#4}{#5}}% - \ifx\pgfplots@createcolormap@colspace@actual\pgfplots@createcolormap@colspace - \else - \ifx\pgfplots@createcolormap@colspace\pgfutil@empty - \let\pgfplots@createcolormap@colspace=\pgfplots@createcolormap@colspace@actual - \let\pgfplots@createcolormap@col@comps=\pgfplots@createcolormap@col@comps@actual - \else - % Oh. We need to convert the color space! - \edef\pgfplots@loc@TMPa{{\pgfplots@createcolormap@colspace@actual}{#2,#3,#4\if4\pgfplots@createcolormap@col@comps@actual,#5\fi}}% - \expandafter\pgfutil@convertcolorspec\pgfplots@loc@TMPa{\pgfplots@createcolormap@colspace}{\pgfplots@loc@TMPa}% - % invoke - % \pgfplots@createcolormap@nextcolor@{#1}{C1}{C2}{C3}{C4}. - % We need to compute C1 ... C4 : - \def\pgf@colmarshal{{#1}}% - \expandafter\pgf@uncomma\pgfplots@loc@TMPa,,% - \if4\pgfplots@createcolormap@col@comps - \else - % ok, we have C4={}. Append it: - \edef\pgf@colmarshal{\pgf@colmarshal{}}% - \fi - \def\pgfplots@loc@TMPb{\expandafter\pgfplots@createcolormap@nextcolor@\pgf@colmarshal}% - \fi - \fi - \pgfplots@loc@TMPb +% #2: a compound element of the form +% '<colorspace>=<comma-separated-color-components>' +% The format is chosen such that it can be forwarded directly to +% \pgfplotscolornormalizesequencenext +% +% see \pgfplotscolornormalizesequencenext for details +\def\pgfplots@createcolormap@nextcolor#1#2{% + \def\pgfplots@createcolormap@context{\pgfplots@createcolormap@nextcolor@tostring#2\pgfplots@EOI{#1}}% + % + \pgfplotscolornormalizesequencenext{#2}% + \let\pgfplots@createcolormap@col@comps=\pgfplotsretvalb + % + \edef\pgfplots@loc@TMPa{{#1}{\pgfplotsretval}}% + \expandafter\pgfplots@createcolormap@nextcolor@\pgfplots@loc@TMPa% }% -\def\pgfplots@createcolormap@nextcolor@#1#2#3#4#5{% -%\message{processing color #1=(#2,#3,#4,#5) with \pgfplots@createcolormap@col@comps@actual\space components^^J}% +\def\pgfplots@createcolormap@nextcolor@#1#2{% +%\message{processing color #1=(#2)^^J}% % compute '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)}% +%\message{found current diff = \pgfplots@createcolormap@H@cur\ ( from \pgfplots@createcolormap@MAX pt - \pgfplots@createcolormap@LAST pt)^^J}% + \let\pgfplots@createcolormap@LAST=\pgfplots@createcolormap@MAX \ifx\pgfplots@createcolormap@H\pgfutil@empty \expandafter\pgfplotsarraycheckempty\expandafter{\pgfplots@createcolormap@name}% \ifpgfplotsarrayempty @@ -406,30 +280,35 @@ \ifx\pgfmathresult\pgfutil@empty % I can't do that yet. \else - \let\pgfplots@loc@TMPb=\pgfmathresult + \let\pgfplots@createcolormap@loop@end=\pgfmathresult % interpolate missing values using the already fixed H. % This interpolation procedure is stupid because it works % only in forward direction - but it works at least. % For the backwards direction, you can provide the % meshwidth explicitly at % \pgfplotscreatecolormap{}{[1pt]} - \pgfplotsforeachungrouped \c@pgfplots@createcolormap in {1,2,...,\pgfplots@loc@TMPb} {% - \ifdim\c@pgfplots@createcolormap pt=\pgfplots@loc@TMPb pt + \pgfplotsforeachungrouped \c@pgfplots@createcolormap in {1,2,...,\pgfplots@createcolormap@loop@end} {% + \ifdim\c@pgfplots@createcolormap pt=\pgfplots@createcolormap@loop@end pt % % omit the last. \else - \pgfmathparse{\pgfplots@createcolormap@lastA + \c@pgfplots@createcolormap/\pgfplots@loc@TMPb * ( #2 - \pgfplots@createcolormap@lastA )}% - \let\pgfplots@createcolormap@nextA=\pgfmathresult - \pgfmathparse{\pgfplots@createcolormap@lastB + \c@pgfplots@createcolormap/\pgfplots@loc@TMPb * ( #3 - \pgfplots@createcolormap@lastB )}% - \let\pgfplots@createcolormap@nextB=\pgfmathresult - \pgfmathparse{\pgfplots@createcolormap@lastC + \c@pgfplots@createcolormap/\pgfplots@loc@TMPb * ( #4 - \pgfplots@createcolormap@lastC )}% - \let\pgfplots@createcolormap@nextC=\pgfmathresult - \if4\pgfplots@createcolormap@col@comps - \pgfmathparse{\pgfplots@createcolormap@lastD + \c@pgfplots@createcolormap/\pgfplots@loc@TMPb * ( #4 - \pgfplots@createcolormap@lastD )}% - \let\pgfplots@createcolormap@nextD=\pgfmathresult - \fi + \pgfmathparse{\c@pgfplots@createcolormap/\pgfplots@createcolormap@loop@end}% + \let\pgfplots@createcolormap@scale@current=\pgfmathresult + \pgfmathparse{1-\pgfplots@createcolormap@scale@current}% + \let\pgfplots@createcolormap@scale@last=\pgfmathresult + % + \pgfplotscolornormalizesequencezero + \pgfplotscolornormalizesequenceaddweighted + {\pgfplotsretval} + {\pgfplots@createcolormap@scale@current} + {#2}% + \pgfplotscolornormalizesequenceaddweighted + {\pgfplotsretval} + {\pgfplots@createcolormap@scale@last} + {\pgfplots@createcolormap@last}% % +%\message{interpolation step \c@pgfplots@createcolormap = \pgfplotsretval^^J}% \edef\pgfplots@loc@TMPa{% - \noexpand\pgfplotsarraypushback{\pgfplots@createcolormap@nextA,\pgfplots@createcolormap@nextB,\pgfplots@createcolormap@nextC\if4\pgfplots@createcolormap@col@comps,\pgfplots@createcolormap@nextD\fi}% + \noexpand\pgfplotsarraypushback{\pgfplotsretval}% \noexpand\to}% \expandafter\pgfplots@loc@TMPa\expandafter{\pgfplots@createcolormap@name}% \fi @@ -437,12 +316,9 @@ \fi \fi \fi - \edef\pgfplots@loc@TMPa{\noexpand\pgfplotsarraypushback{#2,#3,#4\if4\pgfplots@createcolormap@col@comps,#5\fi}\noexpand\to}% + \edef\pgfplots@loc@TMPa{\noexpand\pgfplotsarraypushback{#2}\noexpand\to}% \expandafter\pgfplots@loc@TMPa\expandafter{\pgfplots@createcolormap@name}% - \edef\pgfplots@createcolormap@lastA{#2}% - \edef\pgfplots@createcolormap@lastB{#3}% - \edef\pgfplots@createcolormap@lastC{#4}% - \edef\pgfplots@createcolormap@lastD{#5}% + \edef\pgfplots@createcolormap@last{#2}% }% \def\pgfplots@createcolormap@nextRGB@consider@reinterpolation#1\relax{% \pgf@xa=#1pt @@ -488,6 +364,21 @@ \endgroup } +% Defines \pgfplotsretval to contain the mesh width of colormap #1 +\def\pgfplotscolormapgetmeshwidth#1{% + \expandafter\let\expandafter\pgfplotsretval\csname pgfpl@cm@#1@h\endcsname% +}% + +% defines macro #2 to contain a serialized variant of the color +% components (only the color components!) +\def\pgfplotscolormapserializecomponentstomacro#1#2{% + \pgfplotsapplistXnewempty\pgfplots@serialize@list@ + \pgfplotsarrayforeachungrouped{pgfpl@cm@#1}\as\elem{% + \expandafter\pgfplotsapplistXpushback\expandafter{\elem},\to\pgfplots@serialize@list@ + }% + \pgfplotsapplistXlet#2=\pgfplots@serialize@list@ +}% + % Copies the contents of the colormap named '#1' into a macro '#2'. % Invocation of the macro will then re-create the colormap. % @@ -495,11 +386,7 @@ % #2: a macro name \def\pgfplotscolormapserializetomacro#1#2{% \begingroup - \pgfplotsapplistXnewempty\pgfplots@serialize@list@ - \pgfplotsarrayforeachungrouped{pgfpl@cm@#1}\as\elem{% - \expandafter\pgfplotsapplistXpushback\expandafter{\elem},\to\pgfplots@serialize@list@ - }% - \pgfplotsapplistXlet\pgfplots@serialize@list=\pgfplots@serialize@list@ + \pgfplotscolormapserializecomponentstomacro{#1}\pgfplots@serialize@list \toks0={\expandafter\def\csname pgfpl@cm@#1@h\endcsname}% \toks1={\expandafter\def\csname pgfpl@cm@#1@invh\endcsname}% \toks2={% @@ -552,12 +439,16 @@ \def\pgfplots@loc@TMPa{}% \def\pgfplots@loc@TMPb{}% \def\pgfplots@loc@TMPc{}% + \ifnum\csname pgfpl@cm@#1@col@comps\endcsname>4 + \pgfplots@error{Sorry, processing more than 4 color components (as required for color map #1) is unsupported in this context}% + \fi \pgfplotsarrayforeachungrouped{pgfpl@cm@#1}\as\cdata{% - \if4\csname pgfpl@cm@#1@col@comps\endcsname - \edef\cdata{\expandafter\pgfplotscolormaptopdffunction@convertcdata@four\cdata\relax}% - \else - \edef\cdata{\expandafter\pgfplotscolormaptopdffunction@convertcdata\cdata\relax}% - \fi + \edef\cdata{% + \expandafter + \expandafter + \csname pgfplotscolormaptopdffunction@convertcdata@\csname pgfpl@cm@#1@col@comps\endcsname\endcsname + \cdata\relax + }% \ifnum\c@pgf@counta>0 \t@pgfplots@toka=\expandafter{\pgfplotsretval}% \xdef\pgfplotsretval{% @@ -589,8 +480,10 @@ }% \endgroup }% -\def\pgfplotscolormaptopdffunction@convertcdata#1,#2,#3\relax{#1 #2 #3}% -\def\pgfplotscolormaptopdffunction@convertcdata@four#1,#2,#3,#4\relax{#1 #2 #3 #4}% +\expandafter\def\csname pgfplotscolormaptopdffunction@convertcdata@1\endcsname#1\relax{#1}% +\expandafter\def\csname pgfplotscolormaptopdffunction@convertcdata@2\endcsname#1,#2\relax{#1 #2}% +\expandafter\def\csname pgfplotscolormaptopdffunction@convertcdata@3\endcsname#1,#2,#3\relax{#1 #2 #3}% +\expandafter\def\csname pgfplotscolormaptopdffunction@convertcdata@4\endcsname#1,#2,#3,#4\relax{#1 #2 #3 #4}% % Invokes '#2' if a color map named '#1' exists and '#3' if no such color map exists. \def\pgfplotscolormapifdefined#1#2#3{\pgfplotsarrayifdefined{pgfpl@cm@#1}{#2}{#3}}% @@ -639,7 +532,7 @@ \else \pgfutil@ifundefined{pgfpl@cm@#1@warned}{% \expandafter\gdef\csname pgfpl@cm@#1@warned\endcsname{1}% - \pgfplots@warning{I am about to convert colormap '#1' from \pgfplots@colspace\space to rgb (which might be lossy). Perhaps the choice 'colorbar sampled={surf,shader=interp}' yields better results since it supports \pgfplots@colspace.}% + \pgfplotswarning{lossy colormap rgb conversion}{#1}{\pgfplots@colspace}\pgfeov% }{% }% \edef\pgf@tempcolor{{\pgfplots@colspace}{\pgfplotscolormaptoshadingspec@TMP}}% @@ -752,6 +645,8 @@ \expandafter\pgfplots@discardperiod\pgfmathresult\relax \pgfmathsubtract@{\pgfplotscolormapfind@transformedx@divh}{\pgfplotscolormapfind@intervalno}% \let\pgfplots@loc@factor=\pgfmathresult + \pgfmathsubtract@{1}{\pgfplots@loc@factor}% + \let\pgfplots@loc@factor@two=\pgfmathresult %\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. @@ -760,53 +655,30 @@ \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}% - \if4\csname pgfpl@cm@#5@col@comps\endcsname - \expandafter\pgfplotscolormapfind@interpolate@four\pgfplots@loc@TMPa\relax - \else - \expandafter\pgfplotscolormapfind@interpolate\pgfplots@loc@TMPa\relax - \fi + % + % + % color^m(x) = ( x/h - i ) * ( c_{i+1}^m - c_{i}^m ) + c_i^m + % = s * c_{i+1}^m + S * c_i^m + % + % s= x_h / h -i + % S = 1 - s + \pgfplotscolorzero{\csname pgfpl@cm@#5@col@comps\endcsname}% + \pgfplotscoloraddweighted + {\csname pgfpl@cm@#5@col@comps\endcsname} + {\pgfplotsretval}% + {\pgfplots@loc@factor@two}% + {\pgfplotscolormapfind@rgb@LEFT}% + \pgfplotscoloraddweighted + {\csname pgfpl@cm@#5@col@comps\endcsname} + {\pgfplotsretval}% + {\pgfplots@loc@factor}% + {\pgfplotscolormapfind@rgb@RIGHT}% + \let\pgfmathresult=\pgfplotsretval \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 - \pgfmathmultiply@{\pgfplots@loc@factor}{\pgfplotscolormapfind@Cdiff}% - \expandafter\pgfmathadd@\expandafter{\pgfmathresult}{#1}% - \let\RED=\pgfmathresult - % G: - \pgfmathsubtract@{#5}{#2}% - \let\pgfplotscolormapfind@Cdiff=\pgfmathresult - \pgfmathmultiply@{\pgfplots@loc@factor}{\pgfplotscolormapfind@Cdiff}% - \expandafter\pgfmathadd@\expandafter{\pgfmathresult}{#2}% - \let\GREEN=\pgfmathresult - % B: - \pgfmathsubtract@{#6}{#3}% - \let\pgfplotscolormapfind@Cdiff=\pgfmathresult - \pgfmathmultiply@{\pgfplots@loc@factor}{\pgfplotscolormapfind@Cdiff}% - \expandafter\pgfmathadd@\expandafter{\pgfmathresult}{#3}% - \let\BLUE=\pgfmathresult - \edef\pgfmathresult{\RED,\GREEN,\BLUE}% -}% -\def\pgfplotscolormapfind@interpolate@four#1,#2,#3,#4:#5,#6,#7,#8\relax{% - \pgfplotscolormapfind@interpolate#1,#2,#3:#5,#6,#7\relax - \let\CMY=\pgfmathresult - \pgfmathsubtract@{#8}{#4}% - \let\pgfplotscolormapfind@Cdiff=\pgfmathresult - \pgfmathmultiply@{\pgfplots@loc@factor}{\pgfplotscolormapfind@Cdiff}% - \expandafter\pgfmathadd@\expandafter{\pgfmathresult}{#4}% - \let\K=\pgfmathresult - \edef\pgfmathresult{\CMY,\K}% -} % Performs a direct color access into color map '#2' using an index % '#1'. @@ -856,8 +728,10 @@ \pgfutil@definecolor{mapped color}{rgb}{0,0,0}% make sure this color exists. It will be overwritten if needed. +% ATTENTION: replicated in pgfplots.code.tex : \pgfplotscreatecolormap{hot}{color(0cm)=(blue); color(1cm)=(yellow); color(2cm)=(orange); color(3cm)=(red)} +\def\pgfplotspointmetatransformedrange{0:1000} % Defines the 'mapped color' on the basis of % the current color map. 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 0ef2cb01c8d..57cc47873dd 100644 --- a/Master/texmf-dist/tex/generic/pgfplots/util/pgfplotsutil.code.tex +++ b/Master/texmf-dist/tex/generic/pgfplots/util/pgfplotsutil.code.tex @@ -1131,11 +1131,21 @@ }{% \pgfplotscoordmath{#5}{op}{divide}{{\pgfplots@x}{\pgfplots@r}}% \let\pgfplots@quot=\pgfmathresult + % + \pgfplotscoordmath{#5}{one}% + \let\pgfplots@loc@TMPc=\pgfmathresult + \pgfplotscoordmath{#5}{min}{\pgfplots@quot}{\pgfplots@loc@TMPc}% + \let\pgfplots@quot=\pgfmathresult + \pgfplotscoordmath{#5}{-one}% + \let\pgfplots@loc@TMPc=\pgfmathresult + \pgfplotscoordmath{#5}{max}{\pgfplots@quot}{\pgfplots@loc@TMPc}% + \let\pgfplots@quot=\pgfmathresult + % \pgfplotscoordmath{#5}{op}{acos}{{\pgfplots@quot}}% % \pgfplotscoordmath{#5}{if is}{\pgfplots@y}{-}{% \let\pgfplots@acos=\pgfmathresult - \pgfplotscoordmath{#5}{parsenumber}{-1}% + \pgfplotscoordmath{#5}{-one}% \pgfplotscoordmath{#5}{op}{multiply}{{\pgfmathresult}{\pgfplots@acos}}% }{}% }% @@ -1976,7 +1986,7 @@ \catcode`\%=12 \gdef\pgfplotsPERCENT{%}} \pgfutil@IfUndefined{directlua}{}{% - \directlua{require(\pgfplotsDQ pgfplots.lua\pgfplotsDQ)}% + \directlua{require(\pgfplotsDQ pgfplots\pgfplotsDQ)}% }% % swaps the content of two macros |