Data transformation and statistical utilities.
Provides functions for summarizing data, computing statistics, and transforming data for visualization.
Examples
data = [
%{category: "A", value: 10},
%{category: "A", value: 20},
%{category: "B", value: 15}
]
Visualize.Data.extent(data, & &1.value)
# => {10, 20}
Visualize.Data.group(data, & &1.category)
# => %{"A" => [...], "B" => [...]}
Summary
Functions
Creates histogram bins from continuous data.
Creates a cross product of two arrays.
Returns the standard deviation.
Returns {min, max} as a tuple.
Groups data by a key function.
Largest-Triangle-Three-Buckets: about n of the elements, chosen to keep the series'
visual shape (spec/08 §5.2; Steinarsson 2013).
M4: per pixel column, the first, last, least-y and greatest-y elements — the
elements a line drawn width pixels wide needs to draw the same pixels as all of them
(spec/08 §5.2; Jugel et al. 2014).
Returns the maximum value.
Returns the arithmetic mean.
Returns the median value.
Returns the minimum value.
Returns the p-quantile value.
Generates a range of numbers.
Groups data and applies a reducer to each group.
Sorts data by an accessor function.
Returns the sum of values.
Generates evenly-spaced tick values for a domain.
Returns unique values by accessor.
Returns the variance of values.
Functions
Creates histogram bins from continuous data.
Options
:thresholds- number of bins or list of threshold values:domain- [min, max] range to bin
Examples
Visualize.Data.bin([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], thresholds: 5)
# Returns list of bins with :x0, :x1, :values keys
Creates a cross product of two arrays.
Examples
Visualize.Data.cross([1, 2], ["a", "b"])
# => [{1, "a"}, {1, "b"}, {2, "a"}, {2, "b"}]
Returns the standard deviation.
Returns {min, max} as a tuple.
Examples
Visualize.Data.extent([3, 1, 4, 1, 5])
# => {1, 5}
Visualize.Data.extent(data, & &1.value)
# => {min_value, max_value}
Groups data by a key function.
Returns a map where keys are the result of the key function and values are lists of matching elements.
Examples
data = [%{cat: "A", val: 1}, %{cat: "A", val: 2}, %{cat: "B", val: 3}]
Visualize.Data.group(data, & &1.cat)
# => %{"A" => [%{cat: "A", val: 1}, %{cat: "A", val: 2}], "B" => [%{cat: "B", val: 3}]}
Largest-Triangle-Three-Buckets: about n of the elements, chosen to keep the series'
visual shape (spec/08 §5.2; Steinarsson 2013).
The accessor returns {x, y}; without one the elements are {x, y} tuples. A datum
whose x or y is not a number is a gap: the defined data are reduced run by run
between the gaps, and each run of gaps keeps its first element in place, so a line over
the result still breaks where the input broke. Input of n or fewer elements is
returned unchanged; without gaps the result is exactly n elements, the first and the
last among them. n must be at least 3.
Examples
iex> Visualize.Data.lttb([{0, 0}, {1, 1}, {2, 0}, {3, 5}, {4, 0}, {5, 1}, {6, 0}], 4)
[{0, 0}, {2, 0}, {3, 5}, {6, 0}]
iex> Visualize.Data.lttb([{0, 0}, {1, 3}, {2, nil}, {3, 4}, {4, 1}], 9)
[{0, 0}, {1, 3}, {2, nil}, {3, 4}, {4, 1}]
M4: per pixel column, the first, last, least-y and greatest-y elements — the
elements a line drawn width pixels wide needs to draw the same pixels as all of them
(spec/08 §5.2; Jugel et al. 2014).
The columns split the extent of the defined x readings evenly. The accessor, the gaps
and the runs are as lttb/3's: each run of gaps keeps its first element in place, and
each stretch of one run in one column keeps at most four elements, deduplicated and in
input order. width must be at least 1.
Examples
iex> Visualize.Data.m4([{0, 1}, {1, 5}, {2, 0}, {3, 2}, {4, 3}, {5, 9}, {6, 4}, {7, 6}], 2)
[{0, 1}, {1, 5}, {2, 0}, {3, 2}, {4, 3}, {5, 9}, {7, 6}]
iex> Visualize.Data.m4([{0, 1}, {1, 2}, {2, nil}, {3, nil}, {4, 3}], 1)
[{0, 1}, {1, 2}, {2, nil}, {4, 3}]
Returns the maximum value.
Returns the arithmetic mean.
Returns the median value.
Returns the minimum value.
Examples
Visualize.Data.min([3, 1, 4, 1, 5])
# => 1
Visualize.Data.min(data, & &1.value)
# => minimum value from data
Returns the p-quantile value.
p should be between 0 and 1.
Generates a range of numbers.
Examples
Visualize.Data.range(0, 5)
# => [0, 1, 2, 3, 4]
Visualize.Data.range(0, 1, 0.2)
# => [0, 0.2, 0.4, 0.6, 0.8]
Groups data and applies a reducer to each group.
Examples
data = [%{cat: "A", val: 1}, %{cat: "A", val: 2}, %{cat: "B", val: 3}]
Visualize.Data.rollup(data, & &1.cat, &length/1)
# => %{"A" => 2, "B" => 1}
Visualize.Data.rollup(data, & &1.cat, fn items ->
Visualize.Data.sum(items, & &1.val)
end)
# => %{"A" => 3, "B" => 3}
Sorts data by an accessor function.
Returns the sum of values.
Generates evenly-spaced tick values for a domain.
Useful for creating axis ticks without a scale.
Returns unique values by accessor.
Returns the variance of values.