ContEx v0.2.0 Contex.ContinuousLinearScale View Source
A linear scale to map continuous numberic data to a plotting coordinate system.
Implements the general aspects of scale setup and use defined in the Contex.Scale protocol
The ContinuousLinearScale is responsible for mapping to and from values in the data
to a visual scale. The two key concepts are "domain" and "range".
The "domain" represents values in the dataset to be plotted.
The "range" represents the plotting coordinate system use to plot values in the "domain".
Important Note - When you set domain and range, the scale code makes a few adjustments based on the desired number of tick intervals so that the ticks look "nice" - i.e. on round numbers. So if you have a data range of 0.0 → 8.7 and you want 10 intervals the scale won't display ticks at 0.0, 0.87, 1.74 etc, it will round up the domain to 10 so you have nice tick intervals of 0, 1, 2, 3 etc.
By default the scale creates 10 tick intervals.
When domain and range are both set, the scale creates transform functions to map each way between the domain and range that are then available to the various plots to map data to plotting coordinate systems, and potentially vice-versa.
The typical setup of the scale looks like this:
y_scale
= ContinuousLinearScale.new()
|> ContinuousLinearScale.domain(min_value, max_value)
|> Scale.set_range(start_of_y_plotting_coord, end_of_y_plotting_coord)
Translating a value to plotting coordinates would then look like this:
plot_y = y_scale.domain_to_range_fn.(y_value)
ContinuousLinearScale also implements the Contex.Scale protocol that provides a nicer way to call the
transform functions, but in reality, calculation of plotting coordinates is typically done in tight loops
so you are more likely to do something like:
x_tx_fn = x_scale.domain_to_range_fn
y_tx_fn = y_scale.domain_to_range_fn
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
Sets the extents of the value domain for the scale by specifying a list of values to be displayed.
Sets the extents of the value domain for the scale.
Defines the number of intervals between ticks.
Creates a new scale with defaults
Link to this section Functions
domain(scale, data)
View Sourcedomain(Contex.ContinuousLinearScale.t(), [number()]) :: Contex.ContinuousLinearScale.t()
Sets the extents of the value domain for the scale by specifying a list of values to be displayed.
The scale will determine the extents of the data.
domain(scale, min, max)
View Sourcedomain(Contex.ContinuousLinearScale.t(), number(), number()) :: Contex.ContinuousLinearScale.t()
Sets the extents of the value domain for the scale.
interval_count(scale, interval_count)
View Sourceinterval_count(Contex.ContinuousLinearScale.t(), integer()) :: Contex.ContinuousLinearScale.t()
Defines the number of intervals between ticks.
Defaults to 10.
Tick-rendering is the responsibility of Contex.Axis, but calculating tick intervals is the responsibility
of the scale.
Creates a new scale with defaults