Skip to content

Commit 2a2addd

Browse files
[SLD] Align the feeders' names horizontally (#747)
* Separate yShift computation for feeder nodes to align the labels' name * Update unit tests * Fix graph label position Signed-off-by: BOUTIER Charly <charly.boutier@rte-france.com> Co-authored-by: Florian Dupuy <florian.dupuy@rte-france.com>
1 parent 7788349 commit 2a2addd

File tree

133 files changed

+961
-925
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+961
-925
lines changed

single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/AbstractLabelProvider.java

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public List<NodeLabel> getNodeLabels(Node node, Direction direction) {
5454
if (node instanceof BusNode) {
5555
getLabelOrNameOrId(node).ifPresent(label -> nodeLabels.add(new NodeLabel(label, getBusLabelPosition(), null)));
5656
} else if (node instanceof FeederNode || svgParameters.isDisplayEquipmentNodesLabel() && node instanceof EquipmentNode) {
57-
getLabelOrNameOrId(node).ifPresent(label -> nodeLabels.add(new NodeLabel(label, getLabelPosition(node, direction), null)));
57+
getLabelOrNameOrId(node).ifPresent(label -> nodeLabels.add(new NodeLabel(label, getFeederLabelPosition(node, direction), null)));
5858
} else if (svgParameters.isDisplayConnectivityNodesId() && node instanceof ConnectivityNode) {
5959
nodeLabels.add(new NodeLabel(node.getId(), getLabelPosition(node, direction), null));
6060
}
@@ -100,22 +100,58 @@ protected LabelPosition getBusDecoratorPosition() {
100100
return new LabelPosition("BUS_DECORATOR", 35, -10, true, 0);
101101
}
102102

103+
protected LabelPosition getFeederLabelPosition(Node node, Direction direction) {
104+
return new LabelPosition(getLabelPositionName(direction), getLabelXShift(),
105+
getFeederLabelYShift(node, direction), svgParameters.isLabelCentered(), getLabelAngle(direction));
106+
}
107+
103108
protected LabelPosition getLabelPosition(Node node, Direction direction) {
104-
double yShift = -LABEL_OFFSET;
105-
String positionName = "";
106-
double angle = 0;
107-
if (direction != UNDEFINED) {
108-
yShift = direction == TOP
109-
? -LABEL_OFFSET
110-
: ((int) (componentLibrary.getSize(node.getComponentType()).getHeight()) + LABEL_OFFSET);
111-
positionName = direction == TOP ? "N" : "S";
112-
if (svgParameters.isLabelDiagonal()) {
113-
angle = direction == TOP ? -svgParameters.getAngleLabelShift() : svgParameters.getAngleLabelShift();
114-
}
109+
return new LabelPosition(getLabelPositionName(direction), getLabelXShift(),
110+
getLabelYShift(node, direction), svgParameters.isLabelCentered(), getLabelAngle(direction));
111+
}
112+
113+
private double getLabelXShift() {
114+
return svgParameters.isLabelCentered() ? 0 : -LABEL_OFFSET;
115+
}
116+
117+
private double getLabelYShift(Node node, Direction direction) {
118+
return direction != TOP
119+
? componentLibrary.getSize(node.getComponentType()).getHeight() + LABEL_OFFSET
120+
: -LABEL_OFFSET;
121+
}
122+
123+
private double getFeederLabelYShift(Node node, Direction direction) {
124+
if (direction == UNDEFINED) {
125+
return -LABEL_OFFSET;
115126
}
116127

117-
return new LabelPosition(positionName + "_LABEL",
118-
svgParameters.isLabelCentered() ? 0 : -LABEL_OFFSET, yShift, svgParameters.isLabelCentered(), (int) angle);
128+
// The FeederNode position is at the top-left position of the corresponding component.
129+
// We first shift to half the component height to be back at the center of the component, knowing that
130+
// all the FeederNode centers are on the same horizontal line.
131+
double shiftToFeederComponentCenter = componentLibrary.getSize(node.getComponentType()).getHeight() / 2;
132+
133+
// Then we add a shift of half the max component height to be just above/just below all feeder components.
134+
double shiftToFeederOut = (direction == TOP ? -1 : 1) * layoutParameters.getMaxComponentHeight() / 2;
135+
136+
// And finally we add an offset to be slightly above a component whose height is equal to the max height
137+
double margin = (direction == TOP ? -1 : 1) * LABEL_OFFSET;
138+
139+
return shiftToFeederComponentCenter + shiftToFeederOut + margin;
140+
}
141+
142+
private int getLabelAngle(Direction direction) {
143+
if (!svgParameters.isLabelDiagonal()) {
144+
return 0;
145+
}
146+
return (int) Math.round((direction == TOP ? -1 : 1) * svgParameters.getAngleLabelShift());
147+
}
148+
149+
private String getLabelPositionName(Direction direction) {
150+
return switch (direction) {
151+
case TOP -> "N_LABEL";
152+
case BOTTOM -> "S_LABEL";
153+
default -> "LABEL";
154+
};
119155
}
120156

121157
protected LabelPosition getInternal2WTDecoratorPosition(Orientation orientation) {

single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/CustomLabelProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public List<NodeLabel> getNodeLabels(Node node, Direction direction) {
150150
addNodeLabels(l, nodeLabels, getBusLabelPosition(), getAdditionalBusLabelPosition()));
151151
} else if (node instanceof FeederNode || svgParameters.isDisplayEquipmentNodesLabel() && node instanceof EquipmentNode) {
152152
getEquipmentLabel(node).ifPresent(l ->
153-
addNodeLabels(l, nodeLabels, getLabelPosition(node, direction), getAdditionalLabelPosition(node, direction)));
153+
addNodeLabels(l, nodeLabels, getFeederLabelPosition(node, direction), getAdditionalLabelPosition(node, direction)));
154154
} else if (svgParameters.isDisplayConnectivityNodesId() && node instanceof ConnectivityNode) {
155155
nodeLabels.add(new NodeLabel(node.getId(), getLabelPosition(node, direction), null));
156156
}

single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DefaultSVGWriter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ protected void drawGraphLabel(Element root, VoltageLevelGraph graph, GraphMetada
531531
Element gLabel = root.getOwnerDocument().createElement(GROUP);
532532
gLabel.setAttribute("id", idLabelVoltageLevel);
533533

534-
double yPos = graph.getY() - 20.;
534+
double yPos = graph.getY() - 24.;
535535

536536
String graphName = svgParameters.isUseName() ? graph.getVoltageLevelInfos().getName() : graph.getVoltageLevelInfos().getId();
537537
Element label = createLabelElement(graphName, graph.getX(), yPos, 0, gLabel);

single-line-diagram/single-line-diagram-core/src/test/resources/CustomLabelProviderTest1.svg

Lines changed: 10 additions & 10 deletions
Loading

0 commit comments

Comments
 (0)