# ContEx v0.3.0 Contex.Scale protocol View Source

Provides a common interface for scales generating plotting coordinates.

This enables Log & Linear scales, for example, to be handled exactly the same way in plot generation code.

Example:

``````  # It doesn't matter if x & y scales are log, linear or discretizing scale
x_tx_fn = Scale.domain_to_range_fn(x_scale)
y_tx_fn = Scale.domain_to_range_fn(y_scale)

points_to_plot = Enum.map(big_load_of_data, fn %{x: x, y: y}=_row ->
{x_tx_fn.(x), y_tx_fn.(y)}
end)``````

# Link to this section Summary

## Functions

Transforms a value in the domain to a plotting coordinate within the range

Returns a transform function to convert values within the domain to the range.

Formats a domain value according to formatting rules calculated for the scale.

Returns the plotting range set for the scale

Applies a plotting range set for the scale

Returns a list of tick values in the domain of the scale

Returns a list of tick locations in the range of the scale

# t()

View Source
`t() :: term()`

# domain_to_range(scale, domain_val)

View Source
`domain_to_range(t(), any()) :: number()`

Transforms a value in the domain to a plotting coordinate within the range

# domain_to_range_fn(scale)

View Source
`domain_to_range_fn(t()) :: (... -> any())`

Returns a transform function to convert values within the domain to the range.

Typically this function is used to calculate plotting coordinates for input data.

# get_formatted_tick(scale, tick_val)

View Source
`get_formatted_tick(t(), number()) :: String.t()`

Formats a domain value according to formatting rules calculated for the scale.

For example, timescales will have formatting rules calculated based on the overall time period being plotted. Numeric scales may calculate number of decimal places to show based on the range of data being plotted.

# get_range(scale)

View Source
`get_range(t()) :: {number(), number()}`

Returns the plotting range set for the scale

Note that there is not an equivalent for the domain, as the domain is specific to the type of scale.

# set_range(scale, start, finish)

View Source
`set_range(t(), number(), number()) :: t()`

Applies a plotting range set for the scale

# ticks_domain(scale)

View Source
`ticks_domain(t()) :: [any()]`

Returns a list of tick values in the domain of the scale

Typically these are used to label the tick

`ticks_range(t()) :: [number()]`