briefing 0.2.1__tar.gz → 0.2.3__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.
- {briefing-0.2.1 → briefing-0.2.3}/CHANGELOG.md +43 -1
- {briefing-0.2.1 → briefing-0.2.3}/PKG-INFO +1 -1
- {briefing-0.2.1 → briefing-0.2.3}/src/briefing/__init__.py +1 -1
- {briefing-0.2.1 → briefing-0.2.3}/src/briefing/blocks/layout.py +21 -7
- {briefing-0.2.1 → briefing-0.2.3}/src/briefing/lab/_blocks.py +15 -1
- {briefing-0.2.1 → briefing-0.2.3}/src/briefing/lab/_render_calendar.py +17 -6
- {briefing-0.2.1 → briefing-0.2.3}/src/briefing/lab/static/calendar.js +57 -2
- {briefing-0.2.1 → briefing-0.2.3}/src/briefing/renderers/html.py +2 -2
- {briefing-0.2.1 → briefing-0.2.3}/src/briefing/renderers/table.py +6 -3
- {briefing-0.2.1 → briefing-0.2.3}/src/briefing/static/report.css +8 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/contract.py +1 -1
- {briefing-0.2.1 → briefing-0.2.3}/tests/test_blocks/test_layout.py +17 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/test_browser/test_calendar.py +95 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/test_contract.py +9 -2
- {briefing-0.2.1 → briefing-0.2.3}/tests/test_deprecations.py +21 -1
- {briefing-0.2.1 → briefing-0.2.3}/tests/test_docs_gallery.py +1 -12
- {briefing-0.2.1 → briefing-0.2.3}/tests/test_lab/test_calendar.py +44 -2
- {briefing-0.2.1 → briefing-0.2.3}/tests/test_renderers/test_table.py +12 -0
- {briefing-0.2.1 → briefing-0.2.3}/.gitignore +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/LICENSE +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/README.md +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/noxfile.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/pyproject.toml +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/src/briefing/__main__.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/src/briefing/_cli.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/src/briefing/_error.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/src/briefing/_frames.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/src/briefing/_preview.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/src/briefing/blocks/__init__.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/src/briefing/blocks/asset.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/src/briefing/blocks/banner.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/src/briefing/blocks/base.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/src/briefing/blocks/text.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/src/briefing/export/__init__.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/src/briefing/export/_image.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/src/briefing/export/_pdf.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/src/briefing/export/_render.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/src/briefing/lab/__init__.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/src/briefing/lab/_render_datadive.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/src/briefing/lab/_render_profile.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/src/briefing/lab/static/lab.js +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/src/briefing/py.typed +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/src/briefing/renderers/__init__.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/src/briefing/renderers/formatting.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/src/briefing/renderers/formula.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/src/briefing/renderers/normalize.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/src/briefing/renderers/plot.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/src/briefing/renderers/registry.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/src/briefing/renderers/script_json.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/src/briefing/static/export.css +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/src/briefing/static/export.js +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/src/briefing/static/report.js +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/src/briefing/templates/report.html.j2 +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/__init__.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/banner_images.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/compat_reports.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/conftest.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/html_helpers.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/image_helpers.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/pdf_reader.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/snapshots/compat_0_1_2/blocks.body.html +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/snapshots/compat_0_1_2/pages.body.html +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/test_blocks/__init__.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/test_blocks/test_banner.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/test_blocks/test_base.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/test_blocks/test_text.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/test_browser/__init__.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/test_browser/conftest.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/test_browser/test_banner.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/test_browser/test_bignumber.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/test_browser/test_cli_export.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/test_browser/test_code.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/test_browser/test_datadive.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/test_browser/test_datatable.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/test_browser/test_export_image.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/test_browser/test_export_menu.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/test_browser/test_export_pdf.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/test_browser/test_formula.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/test_browser/test_layout.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/test_browser/test_notebook.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/test_browser/test_plots.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/test_browser/test_print.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/test_browser/test_spacing.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/test_browser/test_text.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/test_browser/test_toggle_theme.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/test_cli.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/test_compat.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/test_docstrings.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/test_export.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/test_frames.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/test_lab/__init__.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/test_lab/test_datadive.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/test_lab/test_lab_boundary.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/test_lab/test_profile.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/test_no_viz_deps.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/test_pdf_reader.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/test_preview.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/test_readme.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/test_renderers/__init__.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/test_renderers/test_export_menu.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/test_renderers/test_formula.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/test_renderers/test_html.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/test_renderers/test_normalize.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/test_renderers/test_plot.py +0 -0
- {briefing-0.2.1 → briefing-0.2.3}/tests/test_renderers/test_reproducible.py +0 -0
|
@@ -10,6 +10,46 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
10
10
|
|
|
11
11
|
## [Unreleased]
|
|
12
12
|
|
|
13
|
+
## [0.2.3] - 2026-11-07
|
|
14
|
+
|
|
15
|
+
### Fixed
|
|
16
|
+
|
|
17
|
+
- `Group` rejects a `columns` that isn't a whole number of 1 or more, and `widths` that
|
|
18
|
+
aren't positive numbers, with a `BriefingError`. They used to be accepted and wrote invalid
|
|
19
|
+
CSS, so the browser dropped the layout without saying so (#98).
|
|
20
|
+
- `Table` with a pandas `Styler` gives the same bytes on every run: its ids and CSS selectors
|
|
21
|
+
come from the report instead of the random uuid pandas picks. The `Styler` you pass keeps
|
|
22
|
+
its own uuid (#101).
|
|
23
|
+
|
|
24
|
+
## [0.2.2] - 2026-11-04
|
|
25
|
+
|
|
26
|
+
### Added
|
|
27
|
+
|
|
28
|
+
- `lab.CalendarHeatmap`: hovering a day, an hour or an event band shows a tooltip at once,
|
|
29
|
+
styled with the theme: the date (now with its weekday) in bold, the exact value, "below
|
|
30
|
+
target …" and the day's events. It also opens on keyboard focus and on tap, stays inside
|
|
31
|
+
the window, and never prints. The browser's slower built-in tooltip no longer doubles up;
|
|
32
|
+
without JavaScript it is still there (#109).
|
|
33
|
+
|
|
34
|
+
### Changed
|
|
35
|
+
|
|
36
|
+
- `lab.CalendarHeatmap` names every weekday row of the day calendar, not just Mon, Wed
|
|
37
|
+
and Fri (#113).
|
|
38
|
+
|
|
39
|
+
### Deprecated
|
|
40
|
+
|
|
41
|
+
- `lab.CalendarHeatmap`'s hour view, `views=("hours",)` or `("days", "hours")`, raises a
|
|
42
|
+
`DeprecationWarning`. It still works; a dedicated time-pattern heatmap (weekday × hour,
|
|
43
|
+
weekday × month, …) is planned to replace it, and the hour view will be removed in 0.4.0
|
|
44
|
+
at the earliest, never before that replacement ships (#111).
|
|
45
|
+
|
|
46
|
+
### Fixed
|
|
47
|
+
|
|
48
|
+
- `lab.CalendarHeatmap(week_start="sunday")` put each weekday label one row off ("Sun"
|
|
49
|
+
on the Monday row); every label now sits on its own row (#113).
|
|
50
|
+
- `lab.CalendarHeatmap` shows values exactly: a non-integer of 10,000 or more read
|
|
51
|
+
`1.235e+04` in the tooltip and the legend; it now reads `12,345.67` (#109).
|
|
52
|
+
|
|
13
53
|
## [0.2.1] - 2026-11-04
|
|
14
54
|
|
|
15
55
|
### Changed
|
|
@@ -211,7 +251,9 @@ First public release.
|
|
|
211
251
|
inherits its base's renderer.
|
|
212
252
|
- Ships inline type hints (`py.typed`). Python 3.11+.
|
|
213
253
|
|
|
214
|
-
[Unreleased]: https://github.com/jeanmidevacc/briefing/compare/v0.2.
|
|
254
|
+
[Unreleased]: https://github.com/jeanmidevacc/briefing/compare/v0.2.3...HEAD
|
|
255
|
+
[0.2.3]: https://github.com/jeanmidevacc/briefing/compare/v0.2.2...v0.2.3
|
|
256
|
+
[0.2.2]: https://github.com/jeanmidevacc/briefing/compare/v0.2.1...v0.2.2
|
|
215
257
|
[0.2.1]: https://github.com/jeanmidevacc/briefing/compare/v0.2.0...v0.2.1
|
|
216
258
|
[0.2.0]: https://github.com/jeanmidevacc/briefing/compare/v0.1.2...v0.2.0
|
|
217
259
|
[0.1.2]: https://github.com/jeanmidevacc/briefing/compare/v0.1.1...v0.1.2
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: briefing
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.3
|
|
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
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"""Layout and container blocks: Group, Select, Toggle, Page, Briefing."""
|
|
2
2
|
from __future__ import annotations
|
|
3
3
|
|
|
4
|
+
import math
|
|
5
|
+
import numbers
|
|
4
6
|
import typing as t
|
|
5
7
|
import warnings
|
|
6
8
|
from collections.abc import Sequence
|
|
@@ -37,6 +39,12 @@ class VAlign(StrEnum):
|
|
|
37
39
|
BOTTOM = "bottom"
|
|
38
40
|
|
|
39
41
|
|
|
42
|
+
def _is_positive_number(value: object, *, whole: bool = False) -> bool:
|
|
43
|
+
"""Whether *value* is a finite number above zero; ``True`` and ``False`` don't count."""
|
|
44
|
+
kind = numbers.Integral if whole else numbers.Real
|
|
45
|
+
return isinstance(value, kind) and not isinstance(value, bool) and 0 < float(value) < math.inf
|
|
46
|
+
|
|
47
|
+
|
|
40
48
|
# ── layout blocks ─────────────────────────────────────────────────────────────
|
|
41
49
|
|
|
42
50
|
|
|
@@ -49,8 +57,8 @@ class Group(ContainerBlock):
|
|
|
49
57
|
Args:
|
|
50
58
|
*arg_blocks: The child blocks; strings become ``Text`` and dataframes ``DataTable``.
|
|
51
59
|
blocks: The children as a list, instead of positional arguments.
|
|
52
|
-
columns: Number of grid columns.
|
|
53
|
-
widths: Relative column widths, one per column (e.g. ``[2, 1]``).
|
|
60
|
+
columns: Number of grid columns, a whole number of 1 or more.
|
|
61
|
+
widths: Relative column widths, positive numbers, one per column (e.g. ``[2, 1]``).
|
|
54
62
|
valign: Vertical alignment of the cells: ``"top"``, ``"center"`` or ``"bottom"``.
|
|
55
63
|
name: Stable block id (letters, digits, ``_`` and ``-``), for referencing the block.
|
|
56
64
|
label: Tab or dropdown label when the block is inside a ``Select``.
|
|
@@ -73,12 +81,18 @@ class Group(ContainerBlock):
|
|
|
73
81
|
name: BlockId | None = None,
|
|
74
82
|
label: str | None = None,
|
|
75
83
|
) -> None:
|
|
76
|
-
if
|
|
77
|
-
raise BriefingError(
|
|
78
|
-
|
|
79
|
-
)
|
|
84
|
+
if not _is_positive_number(columns, whole=True):
|
|
85
|
+
raise BriefingError(f"Group 'columns' must be a whole number of 1 or more, not {columns!r}.")
|
|
86
|
+
if widths is not None:
|
|
87
|
+
if len(widths) != columns:
|
|
88
|
+
raise BriefingError(
|
|
89
|
+
f"Group 'widths' length ({len(widths)}) must match 'columns' ({columns})."
|
|
90
|
+
)
|
|
91
|
+
for width in widths:
|
|
92
|
+
if not _is_positive_number(width):
|
|
93
|
+
raise BriefingError(f"Group 'widths' must be positive numbers such as [2, 1], not {width!r}.")
|
|
80
94
|
super().__init__(*arg_blocks, blocks=blocks, name=name, label=label)
|
|
81
|
-
self.columns = columns
|
|
95
|
+
self.columns = int(columns)
|
|
82
96
|
self.widths = widths
|
|
83
97
|
self.valign = VAlign(valign)
|
|
84
98
|
|
|
@@ -155,6 +155,15 @@ 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
|
|
|
@@ -163,6 +172,7 @@ class CalendarHeatmap(Block):
|
|
|
163
172
|
continuously across a year boundary, with month labels and a year marker.
|
|
164
173
|
The calendar fits the width available (the report or a ``Group`` column),
|
|
165
174
|
between 0.6x and 2x its natural size; below that it scrolls sideways.
|
|
175
|
+
Hovering a cell shows its date and exact value.
|
|
166
176
|
|
|
167
177
|
Args:
|
|
168
178
|
df: The data, as any dataframe briefing accepts (pandas, polars, pyarrow…).
|
|
@@ -173,7 +183,9 @@ class CalendarHeatmap(Block):
|
|
|
173
183
|
group: Column to split by: one calendar per group, stacked, on one shared colour scale.
|
|
174
184
|
views: ``("days",)``, ``("hours",)`` or ``("days", "hours")``: the day calendar
|
|
175
185
|
and/or a 7 × 24 weekday-by-hour grid; with both, tabs switch between them.
|
|
176
|
-
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).
|
|
177
189
|
tz: A time zone such as ``"America/Montreal"``. Converts timezone-aware
|
|
178
190
|
timestamps only; naive timestamps and plain dates are taken as already
|
|
179
191
|
local, so a date at midnight never moves to the previous day.
|
|
@@ -241,6 +253,8 @@ class CalendarHeatmap(Block):
|
|
|
241
253
|
)
|
|
242
254
|
if tz is not None:
|
|
243
255
|
_check_tz(tz)
|
|
256
|
+
if "hours" in views:
|
|
257
|
+
warnings.warn(HOURS_VIEW_DEPRECATION, DeprecationWarning, stacklevel=2)
|
|
244
258
|
if "hours" in views and not _has_times(frame[date]):
|
|
245
259
|
raise BriefingError(
|
|
246
260
|
f"CalendarHeatmap: the hour view needs a time of day, but {date!r} holds dates only. "
|
|
@@ -188,7 +188,18 @@ def _group_attr(block: CalendarHeatmap, group: str | None) -> str:
|
|
|
188
188
|
|
|
189
189
|
|
|
190
190
|
def _fmt(v: float) -> str:
|
|
191
|
-
|
|
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}"
|
|
192
203
|
|
|
193
204
|
|
|
194
205
|
def _what(block: CalendarHeatmap) -> str:
|
|
@@ -227,9 +238,8 @@ def _days_svg(
|
|
|
227
238
|
height = _TOP + grid_h + (len(lanes) * _LANE + 6 if lanes else 0)
|
|
228
239
|
parts = [_svg_open("bf-cal__days", width, height, "Calendar heatmap")]
|
|
229
240
|
|
|
230
|
-
for
|
|
231
|
-
|
|
232
|
-
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
|
|
233
243
|
parts.append(f'<text class="bf-cal__weekday" x="0" y="{y}">{name}</text>')
|
|
234
244
|
|
|
235
245
|
year_shown: int | None = None
|
|
@@ -256,16 +266,17 @@ def _days_svg(
|
|
|
256
266
|
col, row = pos(day)
|
|
257
267
|
x, y = _LEFT + col * _STEP, _TOP + row * _STEP
|
|
258
268
|
value, goal = data.get(day), target(day)
|
|
269
|
+
when = f"{_WEEKDAYS[day.weekday()]} {day.isoformat()}"
|
|
259
270
|
cls = ["bf-cal__day"]
|
|
260
271
|
fill = ""
|
|
261
272
|
if value is None:
|
|
262
273
|
cls.append("bf-cal__day--empty")
|
|
263
|
-
tip = f"{
|
|
274
|
+
tip = f"{when} · no data"
|
|
264
275
|
else:
|
|
265
276
|
fill, extra = colour(value)
|
|
266
277
|
if extra:
|
|
267
278
|
cls.append(extra)
|
|
268
|
-
tip = f"{
|
|
279
|
+
tip = f"{when} · {_fmt(value)} {what}"
|
|
269
280
|
# No data falls short of a positive target only: nothing is below a target of 0.
|
|
270
281
|
if goal is not None and ((value is None and goal > 0) or (value is not None and value < goal)):
|
|
271
282
|
cls.append("bf-cal__day--below")
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
/* briefing lab: CalendarHeatmap — sizing, and on_click="rows" (click a day or an hour to
|
|
1
|
+
/* briefing lab: CalendarHeatmap — sizing, hover tooltip, and on_click="rows" (click a day or an hour to
|
|
2
|
+
list its rows). Vanilla JS. */
|
|
2
3
|
(function () {
|
|
3
4
|
'use strict';
|
|
4
5
|
|
|
@@ -27,6 +28,60 @@
|
|
|
27
28
|
});
|
|
28
29
|
});
|
|
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
|
+
|
|
30
85
|
document.querySelectorAll('.bf-calendar').forEach(function (figure) {
|
|
31
86
|
var dataEl = figure.querySelector('script.bf-cal__rows');
|
|
32
87
|
if (!dataEl) return;
|
|
@@ -42,7 +97,7 @@
|
|
|
42
97
|
var date = cell.getAttribute('data-date');
|
|
43
98
|
var key = (date ? 'd|' + date : 'h|' + cell.getAttribute('data-hour')) + (group !== null ? '|' + group : '');
|
|
44
99
|
var entry = data.cells[key];
|
|
45
|
-
var when = cell.
|
|
100
|
+
var when = (cell.getAttribute('data-tip') || '').split(' \u00b7 ')[0];
|
|
46
101
|
var count = entry ? entry.total + (entry.total === 1 ? ' row' : ' rows') : 'no rows';
|
|
47
102
|
title.textContent = [when, group, count].filter(function (x) { return x !== null; }).join(' · ');
|
|
48
103
|
body.textContent = '';
|
|
@@ -317,8 +317,8 @@ def _render_plot(block: Plot, idgen: _IdGen) -> str:
|
|
|
317
317
|
|
|
318
318
|
|
|
319
319
|
@renderer_for(Table)
|
|
320
|
-
def _render_table(block: Table,
|
|
321
|
-
return render_table(block)
|
|
320
|
+
def _render_table(block: Table, idgen: _IdGen) -> str:
|
|
321
|
+
return render_table(block, idgen)
|
|
322
322
|
|
|
323
323
|
|
|
324
324
|
@renderer_for(DataTable)
|
|
@@ -19,6 +19,7 @@ HTML contains the full data set, so the table works offline forever.
|
|
|
19
19
|
"""
|
|
20
20
|
from __future__ import annotations
|
|
21
21
|
|
|
22
|
+
import copy
|
|
22
23
|
import html as _html
|
|
23
24
|
import math
|
|
24
25
|
import numbers
|
|
@@ -26,6 +27,7 @@ import typing as t
|
|
|
26
27
|
from datetime import date, timedelta
|
|
27
28
|
|
|
28
29
|
from briefing._error import BriefingError
|
|
30
|
+
from briefing.renderers.registry import IdGen
|
|
29
31
|
|
|
30
32
|
if t.TYPE_CHECKING:
|
|
31
33
|
from briefing.blocks.asset import DataTable, Table
|
|
@@ -100,7 +102,7 @@ def _use_index(df: t.Any) -> bool:
|
|
|
100
102
|
# ── static Table ──────────────────────────────────────────────────────────────
|
|
101
103
|
|
|
102
104
|
|
|
103
|
-
def render_table(block: Table) -> str:
|
|
105
|
+
def render_table(block: Table, idgen: IdGen | None = None) -> str:
|
|
104
106
|
"""Render a :class:`~briefing.Table` block to a static HTML table fragment."""
|
|
105
107
|
try:
|
|
106
108
|
from pandas.io.formats.style import Styler
|
|
@@ -112,8 +114,9 @@ def render_table(block: Table) -> str:
|
|
|
112
114
|
data = block.data
|
|
113
115
|
|
|
114
116
|
if isinstance(data, Styler):
|
|
115
|
-
#
|
|
116
|
-
|
|
117
|
+
# A full <style>+<table> fragment, used as it is apart from the id: pandas puts a random
|
|
118
|
+
# uuid in every id and selector. The copy leaves the caller's Styler as it was.
|
|
119
|
+
table_html = copy.copy(data).set_uuid((idgen or IdGen()).next("table")).to_html()
|
|
117
120
|
else:
|
|
118
121
|
table_html = data.to_html(
|
|
119
122
|
classes="bf-table__table",
|
|
@@ -736,6 +736,13 @@ body {
|
|
|
736
736
|
.bf-cal__swatch--empty { border: 1px dashed var(--bf-border); }
|
|
737
737
|
.bf-cal__swatch--below { border: 1.5px solid #dc2626; }
|
|
738
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; }
|
|
739
746
|
.bf-calendar rect[role="button"]:focus-visible { stroke: var(--bf-accent); stroke-width: 2; }
|
|
740
747
|
.bf-cal__panel { margin-top: 0.75rem; border: 1px solid var(--bf-border); border-radius: var(--bf-radius);
|
|
741
748
|
padding: 0.6rem 0.75rem; }
|
|
@@ -787,4 +794,5 @@ html.bf-printing .bf-print-label {
|
|
|
787
794
|
/* A calendar may shrink to fit the sheet instead of being clipped (#106). */
|
|
788
795
|
.bf-cal__days, .bf-cal__hours { min-width: 0; --bf-cal-text: 1; }
|
|
789
796
|
.bf-cal__swatch { width: 11px; height: 11px; }
|
|
797
|
+
.bf-cal__tip { display: none !important; }
|
|
790
798
|
}
|
|
@@ -150,7 +150,7 @@ RULES: dict[str, Callable[[Tag], None]] = {
|
|
|
150
150
|
|
|
151
151
|
|
|
152
152
|
def check_deterministic(render: Callable[[], str]) -> None:
|
|
153
|
-
"""Two
|
|
153
|
+
"""Two calls to *render* give byte-identical output (run with ``SOURCE_DATE_EPOCH`` set)."""
|
|
154
154
|
first, second = render(), render()
|
|
155
155
|
if first != second:
|
|
156
156
|
pairs = enumerate(zip(first, second, strict=False))
|
|
@@ -3,6 +3,7 @@ from __future__ import annotations
|
|
|
3
3
|
|
|
4
4
|
import warnings
|
|
5
5
|
|
|
6
|
+
import numpy as np
|
|
6
7
|
import pytest
|
|
7
8
|
|
|
8
9
|
from briefing._error import BriefingError
|
|
@@ -34,6 +35,22 @@ class TestGroup:
|
|
|
34
35
|
g = Group(blocks=items, columns=2)
|
|
35
36
|
assert len(g) == 2
|
|
36
37
|
|
|
38
|
+
@pytest.mark.parametrize("columns", [0, -1, 1.5, 2.0, True, "2", None])
|
|
39
|
+
def test_columns_must_be_a_whole_number_of_one_or_more(self, columns):
|
|
40
|
+
with pytest.raises(BriefingError, match="'columns' must be a whole number of 1 or more"):
|
|
41
|
+
Group(*make_texts(2), columns=columns)
|
|
42
|
+
|
|
43
|
+
@pytest.mark.parametrize("width", [0, -1, float("nan"), float("inf"), True, "1", None])
|
|
44
|
+
def test_widths_must_be_positive_numbers(self, width):
|
|
45
|
+
with pytest.raises(BriefingError, match="'widths' must be positive numbers"):
|
|
46
|
+
Group(*make_texts(2), columns=2, widths=[1, width])
|
|
47
|
+
|
|
48
|
+
@pytest.mark.parametrize(("columns", "widths"), [(np.int64(2), [np.int64(2), np.float64(1.5)])])
|
|
49
|
+
def test_numpy_numbers_work_like_python_ones(self, columns, widths):
|
|
50
|
+
g = Group(*make_texts(2), columns=columns, widths=widths)
|
|
51
|
+
assert g.columns == 2
|
|
52
|
+
assert type(g.columns) is int
|
|
53
|
+
|
|
37
54
|
def test_widths_correct_length(self):
|
|
38
55
|
g = Group(*make_texts(2), columns=2, widths=[2, 1])
|
|
39
56
|
assert g.widths == [2, 1]
|
|
@@ -8,6 +8,9 @@ from playwright.sync_api import Page
|
|
|
8
8
|
import briefing as bf
|
|
9
9
|
from tests.test_browser.conftest import Viewer
|
|
10
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
|
+
|
|
11
14
|
|
|
12
15
|
@pytest.mark.parametrize("theme", ["default", "dark"])
|
|
13
16
|
def test_zero_no_data_and_below_target_are_visibly_different(viewer: Viewer, df_pipeline_log: pd.DataFrame,
|
|
@@ -145,3 +148,95 @@ def test_capped_cells_say_so_and_values_stay_text(viewer: Viewer) -> None:
|
|
|
145
148
|
assert panel.locator("tbody tr").count() == 50
|
|
146
149
|
assert "first 50 of 120 rows" in panel.inner_text()
|
|
147
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))
|
|
@@ -27,6 +27,9 @@ from tests.contract import (
|
|
|
27
27
|
parse_report,
|
|
28
28
|
)
|
|
29
29
|
|
|
30
|
+
# The "calendar" scenario keeps the deprecated hour view (#111) so the contract still covers it.
|
|
31
|
+
pytestmark = pytest.mark.filterwarnings("ignore:CalendarHeatmap. the hour view:DeprecationWarning")
|
|
32
|
+
|
|
30
33
|
Frames = Callable[[str], pd.DataFrame]
|
|
31
34
|
Build = Callable[[Frames], bf.Briefing]
|
|
32
35
|
|
|
@@ -127,6 +130,9 @@ SCENARIOS: dict[str, Build] = {
|
|
|
127
130
|
bf.Plot(_matplotlib_figure("line")), bf.Plot(_matplotlib_figure("bar"))
|
|
128
131
|
),
|
|
129
132
|
"table-styler": lambda df: bf.Briefing(bf.Table(df("df_constant").style.highlight_max(), caption="Styled")),
|
|
133
|
+
"two-table-stylers": lambda df: bf.Briefing(
|
|
134
|
+
bf.Table(df("df_constant").style.highlight_max()), bf.Table(df("df_constant").style.highlight_max())
|
|
135
|
+
),
|
|
130
136
|
**{
|
|
131
137
|
f"{kind}-{fixture}": _over_frame(make, fixture)
|
|
132
138
|
for kind, make in FRAME_BLOCKS.items()
|
|
@@ -205,8 +211,9 @@ def test_report_is_deterministic(
|
|
|
205
211
|
rule: str, scenario: str, frames: Frames, monkeypatch: pytest.MonkeyPatch
|
|
206
212
|
) -> None:
|
|
207
213
|
monkeypatch.setenv("SOURCE_DATE_EPOCH", "1700000000")
|
|
208
|
-
report
|
|
209
|
-
|
|
214
|
+
# Rebuild the report for each render: the promise is same input, same bytes. Rendering one
|
|
215
|
+
# object twice would miss randomness picked when a block or its data is created (#101).
|
|
216
|
+
check_deterministic(lambda: bf.stringify(SCENARIOS[scenario](frames), name=REPORT_NAME))
|
|
210
217
|
|
|
211
218
|
|
|
212
219
|
def _all_block_types() -> set[type]:
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
"""Deprecated
|
|
1
|
+
"""Deprecated names and features: the folio -> bulletin -> briefing aliases, and the calendar hour view."""
|
|
2
2
|
from __future__ import annotations
|
|
3
3
|
|
|
4
|
+
import typing as t
|
|
4
5
|
import warnings
|
|
5
6
|
|
|
6
7
|
import pytest
|
|
@@ -72,3 +73,22 @@ def test_plot_scale_is_gone_after_0_2() -> None:
|
|
|
72
73
|
version = tuple(int(part) for part in bf.__version__.split(".")[:2])
|
|
73
74
|
if version >= (0, 3):
|
|
74
75
|
assert "scale" not in inspect.signature(bf.Plot).parameters
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
# ── CalendarHeatmap's hour view (#111) ────────────────────────────────────────
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
@pytest.mark.parametrize("views", [("hours",), ("days", "hours"), ["hours", "days"]])
|
|
82
|
+
def test_the_calendar_hour_view_warns_and_still_renders(views: tuple[str, ...], df_pipeline_log: t.Any) -> None:
|
|
83
|
+
expected = r"hour view .* deprecated since briefing 0\.2\.2.*issues/111"
|
|
84
|
+
with pytest.warns(DeprecationWarning, match=expected) as caught:
|
|
85
|
+
block = bf.lab.CalendarHeatmap(df_pipeline_log, date="run_at", views=views)
|
|
86
|
+
assert caught[0].filename == __file__ # points at the caller's line (stacklevel=2)
|
|
87
|
+
assert "bf-cal__hours" in bf.stringify(bf.Briefing(block))
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def test_the_day_calendar_alone_does_not_warn(df_pipeline_log: t.Any) -> None:
|
|
91
|
+
with warnings.catch_warnings():
|
|
92
|
+
warnings.simplefilter("error")
|
|
93
|
+
bf.lab.CalendarHeatmap(df_pipeline_log, date="run_at")
|
|
94
|
+
bf.lab.CalendarHeatmap(df_pipeline_log, date="run_at", views=("days",))
|
|
@@ -36,8 +36,6 @@ BY_ID = {example.id: example for example in EXAMPLES}
|
|
|
36
36
|
|
|
37
37
|
#: Rules every report fails today, as in tests/test_contract.py.
|
|
38
38
|
KNOWN_FAILURES = {"generator_meta": "#23: no generator meta tag yet"}
|
|
39
|
-
#: Examples whose output changes between runs today, by their ``:title:``.
|
|
40
|
-
NOT_DETERMINISTIC = {"A styled Table": "#101: a pandas Styler gets a random uuid"}
|
|
41
39
|
|
|
42
40
|
_reports: dict[str, str] = {}
|
|
43
41
|
|
|
@@ -67,16 +65,7 @@ def test_example_follows_rule(rule: str, example_id: str, tmp_path_factory: pyte
|
|
|
67
65
|
RULES[rule](parse_report(_report(example_id, tmp_path_factory)))
|
|
68
66
|
|
|
69
67
|
|
|
70
|
-
|
|
71
|
-
cases = []
|
|
72
|
-
for ex in EXAMPLES:
|
|
73
|
-
reason = NOT_DETERMINISTIC.get(ex.options.get("title", ""))
|
|
74
|
-
marks = [pytest.mark.xfail(reason=reason, strict=True)] if reason else []
|
|
75
|
-
cases.append(pytest.param(ex.id, marks=marks, id=ex.id))
|
|
76
|
-
return cases
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
@pytest.mark.parametrize("example_id", _deterministic_cases())
|
|
68
|
+
@pytest.mark.parametrize("example_id", [ex.id for ex in EXAMPLES])
|
|
80
69
|
def test_example_is_deterministic(example_id: str, tmp_path_factory: pytest.TempPathFactory) -> None:
|
|
81
70
|
again = gallery.run_example(BY_ID[example_id].code, tmp_path_factory.mktemp("again"), where=example_id)
|
|
82
71
|
assert again.read_text(encoding="utf-8") == _report(example_id, tmp_path_factory)
|
|
@@ -10,9 +10,12 @@ from bs4 import BeautifulSoup, Tag
|
|
|
10
10
|
|
|
11
11
|
import briefing as bf
|
|
12
12
|
from briefing.lab import CalendarHeatmap
|
|
13
|
-
from briefing.lab._render_calendar import GITHUB, render_calendar
|
|
13
|
+
from briefing.lab._render_calendar import GITHUB, _fmt, render_calendar
|
|
14
14
|
from tests.html_helpers import attr, classes, find_one
|
|
15
15
|
|
|
16
|
+
# The hour view is deprecated (#111) but still supported: its tests keep running without the warning.
|
|
17
|
+
pytestmark = pytest.mark.filterwarnings("ignore:CalendarHeatmap. the hour view:DeprecationWarning")
|
|
18
|
+
|
|
16
19
|
|
|
17
20
|
def _soup(block: CalendarHeatmap) -> BeautifulSoup:
|
|
18
21
|
return BeautifulSoup(render_calendar(block), "html.parser")
|
|
@@ -169,7 +172,7 @@ def test_week_start(df_pipeline_log: pd.DataFrame, week_start: str, weekday: int
|
|
|
169
172
|
def test_tooltips_show_date_and_value(df_pipeline_log: pd.DataFrame) -> None:
|
|
170
173
|
cells = _cells(_soup(CalendarHeatmap(df_pipeline_log, date="run_at", value="rows", agg="sum")))
|
|
171
174
|
title = find_one(cells["2025-12-07"], "title").get_text()
|
|
172
|
-
assert title.startswith("2025-12-07") and "rows" in title
|
|
175
|
+
assert title.startswith("Sun 2025-12-07 · ") and "rows" in title # weekday first, for the tooltip (#109)
|
|
173
176
|
|
|
174
177
|
|
|
175
178
|
def test_labels_are_escaped(df_pipeline_log: pd.DataFrame) -> None:
|
|
@@ -301,3 +304,42 @@ def test_rows_json_cannot_close_its_script(df_pipeline_log: pd.DataFrame) -> Non
|
|
|
301
304
|
soup = _soup(CalendarHeatmap(df, date="run_at", on_click="rows"))
|
|
302
305
|
assert soup.find("img") is None and "<" not in find_one(soup, "script.bf-cal__rows").get_text()
|
|
303
306
|
assert _rows(soup)["cells"]["d|2026-01-05"]["rows"][0][1] == "</script><img src=x onerror=y()>"
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
# ── exact values in tooltips and the legend (#109) ────────────────────────────
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
@pytest.mark.parametrize(("value", "shown"), [
|
|
313
|
+
(3, "3"), (1234, "1,234"), (12345.67, "12,345.67"), (-12345.678, "-12,345.68"), (1234.5, "1,234.5"),
|
|
314
|
+
(10_000_000.5, "10,000,000.5"), (0.12345, "0.1235"), (-0.5, "-0.5"), (0.00001234, "1.23e-05"),
|
|
315
|
+
])
|
|
316
|
+
def test_values_are_shown_exactly(value: float, shown: str) -> None:
|
|
317
|
+
assert _fmt(value) == shown
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
def test_a_large_fractional_value_has_no_exponent_in_tooltip_or_legend() -> None:
|
|
321
|
+
df = pd.DataFrame({"day": pd.to_datetime(["2026-01-05", "2026-01-06"]), "amount": [12345.67, 20000.25]})
|
|
322
|
+
soup = _soup(CalendarHeatmap(df, date="day", value="amount", colors=["#eee", "#333"]))
|
|
323
|
+
tip = find_one(find_one(soup, 'rect[data-date="2026-01-05"]'), "title").get_text()
|
|
324
|
+
assert tip == "Mon 2026-01-05 · 12,345.67 amount"
|
|
325
|
+
legend = find_one(soup, ".bf-cal__legend").get_text()
|
|
326
|
+
assert "e+0" not in legend and "12,345.67" in legend
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
# ── weekday labels (#113) ─────────────────────────────────────────────────────
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
@pytest.mark.parametrize("week_start", ["monday", "sunday"])
|
|
333
|
+
def test_every_weekday_is_named_on_its_own_row(week_start: str) -> None:
|
|
334
|
+
df = pd.DataFrame({"d": pd.date_range("2026-01-05", "2026-01-18")}) # two full weeks from a Monday
|
|
335
|
+
soup = _soup(CalendarHeatmap(df, date="d", week_start=week_start))
|
|
336
|
+
row_of_day = {float(attr(r, "y")): pd.Timestamp(attr(r, "data-date")).strftime("%a")
|
|
337
|
+
for r in soup.select("rect.bf-cal__day")}
|
|
338
|
+
labels = soup.select("svg.bf-cal__days text.bf-cal__weekday")
|
|
339
|
+
assert [t.get_text() for t in labels] == ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
|
|
340
|
+
for label in labels: # a label's baseline sits inside its row: y = row top + cell - 1
|
|
341
|
+
row_top = float(attr(label, "y")) - 10
|
|
342
|
+
assert row_of_day[row_top] == label.get_text()
|
|
343
|
+
tops = sorted(float(attr(t, "y")) for t in labels)
|
|
344
|
+
first = "Sun" if week_start == "sunday" else "Mon"
|
|
345
|
+
assert next(t.get_text() for t in labels if float(attr(t, "y")) == tops[0]) == first
|
|
@@ -79,6 +79,18 @@ class TestRenderTable:
|
|
|
79
79
|
html = render_table(Table(styler))
|
|
80
80
|
assert "<table" in html
|
|
81
81
|
|
|
82
|
+
def test_equal_stylers_render_the_same_bytes(self, simple_df):
|
|
83
|
+
first, second = (render_table(Table(simple_df.style.highlight_max())) for _ in range(2))
|
|
84
|
+
assert first == second
|
|
85
|
+
|
|
86
|
+
def test_rendering_leaves_the_stylers_uuid_alone(self, simple_df):
|
|
87
|
+
styler = simple_df.style.highlight_max()
|
|
88
|
+
own_uuid = styler.uuid
|
|
89
|
+
html = render_table(Table(styler))
|
|
90
|
+
assert styler.uuid == own_uuid
|
|
91
|
+
assert own_uuid not in html
|
|
92
|
+
assert f"T_{own_uuid}" in styler.to_html()
|
|
93
|
+
|
|
82
94
|
def test_rangeindex_hidden_by_default(self, simple_df):
|
|
83
95
|
# Default RangeIndex should not appear as a column
|
|
84
96
|
html = render_table(Table(simple_df))
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|