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

[2.3.5] External layout algorithms: All VertexSizes passed in are (0,0) #48

Closed
ValentinMarinov opened this issue Mar 15, 2016 · 1 comment

Comments

@ValentinMarinov
Copy link

To reproduce:

  1. Create a custom layout algorithm by inheriting from IExternalLayout<TVertex, TEdge>
  2. Make sure NeedVertexSizes returns true (otherwise VertexSizes will be null)
  3. Put a breakpoint on Compute(...) and inspect the elements in VertexSizes (all are zero-sized)

Bug cause (assumption):

public Dictionary<TVertex, Size> GetVertexSizes()
{
    //measure if needed and get all vertex sizes            
    Measure(new USize(double.PositiveInfinity, double.PositiveInfinity));
    var vertexSizes = new Dictionary<TVertex, Size>(_vertexlist.Count(a => ((IGraphXVertex)a.Value.Vertex).SkipProcessing != ProcessingOptionEnum.Exclude));
    //go through the vertex presenters and get the actual layoutpositions
    foreach (var vc in VertexList.Where(vc => ((IGraphXVertex)vc.Value.Vertex).SkipProcessing != ProcessingOptionEnum.Exclude))
    {
        vertexSizes[vc.Key] = new Size(vc.Value.ActualWidth, vc.Value.ActualHeight);
    }
    return vertexSizes;
}

Note: ActualWidth and ActualHeight (If I am right) are determined in the Arrange/Render step
and vc.Value.DesiredSize.Width and vc.Value.DesiredSize.Height should be used instead.

Workaround:

public class MyExternalAlgorithm: IExternalLayout<DataVertex, DataEdge>, ILayoutEdgeRouting<DataEdge>
{
    private MyGraph Graph { get; set; }

    private void WorkaroundForZeroVertexSizes()
    {
        var vertexControls = GraphArea.GetAllVertexControls();
        foreach (var vertexControl in vertexControls)
        {
            var vertex = vertexControl.Vertex as DataVertex;
            VertexSizes[vertex] = new GraphX.Measure.Size()
            {
                Width = vertexControl.DesiredSize.Width,
                Height = vertexControl.DesiredSize.Height
            };
        }
    }

    public void Compute(CancellationToken cancellationToken)
    {
        WorkaroundForZeroVertexSizes();
        // Now VertexSizes should be properly assigned
    }

    public IDictionary<DataVertex, GraphX.Measure.Point> VertexPositions { get; set; }
    public IDictionary<DataVertex, GraphX.Measure.Size> VertexSizes { get; set; }

    public bool NeedVertexSizes
    {
        get { return true; }
    }
    public bool SupportsObjectFreeze
    {
        get { return false; }
    }

    public MyExternalAlgorithm(MyGraph graph)
    {
        Graph = graph;
    }
}
@panthernet
Copy link
Owner

Thanks! Fixed.

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

No branches or pull requests

2 participants