diff options
| author | Douglas B. Rumbaugh <doug@douglasrumbaugh.com> | 2026-01-11 12:32:34 -0500 |
|---|---|---|
| committer | Douglas B. Rumbaugh <doug@douglasrumbaugh.com> | 2026-01-11 12:32:34 -0500 |
| commit | ef2ba740a784c47f09f9cd5aedd0a096c00b845b (patch) | |
| tree | df7c9ef14c1d9bc85fbdf7ef73f4a15c79ce9081 /weekschedule.cls | |
| parent | f5f69a70c25af4f59f9caa5f0d24e46b7fbd9871 (diff) | |
| download | weekschedule-ef2ba740a784c47f09f9cd5aedd0a096c00b845b.tar.gz | |
Added weekends
Diffstat (limited to 'weekschedule.cls')
| -rw-r--r-- | weekschedule.cls | 87 |
1 files changed, 64 insertions, 23 deletions
diff --git a/weekschedule.cls b/weekschedule.cls index 7fccb80..39b0256 100644 --- a/weekschedule.cls +++ b/weekschedule.cls @@ -41,6 +41,12 @@ \newcommand{\@hourheight}{1.5} \newcommand{\@padding}{0.08} +% Week configuration +\newcommand{\@weektype}{workweek} % workweek, fullweeksunday, fullweekmonday +\newcommand{\@weekdaylist}{Monday,Tuesday,Wednesday,Thursday,Friday} +\newcommand{\@weekdaydisplay}{Monday,Tuesday,Wednesday,Thursday,Friday} +\newcommand{\@daycount}{5} + % ============================================ % User-facing configuration commands % ============================================ @@ -64,6 +70,28 @@ \newcommand{\twentyfourhourtime}{\@usetwentyfourhourtrue} \newcommand{\twelvehourtime}{\@usetwentyfourhourfalse} +% Week configuration toggles +\newcommand{\weekworkweek}{% + \renewcommand{\@weektype}{workweek}% + \renewcommand{\@weekdaylist}{Monday,Tuesday,Wednesday,Thursday,Friday}% + \renewcommand{\@weekdaydisplay}{Monday,Tuesday,Wednesday,Thursday,Friday}% + \renewcommand{\@daycount}{5}% +} + +\newcommand{\weekfullsunday}{% + \renewcommand{\@weektype}{fullweeksunday}% + \renewcommand{\@weekdaylist}{Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday}% + \renewcommand{\@weekdaydisplay}{Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday}% + \renewcommand{\@daycount}{7}% +} + +\newcommand{\weekfullmonday}{% + \renewcommand{\@weektype}{fullweekmonday}% + \renewcommand{\@weekdaylist}{Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday}% + \renewcommand{\@weekdaydisplay}{Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday}% + \renewcommand{\@daycount}{7}% +} + % Layout customization \newcommand{\setdaywidth}[1]{\renewcommand{\@daywidth}{#1}} \newcommand{\sethourheight}[1]{\renewcommand{\@hourheight}{#1}} @@ -84,6 +112,7 @@ % ============================================ \newcounter{@numclasses} \setcounter{@numclasses}{0} +\newcounter{@daypos} % Define an event class with RGB color % Usage: \eventclass{ClassName}{R,G,B} @@ -123,16 +152,22 @@ \vspace{0.05cm} \begin{tikzpicture}[x=1cm, y=1cm] - % Store parameters - \pgfmathsetmacro{\daywidth}{\@daywidth} + % Calculate dynamic day width based on number of days + % Reserve 1.5cm for time labels, divide remaining width by day count + \pgfmathsetmacro{\availablewidth}{(\textwidth/1cm) - 1.5} + \pgfmathsetmacro{\daywidth}{\availablewidth / \@daycount} + + % Store other parameters \pgfmathsetmacro{\hourheight}{\@hourheight} \pgfmathsetmacro{\padding}{\@padding} \pgfmathtruncatemacro{\starthour}{\@starthour} \pgfmathtruncatemacro{\endhour}{\@endhour} - % Draw column headers (days) - \foreach \day/\dayname in {0/Monday, 1/Tuesday, 2/Wednesday, 3/Thursday, 4/Friday} { - \node[anchor=south, font=\large\bfseries] at (\day*\daywidth+\daywidth/2, -\starthour*\hourheight+0.2) {\dayname}; + % Draw column headers (days) - iterate through configured day list + \setcounter{@daypos}{0} + \@for\@currentday:=\@weekdaylist\do{% + \node[anchor=south, font=\large\bfseries] at (\the@daypos*\daywidth+\daywidth/2, -\starthour*\hourheight+0.2) {\@currentday}; + \stepcounter{@daypos}% } % Draw row headers (times) @@ -150,20 +185,21 @@ \fi } - % Draw vertical lines (day separators) - \foreach \day in {0,...,5} { + % Draw vertical lines (day separators) - dynamically based on week type + \foreach \day in {0,...,\@daycount} { \draw[gray] (\day*\daywidth, -\starthour*\hourheight) -- (\day*\daywidth, -\endhour*\hourheight); } % Draw horizontal lines (hour separators) + \pgfmathsetmacro{\gridwidth}{\@daycount*\daywidth} \foreach \hour in {\starthour,...,\endhour} { - \draw[gray] (0, -\hour*\hourheight) -- (5*\daywidth, -\hour*\hourheight); + \draw[gray] (0, -\hour*\hourheight) -- (\gridwidth, -\hour*\hourheight); } % Draw half-hour lines (dashed) \pgfmathtruncatemacro{\lasthour}{\endhour-1} \foreach \hour in {\starthour,...,\lasthour} { - \draw[gray, dashed, line width=0.25pt] (0, -\hour*\hourheight-0.5*\hourheight) -- (5*\daywidth, -\hour*\hourheight-0.5*\hourheight); + \draw[gray, dashed, line width=0.25pt] (0, -\hour*\hourheight-0.5*\hourheight) -- (\gridwidth, -\hour*\hourheight-0.5*\hourheight); } % Draw all events @@ -206,17 +242,21 @@ \@drawforeachday{\@evclass}{\@evname}{\@evdays}{\@startdec}{\@enddec}% } +\newcounter{@evdaypos} + \newcommand{\@drawforeachday}[5]{% - % #1=class, #2=name, #3=days, #4=start, #5=end - \@checkandrawday{#1}{#2}{#3}{#4}{#5}{Monday}{0}% - \@checkandrawday{#1}{#2}{#3}{#4}{#5}{Tuesday}{1}% - \@checkandrawday{#1}{#2}{#3}{#4}{#5}{Wednesday}{2}% - \@checkandrawday{#1}{#2}{#3}{#4}{#5}{Thursday}{3}% - \@checkandrawday{#1}{#2}{#3}{#4}{#5}{Friday}{4}% + % #1=class, #2=name, #3=event days, #4=start, #5=end + % Iterate through the week's day list and draw event if it's on that day + \setcounter{@evdaypos}{0} + \@for\@weekday:=\@weekdaylist\do{% + \@checkandrawday{#1}{#2}{#3}{#4}{#5}{\@weekday}{\the@evdaypos}% + \stepcounter{@evdaypos}% + }% } \newcommand{\@checkandrawday}[7]{% - % #1=class, #2=name, #3=days string, #4=start, #5=end, #6=dayname, #7=daynum + % #1=class, #2=name, #3=event days string, #4=start, #5=end, #6=dayname, #7=daypos + % Check if this day is in the event's day list \@checkdayinlist{#3}{#6}% \if@daymatched \@draweventbox{#1}{#2}{#7}{#4}{#5}% @@ -228,10 +268,10 @@ \newcommand{\@checkdayinlist}[2]{% % #1 = comma-separated day list, #2 = day to check \@daymatchedfalse - \def\@daytocheck{#2}% + \edef\@daytocheck{#2}% \@for\@testday:=#1\do{% \edef\@trimmedday{\@testday}% - \ifx\@trimmedday\@daytocheck + \ifnum\pdfstrcmp{\@trimmedday}{\@daytocheck}=0 \@daymatchedtrue \fi }% @@ -239,13 +279,14 @@ \newcommand{\@draweventbox}[5]{% % #1 = class, #2 = name, #3 = day number, #4 = start decimal, #5 = end decimal - \pgfmathsetmacro{\daywidth}{\@daywidth} - \pgfmathsetmacro{\hourheight}{\@hourheight} - \pgfmathsetmacro{\padding}{\@padding} + % Note: daywidth, hourheight, padding are already set in parent scope + % Clamp start and end times to calendar bounds + \pgfmathsetmacro{\startdec}{max(#4, \@starthour)} + \pgfmathsetmacro{\enddec}{min(#5, \@endhour)} \pgfmathsetmacro{\xstart}{#3*\daywidth+\padding} \pgfmathsetmacro{\xend}{#3*\daywidth+\daywidth-\padding} - \pgfmathsetmacro{\ystart}{-#4*\hourheight-\padding} - \pgfmathsetmacro{\yend}{-#5*\hourheight+\padding} + \pgfmathsetmacro{\ystart}{-\startdec*\hourheight-\padding} + \pgfmathsetmacro{\yend}{-\enddec*\hourheight+\padding} \pgfmathsetmacro{\ymid}{(\ystart+\yend)/2} \pgfmathsetmacro{\xcenter}{#3*\daywidth+\daywidth/2} % Draw the box |