GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
Data Structures | Enumerations | Functions | Variables
gp_widget_graph.h File Reference

An XY graph. More...

#include <utils/gp_cbuffer.h>
#include <widgets/gp_widget_types.h>
#include <widgets/gp_widget_size_units.h>

Go to the source code of this file.

Data Structures

struct  gp_widget_graph_point
 A graph point. More...
 

Enumerations

enum  gp_widget_graph_style { GP_WIDGET_GRAPH_POINT , GP_WIDGET_GRAPH_LINE , GP_WIDGET_GRAPH_FILL , GP_WIDGET_GRAPH_STYLE_MAX }
 A graph drawing style. More...
 

Functions

gp_widgetgp_widget_graph_new (gp_widget_size min_w, gp_widget_size min_h, const char *x_label, const char *y_label, size_t max_data_points)
 Allocates and initializes a new graph widget.
 
void gp_widget_graph_point_add (gp_widget *self, double x, double y)
 Adds a graph point.
 
void gp_widget_graph_style_set (gp_widget *self, enum gp_widget_graph_style style)
 Sets a graph style.
 
void gp_widget_graph_yrange_set (gp_widget *self, double min_y, double max_y)
 Sets graph y range.
 
void gp_widget_graph_ymin_set (gp_widget *self, double min_y)
 Sets graph y minimum.
 
void gp_widget_graph_ymax_set (gp_widget *self, double max_y)
 Sets graph y maximum.
 
void gp_widget_graph_yrange_clear (gp_widget *self)
 Clears graph y range.
 
void gp_widget_graph_color_set (gp_widget *self, enum gp_widgets_color color)
 Sets graph color.
 

Variables

const char * gp_widget_graph_style_names [GP_WIDGET_GRAPH_STYLE_MAX]
 A graph style names.
 

Detailed Description

An XY graph.

Graph widget JSON attributes

Attribute Type Default Description
color string "text" A graph color, parsed by gp_widgets_color_name_idx().
max_data_points uint 100 Maximal number of graph data points.
min_h string Minimal height, parsed by gp_widget_size_units_parse().
min_w string Minimal width, parsed by gp_widget_size_units_parse().
style string One of "point", "line" or "fill", gp_widget_graph_style.

Definition in file gp_widget_graph.h.

Enumeration Type Documentation

◆ gp_widget_graph_style

A graph drawing style.

Enumerator
GP_WIDGET_GRAPH_POINT 

Point graph.

Graph is drawn using individual points.

GP_WIDGET_GRAPH_LINE 

Points connected by line.

The graph points are connected by a line.

GP_WIDGET_GRAPH_FILL 

Area below graph is filled.

The area bellow the line created by the graph points is filled.

GP_WIDGET_GRAPH_STYLE_MAX 

Maximal number of styles.

Definition at line 35 of file gp_widget_graph.h.

Function Documentation

◆ gp_widget_graph_color_set()

void gp_widget_graph_color_set ( gp_widget self,
enum gp_widgets_color  color 
)

Sets graph color.

Parameters
selfA graph widget.
colorAn color index.

◆ gp_widget_graph_new()

gp_widget * gp_widget_graph_new ( gp_widget_size  min_w,
gp_widget_size  min_h,
const char *  x_label,
const char *  y_label,
size_t  max_data_points 
)

Allocates and initializes a new graph widget.

Parameters
min_wA minimal width.
min_hA minimal height.
x_labelA label for the x axis.
y_labelA label for the y axis.
max_data_pointsA maximal number of graph data points.
Returns
A graph widget.

◆ gp_widget_graph_point_add()

void gp_widget_graph_point_add ( gp_widget self,
double  x,
double  y 
)

Adds a graph point.

The graph data are stored in a circular buffer, when buffer is full the last data point is discarded before new point is added.

Parameters
selfA graph widget.
xA x coordinate of the data point.
yA y coordinate of the data point.

◆ gp_widget_graph_style_set()

void gp_widget_graph_style_set ( gp_widget self,
enum gp_widget_graph_style  style 
)

Sets a graph style.

Parameters
selfA graph widget.
styleA graph style.

◆ gp_widget_graph_ymax_set()

void gp_widget_graph_ymax_set ( gp_widget self,
double  max_y 
)

Sets graph y maximum.

If range is not set the graph is autorange mode and the data will fit the y scale.

Parameters
selfA graph widget.
max_yNew y maximum.

◆ gp_widget_graph_ymin_set()

void gp_widget_graph_ymin_set ( gp_widget self,
double  min_y 
)

Sets graph y minimum.

If range is not set the graph is autorange mode and the data will fit the y scale.

Parameters
selfA graph widget.
min_yNew y minimum.

◆ gp_widget_graph_yrange_clear()

void gp_widget_graph_yrange_clear ( gp_widget self)

Clears graph y range.

Returns graph widget into autorange mode.

Parameters
selfA graph widget.

◆ gp_widget_graph_yrange_set()

void gp_widget_graph_yrange_set ( gp_widget self,
double  min_y,
double  max_y 
)

Sets graph y range.

If range is not set the graph is autorange mode and the data will fit the y scale.

Parameters
selfA graph widget.
min_yNew y minimum.
max_yNew y maximum.