View Source Contex.PointPlot (ContEx v0.5.0)

A simple point plot, plotting points showing y values against x values.

It is possible to specify multiple y columns with the same x column. It is not yet possible to specify multiple independent series.

The x column can either be numeric or date time data. If numeric, a Contex.ContinuousLinearScale is used to scale the values to the plot, and if date time, a Contex.TimeScale is used.

Fill colours for each y column can be specified with colours/2.

A column in the dataset can optionally be used to control the colours. See colours/2 and set_colour_col_name/2

Link to this section Summary

Functions

Specifies the label rotation value that will be applied to the bottom axis. Accepts integer values for degrees of rotation or :auto. Note that manually set rotation values other than 45 or 90 will be treated as zero. The default value is :auto, which sets the rotation to zero degrees if the number of items on the axis is greater than eight, 45 degrees otherwise.

Set the colour palette for fill colours.

Allows the axis tick labels to be overridden. For example, if you have a numeric representation of money and you want to have the value axis show it as millions of dollars you might do something like

Allows the axis tick labels to be overridden. For example, if you have a numeric representation of money and you want to have the value axis show it as millions of dollars you might do something like

Create a new point plot definition and apply defaults.

If a single y column is specified, it is possible to use another column to control the point colour.

Sets the default scales for the plot based on its column mapping.

Specify which column in the dataset is used for the x values.

Specify which column(s) in the dataset is/are used for the y values.

Link to this section Types

@type t() :: %Contex.PointPlot{
  colour_palette: term(),
  dataset: term(),
  legend_scale: term(),
  mapping: term(),
  options: term(),
  transforms: term(),
  x_scale: term(),
  y_scale: term()
}

Link to this section Functions

Link to this function

axis_label_rotation(plot, rotation)

View Source
This function is deprecated. Set in new/2 options.
@spec axis_label_rotation(t(), integer() | :auto) :: t()

Specifies the label rotation value that will be applied to the bottom axis. Accepts integer values for degrees of rotation or :auto. Note that manually set rotation values other than 45 or 90 will be treated as zero. The default value is :auto, which sets the rotation to zero degrees if the number of items on the axis is greater than eight, 45 degrees otherwise.

Link to this function

colours(plot, colour_palette)

View Source
This function is deprecated. Set in new/2 options.
@spec colours(t(), Contex.CategoryColourScale.colour_palette()) :: t()

Set the colour palette for fill colours.

Where multiple y columns are defined for the plot, a different colour will be used for each column.

If a single y column is defined and a colour column is defined (see set_colour_col_name/2), a different colour will be used for each unique value in the colour column.

If a single y column is defined and no colour column is defined, the first colour in the supplied colour palette will be used to plot the points.

Link to this function

custom_x_formatter(plot, custom_x_formatter)

View Source
This function is deprecated. Set in new/2 options.
@spec custom_x_formatter(t(), nil | (... -> any())) :: t()

Allows the axis tick labels to be overridden. For example, if you have a numeric representation of money and you want to have the value axis show it as millions of dollars you might do something like:

  # Turns 1_234_567.67 into $1.23M
  defp money_formatter_millions(value) when is_number(value) do
    "$#{:erlang.float_to_binary(value/1_000_000.0, [decimals: 2])}M"
  end

  defp show_chart(data) do
    PointPlot.new(data)
    |> PointPlot.custom_x_formatter(&money_formatter_millions/1)
  end
Link to this function

custom_y_formatter(plot, custom_y_formatter)

View Source
This function is deprecated. Set in new/2 options.
@spec custom_y_formatter(t(), nil | (... -> any())) :: t()

Allows the axis tick labels to be overridden. For example, if you have a numeric representation of money and you want to have the value axis show it as millions of dollars you might do something like:

  # Turns 1_234_567.67 into $1.23M
  defp money_formatter_millions(value) when is_number(value) do
    "$#{:erlang.float_to_binary(value/1_000_000.0, [decimals: 2])}M"
  end

  defp show_chart(data) do
    PointPlot.new(data)
    |> PointPlot.custom_y_formatter(&money_formatter_millions/1)
  end
Link to this function

new(dataset, options \\ [])

