summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/pgfplots/util/pgfplotscolormap.code.tex
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/generic/pgfplots/util/pgfplotscolormap.code.tex')
-rw-r--r--Master/texmf-dist/tex/generic/pgfplots/util/pgfplotscolormap.code.tex1803
1 files changed, 1519 insertions, 284 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
index fe79bad2665..992687268c3 100644
--- a/Master/texmf-dist/tex/generic/pgfplots/util/pgfplotscolormap.code.tex
+++ b/Master/texmf-dist/tex/generic/pgfplots/util/pgfplotscolormap.code.tex
@@ -29,6 +29,10 @@
\pgfkeyssetvalue{/pgfplots/colormap default colorspace}{auto}
+% preset for '/pgfplots/colormap uniform=always
+% This is only used for the colormap predefined in this very file.
+\def\pgfplots@colormap@uniform@choice{0}%
+
% This package relies on pgfplots temporary registers and its array
% data structure.
@@ -53,17 +57,45 @@
% \pgfplotscreatecolormap{my map}{color=(green); color=(red); color=(blue); color=(yellow)}
\def\pgfplotscreatecolormap#{\pgfplots@createcolormap}%
\def\pgfplots@createcolormap#1#2{%
+ \pgfkeysinterruptkeyfilter
\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.
- \def\pgfplots@createcolormap@MAX{0}% To be computed.
+ \pgfplotsapplistXnewempty\pgfplots@createcolormap@X
+ %
+ % '0' = is not uniform
+ % '1' = is uniform
+ % '2' = is FORCED to be uniform, i.e. will be reinterpolated
+ \ifcase\pgfplots@colormap@uniform@choice\relax
+ % colormap uniform=always (due to compatibility requirements)
+ \def\b@pgfplotscreatecolormap@isuniform{2}%
+ \or
+ % colormap uniform=if requested
+ \def\b@pgfplotscreatecolormap@isuniform{1}%
+ \fi
+ \def\pgfplots@createcolormap@MIN{}% To be computed.
+ \def\pgfplots@createcolormap@MAX{}% To be computed.
+ \def\b@pgfplots@createcolormap@pos@mode{a}% [a]uto or [m]anual
\pgfplots@createcolormap@initcolorspace
\let\pgfplots@createcolormap@LAST=\pgfplots@createcolormap@MIN
% PARSE IT:
- \edef\pgfplots@loc@TMPa{#2}%
\let\pgfplots@createcolormap@context=\pgfutil@empty
+ %%%%%%%%%%%%%%%%%%
% this does also init @H:
+ \pgflibraryfpuifactive{%
+ \def\pgfplots@createcolormap@restore@fpu{}%
+ }{%
+ \def\pgfplots@createcolormap@restore@fpu{\pgfkeys{/pgf/fpu=false}}%
+ \pgfkeys{/pgf/fpu=true}%
+ }%
+ %\edef\pgfplots@loc@TMPa{#2}% XXX this fails for active chars and
+ %if key/value options are too special
+ \def\pgfplots@loc@TMPa{#2}%
\expandafter\pgfplots@createcolormap@startloop\pgfplots@loc@TMPa\pgfplots@EOI
+ %
+ \pgfplots@createcolormap@restore@fpu
+ %
+ %%%%%%%%%%%%%%%%%%
+ %
\expandafter\pgfplotsarraycheckempty\expandafter{\pgfplots@createcolormap@name}%
% sanity checking:
\expandafter\pgfplotsarraysizetomacro\expandafter{\pgfplots@createcolormap@name}\to\pgfplots@loc@TMPa
@@ -72,15 +104,52 @@
\or
\pgfplots@error{Sorry, you need to provide at least two points of a colormap.}%
\fi
- % Map the input range [0pt,MAX] linearly to [0,1000]
- \pgfmathdivide@{\pgfplotscolormaprange}{\pgfplots@createcolormap@MAX}%
+ % Map the input range [MIN,MAX] linearly to [0,1000]
+ \pgfmathfloatsubtract@{\pgfplots@createcolormap@MAX}{\pgfplots@createcolormap@MIN}%
\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}%
+ \pgfmathfloatdivide@{\pgfplotscolormaprange@float}{\pgfplots@loc@TMPb}%
+ \let\pgfplots@loc@TMPb=\pgfmathresult
+ \pgfmathfloatmultiply@{\pgfplots@loc@TMPb}{\pgfplots@createcolormap@H}%
+ \let\pgfplots@loc@TMPd=\pgfmathresult
+ \pgfplots@createcolormap@normalize{\pgfmathresult}%
+ \expandafter\let\csname\pgfplots@createcolormap@name @h\endcsname=\pgfmathresult
+ %
+ \pgfmathfloatreciprocal@{\pgfplots@loc@TMPd}%
+ \pgfplots@createcolormap@normalize{\pgfmathresult}%
\expandafter\let\csname\pgfplots@createcolormap@name @invh\endcsname=\pgfmathresult
%
+ % ... and set up the X coordinates if the grid is not uniform:
+ \expandafter\pgfplotsarraynewempty\expandafter{\pgfplots@createcolormap@name @X}%
+ \if0\b@pgfplotscreatecolormap@isuniform
+ % Uncomment the '\iftrue' for testing purposes (to see if a uniform map changes if
+ % processed as non-uniform):
+% \iftrue
+ \pgfplotsapplistXlet\pgfplots@loc@TMPc=\pgfplots@createcolormap@X
+ \expandafter\pgfplotsutilforeachcommasep\expandafter{\pgfplots@loc@TMPc}\as\pgfplots@loc@TMPc{%
+ \ifx\pgfplots@loc@TMPc\pgfutil@empty
+ \else
+ % apply the trafo [MIN,MAX] -> [0,1000] here as well:
+ \pgfmathfloatsubtract@{\pgfplots@loc@TMPc}{\pgfplots@createcolormap@MIN}%
+ \expandafter\pgfmathfloatmultiply@\expandafter{\pgfmathresult}{\pgfplots@loc@TMPb}%
+ \pgfplots@createcolormap@normalize{\pgfmathresult}%
+ \expandafter\pgfplotsarraypushback\expandafter{\pgfmathresult}\to{pgfpl@cm@#1@X}%
+ \fi
+ }%
+ %
+ \pgfplotscolormapsetadditionalintervalwidth@{#1}%
+ \else
+ \expandafter\let\csname\pgfplots@createcolormap@name @X@scale@order@z\endcsname=\pgfutil@empty
+ \fi
+ % clear temporary list:
+ \pgfplotsapplistXnewempty\pgfplots@createcolormap@X
+ %
+ \if m\b@pgfplots@createcolormap@pos@mode
+ % Ah - we have manually provided positions!
+ % DISABLE the extra interval. You have to enable it explicitly
+ % by means of 'colormap access/extra interval width=0.1'
+ \expandafter\def\csname\pgfplots@createcolormap@name @X@scale@order@z\endcsname{0}%
+ \fi
+ %
\endpgfplotscolornormalizesequence%
\expandafter\let\csname\pgfplots@createcolormap@name @colspace\endcsname=\pgfplotsretval
\expandafter\let\csname\pgfplots@createcolormap@name @col@comps\endcsname=\pgfplotsretvalb
@@ -89,19 +158,89 @@
\expandafter\edef\csname\pgfplots@createcolormap@name @lastindex\endcsname{\the\c@pgf@counta}%
%\pgfplots@colormap@showdebuginfofor{#1}%
\pgfplots@colormap@LUA@new{#1}%
+ \endpgfkeysinterruptkeyfilter
}
+\def\pgfplots@createcolormap@normalize#1{%
+ \pgfmathfloattofixed{#1}%
+ \pgf@xa=\pgfmathresult pt %
+ \edef\pgfmathresult{\pgf@sys@tonumber\pgf@xa}% normalize number.
+}%
+
+% Allows to customize the width of the additional interval used for
+% 'colormap access=piecewise constant'.
+%
+% #1 colormap name
+% #2 the additional interval width for this colormap. Use '0' to disable the additional
+% interval. The value is relative to the total width and must be in
+% the range 0<=#2<=0.9
+\def\pgfplotscolormapsetadditionalintervalwidth#1#2{%
+ \edef\pgfplots@loc@TMPd{#2}%
+ \def\pgfplots@loc@TMPc{h}%
+ \ifx\pgfplots@loc@TMPd\pgfplots@loc@TMPc
+ % 'h' means: mesh width:
+ \pgfplotscolormapifisuniform{#1}{%
+ \expandafter\let\csname pgfpl@cm@#1@X@scale@order@z\endcsname\pgfutil@empty%
+ }{%
+ \pgfplotscolormapsetadditionalintervalwidth@{#1}%
+ }%
+ \else
+ \pgfmathparse{#2}%
+ \pgfplotscolormapifisuniform{#1}{%
+ \ifdim\pgfmathresult pt>0pt
+ \pgfplots@error{Uniform colormaps support no configuration of the additional interval width for a colormap (although you can use 0 to turn it off). Please use a non-uniform colormap.}%
+ \else
+ % DISABLE the extra interval!
+ \expandafter\def\csname pgfpl@cm@#1@X@scale@order@z\endcsname{0}%
+ \fi
+ }{%
+ \ifdim\pgfmathresult pt>0pt
+ \ifdim\pgfmathresult pt>0.9pt
+ \pgfplots@error{Expected a number 0< X <= 0.9, not \pgfmathresult}%
+ \else
+ % compute the 'h'.
+ %
+ % Note that 's:=#2' is a fraction 0<x<1 of the RESULTING
+ % range, i.e. s * 1000 = H where 0<=H<=1000.
+ % but H = 1000/(1000+h) * 1000, and we need the 'h'.
+ %
+ % -> h = 1000/s - 1000.
+ % regarding the '1-#2': I did some mistake in my
+ % computation and that fixed it :-/
+ \pgfmathparse{1000/(1-#2)-1000}%
+ \expandafter\let\csname pgfpl@cm@#1@h\endcsname=\pgfmathresult
+ \expandafter\let\csname pgfpl@cm@#1@invh\endcsname=\pgfutil@empty% unused!
+ \pgfplotscolormapsetadditionalintervalwidth@{#1}%
+ \fi
+ \else
+ % DISABLE the extra interval!
+ \expandafter\def\csname pgfpl@cm@#1@X@scale@order@z\endcsname{0}%
+ \fi
+ }%
+ \fi
+}%
+
+% see \pgfplotscolormapsetadditionalintervalwidth
+\def\pgfplotscolormapsetadditionalintervalwidth@#1{%
+ % 'colormap access=piecewise constant' (order 0) requires a
+ % special scaling factor. See its consumers for details +
+ % documentation
+ \pgfmathparse{1000/(1000+\csname pgfpl@cm@#1@h\endcsname)}%
+ \expandafter\let\csname pgfpl@cm@#1@X@scale@order@z\endcsname=\pgfmathresult
+}%
\def\pgfplots@createcolormap@initcolorspace{%
\pgfplotscolornormalizesequence[
colorspace=\pgfkeysvalueof{/pgfplots/colormap default colorspace},
- context message=\pgfplots@createcolormap@context,
+ context message=\pgfplots@createcolormap@context\pgfplots@createcolormap@trace,
]%
}%
\def\pgfplots@createcolormap@seth[#1]{%
\def\pgfplots@createcolormap@context{[#1]}%
\pgfmathparse{#1}%
\let\pgfplots@createcolormap@H=\pgfmathresult
+ % request for a uniform colormap:
+ \def\b@pgfplotscreatecolormap@isuniform{3}%
\pgfplots@createcolormap@
}%
@@ -118,175 +257,770 @@
{%
\pgfutil@ifnextchar;{\pgfplots@createcolormap@grabsemicolon}%
{%
- \expandafter\pgfutil@ifnextchar\pgfplots@activesemicolon{\pgfplots@createcolormap@grabsemicolon@active}%
- {%
- \pgfplots@createcolormap@grabnext
+ \pgfutil@ifnextchar,{\pgfplots@createcolormap@grabcomma}%
+ {
+ \expandafter\pgfutil@ifnextchar\pgfplots@activesemicolon{\pgfplots@createcolormap@grabsemicolon@active}%
+ {%
+ \pgfplots@createcolormap@grabnext
+ }%
}%
}%
}%
}
+
+% Executes '#1' if there are more tokens and '#2' if not.
+\def\pgfplots@createcolormap@ifhasmorecolors#1#2{%
+ \pgfutil@ifnextchar\pgfplots@EOI{%
+ #2% no more tokens.
+ }{%
+ \pgfutil@ifnextchar;{\pgfplots@createcolormap@grabsemicolon@hasnext{#1}{#2}}%
+ {%
+ \pgfutil@ifnextchar,{\pgfplots@createcolormap@grabcomma@hasnext{#1}{#2}}%
+ {
+ \expandafter\pgfutil@ifnextchar\pgfplots@activesemicolon{\pgfplots@createcolormap@grabsemicolon@active@hasnext{#1}{#2}}%
+ {%
+ #1% has more.
+ }%
+ }%
+ }%
+ }%
+}%
+
\def\pgfplots@createcolormap@error#1#2\pgfplots@EOI{%
{%
\t@pgfplots@toka={#1#2}%
\t@pgfplots@tokb={#1}%
- \pgfplots@error{Illformed colormap specification: I could not read the substring `\the\t@pgfplots@toka' starting at `\the\t@pgfplots@tokb'}%
+ \pgfplots@error{Illformed colormap specification: I could not read the substring `\the\t@pgfplots@toka' starting at `\the\t@pgfplots@tokb'\pgfplots@createcolormap@trace}%
}%
}%
-\def\pgfplots@createcolormap@grabnext#1({%
- \pgfplots@createcolormap@grabnext@{#1}%
+\def\pgfplots@createcolormap@trace{%
+ \space(color no \expandafter\pgfplotsarraysizeof\expandafter{\pgfplots@createcolormap@name})
+}
+
+\def\pgfplots@createcolormap@grabnext#1={%
+ \pgfutil@ifnextchar({\pgfplots@createcolormap@grabnext@round{#1}=}{%
+ \pgfutil@ifnextchar\bgroup{\pgfplots@createcolormap@grabnext@curly{#1}=}{%
+ \pgfplots@createcolormap@error#1=%
+ }%
+ }%
}
-\def\pgfplots@createcolormap@grabnext@#1#2){%
- \pgfutil@in@={#1}%
+\def\pgfplots@createcolormap@grabnext@round#1=(#2){%
+ \pgfplots@createcolormap@grabnext@@{#1}={#2}%
+}%
+\def\pgfplots@createcolormap@grabnext@curly#1=#2{%
+ \pgfplots@createcolormap@grabnext@@{#1}={#2}%
+}%
+\def\pgfplots@createcolormap@grabnext@@#1=#2{%
+ \pgfutil@in@({#1}%
\ifpgfutil@in@
+ % Ah. We have something like 'color(1cm)' before the equal sign.
+ \pgfplots@createcolormap@grabnext@read@pos#1\pgfplots@EOI%
+ % now:
+ %\pgfplots@loc@TMPa = colorspace
+ %\pgfplots@loc@TMPb = position
+ %
+ \else
% 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
+ \pgfkeys@spdef\pgfplots@loc@TMPa{#1}%
%
\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)%
- }%
- }%
+ \let\pgfplots@loc@TMPb=\pgfmathresult% position
\fi
- \pgfplots@loc@TMPd
+ \def\pgfplots@loc@TMPc{#2}%
+ \pgfplots@createcolormap@grabnext@complete
}%
-\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@grabnext@read@pos#1({%
+ \pgfkeys@spdef\pgfplots@loc@TMPa{#1}% colorspace
+ \pgfplots@createcolormap@grabnext@read@pos@
}%
-
-\def\pgfplots@createcolormap@grabnext@@={%
- \pgfutil@ifnextchar({%
- \pgfplots@createcolormap@grabnext@@@
+\def\pgfplots@createcolormap@grabnext@read@pos@#1){%
+ \def\pgfplots@loc@TMPb{#1}% position
+ \def\b@pgfplots@createcolormap@pos@mode{m}% [m]anual
+ \pgfutil@ifnextchar\pgfplots@EOI{%
+ % OK
+ \pgfplots@gobble@until@EOI
}{%
- \pgfplots@createcolormap@error=%
+ \pgfplots@createcolormap@error#1)%
}%
}%
-\def\pgfplots@createcolormap@grabnext@@@(#1){%
- \def\pgfplots@loc@TMPc{#1}%
- \pgfplots@createcolormap@grabnext@complete
-}%
%%%%%%%%%%
-% defines \pgfplotsretval to contain the argument and \pgfplotsretvalb
-% to contain the colormap name.
-\def\pgfplots@createcolormap@special@split#1{%
+% Splits '<argument> of <source name>*' into (\pgfplotsretval,
+% \pgfplotsretvalb).
+%
+% The 'of' part is optional. If it is missing, '\pgfplotsretval'
+% contains the entire argument and '\pgfplotsretvalb' is the current
+% colormap.
+%
+% Note that '<source name>*' is typically just a colormap name (i.e. without
+% '*'), but it _may_ contain key-value lists! They will be returned as-is.
+% #1: the string to split
+% #2: '1' if '#1' may contain ',' and '0' otherwise
+\def\pgfplots@createcolormap@special@split#1#2{%
\pgfutil@in@{of }{#1}%
\ifpgfutil@in@
\pgfplots@createcolormap@special@split@#1\pgfplots@EOI
\else
- \pgfkeys@spdef\pgfplotsretval{#1}%
- \pgfkeysgetvalue{/pgfplots/colormap name}\pgfplotsretvalb
+ \if1#2\relax
+ % do not check it -- commas are allowed here!
+ \pgfutil@in@false
+ \else
+ \pgfutil@in@{,}{#1}%
+ \fi
+ \ifpgfutil@in@
+ % ah - might be something like '5, target pos={1,2,3}'.
+ % -> define \pgfplotsretval='5' and
+ % \pgfplotsretvalb='<colormap name>, target pos={1,2,3}':
+ %
+ \pgfplots@createcolormap@special@split@command#1\pgfplots@EOI
+ \t@pgfplots@tokb=\expandafter{\pgfplotsretvalb}%
+ \pgfkeysgetvalue{/pgfplots/colormap name}\pgfplotsretvalb
+ \edef\pgfplotsretvalb{\pgfplotsretvalb,\the\t@pgfplots@tokb}%
+ \else
+ \pgfkeys@spdef\pgfplotsretval{#1}%
+ \pgfkeysgetvalue{/pgfplots/colormap name}\pgfplotsretvalb
+ \fi
\fi
- \pgfplots@createcolormap@special@ensure@source@cm{\pgfplotsretvalb}%
+%\message{Split (#1) --> '\pgfplotsretval', '\pgfplotsretvalb'^^J}%
}%
\def\pgfplots@createcolormap@special@split@#1of #2\pgfplots@EOI{%
\pgfkeys@spdef\pgfplotsretval{#1}%
\pgfkeys@spdef\pgfplotsretvalb{#2}%
}
+\def\pgfplots@createcolormap@special@split@command#1,#2\pgfplots@EOI{%
+ \pgfkeys@spdef\pgfplotsretval{#1}%
+ \pgfkeys@spdef\pgfplotsretvalb{#2}%
+}
+
+% Output: \pgfplotsretval will be populated with the resulting
+% colormap name.
\def\pgfplots@createcolormap@special@ensure@source@cm#1{%
- \pgfplotscolormapifdefined{#1}{%
- }{%
- \pgfplots@error{The argument '#1' is no valid colormap.}%
+ \edef\pgfplotsretval{#1}%
+ \pgfplotscolormapifdefined{#1}{}{%
+ % hm... the colormap does not exist? Perhaps someone used
+ % style 'colormap/cool'. Try to define it!
+ \pgfkeysifdefined{/pgfplots/#1/.@cmd}{%
+ \pgfkeysgetvalue{/pgfplots/colormap name}\pgfplots@color@of@colormap@name@old
+ \pgfplotsset{#1}%
+ \pgfkeysgetvalue{/pgfplots/colormap name}\pgfplotsretval
+ \pgfkeyslet{/pgfplots/colormap name}\pgfplots@color@of@colormap@name@old
+ }{%
+ \pgfplots@error{The argument '#1' is no valid colormap.}%
+ }%
}%
}%
-% defines \pgfplotsretval to contain an expanded color definition
-% series
-% #1: position
-% #2: argument(s)
-\expandafter\def\csname pgfplots@createcolormap@grabnextspecial@colors of colormap\endcsname#1#2{%
- \pgfplots@createcolormap@special@split{#2}%
- \pgfplots@createcolormap@special@process{#1}{color of colormap}%
-%\message{colors of colormap(#1)=(#2): resulted in \meaning\pgfplotsretval^^J}%
+\newif\ifpgfplots@createcolormap@target@pos@includes@limits@min
+\newif\ifpgfplots@createcolormap@target@pos@includes@limits@max
+
+% these keys are only evaluated inside of
+% \pgfplots@of@colormap@getresult :
+\pgfqkeys{/pgfplots/of colormap}{%
+ source name/.initial=,
+ target pos/.initial=,
+ target pos min/.initial=,
+ target pos min/insert/.is if=pgfplots@createcolormap@target@pos@includes@limits@min,
+ target pos min*/.style={%
+ /pgfplots/of colormap/target pos min={#1},
+ /pgfplots/of colormap/target pos min/insert=true,
+ },%
+ target pos max/.initial=,
+ target pos max*/.style={%
+ /pgfplots/of colormap/target pos max={#1},
+ /pgfplots/of colormap/target pos max/insert=true,
+ },%
+ target pos max/insert/.is if=pgfplots@createcolormap@target@pos@includes@limits@max,
+ source pos/.initial=,
+ source pos/.set if not empty/.code={%
+ \edef\pgfplots@loc@TMPa{#1}%
+ \ifx\pgfplots@loc@TMPa\pgfutil@empty
+ \else
+ \pgfkeyslet{/pgfplots/of colormap/source pos}\pgfplots@loc@TMPa
+ \fi
+ },
+ %
+ @define/.code={%
+ \pgfplots@error{Please write 'single color' or 'color list' such that pgfplots knows how to interprete values}
+ \let\pgfplotsretval=\pgfutil@empty
+ },
+ single color/.style={%
+ /pgfplots/of colormap/@define/.code={%
+ \pgfplots@createcolormap@special@process@single
+ },
+ },
+ color list/.style={%
+ /pgfplots/of colormap/@define/.code={%
+ \pgfplots@createcolormap@special@process@list%
+ },
+ },
+ color list,
+ %
+ of colormap/.style={#1},
+ %
+ % 'color of colormap={#1}' is a style which boils down to
+ % '@delegate to@ of colormap={color}{#1}'.
+ % The same is true for
+ % colors of colormap
+ % index of colormap
+ % indices of colormap
+ % samples of colormap
+ %
+ % All use this implementation:
+ % #1: how to interprete results. /pgfplots/of colormap/#1 must be
+ % a valid key (like 'color').
+ % #2: the argument which can be '<source pos> of <source name>' or '<source pos>'.
+ % #3: '1' if the source pos may contain ',' and '0' otherwise
+ @delegate to@ of colormap/.code args={#1#2#3}{%
+ % Convert 'color of colormap={...}' and its variants into
+ % 'of colormap={<list of keys>}':
+ \pgfplots@createcolormap@special@split{#2}{#3}%
+ \edef\pgfplots@loc@TMPa{%
+ #1,%
+ source pos={\pgfplotsretval},%
+ % \pgfplotsretvalb will contain the colormap name
+ % --- but it _can_ also contain further key-value pairs!
+ % Do not add braces here such that further key-value pairs
+ % can be found:
+ source name=\pgfplotsretvalb,%
+ }%
+ \expandafter\pgfkeysalso\expandafter{\pgfplots@loc@TMPa}%
+ },
+ %
+ color/.style={%
+ /pgfplots/of colormap/colormap access=map,
+ /pgfplots/of colormap/single color,
+ /pgfplots/of colormap/source pos/.set if not empty={#1},
+ },
+ const color/.style={%
+ /pgfplots/of colormap/colormap access=piecewise constant,
+ /pgfplots/of colormap/single color,
+ /pgfplots/of colormap/source pos/.set if not empty={#1},
+ },
+ index/.style={%
+ /pgfplots/of colormap/colormap access=direct,
+ /pgfplots/of colormap/single color,
+ /pgfplots/of colormap/source pos/.set if not empty={#1},
+ },
+ colors/.style={%
+ /pgfplots/of colormap/colormap access=map,
+ /pgfplots/of colormap/color list,
+ /pgfplots/of colormap/source pos/.set if not empty={#1},
+ },
+ samples/.style={%
+ /pgfplots/of colormap/colormap access=map,% can be overridden if needed.
+ /pgfplots/of colormap/@define/.code={%
+ \pgfplots@createcolormap@special@process@list@sampled%
+ },
+ /pgfplots/of colormap/source pos/.set if not empty={#1},
+ },%
+ %
+ const colors/.style={%
+ /pgfplots/of colormap/colormap access=piecewise constant,
+ /pgfplots/of colormap/color list,
+ /pgfplots/of colormap/source pos/.set if not empty={#1},
+ },
+ indices/.style={%
+ /pgfplots/of colormap/colormap access=direct,
+ /pgfplots/of colormap/color list,
+ /pgfplots/of colormap/source pos/.set if not empty={#1},
+ },
+ colormap access/.style={/pgfplots/colormap access={#1}},
+ source range/.initial=0:1000,
+ %
+ sample for/.is choice,
+ sample for/default/.code={\def\pgfplots@ofcolorbar@sample@for@choice{m}},
+ sample for/const/.code={\def\pgfplots@ofcolorbar@sample@for@choice{c}},
+ sample for=default,
+ %
+ /pgfplots/of colormap/.unknown/.code={%
+ \pgfplotsutilifstringequal{#1}{\pgfkeysnovalue}{%
+ % This here allows to write 'of colormap={initial}'
+ \pgfplotscolormapifdefined{\pgfkeyscurrentname}{%
+ \edef\pgfplots@loc@TMPa{%
+ \noexpand\pgfkeysalso{%
+ /pgfplots/of colormap/source name={\pgfkeyscurrentname},
+ }%
+ }%
+ \pgfplots@loc@TMPa
+ }{%
+ \pgfplots@error{Unknown key '\pgfkeyscurrentname'. Is this a colormap name? Maybe you need to write \string\pgfplotsset{\pgfkeyscurrentname} first?}%
+ }%
+ }{%
+ \pgfkeysgetvalue{/handlers/.unknown/.@cmd}{\pgfkeys@code}%
+ \expandafter\pgfkeys@code\pgfkeyscurrentvalue\pgfeov%
+ }%
+ },
+ %
+ % allow something like 'of colormap={colormap/PuBuGn}':
+ /pgfplots/of colormap/colormap/.unknown/.code={%
+ \edef\pgfplots@loc@TMPa{\noexpand\pgfplotsset{colormap/\pgfkeyscurrentname}}%
+ \pgfplots@loc@TMPa
+ },%
}
-\expandafter\def\csname pgfplots@createcolormap@grabnextspecial@samples of colormap\endcsname#1#2{%
- \pgfplots@createcolormap@special@split{#2}%
+\pgfplotsinvokeforeach{%
+ color,% defines 'color of colormap'
+ index,% defines 'index of colormap'
+ const color,% defines 'const color of colormap'
+ samples,% defines 'samples of colormap'
+}{%
+ \def\pgfplots@glob@TMPa{#1}%
+ \ifx\pgfplots@glob@TMPa\pgfutil@empty
+ \else
+ \pgfkeysdef{/pgfplots/of colormap/#1 of colormap}{%
+ \pgfkeysalso{/pgfplots/of colormap/@delegate to@ of colormap={#1}{##1}{0}}%
+ }%
+ \fi
+}%
+\pgfplotsinvokeforeach{%
+ indices,% defines 'indices of colormap'
+ colors,% defines 'colors of colormap'
+ const colors,% defines 'const colors of colormap'
+}{%
+ \def\pgfplots@glob@TMPa{#1}%
+ \ifx\pgfplots@glob@TMPa\pgfutil@empty
+ \else
+ \pgfkeysdef{/pgfplots/of colormap/#1 of colormap}{%
+ \pgfkeysalso{/pgfplots/of colormap/@delegate to@ of colormap={#1}{##1}{1}}%
+ }%
+ \fi
+}%
+
+% This is the main implementation of 'of colormap'. It is shared by
+% both cycle lists and colormaps.
+%
+\def\pgfplots@of@colormap@getresult#1{%
+ \pgfkeysinterruptkeyfilter
+ \pgfqkeys{/pgfplots/of colormap}{%
+ % ensure that this here is not inherited from the axis'
+ % configuration -- reset it:
+ colormap access=map,%
+ #1}%
+ \pgfkeysgetvalue{/pgfplots/of colormap/source name}\pgfplots@loc@TMPa
+ \edef\pgfplots@loc@TMPa{\pgfplots@loc@TMPa}%
+ \ifx\pgfplots@loc@TMPa\pgfutil@empty
+ \else
+ \pgfkeyslet{/pgfplots/colormap name}\pgfplots@loc@TMPa
+ \fi
+ \pgfplots@createcolormap@special@ensure@source@cm{\pgfkeysvalueof{/pgfplots/colormap name}}%
+ \pgfkeyslet{/pgfplots/colormap name}\pgfplotsretval
+ %
+ \pgfqkeys{/pgfplots/of colormap}{@define}%
+ \endpgfkeysinterruptkeyfilter
+}%
+
+
+\def\pgfplots@createcolormap@special@process@single@error{%
+ \pgfplots@error{Did not find a suitable input source pos in a 'of colormap' specification. Did you forget the 'source pos'? It can be given as 'colors of colormap=(source pos of name)' or 'of colormap=(source pos=...,..)'}%
+ \pgfkeyssetvalue{/pgfplots/of colormap/source pos}{0}%
+}%
+\def\pgfplots@createcolormap@special@process@single@error@comma{%
+ \pgfplots@error{Found an unexpected comma in 'source pos=\pgfkeysvalueof{/pgfplots/of colormap/source pos}'. Please use one of the styles 'colors', 'indices', or 'const colors' in order to process more than one position}%
+ \pgfkeyssetvalue{/pgfplots/of colormap/source pos}{0}%
+}%
+\def\pgfplots@createcolormap@special@process@single{%
\begingroup
- \let\pgfplots@source=\pgfplotsretval
- \let\pgfplots@sourcecm=\pgfplotsretvalb
- \pgfplots@domain@to@foreach 0:1000\relax{\pgfplots@source}%
- \t@pgfplots@toka=\expandafter{\pgfplotsretval}%
- \edef\pgfplotsretval{colors of colormap(#1)=({\the\t@pgfplots@toka} of \pgfplots@sourcecm)}%
+ \let\pgfplots@color@of@colormap@access=\pgfplots@colormap@access
+ \pgfkeysgetvalue{/pgfplots/of colormap/source range}\pgfplotspointmetatransformedrange
+ \ifx\pgfplotspointmetatransformedrange\pgfutil@empty
+ % evaluated by \pgfplots@color@of@colormap@define...
+ \let\pgfplotspointmetatransformedrange=\pgfplotscolormaprange
+ \fi
+ %
+ \pgfkeysgetvalue{/pgfplots/of colormap/source pos}\pgfplots@loc@TMPa
+ \edef\pgfplots@loc@TMPa{\pgfplots@loc@TMPa}%
+ \ifx\pgfplots@loc@TMPa\pgfutil@empty
+ \pgfplots@createcolormap@special@process@single@error
+ \else
+ \edef\pgfplots@loc@TMPa{%
+ \noexpand\pgfutil@in@{,}{\pgfplots@loc@TMPa}%
+ }%
+ \pgfplots@loc@TMPa
+ \ifpgfutil@in@
+ \pgfplots@createcolormap@special@process@single@error@comma
+ \else
+ \pgfmathparse{\pgfkeysvalueof{/pgfplots/of colormap/source pos}}%
+ \pgfkeyslet{/pgfplots/of colormap/source pos}\pgfmathresult
+ \fi
+ \fi
+ %
+ \pgflibraryfpuifactive{\pgfkeys{/pgf/fpu=false}}{}%
+ %
+ \edef\pgfplots@loc@TMPa{%
+ \noexpand\pgfplots@color@of@colormap@define{\pgfkeysvalueof{/pgfplots/of colormap/source pos}}%
+ }%
+ \pgfplots@loc@TMPa
+ %
+ \pgfplots@createcolormap@special@process@single@define
\pgfmath@smuggleone\pgfplotsretval
\endgroup
-%\message{samples of colormap(#1)=(#2): resulted in \meaning\pgfplotsretval^^J}%
-}
-\expandafter\def\csname pgfplots@createcolormap@grabnextspecial@indices of colormap\endcsname#1#2{%
- \pgfplots@createcolormap@special@split{#2}%
- \pgfplots@createcolormap@special@process{#1}{index of colormap}%
-%\message{indices of colormap(#1)=(#2): resulted in \meaning\pgfplotsretval^^J}%
-}
-\expandafter\def\csname pgfplots@createcolormap@grabnextspecial@color of colormap\endcsname#1#2{%
- \begingroup
- % colormap access=map
- \def\pgfplots@color@of@colormap@access{m}%
- \pgfplots@color@of@colormap@define{#2}%
+}%
+
+\def\pgfplots@createcolormap@special@process@single@define{%
+ \pgfkeysgetvalue{/pgfplots/of colormap/target pos}\pgfplots@temp@pos
+ \ifx\pgfplots@temp@pos\pgfutil@empty
+ \else
+ \edef\pgfplots@temp@pos{(\pgfplots@temp@pos)}%
+ \fi
+ %
\edef\pgfplotsretval{%
- \csname pgfpl@cm@\pgfplots@color@of@colormap@name @colspace\endcsname(#1)=(\pgfmathresult)%
+ \csname pgfpl@cm@\pgfkeysvalueof{/pgfplots/colormap name}@colspace\endcsname\pgfplots@temp@pos=(\pgfmathresult)%
}%
- \pgfmath@smuggleone\pgfplotsretval
- \endgroup
+}%
+\let\pgfplots@createcolormap@special@process@single@define@CM=\pgfplots@createcolormap@special@process@single@define%
+
+\def\pgfplots@createcolormap@special@process@list@sanitize@selection{%
+ \pgfkeysgetvalue{/pgfplots/of colormap/source pos}\pgfplots@loc@TMPa
+ \edef\pgfplots@loc@TMPa{\pgfplots@loc@TMPa}%
+ \ifx\pgfplots@loc@TMPa\pgfutil@empty
+ % default to a suitable source pos.
+ \ifnum\pgfplots@pos@size<2
+ % We have either 0 positions or 1 position.
+ % This is clearly insufficient and we assume that this
+ % position argument merely gives the start point for the
+ % list.
+ %
+ % Select all of the input colormap:
+ \edef\pgfplots@loc@TMPa{%
+ \noexpand\pgfkeysalso{%
+ /pgfplots/of colormap/source pos={0,...,\pgfplotscolormaplastindexof{\pgfkeysvalueof{/pgfplots/colormap name}}},%
+ /pgfplots/of colormap/indices,
+ }%
+ }%
+ \pgfplots@loc@TMPa
+ \else
+ % hm... we have no source pos, but we have positions! In
+ % this case, we _sample_ source pos uniformly with one
+ % sample for each position!
+ \pgfkeyslet{/pgfplots/of colormap/source pos}\pgfplots@pos@size
+ \pgfplots@createcolormap@special@process@list@sampled@define{P}%
+ \fi
+ \fi
}
-\expandafter\def\csname pgfplots@createcolormap@grabnextspecial@index of colormap\endcsname#1#2{%
+\def\pgfplots@createcolormap@special@process@list@limits{%
\begingroup
- % colormap access=direct
- \def\pgfplots@color@of@colormap@access{d}%
- \pgfplots@color@of@colormap@define{#2}%
- \edef\pgfplotsretval{%
- \csname pgfpl@cm@\pgfplots@color@of@colormap@name @colspace\endcsname(#1)=(\pgfmathresult)%
- }%
- \pgfmath@smuggleone\pgfplotsretval
+ %
+ \pgfkeysgetvalue{/pgfplots/of colormap/target pos}\pgfplots@target
+ \ifx\pgfplots@target\pgfutil@empty
+ \else
+ \pgfkeys{/pgf/fpu=true}%
+ \pgfkeysgetvalue{/pgfplots/of colormap/target pos min}\pgfplots@target@min
+ \pgfkeysgetvalue{/pgfplots/of colormap/target pos max}\pgfplots@target@max
+ \pgfplots@loc@tmpfalse
+ \ifx\pgfplots@target@min\pgfutil@empty
+ \else
+ \pgfmathparse\pgfplots@target@min
+ \let\pgfplots@target@min=\pgfmathresult
+ \pgfplots@loc@tmptrue
+ \fi
+ \ifx\pgfplots@target@max\pgfutil@empty
+ \else
+ \pgfmathparse\pgfplots@target@max
+ \let\pgfplots@target@max=\pgfmathresult
+ \pgfplots@loc@tmptrue
+ \fi
+ \ifpgfplots@loc@tmp
+ % Ah - we _have_ limit constraints! Enforce them:
+ \def\b@pgfplots@isfirst{1}%
+ \pgfmathfloatcreate{1}{1.0}{324}%
+ \let\pgfplots@firstpos\pgfmathresult%
+ \let\pgfplots@lastpos\pgfmathresult%
+ \pgfplotsapplistXnewempty\pgfplots@createcolormap@trg@accum
+ \def\pgfplots@loc@TMPa{\pgfplotsforeachungrouped \x in}%
+ \expandafter\pgfplots@loc@TMPa\expandafter{\pgfplots@target}{%
+ \ifx\x\pgfutil@empty
+ \else
+ \pgfmathparse{\x}%
+ \let\x=\pgfmathresult
+ \ifx\pgfplots@target@min\pgfutil@empty
+ \else
+ \pgfmathfloatlessthan{\x}{\pgfplots@target@min}%
+ \ifpgfmathfloatcomparison
+ \let\x=\pgfutil@empty
+ \fi
+ \fi
+ \ifx\pgfplots@target@max\pgfutil@empty
+ \else
+ \ifx\x\pgfutil@empty
+ \else
+ \pgfmathfloatlessthan{\pgfplots@target@max}{\x}%
+ \ifpgfmathfloatcomparison
+ \let\x=\pgfutil@empty
+ \fi
+ \fi
+ \fi
+ %
+ \ifx\x\pgfutil@empty
+ \else
+ \let\pgfplots@lastpos=\x
+ \if1\b@pgfplots@isfirst
+ \let\pgfplots@firstpos=\x
+ \def\b@pgfplots@isfirst{0}%
+ \else
+ \edef\x{,\x}%
+ \fi
+ \expandafter\pgfplotsapplistXpushback\expandafter{\x}\to\pgfplots@createcolormap@trg@accum
+ \fi
+ \fi
+ }%
+ %
+ \ifpgfplots@createcolormap@target@pos@includes@limits@max
+ \ifx\pgfplots@target@max\pgfutil@empty
+ \else
+ \pgfmathfloatifapproxequalrel{\pgfplots@lastpos}{\pgfplots@target@max}{%
+ }{%
+ \let\x=\pgfplots@target@max
+ \if1\b@pgfplots@isfirst
+ \def\b@pgfplots@isfirst{0}%
+ \else
+ \edef\x{,\x}%
+ \fi
+ \expandafter\pgfplotsapplistXpushback\expandafter{\x}\to\pgfplots@createcolormap@trg@accum
+ }%
+ \fi
+ \fi
+ %
+ \pgfplotsapplistXlet\pgfplots@target=\pgfplots@createcolormap@trg@accum
+ %
+ \ifpgfplots@createcolormap@target@pos@includes@limits@min
+ \ifx\pgfplots@target@min\pgfutil@empty
+ \else
+ \pgfmathfloatifapproxequalrel{\pgfplots@firstpos}{\pgfplots@target@min}{%
+ }{%
+ \let\x=\pgfplots@target@min
+ \if1\b@pgfplots@isfirst
+ \let\pgfplots@target=\x
+ \else
+ \edef\pgfplots@target{\x,\pgfplots@target}%
+ \fi
+ }%
+ \fi
+ \fi
+ \fi
+ \fi
+ %
+ \global\let\pgfplots@glob@TMPb=\pgfplots@target
\endgroup
-}
-\def\pgfplots@createcolormap@special@process#1#2{%
+%\message{limit application: \pgfkeysvalueof{/pgfplots/of colormap/target pos} ^^J -->\pgfplots@glob@TMPb^^J}%
+ \pgfkeyslet{/pgfplots/of colormap/target pos}\pgfplots@glob@TMPb
+}%
+
+\def\pgfplots@createcolormap@special@process@list@define@target@array{%
+ \pgfplots@createcolormap@special@process@list@limits%
+ %
+ \pgfkeysgetvalue{/pgfplots/of colormap/target pos}\pgfplots@loc@TMP
+ \expandafter\pgfplotsarraynew\expandafter\pgfplots@pos@array\expandafter{\pgfplots@loc@TMP}%
+ %
+ \pgfplotsarraysizetomacro\pgfplots@pos@array\to\pgfplots@pos@size
+}%
+
+% PRECONDITION: Must be invoked within \pgfplots@of@colormap@getresult
+\def\pgfplots@createcolormap@special@process@list{%
\begingroup
- \let\pgfplots@source=\pgfplotsretval
- \let\pgfplots@sourcecm=\pgfplotsretvalb
- \def\pgfplots@temp@pos{(#1)}%
+ \pgfkeys{/pgf/fpu=true}%
+ \pgfplots@createcolormap@special@process@list@define@target@array
%
\pgfplotsapplistXnewempty\pgfplots@createcolormap@special@process@result
+ %
+ \gdef\c@pgfplots@elem{0}%
+ %
+ \def\pgfplots@createcolormap@special@process@list@append{%
+ \pgfplots@createcolormap@special@process@single
+ %
+ % append separator
+ \t@pgfplots@toka=\expandafter{\pgfplotsretval}%
+ \t@pgfplots@tokb=\expandafter{\pgfplots@createcolormap@special@process@list@separator}%
+ \edef\pgfplotsretval{\the\t@pgfplots@toka\the\t@pgfplots@tokb}%
+ %
+ \expandafter\pgfplotsapplistXpushback\pgfplotsretval\to\pgfplots@createcolormap@special@process@result
+ }%
+ %
+ \pgfplots@createcolormap@special@process@list@sanitize@selection
+ %
+ \pgfkeysgetvalue{/pgfplots/of colormap/source pos}\pgfplots@source
+ %
\def\pgfplots@loc@TMPa{\pgfplotsforeachungrouped \x in }%
\expandafter\pgfplots@loc@TMPa\expandafter{\pgfplots@source}{%
- \t@pgfplots@tokb=\expandafter{\pgfplots@sourcecm}%
%
- \edef\currentValue{#2\pgfplots@temp@pos=(\x\space of \the\t@pgfplots@tokb) }%
+ \pgfkeyslet{/pgfplots/of colormap/source pos}\x
%
- \expandafter\pgfplotsapplistXpushback\currentValue\to\pgfplots@createcolormap@special@process@result
+ \ifnum\c@pgfplots@elem<\pgfplots@pos@size\relax
+ \pgfplotsarrayselect\c@pgfplots@elem\of\pgfplots@pos@array\to\pgfplots@loc@TMPa
+ \pgfkeyslet{/pgfplots/of colormap/target pos}\pgfplots@loc@TMPa
+ \else
+ % auto-position:
+ \pgfkeyslet{/pgfplots/of colormap/target pos}\pgfutil@empty
+ \fi
+ %
+ \pgfplots@createcolormap@special@process@list@append
%
- % all following ones receive auto-positions:
- \let\pgfplots@temp@pos=\pgfutil@empty
+ \pgfplotsutil@advancestringcounter@global\c@pgfplots@elem
}%
+ %
+ \pgfutil@loop
+ \ifnum\c@pgfplots@elem<\pgfplots@pos@size\relax
+ \pgfplotsarrayselect\c@pgfplots@elem\of\pgfplots@pos@array\to\pgfplots@loc@TMPa
+ \pgfkeysgetvalue{/pgfplots/of colormap/source pos}\x
+ \pgfplotswarning{too many colormap positions}{index \c@pgfplots@elem\space (value \pgfplots@loc@TMPa)}\pgfeov%
+ \pgfplotsutil@advancestringcounter@global\c@pgfplots@elem
+ %
+ \pgfutil@repeat
+ %
\pgfplotsapplistXlet\pgfplotsretval=\pgfplots@createcolormap@special@process@result
\global\let\pgfplots@glob@TMPa=\pgfplotsretval
\endgroup
\let\pgfplotsretval=\pgfplots@glob@TMPa
+%\message{of colormap with list functionality results in \meaning\pgfplotsretval^^J}%
}%
+\def\pgfplots@createcolormap@special@process@list@sampled{%
+ \begingroup
+ \pgfkeys{/pgf/fpu=true}%
+ \pgfplots@createcolormap@special@process@list@define@target@array
+ %
+ % no need to reapply it in \pgfplots@createcolormap@special@process@list:
+ \let\pgfplots@createcolormap@special@process@list@define@target@array=\relax
+ %
+ \pgfplots@createcolormap@special@process@list@sampled@define{S}%
+ \pgfplots@createcolormap@special@process@list
+ \global\let\pgfplots@glob@TMPa=\pgfplotsretval
+ \endgroup
+ \let\pgfplotsretval=\pgfplots@glob@TMPa
+}
+
+% Defines
+% * 'source range',
+% * 'source pos',
+% in a way such that it implements 'samples of colormap'
+% #1: 'S' if it _must_ satisfy the number of samples and 'P' if it
+% _must_ satisfy the positions
+\def\pgfplots@createcolormap@special@process@list@sampled@define#1{%
+ \begingroup
+ \pgfkeysgetvalue{/pgfplots/of colormap/source pos}\pgfplots@source
+ %
+ \def\b@pgfplots@special@interval{0}%
+ \def\b@pgfplots@special@interval@additional{0}%
+ \if c\pgfplots@ofcolorbar@sample@for@choice%
+ % or colormap/sample for=const:
+ % sample one less and replicate the last color. This
+ % is to compensate for 'colormap access/extra interval width=0'
+ % (which is the default for colormaps with positions)
+ \ifnum\pgfplots@pos@size>1
+ % ah - we have at least 2 positions and 'extra interval width=0' applies!
+ \if S#1%
+ \c@pgf@counta=\pgfplots@source\relax
+ \advance\c@pgf@counta by1 %
+ \ifnum\pgfplots@pos@size=\c@pgf@counta
+ \else
+ \pgfplotsthrow{too few colormap positions}{\pgfplots@pos@size}{There is an unexpected number of arguments to 'target pos' for 'samples of colormap=(\pgfplots@source)'. Please provide \the\c@pgf@counta\space positions, not \pgfplots@pos@size}\pgfeov%
+ \fi
+ \fi
+ \if S#1%
+ % this is the case
+ % samples of colormap={5, target pos={<6 positions>}}
+ % -> we need to replicate the last color such that we see the rightmost color of the input map
+ \def\b@pgfplots@special@interval{1}%
+ % -> we also need one more sample point (one for each position):
+ \def\b@pgfplots@special@interval@additional{1}%
+ \else
+ % we have pgfplots@pos@size=pgfplots@source.
+ \if1\b@pgfplots@createcolormap@found@more@colors
+ % there are more positions/colors!? Ok, no need to
+ % apply it here:
+ \def\b@pgfplots@special@interval{0}%
+ \else
+ \def\b@pgfplots@special@interval{1}%
+ \fi
+ \fi
+ \else
+ \def\b@pgfplots@special@interval{0}%
+ \fi
+ \else
+ \def\b@pgfplots@special@interval{0}%
+ \ifnum\pgfplots@pos@size>1
+ % ah - we have at least 2 positions
+ \if S#1%
+ \ifnum\pgfplots@pos@size=\pgfplots@source
+ \else
+ \pgfplotsthrow{too few colormap positions}{\pgfplots@pos@size}{There is an unexpected number of arguments to 'target pos' for 'samples of colormap=(\pgfplots@source)'. Please provide \pgfplots@source\space positions, not \pgfplots@pos@size}\pgfeov%
+ \fi
+ \fi
+ \fi
+ \fi
+ %
+ \if1\b@pgfplots@special@interval@additional
+ \c@pgf@counta=\pgfplots@source\relax
+ \advance\c@pgf@counta by+1
+ \edef\pgfplots@source{\the\c@pgf@counta}%
+ \fi
+ \if1\b@pgfplots@special@interval
+ \begingroup
+ \c@pgf@counta=\pgfplots@source\relax
+ \advance\c@pgf@counta by-1
+ %
+ \pgfplotsapplistXnewempty\pgfplots@createcolormap@trg@accum
+ \ifnum\c@pgf@counta<2
+ \pgfmathfloatcreate{0}{0.0}{0}%
+ \expandafter\pgfplotsapplistXpushback\expandafter{\pgfmathresult,}\to\pgfplots@createcolormap@trg@accum
+ \else
+ \edef\pgfplots@source{\the\c@pgf@counta}%
+ \pgfplots@domain@to@foreach 0:1000\relax{\pgfplots@source}%
+ %
+ \def\pgfplots@loc@TMPa{\pgfplotsforeachungrouped \x in}%
+ \expandafter\pgfplots@loc@TMPa\expandafter{\pgfplotsretval}{%
+ \expandafter\pgfplotsapplistXpushback\expandafter{\x,}\to\pgfplots@createcolormap@trg@accum
+ }%
+ \fi
+ %
+ \pgfmathfloatcreate{1}{1.0}{3}%
+ \expandafter\pgfplotsapplistXpushback\expandafter{\pgfmathresult}\to\pgfplots@createcolormap@trg@accum
+ %
+ \pgfplotsapplistXlet\pgfplots@target=\pgfplots@createcolormap@trg@accum
+ \global\let\pgfplots@glob@TMPa=\pgfplots@target
+ \endgroup
+ %
+ \let\pgfplotsretval=\pgfplots@glob@TMPa
+ \else
+ \pgfplots@domain@to@foreach 0:1000\relax{\pgfplots@source}%
+ \fi
+ \pgfmath@smuggleone\pgfplotsretval
+ \endgroup
+ \pgfkeyslet{/pgfplots/of colormap/source pos}\pgfplotsretval
+ \pgfqkeys{/pgfplots/of colormap}{%
+ source range=0:1000,%
+ }%
+%\message{define sample positions(#1) = \pgfplotsretval^^J}%
+}%
+
+
+\def\pgfplots@createcolormap@special@process@list@separator@CM{ }%
+\let\pgfplots@createcolormap@special@process@list@separator=\pgfplots@createcolormap@special@process@list@separator@CM
%%%%%%%%%%
+\def\b@pgfplots@createcolormap@found@more@colors{0}%
+
\def\pgfplots@createcolormap@grabnext@complete{%
- \pgfutil@IfUndefined{pgfplots@createcolormap@grabnextspecial@\pgfplots@loc@TMPa}{%
+ \edef\pgfplots@loc@TMPd{%
+ \noexpand\pgfutil@in@{of color}{\pgfplots@loc@TMPa}%
+ }%
+ \pgfplots@loc@TMPd
+ \ifpgfutil@in@
+ \def\pgfplots@loc@TMPd{%
+ \pgfplots@createcolormap@ifhasmorecolors{%
+ \def\b@pgfplots@createcolormap@found@more@colors{1}%
+ \pgfplots@createcolormap@grabnext@complete@of@colormap
+ }{%
+ \def\b@pgfplots@createcolormap@found@more@colors{0}%
+ \pgfplots@createcolormap@grabnext@complete@of@colormap
+ }%
+ }%
+ \else
% ok, this is a 'normal' color specification with position,
% colorspace, and color data.
%
@@ -301,53 +1035,89 @@
%
% continue loop:
\def\pgfplots@loc@TMPd{\pgfplots@createcolormap@}%
- }{%
- % ah - a special one based on another colormap!
- % convert it into the standard format:
- %
- \t@pgfplots@tokb=\expandafter{\pgfplots@loc@TMPc}%
- \edef\pgfplots@loc@TMPd{%
- \expandafter\noexpand\csname pgfplots@createcolormap@grabnextspecial@\pgfplots@loc@TMPa\endcsname
- % position:
- {\pgfplots@loc@TMPb}
- % argument:
- {\the\t@pgfplots@tokb}%
- }%
- \pgfplots@loc@TMPd
- %
- \def\pgfplots@loc@TMPd{%
- \expandafter\pgfplots@createcolormap@\pgfplotsretval
- }%
- }%
+ \fi
%
%
% continue loop:
\pgfplots@loc@TMPd
}%
+\def\pgfplots@createcolormap@grabnext@complete@of@colormap{%
+ % ah - a special one based on another colormap!
+ % convert it into the standard format:
+ \begingroup
+ \let\pgfplotscolormap@at=\pgfplots@loc@TMPb
+ \let\pgfplotscolormap@argument=\pgfplots@loc@TMPc
+ \let\pgfplotscolormap@key=\pgfplots@loc@TMPa
+ %
+ \pgfplots@createcolormap@grabnext@complete@ofcolormap
+ \pgfmath@smuggleone\pgfplotsretval
+ \endgroup
+ %
+ \expandafter\pgfplots@createcolormap@\pgfplotsretval
+}%
+
+% INPUT:
+% \pgfplotscolormap@at
+% \pgfplotscolormap@argument
+% \pgfplotscolormap@key
+% OUTPUT:
+% The result of /pgfplots/of colormap/@define.
+% For the normal colormap definition, it populates
+% \pgfplotsretval with the color specifications as they should
+% be processed by the colormap definition code.
+\def\pgfplots@createcolormap@grabnext@complete@ofcolormap{%
+ \t@pgfplots@tokb=\expandafter{\pgfplotscolormap@argument}%
+ \edef\pgfplotscolormap@keyvalue{%
+ \if m\b@pgfplots@createcolormap@pos@mode
+ % ah - we have had manually provided positions before.
+ % Well, keep them. Otherwise, we will stay at the default
+ % placement.
+ target pos={\pgfplotscolormap@at},%
+ \fi
+ % ... but can be overriden here:
+ \pgfplotscolormap@key={\the\t@pgfplots@tokb},%
+ }%
+ %
+ \let\pgfplots@createcolormap@special@process@single@define=\pgfplots@createcolormap@special@process@single@define@CM
+ \let\pgfplots@createcolormap@special@process@list@separator=\pgfplots@createcolormap@special@process@list@separator@CM
+ %
+ % finally, process the keys:
+ \expandafter\pgfplots@of@colormap@getresult\expandafter{%
+ \pgfplotscolormap@keyvalue,
+ }%
+%\message{\pgfplotscolormap@key={\pgfplotscolormap@argument} -> '\pgfplotscolormap@keyvalue' -> \pgfplotsretval^^J}%
+}%
+
\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}%
+ % first: just use 0.
+ \pgfmathfloatcreate{0}{0.0}{0}%
\else
% not first:
\ifx\pgfplots@createcolormap@H\pgfutil@empty
% ah; we really have to deduce something. We are at the
% second node:
- \def\pgfmathresult{1cm}%
+ %\def\pgfmathresult{1cm}%
+ \pgfmathfloatcreate{1}{2.845274}{1}% 1cm=28.45274pt . Backw compat
\else
- \pgfmathadd@\pgfplots@createcolormap@LAST\pgfplots@createcolormap@H
+ \pgfmathfloatadd@\pgfplots@createcolormap@LAST\pgfplots@createcolormap@H
\fi
\fi
}%
\def\pgfplots@createcolormap@grabsemicolon;{\pgfplots@createcolormap@}%
+\def\pgfplots@createcolormap@grabcomma,{\pgfplots@createcolormap@}%
+
+\def\pgfplots@createcolormap@grabsemicolon@hasnext#1#2;{\pgfplots@createcolormap@ifhasmorecolors{#1}{#2}}%
+\def\pgfplots@createcolormap@grabcomma@hasnext#1#2,{\pgfplots@createcolormap@ifhasmorecolors{#1}{#2}}%
{
\catcode`\;=13
\gdef\pgfplots@createcolormap@grabsemicolon@active;{\pgfplots@createcolormap@}%
+ \gdef\pgfplots@createcolormap@grabsemicolon@active@hasnext#1#2;{\pgfplots@createcolormap@ifhasmorecolors{#1}{#2}}%
}
\def\pgfplots@createcolormap@nextcolor@tostring#1=#2\pgfplots@EOI#3{%
@@ -362,7 +1132,7 @@
%
% see \pgfplotscolornormalizesequencenext for details
\def\pgfplots@createcolormap@nextcolor#1#2{%
- \def\pgfplots@createcolormap@context{\pgfplots@createcolormap@nextcolor@tostring#2\pgfplots@EOI{#1}}%
+ \def\pgfplots@createcolormap@context{\pgfplots@createcolormap@nextcolor@tostring#2\pgfplots@EOI{#1}\pgfplots@createcolormap@trace}%
%
\pgfplotscolornormalizesequencenext{#2}%
\let\pgfplots@createcolormap@col@comps=\pgfplotsretvalb
@@ -375,79 +1145,134 @@
% compute 'h':
\pgfmathparse{#1}%
\let\pgfplots@createcolormap@MAX=\pgfmathresult
- \expandafter\pgfmathsubtract@\expandafter{\pgfmathresult}{\pgfplots@createcolormap@LAST}%
+ %
+ \ifx\pgfplots@createcolormap@MIN\pgfutil@empty
+ % it is the first.
+ \let\pgfplots@createcolormap@MIN=\pgfmathresult
+ \let\pgfplots@createcolormap@LAST=\pgfmathresult
+ \fi
+ %
+ \expandafter\pgfmathfloatsubtract@\expandafter{\pgfmathresult}{\pgfplots@createcolormap@LAST}%
\let\pgfplots@createcolormap@H@cur=\pgfmathresult
-%\message{found current diff = \pgfplots@createcolormap@H@cur\ ( from \pgfplots@createcolormap@MAX pt - \pgfplots@createcolormap@LAST pt)^^J}%
+ \pgfplots@createcolormap@check@increasing@mesh@width
\let\pgfplots@createcolormap@LAST=\pgfplots@createcolormap@MAX
\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. The error occured near `\pgfplots@createcolormap@context'}%
- \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
+ \pgfplots@createcolormap@compute@equalto{\pgfplots@createcolormap@H}{\pgfplots@createcolormap@H@cur}%
+ \ifpgfmathfloatcomparison
\else
- \pgfmathdivide@{\pgfplots@createcolormap@H@cur}{\pgfplots@createcolormap@H}%
- % after this group, \pgfmathresult is
- % - empty if no reinterpolation is possible,
- % - non-empty if reinterpolation IS possible. In this
- % case, it contains the integer multiple of H.
- \begingroup
- \afterassignment\pgfplots@createcolormap@nextRGB@consider@reinterpolation
- \c@pgf@counta=\pgfmathresult\relax
- \pgfmath@smuggleone\pgfmathresult
- \endgroup
- \ifx\pgfmathresult\pgfutil@empty
- % I can't do that yet.
+ \ifnum\b@pgfplotscreatecolormap@isuniform>1
+ % force reinterpolation:
+ \pgfplotscreatecolormap@reinterpolate{#2}%
\else
- \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@createcolormap@loop@end} {%
- \ifdim\c@pgfplots@createcolormap pt=\pgfplots@createcolormap@loop@end pt %
- % omit the last.
- \else
- \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{\pgfplotsretval}%
- \noexpand\to}%
- \expandafter\pgfplots@loc@TMPa\expandafter{\pgfplots@createcolormap@name}%
- \fi
- }%
+ % it is NOT uniform!
+ \def\b@pgfplotscreatecolormap@isuniform{0}%
+ %
+ \pgfmathfloatmintwo{\pgfplots@createcolormap@H@cur}{\pgfplots@createcolormap@H}%
+ \let\pgfplots@createcolormap@H=\pgfmathresult
\fi
\fi
\fi
+ %\message{found current H@cur = \pgfplots@createcolormap@H@cur\space (\pgfplots@createcolormap@LAST) -> H=\pgfplots@createcolormap@H^^J}%
+ %
+ % remember positions:
+ \expandafter\pgfplotsapplistXpushback\expandafter{\pgfplots@createcolormap@MAX,}\to\pgfplots@createcolormap@X
+ %
\edef\pgfplots@loc@TMPa{\noexpand\pgfplotsarraypushback{#2}\noexpand\to}%
\expandafter\pgfplots@loc@TMPa\expandafter{\pgfplots@createcolormap@name}%
\edef\pgfplots@createcolormap@last{#2}%
}%
+
+\def\pgfplots@createcolormap@check@increasing@mesh@width{%
+ \expandafter\pgfplotsarraycheckempty\expandafter{\pgfplots@createcolormap@name}%
+ \ifpgfplotsarrayempty
+ \else
+ \pgfmathfloatifflags{\pgfplots@createcolormap@H@cur}{1}{%
+ % ok, H>0
+ }{%
+ \pgfmathfloattofixed{\pgfplots@createcolormap@H@cur}%
+ \pgfplots@error{Colormaps must have increasing positions. The provided colormap has mesh width '\pgfmathresult' at \pgfplots@createcolormap@context. Please assign increasing positions}%
+ }%
+ \fi
+}%
+\def\pgfplots@createcolormap@compute@equalto#1#2{%
+ %\begingroup
+ %\pgfmathfloatcreate{1}{1.0}{-4}%
+ %\let\pgfmathfloat@relthresh=\pgfmathresult
+ \pgfmathfloatequalto@{#1}{#2}%
+ %\xdef\pgfplots@glob@TMPa{%
+ % \noexpand\def\noexpand\pgfmathresult{\pgfmathresult}%
+ % \ifpgfmathfloatcomparison
+ % \noexpand\pgfmathfloatcomparisontrue
+ % \else
+ % \noexpand\pgfmathfloatcomparisonfalse
+ % \fi
+ %}%
+ %\endgroup
+ %\pgfplots@glob@TMPa
+ %\message{equalto (#1,#2) = \pgfmathresult^^J}%
+}%
+\def\pgfplotscreatecolormap@reinterpolate#1{%
+ \pgfmathfloatdivide@{\pgfplots@createcolormap@H@cur}{\pgfplots@createcolormap@H}%
+ % after this group, \pgfmathresult is
+ % - empty if no reinterpolation is possible,
+ % - non-empty if reinterpolation IS possible. In this
+ % case, it contains the integer multiple of H.
+ \begingroup
+ \pgfmathfloattofixed{\pgfmathresult}%
+ \afterassignment\pgfplots@createcolormap@nextRGB@consider@reinterpolation
+ \c@pgf@counta=\pgfmathresult\relax
+ \pgfmath@smuggleone\pgfmathresult
+ \endgroup
+ \ifx\pgfmathresult\pgfutil@empty
+ % I can't do that yet.
+ \else
+ \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@createcolormap@loop@end} {%
+ \pgfmathfloatequalto@{\c@pgfplots@createcolormap}{\pgfplots@createcolormap@loop@end}%
+ \ifpgfmathfloatcomparison
+ % omit the last.
+ \else
+ \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
+ %
+ \pgfmathfloattofixed\pgfplots@createcolormap@scale@current
+ \let\pgfplots@createcolormap@scale@current=\pgfmathresult
+ \pgfmathfloattofixed\pgfplots@createcolormap@scale@last
+ \let\pgfplots@createcolormap@scale@last=\pgfmathresult
+ %
+ \pgfplotscolornormalizesequencezero
+ \pgfplotscolornormalizesequenceaddweighted
+ {\pgfplotsretval}
+ {\pgfplots@createcolormap@scale@current}
+ {#1}%
+ \pgfplotscolornormalizesequenceaddweighted
+ {\pgfplotsretval}
+ {\pgfplots@createcolormap@scale@last}
+ {\pgfplots@createcolormap@last}%
+ %
+%\message{interpolation step \c@pgfplots@createcolormap = \pgfplotsretval^^J}%
+ \edef\pgfplots@loc@TMPa{%
+ \noexpand\pgfplotsarraypushback{\pgfplotsretval}%
+ \noexpand\to}%
+ \expandafter\pgfplots@loc@TMPa\expandafter{\pgfplots@createcolormap@name}%
+ \fi
+ }%
+ \fi
+}%
\def\pgfplots@createcolormap@nextRGB@consider@reinterpolation#1\relax{%
\pgf@xa=#1pt
\ifdim\pgf@xa>0.5pt % we have something like 99.995 or so.
@@ -462,7 +1287,17 @@
%\message{Checking H/h = \pgfplots@createcolormap@H@cur pt/\pgfplots@createcolormap@H pt = \the\c@pgf@counta+-\pgf@sys@tonumber\pgf@xa\space: \the\pgf@xa > \the\pgf@xb\space (relative to \the\c@pgf@counta)?}%
%
\ifdim\pgf@xa>\pgf@xb
- \pgfplots@error{Sorry, non-uniform colormaps are only partially implemented, yet: the provided points must be multiples of the mesh width h=\pgfplots@createcolormap@H pt (but I found one with H/h = \pgfplots@createcolormap@H@cur pt/\pgfplots@createcolormap@H pt = \the\c@pgf@counta+-\pgf@sys@tonumber\pgf@xa\space which is no integer). Perhaps it helps to provide the mesh widths as argument as in {<name>}{[1cm] <color arguments>}? The error occured near `\pgfplots@createcolormap@context'}%
+ \begingroup
+ \if2\b@pgfplotscreatecolormap@isuniform
+ \pgfplots@error{Non-uniform colormaps are only supported if you write 'compat=1.14' (or higher). Please adopt the compatibility level and retry. The error occured near '\pgfplots@createcolormap@context'}%
+ \else
+ \pgfmathfloattofixed{\pgfplots@createcolormap@H}%
+ \let\pgfplots@createcolormap@H=\pgfmathresult
+ \pgfmathfloattofixed{\pgfplots@createcolormap@H@cur}%
+ \let\pgfplots@createcolormap@H@cur=\pgfmathresult
+ \pgfplots@error{The provided colormap positions are not multiples of the prescribed mesh width h=\pgfplots@createcolormap@H\space (found one with H/h = \pgfplots@createcolormap@H@cur/\pgfplots@createcolormap@H = \the\c@pgf@counta+-\pgf@sys@tonumber\pgf@xa\space which is no integer). The error occured near `\pgfplots@createcolormap@context'}%
+ \fi
+ \endgroup
\let\pgfmathresult=\pgfutil@empty
\else
\ifnum\c@pgf@counta=0
@@ -475,7 +1310,9 @@
\def\pgfplots@colormap@LUA@new#1{%
\ifpgfplots@LUA@supported
- \pgfplotscolormapserializecomponentstomacro{#1}\pgfplots@loc@TMPa
+ \begingroup
+ \pgfplotscolormapserializecomponentstomacro{#1}\pgfplots@values
+ \pgfplotscolormapserializeXtomacro{#1}\pgfplots@pos
\pgfplotsutil@directlua{%
local colorspace =^^J%
pgfplots.\csname pgfpl@cm@#1@colspace\endcsname;^^J%
@@ -483,13 +1320,27 @@
pgfplots.ColorMaps["#1"] = pgfplots.ColorMap.new(^^J%
\csname pgfpl@cm@#1@h\endcsname,^^J%
colorspace,^^J%
- { \pgfplots@loc@TMPa });^^J%
+ { \pgfplots@values },^^J
+ { \pgfplots@pos }^^J
+ );^^J%
else^^J%
io.write("There is no LUA colorspace for '\csname pgfpl@cm@#1@colspace\endcsname' - skipping LUA color map definition of #1\string\n");^^J%
end^^J%
}%
+ \endgroup
+ \fi
+}%
+
+% Executes '#2' if the colormap named '#1' has a uniform grid and '#3'
+% if not.
+\def\pgfplotscolormapifisuniform#1#2#3{%
+ \ifnum0=\pgfplotsarraysizeof{pgfpl@cm@#1@X}\relax
+ #2\relax
+ \else
+ #3\relax
\fi
}%
+
% Shows debug info about colormap #1 into the console.
\def\pgfplots@colormap@showdebuginfofor#1{%
\message{Debug info for color map '#1':^^J}%
@@ -501,10 +1352,18 @@
\message{Colorspace: \csname pgfpl@cm@#1@colspace\endcsname^^JValues (\csname pgfpl@cm@#1@col@comps\endcsname\space components each): ^^J}%
\begingroup
\c@pgf@counta=0
- \pgfplotsarrayforeachungrouped{pgfpl@cm@#1}\as\elem{%
- \pgfmath@basic@multiply@{\the\c@pgf@counta}{\csname pgfpl@cm@#1@h\endcsname}%
- \message{\#\the\c@pgf@counta=(\pgfmathresult)=(\elem);^^J}%
- \advance\c@pgf@counta by1 %
+ \pgfplotscolormapifisuniform{#1}{%
+ \pgfplotsarrayforeachungrouped{pgfpl@cm@#1}\as\elem{%
+ \pgfmath@basic@multiply@{\the\c@pgf@counta}{\csname pgfpl@cm@#1@h\endcsname}%
+ \message{\#\the\c@pgf@counta=(\pgfmathresult)=(\elem);^^J}%
+ \advance\c@pgf@counta by1 %
+ }%
+ }{%
+ \pgfplotsarrayforeachungrouped{pgfpl@cm@#1}\as\elem{%
+ \pgfplotsarrayselect\c@pgf@counta\of{pgfpl@cm@#1@X}\to\pgfmathresult
+ \message{\#\the\c@pgf@counta=(\pgfmathresult)=(\elem);^^J}%
+ \advance\c@pgf@counta by1 %
+ }%
}%
\message{^^J}%
\endgroup
@@ -587,7 +1446,11 @@
\pgfplotsarrayforeach{pgfpl@cm@#2}\as\elem{%
\ifnum\pgfplots@eachnth@cur=0\relax
\gdef\pgfplots@eachnth@cur{0}%
- \pgfmath@basic@multiply@{\pgfplotsarrayforeachindex}{\csname pgfpl@cm@#2@h\endcsname}%
+ \pgfplotscolormapifisuniform{#2}{%
+ \pgfmath@basic@multiply@{\pgfplotsarrayforeachindex}{\csname pgfpl@cm@#2@h\endcsname}%
+ }{%
+ \pgfplotsarrayselect\pgfplotsarrayforeachindex\of{pgfpl@cm@#1@X}\to\pgfmathresult
+ }%
\edef\pgfplots@loc@TMPa{{\elem}{#2}{\pgfplotsarrayforeachindex}{\pgfmathresult}}%
\expandafter\pgfplotscolormaptodatafile@elem\pgfplots@loc@TMPa
\ifx\pgfplotsretval\pgfutil@empty
@@ -613,7 +1476,9 @@
\endgroup
}
-% Defines \pgfplotsretval to contain the mesh width of colormap #1
+% Defines \pgfplotsretval to contain the mesh width of colormap #1.
+% If the color map has a non-uniform grid, it returns the SMALLEST
+% encountered mesh width.
\def\pgfplotscolormapgetmeshwidth#1{%
\expandafter\let\expandafter\pgfplotsretval\csname pgfpl@cm@#1@h\endcsname%
}%
@@ -621,13 +1486,39 @@
% defines macro #2 to contain a serialized variant of the color
% components (only the color components!)
\def\pgfplotscolormapserializecomponentstomacro#1#2{%
+ \pgfplotscolormapserialize@to@macro{pgfpl@cm@#1}{#2}%
+}
+\def\pgfplotscolormapserialize@to@macro#1#2{%
\pgfplotsapplistXnewempty\pgfplots@serialize@list@
- \pgfplotsarrayforeachungrouped{pgfpl@cm@#1}\as\elem{%
- \expandafter\pgfplotsapplistXpushback\expandafter{\elem},\to\pgfplots@serialize@list@
+ \pgfplots@loc@tmptrue
+ \expandafter\pgfplotsarrayforeachungrouped\expandafter{#1}\as\elem{%
+ \ifpgfplots@loc@tmp
+ \expandafter\pgfplotsapplistXpushback\expandafter{\expandafter{\elem}}\to\pgfplots@serialize@list@
+ \pgfplots@loc@tmpfalse
+ \else
+ \expandafter\pgfplotsapplistXpushback\expandafter,\expandafter{\elem}\to\pgfplots@serialize@list@
+ \fi
}%
\pgfplotsapplistXlet#2=\pgfplots@serialize@list@
}%
+\def\pgfplotscolormapserialize@to@macro@nobraces#1#2{%
+ \pgfplotsapplistXnewempty\pgfplots@serialize@list@
+ \pgfplots@loc@tmptrue
+ \expandafter\pgfplotsarrayforeachungrouped\expandafter{#1}\as\elem{%
+ \ifpgfplots@loc@tmp
+ \expandafter\pgfplotsapplistXpushback\elem\to\pgfplots@serialize@list@
+ \pgfplots@loc@tmpfalse
+ \else
+ \expandafter\pgfplotsapplistXpushback\expandafter,\elem\to\pgfplots@serialize@list@
+ \fi
+ }%
+ \pgfplotsapplistXlet#2=\pgfplots@serialize@list@
+}%
+\def\pgfplotscolormapserializeXtomacro#1#2{%
+ \pgfplotscolormapserialize@to@macro@nobraces{pgfpl@cm@#1@X}{#2}%
+}%
+
% Copies the contents of the colormap named '#1' into a macro '#2'.
% Invocation of the macro will then re-create the colormap.
%
@@ -636,6 +1527,7 @@
\def\pgfplotscolormapserializetomacro#1#2{%
\begingroup
\pgfplotscolormapserializecomponentstomacro{#1}\pgfplots@serialize@list
+ \pgfplotscolormapserializeXtomacro{#1}\pgfplots@serialize@list@X
\toks0={\expandafter\def\csname pgfpl@cm@#1@h\endcsname}%
\toks1={\expandafter\def\csname pgfpl@cm@#1@invh\endcsname}%
\toks2={%
@@ -651,6 +1543,16 @@
\toks4=\expandafter{\expandafter\def\csname pgfpl@cm@#1@colspace\endcsname}%
\toks5=\expandafter{\expandafter\def\csname pgfpl@cm@#1@col@comps\endcsname}%
\toks6=\expandafter{\expandafter\def\csname pgfpl@cm@#1@lastindex\endcsname}%
+ \toks7={%
+ \pgfplotsarraynewempty{pgfpl@cm@#1@X}%
+ \expandafter\pgfplotsutilforeachcommasep\pgfplots@loc@TMPa\as\pgfplots@loc@TMPb{%
+ \ifx\pgfplots@loc@TMPb\pgfutil@empty
+ \else
+ \expandafter\pgfplotsarraypushback\pgfplots@loc@TMPb\to{pgfpl@cm@#1@X}%
+ \fi
+ }%
+ }%
+ \toks8=\expandafter{\pgfplots@serialize@list@X}%
\xdef\pgfplots@glob@TMPa{%
\the\toks0 {\csname pgfpl@cm@#1@h\endcsname}%
\the\toks1 {\csname pgfpl@cm@#1@invh\endcsname}%
@@ -659,15 +1561,97 @@
\the\toks4 {\csname pgfpl@cm@#1@colspace\endcsname}%
\the\toks5 {\csname pgfpl@cm@#1@col@comps\endcsname}%
\the\toks6 {\csname pgfpl@cm@#1@lastindex\endcsname}%
+ \noexpand\def\noexpand\pgfplots@loc@TMPa{\the\toks8 }%
+ \the\toks7
+ \def\expandafter\noexpand\csname pgfpl@cm@#1@X@scale@order@z\endcsname{\csname pgfpl@cm@#1@X@scale@order@z\endcsname}%
}%
\endgroup
\let#2=\pgfplots@glob@TMPa
}%
+% Defines \pgfplotsretval to contain an argument for use in \foreachlist
+% which results in all the positions.
+%
+% [#1:#2] : the desired output domain. The smallest position will be
+% mapped to #1, the largest to #2, and all in-between will be mapped
+% accordingly.
+% #3: the colormap name.
+%
+% Note that this switch depends on the current value of 'colormap
+% access': piecewise constant may use different positions.
+%
+% On output, \pgfplotsretval will contain the result.
+\def\pgfplotscolormapgetpositions[#1:#2]#3{%
+ \begingroup
+ \if d\pgfplots@colormap@access
+ \edef\pgfplotsretval{0,1,...,\pgfplotscolormaplastindexof{#3}}%
+ \else
+ \if m\pgfplots@colormap@access
+ \def\b@pgfplots@extra@interval{0}%
+ \edef\pgfplots@H{\csname pgfpl@cm@#3@h\endcsname}%
+ \else
+ \if c\pgfplots@colormap@access
+ \pgfplotscolormap@piecewiseconst@prepare@scale{#3}%
+ \edef\pgfplots@H{\pgf@sys@tonumber\pgf@x}%
+ \fi
+ \fi
+ %
+ \pgfkeys{/pgf/fpu}%
+ \pgfplotsapplistXnewempty\pgfplots@resultaccum
+ \pgfplotscolormapifisuniform{#3}{%
+ \pgfmathparse{#1 + (#2-#1) * \pgfplots@H/1000}%
+ \let\next=\pgfmathresult
+ \pgfmathparse{#2}% + (#2-#1)/1000}%
+ %
+ \def\b@pgfplots@isfirst{1}%
+ \edef\pgfplots@loc@TMPa{\noexpand\pgfplotsforeachungrouped\noexpand \x in {#1,\next,...,\pgfmathresult}}%
+ \pgfplots@loc@TMPa{%
+ \if0\b@pgfplots@isfirst
+ \pgfplotsapplistXpushback,\to\pgfplots@resultaccum
+ \fi
+ \expandafter\pgfplotsapplistXpushback\expandafter{\x}\to\pgfplots@resultaccum
+ \def\b@pgfplots@isfirst{0}%
+ }%
+ }{%
+ \pgfmathparse{(#2-#1)/1000}%
+ \let\pgfplots@scale=\pgfmathresult
+ \pgfplotsarrayforeachungrouped{pgfpl@cm@#3@X}\as\pgfplots@loc@TMPc{%
+ \if m\pgfplots@colormap@access
+ % colormap access=map
+ \pgfmathparse{#1 + \pgfplots@loc@TMPc * \pgfplots@scale}%
+ \else
+ \if1\b@pgfplots@extra@interval
+ \pgfmathparse{#1 + \pgfplots@loc@TMPc * \pgfplots@H* \pgfplots@scale}%
+ \else
+ % DISABLE additional interval!
+ % Means: use the input position as usual:
+ \pgfmathparse{#1 + \pgfplots@loc@TMPc * \pgfplots@scale}%
+ \fi
+ \fi
+ \ifnum\pgfplotsarrayforeachindex>0
+ \pgfplotsapplistXpushback,\to\pgfplots@resultaccum
+ \fi
+ \expandafter\pgfmathfloattofixed\expandafter{\pgfmathresult}%
+ \expandafter\pgfplotsapplistXpushback\expandafter{\pgfmathresult}\to\pgfplots@resultaccum
+ }%
+ \if1\b@pgfplots@extra@interval
+ \pgfmathparse{#2}%
+ \pgfplotsapplistXpushback,\to\pgfplots@resultaccum
+ \expandafter\pgfmathfloattofixed\expandafter{\pgfmathresult}%
+ \expandafter\pgfplotsapplistXpushback\expandafter{\pgfmathresult}\to\pgfplots@resultaccum
+ \fi
+ }%
+ \pgfplotsapplistXlet\pgfplotsretval=\pgfplots@resultaccum
+ \fi
+ \pgfmath@smuggleone\pgfplotsretval
+ \endgroup
+}%
+
% this is a CONSTANT! Do NOT change it!
% Just read it -- just in case \pgfplotscolormaptopdffunction will use
% a different upper bound in the future.
-\def\pgfplotscolormappdfmax{1}% FIXME : why? 1000 would be more precise...?
+\def\pgfplotscolormappdfmax{1000}%
+\def\pgfplotscolormappdfmax@inv{1}%
% Expands to the size of colormap #1 .
\def\pgfplotscolormapsizeof#1{%
@@ -678,6 +1662,12 @@
}%
}%
+% Defines \pgfplotsretval to contain the color of color map '#1' at
+% index '#2'
+\def\pgfplotscolormapgetcolor#1#2{%
+ \pgfplotsarrayselect{#2}\of{pgfpl@cm@#1}\to\pgfplotsretval
+}%
+
% Expands to the last index of colormap #1 (or -1)
\def\pgfplotscolormaplastindexof#1{%
\pgfplotscolormapifdefined{#1}{%
@@ -687,6 +1677,100 @@
}%
}%
+% POSTCONDITION:
+% 1. for uniform #1:
+% \pgf@x contains the MODIFIED mesh width
+% \b@pgfplots@extra@interval is 1 if and only if an extra interval
+% should be added
+% 2. for non-uniform #1:
+% \pgf@x is a scaling factor to map input positions to MODIFIED
+% positions
+% \b@pgfplots@extra@interval is 1 if and only if an extra interval
+\def\pgfplotscolormap@piecewiseconst@prepare@scale#1{%
+ % advance the number of intervals by 1.
+ \pgfplotscolormapifisuniform{#1}{%
+ % To this end, we have to compute
+ % N = n+1
+ % and
+ % H = 1000 / (N-1) = 1000/n.
+ % Store H in \pgf@x:
+ \expandafter\ifx\csname pgfpl@cm@#1@X@scale@order@z\endcsname\pgfutil@empty%
+ \c@pgf@countd=\pgfplotscolormapsizeof{#1}\relax
+ %
+ \global\pgf@x=1000pt %
+ \global\divide\pgf@x by\c@pgf@countd
+ \def\b@pgfplots@extra@interval{1}%
+ \else
+ % DISABLE the extra interval!
+ \global\pgf@x=\csname pgfpl@cm@#1@h\endcsname pt %
+ \def\b@pgfplots@extra@interval{0}%
+ \fi
+ }{%
+ % the very same idea as for uniform colormaps applies
+ % for non-uniform maps as well: we create an
+ % artificial interval at the rightmost end.
+ % The idea is to think of a temporary map in the range
+ % [0,1000+ h] where h is the current colormap's
+ % mesh width.
+ % Since the domain is [0,1000], we map [0,1000+h]
+ % linearly into [0,1000].
+ %
+ % This here is the scaling factor:
+ \global\pgf@x=\csname pgfpl@cm@#1@X@scale@order@z\endcsname pt %
+ % see also
+ % \pgfplotscolormapfindpiecewiseconst@precomputed for
+ % comments
+ \ifdim\pgf@x>0sp %
+ \def\b@pgfplots@extra@interval{1}%
+ \else
+ % disable it
+ \def\b@pgfplots@extra@interval{0}%
+ \fi
+ }%
+}%
+
+% #1: colormap name
+% #2: yes code
+% #3: no code
+\def\pgfplotscolormapifrequiresextrainterval#1#2#3{%
+ \if c\pgfplots@colormap@access
+ \pgfplotscolormapifisuniform{#1}{%
+ \expandafter\ifx\csname pgfpl@cm@#1@X@scale@order@z\endcsname\pgfutil@empty%
+ % no...
+ #3\relax%
+ \else
+ % yes:
+ #2\relax%
+ \fi
+ }{%
+ \ifdim\csname pgfpl@cm@#1@X@scale@order@z\endcsname pt>0pt
+ % yes:
+ #2\relax%
+ \else
+ % no:
+ #3\relax%
+ \fi
+ }%
+ \else
+ % no:
+ #3\relax%
+ \fi
+}%
+% #1: colormap name
+% #2: yes code
+% #3: no code
+\def\pgfplotscolormapifdrawslastcolor#1#2#3{%
+ \pgfplotscolormapifrequiresextrainterval{#1}{%
+ #2\relax%
+ }{%
+ \if c\pgfplots@colormap@access
+ #3\relax%
+ \else
+ #2\relax%
+ \fi
+ }%
+}%
+
% Writes a PDF function of /FunctionType 3 to \pgfplotsretval
%
% The /Domain argument will be set to [ 0 \pgfplotscolormappdfmax ] and bounds will be
@@ -715,6 +1799,7 @@
\pgfplots@error{Sorry, processing more than 4 color components (as required for color map #1) is unsupported in this context}%
\fi
%
+ \def\b@pgfplots@extra@interval{0}%
\if m\pgfplots@colormap@access
% colormap access=map
\def\pgfplots@order{1}%
@@ -729,16 +1814,7 @@
% See comments in pgfplotscolormapfindpiecewiseconst@precomputed@
\def\pgfplots@order{0}%
%
- % advance the number of intervals by 1.
- % To this end, we have to compute
- % N = n+1
- % and
- % H = 1000 / (N-1) = 1000/n.
- % Store H in \pgf@x:
- \c@pgf@countd=\pgfplotscolormapsizeof{#1}\relax
- %
- \global\pgf@x=1000pt %
- \global\divide\pgf@x by\c@pgf@countd
+ \pgfplotscolormap@piecewiseconst@prepare@scale{#1}%
%
% interchange the sequence in the PDF function as it is
% defined as
@@ -775,9 +1851,25 @@
}%
\expandafter\pgfplotsapplistXpushback\expandafter{\pgfplots@loc@TMPd}\to\pgfplots@resultaccum
\ifnum\c@pgf@counta<\c@pgf@countb\relax
- \pgf@xa=\pgf@x
- \multiply\pgf@xa by\c@pgf@counta\relax
- \divide\pgf@xa by1000 % we want [ 0 1 ] not [0 1000] as domain XXX : why!?
+ \pgfplotscolormapifisuniform{#1}{%
+ \pgf@xa=\pgf@x
+ \multiply\pgf@xa by\c@pgf@counta\relax
+ }{%
+ \pgfplotsarrayselect{\c@pgf@counta}\of{pgfpl@cm@#1@X}\to\pgfplots@loc@TMPc
+ \if m\pgfplots@colormap@access
+ % colormap access=map
+ \pgf@xa=\pgfplots@loc@TMPc pt %
+ \else
+ \if1\b@pgfplots@extra@interval
+ \pgf@xa=\pgfplots@loc@TMPc\pgf@x%
+ \else
+ % DISABLE additional interval!
+ % Means: use the input position as usual:
+ \pgf@xa=\pgfplots@loc@TMPc pt %
+ \fi
+ \fi
+ }%
+ \divide\pgf@xa by\pgfplotscolormappdfmax@inv\relax% we want [ 0 1 ] not [0 1000] as domain XXX : why!?
\edef\pgfplots@loc@TMPc{ \pgf@sys@tonumber\pgf@xa}%
\expandafter\pgfplotsapplistXpushback\expandafter{\pgfplots@loc@TMPc}\to\pgfplots@bounds@accum%
\fi
@@ -786,7 +1878,7 @@
\let\pgfplots@loc@TMPa=\cdata
\advance\c@pgf@counta by1
}%
- \if 0\pgfplots@order
+ \if1\b@pgfplots@extra@interval
% add an artificial interval.
\edef\pgfplots@loc@TMPd{%
<<
@@ -797,10 +1889,15 @@
>>
}%
\expandafter\pgfplotsapplistXpushback\expandafter{\pgfplots@loc@TMPd}\to\pgfplots@resultaccum
- \pgf@xa=\pgf@x
\advance\c@pgf@counta by-1 %
- \multiply\pgf@xa by\c@pgf@counta\relax
- \divide\pgf@xa by1000 % we want [ 0 1 ] not [0 1000] as domain XXX : why!?
+ \pgfplotscolormapifisuniform{#1}{%
+ \pgf@xa=\pgf@x
+ \multiply\pgf@xa by\c@pgf@counta\relax
+ }{%
+ \pgfplotsarrayselect{\c@pgf@counta}\of{pgfpl@cm@#1@X}\to\pgfplots@loc@TMPc
+ \pgf@xa=\pgfplots@loc@TMPc\pgf@x%
+ }%
+ \divide\pgf@xa by\pgfplotscolormappdfmax@inv\relax% we want [ 0 1 ] not [0 1000] as domain XXX : why!?
\edef\pgfplots@loc@TMPc{ \pgf@sys@tonumber\pgf@xa}%
\expandafter\pgfplotsapplistXpushback\expandafter{\pgfplots@loc@TMPc}\to\pgfplots@bounds@accum%
\pgfplotsapplistXpushback{ 0 1}\to\pgfplots@encode@accum%
@@ -865,7 +1962,13 @@
\c@pgf@counta=0
\let#3=\pgfutil@empty
\pgfplotsarrayforeachungrouped{pgfpl@cm@#1}\as\pgfplotscolormaptoshadingspec@TMP{%
- \pgf@yb=\c@pgf@counta\pgf@ya
+ \pgfplotscolormapifisuniform{#1}{%
+ \pgf@yb=\c@pgf@counta\pgf@ya
+ }{%
+ \pgfplotsarrayselect\c@pgf@counta\of{pgfpl@cm@#1@X}\to\pgfplots@loc@TMPd
+ \pgfmathmultiply@{\pgfplots@loc@TMPd}{\pgfplots@loc@TMPb}%
+ \pgf@yb=\pgfmathresult pt %
+ }%
\edef\pgfplots@colspace{\csname pgfpl@cm@#1@colspace\endcsname}%
% FIXME : PGF shadings accept only RGB!
\if1\pgfplotscolormaptoshadingspectorgb
@@ -910,6 +2013,8 @@
% Expands to the transformed range's right end of every colormap. The left
% end is fixed to '0'.
\def\pgfplotscolormaprange{1000}
+\pgfmathfloatcreate{1}{1.0}{3}%
+\let\pgfplotscolormaprange@float=\pgfmathresult
\def\pgfplotscolormapgetcolorspace#1{%
\edef\pgfplotsretval{\csname pgfpl@cm@#1@colspace\endcsname}%
@@ -952,17 +2057,22 @@
}%
\def\pgfplotscolormapfind@precomputed[#1:#2][#3]#4#5{%
\ifpgfplots@LUA@supported
- \edef\pgfmathresult{%
- \pgfplotsutil@directlua{%
- pgfplots.texColorMapPrecomputed("#5", #1,#2,#4)
+ \pgfplotscolormapifisuniform{#5}{%
+ \edef\pgfmathresult{%
+ \pgfplotsutil@directlua{%
+ pgfplots.texColorMapPrecomputed("#5", "#1","#2","#4")
+ }%
}%
- }%
- \ifx\pgfmathresult\pgfutil@empty
- \pgfplotscolormapfind@precomputed@warn@LUA{#5}%
+ \ifx\pgfmathresult\pgfutil@empty
+ \pgfplotscolormapfind@precomputed@warn@LUA{#5}%
+ \pgfplotscolormapfind@precomputed@[#1:#2][#3]{#4}{#5}%
+ \else
+ %\message{LUA colormapfind[#1:#2](#4)(#5) = \pgfmathresult^^J}%
+ \fi
+ }{%
+ % FIXME : implement LUA for non-uniform colormaps
\pgfplotscolormapfind@precomputed@[#1:#2][#3]{#4}{#5}%
- \else
- %\message{LUA colormapfind[#1:#2](#4)(#5) = \pgfmathresult^^J}%
- \fi
+ }%
\else
\pgfplotscolormapfind@precomputed@[#1:#2][#3]{#4}{#5}%
\fi
@@ -974,33 +2084,45 @@
\expandafter\gdef\csname pgfplotscolormapfind@precomputed@warn@LUA@#1\endcsname{1}%
\fi
}%
-\def\pgfplotscolormapfind@@@[#1:#2][#3]#4#5{%
- % 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' ... ^^J}%
- \def\pgfplots@loc@samerange{0:1000}%
+\def\pgfplotscolormapfind@transform[#1:#2][#3]#4#5{%
+ \edef\pgfplots@loc@TMPa{#1:#2}%
+ \edef\pgfplots@loc@samerange{0:\pgfplotscolormaprange}%
\ifx\pgfplots@loc@TMPa\pgfplots@loc@samerange
% we have phi(#4) = #4 because #4 in [0:1000].
- \def\pgfmathresult{#4}%
+ \pgfmathfloatparsenumber{#4}%
+ \pgfmathfloattofixed\pgfmathresult
\else
+ % Step 0: compute #3 if it is missing and write it into \pgfplots@loc@TMPa.
+%\message{mapping '#4' into colormap '#5' with range [#1:#2] ... ^^J}%
+ \pgfmathfloatparsenumber{#1}%
+ \let\pgfplots@L=\pgfmathresult
+ %
+ \def\pgfplots@loc@TMPa{#3}%
+ \ifx\pgfplots@loc@TMPa\pgfutil@empty
+ \pgfmathfloatparsenumber{#2}%
+ \let\pgfplots@R=\pgfmathresult
+ \pgfmathfloatsubtract@{\pgfplots@R}{\pgfplots@L}%
+ \let\pgfplots@loc@TMPb=\pgfmathresult
+ \pgfmathfloatdivide@{\pgfplotscolormaprange@float}{\pgfplots@loc@TMPb}%
+ \else
+ \pgfmathfloatparsenumber{#3}%
+ \fi
+ \let\pgfplots@loc@TMPa=\pgfmathresult
+ %
% 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}%
+ \pgfmathfloatparsenumber{#4}%
+ \let\pgfplots@V=\pgfmathresult
+ \pgfmathfloatsubtract@{\pgfplots@V}{\pgfplots@L}%
+ \expandafter\pgfmathfloatmultiply@\expandafter{\pgfmathresult}{\pgfplots@loc@TMPa}%
+ \pgfmathfloattofixed\pgfmathresult
\fi
- \ifdim\pgfmathresult pt<0pt
+ \ifdim\pgfmathresult pt<0pt %
\def\pgfmathresult{0}%
\else
- \ifdim\pgfmathresult pt>1000pt
+ \ifdim\pgfmathresult pt>1000pt %
\def\pgfmathresult{1000}%
\fi
\fi
@@ -1008,44 +2130,84 @@
\def\pgfplotscolormapfind@precomputed@[#1:#2][#3]#4#5{%
\pgfplotscolormapassertexists{#5}%
\begingroup
- \pgfplotscolormapfind@@@[#1:#2][#3]{#4}{#5}%
+ \pgfplotscolormapfind@transform[#1:#2][#3]{#4}{#5}%
+ \let\pgfplotscolormapfind@transformedx=\pgfmathresult
%
% Now, we have it in [0,1000]. Find the correct interval:
- \let\pgfplotscolormapfind@transformedx=\pgfmathresult
- \pgfmathmultiply@{\pgfplotscolormapfind@transformedx}{\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
- % Step 2: interpolate the desired RGB value using vector valued
- % interpolation on the identified interval.
- \c@pgf@counta=\pgfplotscolormapfind@intervalno\relax
+ \pgfplotscolormapifisuniform{#5}{%
+ \pgfmathmultiply@{\pgfplotscolormapfind@transformedx}{\csname pgfpl@cm@#5@invh\endcsname}%
+ \let\pgfplotscolormapfind@transformedx@divh=\pgfmathresult
+ % assign \pgfplotscolormapfind@intervalno := \pgfmathresult
+ % without '.0' suffix:
+ \expandafter\pgfplotscolormap@floor@unforgiving\pgfmathresult\relax
+ % Step 2: interpolate the desired RGB value using vector valued
+ % interpolation on the identified interval.
+ \c@pgf@counta=\pgfplotscolormapfind@intervalno\relax
+ % color^m(x) = ( (x-x_i)/(x_{i+1} - x_i) ) * (c_{i+1}^m - c_i^m ) + c_i^m
+ % = ( 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
+ \pgfmathsubtract@{\pgfplotscolormapfind@transformedx@divh}{\pgfplotscolormapfind@intervalno}%
+ \let\pgfplots@loc@factor=\pgfmathresult
+ }{%
+ \pgfplotsarraybinarysearch{pgfpl@cm@#5@X}{\pgfplotscolormapfind@transformedx}{0}{\pgfplotscolormapsizeof{#5}}%
+ \c@pgf@counta=\pgfplotsretval\relax
+ \ifnum\c@pgf@counta<0
+ % as per definition of \pgfplotsarraybinarysearch, a
+ % negative result indicates the "insertion point" ...
+ \c@pgf@counta=-\c@pgf@counta
+ % ... plus one.
+ \advance\c@pgf@counta by-1
+ %
+ % But we do not WANT the insertion point! We want the LEFT
+ % interval boundary!
+ \advance\c@pgf@counta by-1
+ \fi
+ %
+ % color^m(x) = ( (x-x_i)/(x_{i+1} - x_i) ) * (c_{i+1}^m - c_i^m ) + c_i^m
+ % = s * c_{i+1}^m + S * c_i^m
+ %
+ % s = (x - x_i) / (x_{i+1} - x_i)
+ \begingroup
+ \pgfplotsarrayselect\c@pgf@counta\of{pgfpl@cm@#5@X}\to\pgfplotscolormapfind@rgb@X@left
+ \advance\c@pgf@counta by1
+ \ifnum\c@pgf@counta<\pgfplotsarraysizeof{pgfpl@cm@#5} %
+ % ok, we really have an interval
+ \pgfplotsarrayselect\c@pgf@counta\of{pgfpl@cm@#5@X}\to\pgfplotscolormapfind@rgb@X@right
+ %
+ \pgfmathsubtract@{\pgfplotscolormapfind@rgb@X@right}{\pgfplotscolormapfind@rgb@X@left}%
+ \let\pgfplotscolormapfind@h=\pgfmathresult
+ \pgfmathsubtract@{\pgfplotscolormapfind@transformedx}{\pgfplotscolormapfind@rgb@X@left}%
+ \let\pgfplots@loc@TMPa=\pgfmathresult
+ \pgfmathdivide@{\pgfplots@loc@TMPa}{\pgfplotscolormapfind@h}%
+ \let\pgfplots@loc@factor=\pgfmathresult
+ \else
+ % irrelevant (not used)
+ \def\pgfplots@loc@factor{1}%
+ \fi
+ \pgfmath@smuggleone\pgfplots@loc@factor
+ \endgroup
+ }%
+ % POSTCONDITION: \c@pgf@counta is the index of the LEFT interval
+ % and \pgfplots@loc@factor is the factor for the linear interpolation.
+ %
%\message{mapping [#1,#2] -> [0,\pgfplotscolormaprange] yielded phi(#4) = \pgfplotscolormapfind@transformedx, situated in interval no \the\c@pgf@counta.^^J}%
\pgfplotsarrayselect\c@pgf@counta\of{pgfpl@cm@#5}\to\pgfplotscolormapfind@rgb@LEFT
%
% do the stuff which is specific to linear interpolation:
%
- \pgfmathsubtract@{\pgfplotscolormapfind@transformedx@divh}{\pgfplotscolormapfind@intervalno}%
- \let\pgfplots@loc@factor=\pgfmathresult
+ % S = 1 - s
\pgfmathsubtract@{1}{\pgfplots@loc@factor}%
\let\pgfplots@loc@factor@two=\pgfmathresult
%
- \pgfplotsarraysize{pgfpl@cm@#5}\to\c@pgf@countb
- \advance\c@pgf@countb-1 %
- \ifnum\c@pgf@counta<\c@pgf@countb
- % Ah: (selected index < length-1) . That means: we have an interval.
- \advance\c@pgf@counta by1
+ \advance\c@pgf@counta by1 %
+ \ifnum\c@pgf@counta<\pgfplotsarraysizeof{pgfpl@cm@#5} %
+ % Ah: (selected index < length) . That means: we have an interval.
\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].^^J}%
%
%
- % 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}
@@ -1123,7 +2285,7 @@
\def\pgfplotscolormapfindpiecewiseconst@precomputed@[#1:#2][#3]#4#5{%
\pgfplotscolormapassertexists{#5}%
\begingroup
- \pgfplotscolormapfind@@@[#1:#2][#3]{#4}{#5}%
+ \pgfplotscolormapfind@transform[#1:#2][#3]{#4}{#5}%
\let\pgfplotscolormapfind@transformedx=\pgfmathresult
%
% Now, we have it in [0,1000]. Find the correct interval:
@@ -1148,19 +2310,77 @@
% what I really need is:
% 1/H = N/1000 = (1000 h^{-1} +1)/ 1000 = h^{-1} + 1/1000
%
- % compute 1/H here:
- \pgfmathadd@{\csname pgfpl@cm@#5@invh\endcsname}{0.001}%
- \let\pgfplots@piecewiseconst@invh=\pgfmathresult%
- \pgfmathmultiply@{\pgfplotscolormapfind@transformedx}{\pgfplots@piecewiseconst@invh}%
- \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
- % Step 2: interpolate the desired RGB value using vector valued
- % interpolation on the identified interval.
- \c@pgf@counta=\pgfplotscolormapfind@intervalno\relax
+ \pgfplotscolormapifisuniform{#5}{%
+ %
+ \expandafter\ifx\csname pgfpl@cm@#5@X@scale@order@z\endcsname\pgfutil@empty%
+ % compute 1/H here:
+ \pgfmathadd@{\csname pgfpl@cm@#5@invh\endcsname}{0.001}%
+ \let\pgfplots@piecewiseconst@invh=\pgfmathresult%
+ \else
+ % disable the extra interval
+ \expandafter\let\expandafter\pgfplots@piecewiseconst@invh\csname pgfpl@cm@#5@invh\endcsname
+ \fi
+ \pgfmathmultiply@{\pgfplotscolormapfind@transformedx}{\pgfplots@piecewiseconst@invh}%
+ \let\pgfplotscolormapfind@transformedx@divh=\pgfmathresult
+ % assign \pgfplotscolormapfind@intervalno := \pgfmathresult
+ % without '.0' suffix:
+ \expandafter\pgfplotscolormap@floor\pgfmathresult\relax
+ % Step 2: interpolate the desired RGB value using vector valued
+ % interpolation on the identified interval.
+ \c@pgf@counta=\pgfplotscolormapfind@intervalno\relax
+ }{%
+ % the same idea can also be applied to non-uniform grids.
+ % However, it is more involved here.
+ %
+ % My idea is that I add an extra interval of length 'h' at the right end of
+ % the domain, i.e. I enlarge the domain to [0,1000+h].
+ %
+ % To this end, I map the input number linearly from
+ % [0,1000] -> [0,1000+h]
+ % using k(t) = (1000+h)/1000 * t
+ %
+ % Note that k(t) = 1/ pgfpl@cm@#5@X@scale@order@z
+ %
+ % and search in the existing X coordinates of the colormap.
+ % Note that these X coordinates actually do not contain the
+ % artifical rightmost boundary point at 1000+h. But that is
+ % ok, we plan to assign COLOR(1000+h) := COLOR(1000) anyway.
+ %
+ % Naturally, some values 'k(t)' will be BEYOND '1000'. In this
+ % case, we simply use the rightmost interval and are done with
+ % it.
+ %
+ % compute k(t):
+ \ifdim\csname pgfpl@cm@#5@X@scale@order@z\endcsname pt>0pt
+ \pgfmathadd@{1000}{\csname pgfpl@cm@#5@h\endcsname}%
+ \pgf@xa=\pgfmathresult pt %
+ \divide\pgf@xa by1000 %
+ \edef\pgfplotscolormapfind@map@to@extra@interval{\pgf@sys@tonumber\pgf@xa}%
+ %
+ \pgfmathmultiply@{\pgfplotscolormapfind@transformedx}{\pgfplotscolormapfind@map@to@extra@interval}%
+ \let\pgfplotscolormapfind@transformedx@=\pgfmathresult
+ \else
+ % disable the extra interval
+ \let\pgfplotscolormapfind@transformedx@=\pgfplotscolormapfind@transformedx
+ \fi
+ %
+ % search k(t) in the original X values.
+ \pgfplotsarraybinarysearch{pgfpl@cm@#5@X}{\pgfplotscolormapfind@transformedx@}{0}{\pgfplotscolormapsizeof{#5}}%
+ \c@pgf@counta=\pgfplotsretval\relax
+ \ifnum\c@pgf@counta<0
+ % as per definition of \pgfplotsarraybinarysearch, a
+ % negative result indicates the "insertion point" ...
+ \c@pgf@counta=-\c@pgf@counta
+ % ... plus one.
+ \advance\c@pgf@counta by-1
+ %
+ % But we do not WANT the insertion point! We want the LEFT
+ % interval boundary!
+ \advance\c@pgf@counta by-1
+ \fi
+%\pgfplotscolormapserializeXtomacro{#5}\XXX
+%\message{k(\pgfplotscolormapfind@transformedx) = \pgfplotscolormapfind@transformedx@. Searching for value in X=(\XXX) resulted in \pgfplotsretval, and the index to use is \the\c@pgf@counta.^^J}%
+ }%
%
\ifnum\c@pgf@counta=\pgfplotscolormapsizeof{#5}\relax
% we have artificially increased the "h" (see the comments
@@ -1169,13 +2389,27 @@
\advance\c@pgf@counta by-1
\fi
%
-%\message{mapping [#1,#2] -> [0,\pgfplotscolormaprange] yielded phi(#4) = \pgfplotscolormapfind@transformedx, situated in interval no \the\c@pgf@counta.^^J}%
+%\message{mapping [#1,#2] -> [0,\pgfplotscolormaprange] yielded phi = \pgfplotscolormapfind@transformedx, situated in interval no \the\c@pgf@counta/\pgfplotsarraysizeof{pgfpl@cm@#5}.^^J}%
\pgfplotsarrayselect\c@pgf@counta\of{pgfpl@cm@#5}\to\pgfplotscolormapfind@rgb@LEFT
\let\pgfmathresult=\pgfplotscolormapfind@rgb@LEFT
\pgfmath@smuggleone\pgfmathresult
\endgroup
}%
+\def\pgfplotscolormap@floor#1.#2\relax{%
+ \ifdim0.#2pt>0.999pt
+ % ok, it is ALMOST one more! Take this as rounding inaccuracy
+ \c@pgf@counta=#1\relax
+ \advance\c@pgf@counta by1
+ \edef\pgfplotscolormapfind@intervalno{\the\c@pgf@counta}%
+ \else
+ \def\pgfplotscolormapfind@intervalno{#1}%
+ \fi
+}%
+
+\def\pgfplotscolormap@floor@unforgiving#1.#2\relax{%
+ \def\pgfplotscolormapfind@intervalno{#1}%
+}%
% Performs a direct color access into color map '#2' using an index
% '#1'.
@@ -1189,8 +2423,10 @@
\def\pgfplotscolormapgetindex#1#2{%
\pgfplotscolormapassertexists{#2}%
\begingroup
- \afterassignment\pgfplots@gobble@until@relax
- \c@pgf@counta=#1\relax
+ \pgfmathfloatparsenumber{#1}%
+ \expandafter\pgfmathfloattoint\expandafter{\pgfmathresult}%
+ %\afterassignment\pgfplots@gobble@until@relax
+ \c@pgf@counta=\pgfmathresult\relax
\ifnum\c@pgf@counta<0
\c@pgf@counta=0
\else
@@ -1231,7 +2467,6 @@
\fi
}%
-
\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)}