RMGui 0.15.0
C11 retained-mode UI library: layout kernel, style schema, widget painters, fonts, software framebuffer
Loading...
Searching...
No Matches
chart_plot.h File Reference

chart_plot.h — the plot painters over a chart series or a precomputed column array: line, area-under-line and min/max band, the nearest-sample hit test, the crosshair and the legend row. More...

#include <stddef.h>
#include <stdint.h>
#include "fb.h"
#include "font.h"
#include "geom.h"
#include "style.h"
#include "chart_axis.h"
#include "chart_series.h"
#include "draw_target.h"
#include "ui_context.h"

Data Structures

struct  rmgui_chart_plot_samples_view_t
 A sample plot borrowing a chart window and a live series. More...
struct  rmgui_chart_plot_columns_view_t
 A plot borrowing a chart window and count reduced columns. More...
struct  rmgui_chart_legend_view_t
 A legend borrowing count names and their UTF-8 byte lengths. More...

Enumerations

enum  { RMGUI_CHART_PLOT_LINE = 1 , RMGUI_CHART_PLOT_AREA = 2 , RMGUI_CHART_PLOT_BAND = 4 }

Functions

void rmgui_chart_plot_samples (rmgui_fb_t *fb, rmgui_rect_t rect, rmgui_rect_t clip, const rmgui_chart_view_t *view, const rmgui_style_resolved_t *rs, const rmgui_chart_series_t *series, int series_index, unsigned flags)
 Paints series (every sample, oldest first) into the window view with the roles of rs->series[series_index]: LINE the 1 px polyline, AREA the fill under it plus the line, BAND for every pixel column holding at least one sample the rows from that column's max value to its min (columns without samples paint nothing).
void rmgui_chart_plot_samples_to (rmgui_target_t *, rmgui_rect_t, rmgui_rect_t, const rmgui_chart_view_t *, const rmgui_style_resolved_t *, const rmgui_chart_series_t *, int, unsigned)
 Explicit destination sample plot, identical mapping and paint order.
void rmgui_chart_plot_columns (rmgui_fb_t *fb, rmgui_rect_t rect, rmgui_rect_t clip, const rmgui_chart_view_t *view, const rmgui_style_resolved_t *rs, const rmgui_chart_column_t *cols, size_t n, int series_index, unsigned flags)
 Paints the pre-downsampled cols[0, n) covering the window view left to right, each column i spanning the x range the suite mapping gives its t interval.
int rmgui_chart_plot_hit (const rmgui_rect_t *rect, const rmgui_chart_view_t *view, const rmgui_chart_series_t *series, int x, size_t *idx)
 Nearest sample to pixel column x, ties toward the older (lower) index, into *idx; returns 0.
void rmgui_chart_crosshair_paint (rmgui_fb_t *fb, rmgui_rect_t rect, rmgui_rect_t clip, const rmgui_chart_view_t *view, const rmgui_style_resolved_t *rs, const rmgui_chart_series_t *series, size_t idx, rmgui_font_t *font, int font_px)
 Crosshair for the sample idx: a 1 px vertical rs->crosshair hairline across the rect at the sample's x and a 1 px-radius rs->crosshair disc about the sample pixel's centre.
void rmgui_chart_legend_paint (rmgui_fb_t *fb, rmgui_rect_t rect, rmgui_rect_t clip, const rmgui_style_resolved_t *rs, rmgui_font_t *font, int font_px, const char *const *names, const uint32_t *name_lens, int count)
 Legend row: per series a font_px-square swatch of rs->series[i] (index clamped to 5) top-aligned at rect.y, then the name in rs->text at font_px, entries left to right from rect.x separated by font_px gaps (swatch-to-text: font_px / 2).
void rmgui_chart_plot_columns_to (rmgui_target_t *, rmgui_rect_t, rmgui_rect_t, const rmgui_chart_view_t *, const rmgui_style_resolved_t *, const rmgui_chart_column_t *, size_t, int, unsigned)
 Explicit destination columns with CPU plot flags and coverage.
void rmgui_chart_crosshair_paint_to (rmgui_target_t *, rmgui_rect_t, rmgui_rect_t, const rmgui_chart_view_t *, const rmgui_style_resolved_t *, const rmgui_chart_series_t *, size_t, rmgui_font_t *, int)
 Explicit crosshair destination; the font parameters remain unused.
void rmgui_chart_legend_paint_to (rmgui_target_t *, rmgui_rect_t, rmgui_rect_t, const rmgui_style_resolved_t *, rmgui_font_t *, int, const char *const *, const uint32_t *, int)
 Explicit legend destination; RECORD requires prepared name glyphs.
int rmgui_chart_plot_samples_draw (const rmgui_ui_t *ui, const rmgui_chart_plot_samples_view_t *plot, rmgui_rect_t rect)
 Draw a valid sample plot.
