Skip to content

Commit 5ee79bf

Browse files
DocAtPromptclaude
andcommitted
calendar: a marked day wears its own colour (§ 7.12)
A holidays entry was a date and a label. It now carries an optional colour of its own, and the document a holiday_color for the entries that name none — because a birthday and a public holiday are the same thing to a calendar, and the colour is what tells them apart. The colour beats the weekend shade: a marked day is the more particular fact about that square. It is shown the same way everywhere, behind the day rather than in it — the cell in the half-year table, the row on the month page, a patch behind the number in the full-year overview (which has no cell boxes by design), and a patch behind the label on the day page, which is the only place the label itself appears. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 16465cb commit 5ee79bf

6 files changed

Lines changed: 120 additions & 19 deletions

File tree

‎ctrlgrid/data/presets/calendar-a4.yaml‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,16 @@ months:
4545
- December
4646
weekdays: [Mon, Tue, Wed, Thu, Fri, Sat, Sun]
4747

48-
# A list of holidays: each marks its day cell and shows on the month and day.
48+
# Marked days: holidays, birthdays, anniversaries — the calendar treats them
49+
# alike. Each fills its cell in the half-year table, its row on the month page,
50+
# its number in the full-year overview, and carries its label on the day page.
51+
# `color` is per entry; entries without one take `holiday_color`.
52+
holiday_color: "#fce9e4"
4953
holidays:
5054
- { date: 2026-01-01, label: New Year }
5155
- { date: 2026-12-25, label: Christmas }
56+
# - { date: 2026-05-03, label: "Mama's birthday", color: "#ffd9ec" }
57+
# holidays_file: holidays.ics # or a YAML list — see § 7.12
5258

5359
# A cover: a full-page colour with a centred title and subtitle. Drop it for no
5460
# title page.

‎ctrlgrid/generators/calendar.py‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,13 @@ def _resolve_def_image(value: str | None, info, field: str) -> str | None:
7474

7575

7676
class Holiday(Section):
77-
"""One holiday: a date and the label to show on it (§ 7)."""
77+
"""One marked day: a date, the label to show on it, and optionally its own
78+
colour (§ 7). Not only public holidays — a birthday or an anniversary is the
79+
same thing to the calendar, and its own colour is what tells them apart."""
7880

7981
date: datetime.date
8082
label: str
83+
color: ColorField | None = None
8184

8285

