View Source ExTeal.Metric behaviour (ExTeal v0.27.7)

Describes the behaviour of a metric with specific callbacks for building a base result, calculating the values, applying then and returning the result

Summary

Callbacks

Define the options that are passed as a metrics options map as it's returned as part of a metric result.

The name of the component to mount in the ux responsible for rendering the content

Define the range to render by default for a metric.

A string representing how a value is formatted before being displayed by the numbro library. Defaults to 0,0

Only display the metric on the detail page of a specific resource.

Only display the metric on the index page of a specific resource.

Options that are serialized into the configuration of a metric card.

A string to prepend to any displayed value on the metric card. For example: $

Define which ranges are available for a metric.

A string to appended to any displayed value on the metric card. For example: °

Set the title displayed at the top of the card, defaults to a humanized title of the module

Explicitly set the uri used to fetch the details of a card.

Set the width of card that displays the metric. Defaults to 1/3. 1/3 and full are the only allowed values

Types

@type range() :: %{label: String.t(), unit: unit(), value: integer()}
@type unit() :: :minute | :hour | :day | :week | :month | :year

Callbacks

@callback chart_options() :: map()

Define the options that are passed as a metrics options map as it's returned as part of a metric result.

@callback component() :: String.t()

The name of the component to mount in the ux responsible for rendering the content

@callback date_field() :: atom()
@callback date_field_type() :: :naive_datetime | :utc_datetime
@callback default_range() :: range()

Define the range to render by default for a metric.

@callback format() :: String.t()

A string representing how a value is formatted before being displayed by the numbro library. Defaults to 0,0

@callback multiple_results() :: boolean()
@callback only_on_detail(Plug.Conn.t()) :: boolean()

Only display the metric on the detail page of a specific resource.

@callback only_on_index(Plug.Conn.t()) :: boolean()

Only display the metric on the index page of a specific resource.

@callback options(Plug.Conn.t()) :: map()

Options that are serialized into the configuration of a metric card.

Used as part of a dashboard or card list on a resource index or detail page.

@callback prefix() :: String.t() | nil

A string to prepend to any displayed value on the metric card. For example: $

@callback ranges() :: [range()]

Define which ranges are available for a metric.

Defaults to Metric.default_ranges/0 but can be overriden per metric.

@callback suffix() :: String.t() | nil

A string to appended to any displayed value on the metric card. For example: °

@callback title() :: String.t()

Set the title displayed at the top of the card, defaults to a humanized title of the module

@callback uri() :: String.t()

Explicitly set the uri used to fetch the details of a card.

@callback width() :: String.t()

Set the width of card that displays the metric. Defaults to 1/3. 1/3 and full are the only allowed values

Functions

@spec default_ranges() :: [range()]