int rmgui_chart_plot_columns_draw (const rmgui_ui_t *ui, const rmgui_chart_plot_columns_view_t *plot, rmgui_rect_t rect)
 Draw reduced columns.
int rmgui_chart_crosshair_draw (const rmgui_ui_t *ui, const rmgui_chart_plot_samples_view_t *plot, size_t index, rmgui_rect_t rect)
 Draw a crosshair at a valid sample index in the plot, without text.
int rmgui_chart_legend_prepare (const rmgui_ui_t *ui, const rmgui_chart_legend_view_t *legend)
 Prepare the legend's labels before recording.
int rmgui_chart_legend_draw (const rmgui_ui_t *ui, const rmgui_chart_legend_view_t *legend, rmgui_rect_t rect)
 Draw legend swatches and labels; without a font nothing is drawn.

Detailed Description

chart_plot.h — the plot painters over a chart series or a precomputed column array: line, area-under-line and min/max band, the nearest-sample hit test, the crosshair and the legend row.

Mapping (the suite rule, binding): a sample at relative t and value v paints at x = rect.x + (t - t0) * rect.w / (t1 - t0) and, the value axis inverted, y = rect.y + (v1 - v) * rect.h / (v1 - v0); both in int64, truncating. Timestamps subtract wrap-safe. Values outside [v0, v1] clamp to the rect edge rows; timestamps outside [t0, t1] clamp to the edge columns (v0 and t0 paint on the last row/column, v1 and t1 on the first). Lines are polylines of 1 px rmgui_draw_aa_line BUTT segments in OVER mode; AREA fills, per pixel column between the first and last sample's x, from the line's y at that column down to the rect's bottom row, then paints the line over it. Every painter writes only pixels inside the intersection of clip and rect, refused inputs paint nothing, and no call allocates.

Constants

What rmgui_chart_plot_samples and rmgui_chart_plot_columns paint: a bitwise-or of these; any other bit refuses.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
RMGUI_CHART_PLOT_LINE 
RMGUI_CHART_PLOT_AREA 
RMGUI_CHART_PLOT_BAND 

Function Documentation

◆ rmgui_chart_plot_samples()

void rmgui_chart_plot_samples ( rmgui_fb_t * fb,
rmgui_rect_t rect,
rmgui_rect_t clip,
const rmgui_chart_view_t * view,
const rmgui_style_resolved_t * rs,
const rmgui_chart_series_t * series,
int series_index,
unsigned flags )

Paints series (every sample, oldest first) into the window view with the roles of rs->series[series_index]: LINE the 1 px polyline, AREA the fill under it plus the line, BAND for every pixel column holding at least one sample the rows from that column's max value to its min (columns without samples paint nothing).

The polyline's cost is bounded by the rect's pixel width, not the sample count: the samples that map to one pixel column are drawn as one vertical segment over that column's value extent, so the per-column minimum and maximum are always painted; columns holding one or two samples paint exactly the per-sample polyline. In a denser column the connector from the previous column lands on the extent end nearer the column's first sample and the connector to the next column leaves from the other end, not from the column's last sample. NULL fb, view, rs or series, an empty rect, an empty or inverted view (t1 <= t0 or v1 <= v0), series_index outside 0..5, an empty series or unknown flag bits paint nothing.

◆ rmgui_chart_plot_samples_to()

void rmgui_chart_plot_samples_to ( rmgui_target_t * ,
rmgui_rect_t ,
rmgui_rect_t ,
const rmgui_chart_view_t * ,
const rmgui_style_resolved_t * ,
const rmgui_chart_series_t * ,
int ,
unsigned  )

Explicit destination sample plot, identical mapping and paint order.

RECORD appends bounded value/AA commands without allocation; failures latch.

◆ rmgui_chart_plot_columns()

void rmgui_chart_plot_columns ( rmgui_fb_t * fb,
rmgui_rect_t rect,
rmgui_rect_t clip,
const rmgui_chart_view_t * view,
const rmgui_style_resolved_t * rs,
const rmgui_chart_column_t * cols,
size_t n,
int series_index,
unsigned flags )

Paints the pre-downsampled cols[0, n) covering the window view left to right, each column i spanning the x range the suite mapping gives its t interval.

BAND fills each column's rows from y(max) to y(min) inclusive — except a column with min == max == 0, the no-data sentinel from rmgui_chart_series_columns, which paints nothing. LINE joins the column tops (a point per non-sentinel column at its left edge and max value). AREA fills under those tops to the rect's bottom row, then paints the line over it. Refusals as for rmgui_chart_plot_samples, plus NULL cols or n == 0.

◆ rmgui_chart_plot_hit()

int rmgui_chart_plot_hit ( const rmgui_rect_t * rect,
const rmgui_chart_view_t * view,
const rmgui_chart_series_t * series,
int x,
size_t * idx )