8386
class DayBlock(Section):
@@ -190,6 +193,9 @@ class CalendarConfig(BaseModel):
190193
weekdays: tuple[str, ...] | None = None
191194
holidays: tuple[Holiday, ...] = ()
192195
holidays_file: str | None = None
196+
#: The fill for a marked day that names no colour of its own (§ 7). It beats
197+
#: the weekend shade, because a marked day is the more particular fact.
198+
holiday_color: ColorField = "#fce9e4"
193199
#: Computed provenance for the report (set by the before-validator, never by
194200
#: the user); `describe()` names it. § 7.12.
195201
holidays_source: str | None = None
@@ -473,7 +479,7 @@ def pages(self, cfg: CalendarConfig, *, area: Area, q: WriterQuery) -> Iterator[
473479
weekdays = cfg.weekday_names()
474480
has_notes = cfg.notes is not None
475481
has_week = cfg.week_view is not None
476-
holidays = {h.date: h.label for h in cfg.holidays}
482+
holidays = {h.date: h for h in cfg.holidays}
477483
all_days = list(days_of_year(cfg.year))
478484
weeks = weeks_of_year(cfg.year, cfg.week_start) if has_week else []
479485
day_blocks = cfg.day.blocks if cfg.day is not None else (

‎ctrlgrid/generators/calendar_layout.py‎

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,25 @@ def done(self, dest, kind, title) -> DocumentPage:
131131
links=tuple(self.links), title=title)
132132

133133

134+
def marked_days(cfg) -> dict[datetime.date, str]:
135+
"""date → the colour that marks it (§ 7).
136+
137+
A marked day is any entry of `holidays` — a public holiday, a birthday, an
138+
anniversary; the calendar does not care which. Its own `color` wins, else the
139+
definition's `holiday_color`.
140+
"""
141+
return {h.date: (h.color or cfg.holiday_color) for h in cfg.holidays}
142+
143+
144+
def _badge(page: Page, x, top, text, size, color) -> None:
145+
"""A filled patch behind a piece of text — how a marked day shows itself
146+
where there is no cell to fill (§ 7). Drawn before the text, so the text
147+
reads over it; the patch is the glyphs' own width, measured."""
148+
pad = pt(1.5)
149+
width = page.q.text_width(text, family="sans", size=round(size))
150+
page.box(x - pad, top - pad, width + 2 * pad, size + 2 * pad, 0.0, color, color)
151+
152+
134153
# ------------------------------------------------------------------ nav strip
135154

136155

@@ -291,11 +310,12 @@ def year_overview_page(page: Page, cfg, n: Nav, months, weekdays) -> DocumentPag
291310
gutter = _YEAR_GUTTER
292311
cell_w = mini_month_cell_width(page.W)
293312
cell_h = (page.H - top - pt(2) - (rows - 1) * gutter) / rows
313+
marked = marked_days(cfg)
294314
for m in range(12):
295315
r, c = divmod(m, cols)
296316
_mini_month(page, cfg, months, weekdays, m + 1,
297317
c * (cell_w + gutter), top + r * (cell_h + gutter), cell_w, cell_h,
298-
n.has_week)
318+
n.has_week, marked)
299319
return page.done("year", "year", f"{cfg.year} full year")
300320

301321

@@ -330,7 +350,7 @@ def mini_month_cell_width(area_width: int) -> float:
330350

331351

