briefing 0.2.0__tar.gz → 0.2.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. {briefing-0.2.0 → briefing-0.2.2}/CHANGELOG.md +44 -1
  2. {briefing-0.2.0 → briefing-0.2.2}/PKG-INFO +1 -1
  3. {briefing-0.2.0 → briefing-0.2.2}/src/briefing/__init__.py +1 -1
  4. {briefing-0.2.0 → briefing-0.2.2}/src/briefing/lab/_blocks.py +17 -1
  5. {briefing-0.2.0 → briefing-0.2.2}/src/briefing/lab/_render_calendar.py +29 -10
  6. briefing-0.2.2/src/briefing/lab/static/calendar.js +140 -0
  7. {briefing-0.2.0 → briefing-0.2.2}/src/briefing/static/report.css +24 -6
  8. briefing-0.2.2/tests/test_browser/test_calendar.py +242 -0
  9. {briefing-0.2.0 → briefing-0.2.2}/tests/test_contract.py +3 -0
  10. {briefing-0.2.0 → briefing-0.2.2}/tests/test_deprecations.py +21 -1
  11. {briefing-0.2.0 → briefing-0.2.2}/tests/test_lab/test_calendar.py +44 -2
  12. briefing-0.2.0/src/briefing/lab/static/calendar.js +0 -60
  13. briefing-0.2.0/tests/test_browser/test_calendar.py +0 -81
  14. {briefing-0.2.0 → briefing-0.2.2}/.gitignore +0 -0
  15. {briefing-0.2.0 → briefing-0.2.2}/LICENSE +0 -0
  16. {briefing-0.2.0 → briefing-0.2.2}/README.md +0 -0
  17. {briefing-0.2.0 → briefing-0.2.2}/noxfile.py +0 -0
  18. {briefing-0.2.0 → briefing-0.2.2}/pyproject.toml +0 -0
  19. {briefing-0.2.0 → briefing-0.2.2}/src/briefing/__main__.py +0 -0
  20. {briefing-0.2.0 → briefing-0.2.2}/src/briefing/_cli.py +0 -0
  21. {briefing-0.2.0 → briefing-0.2.2}/src/briefing/_error.py +0 -0
  22. {briefing-0.2.0 → briefing-0.2.2}/src/briefing/_frames.py +0 -0
  23. {briefing-0.2.0 → briefing-0.2.2}/src/briefing/_preview.py +0 -0
  24. {briefing-0.2.0 → briefing-0.2.2}/src/briefing/blocks/__init__.py +0 -0
  25. {briefing-0.2.0 → briefing-0.2.2}/src/briefing/blocks/asset.py +0 -0
  26. {briefing-0.2.0 → briefing-0.2.2}/src/briefing/blocks/banner.py +0 -0
  27. {briefing-0.2.0 → briefing-0.2.2}/src/briefing/blocks/base.py +0 -0
  28. {briefing-0.2.0 → briefing-0.2.2}/src/briefing/blocks/layout.py +0 -0
  29. {briefing-0.2.0 → briefing-0.2.2}/src/briefing/blocks/text.py +0 -0
  30. {briefing-0.2.0 → briefing-0.2.2}/src/briefing/export/__init__.py +0 -0
  31. {briefing-0.2.0 → briefing-0.2.2}/src/briefing/export/_image.py +0 -0
  32. {briefing-0.2.0 → briefing-0.2.2}/src/briefing/export/_pdf.py +0 -0
  33. {briefing-0.2.0 → briefing-0.2.2}/src/briefing/export/_render.py +0 -0
  34. {briefing-0.2.0 → briefing-0.2.2}/src/briefing/lab/__init__.py +0 -0
  35. {briefing-0.2.0 → briefing-0.2.2}/src/briefing/lab/_render_datadive.py +0 -0
  36. {briefing-0.2.0 → briefing-0.2.2}/src/briefing/lab/_render_profile.py +0 -0
  37. {briefing-0.2.0 → briefing-0.2.2}/src/briefing/lab/static/lab.js +0 -0
  38. {briefing-0.2.0 → briefing-0.2.2}/src/briefing/py.typed +0 -0
  39. {briefing-0.2.0 → briefing-0.2.2}/src/briefing/renderers/__init__.py +0 -0
  40. {briefing-0.2.0 → briefing-0.2.2}/src/briefing/renderers/formatting.py +0 -0
  41. {briefing-0.2.0 → briefing-0.2.2}/src/briefing/renderers/formula.py +0 -0
  42. {briefing-0.2.0 → briefing-0.2.2}/src/briefing/renderers/html.py +0 -0
  43. {briefing-0.2.0 → briefing-0.2.2}/src/briefing/renderers/normalize.py +0 -0
  44. {briefing-0.2.0 → briefing-0.2.2}/src/briefing/renderers/plot.py +0 -0
  45. {briefing-0.2.0 → briefing-0.2.2}/src/briefing/renderers/registry.py +0 -0
  46. {briefing-0.2.0 → briefing-0.2.2}/src/briefing/renderers/script_json.py +0 -0
  47. {briefing-0.2.0 → briefing-0.2.2}/src/briefing/renderers/table.py +0 -0
  48. {briefing-0.2.0 → briefing-0.2.2}/src/briefing/static/export.css +0 -0
  49. {briefing-0.2.0 → briefing-0.2.2}/src/briefing/static/export.js +0 -0
  50. {briefing-0.2.0 → briefing-0.2.2}/src/briefing/static/report.js +0 -0
  51. {briefing-0.2.0 → briefing-0.2.2}/src/briefing/templates/report.html.j2 +0 -0
  52. {briefing-0.2.0 → briefing-0.2.2}/tests/__init__.py +0 -0
  53. {briefing-0.2.0 → briefing-0.2.2}/tests/banner_images.py +0 -0
  54. {briefing-0.2.0 → briefing-0.2.2}/tests/compat_reports.py +0 -0
  55. {briefing-0.2.0 → briefing-0.2.2}/tests/conftest.py +0 -0
  56. {briefing-0.2.0 → briefing-0.2.2}/tests/contract.py +0 -0
  57. {briefing-0.2.0 → briefing-0.2.2}/tests/html_helpers.py +0 -0
  58. {briefing-0.2.0 → briefing-0.2.2}/tests/image_helpers.py +0 -0
  59. {briefing-0.2.0 → briefing-0.2.2}/tests/pdf_reader.py +0 -0
  60. {briefing-0.2.0 → briefing-0.2.2}/tests/snapshots/compat_0_1_2/blocks.body.html +0 -0
  61. {briefing-0.2.0 → briefing-0.2.2}/tests/snapshots/compat_0_1_2/pages.body.html +0 -0
  62. {briefing-0.2.0 → briefing-0.2.2}/tests/test_blocks/__init__.py +0 -0
  63. {briefing-0.2.0 → briefing-0.2.2}/tests/test_blocks/test_banner.py +0 -0
  64. {briefing-0.2.0 → briefing-0.2.2}/tests/test_blocks/test_base.py +0 -0
  65. {briefing-0.2.0 → briefing-0.2.2}/tests/test_blocks/test_layout.py +0 -0
  66. {briefing-0.2.0 → briefing-0.2.2}/tests/test_blocks/test_text.py +0 -0
  67. {briefing-0.2.0 → briefing-0.2.2}/tests/test_browser/__init__.py +0 -0
  68. {briefing-0.2.0 → briefing-0.2.2}/tests/test_browser/conftest.py +0 -0
  69. {briefing-0.2.0 → briefing-0.2.2}/tests/test_browser/test_banner.py +0 -0
  70. {briefing-0.2.0 → briefing-0.2.2}/tests/test_browser/test_bignumber.py +0 -0
  71. {briefing-0.2.0 → briefing-0.2.2}/tests/test_browser/test_cli_export.py +0 -0
  72. {briefing-0.2.0 → briefing-0.2.2}/tests/test_browser/test_code.py +0 -0
  73. {briefing-0.2.0 → briefing-0.2.2}/tests/test_browser/test_datadive.py +0 -0
  74. {briefing-0.2.0 → briefing-0.2.2}/tests/test_browser/test_datatable.py +0 -0
  75. {briefing-0.2.0 → briefing-0.2.2}/tests/test_browser/test_export_image.py +0 -0
  76. {briefing-0.2.0 → briefing-0.2.2}/tests/test_browser/test_export_menu.py +0 -0
  77. {briefing-0.2.0 → briefing-0.2.2}/tests/test_browser/test_export_pdf.py +0 -0
  78. {briefing-0.2.0 → briefing-0.2.2}/tests/test_browser/test_formula.py +0 -0
  79. {briefing-0.2.0 → briefing-0.2.2}/tests/test_browser/test_layout.py +0 -0
  80. {briefing-0.2.0 → briefing-0.2.2}/tests/test_browser/test_notebook.py +0 -0
  81. {briefing-0.2.0 → briefing-0.2.2}/tests/test_browser/test_plots.py +0 -0
  82. {briefing-0.2.0 → briefing-0.2.2}/tests/test_browser/test_print.py +0 -0
  83. {briefing-0.2.0 → briefing-0.2.2}/tests/test_browser/test_spacing.py +0 -0
  84. {briefing-0.2.0 → briefing-0.2.2}/tests/test_browser/test_text.py +0 -0
  85. {briefing-0.2.0 → briefing-0.2.2}/tests/test_browser/test_toggle_theme.py +0 -0
  86. {briefing-0.2.0 → briefing-0.2.2}/tests/test_cli.py +0 -0
  87. {briefing-0.2.0 → briefing-0.2.2}/tests/test_compat.py +0 -0
  88. {briefing-0.2.0 → briefing-0.2.2}/tests/test_docs_gallery.py +0 -0
  89. {briefing-0.2.0 → briefing-0.2.2}/tests/test_docstrings.py +0 -0
  90. {briefing-0.2.0 → briefing-0.2.2}/tests/test_export.py +0 -0
  91. {briefing-0.2.0 → briefing-0.2.2}/tests/test_frames.py +0 -0
  92. {briefing-0.2.0 → briefing-0.2.2}/tests/test_lab/__init__.py +0 -0
  93. {briefing-0.2.0 → briefing-0.2.2}/tests/test_lab/test_datadive.py +0 -0
  94. {briefing-0.2.0 → briefing-0.2.2}/tests/test_lab/test_lab_boundary.py +0 -0
  95. {briefing-0.2.0 → briefing-0.2.2}/tests/test_lab/test_profile.py +0 -0
  96. {briefing-0.2.0 → briefing-0.2.2}/tests/test_no_viz_deps.py +0 -0
  97. {briefing-0.2.0 → briefing-0.2.2}/tests/test_pdf_reader.py +0 -0
  98. {briefing-0.2.0 → briefing-0.2.2}/tests/test_preview.py +0 -0
  99. {briefing-0.2.0 → briefing-0.2.2}/tests/test_readme.py +0 -0
  100. {briefing-0.2.0 → briefing-0.2.2}/tests/test_renderers/__init__.py +0 -0
  101. {briefing-0.2.0 → briefing-0.2.2}/tests/test_renderers/test_export_menu.py +0 -0
  102. {briefing-0.2.0 → briefing-0.2.2}/tests/test_renderers/test_formula.py +0 -0
  103. {briefing-0.2.0 → briefing-0.2.2}/tests/test_renderers/test_html.py +0 -0
  104. {briefing-0.2.0 → briefing-0.2.2}/tests/test_renderers/test_normalize.py +0 -0
  105. {briefing-0.2.0 → briefing-0.2.2}/tests/test_renderers/test_plot.py +0 -0
  106. {briefing-0.2.0 → briefing-0.2.2}/tests/test_renderers/test_reproducible.py +0 -0
  107. {briefing-0.2.0 → briefing-0.2.2}/tests/test_renderers/test_table.py +0 -0
