microsoft / automatic-graph-layout

A set of tools for graph layout and viewing
Other
1.35k stars 302 forks source link

Why having space when inserting edge #319

Open quanap5 opened 2 years ago

quanap5 commented 2 years ago

Hi everyone, I am in a product that needs visualization from the MsAgl library. I used sample source code as reference and in the Editing, there is a strange thing like the below image. When I insert an edge using editor, there is a space between the node and added edge. This space just disappears when I use auto-layout function on the editor. I expect the added edge always be connected to the node without space (gap). Could you help me with this issue? How to modify code or which part of code is related to this issue. Thank you very much.

askMsAgl

MVoloshin commented 2 years ago

The issue seems to be introduced by some of the latest commits

quanap5 commented 2 years ago

Maybe, I have a solution for this issue. I set attributes for the edge. For example:

this.gViewer.LayoutEditor.EdgeAttr.ArrowheadAtSource = ArrowStyle.None;
this.gViewer.LayoutEditor.EdgeAttr.ArrowheadAtTarget = ArrowStyle.Normal;

solveMsAgl

MVoloshin commented 2 years ago

Is it necessary to set them each time when I add a new edge? I've tried setting both to ArrowStyle:None, but I sporadically get blank spaces anyway(

quanap5 commented 2 years ago

Is it necessary to set them each time when I add a new edge? I've tried setting both to ArrowStyle:None, but I sporadically get blank spaces anyway(

I just set one time for LayoutEditor. I have tested with the latest version.

sample2

quanap5 commented 2 years ago

Is it necessary to set them each time when I add a new edge? I've tried setting both to ArrowStyle:None, but I sporadically get blank spaces anyway(

For the case of both ArrowStyle: None. My product still works well. For example; sample1

MVoloshin commented 2 years ago

First 5 or 6 added edges are rendered correctly but then I start getting spaces again( Could you share some sources, please? P.S. I also have to somehow handle edges that are added via "Edge Insertion" inside the graph

levnach commented 2 years ago

I think I fixed it with https://github.com/microsoft/automatic-graph-layout/commit/da3b5a3cafa10d9271bff1e90a68c913ab084312. The problem was the different treatment of the source and the target of the edge. By default, msagl draws the arrowhead at the target but does not draw the arrowhead at the source. This behavior was causing the bug and I think it is going to work now. I changed the default values for EdgeAttr.arrowheadAtSource = ArrawStyle.None, and EdgeAttr.arrowheadAtTarget = ArrawStyle.Default. The rest of the code should treat arrowheads independently of which end it is.

MVoloshin commented 2 years ago

@levnach, problem still not solved. Huge arrows still start appearing after adding a few edges.

System::Void Form1::Form1_Load(System::Object^ sender, System::EventArgs^ e) {
        gviewer1->Graph = gcnew Microsoft::Msagl::Drawing::Graph();
        gviewer1->LayoutEditor->EdgeAttr->ArrowheadAtSource = ArrowStyle::None;
        gviewer1->LayoutEditor->EdgeAttr->ArrowheadAtTarget = ArrowStyle::None;
    }

System::Void Form1::gviewer1_EdgeAdded(System::Object^ sender, System::EventArgs^ e) {
    Edge^ edge = dynamic_cast<Edge^>(sender);    
    Microsoft::Msagl::Routing::StraightLineEdges::CreateSimpleEdgeCurveWithUnderlyingPolyline(edge->GeometryEdge);
}
levnach commented 2 years ago

@MVoloshin , please see that https://github.com/microsoft/automatic-graph-layout/commit/796ccb711093e0dd864dd285d756ab13fcb6d258 fixes it.