From d855ba8830551ba9f8d1ee9cff14637598e9d638 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Fri, 17 Mar 2023 10:56:45 +0100 Subject: [PATCH] fix(chart): fix rounding error in lv_chart_get_point_pos_by_id fixes #4064 --- src/widgets/chart/lv_chart.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/widgets/chart/lv_chart.c b/src/widgets/chart/lv_chart.c index 55b7932a2..f556c8edb 100644 --- a/src/widgets/chart/lv_chart.c +++ b/src/widgets/chart/lv_chart.c @@ -299,17 +299,17 @@ void lv_chart_get_point_pos_by_id(lv_obj_t * obj, lv_chart_series_t * ser, uint1 int32_t block_gap = ((int32_t)lv_obj_get_style_pad_column(obj, LV_PART_MAIN) * chart->zoom_x) >> 8; /*Gap between the column on ~adjacent X*/ lv_coord_t block_w = (w - ((chart->point_cnt - 1) * block_gap)) / chart->point_cnt; - lv_coord_t col_w = block_w / ser_cnt; - - p_out->x = (int32_t)((int32_t)w * id) / chart->point_cnt; + lv_coord_t col_w = (block_w - (ser_cnt - 1) * ser_gap) / ser_cnt; + // p_out->x = (int32_t)((int32_t)w * id) / chart->point_cnt; + p_out->x = (int32_t)((int32_t)(w - block_w) * id) / (chart->point_cnt - 1); lv_chart_series_t * ser_i = NULL; _LV_LL_READ_BACK(&chart->series_ll, ser_i) { if(ser_i == ser) break; - p_out->x += col_w; + p_out->x += col_w + ser_gap; } - p_out->x += (col_w - ser_gap) / 2; + p_out->x += col_w / 2; } else { p_out->x = 0;