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

plotter: Adjust min and max plot heights to be a factor of the min and max values #1612

Merged

Conversation

rafaellehmkuhl
Copy link
Member

@rafaellehmkuhl rafaellehmkuhl commented Jan 24, 2025

This prevents cases where the value is constant and no line appears in the plot, since the current and only value is equal to min and max, like when monitoring an stable video frame rate.

Copy link
Contributor

@ES-Alexander ES-Alexander left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does make it so constant values get displayed instead of hidden, but there's something wrong with the update range - it's possible to get several consecutive values outside the widget (maybe related to #1561, if the canvasHeight is incorrect or something?), and when there are small changes they're confined to the middle of the widget instead of expanding to fill it:

Screen.Recording.2025-01-27.at.12.09.42.am.mov

Also, the issue you linked to seems to be about video connection logs - I'm not sure this PR fixes that?

@rafaellehmkuhl
Copy link
Member Author

@ES-Alexander everything is inside the canvas now.

Copy link
Contributor

@ES-Alexander ES-Alexander left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I knew it was squashing small fluctuations, but it took me a while to figure out why, and suggest an alternative/fix.

Comment on lines 283 to 286
maxValue = Math.max(...valuesHistory)
const maxY = maxValue > 0 ? maxValue * 1.05 : maxValue * 0.95
minValue = Math.min(...valuesHistory)
const minY = minValue > 0 ? minValue * 0.95 : minValue * 1.05
Copy link
Contributor

@ES-Alexander ES-Alexander Jan 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
maxValue = Math.max(...valuesHistory)
const maxY = maxValue > 0 ? maxValue * 1.05 : maxValue * 0.95
minValue = Math.min(...valuesHistory)
const minY = minValue > 0 ? minValue * 0.95 : minValue * 1.05
maxValue = Math.max(...valuesHistory)
minValue = Math.min(...valuesHistory)
// Add a buffer to keep the plot neatly within bounds, and centered when there are no changes
const buffer = 0.05 * (maxValue != minValue ? maxValue - minValue : 1)
const maxY = maxValue + buffer
const minY = minValue - buffer

I figured out why it was squashing small fluctuations! If the buffer is a fixed proportion of the values then if the values are changing by less than that proportion (e.g. due to a relatively large offset) then they end up getting compressed in the plot.

This alternative approach keeps a 5% buffer of the range for normal use-cases, and then treats a flatline of all the same values (i.e. range == 0) as a special case that keeps the line centered.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before:
image

After:
image

@rafaellehmkuhl
Copy link
Member Author

rafaellehmkuhl commented Jan 28, 2025

I knew it was squashing small fluctuations, but it took me a while to figure out why, and suggest an alternative/fix.

Maaaaaan I'm testing with a sine wave here and you're absolutely right! Wtaf! Nice catch!

…d max values

This prevents cases where the value is constant and no line appears in the plot, since the current and only value is equal to min and max.

Co-authored-by: ES-Alexander <[email protected]>
Copy link
Contributor

@ES-Alexander ES-Alexander left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to work well - nice! :D

@rafaellehmkuhl
Copy link
Member Author

Seems to work well - nice! :D

Nice! Made sure to put you as co-author in this one! Thanks for the solution on the centering problem!

@rafaellehmkuhl rafaellehmkuhl merged commit cfb0176 into bluerobotics:master Jan 28, 2025
11 checks passed
@rafaellehmkuhl rafaellehmkuhl deleted the adjust-plotter-min-max branch January 28, 2025 21:22
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.

2 participants