fix(chart): fix rounding error in lv_chart_get_point_pos_by_id

fixes #4064
This commit is contained in:
Gabor Kiss-Vamosi 2023-03-17 10:56:45 +01:00
parent 9029733b3b
commit d855ba8830

View File

@ -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;