From c71047f35975b293362320406c6104b8edcf2b73 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Tue, 12 Feb 2019 06:03:06 +0100 Subject: [PATCH] lv_chart: LV_CHART_VETICAL_LINES fixes --- lv_objx/lv_chart.c | 55 ++++++++++++++++++---------------------------- lv_objx/lv_chart.h | 8 +++---- 2 files changed, 25 insertions(+), 38 deletions(-) diff --git a/lv_objx/lv_chart.c b/lv_objx/lv_chart.c index 1dedaa7a4..3bd6f5304 100644 --- a/lv_objx/lv_chart.c +++ b/lv_objx/lv_chart.c @@ -764,12 +764,18 @@ 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) { + lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart); + lv_coord_t w = lv_obj_get_width(chart); + /*Vertical lines works only if the width == point count. Else use the normal line type*/ + if(ext->point_cnt != w) { + lv_chart_draw_lines(chart, mask); + return; + } 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; @@ -789,47 +795,28 @@ static void lv_chart_draw_vertical_lines(lv_obj_t * chart, const lv_area_t * mas 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); - p1.y = LV_COORD_MIN; p2.y = h - y_tmp + y_ofs; + p1.y = p2.y; - if(ext->point_cnt == w) + for(i = 0; i < ext->point_cnt; i++) { - 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++; + } - 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++; - } - + if(ser->points[i] != LV_CHART_POINT_DEF) { 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); - } - } + p2.x = ((w * i) / (ext->point_cnt - 1)) + x_ofs; + p1.x = p2.x; + p1.y = p2.y; } } } diff --git a/lv_objx/lv_chart.h b/lv_objx/lv_chart.h index 08d4c4eea..baea9d0f4 100644 --- a/lv_objx/lv_chart.h +++ b/lv_objx/lv_chart.h @@ -62,10 +62,10 @@ typedef struct /*Chart types*/ enum { - LV_CHART_TYPE_LINE = 0x01, - LV_CHART_TYPE_COLUMN = 0x02, - LV_CHART_TYPE_POINT = 0x04, - LV_CHART_TYPE_VERTICAL_LINE = 0x08, + LV_CHART_TYPE_LINE = 0x01, /*Connect the points with lines*/ + LV_CHART_TYPE_COLUMN = 0x02, /*Draw columns*/ + LV_CHART_TYPE_POINT = 0x04, /*Draw circles on the points*/ + LV_CHART_TYPE_VERTICAL_LINE = 0x08, /*Draw vertical lines on points (useful when chart width == point count)*/ }; typedef uint8_t lv_chart_type_t;