332352
def _mini_month(page: Page, cfg, months, weekdays, month, x, top, w, h,
333-
has_week: bool = False) -> None:
353+
has_week: bool = False, marked: dict | None = None) -> None:
334354
"""One mini-month of the full-year overview (§ 7).
335355
336356
Everything hangs off one right edge per column: the weekday letter and every
@@ -406,6 +426,10 @@ def right_edge(column: int) -> float:
406426
# and the tap box follow the glyphs rather than a guessed box.
407427
cx = right_edge(idx % 7) - page.q.text_width(label, family="sans", size=round(day_size))
408428
cy = grid_top + (idx // 7) * row_h
429+
# No cell boxes here by design (§ 7), so a marked day colours the number.
430+
colour = (marked or {}).get(datetime.date(cfg.year, month, d))
431+
if colour:
432+
_badge(page, round(cx), round(cy), label, day_size, colour)
409433
page.link_text(round(cx), round(cy), label,
410434
f"day-{cfg.year:04d}-{month:02d}-{d:02d}", day_size)
411435

@@ -434,6 +458,7 @@ def _half_table(page: Page, cfg, months, top, h, *, first_month: int) -> None:
434458
col_w = (page.W - day_col - (day_col if both else 0)) / 6
435459
row_h = h / 32 # one header row + 31 day rows
436460
shade = cfg.year_view.weekend_shade
461+
marked = marked_days(cfg)
437462
size = pt(6.5)
438463

439464
def in_row(row: int, text_size: float) -> int:
@@ -456,8 +481,10 @@ def in_row(row: int, text_size: float) -> int:
456481
for d in range(1, ndays + 1):
457482
rtop = top + row_h * d
458483
date = datetime.date(cfg.year, month, d)
459-
if date.weekday() >= 5 and shade:
460-
page.box(cx, rtop, col_w, row_h, 0.0, shade, shade)
484+
# The marked day's own colour first: it is the more particular fact.
485+
fill = marked.get(date) or (shade if date.weekday() >= 5 else None)
486+
if fill:
487+
page.box(cx, rtop, col_w, row_h, 0.0, fill, fill)
461488
page.box(cx, rtop, col_w, row_h, 0.2, GUIDE) # only existing days get a cell
462489
if cfg.year_view.cell_link == "day":
463490
page.links.append(
@@ -472,30 +499,38 @@ def month_page(page: Page, cfg, n: Nav, months, weekdays, month, holidays, prev,
472499
top = crumb(page, title=f"{months[month - 1]} {cfg.year}", prev=prev, nxt=nxt, up="year")
473500
avail = page.H - top - pt(2)
474501
row_h = avail / ndays
502+
marked = marked_days(cfg)
475503
for d in range(1, ndays + 1):
476504
date = datetime.date(cfg.year, month, d)
477505
rtop = top + (d - 1) * row_h
478-
if date.weekday() >= 5 and cfg.month_view.weekend_shade:
479-
page.box(0, rtop, page.W, row_h, 0.0,
480-
cfg.month_view.weekend_shade, cfg.month_view.weekend_shade)
506+
fill = marked.get(date) or (
507+
cfg.month_view.weekend_shade if date.weekday() >= 5 else None
508+
)
509+
if fill:
510+
page.box(0, rtop, page.W, row_h, 0.0, fill, fill)
481511
page.hline(0, page.W, rtop, 0.2, GUIDE)
482512
page.link_text(pt(1), round(rtop + row_h / 2 - pt(5)),
483513
f"{weekdays[date.weekday()]} {d}", f"day-{date.isoformat()}", pt(10))
484-
label = holidays.get(date)
485-
if label:
486-
page.text(mm(22), round(rtop + row_h / 2 - pt(4)), label, pt(8), LINK)
514+
holiday = holidays.get(date)
515+
if holiday is not None:
516+
page.text(mm(22), round(rtop + row_h / 2 - pt(4)), holiday.label, pt(8), INK)
487517
page.hline(0, page.W, top + ndays * row_h, 0.2, GUIDE)
488518
return page.done(f"month-{month:02d}", "month", f"{months[month - 1]} {cfg.year}")
489519

490520

491-
def day_page(page: Page, cfg, n: Nav, months, weekdays, date, blocks, holiday_label, prev, nxt):
521+
def day_page(page: Page, cfg, n: Nav, months, weekdays, date, blocks, holiday, prev, nxt):
492522
month = date.month
493523
nav(page, n)
494524
title = f"{weekdays[date.weekday()]} {date.day} {months[month - 1]}"
495525
top = crumb(page, title=title, prev=prev, nxt=nxt, up=f"month-{month:02d}")
496-
if holiday_label:
497-
page.text(0, top, holiday_label, pt(9), LINK)
498-
top += pt(12)
526+
if holiday is not None:
527+
# The day has no cell to fill, so the label wears the colour itself. It
528+
# starts a little lower than the body would: the patch reaches above the
529+
# cap, and the title above it has descenders.
530+
top += pt(4)
531+
_badge(page, 0, top, holiday.label, pt(9), holiday.color or cfg.holiday_color)
532+
page.text(0, top, holiday.label, pt(9), INK)
533+
top += pt(16)
499534
_draw_blocks(page, blocks, top)
500535
return page.done(f"day-{date.isoformat()}", "day", title)
501536

‎docs/CLAUDE.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ needs a human *and* the user has chosen to defer PyPI for now (see *Not done*).
3939
uv sync --extra dev && uv run pytest && uv run ruff check .
4040
```
4141

42-
965 tests, all green, ruff clean. Sixty-odd commits on `main`, linear history,
42+
974 tests, all green, ruff clean. Sixty-odd commits on `main`, linear history,
4343
pushed to **[github.com/DocAtPrompt/ctrlgrid](https://github.com/DocAtPrompt/ctrlgrid)**
4444
(public); CI runs green there on Linux (3.11–3.13), macOS and Windows. Eleven
4545
presets — one per generator (`lines`, `dots`, `polar`, `form`, `maze`,

‎docs/pflichtenheft-vorlagengenerator.md‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1185,7 +1185,16 @@ gegen `base_dir` aufgelöst wie `logo`, aufs Jahr gefiltert und mit der
11851185
Inline-Liste vereint (Inline gewinnt bei Datumsgleichheit). Wiederkehrende
11861186
(`RRULE`) und terminierte (DATE-TIME) `.ics`-Events werden **gezählt
11871187
übersprungen**, nie still verschluckt; die Quelle nennt der Laufbericht
1188-
(`X-WR-CALNAME`/`PRODID`), nichts im PDF. Damit ist § 7.12 vollständig.
1188+
(`X-WR-CALNAME`/`PRODID`), nichts im PDF.
1189+
1190+
Ein Eintrag ist nicht auf Feiertage beschränkt — Geburtstage und Jahrestage sind
1191+
demselben Kalender dasselbe. Jeder trägt optional eine **eigene Farbe** (`color`),
1192+
sonst die des Dokuments (`holiday_color`); sie **schlägt die Wochenend-Tönung**,
1193+
weil der markierte Tag die besondere Aussage ist. Gezeigt wird sie überall
1194+
*hinter* dem Tag: als Zellfüllung in der Halbjahrestabelle, als Zeilenfüllung auf
1195+
der Monatsseite, als Fläche hinter der Zahl in der Ganzjahresübersicht (die
1196+
bewusst keine Zellrahmen hat) und als Fläche hinter der Bezeichnung auf der
1197+
Tagesseite. Damit ist § 7.12 vollständig.
11891198

11901199
---
11911200

‎tests/test_calendar.py‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,3 +527,48 @@ def test_by_default_the_numbers_are_on_the_left_only(self) -> None:
527527
only = [t for t in page.marks
528528
if isinstance(t, Text) and t.content == "31" and t.size == pt(6.5)]
529529
assert len(only) == 1
530+
531+
532+
class TestMarkedDays:
533+
"""A marked day — a holiday, a birthday, an anniversary — wears a colour,
534+
its own or the definition's default, and it beats the weekend shade (§ 7)."""
535+
536+
MARKS = {
537+
"holidays": [
538+
{"date": "2026-01-01", "label": "New Year"},
539+
{"date": "2026-05-03", "label": "Birthday", "color": "#ffd9ec"},
540+
]
541+
}
542+
543+
def _page(self, dest: str):
544+
pages, _dests, _edges = _graph(cfg(**self.MARKS))
545+
return next(p for p in pages if p.dest == dest)
546+
547+
def _fills(self, page) -> set[str]:
548+
return {m.fill_color for m in page.marks
549+
if isinstance(m, Polygon) and m.fill_color}
550+
551+
def test_an_entry_may_carry_its_own_colour(self) -> None:
552+
c = cfg(**self.MARKS)
553+
assert c.holidays[1].color == "#ffd9ec"
554+
assert c.holidays[0].color is None # this one takes the default
555+
assert c.holiday_color is not None
556+
557+
def test_the_half_year_cell_takes_the_marked_colour(self) -> None:
558+
fills = self._fills(self._page("half-1"))
559+
c = cfg(**self.MARKS)
560+
assert c.holiday_color in fills # New Year's cell
561+
assert c.year_view.weekend_shade in fills # weekends still shaded
562+
563+
def test_the_month_row_takes_the_entrys_own_colour(self) -> None:
564+
assert "#ffd9ec" in self._fills(self._page("month-05"))
565+
566+
def test_the_year_overview_colours_the_number_itself(self) -> None:
567+
# No cell boxes there by design, so the mark is a patch behind the number.
568+
assert cfg(**self.MARKS).holiday_color in self._fills(self._page("year"))
569+
570+
def test_the_day_page_sets_the_label_on_its_colour(self) -> None:
571+
assert "#ffd9ec" in self._fills(self._page("day-2026-05-03"))
572+
573+
def test_an_unmarked_weekday_stays_plain(self) -> None:
574+
assert self._fills(self._page("day-2026-05-04")) == set()

0 commit comments

Comments
 (0)