@@ -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 ) {
0 commit comments