View Source
@spec new(
  Contex.Dataset.t(),
  keyword()
) :: t()

Create a new point plot definition and apply defaults.

Options may be passed to control the settings for the barchart. Options available are:

  • :axis_label_rotation : :auto (default), 45 or 90

Specifies the label rotation value that will be applied to the bottom axis. Accepts integer values for degrees of rotation or :auto. Note that manually set rotation values other than 45 or 90 will be treated as zero. The default value is :auto, which sets the rotation to zero degrees if the number of items on the axis is greater than eight, 45 degrees otherwise.

  • :custom_x_scale : nil (default) or an instance of a suitable Contex.Scale.

The scale must be suitable for the data type and would typically be either Contex.ContinuousLinearScale or Contex.TimeScale. It is not necessary to set the range for the scale as the range is set as part of the chart layout process.

  • :custom_y_scale : nil (default) or an instance of a suitable Contex.Scale.

  • :custom_x_formatter : nil (default) or a function with arity 1

Allows the axis tick labels to be overridden. For example, if you have a numeric representation of money and you want to have the x axis show it as millions of dollars you might do something like:

  # Turns 1_234_567.67 into $1.23M
  defp money_formatter_millions(value) when is_number(value) do
    "$#{:erlang.float_to_binary(value/1_000_000.0, [decimals: 2])}M"
  end

  defp show_chart(data) do
    PointPlot.new(
      dataset,
      mapping: %{x_col: :column_a, y_cols: [:column_b, column_c]},
      custom_x_formatter: &money_formatter_millions/1
    )
  end
  • :custom_y_formatter : nil (default) or a function with arity 1.
  • :colour_palette : :default (default) or colour palette - see colours/2

Overrides the default colours.

Where multiple y columns are defined for the plot, a different colour will be used for each column.

If a single y column is defined and a :fill_colcolumn is mapped, a different colour will be used for each unique value in the colour column.

If a single y column is defined and no :fill_colcolumn is mapped, the first colour in the supplied colour palette will be used to plot the points.

Colours can either be a named palette defined in Contex.CategoryColourScale or a list of strings representing hex code of the colour as per CSS colour hex codes, but without the #. For example:

  chart = PointPlot.new(
      dataset,
      mapping: %{x_col: :column_a, y_cols: [:column_b, column_c]},
      colour_palette: ["fbb4ae", "b3cde3", "ccebc5"]
    )

The colours will be applied to the data series in the same order as the columns are specified in set_val_col_names/2

  • :mapping : Maps attributes required to generate the barchart to columns in the dataset.

If the data in the dataset is stored as a map, the :mapping option is required. If the dataset is not stored as a map, :mapping may be left out, in which case the first column will be used for the x and the second column used as the y. This value must be a map of the plot's :x_col and :y_cols to keys in the map, such as %{x_col: :column_a, y_cols: [:column_b, column_c]}. The value for the :y_cols key must be a list.

If a single y column is specified an optional :fill_col mapping can be provided to control the point colour. This is ignored if there are multiple y columns.

Link to this function

set_colour_col_name(plot, fill_col_name)

View Source
This function is deprecated. Use `:mapping` option in `new/2`.
@spec set_colour_col_name(t(), Contex.Dataset.column_name()) :: t()

If a single y column is specified, it is possible to use another column to control the point colour.

Note: This is ignored if there are multiple y columns.

Link to this function

set_default_scales(plot)

View Source
This function is deprecated. Default scales are now silently applied.
@spec set_default_scales(t()) :: t()

Sets the default scales for the plot based on its column mapping.

Link to this function

set_x_col_name(plot, x_col_name)

View Source
This function is deprecated. Use `:mapping` option in `new/2`.
@spec set_x_col_name(t(), Contex.Dataset.column_name()) :: t()

Specify which column in the dataset is used for the x values.

This column must contain numeric or date time data.

Link to this function

set_y_col_names(plot, y_col_names)

View Source
This function is deprecated. Use `:mapping` option in `new/2`.
@spec set_y_col_names(t(), [Contex.Dataset.column_name()]) :: t()

Specify which column(s) in the dataset is/are used for the y values.

These columns must contain numeric data.

Where more than one y column is specified the colours are used to identify data from each column.