summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/pgfplots/libs/tikzlibrarypgfplots.dateplot.code.tex
blob: 8ac9a7631c02241a6727cfe74f08b219501474c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
%--------------------------------------------
%
% Package pgfplots, library for high-level coordinates.
%
% Copyright 2007/2008/2009 by Christian Feuersänger.
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
% 
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
% 
% You should have received a copy of the GNU General Public License
% along with this program.  If not, see <http://www.gnu.org/licenses/>.
%
%--------------------------------------------

\pgfutil@usemodule{pgfcalendar}

% Idea: allow
%--------------------------------------------------
% \begin{tikzpicture}
% 	\begin{axis}[
% 		date coordinates in=x,
% 		xticklabel={\day.\month.},
% 	]
% 	\addplot coordinates {
% 		(2008-01-5, 5)
% 		(2008-01-12, 10)
% 		(2008-01-16, 20)
% 	};
% 	\end{axis}
% \end{tikzpicture}
%-------------------------------------------------- 

\def\pgfplotslibdateplot@number@to@julian@and@time#1.#2\julianto#3\hourto#4\minuteto#5{%
	#3=#1
	\pgf@xa=0.#2pt
	\multiply\pgf@xa by24
	\afterassignment\pgfplots@gobble@until@relax
	\c@pgf@countb=\the\pgf@xa\relax
	\edef#4{\the\c@pgf@countb}%
	\advance\pgf@xa by-#4pt
	\multiply\pgf@xa by60
	\afterassignment\pgfplots@gobble@until@relax
	\c@pgf@countb=\the\pgf@xa\relax
	% round minutes (we may loose precision here)
	\advance\pgf@xa by-\the\c@pgf@countb pt
	\ifdim\pgf@xa>0.5pt	
		\advance\c@pgf@countb by1
	\fi
	\edef#5{\the\c@pgf@countb}%
}

% #1 the date
% #2 the hours
% #3 the minutes
% #4 is either empty or is the seconds. 
% #5 a macro which will be filled with the date part.
% #6 the macro which will contain a number in the range [0,1]
% representing hours and minutes.
%
% If you don't have seconds, you have to provide the second ':' sign
% as dummy! In that case #4 will be empty.
\def\pgfplotslibdateplot@map@time#1 #2:#3:#4\dateto#5\timeto#6{%
	\pgf@xa=#2pt
	\divide\pgf@xa by24
	\pgf@xb=#3pt
	\divide\pgf@xb by1440
	\advance\pgf@xa by\pgf@xb
	\ifdim\pgf@xa<0pt
		\pgf@xa=0pt
	\else
		\ifdim\pgf@xa>1pt
			\pgf@xa=1pt
		\fi
	\fi
	\def#5{#1}%
	\edef#6{\pgf@sys@tonumber\pgf@xa}%
}%
\def\pgfplotslibdateplot@discard@zero@dot 0.#1\to#2{\def#2{#1}}%

\pgfplotsset{
	/pgfplots/date ZERO/.code={%
		\begingroup
		\pgfcalendardatetojulian{#1}\c@pgf@counta
		\edef\pgfmathresult{\the\c@pgf@counta}%
		\pgfmath@smuggleone\pgfmathresult
		\endgroup
		\let\pgfplots@calender@ZEROSHIFT=\pgfmathresult
	},
	date ZERO=2006-01-01,
	/pgfplots/date coordinates in/.style={
		/pgfplots/#1 coord trafo/.code={%
			\begingroup
			\edef\pgfplotstempjuliandate{##1}%
			% check if we also have a TIME like '2006-01-01 11:21'
			\expandafter\pgfutil@in@\expandafter:\expandafter{\pgfplotstempjuliandate}%
			\ifpgfutil@in@
				% we have a TIME!
				\expandafter\pgfplotslibdateplot@map@time\pgfplotstempjuliandate:\dateto\pgfplotstempjuliandate\timeto\pgfplotstemptime
			\else
				\let\pgfplotstemptime=\pgfutil@empty
			\fi
			\expandafter\pgfcalendardatetojulian\expandafter{\pgfplotstempjuliandate}\c@pgf@counta
			\advance\c@pgf@counta by-\pgfplots@calender@ZEROSHIFT\relax
			\ifx\pgfplotstemptime\pgfutil@empty
				% no time:
				\edef\pgfmathresult{\the\c@pgf@counta}%
			\else
				% add time fraction (which should be in the range
				% [0,1]).
				\ifdim\pgfplotstemptime pt<1pt
					% discard prefix '0.':
					\expandafter\pgfplotslibdateplot@discard@zero@dot\pgfplotstemptime\to\pgfplotstemptime
					\edef\pgfmathresult{\the\c@pgf@counta.\pgfplotstemptime}%
				\else
					% assume \pgfplotstemptime=1pt :
					\advance\c@pgf@counta by1
					\edef\pgfmathresult{\the\c@pgf@counta}%
				\fi
			\fi
			\pgfmath@smuggleone\pgfmathresult
			\endgroup
		},
		/pgfplots/#1 coord inv trafo/.code={%
			\begingroup
				\pgfplotslibdateplot@number@to@julian@and@time##1\julianto{\c@pgf@counta}\hourto\Hour\minuteto\Minute%
				\advance\c@pgf@counta by\pgfplots@calender@ZEROSHIFT\relax
				\expandafter\pgfcalendarjuliantodate\expandafter{\the\c@pgf@counta}\year\month\day
				\xdef\pgfplotslibdateplot@TMP{%
					\noexpand\def\noexpand\year{\year}%
					\noexpand\def\noexpand\month{\month}%
					\noexpand\def\noexpand\day{\day}%
					\noexpand\def\noexpand\Hour{\Hour}%
					\noexpand\def\noexpand\Minute{\Minute}%
				}%
			\endgroup
			\pgfplotslibdateplot@TMP
			\let\hour=\Hour
			\let\minute=\Minute
			\ifnum\hour<10
				\edef\hour{0\hour}%
			\fi
			\ifnum\minute<10
				\edef\minute{0\minute}%
			\fi
			\def\Second{0}%
			\def\second{00}%
			\edef\lowlevel{##1}%
			\edef\pgfmathresult{\year-\month-\day}%
		},
		/pgfplots/#1ticklabel={\tick},%
		/pgfplots/scaled #1 ticks=false,
		/pgfplots/plot coordinates/math parser=false,%
	},
	/pgfplots/date coordinates in/.value required,
}