add optimized chart drawing for test

This commit is contained in:
AloyseTech
2018-11-15 00:01:05 +01:00
parent 7897500c1e
commit 5102e71e84
2 changed files with 79 additions and 1 deletions

View File

@@ -34,6 +34,7 @@ static void lv_chart_draw_div(lv_obj_t * chart, const lv_area_t * mask);
static void lv_chart_draw_lines(lv_obj_t * chart, const lv_area_t * mask); static void lv_chart_draw_lines(lv_obj_t * chart, const lv_area_t * mask);
static void lv_chart_draw_points(lv_obj_t * chart, const lv_area_t * mask); static void lv_chart_draw_points(lv_obj_t * chart, const lv_area_t * mask);
static void lv_chart_draw_cols(lv_obj_t * chart, const lv_area_t * mask); static void lv_chart_draw_cols(lv_obj_t * chart, const lv_area_t * mask);
static void lv_chart_draw_vertical_lines(lv_obj_t * chart, const lv_area_t * mask);
/********************** /**********************
* STATIC VARIABLES * STATIC VARIABLES
@@ -460,6 +461,7 @@ static bool lv_chart_design(lv_obj_t * chart, const lv_area_t * mask, lv_design_
if(ext->type & LV_CHART_TYPE_LINE) lv_chart_draw_lines(chart, mask); if(ext->type & LV_CHART_TYPE_LINE) lv_chart_draw_lines(chart, mask);
if(ext->type & LV_CHART_TYPE_COLUMN) lv_chart_draw_cols(chart, mask); if(ext->type & LV_CHART_TYPE_COLUMN) lv_chart_draw_cols(chart, mask);
if(ext->type & LV_CHART_TYPE_POINT) lv_chart_draw_points(chart, mask); if(ext->type & LV_CHART_TYPE_POINT) lv_chart_draw_points(chart, mask);
if(ext->type & LV_CHART_TYPE_VERTICAL_LINE) lv_chart_draw_vertical_lines(chart, mask);
} }
return true; return true;
} }
@@ -718,4 +720,79 @@ static void lv_chart_draw_cols(lv_obj_t * chart, const lv_area_t * mask)
} }
} }
} }
/**
* Draw the data lines as vertical lines on a chart if there is only 1px between point
* @param obj pointer to chart object
*/
static void lv_chart_draw_vertical_lines(lv_obj_t * chart, const lv_area_t * mask)
{
lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart);
uint16_t i;
lv_point_t p1;
lv_point_t p2;
lv_coord_t w = lv_obj_get_width(chart);
lv_coord_t h = lv_obj_get_height(chart);
lv_coord_t x_ofs = chart->coords.x1;
lv_coord_t y_ofs = chart->coords.y1;
int32_t y_tmp;
lv_chart_series_t * ser;
lv_opa_t opa_scale = lv_obj_get_opa_scale(chart);
lv_style_t style;
lv_style_copy(&style, &lv_style_plain);
style.line.opa = ext->series.opa;
style.line.width = ext->series.width;
/*Go through all data lines*/
LL_READ_BACK(ext->series_ll, ser) {
style.line.color = ser->color;
p1.x = 0 + x_ofs;
p2.x = 0 + x_ofs;
y_tmp = (int32_t)((int32_t) ser->points[0] - ext->ymin) * h;
y_tmp = y_tmp / (ext->ymax - ext->ymin);
p2.y = h - y_tmp + y_ofs;
if(ext->point_cnt == w)
{
for(i = 0; i < ext->point_cnt; i++)
{
y_tmp = (int32_t)((int32_t) ser->points[i] - ext->ymin) * h;
y_tmp = y_tmp / (ext->ymax - ext->ymin);
p2.y = h - y_tmp + y_ofs;
if(p1.y == p2.y)
{
p2.x++;
}
lv_draw_line(&p1, &p2, mask, &style, opa_scale);
p2.x = ((w * i) / (ext->point_cnt - 1)) + x_ofs;
p1.x = p2.x;
p1.y = p2.y;
}
}
else
{
for(i = 1; i < ext->point_cnt; i ++) {
p1.x = p2.x;
p1.y = p2.y;
p2.x = ((w * i) / (ext->point_cnt - 1)) + x_ofs;
y_tmp = (int32_t)((int32_t) ser->points[i] - ext->ymin) * h;
y_tmp = y_tmp / (ext->ymax - ext->ymin);
p2.y = h - y_tmp + y_ofs;
if(ser->points[i - 1] >= 0 && ser->points[i] >= 0)
{
lv_draw_line(&p1, &p2, mask, &style, opa_scale);
}
}
}
}
}
#endif #endif

View File

@@ -49,7 +49,7 @@ typedef struct
uint8_t hdiv_cnt; /*Number of horizontal division lines*/ uint8_t hdiv_cnt; /*Number of horizontal division lines*/
uint8_t vdiv_cnt; /*Number of vertical division lines*/ uint8_t vdiv_cnt; /*Number of vertical division lines*/
uint16_t point_cnt; /*Point number in a data line*/ uint16_t point_cnt; /*Point number in a data line*/
uint8_t type :3; /*Line, column or point chart (from 'lv_chart_type_t')*/ uint8_t type :4; /*Line, column or point chart (from 'lv_chart_type_t')*/
struct { struct {
lv_coord_t width; /*Line width or point radius*/ lv_coord_t width; /*Line width or point radius*/
uint8_t num; /*Number of data lines in dl_ll*/ uint8_t num; /*Number of data lines in dl_ll*/
@@ -64,6 +64,7 @@ enum
LV_CHART_TYPE_LINE = 0x01, LV_CHART_TYPE_LINE = 0x01,
LV_CHART_TYPE_COLUMN = 0x02, LV_CHART_TYPE_COLUMN = 0x02,
LV_CHART_TYPE_POINT = 0x04, LV_CHART_TYPE_POINT = 0x04,
LV_CHART_TYPE_VERTICAL_LINE = 0x08,
}; };
typedef uint8_t lv_chart_type_t; typedef uint8_t lv_chart_type_t;