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

Fix for the label clipping in the label layout algorithm #3273

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

rita-gwen
Copy link
Contributor

No description provided.

Copy link
Contributor

@nickshulman nickshulman left a 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")
Copy link
Contributor

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;
Copy link
Contributor

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,
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@rita-gwen
Copy link
Contributor Author

The most recent commit should fix the label clipping in small-size plots in the DIA tuturials. This is how it looks:
DIATtof tutorial
image
DIAPacef tutorial:
image

@rita-gwen rita-gwen requested a review from brendanx67 December 20, 2024 01:52
@brendanx67
Copy link
Contributor

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.

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.

3 participants