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

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

Specify the type of time field used in the date_field. Defaults to :naive_datetime

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

Specify if a metric can return multiple results. Defaults to false

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
Link to this type

valid_date_field_type()

View Source
@type valid_date_field_type() :: :naive_datetime | :utc_datetime | :date

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() :: valid_date_field_type()

Specify the type of time field used in the date_field. Defaults to :naive_datetime

Metrics based on :date fields will only be aggregated by day, discarding time and timezone information

@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()

Specify if a metric can return multiple results. Defaults to false

If set to true, Teal expects the calculate/1 function to return a list of aggregates

@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_date_ranges() :: [range()]
Link to this function

default_date_ranges(arg1)

View Source
@spec default_date_ranges(valid_date_field_type()) :: [range()]