View Source Contex.Scale protocol (ContEx v0.5.0)
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
Link to this section Types
@type t() :: term()
Link to this section 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.
Typically this function is used to calculate plotting coordinates for input data.
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.
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.
Applies a plotting range set for the scale
Returns a list of tick values in the domain of the scale
Typically these are used to label the tick
Returns a list of tick locations in the range of the scale
Typically these are used to plot the location of the tick