View Source Contex.Axis (ContEx v0.5.0)

Contex.Axis represents the visual appearance of a Contex.Scale

In general terms, an Axis is responsible for rendering a Contex.Scale where the scale is used to position a graphical element.

As an end-user of the Contex you won't need to worry too much about Axes - the specific plot types take care of them. Things like styling and scales are handled elsewhere. However, if you are building a new plot type you will need to understand how they work.

Axes can be drawn with ticks in different locations relative to the Axis based on the orientation. For example, when :orientation is :top, the axis is drawn as a horizontal line with the ticks above and the tick text above that.

:rotation is used to optionally rotate the labels and can either by 45 or 90 (anything else is considered to be 0).

:tick_size_inner and :tick_size_outer control the line lengths of the ticks.

:tick_padding controls the gap between the end of the tick mark and the tick text.

:flip_factor is for internal use. Whatever you set it to will be ignored.

An offset relative to the containing SVG element's origin is used to position the axis line. For example, an x-axis drawn at the bottom of the plot will typically be offset by the height of the plot content. The different plot types look after this internally.

There are some layout heuristics to calculate text sizes and offsets based on axis orientation and whether the tick labels are rotated.

Link to this section Summary

Functions

Generates grid-lines for each tick in the Contex.Scale specified for the axis.

Create a new axis struct with orientation being one of :top, :left, :right, :bottom

Create a new axis struct with orientation set to :bottom.

Create a new axis struct with orientation set to :left.

Create a new axis struct with orientation set to :right.

Create a new axis struct with orientation set to :top.

Sets the offset for where the axis will be drawn. The offset will either be horizontal or vertical depending on the orientation of the axis.

Generates the SVG content for the axis (axis line, tick mark, tick labels). The coordinate system will be in the coordinate system of the containing plot (i.e. the range of the Contex.Scale specified for the axis)

Link to this section Types

@type orientations() :: :top | :left | :right | :bottom
@type t() :: %Contex.Axis{
  flip_factor: term(),
  offset: term(),
  orientation: term(),
  rotation: term(),
  scale: term(),
  tick_padding: term(),
  tick_size_inner: term(),
  tick_size_outer: term()
}

Link to this section Functions

Generates grid-lines for each tick in the Contex.Scale specified for the axis.

@spec new(Contex.Scale.t(), orientations()) :: t()

Create a new axis struct with orientation being one of :top, :left, :right, :bottom

@spec new_bottom_axis(Contex.Scale.t()) :: t()

Create a new axis struct with orientation set to :bottom.

Equivalent to Axis.new(scale, :bottom)

@spec new_left_axis(Contex.Scale.t()) :: t()

Create a new axis struct with orientation set to :left.

Equivalent to Axis.new(scale, :left)

@spec new_right_axis(Contex.Scale.t()) :: t()

Create a new axis struct with orientation set to :right.

Equivalent to Axis.new(scale, :right)

@spec new_top_axis(Contex.Scale.t()) :: t()

Create a new axis struct with orientation set to :top.

Equivalent to Axis.new(scale, :top)

Link to this function

set_offset(axis, offset)

View Source
@spec set_offset(t(), number()) :: t()

Sets the offset for where the axis will be drawn. The offset will either be horizontal or vertical depending on the orientation of the axis.

Generates the SVG content for the axis (axis line, tick mark, tick labels). The coordinate system will be in the coordinate system of the containing plot (i.e. the range of the Contex.Scale specified for the axis)