Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Eclipse Layout Kernel » Getting the shape of edges using the ELK Java API?
Getting the shape of edges using the ELK Java API? [message #1796898] Sun, 21 October 2018 19:08 Go to next message
vlq . is currently offline vlq .Friend
Messages: 2
Registered: October 2018
Junior Member
I am trying to use the Java API to make a simple command-line tool and I can't figure out how to get the path (i.e. the bending points) of the edges. ElkEdge.getSections() seems to give me only the starting and end points. I have also tried ElkEdge.getProperty(LayeredOptions.JUNCTION_POINTS) and LEdge.getBendPoints() with an LGraph, but they both always return an empty list for me.

Below is a pretty simple test graph that I tried to replicate in Java.

algorithm: layered

node n1 {
    layout [ size: 100, 100 ]
    portConstraints: FIXED_POS
    port p1 {
        layout [ position: 100, 0 size: 10, 10 ]
    }
}
node n2 {
    layout [ size: 100, 100 ]
    portConstraints: FIXED_POS
    port p2 {
        layout [ position: 80, 100 size: 20, 20 ]
    }
}
edge n1.p1 -> n2.p2

My Java code:
LayoutMetaDataService.getInstance();  // Forces initialization of ELK reflective classes.
ElkNode rootNode = ElkGraphUtil.createGraph();
rootNode.setProperty(LayeredOptions.EDGE_ROUTING, EdgeRouting.ORTHOGONAL);

ElkNode elkNode1 = ElkGraphUtil.createNode(rootNode);
elkNode1.setDimensions(100.0, 100.0);
elkNode1.setProperty(CoreOptions.PORT_CONSTRAINTS, PortConstraints.FIXED_POS);

ElkPort elkPort1 = ElkGraphUtil.createPort(elkNode1);
elkPort1.setDimensions(10.0, 10.0);
elkPort1.setLocation(100.0, 0.0);

ElkNode elkNode2 = ElkGraphUtil.createNode(rootNode);
elkNode2.setDimensions(100.0, 100.0);
elkNode2.setProperty(CoreOptions.PORT_CONSTRAINTS, PortConstraints.FIXED_POS);

ElkPort elkPort2 = ElkGraphUtil.createPort(elkNode2);
elkPort2.setDimensions(20.0, 20.0);
elkPort2.setLocation(80.0, 100.0);

ElkEdge edge = ElkGraphUtil.createEdge(rootNode);
edge.getSources().add(elkPort1);
edge.getTargets().add(elkPort2);

LayeredLayoutProvider layeredLayoutProvider = new LayeredLayoutProvider();
layeredLayoutProvider.initialize(null);
try {
    BasicProgressMonitor progressMonitor = new BasicProgressMonitor();
    layeredLayoutProvider.layout(rootNode, progressMonitor);
} finally {
    layeredLayoutProvider.dispose();
}

System.out.println(elkNode1);
System.out.println(elkNode2);
System.out.println(edge.getSections());
System.out.println(edge.getProperty(LayeredOptions.JUNCTION_POINTS));

Which outputs:
ElkNode (12.0,137.0 | 100.0,100.0)
ElkNode (142.0,12.0 | 100.0,100.0)
[org.eclipse.elk.graph.impl.ElkEdgeSectionImpl@d4342c2 (startX: 122.0, startY: 142.0, endX: 232.0, endY: 132.0, identifier: null)]
()

So the edge seems to go diagonally from (122, 142) to (232, 132), which is fine, but there are no junctions even though I was hoping for an orthogonal graph.
Re: Getting the shape of edges using the ELK Java API? [message #1797281 is a reply to message #1796898] Mon, 29 October 2018 13:49 Go to previous messageGo to next message
Miro Spönemann is currently offline Miro SpönemannFriend
Messages: 71
Registered: March 2015
Location: Kiel, Germany
Member

Junction points are used when multiple edges are connected to the same port. This does not apply here.

Have you tried printing
edge.getSections().getBendPoints()
?
Re: Getting the shape of edges using the ELK Java API? [message #1797394 is a reply to message #1797281] Tue, 30 October 2018 14:33 Go to previous message
vlq . is currently offline vlq .Friend
Messages: 2
Registered: October 2018
Junior Member
That works nicely, thank you!

I will just add to the answer that edge.getSections() returns a list and getBendPoints() is a method of the actual sections (although there is just one in the example):
EList<ElkEdgeSection> sections = edge.getSections();
for(ElkEdgeSection s : sections)
    System.out.println(s.getBendPoints());
Previous Topic:[ELK] Labels of edges are not correctly placed and overlapped in Sirius
Next Topic:Tutorial incomplete
Goto Forum:
  


Current Time: Sun Apr 18 16:54:55 GMT 2021

Powered by FUDForum. Page generated in 0.01938 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top