2016-08-08 16:25:41 +02:00
|
|
|
/**
|
|
|
|
* @file lv_chart.h
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2017-04-24 16:16:36 +02:00
|
|
|
#ifndef LV_CHART_H
|
|
|
|
#define LV_CHART_H
|
2016-08-08 16:25:41 +02:00
|
|
|
|
2017-07-09 15:32:49 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2016-08-08 16:25:41 +02:00
|
|
|
/*********************
|
|
|
|
* INCLUDES
|
|
|
|
*********************/
|
2019-12-26 02:49:30 +01:00
|
|
|
#include "../lv_conf_internal.h"
|
2018-07-07 11:53:22 +02:00
|
|
|
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_CHART != 0
|
2016-08-08 16:25:41 +02:00
|
|
|
|
2017-11-30 11:35:33 +01:00
|
|
|
#include "../lv_core/lv_obj.h"
|
2016-08-08 16:25:41 +02:00
|
|
|
#include "lv_line.h"
|
|
|
|
|
|
|
|
/*********************
|
|
|
|
* DEFINES
|
|
|
|
*********************/
|
2019-06-21 15:26:28 +02:00
|
|
|
|
|
|
|
/**Default value of points. Can be used to not draw a point*/
|
2019-04-04 07:15:40 +02:00
|
|
|
#define LV_CHART_POINT_DEF (LV_COORD_MIN)
|
2016-08-08 16:25:41 +02:00
|
|
|
|
2019-06-19 13:43:02 +02:00
|
|
|
/**Automatically calculate the tick length*/
|
|
|
|
#define LV_CHART_TICK_LENGTH_AUTO 255
|
|
|
|
|
2019-10-03 23:20:50 +03:00
|
|
|
LV_EXPORT_CONST_INT(LV_CHART_POINT_DEF);
|
|
|
|
LV_EXPORT_CONST_INT(LV_CHART_TICK_LENGTH_AUTO);
|
|
|
|
|
2016-08-08 16:25:41 +02:00
|
|
|
/**********************
|
|
|
|
* TYPEDEFS
|
|
|
|
**********************/
|
2019-03-17 05:23:43 +01:00
|
|
|
|
2019-06-27 18:07:26 -04:00
|
|
|
/** Chart types*/
|
2019-04-04 07:15:40 +02:00
|
|
|
enum {
|
2020-01-14 22:53:27 +01:00
|
|
|
LV_CHART_TYPE_NONE = 0x00, /**< Don't draw the series*/
|
|
|
|
LV_CHART_TYPE_LINE = 0x01, /**< Connect the points with lines*/
|
|
|
|
LV_CHART_TYPE_COLUMN = 0x02, /**< Draw columns*/
|
2019-03-17 05:23:43 +01:00
|
|
|
};
|
|
|
|
typedef uint8_t lv_chart_type_t;
|
|
|
|
|
2019-06-27 18:07:26 -04:00
|
|
|
/** Chart update mode for `lv_chart_set_next`*/
|
2019-06-06 06:05:40 +02:00
|
|
|
enum {
|
2019-06-27 18:07:26 -04:00
|
|
|
LV_CHART_UPDATE_MODE_SHIFT, /**< Shift old data to the left and add the new one o the right*/
|
|
|
|
LV_CHART_UPDATE_MODE_CIRCULAR, /**< Add the new data in a circular way*/
|
2019-03-17 16:23:08 +03:30
|
|
|
};
|
|
|
|
typedef uint8_t lv_chart_update_mode_t;
|
2019-06-06 06:05:40 +02:00
|
|
|
|
2020-02-26 19:48:27 +01:00
|
|
|
typedef struct {
|
2017-11-23 21:28:36 +01:00
|
|
|
lv_coord_t * points;
|
|
|
|
lv_color_t color;
|
2018-11-29 22:03:56 +01:00
|
|
|
uint16_t start_point;
|
2018-06-19 09:49:58 +02:00
|
|
|
} lv_chart_series_t;
|
2017-04-13 10:20:35 +02:00
|
|
|
|
2019-06-27 18:07:26 -04:00
|
|
|
/** Data of axis */
|
2019-04-04 07:15:40 +02:00
|
|
|
enum {
|
2019-09-18 15:44:57 +03:00
|
|
|
LV_CHART_AXIS_SKIP_LAST_TICK = 0x00, /**< don't draw the last tick */
|
|
|
|
LV_CHART_AXIS_DRAW_LAST_TICK = 0x01, /**< draw the last tick */
|
|
|
|
LV_CHART_AXIS_INVERSE_LABELS_ORDER = 0x02 /**< draw tick labels in an inversed order*/
|
2019-03-22 17:24:40 +02:00
|
|
|
};
|
|
|
|
typedef uint8_t lv_chart_axis_options_t;
|
|
|
|
|
2020-02-26 19:48:27 +01:00
|
|
|
typedef struct {
|
2019-04-04 07:15:40 +02:00
|
|
|
const char * list_of_values;
|
|
|
|
lv_chart_axis_options_t options;
|
2019-06-19 13:43:02 +02:00
|
|
|
uint8_t num_tick_marks;
|
2019-04-04 07:15:40 +02:00
|
|
|
uint8_t major_tick_len;
|
|
|
|
uint8_t minor_tick_len;
|
2019-03-22 17:24:40 +02:00
|
|
|
} lv_chart_axis_cfg_t;
|
|
|
|
|
2017-04-10 11:33:38 +02:00
|
|
|
/*Data of chart */
|
2020-02-26 19:48:27 +01:00
|
|
|
typedef struct {
|
2017-04-13 15:57:02 +02:00
|
|
|
/*No inherited ext*/ /*Ext. of ancestor*/
|
2017-01-14 23:54:16 +01:00
|
|
|
/*New data for this type */
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_ll_t series_ll; /*Linked list for the data line pointers (stores lv_chart_dl_t)*/
|
|
|
|
lv_coord_t ymin; /*y min value (used to scale the data)*/
|
|
|
|
lv_coord_t ymax; /*y max value (used to scale the data)*/
|
|
|
|
uint8_t hdiv_cnt; /*Number of horizontal division lines*/
|
|
|
|
uint8_t vdiv_cnt; /*Number of vertical division lines*/
|
|
|
|
uint16_t point_cnt; /*Point number in a data line*/
|
2020-01-16 14:26:36 +01:00
|
|
|
lv_style_list_t style_series_bg;
|
|
|
|
lv_style_list_t style_series;
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_chart_type_t type; /*Line, column or point chart (from 'lv_chart_type_t')*/
|
2019-03-22 17:24:40 +02:00
|
|
|
lv_chart_axis_cfg_t y_axis;
|
|
|
|
lv_chart_axis_cfg_t x_axis;
|
2019-09-18 15:44:57 +03:00
|
|
|
lv_chart_axis_cfg_t secondary_y_axis;
|
2019-06-06 06:05:40 +02:00
|
|
|
uint8_t update_mode : 1;
|
2018-06-19 09:49:58 +02:00
|
|
|
} lv_chart_ext_t;
|
2016-08-08 16:25:41 +02:00
|
|
|
|
2020-01-14 22:53:27 +01:00
|
|
|
/*Parts of the chart*/
|
2019-06-11 06:33:33 +02:00
|
|
|
enum {
|
2020-01-14 22:53:27 +01:00
|
|
|
LV_CHART_PART_BG = LV_OBJ_PART_MAIN,
|
|
|
|
LV_CHART_PART_SERIES_BG = _LV_OBJ_PART_VIRTUAL_LAST,
|
|
|
|
LV_CHART_PART_SERIES
|
2019-06-11 06:33:33 +02:00
|
|
|
};
|
|
|
|
|
2016-08-08 16:25:41 +02:00
|
|
|
/**********************
|
|
|
|
* GLOBAL PROTOTYPES
|
|
|
|
**********************/
|
2017-01-13 23:27:49 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a chart background objects
|
|
|
|
* @param par pointer to an object, it will be the parent of the new chart background
|
2019-04-04 07:15:40 +02:00
|
|
|
* @param copy pointer to a chart background object, if not NULL then the new object will be copied
|
|
|
|
* from it
|
2017-01-13 23:27:49 +01:00
|
|
|
* @return pointer to the created chart background
|
|
|
|
*/
|
2018-07-30 06:52:29 +02:00
|
|
|
lv_obj_t * lv_chart_create(lv_obj_t * par, const lv_obj_t * copy);
|
2017-01-13 23:27:49 +01:00
|
|
|
|
2017-11-15 15:50:33 +01:00
|
|
|
/*======================
|
|
|
|
* Add/remove functions
|
|
|
|
*=====================*/
|
2016-08-08 16:25:41 +02:00
|
|
|
|
2017-01-13 23:27:49 +01:00
|
|
|
/**
|
2017-11-15 15:50:33 +01:00
|
|
|
* Allocate and add a data series to the chart
|
2017-01-13 23:27:49 +01:00
|
|
|
* @param chart pointer to a chart object
|
2017-11-15 15:50:33 +01:00
|
|
|
* @param color color of the data series
|
|
|
|
* @return pointer to the allocated data series
|
2017-01-13 23:27:49 +01:00
|
|
|
*/
|
2017-11-23 21:28:36 +01:00
|
|
|
lv_chart_series_t * lv_chart_add_series(lv_obj_t * chart, lv_color_t color);
|
2016-08-08 16:25:41 +02:00
|
|
|
|
2018-10-30 17:26:26 +01:00
|
|
|
/**
|
|
|
|
* Clear the point of a serie
|
|
|
|
* @param chart pointer to a chart object
|
|
|
|
* @param serie pointer to the chart's serie to clear
|
|
|
|
*/
|
|
|
|
void lv_chart_clear_serie(lv_obj_t * chart, lv_chart_series_t * serie);
|
|
|
|
|
2017-11-15 15:50:33 +01:00
|
|
|
/*=====================
|
|
|
|
* Setter functions
|
|
|
|
*====================*/
|
2016-08-08 16:25:41 +02:00
|
|
|
|
2017-01-13 23:27:49 +01:00
|
|
|
/**
|
|
|
|
* Set the number of horizontal and vertical division lines
|
|
|
|
* @param chart pointer to a graph background object
|
|
|
|
* @param hdiv number of horizontal division lines
|
|
|
|
* @param vdiv number of vertical division lines
|
|
|
|
*/
|
2017-10-26 21:20:10 +02:00
|
|
|
void lv_chart_set_div_line_count(lv_obj_t * chart, uint8_t hdiv, uint8_t vdiv);
|
2017-01-13 23:27:49 +01:00
|
|
|
|
|
|
|
/**
|
2017-11-15 15:50:33 +01:00
|
|
|
* Set the minimal and maximal y values
|
2017-01-13 23:27:49 +01:00
|
|
|
* @param chart pointer to a graph background object
|
|
|
|
* @param ymin y minimum value
|
|
|
|
* @param ymax y maximum value
|
|
|
|
*/
|
2017-11-23 21:28:36 +01:00
|
|
|
void lv_chart_set_range(lv_obj_t * chart, lv_coord_t ymin, lv_coord_t ymax);
|
2017-01-13 23:27:49 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a new type for a chart
|
|
|
|
* @param chart pointer to a chart object
|
|
|
|
* @param type new type of the chart (from 'lv_chart_type_t' enum)
|
|
|
|
*/
|
|
|
|
void lv_chart_set_type(lv_obj_t * chart, lv_chart_type_t type);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the number of points on a data line on a chart
|
|
|
|
* @param chart pointer r to chart object
|
2017-11-15 15:50:33 +01:00
|
|
|
* @param point_cnt new number of points on the data lines
|
2017-01-13 23:27:49 +01:00
|
|
|
*/
|
2017-11-15 15:50:33 +01:00
|
|
|
void lv_chart_set_point_count(lv_obj_t * chart, uint16_t point_cnt);
|
2017-01-13 23:27:49 +01:00
|
|
|
|
2017-12-20 16:51:34 +01:00
|
|
|
/**
|
|
|
|
* Initialize all data points with a value
|
|
|
|
* @param chart pointer to chart object
|
|
|
|
* @param ser pointer to a data series on 'chart'
|
|
|
|
* @param y the new value for all points
|
|
|
|
*/
|
|
|
|
void lv_chart_init_points(lv_obj_t * chart, lv_chart_series_t * ser, lv_coord_t y);
|
|
|
|
|
|
|
|
/**
|
2019-04-10 06:22:45 +02:00
|
|
|
* Set the value of points from an array
|
2017-12-20 16:51:34 +01:00
|
|
|
* @param chart pointer to chart object
|
|
|
|
* @param ser pointer to a data series on 'chart'
|
|
|
|
* @param y_array array of 'lv_coord_t' points (with 'points count' elements )
|
|
|
|
*/
|
2019-05-25 16:43:57 +03:00
|
|
|
void lv_chart_set_points(lv_obj_t * chart, lv_chart_series_t * ser, lv_coord_t y_array[]);
|
2017-12-20 16:51:34 +01:00
|
|
|
|
2017-01-13 23:27:49 +01:00
|
|
|
/**
|
|
|
|
* Shift all data right and set the most right data on a data line
|
|
|
|
* @param chart pointer to chart object
|
2017-11-15 15:50:33 +01:00
|
|
|
* @param ser pointer to a data series on 'chart'
|
2017-01-13 23:27:49 +01:00
|
|
|
* @param y the new value of the most right data
|
|
|
|
*/
|
2017-11-23 21:28:36 +01:00
|
|
|
void lv_chart_set_next(lv_obj_t * chart, lv_chart_series_t * ser, lv_coord_t y);
|
2017-11-15 15:50:33 +01:00
|
|
|
|
2019-04-06 16:30:01 +04:30
|
|
|
/**
|
|
|
|
* Set update mode of the chart object.
|
|
|
|
* @param chart pointer to a chart object
|
|
|
|
* @param update mode
|
|
|
|
*/
|
|
|
|
void lv_chart_set_update_mode(lv_obj_t * chart, lv_chart_update_mode_t update_mode);
|
2019-06-06 06:05:40 +02:00
|
|
|
|
2019-03-22 17:24:40 +02:00
|
|
|
/**
|
2019-06-19 13:43:02 +02:00
|
|
|
* Set the length of the tick marks on the x axis
|
|
|
|
* @param chart pointer to the chart
|
|
|
|
* @param major_tick_len the length of the major tick or `LV_CHART_TICK_LENGTH_AUTO` to set automatically
|
|
|
|
* (where labels are added)
|
|
|
|
* @param minor_tick_len the length of the minor tick, `LV_CHART_TICK_LENGTH_AUTO` to set automatically
|
|
|
|
* (where no labels are added)
|
2019-03-22 17:24:40 +02:00
|
|
|
*/
|
2019-06-19 13:43:02 +02:00
|
|
|
void lv_chart_set_x_tick_length(lv_obj_t * chart, uint8_t major_tick_len, uint8_t minor_tick_len);
|
2019-03-22 17:24:40 +02:00
|
|
|
|
|
|
|
/**
|
2019-06-19 13:43:02 +02:00
|
|
|
* Set the length of the tick marks on the y axis
|
|
|
|
* @param chart pointer to the chart
|
|
|
|
* @param major_tick_len the length of the major tick or `LV_CHART_TICK_LENGTH_AUTO` to set automatically
|
|
|
|
* (where labels are added)
|
|
|
|
* @param minor_tick_len the length of the minor tick, `LV_CHART_TICK_LENGTH_AUTO` to set automatically
|
|
|
|
* (where no labels are added)
|
2019-03-22 17:24:40 +02:00
|
|
|
*/
|
2019-06-19 13:43:02 +02:00
|
|
|
void lv_chart_set_y_tick_length(lv_obj_t * chart, uint8_t major_tick_len, uint8_t minor_tick_len);
|
2019-04-04 07:15:40 +02:00
|
|
|
|
2019-09-18 15:44:57 +03:00
|
|
|
/**
|
|
|
|
* Set the length of the tick marks on the secondary y axis
|
|
|
|
* @param chart pointer to the chart
|
|
|
|
* @param major_tick_len the length of the major tick or `LV_CHART_TICK_LENGTH_AUTO` to set automatically
|
|
|
|
* (where labels are added)
|
|
|
|
* @param minor_tick_len the length of the minor tick, `LV_CHART_TICK_LENGTH_AUTO` to set automatically
|
|
|
|
* (where no labels are added)
|
|
|
|
*/
|
|
|
|
void lv_chart_set_secondary_y_tick_length(lv_obj_t * chart, uint8_t major_tick_len, uint8_t minor_tick_len);
|
|
|
|
|
2019-06-17 16:05:30 +02:00
|
|
|
/**
|
2019-06-19 13:43:02 +02:00
|
|
|
* Set the x-axis tick count and labels of a chart
|
2019-06-17 16:05:30 +02:00
|
|
|
* @param chart pointer to a chart object
|
|
|
|
* @param list_of_values list of string values, terminated with \n, except the last
|
|
|
|
* @param num_tick_marks if list_of_values is NULL: total number of ticks per axis
|
2019-06-19 13:43:02 +02:00
|
|
|
* else number of ticks between two value labels
|
2019-06-17 16:05:30 +02:00
|
|
|
* @param options extra options
|
|
|
|
*/
|
2019-06-27 07:16:15 +02:00
|
|
|
void lv_chart_set_x_tick_texts(lv_obj_t * chart, const char * list_of_values, uint8_t num_tick_marks,
|
|
|
|
lv_chart_axis_options_t options);
|
2019-06-19 13:43:02 +02:00
|
|
|
|
2019-09-18 15:44:57 +03:00
|
|
|
/**
|
|
|
|
* Set the secondary y-axis tick count and labels of a chart
|
|
|
|
* @param chart pointer to a chart object
|
|
|
|
* @param list_of_values list of string values, terminated with \n, except the last
|
|
|
|
* @param num_tick_marks if list_of_values is NULL: total number of ticks per axis
|
|
|
|
* else number of ticks between two value labels
|
|
|
|
* @param options extra options
|
|
|
|
*/
|
|
|
|
void lv_chart_set_secondary_y_tick_texts(lv_obj_t * chart, const char * list_of_values, uint8_t num_tick_marks,
|
2020-02-26 19:48:27 +01:00
|
|
|
lv_chart_axis_options_t options);
|
2019-09-18 15:44:57 +03:00
|
|
|
|
2019-06-19 13:43:02 +02:00
|
|
|
/**
|
|
|
|
* Set the y-axis tick count and labels of a chart
|
|
|
|
* @param chart pointer to a chart object
|
|
|
|
* @param list_of_values list of string values, terminated with \n, except the last
|
|
|
|
* @param num_tick_marks if list_of_values is NULL: total number of ticks per axis
|
|
|
|
* else number of ticks between two value labels
|
|
|
|
* @param options extra options
|
|
|
|
*/
|
2019-06-27 07:16:15 +02:00
|
|
|
void lv_chart_set_y_tick_texts(lv_obj_t * chart, const char * list_of_values, uint8_t num_tick_marks,
|
|
|
|
lv_chart_axis_options_t options);
|
2019-06-19 13:43:02 +02:00
|
|
|
|
2017-11-15 15:50:33 +01:00
|
|
|
/*=====================
|
|
|
|
* Getter functions
|
|
|
|
*====================*/
|
2016-08-08 16:25:41 +02:00
|
|
|
|
2017-01-13 23:27:49 +01:00
|
|
|
/**
|
|
|
|
* Get the type of a chart
|
|
|
|
* @param chart pointer to chart object
|
|
|
|
* @return type of the chart (from 'lv_chart_t' enum)
|
|
|
|
*/
|
2018-07-30 06:52:29 +02:00
|
|
|
lv_chart_type_t lv_chart_get_type(const lv_obj_t * chart);
|
2017-01-13 23:27:49 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the data point number per data line on chart
|
|
|
|
* @param chart pointer to chart object
|
|
|
|
* @return point number on each data line
|
|
|
|
*/
|
2019-11-01 11:09:56 +01:00
|
|
|
uint16_t lv_chart_get_point_count(const lv_obj_t * chart);
|
2016-08-11 15:00:46 +02:00
|
|
|
|
2017-11-15 15:50:33 +01:00
|
|
|
/*=====================
|
|
|
|
* Other functions
|
|
|
|
*====================*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Refresh a chart if its data line has changed
|
|
|
|
* @param chart pointer to chart object
|
|
|
|
*/
|
|
|
|
void lv_chart_refresh(lv_obj_t * chart);
|
2017-04-21 09:15:39 +02:00
|
|
|
|
2016-08-08 16:25:41 +02:00
|
|
|
/**********************
|
|
|
|
* MACROS
|
|
|
|
**********************/
|
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
#endif /*LV_USE_CHART*/
|
2016-08-08 16:25:41 +02:00
|
|
|
|
2017-07-09 15:32:49 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
} /* extern "C" */
|
2016-08-08 16:25:41 +02:00
|
|
|
#endif
|
2017-07-09 15:32:49 +02:00
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
#endif /*LV_CHART_H*/
|