use of org.eclipse.elk.core.options.EdgeLabelPlacement in project elk by eclipse.
the class LayoutDotExporter method setEdgeLabels.
@Override
protected void setEdgeLabels(final ElkEdge kedge, final List<Attribute> attributes, final boolean isVertical) {
super.setEdgeLabels(kedge, attributes, isVertical);
// set label distance and angle
if (Iterables.any(kedge.getLabels(), (ElkLabel label) -> {
EdgeLabelPlacement elp = label.getProperty(CoreOptions.EDGE_LABELS_PLACEMENT);
return elp == EdgeLabelPlacement.HEAD || elp == EdgeLabelPlacement.TAIL;
})) {
double distance = kedge.getProperty(GraphvizMetaDataProvider.LABEL_DISTANCE);
if (distance >= 0.0) {
attributes.add(createAttribute(Attributes.LABELDISTANCE, distance));
}
double angle = kedge.getProperty(GraphvizMetaDataProvider.LABEL_ANGLE);
attributes.add(createAttribute(Attributes.LABELANGLE, angle));
}
}
use of org.eclipse.elk.core.options.EdgeLabelPlacement in project elk by eclipse.
the class DotExporter method applyEdgeLabelPos.
/**
* Applies the edge label positions for the given edge.
*
* @param elkedge edge for which labels are processed
* @param posString string with label position
* @param placement label placement to choose
* @param offsetx x offset added to positions
* @param offsety y offset added to positions
*/
private void applyEdgeLabelPos(final ElkEdge elkedge, final String posString, final EdgeLabelPlacement placement, final KVector offset) {
double combinedWidth = 0.0;
double combinedHeight = 0.0;
for (ElkLabel label : elkedge.getLabels()) {
EdgeLabelPlacement elp = label.getProperty(CoreOptions.EDGE_LABELS_PLACEMENT);
if (elp == placement) {
combinedWidth = Math.max(combinedWidth, label.getWidth());
combinedHeight += label.getHeight();
}
}
try {
KVector pos = new KVector();
pos.parse(posString);
double xpos = pos.x - combinedWidth / 2 + offset.x;
double ypos = pos.y - combinedHeight / 2 + offset.y;
for (ElkLabel label : elkedge.getLabels()) {
EdgeLabelPlacement elp = label.getProperty(CoreOptions.EDGE_LABELS_PLACEMENT);
if (elp == placement) {
double xoffset = (combinedWidth - label.getWidth()) / 2;
label.setX(xpos + xoffset);
label.setY(ypos);
ypos += label.getHeight();
}
}
} catch (IllegalArgumentException exception) {
// ignore exception
}
}
use of org.eclipse.elk.core.options.EdgeLabelPlacement in project elk by eclipse.
the class DotExporter method setEdgeLabels.
/**
* Set edge labels for the given edge.
*
* @param elkedge edge whose labels shall be set
* @param attributes edge attribute list to which the labels are added
* @param isVertical indicates whether vertical layout direction is active
*/
protected void setEdgeLabels(final ElkEdge elkedge, final List<Attribute> attributes, final boolean isVertical) {
if (elkedge.getLabels().isEmpty()) {
return;
}
// as Graphviz only supports positioning of one label per label placement, all labels
// are stacked to one big label as workaround
StringBuilder midLabel = new StringBuilder(), headLabel = new StringBuilder(), tailLabel = new StringBuilder();
String fontName = null;
int fontSize = 0;
boolean isCenterFontName = false, isCenterFontSize = false;
for (ElkLabel label : elkedge.getLabels()) {
StringBuilder buffer = midLabel;
EdgeLabelPlacement placement = label.getProperty(CoreOptions.EDGE_LABELS_PLACEMENT);
boolean takeFontName = false, takeFontSize = false;
switch(placement) {
case HEAD:
takeFontName = fontName == null;
takeFontSize = fontSize <= 0;
buffer = headLabel;
break;
case TAIL:
takeFontName = fontName == null;
takeFontSize = fontSize <= 0;
buffer = tailLabel;
break;
default:
// CENTER
takeFontName = fontName == null || !isCenterFontName;
isCenterFontName = true;
takeFontSize = fontSize <= 0 || !isCenterFontSize;
isCenterFontSize = true;
break;
}
if (buffer.length() > 0) {
buffer.append("\n");
}
buffer.append(label.getText());
if (takeFontName) {
fontName = label.getProperty(CoreOptions.FONT_NAME);
}
if (takeFontSize) {
fontSize = label.getProperty(CoreOptions.FONT_SIZE);
// increase the font size to let Graphviz prepare more room for the label
if (fontSize > 0) {
fontSize *= FONT_SIZE_MULT;
}
}
}
// edge overlapping
if (midLabel.length() > 0) {
double labelSpacing = elkedge.getProperty(CoreOptions.SPACING_EDGE_LABEL);
if (labelSpacing < 1) {
labelSpacing = 0;
}
int charsToAdd = (int) labelSpacing - 1;
for (int i = 0; i < charsToAdd; i++) {
midLabel.append(isVertical ? "O" : "\nO");
}
attributes.add(createAttribute(Attributes.LABEL, createString(midLabel.toString())));
}
// set head label
if (headLabel.length() > 0) {
attributes.add(createAttribute(Attributes.HEADLABEL, createString(headLabel.toString())));
}
// set tail label
if (tailLabel.length() > 0) {
attributes.add(createAttribute(Attributes.TAILLABEL, createString(tailLabel.toString())));
}
// set font name
if (fontName != null && fontName.length() > 0) {
attributes.add(createAttribute(Attributes.FONTNAME, "\"" + fontName + "\""));
}
// set font size
if (fontSize > 0) {
attributes.add(createAttribute(Attributes.FONTSIZE, fontSize));
}
}
Aggregations