View Source Contex.ContinuousLogScale (ContEx v0.5.0)

A logarithmic scale to map continuous numeric data to a plotting coordinate system.

This works like Contex.ContinuousLinearScale, and the settings are given as keywords.

  ContinuousLogScale.new(
        domain: {0, 100},
        tick_positions: [0, 5, 10, 15, 30, 60,  120,  240, 480, 960],
        log_base: :base_10,
        negative_numbers: :mask,
        linear_range: 1
      )

Logarithm

  • log_base is the logarithm base. Defaults to 2. Can be set to :base_2, :base_e or :base_10.
  • negative_numbers controls how negative numbers are represented. It can be:
    • :mask: always return 0
    • :clip: always returns 0
    • :sym: logarithms are drawn symmetrically, that is, the log of a number n when n < 0 is -log(abs(n))
  • linear_range is a range -if any- where results are not logarithmical

Data domain

Unfortunately, a domain must be given for all custom scales. To make your life easier, you can either:

  • domain: {0, 27} will set an explicit domain, or
  • dataset and axis let you specify a Dataset and one or a list of axes, and the domain will be computed out of them all.

Ticks

  • interval_count divides the interval in n linear slices, or
  • tick_positions can receive a list of explicit possible ticks, that will be displayed ony if they are within the domain area.
  • custom_tick_formatter is a function to be applied to the ticks.

Link to this section Summary

Functions

Translates a value into its logarithm, given the mode and an optional linear part.

Creates a new scale with defaults.

Fixes inconsistencies and scales.

Link to this section Types

@type t() :: %Contex.ContinuousLogScale{
  custom_tick_formatter: term(),
  display_decimals: term(),
  domain: term(),
  interval_count: term(),
  linear_range: term(),
  log_base_fn: term(),
  negative_numbers: term(),
  nice_domain: term(),
  range: term(),
  tick_positions: term()
}

Link to this section Functions

Link to this function

get_domain(requested_domain, requested_dataset, requested_columns)

View Source
@spec get_domain(:notfound | {any(), any()}, any(), any()) :: {number(), number()}

Computes the correct domain {a, b}.

  • If it is explicitly passed, we use it.
  • If there is a dataset and a column or a list of columns, we use that
  • If all else fails, we use {0, 1}
Link to this function

get_domain_to_range_function(scale)

View Source
@spec get_domain_to_range_function(t()) :: (number() -> float())
Link to this function

log_value(v, fn_exp, mode, lin)

View Source
@spec log_value(number(), function(), :clip | :mask | :sym, float()) :: any()

Translates a value into its logarithm, given the mode and an optional linear part.

Creates a new scale with defaults.

@spec nice(t()) :: t()

Fixes inconsistencies and scales.