Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(chart) fixed cursor positioning with large Y rescaling without LV_USE_LARGE_COORD #2399

Merged
merged 1 commit into from Jul 23, 2021

Conversation

EnricoLusaEGF
Copy link
Contributor

Description of the feature or fix

Example of the issue (notice the chart.set_range(lv.chart.AXIS.PRIMARY_Y, -1000, 1000), and that when clicking the chart the cursor gets wrongly positioned):
https://sim.lvgl.io/v8.1/micropython/ports/javascript/index.html?script_startup=https://raw.githubusercontent.com/lvgl/lvgl/bfab70802e361ccd396c9779a000e7342793f9f3/examples/header.py&script=https://raw.githubusercontent.com/lvgl/lvgl/bfab70802e361ccd396c9779a000e7342793f9f3/examples/widgets/chart/lv_example_chart_6.py&script_direct=f5c92e36d5f5c45f8ecbe82983e2c216a5bb72d0

This is due to the overflow of
p_out->y = (int32_t)((int32_t)ser->y_points[id] - chart->ymin[ser->y_axis_sec]) * h;
when p_out->y is an int16_t (when LV_USE_LARGE_COORD is not set).
This is just a temporary calculation, so there is no need to use LV_USE_LARGE_COORD just for this. In most cases, after the division:
p_out->y = p_out->y / (chart->ymax[ser->y_axis_sec] - chart->ymin[ser->y_axis_sec])
p_out->y will again be in the [-32k,+32k] range.
Using a temporary int32_t solves this.

@kisvegabor
Copy link
Member

Looks good, thank you!

@kisvegabor kisvegabor merged commit 1b7e2b5 into lvgl:master Jul 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants