Raxol. UI. Charts. ChartUtils
(Raxol v2.6.0)
View Source
Shared utilities for chart rendering: scaling, range computation, axis/legend cell generation, and data normalization.
Summary
Functions
Computes a display range with 5% padding on each side.
Returns {min, max}. Single-value and empty inputs are handled gracefully.
Computes an auto range for 2D {x, y} data.
Returns {{x_min, x_max}, {y_min, y_max}}.
Computes the plot region within a chart area, reserving space for axes and legend.
Formats a number as an axis label string with configurable precision.
Formats a number with 1 decimal place.
Normalizes a list or CircularBuffer to a plain list of numbers.
Normalizes a list or CircularBuffer of {x, y} tuples to a plain list.
Renders Y-axis labels and X-axis line as cell tuples.
Renders a legend showing series names with their colors.
Resolves a Y-axis range from data values and opts (:min, :max).
Falls back to auto_range/1 for :auto bounds. Empty data defaults to {0.0, 1.0}.
Linearly scales a value from [min, max] to [new_min, new_max].
Returns new_min when min == max to avoid division by zero.
Converts a string into a list of cell tuples placed at consecutive X positions.
Summarizes series for MCP tool output: name, color, and normalized 1D data.
Summarizes series for MCP tool output with 2D {x, y} data.
Types
@type cell() :: {non_neg_integer(), non_neg_integer(), String.t(), atom(), atom(), map()}
Functions
Computes a display range with 5% padding on each side.
Returns {min, max}. Single-value and empty inputs are handled gracefully.
Computes an auto range for 2D {x, y} data.
Returns {{x_min, x_max}, {y_min, y_max}}.
@spec compute_plot_region( non_neg_integer(), non_neg_integer(), pos_integer(), pos_integer(), boolean(), boolean() ) :: map()
Computes the plot region within a chart area, reserving space for axes and legend.
Formats a number as an axis label string with configurable precision.
Formats a number with 1 decimal place.
Normalizes a list or CircularBuffer to a plain list of numbers.
Normalizes a list or CircularBuffer of {x, y} tuples to a plain list.
@spec render_axes( {non_neg_integer(), non_neg_integer(), pos_integer(), pos_integer()}, {number(), number()}, keyword() ) :: [cell()]
Renders Y-axis labels and X-axis line as cell tuples.
@spec render_legend(non_neg_integer(), non_neg_integer(), [map()]) :: [cell()]
Renders a legend showing series names with their colors.
Resolves a Y-axis range from data values and opts (:min, :max).
Falls back to auto_range/1 for :auto bounds. Empty data defaults to {0.0, 1.0}.
Linearly scales a value from [min, max] to [new_min, new_max].
Returns new_min when min == max to avoid division by zero.
@spec string_to_cells( String.t(), non_neg_integer(), non_neg_integer(), atom(), atom() ) :: [cell()]
Converts a string into a list of cell tuples placed at consecutive X positions.
Summarizes series for MCP tool output: name, color, and normalized 1D data.
Summarizes series for MCP tool output with 2D {x, y} data.