Skip to content

feat: Better histogram control (plus pygfx histogram overhaul) #146

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

Merged
merged 45 commits into from
Apr 1, 2025

Conversation

gselzer
Copy link
Collaborator

@gselzer gselzer commented Mar 1, 2025

This PR adds:

  • A button to toggle the logarithmic base for the histogram. Originally, I was thinking that a slider would be nice (as I remembered @tlambert03 showing me some similar sort of functionality in Elements) but I couldn't get it to work nicely so for now the button will accomplish our goals.
  • A button to reset the histogram view, because I got tired of losing it.
  • A retained histogram frustum when setting the data. I find it frustrating when you pan/zoom to have a nice view of the data for that to be reset when you update the data.

To accomplish these features, some serious TLC was required to accomodate the new histogram features using pygfx. The way that we were calculating the margins was becoming increasingly complicated, so I developed a new strategy where the plot, x-axis, and y-axis are all rendered separately. This enables us to easily:

  • Create one scene for canvas elements that should not move in response to user input, like the x-axis.
  • Provide margins with far less computation.
    The downside here is more complication in the rendering pipeline, but I think it's better than it was.
Recording.2025-02-28.213811.mp4

These controls should be ready for opinions (cc @tlambert03, @fdrgsp), but also still need to:

  • Resolve all FIXMEs
  • Clean
  • Test

@gselzer gselzer added the enhancement New feature or request label Mar 1, 2025
@gselzer gselzer self-assigned this Mar 1, 2025
Copy link

codecov bot commented Mar 1, 2025

Codecov Report

Attention: Patch coverage is 82.40223% with 63 lines in your changes missing coverage. Please review.

Project coverage is 84.37%. Comparing base (cdc4f5d) to head (b735349).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/ndv/views/_pygfx/_histogram.py 66.66% 28 Missing ⚠️
src/ndv/views/_jupyter/_app.py 0.00% 8 Missing ⚠️
src/ndv/views/_vispy/_plot_widget.py 68.00% 8 Missing ⚠️
src/ndv/views/_qt/_app.py 0.00% 5 Missing ⚠️
src/ndv/views/_vispy/_histogram.py 89.36% 5 Missing ⚠️
src/ndv/views/_wx/_app.py 44.44% 5 Missing ⚠️
src/ndv/views/_jupyter/_array_view.py 97.14% 1 Missing ⚠️
src/ndv/views/_qt/_array_view.py 98.03% 1 Missing ⚠️
src/ndv/views/bases/_graphics/_mouseable.py 66.66% 1 Missing ⚠️
src/ndv/views/bases/_lut_view.py 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #146      +/-   ##
==========================================
+ Coverage   80.80%   84.37%   +3.57%     
==========================================
  Files          45       45              
  Lines        4271     4487     +216     
==========================================
+ Hits         3451     3786     +335     
+ Misses        820      701     -119     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tlambert03
Copy link
Member

also great stuff here. if implementing the slider was problematic, i'm fine with a button for now. I was recently playing with histograms as well, and trying to apply range limits (so that the thing doesn't scroll past, for example, 0-65,535). I think it's pretty straightforward using the 1DPanZoom camera, and updating the rect.setter so that you can never set the rect larger than the full range. (we should probably only do it for integer dtypes though)

I'll have a closer look at the changes required here soon. thanks!

Useful for histograms right now but potentially for array canvases as
well?
@gselzer
Copy link
Collaborator Author

gselzer commented Mar 5, 2025

I was recently playing with histograms as well, and trying to apply range limits (so that the thing doesn't scroll past, for example, 0-65,535).

Let me know what you think of 5bf0f1e - could use a little polish but I think it works pretty well.

gselzer added 2 commits March 12, 2025 13:11
I don't think this applies anymore
Since the goal is to not move the camera when updating data, without
this change we'll never set the camera to the right place the first
time!
@gselzer gselzer force-pushed the histogram-log-slider branch 2 times, most recently from 8621b37 to 6c79110 Compare March 12, 2025 21:42
@gselzer gselzer force-pushed the histogram-log-slider branch from 6c79110 to f9500d1 Compare March 12, 2025 21:46
Not sure how I feel about this addition to the model, but it's very
useful!
@gselzer
Copy link
Collaborator Author

gselzer commented Mar 13, 2025

Particular review going to acedb6e would be worthwhile, as it adds a new field clim_bounds to the LutModel. The problem I was trying to solve here is "how do we notify each LutView (specifically the clims sliders and the histograms) about the maximum allowed clim?", which is both needed to solve this:

I was recently playing with histograms as well, and trying to apply range limits (so that the thing doesn't scroll past, for example, 0-65,535)

as well as #152, which this PR would now close. However there may be a better place to store this state...

@gselzer gselzer mentioned this pull request Mar 20, 2025
2 tasks
...maybe this can resolve the macos segfaults?
@gselzer gselzer force-pushed the histogram-log-slider branch 4 times, most recently from 12db99a to e5ee529 Compare March 20, 2025 20:03
@gselzer gselzer force-pushed the histogram-log-slider branch from e5ee529 to 48f8c90 Compare March 20, 2025 20:08
@gselzer gselzer force-pushed the histogram-log-slider branch from 15f8cd4 to cf5f19c Compare March 21, 2025 15:00
It's not clear how to fix them...
@gselzer gselzer marked this pull request as ready for review March 21, 2025 15:45
@gselzer
Copy link
Collaborator Author

gselzer commented Mar 21, 2025

@tlambert03 I think this PR is probably ready for some eyes, in particular I'd like your feedback on:

  • The addition of LUTModel.clim_bounds
  • If you have any intuition on the pygfx histogram test qt leaks (see d142963)

Copy link
Member

@tlambert03 tlambert03 left a comment

Choose a reason for hiding this comment

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

hey @gselzer,

i took a brief look at this in the time I just had available and I like everything I see. I'm liking everything i see, and as usual: all your changes indicate a deep understanding of the system and they're all for the better. since I'm a bit busy this week, if you want to just merge this at any point, feel free to, (or specifically ask anything else). I'm happy with clim_bounds, and 5bf0f1e looks fine to me.

haven't looked too deeply at the pygfx changes. but the behavior seems good (outside of a sizing issue as shown in the screenshot below when using histogram in pygfx... i think it might need an explicit size policy?)

Screenshot 2025-03-29 at 5 45 40 PM

I'll take a look at the leaks when I have a moment (but skipping them now is also ok with me)

@gselzer gselzer merged commit 78fd390 into pyapp-kit:main Apr 1, 2025
51 checks passed
@gselzer gselzer deleted the histogram-log-slider branch April 1, 2025 23:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants