Fude.Data (Fude v0.1.0)

Copy Markdown View Source

The data of a chart, in columns: each field with its type and its values, in the order of the rows.

Fude takes:

  • a list of maps, with atom or string keys;
  • a map of :columns (names) and :rows (lists of values in the columns' order), as a query result has them (Postgrex.Result, Lotus.Result), with atom or string keys.

The values become those the browser draws: a Decimal a number, a Date, NaiveDateTime or DateTime a time (milliseconds since 1970, a date at its midnight in UTC), and anything else that is not a number text. nil stays: it is a gap.

Summary

Functions

The values of a field.

The field of a name, or nil.

The names of the fields, in order.

The data in columns. With only (names), it reads only those fields: a chart reads the few it draws of a query's many. Raises an ArgumentError when the data is none of the forms above.

The data as rows: a list of maps with string keys, as Fude.Spec.dump/2 puts it.

The rows whose field has a value.

Types

field()

@type field() :: %{name: String.t(), type: type(), unit: :day | :month | :year | nil}

t()

@type t() :: %Fude.Data{
  columns: %{required(String.t()) => [term()]},
  count: non_neg_integer(),
  fields: [field()],
  names: [String.t()]
}

type()

@type type() :: :number | :time | :category

Functions

column(data, name)

@spec column(t(), String.t()) :: [term()]

The values of a field.

field(data, name)

@spec field(t(), String.t()) :: field() | nil

The field of a name, or nil.

names(data)

@spec names(t()) :: [String.t()]

The names of the fields, in order.

new(data, only \\ nil)

@spec new(term(), [String.t()] | nil) :: t()

The data in columns. With only (names), it reads only those fields: a chart reads the few it draws of a query's many. Raises an ArgumentError when the data is none of the forms above.

rows(data)

@spec rows(term()) :: [map()]

The data as rows: a list of maps with string keys, as Fude.Spec.dump/2 puts it.

where(data, name, value)

@spec where(t(), String.t(), term()) :: t()

The rows whose field has a value.