microsoft/automatic-graph-layout

flipped coordinates in new wpf application

Closed this issue · 4 comments

Hallo.

I am trying to use the "Editing" example to start a new WPF project. I copied only the code from the form to a new WPF app. At the end I use this method to just calculate the node positions: LayoutHelpers.CalculateLayout(g.GeometryGraph, g.LayoutAlgorithmSettings, null);

Then I compared my result with the one in the "Editing" example. For some reason I get the node and edge positions in my app mirrored or flipped vertically. I have sought for days now without any luck. Does someone have an idea why I get the nodes mirrored?

Afterwards I decided to do the same thing but using the code from the "WpfApplicationSample". I started a new new WPF project with a standard window in it. I named the standard grid in the mainwindow to match the grid name in the "WpfApplicationSample". But again the same happens, everything is mirror/flipped. Can someone point me in the right direction? I am trying to find out but until now without any luck.

Because it happens in both the Editing and WpfApplicationSample samples I guess there must be something wrong in the msagl.dll itself.

Regards

Just flip the geometry graph coordinates with the following two lines:
var matrix = new PlaneTransformation(1, 0, 0, 0, -1, 0);
g.GeometryGraph.Transform(matrix);

The viewers in msagl usually apply this transformation in the end.

Thanks for your reply! Nice that you are still answering questions for this amazing project.
I did what you said but it did not help. I also tried that a few days ago without any luck.

I created a repro and placed it in a google drive, if you are interested you can see the odd behaiviour for yourself.
In the repro I use LayerDirection.TB. However if I use LayerDirection.LR than nothing is displayed because the coordinates are negative.

https://drive.google.com/drive/folders/1VnYUm1Goeh0n2bQ_eHLhqYIuLKkX-fJZ?usp=sharing

This is not an odd behavior. When you call LayoutHelpers.CalculateLayout(g.GeometryGraph, g.LayoutAlgorithmSettings, null); msagl has no idea where to position the graph. So it puts the graph into an arbitrary rectangle.You need to fit this rectangle box into your client window's rectangle. You can do it by applying PlaneTransformortion to the graph, or by using WPF graphics transformations.

Thanks a lot that solved the issue. What also helps is redrawing everything. I guess that in the second redraw the msagl knows where to place the graph. (a second redraw is not a good solution of course)

Additionaly I will try to add an option to hide the dropdown button in the subgraps. If it works I will add a pull request.

Once again thanks a lot. This is a greate project!!!!