RobustChart
Namespace: SnowBank.Numerics · class
Generates ASCII Art that look like plots
Methods
DrawData
static void DrawData(FrameBuffer frame, Data xs, Func<double, double> xAxis, Func<double, double> yAxis, int x0 = 0, int y0 = 0, char c = '*', char nc = 'x')
Draws a series of data onto a frame
frame— Frame where to drawxs— Series of dataxAxis— Scaler for the X axisyAxis— Scaler for the Y axisx0— X coordinate of the originy0— Y coordinate of the originc— "Color" for the pointsnc— "Color" for the missing values
static void DrawData(FrameBuffer frame, Data xs, Data ys, Func<double, double> xAxis, Func<double, double> yAxis, int x0 = 0, int y0 = 0, char c = '*', char nc = 'x')
Draws an X/Y plot onto a frame
frame— Frame where to drawxs— Series of data for the X coordinatesys— Series of data for the Y coordinatesxAxis— Scaler for the X axisyAxis— Scaler for the Y axisx0— X coordinate of the originy0— Y coordinate of the originc— "Color" for the pointsnc— "Color" for the missing values
Render
static string Render(Data ys, int width, int height, double? min = null, double? max = null, int digits = 0, char c = '#')
Renders a Plot
ys— Values for the Y coordinates of the pointswidth— Width (in characters) of the plot. Final width will be larger to accomodate for the axis and labelsheight— Height (in characters) of the plot. Final eight will be larger to accomodate for the axis and labelsmin— Minimum value on the Y axis (automatically computed ifnull)max— Maximum value on the Y axis (automatically computed ifnull)digits— Number of digits used for rounding. If positive, number of decimal digits (ex: 2 for 1.2345=>'1.23'). If positive, number of significant digits (ex: -3 for 123456=>'123000').c— Character used for drawing the points of the series
Returns: Multi-line string that contains the rendered plot
static string Render(Data[] series, int width, int height, double? min = null, double? max = null, int digits = 0, string chars = null)
Renders a Plot
series— List of series to plotwidth— Width (in characters) of the plot. Final width will be larger to accomodate for the axis and labelsheight— Height (in characters) of the plot. Final eight will be larger to accomodate for the axis and labelsmin— Minimum value on the Y axis (automatically computed ifnull)max— Maximum value on the Y axis (automatically computed ifnull)digits— Number of digits used for rounding. If positive, number of decimal digits (ex: 2 for 1.2345=>'1.23'). If positive, number of significant digits (ex: -3 for 123456=>'123000').chars— String with all the characters used for drawing the points of each series.chars[0] is used to drawseries[0], and so on. Modulo is used if there is more series than "colors"
Returns: Multi-line string that contains the rendered plot
RenderFrame
static FrameBuffer RenderFrame(Data ys, int width, int height, double? min = null, double? max = null, int digits = 0, char c = '#')
Renders a Plot
ys— Values for the Y coordinates of the pointswidth— Width (in characters) of the plot. Final width will be larger to accomodate for the axis and labelsheight— Height (in characters) of the plot. Final eight will be larger to accomodate for the axis and labelsmin— Minimum value on the Y axis (automatically computed ifnull)max— Maximum value on the Y axis (automatically computed ifnull)digits— Number of digits used for rounding. If positive, number of decimal digits (ex: 2 for 1.2345=>'1.23'). If positive, number of significant digits (ex: -3 for 123456=>'123000').c— Character used for drawing the points of the series
Returns: Multi-line string that contains the rendered plot
static FrameBuffer RenderFrame(Data[] series, int width, int height, double? min = null, double? max = null, int digits = 0, string chars = null)
Renders a Plot
series— List of series to plotwidth— Width (in characters) of the plot. Final width will be larger to accomodate for the axis and labelsheight— Height (in characters) of the plot. Final eight will be larger to accomodate for the axis and labelsmin— Minimum value on the Y axis (automatically computed ifnull)max— Maximum value on the Y axis (automatically computed ifnull)digits— Number of digits used for rounding. If positive, number of decimal digits (ex: 2 for 1.2345=>'1.23'). If positive, number of significant digits (ex: -3 for 123456=>'123000').chars— String with all the characters used for drawing the points of each series.chars[0] is used to drawseries[0], and so on. Modulo is used if there is more series than "colors"
Returns: Multi-line string that contains the rendered plot
static FrameBuffer RenderFrame(Data xs, Data ys, int width, int height, double? xMin = null, double? xMax = null, double? yMin = null, double? yMax = null, int digits = 0, char c = '#')
Renders a XY Plot
xs— Series for the X coordinatesys— Series for the Y coordinateswidth— Width (in characters) of the plot. Final width will be larger to accomodate for the axis and labelsheight— Height (in characters) of the plot. Final eight will be larger to accomodate for the axis and labelsxMin— Minimum value of the X axis (automatically computed ifnull)xMax— Maximum value of the X axis (automatically computed ifnull)yMin— Minimum value of the Y axis (automatically computed ifnull)yMax— Maximum value of the Y axis (automatically computed ifnull)digits— Number of digits used for rounding. If positive, number of decimal digits (ex: 2 for 1.2345=>'1.23'). If positive, number of significant digits (ex: -3 for 123456=>'123000').c— Character used for drawing the points of the series
Returns: Rendered frame
SigCeiling
static double SigCeiling(double x, int digits)
Rounds a value up to the specified number of digits
x— Value to round downdigits— If positive, number of decimal digits. If negative, number of significant digits
Returns: Rounded value
- SigCeiling(PI, 2) => 3.15 - SigCeiling(123456789, -3) => 123,457,000
SigFloor
static double SigFloor(double x, int digits)
Rounds a value down to the specified number of digits
x— Value to round downdigits— If positive, number of decimal digits. If negative, number of significant digits
Returns: Rounded value
- SigFloor(PI, 2) => 3.14 - SigFloor(123456789, 3) => 123,456,000
SigFormat
static string SigFormat(double x, int digits)
Formats a value
x— Value to formatdigits— If positive, number of decimal digits. If negative, number of significant digitsSigFormat(PI, 2) => "3.15" - SigFormat(123456789, -3) => "123,456,000"