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

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

Draft
wants to merge 30 commits into
base: main
Choose a base branch
from

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 67.32955% with 115 lines in your changes missing coverage. Please review.

Project coverage is 79.73%. Comparing base (384e1d7) to head (28fb2a2).

Files with missing lines Patch % Lines
src/ndv/views/_pygfx/_histogram.py 53.75% 37 Missing ⚠️
src/ndv/views/_vispy/_histogram.py 41.86% 25 Missing ⚠️
src/ndv/views/_wx/_array_view.py 86.25% 11 Missing ⚠️
src/ndv/views/_jupyter/_app.py 0.00% 8 Missing ⚠️
src/ndv/views/_jupyter/_array_view.py 75.00% 8 Missing ⚠️
src/ndv/views/_vispy/_plot_widget.py 68.00% 8 Missing ⚠️
src/ndv/views/_qt/_array_view.py 89.28% 6 Missing ⚠️
src/ndv/views/_qt/_app.py 0.00% 5 Missing ⚠️
src/ndv/views/_wx/_app.py 44.44% 5 Missing ⚠️
src/ndv/views/bases/_graphics/_mouseable.py 66.66% 1 Missing ⚠️
... and 1 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #146      +/-   ##
==========================================
- Coverage   80.68%   79.73%   -0.95%     
==========================================
  Files          44       44              
  Lines        4209     4417     +208     
==========================================
+ Hits         3396     3522     +126     
- Misses        813      895      +82     

☔ 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 force-pushed the histogram-log-slider branch from b79aaa1 to 5e983b2 Compare March 14, 2025 15:45
@gselzer gselzer force-pushed the histogram-log-slider branch from 5e983b2 to 7afd5ad Compare March 14, 2025 15:47
@gselzer gselzer force-pushed the histogram-log-slider branch from 3e66df0 to 5139aba Compare March 14, 2025 16:50
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