EasyGUI  v0.1
Platform independent GUI Library
Graph

Graph which can display plots. More...

Data Structures

struct  GUI_GRAPH_DATA_t
 Graph data widget structure. More...
 
struct  GUI_GRAPH_t
 Graph widget structure. More...
 

Typedefs

typedef GUI_GRAPH_DATA_tGUI_GRAPH_DATA_p
 

Enumerations

enum  GUI_GRAPH_COLOR_t { GUI_GRAPH_COLOR_BG = 0x00, GUI_GRAPH_COLOR_FG = 0x01, GUI_GRAPH_COLOR_BORDER = 0x02, GUI_GRAPH_COLOR_GRID = 0x03 }
 Graph color list enumeration. More...
 
enum  GUI_GRAPH_BORDER_t { GUI_GRAPH_BORDER_TOP = 0x00, GUI_GRAPH_BORDER_RIGHT = 0x01, GUI_GRAPH_BORDER_BOTTOM = 0x02, GUI_GRAPH_BORDER_LEFT = 0x03 }
 Graph border list enumeration. More...
 
enum  GUI_GRAPH_TYPE_t { GUI_GRAPH_TYPE_YT = 0x00, GUI_GRAPH_TYPE_XY = 0x01 }
 Graph type enumeration. More...
 

Functions

GUI_HANDLE_p gui_graph_create (GUI_ID_t id, GUI_iDim_t x, GUI_iDim_t y, GUI_Dim_t width, GUI_Dim_t height, GUI_HANDLE_p parent, GUI_WIDGET_CALLBACK_t cb, uint16_t flags)
 Create new graph widget. More...
 
uint8_t gui_graph_setcolor (GUI_HANDLE_p h, GUI_GRAPH_COLOR_t index, GUI_Color_t color)
 Set color to specific part of widget. More...
 
uint8_t gui_graph_setminx (GUI_HANDLE_p h, float v)
 Set minimal X value of plot. More...
 
uint8_t gui_graph_setmaxx (GUI_HANDLE_p h, float v)
 Set maximal X value of plot. More...
 
uint8_t gui_graph_setminy (GUI_HANDLE_p h, float v)
 Set minimal Y value of plot. More...
 
uint8_t gui_graph_setmaxy (GUI_HANDLE_p h, float v)
 Set maximal Y value of plot. More...
 
uint8_t gui_graph_zoomreset (GUI_HANDLE_p h)
 Reset zoom of widget. More...
 
uint8_t gui_graph_zoom (GUI_HANDLE_p h, float zoom, float x, float y)
 Zoom widget display data. More...
 
uint8_t gui_graph_attachdata (GUI_HANDLE_p h, GUI_GRAPH_DATA_p data)
 Attach new data object to graph widget. More...
 
uint8_t gui_graph_detachdata (GUI_HANDLE_p h, GUI_GRAPH_DATA_p data)
 Detach existing data object from graph widget. More...
 
GUI_GRAPH_DATA_p gui_graph_data_create (GUI_GRAPH_TYPE_t type, size_t length)
 Creates data object according to specific type. More...
 
uint8_t gui_graph_data_addvalue (GUI_GRAPH_DATA_p data, int16_t x, int16_t y)
 Add new value to the end of data object. More...
 
uint8_t gui_graph_data_setcolor (GUI_GRAPH_DATA_p data, GUI_Color_t color)
 Set color for graph data. More...
 

Detailed Description

Graph which can display plots.

Graph widget to display plot lines of 2 different types, either XY or YT.

image_widget_graph.png
Graph widget with 2 data plots. Red is XY and green is YT

Example code for image above

handle = gui_graph_create(ID_GRAPH_MAIN, 10, 10, 400, 220, h, 0, 0);
//Create data objects
if (!graphdata1) {
graphdata1->Color = GUI_COLOR_RED;
}
if (!graphdata2) {
graphdata2 = gui_graph_data_create(GUI_GRAPH_TYPE_YT, len / 2);
graphdata2->Color = GUI_COLOR_GREEN;
}
//Fill data objects
for (i = 0; i <= 360; i += 360 / len) {
x = cos((float)i * (PI / 180.0f));
y = sin((float)i * (PI / 180.0f));
gui_graph_data_addvalue(graphdata1, x * radius, y * radius);
gui_graph_data_addvalue(graphdata2, x * radius / 3, y * radius / 4);
}
gui_graph_attachdata(handle, graphdata1);
gui_graph_attachdata(handle, graphdata2);

Typedef Documentation

GUI Graph data pointer

Enumeration Type Documentation

Graph border list enumeration.

Enumerator
GUI_GRAPH_BORDER_TOP 

Border top index

GUI_GRAPH_BORDER_RIGHT 

Border right index

GUI_GRAPH_BORDER_BOTTOM 

Border bottom index

GUI_GRAPH_BORDER_LEFT 

Border left index

Graph color list enumeration.

See also
gui_graph_setcolor
Enumerator
GUI_GRAPH_COLOR_BG 

Background color index

GUI_GRAPH_COLOR_FG 

Foreground color index (background of plotting area)

GUI_GRAPH_COLOR_BORDER 

Border color index

GUI_GRAPH_COLOR_GRID 

Grid color index

Graph type enumeration.

Enumerator
GUI_GRAPH_TYPE_YT 

Data type is Y versus time

GUI_GRAPH_TYPE_XY 

Data type is Y versus X [Y(x)]

Function Documentation

uint8_t gui_graph_attachdata ( GUI_HANDLE_p  h,
GUI_GRAPH_DATA_p  data 
)

