| 1 |
% Copyright 2022 by Qrrbrbirlbel |
| 2 |
% |
| 3 |
% This file may be distributed and/or modified |
| 4 |
% |
| 5 |
% 1. under the LaTeX Project Public License and/or |
| 6 |
% 2. under the GNU Free Documentation License. |
| 7 |
% |
| 8 |
|
| 9 |
\usetikzlibrary{calendar} |
| 10 |
\pgfutil@usemodule{pgfcalendar-ext} |
| 11 |
|
| 12 |
% Shift between days |
| 13 |
|
| 14 |
\def\tikz@lib@cal@xshift{\pgfkeysvalueof{/tikz/day xshift}} |
| 15 |
\def\tikz@lib@cal@yshift{\pgfkeysvalueof{/tikz/day yshift}} |
| 16 |
\pgfkeyslet{/tikz/day xshift/.@cmd}\@undefined |
| 17 |
\pgfkeyslet{/tikz/day xshift/.@body}\@undefined |
| 18 |
\pgfkeyslet{/tikz/day xshift/.@def}\@undefined |
| 19 |
\pgfkeyslet{/tikz/day yshift/.@cmd}\@undefined |
| 20 |
\pgfkeyslet{/tikz/day yshift/.@body}\@undefined |
| 21 |
\pgfkeyslet{/tikz/day yshift/.@def}\@undefined |
| 22 |
\tikzset{day xshift/.initial=3ex,day yshift/.initial=3.5ex} |
| 23 |
|
| 24 |
% Shift between months |
| 25 |
|
| 26 |
\def\tikz@lib@cal@month@xshift{\pgfkeysvalueof{/tikz/month xshift}} |
| 27 |
\def\tikz@lib@cal@month@yshift{\pgfkeysvalueof{/tikz/month yshift}} |
| 28 |
\pgfkeyslet{/tikz/month xshift/.@cmd}\@undefined |
| 29 |
\pgfkeyslet{/tikz/month xshift/.@body}\@undefined |
| 30 |
\pgfkeyslet{/tikz/month xshift/.@def}\@undefined |
| 31 |
\pgfkeyslet{/tikz/month yshift/.@cmd}\@undefined |
| 32 |
\pgfkeyslet{/tikz/month yshift/.@body}\@undefined |
| 33 |
\pgfkeyslet{/tikz/month xshift/.@def}\@undefined |
| 34 |
\tikzset{month xshift/.initial=9ex,month yshift/.initial=9ex} |
| 35 |
|
| 36 |
% Internal option for storing the "width" of a calendar as a number of |
| 37 |
% days |
| 38 |
|
| 39 |
\def\tikz@lib@cal@width{\pgfkeysvalueof{/tikz/tikz@lib@cal@width}} |
| 40 |
\pgfkeyslet{/tikz/tikz@lib@cal@width/.@cmd}\@undefined |
| 41 |
\pgfkeyslet{/tikz/tikz@lib@cal@width/.@body}\@undefined |
| 42 |
\pgfkeyslet{/tikz/tikz@lib@cal@width/.@def}\@undefined |
| 43 |
\tikzset{tikz@lib@cal@width/.initial=1} |
| 44 |
|
| 45 |
% Weeks |
| 46 |
|
| 47 |
\def\tikzextweekcode{\pgfkeysvalueof{/tikz/ext/week code}} |
| 48 |
\def\tikzextweektext{\pgfkeysvalueof{/tikz/ext/week text}} |
| 49 |
|
| 50 |
\tikzextset{ |
| 51 |
week code/.initial={% |
| 52 |
\node[ext/every week]{\pgfkeysvalueof{/tikz/ext/week text}};}, |
| 53 |
week text/.initial={\%n=}, |
| 54 |
every week/.code=, |
| 55 |
week label left/.style={ |
| 56 |
/tikz/ext/every week/.append style={ |
| 57 |
/tikz/anchor=base east, |
| 58 |
/tikz/xshift=-1.25*\pgfkeysvalueof{/tikz/day xshift}}, |
| 59 |
/tikz/execute before day scope=% |
| 60 |
\ifdate{Monday, equals=\pgfcalendarbeginiso}{\tikzextweekcode}{}}} |
| 61 |
|
| 62 |
% |
| 63 |
% Overwriting original \tikz@lib@cal@if@else@code |
| 64 |
% |
| 65 |
\def\tikz@lib@cal@if@else@code#1#2#3{% |
| 66 |
\tikzext@cal@doif\tikz@lib@cal@ifs{\ifdate{#1}{#2}{#3}}% |
| 67 |
\tikz@lib@cal@scanner% |
| 68 |
} |
| 69 |
|
| 70 |
\let\tikzext@cal@doif\tikzextutil@addto@macro |
| 71 |
\tikzset{execute at begin day scope=\let\tikzext@cal@doif\pgfutil@secondoftwo} |
| 72 |
|
| 73 |
|
| 74 |
\pgfmathdeclarefunction{ext_weeksinmonthofyear}{3}{% #1 = first weekday, #2 = month, #3 = year |
| 75 |
\begingroup |
| 76 |
\pgfmathlastdayinmonthofyear@{#2}{#3}% |
| 77 |
\pgfmathadd@{#1}{\pgfmathresult}% |
| 78 |
\pgfmathdivide@{\pgfmathresult}{7}% |
| 79 |
\pgfmathceil@{\pgfmathresult}% |
| 80 |
\pgfmathint@{\pgfmathresult}% |
| 81 |
\pgfmathsmuggle\pgfmathresult |
| 82 |
\endgroup |
| 83 |
} |
| 84 |
\pgfmathdeclarefunction{ext_lastdayinmonthofyear}{2}{% #1 = month, #2 = year |
| 85 |
\begingroup |
| 86 |
\pgfextcalendar@getlastYMX{#2}{#1}{\pgfutil@tempcnta}% |
| 87 |
\edef\pgfmathresult{\the\pgfutil@tempcnta}% |
| 88 |
\pgfmathsmuggle\pgfmathresult |
| 89 |
\endgroup |
| 90 |
} |
| 91 |
\expandafter\let\expandafter\pgfmathextweeksinmonthofyear\csname pgfmathext_weeksinmonthofyear\endcsname |
| 92 |
\expandafter\let\expandafter\pgfmathextweeksinmonthofyear@\csname pgfmathext_weeksinmonthofyear@\endcsname |
| 93 |
\expandafter\let\expandafter\pgfmathextlastdayinmonthofyear\csname pgfmathext_lastdayinmonthofyear\endcsname |
| 94 |
\expandafter\let\expandafter\pgfmathextlastdayinmonthofyear@\csname pgfmathext_lastdayinmonthofyear@\endcsname |
| 95 |
|
| 96 |
%%% Compatibility |
| 97 |
\tikzextset{ |
| 98 |
compat/pgfcalendar-ext/warn/.append code={% |
| 99 |
\tikzextutil@compatwarning@cmd{calendar-plus}{pre 0.6}{pgfmathlastdayinmonthofyear}\pgfmathextlastdayinmonthofyear\tikzextutil@gobblethree |
| 100 |
\tikzextutil@compatwarning@cmd{calendar-plus}{pre 0.6}{pgfmathweeksinmonthofyear}\pgfmathextweeksinmonthofyear\pgfutil@gobbletwo |
| 101 |
\pgfutil@for\tikzext@temp:=Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec,% |
| 102 |
leap year,and,not,week of month,week of month',calendar week of month,% |
| 103 |
calendar week of month',yesterday,week\do{% |
| 104 |
\pgfkeys@expanded{\noexpand\tikzextutil@compatwarning@key |
| 105 |
{pgfcalendar-ext}{pre 0.6}{/pgf/calendar/\tikzext@temp}{/pgf/calendar/ext/\tikzext@temp}% |
| 106 |
}% |
| 107 |
}% |
| 108 |
\pgfkeyssetvalue{/pgf/calendar/leap year/.@def}{\pgfcalendarifdateyear}% |
| 109 |
\pgfkeyssetvalue{/pgf/calendar/calendar week of month/.@def}{1}% |
| 110 |
\pgfkeyssetvalue{/pgf/calendar/calendar week of month'/.@def}{1}% |
| 111 |
\tikzextutil@compatwarning@cmd{pgfcalendar-ext}{pre 0.6} |
| 112 |
{pgfcalendarjulianyeartoweek}\pgfextcalendarjulianyeartoweek\tikzextutil@gobblethree |
| 113 |
}, |
| 114 |
compat/pgfcalendar-ext/pre 0.6/.append code={% |
| 115 |
\pgfutil@for\tikzext@temp:=Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec,% |
| 116 |
leap year,and,not,week of month,week of month',calendar week of month,% |
| 117 |
calendar week of month',yesterday,week\do{% |
| 118 |
\pgfkeysedef{/pgf/calendar/\tikzext@temp}{% |
| 119 |
\noexpand\pgfkeysvalueof{/pgf/calendar/ext/\tikzext@temp/.@cmd}##1\noexpand\pgfeov |
| 120 |
}% |
| 121 |
\let\pgfcalendarjulianyeartoweek\pgfextcalendarjulianyeartoweek |
| 122 |
\let\pgfmathweeksinmonthofyear\pgfmathextweeksinmonthofyear |
| 123 |
\let\pgfmathweeksinmonthofyear@\pgfmathextweeksinmonthofyear@ |
| 124 |
\let\pgfmathlastdayinmonthofyear\pgfmathextlastdayinmonthofyear |
| 125 |
\let\pgfmathlastdayinmonthofyear@\pgfmathextlastdayinmonthofyear@ |
| 126 |
\def\pgfcalendarcurrentweek{\pgfextcalendarcurrentweek}% |
| 127 |
\def\pgfcalendarifdateweek{\pgfextcalendarifdateweek}% |
| 128 |
}% |
| 129 |
}, |
| 130 |
compat/pgfcalendar-ext/\pgfkeysvalueof{/tikz/ext/compat/pgfcalendar-ext}% |
| 131 |
} |
| 132 |
\endinput |