Raxol.Terminal.Graphics.ChartDataUtils (Raxol v2.0.1)
View SourceShared utilities for chart data processing and transformation.
This module contains common functions used across different chart modules to avoid code duplication and ensure consistent data processing behavior.
Summary
Functions
Flattens 2D heatmap data into a list of data points.
Converts histogram values into data points with binning.
Functions
Flattens 2D heatmap data into a list of data points.
Takes a 2D array (list of lists) and converts it into a flat list of data points with x, y coordinates and values.
Parameters
data- 2D array (list of rows, where each row is a list of values)
Returns
List of maps with :x, :y, :value, and :timestamp keys.
Examples
iex> data = [[1, 2], [3, 4]]
iex> ChartDataUtils.flatten_heatmap_data(data)
[
%{x: 0, y: 0, value: 1, timestamp: _},
%{x: 1, y: 0, value: 2, timestamp: _},
%{x: 0, y: 1, value: 3, timestamp: _},
%{x: 1, y: 1, value: 4, timestamp: _}
]
Converts histogram values into data points with binning.
Takes a list of values and creates histogram bins with counts.
Parameters
values- List of numeric values to binconfig- Configuration map with optional :bins key (defaults to 10)
Returns
List of maps representing histogram bins with counts.
Examples
iex> values = [1, 2, 3, 4, 5]
iex> config = %{bins: 3}
iex> ChartDataUtils.histogram_data_points(values, config)
[
%{bin: 0, start: 1.0, end: 2.33, count: 2, timestamp: _},
%{bin: 1, start: 2.33, end: 3.67, count: 2, timestamp: _},
%{bin: 2, start: 3.67, end: 5.0, count: 1, timestamp: _}
]