diff options
author | Karl Berry <karl@freefriends.org> | 2016-01-08 00:02:17 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2016-01-08 00:02:17 +0000 |
commit | 4e668f51370a93cc9dc26b1a11a949b50493b353 (patch) | |
tree | 85ab6891036f9a348e68f83e31c56b069332a9ca /Master/texmf-dist/tex/generic/pgfplots/util | |
parent | f2995718d3db02b5ff46d4552b9281b9761327ae (diff) |
pgfplots (7jan16)
git-svn-id: svn://tug.org/texlive/trunk@39303 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/generic/pgfplots/util')
-rw-r--r-- | Master/texmf-dist/tex/generic/pgfplots/util/pgfplotscolormap.code.tex | 527 | ||||
-rw-r--r-- | Master/texmf-dist/tex/generic/pgfplots/util/pgfplotsutil.code.tex | 130 |
2 files changed, 579 insertions, 78 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 c80b2c7b848..fe79bad2665 100644 --- a/Master/texmf-dist/tex/generic/pgfplots/util/pgfplotscolormap.code.tex +++ b/Master/texmf-dist/tex/generic/pgfplots/util/pgfplotscolormap.code.tex @@ -84,6 +84,9 @@ \endpgfplotscolornormalizesequence% \expandafter\let\csname\pgfplots@createcolormap@name @colspace\endcsname=\pgfplotsretval \expandafter\let\csname\pgfplots@createcolormap@name @col@comps\endcsname=\pgfplotsretvalb + \c@pgf@counta=\expandafter\pgfplotsarraysizeof\expandafter{\pgfplots@createcolormap@name}\relax + \advance\c@pgf@counta by-1 % + \expandafter\edef\csname\pgfplots@createcolormap@name @lastindex\endcsname{\the\c@pgf@counta}% %\pgfplots@colormap@showdebuginfofor{#1}% \pgfplots@colormap@LUA@new{#1}% } @@ -184,18 +187,142 @@ \pgfplots@createcolormap@grabnext@complete }% +%%%%%%%%%% + +% defines \pgfplotsretval to contain the argument and \pgfplotsretvalb +% to contain the colormap name. +\def\pgfplots@createcolormap@special@split#1{% + \pgfutil@in@{of }{#1}% + \ifpgfutil@in@ + \pgfplots@createcolormap@special@split@#1\pgfplots@EOI + \else + \pgfkeys@spdef\pgfplotsretval{#1}% + \pgfkeysgetvalue{/pgfplots/colormap name}\pgfplotsretvalb + \fi + \pgfplots@createcolormap@special@ensure@source@cm{\pgfplotsretvalb}% +}% +\def\pgfplots@createcolormap@special@split@#1of #2\pgfplots@EOI{% + \pgfkeys@spdef\pgfplotsretval{#1}% + \pgfkeys@spdef\pgfplotsretvalb{#2}% +} +\def\pgfplots@createcolormap@special@ensure@source@cm#1{% + \pgfplotscolormapifdefined{#1}{% + }{% + \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}% +} +\expandafter\def\csname pgfplots@createcolormap@grabnextspecial@samples of colormap\endcsname#1#2{% + \pgfplots@createcolormap@special@split{#2}% + \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)}% + \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}% + \edef\pgfplotsretval{% + \csname pgfpl@cm@\pgfplots@color@of@colormap@name @colspace\endcsname(#1)=(\pgfmathresult)% + }% + \pgfmath@smuggleone\pgfplotsretval + \endgroup +} +\expandafter\def\csname pgfplots@createcolormap@grabnextspecial@index of colormap\endcsname#1#2{% + \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 + \endgroup +} +\def\pgfplots@createcolormap@special@process#1#2{% + \begingroup + \let\pgfplots@source=\pgfplotsretval + \let\pgfplots@sourcecm=\pgfplotsretvalb + \def\pgfplots@temp@pos{(#1)}% + % + \pgfplotsapplistXnewempty\pgfplots@createcolormap@special@process@result + \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) }% + % + \expandafter\pgfplotsapplistXpushback\currentValue\to\pgfplots@createcolormap@special@process@result + % + % all following ones receive auto-positions: + \let\pgfplots@temp@pos=\pgfutil@empty + }% + \pgfplotsapplistXlet\pgfplotsretval=\pgfplots@createcolormap@special@process@result + \global\let\pgfplots@glob@TMPa=\pgfplotsretval + \endgroup + \let\pgfplotsretval=\pgfplots@glob@TMPa +}% +%%%%%%%%%% + \def\pgfplots@createcolormap@grabnext@complete{% - \edef\pgfplots@loc@TMPa{% - {\pgfplots@loc@TMPb}% position - {% - \pgfplots@loc@TMPa% colorspace - =\pgfplots@loc@TMPc% color data + \pgfutil@IfUndefined{pgfplots@createcolormap@grabnextspecial@\pgfplots@loc@TMPa}{% + % ok, this is a 'normal' color specification with position, + % colorspace, and color data. + % + \edef\pgfplots@loc@TMPa{% + {\pgfplots@loc@TMPb}% position + {% + \pgfplots@loc@TMPa% colorspace + =\pgfplots@loc@TMPc% color data + }% + }% + \expandafter\pgfplots@createcolormap@nextcolor\pgfplots@loc@TMPa + % + % 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 }% }% - \expandafter\pgfplots@createcolormap@nextcolor\pgfplots@loc@TMPa + % % % continue loop: - \pgfplots@createcolormap@ + \pgfplots@loc@TMPd }% \def\pgfplots@createcolormap@grabnext@computenextposition{% @@ -375,13 +502,117 @@ \begingroup \c@pgf@counta=0 \pgfplotsarrayforeachungrouped{pgfpl@cm@#1}\as\elem{% - \message{\#\the\c@pgf@counta: \elem; }% - \advance\c@pgf@counta by1 + \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 % }% \message{^^J}% \endgroup } +% #1: comma-separated list of values for the current entry +% #2: color map name +% #3: the current index into the colormap +% #4: the "x coordinate", i.e. the offset within the colormap +% +% Defines \pgfplotsretval +% +% Example: +% \pgfplotscolormaptodatafile[ +% output each nth=1, +% output format=csv, +% ]{viridis} +% {viridis.dat} +\def\pgfplotscolormaptodatafile@elem#1#2#3#4{ + \let\pgfplotsretval=\pgfutil@empty +}% + +\begingroup +\catcode`\[=1 +\catcode`\]=2 +\catcode`\{=12 +\catcode`\}=12 +\xdef\pgfplots@lbrace[{]% +\xdef\pgfplots@rbrace[}]% +\endgroup + + +\pgfkeys{ + /pgfplots/colormap/output each nth/.initial=1, + /pgfplots/colormap/output format/.is choice, + /pgfplots/colormap/output format/csv/.code={% + \def\pgfplotscolormaptodatafile@head##1{% + \let\pgfplotsretval=\pgfutil@empty + }% + \def\pgfplotscolormaptodatafile@elem##1##2##3##4{% + \edef\pgfplotsretval{##4,##1}% + }% + \def\pgfplotscolormaptodatafile@foot##1{% + \let\pgfplotsretval=\pgfutil@empty + }% + }, + /pgfplots/colormap/output format/native/.code={% + \def\pgfplotscolormaptodatafile@head##1{% + \edef\pgfplotsretval{\string\pgfplotsset\pgfplots@lbrace colormap={##1}\pgfplots@lbrace}% + }% + \def\pgfplotscolormaptodatafile@elem##1##2##3##4{% + \edef\pgfplotsretval{\csname pgfpl@cm@##2@colspace\endcsname=(##1)}% + }% + \def\pgfplotscolormaptodatafile@foot##1{% + \edef\pgfplotsretval{\pgfplots@rbrace\pgfplots@rbrace}% + }% + }, + /pgfplots/colormap/output format=csv, +} + + +% An export of a color map. +% #1: options. Can use 'output each nth=2' and 'output format=csv|native' +% #2: a color map +% #3: a data file +\def\pgfplotscolormaptodatafile{\pgfutil@ifnextchar[{\pgfplotscolormaptodatafile@}{\pgfplotscolormaptodatafile@[]}}% +\def\pgfplotscolormaptodatafile@[#1]#2#3{% + \begingroup + \pgfqkeys{/pgfplots/colormap}{#1}% + \pgfkeysgetvalue{/pgfplots/colormap/output each nth}{\pgfplots@eachnth}% + \immediate\openout\w@pgf@writea=#3\relax + \pgfplotscolormaptodatafile@head{#2}% + \ifx\pgfplotsretval\pgfutil@empty + \else + \immediate\write\w@pgf@writea{% + \pgfplotsretval + }% + \fi + \gdef\pgfplots@eachnth@cur{0}% + \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}% + \edef\pgfplots@loc@TMPa{{\elem}{#2}{\pgfplotsarrayforeachindex}{\pgfmathresult}}% + \expandafter\pgfplotscolormaptodatafile@elem\pgfplots@loc@TMPa + \ifx\pgfplotsretval\pgfutil@empty + \else + \immediate\write\w@pgf@writea{% + \pgfplotsretval + }% + \fi + \fi + \pgfplotsutil@advancestringcounter@global\pgfplots@eachnth@cur% + \ifnum\pgfplots@eachnth@cur=\pgfplots@eachnth\relax + \gdef\pgfplots@eachnth@cur{0}% + \fi + }% + \pgfplotscolormaptodatafile@foot{#2}% + \ifx\pgfplotsretval\pgfutil@empty + \else + \immediate\write\w@pgf@writea{% + \pgfplotsretval + }% + \fi + \immediate\closeout\w@pgf@writea + \endgroup +} + % Defines \pgfplotsretval to contain the mesh width of colormap #1 \def\pgfplotscolormapgetmeshwidth#1{% \expandafter\let\expandafter\pgfplotsretval\csname pgfpl@cm@#1@h\endcsname% @@ -419,6 +650,7 @@ \toks3=\expandafter{\pgfplots@serialize@list}% \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}% \xdef\pgfplots@glob@TMPa{% \the\toks0 {\csname pgfpl@cm@#1@h\endcsname}% \the\toks1 {\csname pgfpl@cm@#1@invh\endcsname}% @@ -426,6 +658,7 @@ \the\toks2 \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}% }% \endgroup \let#2=\pgfplots@glob@TMPa @@ -434,32 +667,96 @@ % 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}% +\def\pgfplotscolormappdfmax{1}% FIXME : why? 1000 would be more precise...? + +% Expands to the size of colormap #1 . +\def\pgfplotscolormapsizeof#1{% + \pgfplotscolormapifdefined{#1}{% + \pgfplotsarraysizeof{pgfpl@cm@#1}% + }{% + 0% + }% +}% + +% Expands to the last index of colormap #1 (or -1) +\def\pgfplotscolormaplastindexof#1{% + \pgfplotscolormapifdefined{#1}{% + \csname pgfpl@cm@#1@lastindex\endcsname% + }{% + -1% + }% +}% % Writes a PDF function of /FunctionType 3 to \pgfplotsretval % % The /Domain argument will be set to [ 0 \pgfplotscolormappdfmax ] and bounds will be % computed accordingly. % +% Note that the value depends on 'colormap access' +% % #1: the colormap \def\pgfplotscolormaptopdffunction#1{% \begingroup - \gdef\pgfplotsretval{% + \pgfplotscolormapassertexists{#1}% + \pgfplotsapplistXnewempty\pgfplots@resultaccum + \pgfplotsapplistXpushback{ << /FunctionType 3 /Domain [0 \pgfplotscolormappdfmax] - % /Range [0 1 0 1 0 1] % INCOMPATIBLE WITH ACROBAT 6.0 ! /Functions [ - }% + }\to\pgfplots@resultaccum% \c@pgf@counta=0 \c@pgf@countb=\pgfplotsarraysizeof{pgfpl@cm@#1} % \advance\c@pgf@countb by-1 \def\pgfplots@loc@TMPa{}% - \def\pgfplots@loc@TMPb{}% - \def\pgfplots@loc@TMPc{}% + \pgfplotsapplistXnewempty\pgfplots@bounds@accum% + \pgfplotsapplistXnewempty\pgfplots@encode@accum \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 + % + \if m\pgfplots@colormap@access + % colormap access=map + \def\pgfplots@order{1}% + \global\pgf@x=\csname pgfpl@cm@#1@h\endcsname pt % + \def\pgfplots@C@left{C0}% + \def\pgfplots@C@right{C1}% + \else + \if c\pgfplots@colormap@access + % colormap access=piecewise constant + % This has a dedicated special interval at the rightmost + % end. + % 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 + % + % interchange the sequence in the PDF function as it is + % defined as + % y = C0 + x^0 * (C1 - C0) = C1 + % -> we want the left interval boundary. + \def\pgfplots@C@left{C1}% + \def\pgfplots@C@right{C0}% + \else + % colormap access=direct + \pgfplots@error{This should never happen}% + % ? + \def\pgfplots@order{0}% + \global\pgf@x=\csname pgfpl@cm@#1@h\endcsname pt % + \def\pgfplots@C@left{C0}% + \def\pgfplots@C@right{C1}% + \fi + \fi + % \pgfplotsarrayforeachungrouped{pgfpl@cm@#1}\as\cdata{% \edef\cdata{% \expandafter @@ -468,35 +765,61 @@ \cdata\relax }% \ifnum\c@pgf@counta>0 - \t@pgfplots@toka=\expandafter{\pgfplotsretval}% - \xdef\pgfplotsretval{% - \the\t@pgfplots@toka + \edef\pgfplots@loc@TMPd{% << /FunctionType 2 /Domain [0 \pgfplotscolormappdfmax] - /C0 [\pgfplots@loc@TMPa] /C1 [\cdata] /N 1 + /\pgfplots@C@left\space [\pgfplots@loc@TMPa] /\pgfplots@C@right\space [\cdata] + /N \pgfplots@order >> }% + \expandafter\pgfplotsapplistXpushback\expandafter{\pgfplots@loc@TMPd}\to\pgfplots@resultaccum \ifnum\c@pgf@counta<\c@pgf@countb\relax - \pgf@xa=\csname pgfpl@cm@#1@h\endcsname pt + \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 - \edef\pgfplots@loc@TMPb{\pgfplots@loc@TMPb\space \pgf@sys@tonumber\pgf@xa}% + \divide\pgf@xa by1000 % 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 - \edef\pgfplots@loc@TMPc{\pgfplots@loc@TMPc\space 0 1}% + \pgfplotsapplistXpushback{ 0 1}\to\pgfplots@encode@accum% \fi \let\pgfplots@loc@TMPa=\cdata \advance\c@pgf@counta by1 }% + \if 0\pgfplots@order + % add an artificial interval. + \edef\pgfplots@loc@TMPd{% + << + /FunctionType 2 + /Domain [0 \pgfplotscolormappdfmax] + /\pgfplots@C@left\space [\cdata] /\pgfplots@C@right\space [\cdata] + /N \pgfplots@order + >> + }% + \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!? + \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% + \fi + \pgfplotsapplistXlet\pgfplotsretval=\pgfplots@resultaccum + \pgfplotsapplistXlet\pgfplotsbounds=\pgfplots@bounds@accum + \pgfplotsapplistXlet\pgfplotsencode=\pgfplots@encode@accum \t@pgfplots@toka=\expandafter{\pgfplotsretval}% - \xdef\pgfplotsretval{% + \t@pgfplots@tokb=\expandafter{\pgfplotsbounds}% + \t@pgfplots@tokc=\expandafter{\pgfplotsencode}% + \xdef\pgfplots@glob@TMPa{% \the\t@pgfplots@toka ] - /Bounds [\pgfplots@loc@TMPb] - /Encode [\pgfplots@loc@TMPc] + /Bounds [\the\t@pgfplots@tokb] + /Encode [\the\t@pgfplots@tokc] >> }% \endgroup + \let\pgfplotsretval=\pgfplots@glob@TMPa }% \expandafter\def\csname pgfplotscolormaptopdffunction@convertcdata@1\endcsname#1\relax{#1}% \expandafter\def\csname pgfplotscolormaptopdffunction@convertcdata@2\endcsname#1,#2\relax{#1 #2}% @@ -594,6 +917,12 @@ \def\pgfplotscolormapgetcolorcomps#1{% \edef\pgfplotsretval{\csname pgfpl@cm@#1@col@comps\endcsname}% }% +\def\pgfplotscolormapcolorspaceof#1{% + \csname pgfpl@cm@#1@colspace\endcsname% +}% +\def\pgfplotscolormapcolorcompsof#1{% + \csname pgfpl@cm@#1@col@comps\endcsname% +}% % Linearly maps the number #4 into the colormap #5 and returns the @@ -645,9 +974,7 @@ \expandafter\gdef\csname pgfplotscolormapfind@precomputed@warn@LUA@#1\endcsname{1}% \fi }% -\def\pgfplotscolormapfind@precomputed@[#1:#2][#3]#4#5{% - \pgfplotscolormapassertexists{#5}% - \begingroup +\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}% @@ -677,24 +1004,34 @@ \def\pgfmathresult{1000}% \fi \fi +}% +\def\pgfplotscolormapfind@precomputed@[#1:#2][#3]#4#5{% + \pgfplotscolormapassertexists{#5}% + \begingroup + \pgfplotscolormapfind@@@[#1:#2][#3]{#4}{#5}% + % + % Now, we have it in [0,1000]. Find the correct interval: \let\pgfplotscolormapfind@transformedx=\pgfmathresult - \expandafter\pgfmathmultiply@\expandafter{\pgfmathresult}{\csname pgfpl@cm@#5@invh\endcsname}% + \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 - \pgfmathsubtract@{\pgfplotscolormapfind@transformedx@divh}{\pgfplotscolormapfind@intervalno}% - \let\pgfplots@loc@factor=\pgfmathresult - \pgfmathsubtract@{1}{\pgfplots@loc@factor}% - \let\pgfplots@loc@factor@two=\pgfmathresult % Step 2: interpolate the desired RGB value using vector valued % interpolation on the identified interval. \c@pgf@counta=\pgfplotscolormapfind@intervalno\relax %\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 + \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 @@ -731,6 +1068,115 @@ }% +% Maps the number #4 into the colormap #5 using piecewise constant +% interpolation. It returns the interpolated colors into \pgfmathresult. The result will be a triple +% for an RGB colormap and it will contain four numbers for CMYK. The +% components of the result will be in the range [0:1]. +% +% [#1:#2] the number range of the data source (i.e. of #4). This is required to +% map into the colormap. +% [#3] (optional) the quantity +% s := \pgfplotscolormaprange / (#2-#1). +% Precomputing this quantity may save a lot of time because +% divisions are expensive in TeX. You can omit [#3] or +% provide an empty string here. +% #4 the number to map. +% #5 the colormap's name. Must be defined with +% \pgfplotscreatecolormap before. +% +% Example: +% \pgfplotscolormapfindpiecewiseconst[-1:1]{0.2}{my colormap} +\def\pgfplotscolormapfindpiecewiseconst[#1:#2]{% + \pgfutil@ifnextchar[{% + \pgfplotscolormapfindpiecewiseconst@precomputed[#1:#2]% + }{% + \pgfplotscolormapfindpiecewiseconst@precomputed[#1:#2][]% + }% +}% +\def\pgfplotscolormapfindpiecewiseconst@precomputed[#1:#2][#3]#4#5{% + %\ifpgfplots@LUA@supported + \iffalse + % FIXME : implement + \edef\pgfmathresult{% + \pgfplotsutil@directlua{% + pgfplots.texColorMapPrecomputed("#5", #1,#2,#4) + }% + }% + \ifx\pgfmathresult\pgfutil@empty + \pgfplotscolormapfindpiecewiseconst@precomputed@warn@LUA{#5}% + \pgfplotscolormapfindpiecewiseconst@precomputed@[#1:#2][#3]{#4}{#5}% + \else + %\message{LUA colormapfindpiecewiseconst[#1:#2](#4)(#5) = \pgfmathresult^^J}% + \fi + \else + \pgfplotscolormapfindpiecewiseconst@precomputed@[#1:#2][#3]{#4}{#5}% + \fi +} + +\def\pgfplotscolormapfindpiecewiseconst@precomputed@warn@LUA#1{% + \expandafter\ifx\csname pgfplotscolormapfindpiecewiseconst@precomputed@warn@LUA@#1\endcsname\relax + \pgfplotswarning{lua colormap unavailable}{#1}\pgfeov% + \expandafter\gdef\csname pgfplotscolormapfindpiecewiseconst@precomputed@warn@LUA@#1\endcsname{1}% + \fi +}% + +\def\pgfplotscolormapfindpiecewiseconst@precomputed@[#1:#2][#3]#4#5{% + \pgfplotscolormapassertexists{#5}% + \begingroup + \pgfplotscolormapfind@@@[#1:#2][#3]{#4}{#5}% + \let\pgfplotscolormapfind@transformedx=\pgfmathresult + % + % Now, we have it in [0,1000]. Find the correct interval: + % In principle, we could easily find the correct interval. But the + % native approach has one distinct disadvantage: we will never + % assign the rightmost color unless #4=1000! That means that our + % colormap is not used entirely. + % + % I decided to enlarge the colormap artificially such that the + % rightmost color receives its own interval. + % + % To this end, I recompute the coordinates at which colors "live". + % The operations sounds more involved than it is: I simply need a NEW mesh width locally + % inside of this function. The new mesh width H can be computed as + % follows, assuming that the OLD colormap has mesh width h. + % + % H := 1000/ (N-1) + % + % N := n+1 + % n := 1000/h + 1 = \pgfplotscolormapsizeof{#5} + % + % 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 + % + \ifnum\c@pgf@counta=\pgfplotscolormapsizeof{#5}\relax + % we have artificially increased the "h" (see the comments + % above) -- meaning that this 'if' can happen. + % ->Map the rightmost point to the rightmost interval: + \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}% + \pgfplotsarrayselect\c@pgf@counta\of{pgfpl@cm@#5}\to\pgfplotscolormapfind@rgb@LEFT + \let\pgfmathresult=\pgfplotscolormapfind@rgb@LEFT + \pgfmath@smuggleone\pgfmathresult + \endgroup +}% + + % Performs a direct color access into color map '#2' using an index % '#1'. % @@ -760,7 +1206,8 @@ \endgroup } -% Invokes either \pgfplotscolormapfind or \pgfplotscolormapgetindex, +% Invokes one of \pgfplotscolormapfind, +% \pgfplotscolormapfindpiecewiseconst, or \pgfplotscolormapgetindex, % depending on the value of '/pgfplots/colormap access'. \def\pgfplotscolormapaccess[#1:#2]{% \pgfutil@ifnextchar[{% @@ -771,9 +1218,16 @@ } \def\pgfplotscolormapaccess@precomputed[#1:#2][#3]#4#5{% \if m\pgfplots@colormap@access + % colormap access=map \pgfplotscolormapfind@precomputed[#1:#2][#3]{#4}{#5}% \else - \pgfplotscolormapgetindex{#4}{#5}% + \if c\pgfplots@colormap@access + % colormap access=piecewise constant + \pgfplotscolormapfindpiecewiseconst@precomputed[#1:#2][#3]{#4}{#5}% + \else + % colormap access=direct + \pgfplotscolormapgetindex{#4}{#5}% + \fi \fi }% @@ -782,6 +1236,7 @@ % 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 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 8af2ed312c6..ad8f8bd36a9 100644 --- a/Master/texmf-dist/tex/generic/pgfplots/util/pgfplotsutil.code.tex +++ b/Master/texmf-dist/tex/generic/pgfplots/util/pgfplotsutil.code.tex @@ -1,3 +1,6 @@ +% +% +% %-------------------------------------------- % % Package pgfplots @@ -522,7 +525,9 @@ % % This is the (accidentally) the same as \pgfplotsforeachentryinCSV. \long\def\pgfplotsutilforeachcommasep#1\as#2#3{% - \pgfplotsforeachentryinCSVisterminated@loop{#2}{#3}#1,\pgfplots@EOI + \pgfplots@for@reset@break{% + \pgfplotsforeachentryinCSVisterminated@loop{#2}{#3}#1,\pgfplots@EOI + }% }% % Usage: @@ -538,7 +543,9 @@ % @see \pgfplotsforeachungrouped % This loop can be nested. \long\def\pgfplotsforeachentryinCSV#1#2#3{% - \pgfplotsforeachentryinCSVisterminated@loop{#1}{#3}#2,\pgfplots@EOI + \pgfplots@for@reset@break{% + \pgfplotsforeachentryinCSVisterminated@loop{#1}{#3}#2,\pgfplots@EOI + }% }% % A variant of \pgfplotsforeachentryinCSV where a trailing comma % indicates the end of input. @@ -551,7 +558,9 @@ % % This loop can be nested. \long\def\pgfplotsforeachentryinCSVisterminated#1#2#3{% - \pgfplotsforeachentryinCSVisterminated@loop{#1}{#3}#2\pgfplots@EOI + \pgfplots@for@reset@break{% + \pgfplotsforeachentryinCSVisterminated@loop{#1}{#3}#2\pgfplots@EOI + }% }% % #1 : the loop macro % #2 : the loop BODY @@ -567,7 +576,12 @@ \long\def\pgfplotsforeachentryinCSV@next#1#2#3,{% \def#1{#3}% #2\relax - \pgfplotsforeachentryinCSVisterminated@loop{#1}{#2}% + \ifpgffor@continue + \expandafter\pgfplotsforeachentryinCSVisterminated@loop + \else + \expandafter\pgfplots@gobble@until@EOI + \fi + {#1}{#2}% }% @@ -606,22 +620,38 @@ \pgfplots@error{Found unexpected characters: expected 'in '.}% }% } + +\long\def\pgfplots@for@reset@break#1{% + \ifpgffor@continue + \pgffor@continuetrue + #1\relax + \pgffor@continuetrue + \else + \pgffor@continuetrue + #1\relax + \pgffor@continuefalse + \fi +}% + \long\def\pgfplotsforeachungrouped@@#1#2#3#4{% - \def\pgfplots@foreach@loc@TMPa{#2}% - \ifx\pgfplots@foreach@loc@TMPa\pgfutil@empty - \pgfplotsforeachungrouped@isuniform{#3}% - \ifpgfplots@loc@tmp - % special handling: - % \foreach #1 in {a,b,...,c} can be improved: - \pgfplotsforeachungroupeduniform@{#1}#3\relax{#4}% + \pgfplots@for@reset@break{% + % + \def\pgfplots@foreach@loc@TMPa{#2}% + \ifx\pgfplots@foreach@loc@TMPa\pgfutil@empty + \pgfplotsforeachungrouped@isuniform{#3}% + \ifpgfplots@loc@tmp + % special handling: + % \foreach #1 in {a,b,...,c} can be improved: + \pgfplotsforeachungroupeduniform@{#1}#3\relax{#4}% + \else + % invoke \foreach #1 in {#3} and transport results: + \pgfplotsforeachungroupednonuniform@#1{#3}{#4}% + \fi \else - % invoke \foreach #1 in {#3} and transport results: - \pgfplotsforeachungroupednonuniform@#1{#3}{#4}% + % invoke \foreach #1/#2 in {#3} and transport results: + \pgfplotsforeachungroupedslashed@#1/#2{#3}{#4}% \fi - \else - % invoke \foreach #1/#2 in {#3} and transport results: - \pgfplotsforeachungroupedslashed@#1/#2{#3}{#4}% - \fi + }% } \let\pgfplots@original@pgfmathadd@=\pgfmathadd@ @@ -667,10 +697,21 @@ % This here is much more accurate and does not suffer from the % numerical stability issues of the other loop. % -% TO DO: test it (optimize it?) and enable it for some future compat=<version> -% switch! -\long\def\pgfplotsforeachungroupeduniform@loop@mathengine@PRECISE@CURRENTLY@UNUSED@#1#2#3#4#5#6#7{% - \pgfmathparse{#2+#7*#5}% is this significantly slower than the direct calls? +% #1: comparison fct +% #2: lower limit +% #3: upper limit +% #4: the loop macro name +% #5: h +% #6: code to invoke +% #7: the loop variable (number samples) +\long\def\pgfplotsforeachungroupeduniform@loop@mathengine@precise#1#2#3#4#5#6#7{% + \pgflibraryfpuifactive{% + \pgfmathfloatparsenumber{#7}% + }{% + \edef\pgfmathresult{#7}% + }% + \expandafter\pgfmathmultiply@\expandafter{\pgfmathresult}{#5}% + \expandafter\pgfmathadd@\expandafter{\pgfmathresult}{#2}% \let#4=\pgfmathresult #1{#4}{#3}% substitute this by integer arithmetics \ifdim\pgfmathresult pt=0pt % @@ -695,32 +736,37 @@ \expandafter\pgfplots@loc@TMPa \fi }% -\long\def\pgfplotsforeachungroupeduniform@loop@mathengine#1#2#3#4#5#6#7{% +\long\def\pgfplotsforeachungroupeduniform@loop@mathengine@legacy#1#2#3#4#5#6#7{% #1{#2}{#3}% - \ifdim\pgfmathresult pt=0pt - \pgfutil@in@{.0\relax}{#2\relax}% - \ifpgfutil@in@ - \def\pgfplotsforeach@loc@TMP##1.0\relax{% - \def#4{##1}% - }% - \pgfplotsforeach@loc@TMP#2\relax - \else - \def#4{#2}% + \ifpgffor@continue + \ifdim\pgfmathresult pt=0pt + \pgfutil@in@{.0\relax}{#2\relax}% + \ifpgfutil@in@ + \def\pgfplotsforeach@loc@TMP##1.0\relax{% + \def#4{##1}% + }% + \pgfplotsforeach@loc@TMP#2\relax + \else + \def#4{#2}% + \fi + #6\relax + \pgfmathadd@{#2}{#5}% + \t@pgfplots@toka={{#1}}% + \t@pgfplots@tokb=\expandafter{\pgfmathresult}% + \t@pgfplots@tokc={{#3}{#4}{#5}{#6}{--}}% + % loop! + \edef\pgfplots@loc@TMPa{\noexpand\pgfplotsforeachungroupeduniform@loop@mathengine + \the\t@pgfplots@toka + {\the\t@pgfplots@tokb}% + \the\t@pgfplots@tokc}% + \expandafter\expandafter\expandafter\pgfplots@loc@TMPa \fi - #6\relax - \pgfmathadd@{#2}{#5}% - \t@pgfplots@toka={{#1}}% - \t@pgfplots@tokb=\expandafter{\pgfmathresult}% - \t@pgfplots@tokc={{#3}{#4}{#5}{#6}{--}}% - % loop! - \edef\pgfplots@loc@TMPa{\noexpand\pgfplotsforeachungroupeduniform@loop@mathengine - \the\t@pgfplots@toka - {\the\t@pgfplots@tokb}% - \the\t@pgfplots@tokc}% - \expandafter\pgfplots@loc@TMPa \fi }% +\let\pgfplotsforeachungroupeduniform@loop@mathengine=\pgfplotsforeachungroupeduniform@loop@mathengine@legacy + + \long\def\pgfplotsforeachungroupednonuniform@#1#2#3{% \pgfplotsapplistXXglobalnewempty \foreach\pgfplots@foreach@loc@TMPa in {#2} {% |