-
Notifications
You must be signed in to change notification settings - Fork 100
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
Fix for the label clipping in the label layout algorithm #3273
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me.
It definitely seems to lay out better than before.
Here are some comments which may be helpful. If they're not helpful then I would say don't worry about it and go ahead and merge to master.
@@ -158,7 +158,13 @@ private void UpdateFormatting(IEnumerable<MatchRgbHexColor> colorRows) | |||
public void OnLabelOverlapPropertyChange(object sender, PropertyChangedEventArgs e) | |||
{ | |||
if (e.PropertyName == @"GroupComparisonAvoidLabelOverlap") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably have been:
if (e.PropertyName == nameof(Settings.Default.GroupComparisonAvoidLabelOverlap))
so that "Find References" and other sorts of refactoring would work a little bit better.
GraphSummary.UpdateUI(); | ||
Settings.Default.PropertyChanged += OnLabelOverlapPropertyChange; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I have to write code which removes a listener and adds it back I usually put it inside of a try/finally:
try
{
Settings.Default.PropertyChanged -= OnLabelOverlapPropertyChange;
// do other stuff
}
finally
{
Settings.Default.PropertyChanged += OnLabelOverlapPropertyChange;
}
That way, even if some sort of exception happens, things still get back into an expected state.
For something like this, I would probably just have a field:
private bool _inPropertyChange;
and then in the property change handler:
if (_inPropertyChange)
{
return;
}
try
{
_inPropertyChange = true;
if (e.PorpertyName == nameof(Settings.Default.GroupComparisonAvoidLabelOverlap))
{
// do some stuff
}
else if (e.PropertyName == nameof(Settings.Default.GroupComparisonSuspendLabelLayout))
{
// do other stuff
}
}
finally
{
_inPropertyChange = false;
}
But the way you have this is fine too.
@@ -319,10 +326,13 @@ public bool PlaceLabel(LabeledPoint labPoint, Graphics g) | |||
var roughGoal = goal; | |||
// Search the cell neighborhood for a better position | |||
var goalPoint = _densityGrid[goalCell.Y][goalCell.X]._location; | |||
for (var count = 15; count > 0; count--) | |||
var chartRect = _graph.Chart.Rect; | |||
var allowedRect = new RectangleF(chartRect.X + labelRect.Width / 2, chartRect.Y, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure I understand why labelRect.Width / 2
gets added to the X-coordinate, but a similar sort of thing does not get added to the Y-coordinate.
This code might be correct, but I wanted to point out that it looks suspicious.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is because label coordinates are top-middle, so Y coordinate is not adjusted.
…ub.com/ProteoWizard/pwiz into Skyline/work/20241210_labelClippingFix
Better, but I guess I wonder about the label placement algorithm not finding a better place for the pictured labels. There seems to be a lot of space above the points, and even down a bit from where it is placed. Instead, the placements shown have it overlapping other points. I wonder if the algorithm is now allowing to to be best placed off screen and then simply forcing it on screen, instead of limiting it to placements where it will not get clipped during the best placement search. |
No description provided.