Skip to content

svg_loader

anomaly_match_ui.utils.svg_loader

Logo loaders for ESA and AnomalyMatch branding in the UI.

Load the ESA logo SVG content from the assets package.

Parameters:

Name Type Description Default
height int

Height of the logo in pixels.

required

Returns:

Type Description
str

The SVG markup as a string.

Source code in anomaly_match_ui/utils/svg_loader.py
def load_esa_logo(height: int) -> str:
    """Load the ESA logo SVG content from the assets package.

    Args:
        height: Height of the logo in pixels.

    Returns:
        The SVG markup as a string.
    """
    esa_native_width, esa_native_height = 107.38, 38.975
    esa_svg = load_icon_svg("ESA_logo.svg")
    esa_svg = esa_svg.replace(f'width="{esa_native_width}"', "", 1)
    esa_svg = esa_svg.replace(f'height="{esa_native_height}"', "", 1)
    esa_svg = esa_svg.replace(
        "<svg ",
        f'<svg viewBox="0 0 {esa_native_width} {esa_native_height}" '
        f'style="height:{height}px; width:auto; display:block" ',
        1,
    )
    return esa_svg

load_am_logo_base64()

Load the full AnomalyMatch logo (white variant) as a base64 data URI.

Returns:

Type Description
str

A data:image/png;base64,... URI string.

Source code in anomaly_match_ui/utils/svg_loader.py
def load_am_logo_base64() -> str:
    """Load the full AnomalyMatch logo (white variant) as a base64 data URI.

    Returns:
        A ``data:image/png;base64,...`` URI string.
    """
    return _load_png_base64("am_logo_white.png")

load_am_logo_only_base64()

Load the AnomalyMatch icon-only logo as a base64 data URI.

Returns:

Type Description
str

A data:image/png;base64,... URI string.

Source code in anomaly_match_ui/utils/svg_loader.py
def load_am_logo_only_base64() -> str:
    """Load the AnomalyMatch icon-only logo as a base64 data URI.

    Returns:
        A ``data:image/png;base64,...`` URI string.
    """
    return _load_png_base64("am_logo_only.png")

load_icon_svg(filename)

Load an SVG icon from the assets package.

Parameters:

Name Type Description Default
filename str

Name of the SVG file inside the anomaly_match_ui.assets package.

required

Returns:

Type Description
str

The SVG markup as a string.

Source code in anomaly_match_ui/utils/svg_loader.py
def load_icon_svg(filename: str) -> str:
    """Load an SVG icon from the assets package.

    Args:
        filename: Name of the SVG file inside the ``anomaly_match_ui.assets`` package.

    Returns:
        The SVG markup as a string.
    """
    ref = importlib.resources.files(_ASSETS_PACKAGE).joinpath(filename)
    return ref.read_text(encoding="utf-8")

get_dual_logo_html(height=32)

Return inline HTML with both ESA and AnomalyMatch logos side by side.

Uses the icon-only AM logo for compact display (e.g. headers).

Parameters:

Name Type Description Default
height int

Height of each logo in pixels.

32

Returns:

Type Description
str

HTML string with both logos suitable for ipywidgets.HTML.

Source code in anomaly_match_ui/utils/svg_loader.py
def get_dual_logo_html(height: int = 32) -> str:
    """Return inline HTML with both ESA and AnomalyMatch logos side by side.

    Uses the icon-only AM logo for compact display (e.g. headers).

    Args:
        height: Height of each logo in pixels.

    Returns:
        HTML string with both logos suitable for ``ipywidgets.HTML``.
    """
    am_src = load_am_logo_only_base64()
    return (
        f'<div style="display:flex; align-items:center; justify-content:center; gap:12px;">'
        f"{load_esa_logo(height)}"
        f'<img src="../{am_src}" style="height:{height}px; width:auto; display:block;" '
        f'alt="AnomalyMatch"/>'
        f"</div>"
    )