Skip to content

axline

AxLine: a horizontal or vertical reference line drawn on a plot, styled with a Pen.

LineOrientation

Bases: StrEnum

Defines orientation for axis lines.

HORIZONTAL class-attribute instance-attribute

Python
HORIZONTAL = 'horizontal'

Horizontal line

VERTICAL class-attribute instance-attribute

Python
VERTICAL = 'vertical'

Vertical line

AxLine

Bases: PlottableData2D

Defines a horizontal or vertical line to be drawn on a plot.

value instance-attribute

Python
value: float

Value at which to draw the line (x-value for vertical, y-value for horizontal).

orientation instance-attribute

Python
orientation: LineOrientation

Whether line should be horizontal or vertical.

pen class-attribute instance-attribute

Python
pen: Pen = Pen()

Style and label information for drawing to matplotlib axes.

tags instance-attribute

Python
tags: Tags

Tags to be used for sorting data.

metadata class-attribute instance-attribute

Python
metadata: dict[str, str] = {}

A dictionary of metadata to be used as a tool tip for mouseover in Grafana.

record_type property

Python
record_type: str

Returns:

Type Description
str

Record type should be the same as the class name. The record type is used to search for records from the store.

plot_to_ax

Python
plot_to_ax(ax: Axes) -> None

Plots line to matplotlib axes object.

Parameters:

Name Type Description Default
ax Axes

axes to which line should be plotted

required
Source code in src/trendify/plotting/axline.py
Python
def plot_to_ax(self, ax: Axes) -> None:
    """
    Plots line to matplotlib axes object.

    Args:
        ax (Axes): axes to which line should be plotted

    """
    match self.orientation:
        case LineOrientation.HORIZONTAL:
            ax.axhline(y=self.value, **self.pen.as_scatter_plot_kwargs())
        case LineOrientation.VERTICAL:
            ax.axvline(x=self.value, **self.pen.as_scatter_plot_kwargs())
        case _:
            logger.error(f"Unrecognized line orientation {self.orientation}")

add_to_plotly

Python
add_to_plotly(plotly_figure: PlotlyFigure) -> PlotlyFigure

Add axis line to plotly figure without showing it in the legend

Source code in src/trendify/plotting/axline.py
Python
def add_to_plotly(self, plotly_figure: PlotlyFigure) -> PlotlyFigure:
    """Add axis line to plotly figure without showing it in the legend"""
    match self.orientation:
        case LineOrientation.HORIZONTAL:
            plotly_figure.fig.add_hline(
                y=self.value,
                line=dict(
                    color=self.pen.rgba if self.pen else None,
                    width=self.pen.size if self.pen else None,
                    dash=(
                        self.pen._convert_linestyle_to_plotly()
                        if self.pen
                        else None
                    ),
                ),
                showlegend=False,  # Do not show in the legend
                opacity=self.pen.alpha if self.pen else None,
            )
            plotly_figure.fig.add_annotation(
                x=1.0,
                y=self.value,
                xref="paper",  # Reference to the entire plotting area
                yref="y",
                text=self.pen.label,
                showarrow=False,  # Hide the arrow if not needed
                xanchor="left",
                yanchor="middle",  # Center the text horizontally with the vline
            )
        case LineOrientation.VERTICAL:
            plotly_figure.fig.add_vline(
                x=self.value,
                line=dict(
                    color=self.pen.rgba if self.pen else None,
                    width=self.pen.size if self.pen else None,
                    dash=(
                        self.pen._convert_linestyle_to_plotly()
                        if self.pen
                        else None
                    ),
                ),
                showlegend=False,  # Do not show in the legend
                opacity=self.pen.alpha if self.pen else None,
            )
            plotly_figure.fig.add_annotation(
                x=self.value,
                y=1.0,  # Position slightly above the plot area
                yref="paper",  # Reference to the entire plotting area
                text=self.pen.label,
                showarrow=False,  # Hide the arrow if not needed
                xanchor="center",  # Center the text horizontally with the vline
                yanchor="bottom",
            )
        case _:
            logger.error(f"Unrecognized line orientation {self.orientation}")
            return plotly_figure

    return plotly_figure

__init_subclass__

Python
__init_subclass__(**kwargs: Any) -> None

Registers child subclasses to be able to parse them from JSON payloads using the deserialize method

Source code in src/trendify/base/record.py
Python
def __init_subclass__(cls, **kwargs: Any) -> None:
    """
    Registers child subclasses to be able to parse them from JSON payloads using the
    [deserialize][trendify.base.record.Record.deserialize] method
    """
    super().__init_subclass__(**kwargs)
    _record_subclass_registry[cls.__name__] = cls
    logger.debug(f"Registered Record subclass {cls.__name__!r}")

append_to_list

Python
append_to_list(to_add_to: list) -> Self

Appends self to list.

Parameters:

Name Type Description Default
to_add_to List

list to which self will be appended

required

Returns:

Type Description
Self

returns instance of self

Source code in src/trendify/base/record.py
Python
def append_to_list(self, to_add_to: list) -> Self:
    """
    Appends self to list.

    Args:
        to_add_to (List): list to which `self` will be appended

    Returns:
        (Self): returns instance of `self`

    """
    to_add_to.append(self)
    return self

registry classmethod

Python
registry() -> dict[str, type[Record]]

Returns:

Type Description
dict[str, type[Record]]

a copy of the record_type -> class registry, used by the store to resolve which leaf record_type names correspond to a given (possibly non-leaf) type when filtering by object_type.

Source code in src/trendify/base/record.py
Python
@classmethod
def registry(cls) -> dict[str, type[Record]]:
    """
    Returns:
        (dict[str, type[Record]]): a copy of the record_type -> class registry,
            used by the store to resolve which leaf `record_type` names correspond to a
            given (possibly non-leaf) type when filtering by `object_type`.

    """
    return dict(_record_subclass_registry)

deserialize classmethod

Python
deserialize(record_type: str, payload: str) -> Record

Loads a stored JSON payload into the pydantic dataclass registered under record_type.

Parameters:

Name Type Description Default
record_type str

the record_type discriminator string (same as the class name)

required
payload str

the raw JSON text (e.g. from the store's records.payload column)

required

Returns:

Type Description
Record

the reconstructed, correctly-typed record instance

Source code in src/trendify/base/record.py
Python
@classmethod
def deserialize(cls, record_type: str, payload: str) -> Record:
    """
    Loads a stored JSON payload into the pydantic dataclass registered under `record_type`.

    Args:
        record_type (str): the `record_type` discriminator string (same as the class name)
        payload (str): the raw JSON text (e.g. from the store's `records.payload` column)

    Returns:
        (Record): the reconstructed, correctly-typed record instance

    """
    try:
        duck_type = _record_subclass_registry[record_type]
    except KeyError:
        logger.error(
            f"No registered Record subclass named {record_type!r}. Known types: "
            f"{sorted(_record_subclass_registry)}. This usually means the module "
            f"defining that subclass hasn't been imported in this process."
        )
        raise
    return duck_type.model_validate_json(payload)