ExTeal.Metric.Partition behaviour (ExTeal v0.21.0) View Source

Partition metrics displays a pie chart of values.

Link to this section Summary

Callbacks

Often, the column values that divide your partition metrics into groups will be simple keys, and not something that is human readable. Or, if you are displaying a partition metric grouped by a column that is a boolean, Teal will display labels as "false" and "true". For this reason, Teal provides the label_for/1 callback that can be overriden on a partition metric to provide a custom label for each value.

Link to this section Types

Specs

result() :: %{label: any(), value: float() | integer()}

Link to this section Callbacks

Specs

calculate(ExTeal.Metric.Request.t()) :: [result()]

Specs

label_for(String.t()) :: String.t()

Often, the column values that divide your partition metrics into groups will be simple keys, and not something that is human readable. Or, if you are displaying a partition metric grouped by a column that is a boolean, Teal will display labels as "false" and "true". For this reason, Teal provides the label_for/1 callback that can be overriden on a partition metric to provide a custom label for each value.

@impl true
def label_for(false), do: "User"
def label_for(true), do: "Admin"

It's also useful for handling null values:

@impl true
def label_for(null), do: "None"
def label_for(key), do: String.capitalize(key)

Link to this section Functions

Link to this function

aggregate(metric, query, aggregate, grouper, column)

View Source

Specs

aggregate(
  metric :: module(),
  query :: Ecto.Queryable.t(),
  aggregate :: atom(),
  group_by :: atom(),
  column :: atom()
) :: [result()]
Link to this function

default_order_by(query, grouper)

View Source

By default sort the partition results by the group field