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

widget: plotter: improve NaN handling #1716

Open
ES-Alexander opened this issue Feb 25, 2025 · 0 comments
Open

widget: plotter: improve NaN handling #1716

ES-Alexander opened this issue Feb 25, 2025 · 0 comments
Labels
widget-specific A widget-specific issue

Comments

@ES-Alexander
Copy link
Contributor

ES-Alexander commented Feb 25, 2025

From this PR review comment:

We could maybe generalise this by making it so any valid value followed by nothing is a filled circle, and any valid value directly followed by NaN is an empty circle, which would then help to display things like a rangefinder losing its target lock or something. That way we could just start plotters with NaN, and if they have a last recorded value then they can start with that followed by NaN (which then also makes it clear where the real values start once they begin).

i.e. the value buffer would start with either a single NaN, or the last session endpoint followed by a NaN, and then get new values added to it as they arrive1, and the drawing process would be something like:

# plot values by index
# TODO: allow plotting values over time, or against each other
def h_transform(index):
    return index * canvas_width / len(buffer)

... # handle setting range and offset(TODO: allow user to set manually, instead of always using auto)
def v_transform(value):
    return (value + data_offset) * canvas_height / data_range

prev_value = buffer[0]
line_started = False
for index, value in enumerate(buffer):
    if value.is_nan() and not prev_value.is_nan():
        draw_circle(h_transform(index), v_transform(value), EMPTY)
        line_started = False
    elif not value.is_nan():
        if line_started:
            draw_line_to(h_transform(index), v_transform(value))
        else:
            start_line(h_transform(index), v_transform(value))
            line_started = True
    prev_value = value

if not value.is_nan():
    draw_circle(h_transform(index), v_transform(value), FILLED)
Image

Footnotes

  1. values could be transformed by an axis scaling/offset function (although this is also achievable using compound variables), and the latest min/max values could be updated using the new value, to avoid needing to process the entire buffer for every draw.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
widget-specific A widget-specific issue
Projects
None yet
Development

No branches or pull requests

1 participant