@@ -10,6 +10,47 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
10
10
 
11
11
  ## [Unreleased]
12
12
 
13
+ ## [0.2.2] - 2026-11-04
14
+
15
+ ### Added
16
+
17
+ - `lab.CalendarHeatmap`: hovering a day, an hour or an event band shows a tooltip at once,
18
+ styled with the theme: the date (now with its weekday) in bold, the exact value, "below
19
+ target …" and the day's events. It also opens on keyboard focus and on tap, stays inside
20
+ the window, and never prints. The browser's slower built-in tooltip no longer doubles up;
21
+ without JavaScript it is still there (#109).
22
+
23
+ ### Changed
24
+
25
+ - `lab.CalendarHeatmap` names every weekday row of the day calendar, not just Mon, Wed
26
+ and Fri (#113).
27
+
28
+ ### Deprecated
29
+
30
+ - `lab.CalendarHeatmap`'s hour view, `views=("hours",)` or `("days", "hours")`, raises a
31
+ `DeprecationWarning`. It still works; a dedicated time-pattern heatmap (weekday × hour,
32
+ weekday × month, …) is planned to replace it, and the hour view will be removed in 0.4.0
33
+ at the earliest, never before that replacement ships (#111).
34
+
35
+ ### Fixed
36
+
37
+ - `lab.CalendarHeatmap(week_start="sunday")` put each weekday label one row off ("Sun"
38
+ on the Monday row); every label now sits on its own row (#113).
39
+ - `lab.CalendarHeatmap` shows values exactly: a non-integer of 10,000 or more read
40
+ `1.235e+04` in the tooltip and the legend; it now reads `12,345.67` (#109).
41
+
42
+ ## [0.2.1] - 2026-11-04
43
+
44
+ ### Changed
45
+
46
+ - `lab.CalendarHeatmap` fits the width available to it, the report's or its `Group`
47
+ column's, instead of a fixed size: a year fills a full-width report, and in a column it
48
+ shrinks to fit instead of widening the column and overflowing the page. Cells stay
49
+ between 0.6× and 2× their natural 11 px (a short range stops at 2×; below 0.6× the
50
+ calendar scrolls inside its block); labels change size at half that rate and legend
51
+ swatches follow the cells. When printed it shrinks to fit the sheet instead of being cut
52
+ off (#106).
53
+
13
54
  ## [0.2.0] - 2026-11-04
14
55
 
15
56
  ### Added
@@ -199,7 +240,9 @@ First public release.
199
240
  inherits its base's renderer.
200
241
  - Ships inline type hints (`py.typed`). Python 3.11+.
201
242
 
202
- [Unreleased]: https://github.com/jeanmidevacc/briefing/compare/v0.2.0...HEAD
243
+ [Unreleased]: https://github.com/jeanmidevacc/briefing/compare/v0.2.2...HEAD
244
+ [0.2.2]: https://github.com/jeanmidevacc/briefing/compare/v0.2.1...v0.2.2
245
+ [0.2.1]: https://github.com/jeanmidevacc/briefing/compare/v0.2.0...v0.2.1
203
246
  [0.2.0]: https://github.com/jeanmidevacc/briefing/compare/v0.1.2...v0.2.0
204
247
  [0.1.2]: https://github.com/jeanmidevacc/briefing/compare/v0.1.1...v0.1.2
205
248
  [0.1.1]: https://github.com/jeanmidevacc/briefing/compare/v0.1.0...v0.1.1
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: briefing
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: Build beautiful self-contained HTML reports from Python analysis
5
5
  Project-URL: Homepage, https://github.com/jeanmidevacc/briefing
6
6
  Project-URL: Documentation, https://briefing.readthedocs.io
@@ -134,7 +134,7 @@ def stringify(
134
134
  return render_report(wrapped, name=name, formatting=formatting, now=now)
135
135
 
136
136
 
137
- __version__ = "0.2.0"
137
+ __version__ = "0.2.2"
138
138
 
139
139
  __all__: list[str] = [
140
140
  # error
@@ -155,12 +155,24 @@ class DataDive(Block):
155
155
  self.max_rows = max_rows
156
156
 
157
157
 
158
+ #: Shown once per CalendarHeatmap built with the hour view (#111).
159
+ HOURS_VIEW_DEPRECATION = (
160
+ "CalendarHeatmap: the hour view (views=('hours',) or ('days', 'hours')) is deprecated since briefing "
161
+ "0.2.2. A dedicated time-pattern heatmap (weekday x hour, weekday x month, ...) will replace it, and the "
162
+ "hour view will be removed in 0.4.0 at the earliest, never before that replacement ships. Follow "
163
+ "https://github.com/jeanmidevacc/briefing/issues/111; use views=('days',) for the day calendar alone."
164
+ )
165
+
166
+
158
167
  class CalendarHeatmap(Block):
159
168
  """GitHub-style calendar heatmap: one cell per day, weeks as columns.
160
169
 
161
170
  Counts the rows per day, or aggregates a value column, and colours each day.
162
171
  Days without data look different from days with a zero; the grid runs
163
172
  continuously across a year boundary, with month labels and a year marker.
173
+ The calendar fits the width available (the report or a ``Group`` column),
174
+ between 0.6x and 2x its natural size; below that it scrolls sideways.
175
+ Hovering a cell shows its date and exact value.
164
176
 
165
177
  Args:
166
178
  df: The data, as any dataframe briefing accepts (pandas, polars, pyarrow…).
@@ -171,7 +183,9 @@ class CalendarHeatmap(Block):
171
183
  group: Column to split by: one calendar per group, stacked, on one shared colour scale.
172
184
  views: ``("days",)``, ``("hours",)`` or ``("days", "hours")``: the day calendar
173
185
  and/or a 7 × 24 weekday-by-hour grid; with both, tabs switch between them.
174
- The hour view needs timestamps with a time of day.
186
+ The hour view needs timestamps with a time of day. *Deprecated since
187
+ 0.2.2:* the hour view raises a ``DeprecationWarning`` and will be replaced
188
+ by a dedicated time-pattern heatmap (issue #111).
175
189
  tz: A time zone such as ``"America/Montreal"``. Converts timezone-aware
176
190
  timestamps only; naive timestamps and plain dates are taken as already
177
191
  local, so a date at midnight never moves to the previous day.
@@ -239,6 +253,8 @@ class CalendarHeatmap(Block):
239
253
  )
240
254
  if tz is not None:
241
255
  _check_tz(tz)
256
+ if "hours" in views:
257
+ warnings.warn(HOURS_VIEW_DEPRECATION, DeprecationWarning, stacklevel=2)
242
258
  if "hours" in views and not _has_times(frame[date]):
243
259
  raise BriefingError(
244
260
  f"CalendarHeatmap: the hour view needs a time of day, but {date!r} holds dates only. "
@@ -32,6 +32,16 @@ _WEEKDAYS = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
32
32
  _MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
33
33
 
34
34
 
35
+ def _svg_open(cls: str, width: int, height: int, label: str) -> str:
36
+ """Open a calendar SVG that scales with its block (#106).
37
+
38
+ ``width``/``height`` are the natural size. The CSS stretches the SVG to the block's
39
+ width, between its natural width (``--bf-cal-w``) and twice that.
40
+ """
41
+ return (f'<svg class="{cls}" xmlns="http://www.w3.org/2000/svg" width="{width}" height="{height}" '
42
+ f'viewBox="0 0 {width} {height}" style="--bf-cal-w: {width}px" role="img" aria-label="{label}">')
43
+
44
+
35
45
  @dataclass(frozen=True)
36
46
  class _Event:
37
47
  start: dt.date
@@ -178,7 +188,18 @@ def _group_attr(block: CalendarHeatmap, group: str | None) -> str:
178
188
 
179
189
 
180
190
  def _fmt(v: float) -> str:
181
- return f"{int(v):,}" if float(v).is_integer() else f"{v:,.4g}"
191
+ """A value as the reader should see it, in the tooltip and the legend (#109).
192
+
193
+ Whole numbers get thousands separators; other values of 1 or more are rounded to
194
+ 2 decimals (trailing zeros dropped) and never use scientific notation; values
195
+ below 1 keep 4 significant digits, and only those below 0.0001 use an exponent.
196
+ """
197
+ v = float(v)
198
+ if v.is_integer():
199
+ return f"{int(v):,}"
200
+ if abs(v) >= 1:
201
+ return f"{v:,.2f}".rstrip("0").rstrip(".")
202
+ return f"{v:.4g}" if abs(v) >= 1e-4 else f"{v:.2e}"
182
203
 
183
204
 
184
205
  def _what(block: CalendarHeatmap) -> str:
@@ -215,12 +236,10 @@ def _days_svg(
215
236
  grid_h = 7 * _STEP
216
237
  width = _LEFT + weeks * _STEP
217
238
  height = _TOP + grid_h + (len(lanes) * _LANE + 6 if lanes else 0)
218
- parts = [f'<svg class="bf-cal__days" xmlns="http://www.w3.org/2000/svg" width="{width}" height="{height}" '
219
- f'viewBox="0 0 {width} {height}" role="img" aria-label="Calendar heatmap">']
239
+ parts = [_svg_open("bf-cal__days", width, height, "Calendar heatmap")]
220
240
 
221
- for row in (0, 2, 4): # Mon, Wed, Fri
222
- name = _WEEKDAYS[(row - shift) % 7]
223
- y = _TOP + ((row + shift) % 7) * _STEP + _CELL - 1
241
+ for weekday, name in enumerate(_WEEKDAYS): # every row named, on its own row (#113)
242
+ y = _TOP + ((weekday + shift) % 7) * _STEP + _CELL - 1
224
243
  parts.append(f'<text class="bf-cal__weekday" x="0" y="{y}">{name}</text>')
225
244
 
226
245
  year_shown: int | None = None
@@ -247,16 +266,17 @@ def _days_svg(
247
266
  col, row = pos(day)
248
267
  x, y = _LEFT + col * _STEP, _TOP + row * _STEP
249
268
  value, goal = data.get(day), target(day)
269
+ when = f"{_WEEKDAYS[day.weekday()]} {day.isoformat()}"
250
270
  cls = ["bf-cal__day"]
251
271
  fill = ""
252
272
  if value is None:
253
273
  cls.append("bf-cal__day--empty")
254
- tip = f"{day.isoformat()} · no data"
274
+ tip = f"{when} · no data"
255
275
  else:
256
276
  fill, extra = colour(value)
257
277
  if extra:
258
278
  cls.append(extra)
259
- tip = f"{day.isoformat()} · {_fmt(value)} {what}"
279
+ tip = f"{when} · {_fmt(value)} {what}"
260
280
  # No data falls short of a positive target only: nothing is below a target of 0.
261
281
  if goal is not None and ((value is None and goal > 0) or (value is not None and value < goal)):
262
282
  cls.append("bf-cal__day--below")
@@ -352,8 +372,7 @@ _HOUR_STEP = 16
352
372
  def _hours_svg(block: CalendarHeatmap, data: dict[t.Any, float], colour: Callable[[float], tuple[str, str]]) -> str:
353
373
  shift = 0 if block.week_start == "monday" else 1
354
374
  width, height = _LEFT + 24 * _HOUR_STEP, 18 + 7 * _HOUR_STEP
355
- parts = [f'<svg class="bf-cal__hours" xmlns="http://www.w3.org/2000/svg" width="{width}" height="{height}" '
356
- f'viewBox="0 0 {width} {height}" role="img" aria-label="Activity by weekday and hour">']
375
+ parts = [_svg_open("bf-cal__hours", width, height, "Activity by weekday and hour")]
357
376
  for hour in range(0, 24, 3):
358
377
  parts.append(f'<text class="bf-cal__month" x="{_LEFT + hour * _HOUR_STEP}" y="12">{hour:02d}</text>')
359
378
  what = _what(block)
@@ -0,0 +1,140 @@
1
+ /* briefing lab: CalendarHeatmap — sizing, hover tooltip, and on_click="rows" (click a day or an hour to
2
+ list its rows). Vanilla JS. */
3
+ (function () {
4
+ 'use strict';
5
+
6
+ // The SVGs fit the width of their block (CSS, #106). Publish the scale k on the view: legend
7
+ // swatches follow the cells (--bf-cal-k), and labels change size at half the cells' rate, so
8
+ // they stay readable when the calendar grows or shrinks (--bf-cal-text, in the SVG's units).
9
+ function measure(view) {
10
+ var svg = view.querySelector('svg.bf-cal__days, svg.bf-cal__hours');
11
+ var natural = svg ? parseFloat(svg.getAttribute('width')) : 0;
12
+ var shown = svg ? svg.getBoundingClientRect().width : 0;
13
+ if (!(natural > 0 && shown > 0)) return; // a hidden tab: measured once it is shown
14
+ var k = shown / natural;
15
+ view.style.setProperty('--bf-cal-k', String(k));
16
+ view.style.setProperty('--bf-cal-text', String((1 + k) / (2 * k)));
17
+ }
18
+ document.querySelectorAll('.bf-calendar').forEach(function (figure) {
19
+ var views = figure.querySelectorAll('.bf-cal__views > .bf-select__panel');
20
+ views = views.length ? Array.prototype.slice.call(views) : [figure];
21
+ views.forEach(function (view) {
22
+ measure(view);
23
+ if (window.ResizeObserver) {
24
+ new ResizeObserver(function () { measure(view); }).observe(view);
25
+ } else {
26
+ window.addEventListener('resize', function () { measure(view); });
27
+ }
28
+ });
29
+ });
30
+
31
+ // Hover tooltip (#109): instant, themed, and shown on keyboard focus and tap too. Its text comes
32
+ // from each cell's <title>, which is then removed so the browser's own slow tooltip doesn't double
33
+ // up; clickable cells keep the text as their aria-label. Built with textContent only.
34
+ var tips = [];
35
+ function hideTips() { tips.forEach(function (tip) { tip.hidden = true; }); }
36
+ function showTip(tip, cell) {
37
+ var lines = (cell.getAttribute('data-tip') || '').split(' \u00b7 ');
38
+ tip.textContent = '';
39
+ lines.forEach(function (line, i) {
40
+ var el = document.createElement(i === 0 ? 'strong' : 'div');
41
+ el.textContent = line;
42
+ tip.appendChild(el);
43
+ });
44
+ hideTips();
45
+ tip.hidden = false;
46
+ // Above the cell, centred; below it when there is no room above; always inside the window.
47
+ var box = cell.getBoundingClientRect(), gap = 6, edge = 4;
48
+ var width = tip.offsetWidth, height = tip.offsetHeight;
49
+ var left = box.left + box.width / 2 - width / 2;
50
+ left = Math.max(edge, Math.min(left, document.documentElement.clientWidth - width - edge));
51
+ var top = box.top - height - gap;
52
+ if (top < edge) top = box.bottom + gap;
53
+ tip.style.left = left + 'px';
54
+ tip.style.top = top + 'px';
55
+ }
56
+ document.querySelectorAll('.bf-calendar').forEach(function (figure) {
57
+ var tip = document.createElement('div');
58
+ tip.className = 'bf-cal__tip';
59
+ tip.setAttribute('role', 'tooltip');
60
+ tip.hidden = true;
61
+ figure.appendChild(tip);
62
+ tips.push(tip);
63
+ figure.querySelectorAll('rect.bf-cal__day, rect.bf-cal__hour, g.bf-cal__event').forEach(function (cell) {
64
+ var title = cell.querySelector('title');
65
+ if (!title) return;
66
+ cell.setAttribute('data-tip', title.textContent);
67
+ if (cell.getAttribute('role') === 'button') cell.setAttribute('aria-label', title.textContent);
68
+ cell.removeChild(title);
69
+ cell.addEventListener('mouseenter', function () { showTip(tip, cell); });
70
+ cell.addEventListener('mouseleave', hideTips);
71
+ cell.addEventListener('focus', function () { showTip(tip, cell); });
72
+ cell.addEventListener('blur', hideTips);
73
+ cell.addEventListener('pointerdown', function (e) { if (e.pointerType !== 'mouse') showTip(tip, cell); });
74
+ });
75
+ });
76
+ if (tips.length) {
77
+ // A tap elsewhere, scrolling (the page or a calendar's own scroll box) or Escape hides it.
78
+ document.addEventListener('pointerdown', function (e) {
79
+ if (!(e.target.closest && e.target.closest('[data-tip]'))) hideTips();
80
+ });
81
+ window.addEventListener('scroll', hideTips, true);
82
+ document.addEventListener('keydown', function (e) { if (e.key === 'Escape') hideTips(); });
83
+ }
84
+
85
+ document.querySelectorAll('.bf-calendar').forEach(function (figure) {
86
+ var dataEl = figure.querySelector('script.bf-cal__rows');
87
+ if (!dataEl) return;
88
+ var data = JSON.parse(dataEl.textContent);
89
+ var panel = figure.querySelector('.bf-cal__panel');
90
+ var title = panel.querySelector('.bf-cal__panel-title');
91
+ var body = panel.querySelector('.bf-cal__panel-body');
92
+
93
+ // Built with textContent only: row values are shown as text, never as markup.
94
+ function open(cell) {
95
+ var calendar = cell.closest('.bf-cal__calendar');
96
+ var group = calendar ? calendar.getAttribute('data-group') : null;
97
+ var date = cell.getAttribute('data-date');
98
+ var key = (date ? 'd|' + date : 'h|' + cell.getAttribute('data-hour')) + (group !== null ? '|' + group : '');
99
+ var entry = data.cells[key];
100
+ var when = (cell.getAttribute('data-tip') || '').split(' \u00b7 ')[0];
101
+ var count = entry ? entry.total + (entry.total === 1 ? ' row' : ' rows') : 'no rows';
102
+ title.textContent = [when, group, count].filter(function (x) { return x !== null; }).join(' · ');
103
+ body.textContent = '';
104
+ if (entry) {
105
+ var table = document.createElement('table');
106
+ table.className = 'bf-table__table';
107
+ var head = table.createTHead().insertRow();
108
+ data.columns.forEach(function (name) {
109
+ var th = document.createElement('th');
110
+ th.textContent = name;
111
+ head.appendChild(th);
112
+ });
113
+ var rows = table.createTBody();
114
+ entry.rows.forEach(function (values) {
115
+ var tr = rows.insertRow();
116
+ values.forEach(function (value) { tr.insertCell().textContent = value; });
117
+ });
118
+ var scroll = document.createElement('div');
119
+ scroll.className = 'bf-table__scroll';
120
+ scroll.appendChild(table);
121
+ body.appendChild(scroll);
122
+ if (entry.total > entry.rows.length) {
123
+ var note = document.createElement('p');
124
+ note.className = 'bf-cal__panel-note';
125
+ note.textContent = 'Showing the first ' + entry.rows.length + ' of ' + entry.total + ' rows.';
126
+ body.appendChild(note);
127
+ }
128
+ }
129
+ panel.hidden = false;
130
+ }
131
+
132
+ figure.querySelectorAll('rect.bf-cal__day[role="button"], rect.bf-cal__hour[role="button"]').forEach(function (cell) {
133
+ cell.addEventListener('click', function () { open(cell); });
134
+ cell.addEventListener('keydown', function (e) {
135
+ if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); open(cell); }
136
+ });
137
+ });
138
+ panel.querySelector('.bf-cal__panel-close').addEventListener('click', function () { panel.hidden = true; });
139
+ });
140
+ })();
@@ -706,13 +706,18 @@ body {
706
706
  }
707
707
 
708
708
  /* ── lab.CalendarHeatmap ─────────────────────────────────────────────────── */
709
- .bf-calendar { margin: 0; }
709
+ .bf-calendar { margin: 0; min-width: 0; } /* may shrink inside a Group column (#106) */
710
710
  .bf-cal__calendar + .bf-cal__calendar { margin-top: 1rem; }
711
711
  .bf-cal__group { font-weight: 600; font-size: 0.9rem; margin-bottom: 0.25rem; }
712
712
  .bf-cal__scroll { overflow-x: auto; }
713
- .bf-cal__days, .bf-cal__hours { display: block; max-width: none; font-family: var(--bf-font); }
714
- .bf-cal__days text, .bf-cal__hours text { fill: var(--bf-muted); font-size: 9px; }
715
- .bf-cal__days .bf-cal__year { fill: var(--bf-text); font-weight: 700; font-size: 10px; }
713
+ .bf-cal__days, .bf-cal__hours { display: block; font-family: var(--bf-font);
714
+ /* Fit the width available (report or Group column) from 0.6x to 2x the natural size (#106);
715
+ below 0.6x the calendar scrolls inside its block. */
716
+ width: 100%; height: auto; min-width: calc(0.6 * var(--bf-cal-w)); max-width: calc(2 * var(--bf-cal-w)); }
717
+ /* calendar.js sets --bf-cal-text so labels change size at half the cells' rate; without it,
718
+ labels scale with the SVG. */
719
+ .bf-cal__days text, .bf-cal__hours text { fill: var(--bf-muted); font-size: calc(9px * var(--bf-cal-text, 1)); }
720
+ .bf-cal__days .bf-cal__year { fill: var(--bf-text); font-weight: 700; font-size: calc(10px * var(--bf-cal-text, 1)); }
716
721
  .bf-cal__year-line { stroke: var(--bf-muted); stroke-dasharray: 2 2; }
717
722
  .bf-cal__day--zero, .bf-cal__hour--zero { fill: var(--bf-border); }
718
723
  .bf-cal__day--empty, .bf-cal__hour--empty { fill: none; stroke: var(--bf-border); stroke-width: 1; stroke-dasharray: 2 1.5; }
@@ -720,15 +725,24 @@ body {
720
725
  .bf-cal__day--below { stroke: #dc2626; stroke-width: 1.5; stroke-dasharray: none; }
721
726
  .bf-cal__event rect { fill: color-mix(in oklab, var(--bf-accent) 25%, transparent); stroke: var(--bf-accent); }
722
727
  .bf-cal__event circle { fill: var(--bf-accent); }
723
- .bf-cal__event text { fill: var(--bf-text); font-size: 9px; }
728
+ .bf-cal__event text { fill: var(--bf-text); font-size: calc(9px * var(--bf-cal-text, 1)); }
724
729
  .bf-cal__legend { display: flex; flex-wrap: wrap; gap: 0.25rem 1.25rem; align-items: center;
725
730
  margin-top: 0.5rem; font-size: 0.75rem; color: var(--bf-muted); }
726
731
  .bf-cal__legend-item { display: inline-flex; align-items: center; gap: 3px; }
727
- .bf-cal__swatch { display: inline-block; width: 11px; height: 11px; border-radius: 2px; }
732
+ .bf-cal__swatch { display: inline-block; width: max(8px, 11px * var(--bf-cal-k, 1));
733
+ height: max(8px, 11px * var(--bf-cal-k, 1));
734
+ border-radius: 2px; }
728
735
  .bf-cal__swatch--zero { background: var(--bf-border); }
729
736
  .bf-cal__swatch--empty { border: 1px dashed var(--bf-border); }
730
737
  .bf-cal__swatch--below { border: 1.5px solid #dc2626; }
731
738
  .bf-calendar rect[role="button"] { cursor: pointer; outline: none; }
739
+ /* Hover tooltip (#109), positioned by calendar.js in window coordinates. */
740
+ .bf-cal__tip { position: fixed; z-index: 20; max-width: 260px; padding: 0.35rem 0.55rem;
741
+ background: var(--bf-text); color: var(--bf-bg); font-size: 0.75rem; line-height: 1.45;
742
+ border-radius: 0.375rem; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18); pointer-events: none; }
743
+ .bf-cal__tip[hidden] { display: none; }
744
+ .bf-cal__tip strong { display: block; font-weight: 600; }
745
+ .bf-calendar rect.bf-cal__day:hover, .bf-calendar rect.bf-cal__hour:hover { stroke: var(--bf-text); stroke-width: 1.5; }
732
746
  .bf-calendar rect[role="button"]:focus-visible { stroke: var(--bf-accent); stroke-width: 2; }
733
747
  .bf-cal__panel { margin-top: 0.75rem; border: 1px solid var(--bf-border); border-radius: var(--bf-radius);
734
748
  padding: 0.6rem 0.75rem; }
@@ -777,4 +791,8 @@ html.bf-printing .bf-print-label {
777
791
  .bf-blocks > .bf-select:only-child > .bf-select__panel + .bf-print-label { break-before: page; }
778
792
  .bf-plot, .bf-alert, .bf-bignumber, .bf-formula, .bf-code, .bf-profile__card,
779
793
  .bf-group:has(> .bf-bignumber) { break-inside: avoid; }
794
+ /* A calendar may shrink to fit the sheet instead of being clipped (#106). */
795
+ .bf-cal__days, .bf-cal__hours { min-width: 0; --bf-cal-text: 1; }
796
+ .bf-cal__swatch { width: 11px; height: 11px; }
797
+ .bf-cal__tip { display: none !important; }
780
798
  }
@@ -0,0 +1,242 @@
1
+ """lab.CalendarHeatmap as a reader sees it (#19)."""
2
+ from __future__ import annotations
3
+
4
+ import pandas as pd
5
+ import pytest
6
+ from playwright.sync_api import Page
7
+
8
+ import briefing as bf
9
+ from tests.test_browser.conftest import Viewer
10
+
11
+ # The hour view is deprecated (#111) but still supported: its tests keep running without the warning.
12
+ pytestmark = pytest.mark.filterwarnings("ignore:CalendarHeatmap. the hour view:DeprecationWarning")
13
+
14
+
15
+ @pytest.mark.parametrize("theme", ["default", "dark"])
16
+ def test_zero_no_data_and_below_target_are_visibly_different(viewer: Viewer, df_pipeline_log: pd.DataFrame,
17
+ theme: str) -> None:
18
+ formatting = bf.Formatting.dark() if theme == "dark" else bf.Formatting()
19
+ block = bf.lab.CalendarHeatmap(df_pipeline_log, date="run_at", value="rows", expected=500)
20
+ page = viewer.open(bf.Briefing(block), formatting=formatting)
21
+
22
+ def look(day: str) -> dict[str, str]:
23
+ style: dict[str, str] = page.locator(f'rect[data-date="{day}"]').evaluate(
24
+ "e => { const s = getComputedStyle(e); return {fill: s.fill, stroke: s.stroke, dash: s.strokeDasharray}; }")
25
+ return style
26
+
27
+ background = page.evaluate("() => getComputedStyle(document.body).backgroundColor")
28
+ zero, empty, ok = look("2025-12-04"), look("2026-01-17"), look("2025-11-18")
29
+ assert zero["fill"] not in ("none", background) # a zero is a filled grey cell
30
+ assert empty["fill"] == "none" # no data is an outline only
31
+ assert look("2026-01-03")["stroke"] == "rgb(220, 38, 38)" # a failed run is flagged red
32
+ assert ok["stroke"] in ("none", "") # a normal day has no outline
33
+
34
+
35
+ def _year() -> pd.DataFrame:
36
+ """One run a day through 2025: 53 week columns, a calendar 774 px wide at its natural size."""
37
+ days = pd.date_range("2025-01-01", "2025-12-31", freq="D")
38
+ return pd.DataFrame({"run_at": days, "rows": range(len(days))})
39
+
40
+
41
+ def _width(page: Page, selector: str) -> float:
42
+ box = page.locator(selector).first.bounding_box()
43
+ assert box is not None
44
+ return float(box["width"])
45
+
46
+
47
+ def test_a_year_fills_the_width_of_its_block(viewer: Viewer) -> None:
48
+ page = viewer.open(bf.Briefing(bf.lab.CalendarHeatmap(_year(), date="run_at")))
49
+ assert _width(page, "svg.bf-cal__days") == pytest.approx(_width(page, ".bf-cal__scroll"), abs=1)
50
+ assert _width(page, 'rect[data-date="2025-06-02"]') > 14 # cells grew from their natural 11 px
51
+
52
+
53
+ def test_a_short_range_grows_to_twice_its_natural_size(viewer: Viewer, df_pipeline_log: pd.DataFrame) -> None:
54
+ page = viewer.open(bf.Briefing(bf.lab.CalendarHeatmap(df_pipeline_log, date="run_at", views=("days", "hours"))))
55
+ natural = float(page.locator("svg.bf-cal__days").get_attribute("width") or 0)
56
+ assert _width(page, "svg.bf-cal__days") == pytest.approx(2 * natural, abs=1)
57
+ assert _width(page, 'rect[data-date="2026-01-05"]') == pytest.approx(22, abs=0.5)
58
+ page.get_by_role("tab", name="Hours").click() # a hidden view is measured once it is shown
59
+ natural = float(page.locator("svg.bf-cal__hours").get_attribute("width") or 0)
60
+ assert _width(page, "svg.bf-cal__hours") == pytest.approx(2 * natural, abs=1)
61
+
62
+
63
+ def test_labels_grow_at_half_the_rate_and_swatches_match_cells(viewer: Viewer,
64
+ df_pipeline_log: pd.DataFrame) -> None:
65
+ page = viewer.open(bf.Briefing(bf.lab.CalendarHeatmap(df_pipeline_log, date="run_at")))
66
+ label = page.locator("svg.bf-cal__days text.bf-cal__weekday").first.bounding_box()
67
+ assert label is not None and label["height"] < 20 # 9 px text at 2x would be about 24 px tall
68
+ cell = _width(page, 'rect[data-date="2026-01-05"]')
69
+ assert _width(page, ".bf-cal__swatch:not(.bf-cal__swatch--event-day)") == pytest.approx(cell, abs=0.5)
70
+
71
+
72
+ def test_a_calendar_in_a_group_fits_its_column(viewer: Viewer, df_pipeline_log: pd.DataFrame) -> None:
73
+ year = bf.lab.CalendarHeatmap(_year(), date="run_at")
74
+ page = viewer.open(bf.Briefing(bf.Group(year, bf.lab.CalendarHeatmap(df_pipeline_log, date="run_at"), columns=2)))
75
+ columns = page.locator(".bf-group > .bf-calendar")
76
+ first, second = columns.nth(0).bounding_box(), columns.nth(1).bounding_box()
77
+ assert first is not None and second is not None
78
+ assert first["width"] == pytest.approx(second["width"], abs=1) # the year no longer widens its column
79
+ assert _width(page, "svg.bf-cal__days") == pytest.approx(first["width"], abs=1)
80
+ assert _width(page, 'rect[data-date="2025-06-02"]') < 11 # shrunk to fit
81
+ assert page.evaluate("() => document.documentElement.scrollWidth <= window.innerWidth")
82
+
83
+
84
+ def test_a_narrow_screen_shrinks_then_scrolls(viewer: Viewer) -> None:
85
+ viewer.page.set_viewport_size({"width": 375, "height": 800})
86
+ page = viewer.open(bf.Briefing(bf.lab.CalendarHeatmap(_year(), date="run_at")))
87
+ assert _width(page, 'rect[data-date="2025-06-02"]') == pytest.approx(0.6 * 11, abs=0.3) # the floor
88
+ overflow = page.locator(".bf-cal__scroll").evaluate("e => e.scrollWidth > e.clientWidth")
89
+ assert overflow
90
+ assert page.evaluate("() => document.documentElement.scrollWidth <= window.innerWidth") # inside the block
91
+ label = page.locator("svg.bf-cal__days text.bf-cal__weekday").first.bounding_box()
92
+ assert label is not None and label["height"] > 6 # labels shrink at half the rate
93
+
94
+
95
+ def test_a_year_prints_without_clipping(viewer: Viewer) -> None:
96
+ viewer.page.set_viewport_size({"width": 794, "height": 1123}) # A4 at 96 dpi
97
+ page = viewer.open(bf.Briefing(bf.lab.CalendarHeatmap(_year(), date="run_at")))
98
+ page.emulate_media(media="print")
99
+ page.evaluate("window.dispatchEvent(new Event('beforeprint'))")
100
+ scroll = page.locator(".bf-cal__scroll").bounding_box()
101
+ last = page.locator('rect[data-date="2025-12-31"]').bounding_box()
102
+ assert scroll is not None and last is not None
103
+ assert last["x"] + last["width"] <= scroll["x"] + scroll["width"] + 0.5
104
+
105
+
106
+ def test_a_tab_switches_between_the_day_and_hour_views(viewer: Viewer, df_pipeline_log: pd.DataFrame) -> None:
107
+ page = viewer.open(bf.Briefing(bf.lab.CalendarHeatmap(df_pipeline_log, date="run_at", views=("days", "hours"))))
108
+ days, hours = page.locator("svg.bf-cal__days"), page.locator("svg.bf-cal__hours")
109
+ assert days.is_visible() and not hours.is_visible()
110
+ page.get_by_role("tab", name="Hours").click()
111
+ assert hours.is_visible() and not days.is_visible()
112
+ assert page.locator("rect.bf-cal__hour").count() == 7 * 24
113
+
114
+
115
+ def test_hour_view_labels_are_small(viewer: Viewer, df_pipeline_log: pd.DataFrame) -> None:
116
+ page = viewer.open(bf.Briefing(bf.lab.CalendarHeatmap(df_pipeline_log, date="run_at", views=("hours",))))
117
+ box = page.locator("svg.bf-cal__hours text").first.bounding_box()
118
+ assert box is not None and box["height"] < 20 # not scaled up with the 2x grid
119
+
120
+
121
+ def test_clicking_a_day_lists_its_rows(viewer: Viewer, df_pipeline_log: pd.DataFrame) -> None:
122
+ page = viewer.open(bf.Briefing(bf.lab.CalendarHeatmap(df_pipeline_log, date="run_at", on_click="rows")))
123
+ panel = page.locator(".bf-cal__panel")
124
+ assert not panel.is_visible()
125
+ page.locator('rect[data-date="2025-12-07"]').click()
126
+ assert panel.is_visible()
127
+ assert "2025-12-07" in panel.locator(".bf-cal__panel-title").inner_text()
128
+ assert panel.locator("tbody tr").count() == 2
129
+ assert panel.locator("thead th").all_inner_texts() == ["run_at", "team", "rows"]
130
+ panel.get_by_role("button", name="Close").click()
131
+ assert not panel.is_visible()
132
+
133
+
134
+ def test_keyboard_opens_the_rows_of_an_hour(viewer: Viewer, df_pipeline_log: pd.DataFrame) -> None:
135
+ block = bf.lab.CalendarHeatmap(df_pipeline_log, date="run_at", views=("hours",), on_click="rows")
136
+ page = viewer.open(bf.Briefing(block))
137
+ page.locator('rect[data-hour="0-6"]').focus()
138
+ page.keyboard.press("Enter")
139
+ assert "Mon 06:00" in page.locator(".bf-cal__panel-title").inner_text()
140
+
141
+
142
+ def test_capped_cells_say_so_and_values_stay_text(viewer: Viewer) -> None:
143
+ df = pd.DataFrame({"run_at": [pd.Timestamp("2026-01-05 09:00")] * 120,
144
+ "note": ["<img src=x onerror=window.__hit=1>"] * 120})
145
+ page = viewer.open(bf.Briefing(bf.lab.CalendarHeatmap(df, date="run_at", on_click="rows")))
146
+ page.locator('rect[data-date="2026-01-05"]').click()
147
+ panel = page.locator(".bf-cal__panel")
148
+ assert panel.locator("tbody tr").count() == 50
149
+ assert "first 50 of 120 rows" in panel.inner_text()
150
+ assert panel.locator("img").count() == 0 and page.evaluate("() => window.__hit") is None
151
+
152
+
153
+ # ── hover tooltip (#109) ──────────────────────────────────────────────────────
154
+
155
+
156
+ def _tip_box(page: Page) -> dict[str, float]:
157
+ tip = page.locator(".bf-cal__tip")
158
+ assert tip.is_visible()
159
+ box = tip.bounding_box()
160
+ assert box is not None
161
+ return {"x": box["x"], "y": box["y"], "width": box["width"], "height": box["height"]}
162
+
163
+
164
+ def test_hovering_a_day_shows_its_exact_value_at_once(viewer: Viewer) -> None:
165
+ df = pd.DataFrame({"day": pd.to_datetime(["2026-01-05", "2026-01-06"]), "amount": [12345.67, 3.0]})
166
+ page = viewer.open(bf.Briefing(bf.lab.CalendarHeatmap(df, date="day", value="amount")))
167
+ tip = page.locator(".bf-cal__tip")
168
+ assert not tip.is_visible()
169
+ cell = page.locator('rect[data-date="2026-01-05"]')
170
+ cell.hover()
171
+ assert tip.is_visible() # no delay: visible as soon as the pointer is over the cell
172
+ assert tip.locator("strong").inner_text() == "Mon 2026-01-05"
173
+ assert "12,345.67 amount" in tip.inner_text()
174
+ cell_box, box = cell.bounding_box(), _tip_box(page)
175
+ assert cell_box is not None and box["y"] + box["height"] <= cell_box["y"] # above the cell
176
+ page.mouse.move(0, 0)
177
+ assert not tip.is_visible()
178
+
179
+
180
+ def test_the_native_tooltip_no_longer_doubles_up(viewer: Viewer, df_pipeline_log: pd.DataFrame) -> None:
181
+ page = viewer.open(bf.Briefing(bf.lab.CalendarHeatmap(df_pipeline_log, date="run_at", views=("days", "hours"))))
182
+ assert page.locator(".bf-calendar svg title").count() == 0
183
+ assert page.locator("rect.bf-cal__hour[data-tip]").count() == 7 * 24
184
+
185
+
186
+ def test_hour_cells_and_event_bands_have_tooltips(viewer: Viewer, df_pipeline_log: pd.DataFrame) -> None:
187
+ events = pd.DataFrame({"start": ["2025-12-22"], "end": ["2026-01-02"], "label": ["Freeze"]})
188
+ page = viewer.open(bf.Briefing(bf.lab.CalendarHeatmap(df_pipeline_log, date="run_at", events=events,
189
+ views=("days", "hours"))))
190
+ page.locator("g.bf-cal__event").first.hover()
191
+ assert "Freeze" in page.locator(".bf-cal__tip").inner_text()
192
+ page.get_by_role("tab", name="Hours").click()
193
+ page.locator('rect[data-hour="0-6"]').hover()
194
+ assert page.locator(".bf-cal__tip strong").inner_text().startswith("Mon 06:00")
195
+
196
+
197
+ def test_keyboard_focus_and_tap_show_the_tooltip(viewer: Viewer, df_pipeline_log: pd.DataFrame) -> None:
198
+ page = viewer.open(bf.Briefing(bf.lab.CalendarHeatmap(df_pipeline_log, date="run_at", on_click="rows")))
199
+ cell = page.locator('rect[data-date="2025-12-07"]')
200
+ cell.focus()
201
+ assert page.locator(".bf-cal__tip strong").inner_text() == "Sun 2025-12-07"
202
+ assert cell.get_attribute("aria-label") is not None # clickable cells keep their name
203
+ page.keyboard.press("Escape")
204
+ assert not page.locator(".bf-cal__tip").is_visible()
205
+ other = page.locator('rect[data-date="2025-12-08"]')
206
+ other.dispatch_event("pointerdown", {"pointerType": "touch", "bubbles": True})
207
+ assert page.locator(".bf-cal__tip strong").inner_text() == "Mon 2025-12-08"
208
+ cell.click() # the rows panel still opens, titled from the same text
209
+ assert "2025-12-07" in page.locator(".bf-cal__panel-title").inner_text()
210
+
211
+
212
+ def test_the_tooltip_stays_inside_the_window(viewer: Viewer) -> None:
213
+ viewer.page.set_viewport_size({"width": 375, "height": 800})
214
+ days = pd.date_range("2025-01-01", "2025-12-31", freq="D")
215
+ page = viewer.open(bf.Briefing(bf.lab.CalendarHeatmap(pd.DataFrame({"run_at": days}), date="run_at")))
216
+ page.locator('rect[data-date="2025-01-06"]').scroll_into_view_if_needed()
217
+ page.evaluate("() => window.scrollTo(0, document.querySelector('svg.bf-cal__days').getBoundingClientRect().top"
218
+ " + window.scrollY - 30)") # the first row sits right under the top of the window
219
+ cell = page.locator('rect[data-date="2025-01-06"]')
220
+ cell.hover()
221
+ cell_box, box = cell.bounding_box(), _tip_box(page)
222
+ assert cell_box is not None and box["y"] >= cell_box["y"] + cell_box["height"] # flipped below the cell
223
+ assert box["x"] >= 0 and box["x"] + box["width"] <= 375
224
+
225
+
226
+ def test_the_tooltip_never_prints(viewer: Viewer, df_pipeline_log: pd.DataFrame) -> None:
227
+ page = viewer.open(bf.Briefing(bf.lab.CalendarHeatmap(df_pipeline_log, date="run_at")))
228
+ page.locator('rect[data-date="2025-12-07"]').hover()
229
+ page.emulate_media(media="print")
230
+ assert not page.locator(".bf-cal__tip").is_visible()
231
+
232
+
233
+ def test_weekday_labels_do_not_overlap_when_shrunk(viewer: Viewer) -> None:
234
+ viewer.page.set_viewport_size({"width": 375, "height": 800}) # a year at the 0.6x floor (#113)
235
+ page = viewer.open(bf.Briefing(bf.lab.CalendarHeatmap(_year(), date="run_at")))
236
+ boxes = page.locator("svg.bf-cal__days text.bf-cal__weekday").evaluate_all(
237
+ "els => els.map(e => { const b = e.getBoundingClientRect(); return [b.top, b.height]; })")
238
+ assert len(boxes) == 7
239
+ boxes.sort()
240
+ # A text box includes line spacing (about 1.25x the glyphs); the glyphs stay apart when the
241
+ # rows are at least 0.8 of a box apart.
242
+ assert all(below[0] - above[0] >= 0.8 * above[1] for above, below in zip(boxes, boxes[1:], strict=False))