HIPO  4.3.0
High Performance Output data format for experimental physics
ascii::Asciichart Class Reference

ASCII chart renderer for plotting data series in the terminal. More...

#include <ascii.h>

Public Types

enum  Type { LINE = 0 , CIRCLE = 1 }
 Chart rendering mode. More...
 

Public Member Functions

 Asciichart (const std::vector< double > &series)
 Construct an Asciichart from a single data series. More...
 
 Asciichart (const std::vector< std::vector< double >> &series)
 Construct an Asciichart from multiple unnamed data series. More...
 
 Asciichart (const std::unordered_map< std::string, std::vector< double >> &series)
 Construct an Asciichart from named data series (label -> values map). More...
 
Asciicharttype (Type type)
 Set the chart rendering type. More...
 
Asciichartheight (double height)
 Set the height of the chart in data units. More...
 
Asciichartstyles (const std::vector< Style > &styles)
 Set the styles (colors and decorations) for each data series. More...
 
Asciichartmin (double min)
 Set the minimum value displayed on the y-axis. More...
 
Asciichartmax (double max)
 Set the maximum value displayed on the y-axis. More...
 
Asciichartoffset (size_t offset)
 Set the offset (left margin) for the chart content. More...
 
Asciichartlegend_padding (size_t padding)
 Set the padding between series labels and the chart. More...
 
Asciichartshow_legend (bool show)
 Enable or disable the legend display. More...
 
Asciichartsymbols (const std::map< std::string, std::string > &symbols)
 Set custom symbols used to draw the chart. More...
 
std::string Plot ()
 Generate and return the ASCII chart as a string. More...
 

Detailed Description

ASCII chart renderer for plotting data series in the terminal.

Supports line and circle chart types with configurable height, colors, legends, and custom symbols. Uses ANSI escape codes for styling. Charts can be rendered from single or multiple data series with optional labels for each series.

Example usage:

std::vector<double> data = {1.0, 2.5, 2.0, 3.5, 4.0};
ascii::Asciichart chart(data);
chart.height(10).show_legend(true);
std::cout << chart.Plot();
ASCII chart renderer for plotting data series in the terminal.
Definition: ascii.h:35

Definition at line 35 of file ascii.h.

Member Enumeration Documentation

◆ Type

Chart rendering mode.

Enumerator
LINE 

Line chart mode.

CIRCLE 

Circle/point chart mode.

Definition at line 38 of file ascii.h.

Constructor & Destructor Documentation

◆ Asciichart() [1/3]

ascii::Asciichart::Asciichart ( const std::vector< double > &  series)
inlineexplicit

Construct an Asciichart from a single data series.

Parameters
seriesthe data points to plot

Definition at line 48 of file ascii.h.

◆ Asciichart() [2/3]

ascii::Asciichart::Asciichart ( const std::vector< std::vector< double >> &  series)
inlineexplicit

Construct an Asciichart from multiple unnamed data series.

Parameters
seriesa vector of data series to plot

Definition at line 61 of file ascii.h.

◆ Asciichart() [3/3]

ascii::Asciichart::Asciichart ( const std::unordered_map< std::string, std::vector< double >> &  series)
inlineexplicit

Construct an Asciichart from named data series (label -> values map).

Parameters
seriesa map of series names to their data points

Definition at line 74 of file ascii.h.

Member Function Documentation

◆ height()

Asciichart& ascii::Asciichart::height ( double  height)
inline

Set the height of the chart in data units.

If not specified or set to NaN, the height is automatically determined from the data range.

Parameters
heightthe chart height in data units
Returns
a reference to this Asciichart for method chaining

Definition at line 102 of file ascii.h.

◆ legend_padding()

Asciichart& ascii::Asciichart::legend_padding ( size_t  padding)
inline

Set the padding between series labels and the chart.

Parameters
paddingthe space width in characters
Returns
a reference to this Asciichart for method chaining

Definition at line 161 of file ascii.h.

◆ max()

Asciichart& ascii::Asciichart::max ( double  max)
inline

Set the maximum value displayed on the y-axis.

The displayed maximum will be the larger of this value and the actual maximum in the data.

Parameters
maxthe maximum y-value to display
Returns
a reference to this Asciichart for method chaining

Definition at line 138 of file ascii.h.

◆ min()

Asciichart& ascii::Asciichart::min ( double  min)
inline

Set the minimum value displayed on the y-axis.

The displayed minimum will be the smaller of this value and the actual minimum in the data.

Parameters
minthe minimum y-value to display
Returns
a reference to this Asciichart for method chaining

Definition at line 125 of file ascii.h.

◆ offset()

Asciichart& ascii::Asciichart::offset ( size_t  offset)
inline

Set the offset (left margin) for the chart content.

The offset determines how many columns are reserved for the y-axis labels before the plot area begins.

Parameters
offsetthe left margin width in characters
Returns
a reference to this Asciichart for method chaining

Definition at line 151 of file ascii.h.

◆ Plot()

std::string ascii::Asciichart::Plot ( )
inline

Generate and return the ASCII chart as a string.

Returns
the rendered chart as a multi-line string

Definition at line 193 of file ascii.h.

◆ show_legend()

Asciichart& ascii::Asciichart::show_legend ( bool  show)
inline

Enable or disable the legend display.

Parameters
showif true, display series names in the legend
Returns
a reference to this Asciichart for method chaining

Definition at line 171 of file ascii.h.

◆ styles()

Asciichart& ascii::Asciichart::styles ( const std::vector< Style > &  styles)
inline

Set the styles (colors and decorations) for each data series.

Parameters
stylesa vector of Style objects, one per series
Returns
a reference to this Asciichart for method chaining

Definition at line 112 of file ascii.h.

◆ symbols()

Asciichart& ascii::Asciichart::symbols ( const std::map< std::string, std::string > &  symbols)
inline

Set custom symbols used to draw the chart.

Supported symbol keys: "empty", "center", "axis", "c1", "c2", "parellel", "down", "up", "ldown", "lup", "vertical".

Parameters
symbolsa map of symbol names to their characters
Returns
a reference to this Asciichart for method chaining

Definition at line 184 of file ascii.h.

◆ type()

Asciichart& ascii::Asciichart::type ( Type  type)
inline

Set the chart rendering type.

Parameters
typethe chart type (LINE or CIRCLE)
Returns
a reference to this Asciichart for method chaining

Definition at line 89 of file ascii.h.


The documentation for this class was generated from the following file: