in analysis/render.py [0:0]
def fmt_badge(label: str, message: str, color: str, tooltip: str = "") -> str:
"""Markdown to render a badge
Parameters
----------
label : str
Left-hand side of the badge.
message : str
Right-hand side of the badge.
color : str
Badge color. Accepts hex, rgb, hsl, hsla, css named color, or a preset:
- ImprovedStrong: dark green
- ImprovedWeak: pale green
- DegradedStrong: dark red
- DegradedWeak: pale red
- ChangedStrong: dark blue
- ChangedWeak: pale blue
- Inconclusive: pale grey
- Warning: pale yellow
- Pass: dark green
- Fail: dark red
tooltip : str, optional
Tooltip. Default: standard message for color presets, otherwise none.
"""
if not tooltip:
if color.endswith("Strong"):
tooltip = "Highly statistically significant."
elif color.endswith("Weak"):
tooltip = "Marginally statistically significant."
elif color == "Inconclusive":
tooltip = "Not statistically significant."
match color:
case "ImprovedStrong":
color = DARK_GREEN
case "ImprovedWeak":
color = PALE_GREEN
case "DegradedStrong":
color = DARK_RED
case "DegradedWeak":
color = PALE_RED
case "ChangedStrong":
color = DARK_BLUE
case "ChangedWeak":
color = PALE_BLUE
case "Inconclusive":
color = PALE_GREY
case "Warning":
color = PALE_YELLOW
case "Pass":
color = DARK_GREEN
case "Fail":
color = DARK_RED
case _:
# support custom colors
pass
def escape(s: str) -> str:
return quote(s, safe="").replace("-", "--").replace("_", "__")
badge_content = "-".join(map(escape, [label, message, color]))
url = f"https://img.shields.io/badge/{badge_content}"
alt_text = f"{label}: {message}"
return fmt_image(url, alt_text, tooltip)