Skip to content

Adds a trust bar for size distribution result plots#4009

Merged
jellybean2004 merged 5 commits into
mainfrom
SD_trust_bar
Jul 17, 2026
Merged

Adds a trust bar for size distribution result plots#4009
jellybean2004 merged 5 commits into
mainfrom
SD_trust_bar

Conversation

@jellybean2004

@jellybean2004 jellybean2004 commented Jun 25, 2026

Copy link
Copy Markdown
Member

Description

Fixes #3271

This PR adds a Trust Bar to the Size Distribution perspective, inspired by IRENA-style plots. The bar visually indicates which diameter region is reliable based on the fitted Q-range, using a smooth red/yellow/green gradient.

Key changes

  • Adds a horizontal trust bar above the size distribution plot.

  • Uses two physical trust boundaries derived from the fit range as defined in SizeDistributionLogic:

    • D_low = 1.8 * pi / Qmax
    • D_high = 0.95 * pi / Qmin
  • Displays:

    • red for out-of-range / unreliable diameters
    • yellow for transition regions
    • green for the trusted region
  • A small helper class (TrustBar) handles:

    • drawing the gradient bar
    • clearing it
    • updating it when the x-axis limits change
  • The bar stays aligned when the plot is zoomed or rescaled.

How Has This Been Tested?

Manually tested functionality.

Review Checklist:

Documentation

Installers

  • There is a chance this will affect the installers, if so
    • Windows installer (GH artifact) has been tested (installed and worked)
    • MacOSX installer (GH artifact) has been tested (installed and worked)
    • Wheels installer (GH artifact) has been tested (installed and worked)

Licensing

  • The introduced changes comply with SasView license (BSD 3-Clause)

@butlerpd butlerpd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This works very smoothly whether stretching the graph or changing scales. A GREAT addition that was desired from the beginning. I do have one question I do not fully comprehend though. While the right hand red trust line matches the new trust bar transition, the left hand red line seems to be well into the trust bar's red region instead of lined up with the transition. As far as I can tell both numbers are computed from the exact same code? but maybe used differently?

Otherwise of course those two kludgy trust lines that were created as an easy stop gap in lieu of the trustbar should be removed (see comment on code). Fortunately it was not done yet or I'd have missed the fact that the two do not match. That matching needs a bit more investigation.

Once they match and the red trust lines (trust_plot) are removed this should be good to go.

Comment on lines +641 to +647
# set the trust range for the size distribution plot
self.size_distr_plot.show_trust_bar = True
trust_range = self.logic.computeTrustRange(qmin_fit, qmax_fit)
self.size_distr_plot.trust_range = {
"d_low": trust_range[0],
"d_high": trust_range[1],
}

@butlerpd butlerpd Jul 15, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This code is in the wrong place. It in fact already exists in SizeDistributionlogic, The problem is that currently returns a 2 point plot as self.trust_plot (see line 639). the code in SizeDistributionlogic.newSizeDistrPlot can be considerably simplified by getting rid of all the complicated cruft used to kludge the two lines (the trust_plot) and just return d_low and d_high directly in lieu of the trust_plot which we no longer need. This also solves the problem of having the two kludgy trust lines on top of the nice trust bar we should have had to start.

I suspect that also would allow us to get rid of the DataRole.ROLE_SIZE_DISTRIBUTION specific role and all the infrastructure that depends on it. As I recall that was done specifically to deal with the vline 2 point data? One would need to do a search to make sure it is properly extracted.

@jellybean2004

Copy link
Copy Markdown
Member Author

I found a better way to implement this, which is much simpler and works much better with the log scale.

Will change to that instead.

@jellybean2004
jellybean2004 requested a review from butlerpd July 16, 2026 14:12
@jellybean2004

Copy link
Copy Markdown
Member Author

@butlerpd I have implemented a different approach to creating the trust bar, and it now aligns properly with the lines. Could you please test this one out and let me know if all looks good? I will then remove the lines.

Also, I don't think the data role can be removed, as it is handling other things, not the lines.

@butlerpd butlerpd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The bars now line up indeed. I also tried zooming on the plot and it worked as well. I see what you mean by the old method now. That was an image I guess? which explains a bit of why it shrank a bit differently on log vs linear scale?

As for the ROLE, you may be right. I'm vaguely remembering that it if a regular plot it was wanting to overlay the original data maybe on the plot by default? In which case it needs to stay.

I also so the changes you reverted so we could check how the lines matched the bar (thanks for doing that) and they looked right to me. So if you go ahead and reinstall them this should be ready to merge.

@butlerpd

Copy link
Copy Markdown
Member

Changes checked and approved. I note that you opted to remove the calculation of the trust region from the logic.py completely and go back to your implementation in sizedistribution.py That works too.

Feel free to merge at any time. Look forward to seeing all 3 size distribution improvements together.

@jellybean2004
jellybean2004 merged commit 03d237b into main Jul 17, 2026
36 checks passed
@jellybean2004
jellybean2004 deleted the SD_trust_bar branch July 17, 2026 15:28
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.

Add an IRENA style trust level bar to the Size Distribution results plot

2 participants