Debian Codegraph @

texmf-dist/tex/generic/pgfplots/libs/tikzlibrarypgfplots.dateplot.code.tex

raw
1 %--------------------------------------------
2 %
3 % Package pgfplots, library for high-level coordinates.
4 %
5 % Copyright 2007/2008/2009 by Christian Feuersänger.
6 %
7 % This program is free software: you can redistribute it and/or modify
8 % it under the terms of the GNU General Public License as published by
9 % the Free Software Foundation, either version 3 of the License, or
10 % (at your option) any later version.
11 %
12 % This program is distributed in the hope that it will be useful,
13 % but WITHOUT ANY WARRANTY; without even the implied warranty of
14 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 % GNU General Public License for more details.
16 %
17 % You should have received a copy of the GNU General Public License
18 % along with this program. If not, see <http://www.gnu.org/licenses/>.
19 %
20 %--------------------------------------------
21
22 \pgfutil@usemodule{pgfcalendar}
23
24 % Idea: allow
25 %--------------------------------------------------
26 % \begin{tikzpicture}
27 % \begin{axis}[
28 % date coordinates in=x,
29 % xticklabel={\day.\month.},
30 % ]
31 % \addplot coordinates {
32 % (2008-01-5, 5)
33 % (2008-01-12, 10)
34 % (2008-01-16, 20)
35 % };
36 % \end{axis}
37 % \end{tikzpicture}
38 %--------------------------------------------------
39
40 \def\pgfplotslibdateplot@number@to@julian@and@time#1.#2\julianto#3\hourto#4\minuteto#5{%
41 #3=#1
42 \pgf@xa=0.#2pt
43 \multiply\pgf@xa by24
44 \afterassignment\pgfplots@gobble@until@relax
45 \c@pgf@countb=\the\pgf@xa\relax
46 \edef#4{\the\c@pgf@countb}%
47 \advance\pgf@xa by-#4pt
48 \multiply\pgf@xa by60
49 \afterassignment\pgfplots@gobble@until@relax
50 \c@pgf@countb=\the\pgf@xa\relax
51 % round minutes (we may loose precision here)
52 \advance\pgf@xa by-\the\c@pgf@countb pt
53 \ifdim\pgf@xa>0.5pt
54 \advance\c@pgf@countb by1
55 \ifnum\c@pgf@countb=60
56 \c@pgf@countb=#4 %
57 \advance\c@pgf@countb by1
58 \edef#4{\the\c@pgf@countb}%
59 \c@pgf@countb=0
60 \fi
61 \fi
62 \edef#5{\the\c@pgf@countb}%
63 }
64
65 % #1 the date
66 % #2 the hours
67 % #3 the minutes
68 % #4 is either empty or is the seconds.
69 % #5 a macro which will be filled with the date part.
70 % #6 the macro which will contain a number in the range [0,1]
71 % representing hours and minutes.
72 %
73 % If you don't have seconds, you have to provide the second ':' sign
74 % as dummy! In that case #4 will be empty.
75 \def\pgfplotslibdateplot@map@time#1 #2:#3:#4\dateto#5\timeto#6{%
76 \pgf@xa=#2pt
77 \divide\pgf@xa by24
78 \pgf@xb=#3pt
79 \divide\pgf@xb by1440
80 \advance\pgf@xa by\pgf@xb
81 \ifdim\pgf@xa<0pt
82 \pgf@xa=0pt
83 \else
84 \ifdim\pgf@xa>1pt
85 \pgf@xa=1pt
86 \fi
87 \fi
88 \def#5{#1}%
89 \edef#6{\pgf@sys@tonumber\pgf@xa}%
90 }%
91 \def\pgfplotslibdateplot@discard@zero@dot 0.#1\to#2{\def#2{#1}}%
92
93 %--------------------------------------------------
94 %This here extends it to SECONDS, but the precision is too low
95 % \def\pgfplotslibdateplot@map@time#1 #2:#3:#4\dateto#5\timeto#6{%
96 % \pgf@xa=#2pt
97 % \divide\pgf@xa by24
98 % %
99 % \pgf@xb=#3pt
100 % \divide\pgf@xb by1440
101 % \advance\pgf@xa by\pgf@xb
102 % %
103 % \def\pgfplots@loc@TMPc{#4}%
104 % \ifx\pgfplots@loc@TMPc\pgfutil@empty
105 % \else
106 % \edef\pgfplots@loc@TMPc{\pgfplotslibdateplot@discard@trailing@colon #4}%
107 % \pgf@xb=\pgfplots@loc@TMPc pt
108 % \divide\pgf@xb by1440
109 % \divide\pgf@xb by60
110 % \advance\pgf@xa by\pgf@xb
111 % \fi
112 % %
113 % \ifdim\pgf@xa<0pt
114 % \pgf@xa=0pt
115 % \else
116 % \ifdim\pgf@xa>1pt
117 % \pgf@xa=1pt
118 % \fi
119 % \fi
120 % \def#5{#1}%
121 % \edef#6{\pgf@sys@tonumber\pgf@xa}%
122 % }%
123 % \def\pgfplotslibdateplot@discard@trailing@colon#1:{#1}%
124 %--------------------------------------------------
125
126 \let\pgfplots@calender@ZEROSHIFT=\pgfutil@empty
127 \def\pgfplots@dateplot@ensure@ZEROSHIFT#1{%
128 \ifx\pgfplots@calender@ZEROSHIFT\pgfutil@empty
129 \ifx\pgfplots@global@dateplot@defaultshift\pgfutil@empty
130 \pgfplots@log4{dateplot: setting 'date ZERO={#1}' for this axis.}%
131 \pgfplots@dateplot@parse@ZEROSHIFT{#1}%
132 \global\let\pgfplots@global@dateplot@defaultshift=\pgfmathresult
133 \fi
134 %
135 \let\pgfplots@calender@ZEROSHIFT=\pgfplots@global@dateplot@defaultshift
136 \fi
137 }%
138 % defines \pgfplots@calender@ZEROSHIFT to be the zero shift
139 \def\pgfplots@dateplot@get@ZEROSHIFT{%
140 \ifx\pgfplots@calender@ZEROSHIFT\pgfutil@empty
141 \ifx\pgfplots@global@dateplot@defaultshift\pgfutil@empty
142 % should never happen
143 \pgfplots@error{Illegal internal state: no 'date ZERO' value found}%
144 \def\pgfplots@calender@ZEROSHIFT{0}%
145 \else
146 \let\pgfplots@calender@ZEROSHIFT=\pgfplots@global@dateplot@defaultshift
147 \fi
148 \fi
149 }%
150
151 \def\pgfplots@dateplot@parse@ZEROSHIFT#1{%
152 \begingroup
153 \pgfcalendardatetojulian{#1}\c@pgf@counta
154 \edef\pgfmathresult{\the\c@pgf@counta}%
155 \pgfmath@smuggleone\pgfmathresult
156 \endgroup
157 }%
158
159 \expandafter\def\expandafter\pgfplots@notify@options@are@set\expandafter{\pgfplots@notify@options@are@set
160 \global\let\pgfplots@global@dateplot@defaultshift=\pgfutil@empty
161 }
162
163 \pgfplotsset{
164 /pgfplots/date ZERO/.code={%
165 \pgfplots@dateplot@parse@ZEROSHIFT{#1}%
166 \let\pgfplots@calender@ZEROSHIFT=\pgfmathresult
167 },
168 /pgfplots/date coordinates in/.code={%
169 \pgfkeysdef{/pgfplots/#1 coord trafo}{%
170 \begingroup
171 \edef\pgfplotstempjuliandate{##1}%
172 % check if we also have a TIME like '2006-01-01 11:21'
173 \expandafter\pgfutil@in@\expandafter:\expandafter{\pgfplotstempjuliandate}%
174 \ifpgfutil@in@
175 % we have a TIME!
176 \expandafter\pgfplotslibdateplot@map@time\pgfplotstempjuliandate:\dateto\pgfplotstempjuliandate\timeto\pgfplotstemptime
177 \else
178 \let\pgfplotstemptime=\pgfutil@empty
179 \fi
180 %
181 \expandafter\pgfplots@dateplot@ensure@ZEROSHIFT\expandafter{\pgfplotstempjuliandate}%
182 %
183 \expandafter\pgfcalendardatetojulian\expandafter{\pgfplotstempjuliandate}\c@pgf@counta
184 \advance\c@pgf@counta by-\pgfplots@calender@ZEROSHIFT\relax
185 \ifx\pgfplotstemptime\pgfutil@empty
186 % no time:
187 \edef\pgfmathresult{\the\c@pgf@counta}%
188 \else
189 % add time fraction (which should be in the range
190 % [0,1]).
191 \ifdim\pgfplotstemptime pt<1pt
192 % discard prefix '0.':
193 \expandafter\pgfplotslibdateplot@discard@zero@dot\pgfplotstemptime\to\pgfplotstemptime
194 \edef\pgfmathresult{\the\c@pgf@counta.\pgfplotstemptime}%
195 \else
196 % assume \pgfplotstemptime=1pt :
197 \advance\c@pgf@counta by1
198 \edef\pgfmathresult{\the\c@pgf@counta}%
199 \fi
200 \fi
201 \pgfmath@smuggleone\pgfmathresult
202 \endgroup
203 }%
204 \pgfkeysdef{/pgfplots/#1 coord inv trafo}{%
205 \edef\pgfplotstempjuliandatenumeric{##1}%
206 \begingroup
207 \pgfplots@dateplot@get@ZEROSHIFT
208 %
209 \expandafter\pgfplotslibdateplot@number@to@julian@and@time\pgfplotstempjuliandatenumeric\julianto{\c@pgf@counta}\hourto\Hour\minuteto\Minute%
210 \advance\c@pgf@counta by\pgfplots@calender@ZEROSHIFT\relax
211 \expandafter\pgfcalendarjuliantodate\expandafter{\the\c@pgf@counta}\year\month\day
212 \xdef\pgfplotslibdateplot@TMP{%
213 \noexpand\def\noexpand\year{\year}%
214 \noexpand\def\noexpand\month{\month}%
215 \noexpand\def\noexpand\day{\day}%
216 \noexpand\def\noexpand\Hour{\Hour}%
217 \noexpand\def\noexpand\Minute{\Minute}%
218 }%
219 \endgroup
220 \pgfplotslibdateplot@TMP
221 \let\hour=\Hour
222 \let\minute=\Minute
223 \ifnum\hour<10
224 \edef\hour{0\hour}%
225 \fi
226 \ifnum\minute<10
227 \edef\minute{0\minute}%
228 \fi
229 \def\Second{0}%
230 \def\second{00}%
231 \edef\lowlevel{##1}%
232 \pgfkeysifdefined{/pgfplots/date default inv/#1}{%
233 \edef\pgfmathresult{\pgfkeysvalueof{/pgfplots/date default inv/#1}}%
234 }{%
235 \edef\pgfmathresult{\year-\month-\day\space\hour:\minute:\second}%
236 }%
237 }%
238 \pgfkeysifdefined{/pgfplots/#1ticklabel/.@cmd}{%
239 \pgfkeysalso{%
240 /pgfplots/#1ticklabel={\tick},%
241 /pgfplots/scaled #1 ticks=false,%
242 /pgfplots/plot coordinates/math parser=false,%
243 }%
244 }{%
245 % OK. The style can be used for other coordinates as well
246 % (like hist/data)
247 }%
248 %
249 \pgfkeysifdefined{/pgfplots/#1 is expr}{%
250 \pgfkeyssetvalue{/pgfplots/#1 is expr}{0}%
251 }{}%
252 %
253 % Allow a callback (optional)
254 \pgfkeysifdefined{/pgfplots/#1/@execute on coord trafo changed/.@cmd}{%
255 \pgfkeysalso {/pgfplots/#1/@execute on coord trafo changed}%
256 }{}%
257 },
258 /pgfplots/date coordinates in/.value required,
259 %
260 % #1: the argument for 'data coordinates in={#1}
261 % #2: the default for the inverse transformation. If there is
262 % none, a default will be chosen automatically (with full
263 % information)
264 /pgfplots/date coordinates default inverse/.style 2 args={%
265 /pgfplots/date default inv/#1/.initial=#2,
266 },
267 /pgfplots/date coordinates default inverse={x}{\year-\month-\day},
268 /pgfplots/date coordinates default inverse={y}{\year-\month-\day},
269 /pgfplots/date coordinates default inverse={z}{\year-\month-\day},
270 }