Attach new data object to graph widget.

Parameters
[in,out]hGraph widget handle
[in]dataData object handle
Return values
1Attaching was successful
0Attaching failed
See also
gui_graph_detachdata

Linked list of data plots for this graph

GUI_HANDLE_p gui_graph_create ( GUI_ID_t  id,
GUI_iDim_t  x,
GUI_iDim_t  y,
GUI_Dim_t  width,
GUI_Dim_t  height,
GUI_HANDLE_p  parent,
GUI_WIDGET_CALLBACK_t  cb,
uint16_t  flags 
)

Create new graph widget.

Parameters
[in]idWidget unique ID to use for identity for callback processing
[in]xWidget X position relative to parent widget
[in]yWidget Y position relative to parent widget
[in]widthWidget width in units of pixels
[in]heightWidget height in uints of pixels
[in]parentParent widget handle. Set to NULL to use current active parent widget
[in]cbPointer to GUI_WIDGET_CALLBACK_t callback function. Set to NULL to use default widget callback
[in]flagsFlags for create procedure
Return values
>0: GUI_HANDLE_p object of created widget
0Widget creation failed
uint8_t gui_graph_data_addvalue ( GUI_GRAPH_DATA_p  data,
int16_t  x,
int16_t  y 
)

Add new value to the end of data object.

Parameters
[in]dataData object handle
[in]xX position for point. Used only in case data type is GUI_GRAPH_TYPE_XY, otherwise it is ignored
[in]yY position for point. Always used no matter of data type
Return values
1Value was added to data object ok
0Value was not added to data object
GUI_GRAPH_DATA_p gui_graph_data_create ( GUI_GRAPH_TYPE_t  type,
size_t  length 
)

Creates data object according to specific type.

Note
Data type used in graph widget is 2-byte (short int)
When
  • GUI_GRAPH_TYPE_XY is used, 2 * length * sizeof(short int) of bytes is allocated for X and Y value
Parameters
[in]typeType of data. According to selected type different allocation size will occur
[in]lengthNumber of points on plot.
Return values
>0: GUI_GRAPH_DATA_p object of created widget
0Data creation failed
uint8_t gui_graph_data_setcolor ( GUI_GRAPH_DATA_p  data,
GUI_Color_t  color 
)

Set color for graph data.

Parameters
[in,out]dataPointer to GUI_GRAPH_DATA_p structure with valid data
[in]colorNew color for data
Return values
1New color set ok
0New color was not set
uint8_t gui_graph_detachdata ( GUI_HANDLE_p  h,
GUI_GRAPH_DATA_p  data 
)

Detach existing data object from graph widget.

Parameters
[in,out]hGraph widget handle
[in]dataData object handle
Return values
1Detaching was successful
0Detaching failed
See also
gui_graph_attachdata

Linked list of data plots for this graph Remove data from graph's linked list

uint8_t gui_graph_setcolor ( GUI_HANDLE_p  h,
GUI_GRAPH_COLOR_t  index,
GUI_Color_t  color 
)

Set color to specific part of widget.

Parameters
[in,out]hWidget handle
[in]indexColor index. This parameter can be a value of GUI_GRAPH_COLOR_t enumeration
[in]colorColor value
Return values
1Color was set ok
0Color was not set
uint8_t gui_graph_setmaxx ( GUI_HANDLE_p  h,
float  v 
)

Set maximal X value of plot.

Parameters
[in,out]hWidget handle
[in]vNew maximal X value
Return values
1Value was set ok
0Value was not set
See also
gui_graph_setminx, gui_graph_setminy, gui_graph_setmaxy
uint8_t gui_graph_setmaxy ( GUI_HANDLE_p  h,
float  v 
)

Set maximal Y value of plot.

Parameters
[in,out]hWidget handle
[in]vNew maximal Y value
Return values
1Value was set ok
0Value was not set
See also
gui_graph_setminx, gui_graph_setmaxx, gui_graph_setminy
uint8_t gui_graph_setminx ( GUI_HANDLE_p  h,
float  v 
)

Set minimal X value of plot.

Parameters
[in,out]hWidget handle
[in]vNew minimal X value
Return values
1Value was set ok
0Value was not set
See also
gui_graph_setmaxx, gui_graph_setminy, gui_graph_setmaxy
uint8_t gui_graph_setminy ( GUI_HANDLE_p  h,
float  v 
)

Set minimal Y value of plot.

Parameters
[in,out]hWidget handle
[in]vNew minimal Y value
Return values
1Value was set ok
0Value was not set
See also
gui_graph_setminx, gui_graph_setmaxx, gui_graph_setmaxy
uint8_t gui_graph_zoom ( GUI_HANDLE_p  h,
float  zoom,
float  x,
float  y 
)

Zoom widget display data.

Parameters
[in,out]hWidget handle
[in]zoomZoom coeficient. Use 2.0f to double zoom, use 0.5 to unzoom 2 times, etc.
[in]xX coordinate on plot where zoom focus will apply. Valid value between 0 and 1 relative to width area. Use 0.5 to zoom to center
[in]yY coordinate on plot where zoom focus will apply. Valid value between 0 and 1 relative to height area. Use 0.5 to zoom to center
Return values
1Zoom was reseted
0Zoom was not reseted
uint8_t gui_graph_zoomreset ( GUI_HANDLE_p  h)

Reset zoom of widget.

Parameters
[in,out]hWidget handle
Return values
1Zoom was reseted
0Zoom was not reseted