Skip to main content

render_chart

Function render_chart 

Source
pub fn render_chart(
    series: &[(&str, &[(f64, f64)])],
    width_cells: usize,
    height_cells: usize,
    style: CanvasStyle,
) -> String
Expand description

Render one or more named (label, points) series into a single framed chart.

  • Axis ranges are auto-scaled from the data: min/max x and min/max y across every series. The y range and every series label are printed on the top border; the x range is printed on the bottom border — “framed chart string with x/y axis ranges printed on the border”, per the ticket.
  • Points are plotted as dots only; there is no line interpolation between consecutive samples. Dense series (trajectory integration output, which this is built for, easily has hundreds to thousands of points over a 72-cell-wide canvas) render as a continuous-looking curve purely from sample density; sparse series will look like literally scattered dots. Adding Bresenham-style line segments was considered and dropped: it’s not needed for the trajectory use case and would be extra surface to get right for no visible benefit there.
  • width_cells/height_cells size only the PLOT AREA. The returned string is width_cells + 2 characters wide (a left/right frame column) and height_cells + 2 lines tall (top/bottom frame rows), with no trailing newline.
  • A degenerate axis (every point shares the same x, or the same y) is expanded by ±0.5 around that single value so the scale never divides by zero.
  • Non-finite (NaN/inf) coordinates are skipped entirely — they neither affect the autoscale range nor get plotted — rather than corrupting the whole chart’s scale.