1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-28 07:03:00 +08:00

lv_chart: Fix division by zero issue when all points are equal (#1962)

* Fix division by zero issue when all points are equal

As the title says, when all the points are equal, it attempts division by zero, and in some cases it can result in funny behavior.
Slightly kludgy fix, but not a significant performance impact.

* Actually fix the division by zero issue both ways

Previous commit was slightly broken and only worked one way

* Fix range setting instead of drawing

* Missing y_tmp
This commit is contained in:
Andrey 2020-12-22 12:44:17 +03:00 committed by GitHub
parent 091174069d
commit 07b6d93de4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -333,7 +333,7 @@ void lv_chart_set_y_range(lv_obj_t * chart, lv_chart_axis_t axis, lv_coord_t ymi
if(ext->ymin[axis] == ymin && ext->ymax[axis] == ymax) return;
ext->ymin[axis] = ymin;
ext->ymax[axis] = ymax;
ext->ymax[axis] = (ymax == ymin ? ymax + 1 : ymax);
lv_chart_refresh(chart);
}
@ -1194,7 +1194,7 @@ static void draw_series_line(lv_obj_t * chart, const lv_area_t * series_area, co
lv_coord_t p_act = start_point;
lv_coord_t p_prev = start_point;
int32_t y_tmp = (int32_t)((int32_t)ser->points[p_prev] - ext->ymin[ser->y_axis]) * h;
y_tmp = y_tmp / (ext->ymax[ser->y_axis] - ext->ymin[ser->y_axis]);
y_tmp = y_tmp / (ext->ymax[ser->y_axis] - ext->ymin[ser->y_axis]);
p2.y = h - y_tmp + y_ofs;
for(i = 0; i < ext->point_cnt; i++) {