Home » Modeling » Eclipse Layout Kernel » [question] Layout doesn't calculate dimensions(Basic question about layout functionality)
[question] Layout doesn't calculate dimensions [message #1798977] |
Wed, 28 November 2018 04:18  |
Eclipse User |
|
|
|
Hi, I try to use ELK to generate a layout for a dataflow.
Our system generate a dataflow using our engine, then we would like to transform it in an ELK graph so we can call a layout algorithm, generate ELK JSON in the server side, and show it in a web front end using Sprotty.
I saw a lot of example and try to generate something like the models showed in Model browser of ELK Graph Viewers page.
The question is: do the ELK layout method calculate the dimensions of labels and ports (and consequently node dimensions) too, or I need to specify it in ElkLabel/ElkPort object as a numeric value?
Our generate labels and ports haven't width or height and we would like to link the dimension of node with the dimension of text label and don't hardcode the dimension of port.
To resume what I do:
In the java class we register the LayoutMetadataProvider using LayeredMetaDataProvider, then we create the root node
ElkNode root = elk.createElkNode();
root.setIdentifier(id);
root.setProperty(CoreOptions.ALGORITHM, "elk.layered");
root.setProperty(LayeredOptions.HIERARCHY_HANDLING, HierarchyHandling.INCLUDE_CHILDREN);
Then we create the Graph using a bridge between our Dataflow definition and the ELK Graph data structure and then we call layout and generate the json
RecursiveGraphLayoutEngine engine = new RecursiveGraphLayoutEngine();
engine.layout(root, new BasicProgressMonitor());
// TODO these options are copied from the docs without thinking
json = ElkGraphJson.forGraph(root)
.omitLayout(false)
.omitZeroDimension(true)
.omitZeroPositions(true)
.shortLayoutOptionKeys(false)
.prettyPrint(true)
.toJson();
When we build the graph, in each node we use this properties
node.setProperty(CoreOptions.NODE_SIZE_CONSTRAINTS, EnumSet.allOf(SizeConstraint.class));
node.setProperty(CoreOptions.NODE_LABELS_PLACEMENT, NodeLabelPlacement.outsideTopLeft());
The result of this is something like this (copied from generated json)
{
"id": "G1",
"children": [
{
"id": "N1",
"labels": [
{
"text": "Region presence",
"id": "N1l",
"y": -5.0
}
],
"ports": [
{
"id": "N1_out1",
"layoutOptions": {
"org.eclipse.elk.port.side": "EAST"
},
"x": 84.0,
"y": 27.0
}
],
"children": [
{
"id": "N1rr",
"labels": [
{
"text": "k.first node",
"id": "N1_k.rrl",
"y": -5.0
}
],
"ports": [
{
"id": "N1_k.rr_out",
"layoutOptions": {
"org.eclipse.elk.port.side": "EAST"
},
"x": 20.0,
"y": 10.0
}
],
"layoutOptions": {
"org.eclipse.elk.nodeSize.constraints": "[PORTS, PORT_LABELS, NODE_LABELS, MINIMUM_SIZE]",
"org.eclipse.elk.nodeLabels.placement": "[H_LEFT, V_TOP, OUTSIDE]",
"org.eclipse.elk.resolvedAlgorithm": "Layout Algorithm: org.eclipse.elk.layered",
"org.eclipse.elk.hierarchyHandling": "INCLUDE_CHILDREN"
},
"x": 12.0,
"y": 17.0,
"width": 20.0,
"height": 20.0
},
{
"id": "N1_k.rc",
"labels": [
{
"text": "k.second node",
"id": "N1_k.rcl",
"y": -5.0
}
],
"ports": [
{
"id": "N1_k.rc_out",
"layoutOptions": {
"org.eclipse.elk.port.side": "EAST"
},
"x": 20.0,
"y": 10.0
},
{
"id": "N1_k.rc_in",
"layoutOptions": {
"org.eclipse.elk.port.side": "WEST"
},
"y": 10.0
}
],
"layoutOptions": {
"org.eclipse.elk.nodeSize.constraints": "[PORTS, PORT_LABELS, NODE_LABELS, MINIMUM_SIZE]",
"org.eclipse.elk.nodeLabels.placement": "[H_LEFT, V_TOP, OUTSIDE]",
"org.eclipse.elk.resolvedAlgorithm": "Layout Algorithm: org.eclipse.elk.layered",
"org.eclipse.elk.hierarchyHandling": "INCLUDE_CHILDREN"
},
"x": 52.0,
"y": 17.0,
"width": 20.0,
"height": 20.0
}
],
"layoutOptions": {
"org.eclipse.elk.nodeSize.constraints": "[PORT_LABELS]",
"org.eclipse.elk.nodeLabels.placement": "[H_LEFT, V_TOP, OUTSIDE]",
"org.eclipse.elk.resolvedAlgorithm": "Layout Algorithm: org.eclipse.elk.layered",
"org.eclipse.elk.nodeSize.options": "[DEFAULT_MINIMUM_SIZE]",
"org.eclipse.elk.hierarchyHandling": "INCLUDE_CHILDREN"
},
"x": 12.0,
"y": 17.0,
"width": 84.0,
"height": 49.0,
"edges": [
{
"id": "N1_k.rc_feed",
"sources": [
"N1_k.rr_out"
],
"targets": [
"N1_k.rc_in"
],
"sections": [
{
"id": "s5",
"startPoint": {
"x": 32.0,
"y": 27.0
},
"endPoint": {
"x": 52.0,
"y": 27.0
}
}
],
"layoutOptions": {
"org.eclipse.elk.junctionPoints": "()"
}
},
{
"id": "N1_k.rc_outlink",
"sources": [
"N1_k.rc_out"
],
"targets": [
"N1_out1"
],
"sections": [
{
"id": "s6",
"startPoint": {
"x": 72.0,
"y": 27.0
},
"endPoint": {
"x": 84.0,
"y": 27.0
}
}
],
"layoutOptions": {
"org.eclipse.elk.junctionPoints": "()"
}
}
]
}
],
"layoutOptions": {
"org.eclipse.elk.nodeSize.constraints": "[]",
"org.eclipse.elk.nodeLabels.placement": "[]",
"org.eclipse.elk.resolvedAlgorithm": "Layout Algorithm: org.eclipse.elk.layered",
"org.eclipse.elk.algorithm": "elk.layered",
"org.eclipse.elk.nodeSize.options": "[DEFAULT_MINIMUM_SIZE]",
"org.eclipse.elk.hierarchyHandling": "INCLUDE_CHILDREN"
},
}
This is a little peace of the JSON with some manual modification. I attach the result drawn using the JSON Editor of ELK Graph Viewer page.
The results is the same that I obtain when I draw it in our web using Sprotty, so it seems that this part work.
I understand that this is a question about the basic functionality of ELK, but before writing here, I read a lot of documentation and tried different things without results, so any help will be much appreciated.
Thank!
|
|
| | | | | |
Goto Forum:
Current Time: Thu Apr 24 17:27:45 EDT 2025
Powered by FUDForum. Page generated in 0.04064 seconds
|