stplot 0.1.0__py3-none-any.whl
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.
- stplot/__init__.py +21 -0
- stplot/config/__init__.py +33 -0
- stplot/config/loader.py +106 -0
- stplot/config/models.py +328 -0
- stplot/config/presets/__init__.py +1 -0
- stplot/config/presets/default.yaml +208 -0
- stplot/config/presets/horizons_one_plan.yaml +59 -0
- stplot/io/__init__.py +6 -0
- stplot/io/spatial.py +72 -0
- stplot/io/tabular.py +154 -0
- stplot/plots/__init__.py +122 -0
- stplot/plots/barbell.py +400 -0
- stplot/plots/batch.py +135 -0
- stplot/plots/domains.py +1143 -0
- stplot/plots/executive.py +474 -0
- stplot/plots/export.py +74 -0
- stplot/plots/infographics.py +1118 -0
- stplot/plots/lollipop.py +285 -0
- stplot/plots/maps.py +738 -0
- stplot/plots/matrix.py +190 -0
- stplot/plots/one_plan.py +642 -0
- stplot/plots/paired.py +437 -0
- stplot/plots/scorecards.py +1940 -0
- stplot/plots/state.py +373 -0
- stplot/plots/state_trends.py +1413 -0
- stplot/plots/tables.py +107 -0
- stplot/plots/timeseries.py +607 -0
- stplot/plots/trends.py +305 -0
- stplot/reporting/__init__.py +24 -0
- stplot/reporting/captions.py +177 -0
- stplot/reporting/html_companion.py +339 -0
- stplot/reporting/templates.py +485 -0
- stplot/reporting/word.py +369 -0
- stplot/theme/__init__.py +25 -0
- stplot/theme/folium.py +62 -0
- stplot/theme/mpl.py +181 -0
- stplot/theme/plotly.py +130 -0
- stplot/transform/__init__.py +60 -0
- stplot/transform/categories.py +51 -0
- stplot/transform/columns.py +103 -0
- stplot/transform/filters.py +385 -0
- stplot/transform/merge.py +173 -0
- stplot/transform/pairing.py +154 -0
- stplot/transform/qa.py +297 -0
- stplot/transform/tables.py +573 -0
- stplot/transform/zones.py +354 -0
- stplot-0.1.0.dist-info/METADATA +235 -0
- stplot-0.1.0.dist-info/RECORD +49 -0
- stplot-0.1.0.dist-info/WHEEL +4 -0
stplot/plots/tables.py
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"""Styled summary tables for FMU vs Whole Region reporting."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
import pandas as pd
|
|
9
|
+
|
|
10
|
+
from stplot.config import Config, ensure_config, resolve_palette
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def _contrast_text_color(hex_color: str) -> str:
|
|
14
|
+
"""Return dark or white text color for legible contrast against ``hex_color``."""
|
|
15
|
+
cleaned = hex_color.lstrip("#")
|
|
16
|
+
if len(cleaned) != 6:
|
|
17
|
+
return "#222222"
|
|
18
|
+
r, g, b = int(cleaned[0:2], 16), int(cleaned[2:4], 16), int(cleaned[4:6], 16)
|
|
19
|
+
luminance = 0.299 * r + 0.587 * g + 0.114 * b
|
|
20
|
+
return "#111111" if luminance > 140 else "#ffffff"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def style_summary_table(
|
|
24
|
+
table: pd.DataFrame,
|
|
25
|
+
*,
|
|
26
|
+
palette_key: str = "state_bands",
|
|
27
|
+
palette: dict[str, str] | None = None,
|
|
28
|
+
caption: str | None = None,
|
|
29
|
+
index_name: str | None = None,
|
|
30
|
+
config: str | Path | Config | None = None,
|
|
31
|
+
) -> Any:
|
|
32
|
+
"""Style an FMU vs Whole Region summary table with semantic column colors.
|
|
33
|
+
|
|
34
|
+
Pairs with :func:`stplot.transform.build_fmu_vs_region_table` to produce color-coded
|
|
35
|
+
tables suitable for notebooks, HTML dashboards, or downstream Word report assembly.
|
|
36
|
+
|
|
37
|
+
Args:
|
|
38
|
+
table: Summary DataFrame whose columns correspond to palette keys (e.g., ``A``–``E``
|
|
39
|
+
or ``Improving`` / ``Indeterminate`` / ``Degrading``).
|
|
40
|
+
palette_key: Key in ``config.palettes`` (default ``"state_bands"``).
|
|
41
|
+
palette: Optional explicit category-to-hex color mapping override.
|
|
42
|
+
caption: Optional table caption/title.
|
|
43
|
+
index_name: Optional label displayed in the top-left corner cell.
|
|
44
|
+
config: Optional Config object, preset name, or path to YAML/TOML config.
|
|
45
|
+
|
|
46
|
+
Returns:
|
|
47
|
+
``pandas.io.formats.style.Styler`` object.
|
|
48
|
+
"""
|
|
49
|
+
cfg = ensure_config(config)
|
|
50
|
+
resolved_palette = resolve_palette(palette, cfg, palette_key)
|
|
51
|
+
|
|
52
|
+
work = table.copy()
|
|
53
|
+
if index_name is not None:
|
|
54
|
+
work.index.name = index_name
|
|
55
|
+
|
|
56
|
+
def _style_column(col: pd.Series) -> list[str]:
|
|
57
|
+
bg = resolved_palette.get(str(col.name), cfg.theme.background_color)
|
|
58
|
+
fg = _contrast_text_color(bg)
|
|
59
|
+
return [f"background-color: {bg}; color: {fg}; text-align: center;"] * len(col)
|
|
60
|
+
|
|
61
|
+
styler = work.style.apply(_style_column, axis=0)
|
|
62
|
+
|
|
63
|
+
header_styles: list[dict[str, Any]] = [
|
|
64
|
+
{
|
|
65
|
+
"selector": "table",
|
|
66
|
+
"props": [
|
|
67
|
+
("border-collapse", "collapse"),
|
|
68
|
+
("font-family", f"{cfg.theme.font_family}, sans-serif"),
|
|
69
|
+
("font-size", f"{int(cfg.theme.label_size)}px"),
|
|
70
|
+
],
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"selector": "th, td",
|
|
74
|
+
"props": [
|
|
75
|
+
("padding", "8px 14px"),
|
|
76
|
+
("border-bottom", f"1px solid {cfg.theme.spine_color}"),
|
|
77
|
+
],
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"selector": "th.row_heading, th.index_name",
|
|
81
|
+
"props": [
|
|
82
|
+
("text-align", "left"),
|
|
83
|
+
("background-color", "#f7f7f7"),
|
|
84
|
+
("color", cfg.theme.text_color),
|
|
85
|
+
],
|
|
86
|
+
},
|
|
87
|
+
]
|
|
88
|
+
|
|
89
|
+
for idx, col_name in enumerate(work.columns):
|
|
90
|
+
bg = resolved_palette.get(str(col_name), "#f0f0f0")
|
|
91
|
+
fg = _contrast_text_color(bg)
|
|
92
|
+
header_styles.append(
|
|
93
|
+
{
|
|
94
|
+
"selector": f"th.col_heading.level0.col{idx}",
|
|
95
|
+
"props": [
|
|
96
|
+
("background-color", bg),
|
|
97
|
+
("color", fg),
|
|
98
|
+
("font-weight", "bold"),
|
|
99
|
+
("text-align", "center"),
|
|
100
|
+
],
|
|
101
|
+
}
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
styler = styler.set_table_styles(header_styles)
|
|
105
|
+
if caption:
|
|
106
|
+
styler = styler.set_caption(caption)
|
|
107
|
+
return styler
|