use of org.eclipse.elk.graph.ElkLabel in project elk by eclipse.
the class FixedLayoutProvider method processEdge.
/**
* Process an edge and its labels.
*
* @param edge an edge
* @param edgeRouting the global edge routing setting
*/
private KVector processEdge(final ElkEdge edge, final EdgeRouting edgeRouting) {
// MIGRATE Does this properly support hyperedges?
ElkNode sourceParent = ElkGraphUtil.connectableShapeToNode(edge.getSources().get(0)).getParent();
ElkNode targetParent = ElkGraphUtil.connectableShapeToNode(edge.getTargets().get(0)).getParent();
boolean sameHierarchy = sourceParent == targetParent;
KVector maxv = new KVector();
KVectorChain bendPoints = edge.getProperty(FixedLayouterOptions.BEND_POINTS);
// we need at least two bend points, since the source point and target point must be included
if (bendPoints != null && bendPoints.size() >= 2) {
if (edge.getSections().isEmpty()) {
// We need an edge section to apply the bend points to
ElkEdgeSection edgeSection = ElkGraphFactory.eINSTANCE.createElkEdgeSection();
edge.getSections().add(edgeSection);
} else if (edge.getSections().size() > 1) {
// We can only apply bend points to a single edge section, so throw away all except for the last one
ListIterator<ElkEdgeSection> sections = edge.getSections().listIterator();
while (sections.hasNext()) {
sections.remove();
}
}
ElkUtil.applyVectorChain(bendPoints, edge.getSections().get(0));
}
// determine maximal coordinates
if (sameHierarchy) {
for (ElkEdgeSection edgeSection : edge.getSections()) {
for (ElkBendPoint point : edgeSection.getBendPoints()) {
maxv.x = Math.max(maxv.x, point.getX());
maxv.y = Math.max(maxv.y, point.getY());
}
}
}
// set the fixed position of the edge labels, or leave them as they are
for (ElkLabel label : edge.getLabels()) {
KVector pos = label.getProperty(FixedLayouterOptions.POSITION);
if (pos != null) {
label.setLocation(pos.x, pos.y);
}
if (sameHierarchy) {
maxv.x = Math.max(maxv.x, label.getX() + label.getWidth());
maxv.y = Math.max(maxv.y, label.getY() + label.getHeight());
}
}
return maxv;
}
use of org.eclipse.elk.graph.ElkLabel in project elk by eclipse.
the class FixedLayoutProvider method layout.
@Override
public void layout(final ElkNode layoutNode, final IElkProgressMonitor progressMonitor) {
progressMonitor.begin("Fixed Layout", 1);
EdgeRouting edgeRouting = layoutNode.getProperty(CoreOptions.EDGE_ROUTING);
double maxx = 0;
double maxy = 0;
for (ElkNode node : layoutNode.getChildren()) {
// set the fixed position of the node, or leave it as it is
KVector pos = node.getProperty(FixedLayouterOptions.POSITION);
if (pos != null) {
node.setLocation(pos.x, pos.y);
// set the fixed size of the node
if (node.getProperty(FixedLayouterOptions.NODE_SIZE_CONSTRAINTS).contains(SizeConstraint.MINIMUM_SIZE)) {
KVector minSize = node.getProperty(FixedLayouterOptions.NODE_SIZE_MINIMUM);
if (minSize.x > 0 && minSize.y > 0) {
ElkUtil.resizeNode(node, minSize.x, minSize.y, true, true);
}
}
}
maxx = Math.max(maxx, node.getX() + node.getWidth());
maxy = Math.max(maxy, node.getY() + node.getHeight());
// set the fixed position of the node labels, or leave them as they are
for (ElkLabel label : node.getLabels()) {
pos = label.getProperty(FixedLayouterOptions.POSITION);
if (pos != null) {
label.setLocation(pos.x, pos.y);
}
maxx = Math.max(maxx, node.getX() + label.getX() + label.getWidth());
maxy = Math.max(maxy, node.getY() + label.getY() + label.getHeight());
}
// set the fixed position of the ports, or leave them as they are
for (ElkPort port : node.getPorts()) {
pos = port.getProperty(FixedLayouterOptions.POSITION);
if (pos != null) {
port.setLocation(pos.x, pos.y);
}
double portx = node.getX() + port.getX();
double porty = node.getY() + port.getY();
maxx = Math.max(maxx, portx + port.getWidth());
maxy = Math.max(maxy, porty + port.getHeight());
// set the fixed position of the port labels, or leave them as they are
for (ElkLabel label : port.getLabels()) {
pos = label.getProperty(FixedLayouterOptions.POSITION);
if (pos != null) {
label.setLocation(pos.x, pos.y);
}
maxx = Math.max(maxx, portx + label.getX() + label.getWidth());
maxy = Math.max(maxy, porty + label.getY() + label.getHeight());
}
}
// set fixed routing for the node's outgoing edges (both simple and hierarchical), or leave them as they are
for (ElkEdge edge : ElkGraphUtil.allOutgoingEdges(node)) {
KVector maxv = processEdge(edge, edgeRouting);
maxx = Math.max(maxx, maxv.x);
maxy = Math.max(maxy, maxv.y);
}
// note that this potentially results in hierarchical edges being handled twice
for (ElkEdge edge : ElkGraphUtil.allIncomingEdges(node)) {
if (ElkGraphUtil.getSourceNode(edge).getParent() != layoutNode) {
KVector maxv = processEdge(edge, edgeRouting);
maxx = Math.max(maxx, maxv.x);
maxy = Math.max(maxy, maxv.y);
}
}
}
// if orthogonal routing is selected, determine the junction points
if (edgeRouting == EdgeRouting.ORTHOGONAL) {
for (ElkNode node : layoutNode.getChildren()) {
for (ElkEdge edge : ElkGraphUtil.allOutgoingEdges(node)) {
generateJunctionPoints(edge);
}
}
}
// set size of the parent node unless its size should be fixed as well
if (!layoutNode.getProperty(FixedLayouterOptions.NODE_SIZE_FIXED_GRAPH_SIZE)) {
ElkPadding padding = layoutNode.getProperty(FixedLayouterOptions.PADDING);
double newWidth = maxx + padding.getLeft() + padding.getRight();
double newHeight = maxy + padding.getTop() + padding.getBottom();
ElkUtil.resizeNode(layoutNode, newWidth, newHeight, true, true);
}
progressMonitor.done();
}
use of org.eclipse.elk.graph.ElkLabel in project elk by eclipse.
the class DisCoGraphRenderer method renderNodeChildren.
// filling alpha added by mic
/**
* Paints all children of the given parent node that fall into the given dirty
* area.
*
* @param parent
* the node whose children to paint
* @param graphics
* the graphics context used to paint
* @param area
* dirty area that needs painting
* @param offset
* offset to be added to relative coordinates
* @param edgeSet
* set to be filled with edges that are found on the way
* @param nodeAlpha
* alpha value for nodes
* @param fillingAlpha
* alpha value for node fillings
*/
private void renderNodeChildren(final ElkNode parent, final GC graphics, final Rectangle area, final KVector offset, final Set<ElkEdge> edgeSet, final int nodeAlpha, final int fillingAlpha) {
for (ElkNode child : parent.getChildren()) {
PaintRectangle rect = boundsMap.get(child);
if (rect == null) {
rect = new PaintRectangle(child, offset, getScale());
boundsMap.put(child, rect);
}
KVector childOffset = new KVector(rect.x, rect.y);
// render the child node and its content
if (!rect.painted && rect.intersects(area)) {
// paint this node
graphics.setAlpha(fillingAlpha);
if (configurator.getNodeFillColor() != null) {
graphics.setBackground(configurator.getNodeFillColor());
graphics.fillRectangle(rect.x, rect.y, rect.width, rect.height);
}
graphics.setAlpha(nodeAlpha);
if (configurator.getNodeBorderColor() != null) {
graphics.setForeground(configurator.getNodeBorderColor());
graphics.drawRectangle(rect.x, rect.y, rect.width, rect.height);
}
rect.painted = true;
}
// render node labels
if (configurator.getNodeLabelFont() != null) {
graphics.setFont(configurator.getNodeLabelFont());
for (ElkLabel label : child.getLabels()) {
renderLabel(label, graphics, area, childOffset, nodeAlpha);
}
}
// render ports
for (ElkPort port : child.getPorts()) {
renderPort(port, graphics, area, childOffset, nodeAlpha);
}
// store all incident edges to render them later
edgeSet.addAll(Sets.newHashSet(ElkGraphUtil.allIncidentEdges(child)));
}
}
use of org.eclipse.elk.graph.ElkLabel in project elk by eclipse.
the class AbstractElkGraphSemanticSequencer method sequence.
@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
EPackage epackage = semanticObject.eClass().getEPackage();
ParserRule rule = context.getParserRule();
Action action = context.getAssignedAction();
Set<Parameter> parameters = context.getEnabledBooleanParameters();
if (epackage == ElkGraphPackage.eINSTANCE)
switch(semanticObject.eClass().getClassifierID()) {
case ElkGraphPackage.ELK_BEND_POINT:
sequence_ElkBendPoint(context, (ElkBendPoint) semanticObject);
return;
case ElkGraphPackage.ELK_EDGE:
sequence_EdgeLayout_ElkEdge(context, (ElkEdge) semanticObject);
return;
case ElkGraphPackage.ELK_EDGE_SECTION:
if (rule == grammarAccess.getElkEdgeSectionRule()) {
sequence_ElkEdgeSection(context, (ElkEdgeSection) semanticObject);
return;
} else if (rule == grammarAccess.getElkSingleEdgeSectionRule()) {
sequence_ElkSingleEdgeSection(context, (ElkEdgeSection) semanticObject);
return;
} else
break;
case ElkGraphPackage.ELK_LABEL:
sequence_ElkLabel_ShapeLayout(context, (ElkLabel) semanticObject);
return;
case ElkGraphPackage.ELK_NODE:
if (rule == grammarAccess.getElkNodeRule()) {
sequence_ElkNode_ShapeLayout(context, (ElkNode) semanticObject);
return;
} else if (rule == grammarAccess.getRootNodeRule()) {
sequence_RootNode_ShapeLayout(context, (ElkNode) semanticObject);
return;
} else
break;
case ElkGraphPackage.ELK_PORT:
sequence_ElkPort_ShapeLayout(context, (ElkPort) semanticObject);
return;
case ElkGraphPackage.ELK_PROPERTY_TO_VALUE_MAP_ENTRY:
sequence_Property(context, (Map.Entry) semanticObject);
return;
}
if (errorAcceptor != null)
errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
use of org.eclipse.elk.graph.ElkLabel in project elk by eclipse.
the class ElkGraphUtil method createLabel.
/**
* Creates a new label with the given text for the given graph element.
*
* @param text the label's text.
* @param parent the parent element. May be {@code null}, in which case the new label is not added to anything.
* @return the new label.
*/
public static ElkLabel createLabel(final String text, final ElkGraphElement parent) {
ElkLabel label = createLabel(parent);
label.setText(text);
return label;
}
Aggregations