Nearest sample to pixel column x, ties toward the older (lower) index, into *idx; returns 0.

Returns -1 without touching *idx when rect, view, series or idx is NULL, the rect is empty, the view is empty or inverted, x lies outside the rect, or the series is empty.

◆ rmgui_chart_crosshair_paint()

void rmgui_chart_crosshair_paint ( rmgui_fb_t * fb,
rmgui_rect_t rect,
rmgui_rect_t clip,
const rmgui_chart_view_t * view,
const rmgui_style_resolved_t * rs,
const rmgui_chart_series_t * series,
size_t idx,
rmgui_font_t * font,
int font_px )

Crosshair for the sample idx: a 1 px vertical rs->crosshair hairline across the rect at the sample's x and a 1 px-radius rs->crosshair disc about the sample pixel's centre.

The host paints its own readout text, so font and font_px carry no text; they keep the chart suite's uniform painter signature. Refusals as for rmgui_chart_plot_samples, plus idx out of range.

◆ rmgui_chart_legend_paint()

void rmgui_chart_legend_paint ( rmgui_fb_t * fb,
rmgui_rect_t rect,
rmgui_rect_t clip,
const rmgui_style_resolved_t * rs,
rmgui_font_t * font,
int font_px,
const char *const * names,
const uint32_t * name_lens,
int count )

Legend row: per series a font_px-square swatch of rs->series[i] (index clamped to 5) top-aligned at rect.y, then the name in rs->text at font_px, entries left to right from rect.x separated by font_px gaps (swatch-to-text: font_px / 2).

A name longer than the remaining width is cut at a UTF-8 boundary (rmgui_font_fit); once an entry does not fit, the row ends. NULL fb, rs, font, names or name_lens, count <= 0, font_px < 1 or an empty clip-rect overlap paints nothing.

◆ rmgui_chart_plot_columns_to()

void rmgui_chart_plot_columns_to ( rmgui_target_t * ,
rmgui_rect_t ,
rmgui_rect_t ,
const rmgui_chart_view_t * ,
const rmgui_style_resolved_t * ,
const rmgui_chart_column_t * ,
size_t ,
int ,
unsigned  )

Explicit destination columns with CPU plot flags and coverage.

RECORD snapshots values into bounded commands; no allocation.

◆ rmgui_chart_crosshair_paint_to()

void rmgui_chart_crosshair_paint_to ( rmgui_target_t * ,
rmgui_rect_t ,
rmgui_rect_t ,
const rmgui_chart_view_t * ,
const rmgui_style_resolved_t * ,
const rmgui_chart_series_t * ,
size_t ,
rmgui_font_t * ,
int  )

Explicit crosshair destination; the font parameters remain unused.

◆ rmgui_chart_legend_paint_to()

void rmgui_chart_legend_paint_to ( rmgui_target_t * ,
rmgui_rect_t ,
rmgui_rect_t ,
const rmgui_style_resolved_t * ,
rmgui_font_t * ,
int ,
const char *const * ,
const uint32_t * ,
int  )

Explicit legend destination; RECORD requires prepared name glyphs.

Swatches and text use the same clipping and colors as CPU.

◆ rmgui_chart_plot_samples_draw()

int rmgui_chart_plot_samples_draw ( const rmgui_ui_t * ui,
const rmgui_chart_plot_samples_view_t * plot,
rmgui_rect_t rect )

Draw a valid sample plot.

Returns 0 or -1 for invalid arguments or style; paint errors are reported by the target.

◆ rmgui_chart_plot_columns_draw()

int rmgui_chart_plot_columns_draw ( const rmgui_ui_t * ui,
const rmgui_chart_plot_columns_view_t * plot,
rmgui_rect_t rect )

Draw reduced columns.

Returns 0 or -1 for invalid arguments or style; paint errors are reported by the target.

◆ rmgui_chart_crosshair_draw()

int rmgui_chart_crosshair_draw ( const rmgui_ui_t * ui,
const rmgui_chart_plot_samples_view_t * plot,
size_t index,
rmgui_rect_t rect )

Draw a crosshair at a valid sample index in the plot, without text.

Returns 0 or -1 for invalid arguments or style; paint errors are reported by the target.

◆ rmgui_chart_legend_prepare()

int rmgui_chart_legend_prepare ( const rmgui_ui_t * ui,
const rmgui_chart_legend_view_t * legend )

Prepare the legend's labels before recording.

CPU targets and contexts without a font need no preparation. Returns 0 or -1 on error.

◆ rmgui_chart_legend_draw()

int rmgui_chart_legend_draw ( const rmgui_ui_t * ui,
const rmgui_chart_legend_view_t * legend,
rmgui_rect_t rect )

Draw legend swatches and labels; without a font nothing is drawn.

Returns 0 or -1 for invalid arguments or style; paint errors are reported by the target.