Where a layer's marks move once its stat has run: piled on one another, set side by side, nudged, jittered, or anything a plugin's position does, and the options it takes and the aesthetics it needs and reads.
A position is a struct whose module adopts this behaviour. Given to a layer function's
position:, alone or with its options, as Giggly.Plot.geom_point(plot, position: {MyPlugin.Lifted, by: 2.0}), it moves the layer's marks when the plot is assembled, as Giggly's
own positions do. compute_layer/3 and default_aesthetics/1 call the position's own module's,
so one position moves marks through another by calling them.
compute_layer/3 is handed the layer's table once its geom has set it up, every panel and
group in it, and whether each axis is discrete, continuous or binned, and returns the table with
the marks where they now stand, computed with Giggly.DataFrame's functions. Each aesthetic the
position reads (default_aesthetics/1) is in every row, the value the layer sets or maps, else
the position's default.
Writing a position
use Giggly.Position adopts the behaviour and gives every callback but compute_layer/3 a
default: no aesthetics needed or read, no options, and a struct built from the options
options/0 names. A module states what its position has and moves its marks:
defmodule MyPlugin.Lifted do
use Giggly.Position
alias Giggly.DataFrame
defstruct [:by]
@impl Giggly.Position
def options, do: [by: [type: :float, default: 1.0, doc: "How far each mark moves up."]]
@impl Giggly.Position
def required_aesthetics(_lifted), do: [y: "it moves each mark up"]
@impl Giggly.Position
def compute_layer(lifted, frame, _axis_types),
do: DataFrame.mutate(frame, y: {:+, [:y, {:constant, lifted.by}]})
end
Summary
Types
Whether each axis's scale type is discrete, continuous or binned, a binned axis's positions bin numbers.
A position's struct.
Callbacks
The layer's table frame with its marks moved by position, each axis's scale type in
axis_types.
The aesthetics the position reads, each with the value it takes where a layer neither sets nor maps it, which is put into every row before the position runs.
The position's struct from the validated options a layer's position: gives it.
The options that set the position's fields, as a NimbleOptions schema written as data, each
with its type, its documentation and its default. A layer's position: given the position with
options is validated against it.
The aesthetics the position cannot move a mark without, each with why: met by a value mapped before the stat, an option setting it, the stat writing it, or the geom's setup writing it. A layer missing one is refused when the plot runs, giving the reason.
Functions
The layer's table frame moved by position's module's compute_layer/3.
The aesthetics position reads, by its module's default_aesthetics/1.
Types
@type axis_types() :: %{
x: :continuous | :discrete | :binned,
y: :continuous | :discrete | :binned
}
Whether each axis's scale type is discrete, continuous or binned, a binned axis's positions bin numbers.
@type t() :: struct()
A position's struct.
Callbacks
@callback compute_layer(position :: t(), Giggly.DataFrame.t(), axis_types()) :: Giggly.DataFrame.t()
The layer's table frame with its marks moved by position, each axis's scale type in
axis_types.
The aesthetics the position reads, each with the value it takes where a layer neither sets nor maps it, which is put into every row before the position runs.
The position's struct from the validated options a layer's position: gives it.
@callback options() :: keyword()
The options that set the position's fields, as a NimbleOptions schema written as data, each
with its type, its documentation and its default. A layer's position: given the position with
options is validated against it.
The aesthetics the position cannot move a mark without, each with why: met by a value mapped before the stat, an option setting it, the stat writing it, or the geom's setup writing it. A layer missing one is refused when the plot runs, giving the reason.
Functions
@spec compute_layer(t(), Giggly.DataFrame.t(), axis_types()) :: Giggly.DataFrame.t()
The layer's table frame moved by position's module's compute_layer/3.
The aesthetics position reads, by its module's default_aesthetics/1.