Skip to content

Commit 6901cdc

Browse files
committed
adds a javadoc and removes redundant prefixes
Signed-off-by: Christian Biasuzzi <christian.biasuzzi@soft.it>
1 parent 1678cea commit 6901cdc

2 files changed

Lines changed: 57 additions & 33 deletions

File tree

network-area-diagram/src/main/java/com/powsybl/nad/svg/CustomStyleProvider.java

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,54 @@
1717
import java.util.stream.Stream;
1818

1919
/**
20+
* Enables the customization of the style of NAD elements: Bus nodes, branch-edges and three-winding-transformers edges.
21+
*
22+
* <p>
23+
* NAD elements'style data is defined in the CustomStyleProvider constructor's map parameters.
24+
*
25+
* <p>
26+
* The busNodesStyles map is indexed by the bus ID and defines the style for the bus nodes.
27+
* In the map, a node style is declared in a BusNodeStyles record: fill, edge and edgeWidth are the fill color, the edge color and the edge size for the node, respectively.
28+
*
29+
* <p>
30+
* The edgesStyles map is indexed by the branch ID and defines the style for the edges.
31+
* In the map, the edge style is declared in a EdgeStyles record: edge1, width1 and dash1 are the color, the size and a dash pattern for the first half edge, respectively.
32+
* Edge2, width2 and dash2 are the color, the size and a dash pattern for the second half edge.
33+
*
34+
* <p>
35+
* The threeWtsStyles map is index by the three-winding-transformer ID and defines the style for the transformer’s legs.
36+
* In the map, the style is declared in a ThreeWtStyles record: edge1, width1, dash1, edge2, width2 and dash2, edge3, width23 and dash3,
37+
* are the color, the size and a dash pattern for the three legs of the transformer.
38+
*
39+
* <p>
40+
* Note that the edge size is a string, it can be specified in pixel (e.g, 4px).
41+
* A dash pattern is a string with a sequence of comma and/or white space separated lengths and percentages, that specify the lengths of alternating dashes and gaps in the edge.
42+
* Elements that do not have a style specified in the parameters will be displayed with a default style.
43+
*
2044
* @author Christian Biasuzzi {@literal <christian.biasuzzi at soft.it>}
2145
*/
2246
public class CustomStyleProvider extends AbstractStyleProvider {
2347

24-
final Map<String, CustomBusNodeStyles> busNodesStyles;
25-
final Map<String, CustomEdgeStyles> edgesStyles;
26-
final Map<String, CustomThreeWtStyles> threeWtsStyles;
48+
final Map<String, BusNodeStyles> busNodesStyles;
49+
final Map<String, EdgeStyles> edgesStyles;
50+
final Map<String, ThreeWtStyles> threeWtsStyles;
2751

28-
public record CustomBusNodeStyles(String fill, String edge, String edgeWidth) {
52+
public record BusNodeStyles(String fill, String edge, String edgeWidth) {
2953
}
3054

31-
public record CustomEdgeStyles(String edge1, String width1, String dash1, String edge2, String width2,
32-
String dash2) {
55+
public record EdgeStyles(String edge1, String width1, String dash1, String edge2, String width2,
56+
String dash2) {
3357
}
3458

35-
public record CustomThreeWtStyles(String edge1, String width1, String dash1, String edge2, String width2,
36-
String dash2, String edge3, String width3, String dash3) {
59+
public record ThreeWtStyles(String edge1, String width1, String dash1, String edge2, String width2,
60+
String dash2, String edge3, String width3, String dash3) {
3761
}
3862

39-
private record CustomEdgeStyle(String stroke, String strokeWidth, String dash) {
63+
private record EdgeStyle(String stroke, String strokeWidth, String dash) {
4064
}
4165

42-
public CustomStyleProvider(Map<String, CustomBusNodeStyles> busNodesStyles, Map<String, CustomEdgeStyles> edgesStyles,
43-
Map<String, CustomThreeWtStyles> threeWtsStyles) {
66+
public CustomStyleProvider(Map<String, BusNodeStyles> busNodesStyles, Map<String, EdgeStyles> edgesStyles,
67+
Map<String, ThreeWtStyles> threeWtsStyles) {
4468
this.busNodesStyles = Objects.requireNonNull(busNodesStyles);
4569
this.edgesStyles = Objects.requireNonNull(edgesStyles);
4670
this.threeWtsStyles = Objects.requireNonNull(threeWtsStyles);
@@ -53,7 +77,7 @@ public List<String> getCssFilenames() {
5377

5478
@Override
5579
public String getBusNodeStyle(BusNode busNode) {
56-
CustomBusNodeStyles style = busNodesStyles.get(busNode.getEquipmentId());
80+
BusNodeStyles style = busNodesStyles.get(busNode.getEquipmentId());
5781
if (style != null) {
5882
List<String> parts = new ArrayList<>();
5983
if (style.fill() != null) {
@@ -71,13 +95,13 @@ public String getBusNodeStyle(BusNode busNode) {
7195
return null;
7296
}
7397

74-
private CustomEdgeStyle getEdgeStyle(CustomEdgeStyles styles, BranchEdge.Side side) {
98+
private EdgeStyle getEdgeStyle(EdgeStyles styles, BranchEdge.Side side) {
7599
return (side == BranchEdge.Side.ONE)
76-
? new CustomEdgeStyle(styles.edge1(), styles.width1(), styles.dash1())
77-
: new CustomEdgeStyle(styles.edge2(), styles.width2(), styles.dash2());
100+
? new EdgeStyle(styles.edge1(), styles.width1(), styles.dash1())
101+
: new EdgeStyle(styles.edge2(), styles.width2(), styles.dash2());
78102
}
79103

80-
private String formatEdgeStyle(CustomEdgeStyle lineStyle) {
104+
private String formatEdgeStyle(EdgeStyle lineStyle) {
81105
return Stream.of(
82106
Optional.ofNullable(lineStyle.stroke()).map(stroke -> String.format("stroke:%s;", stroke)).orElse(null),
83107
Optional.ofNullable(lineStyle.strokeWidth()).map(width -> String.format("stroke-width:%s;", width)).orElse(null),
@@ -87,11 +111,11 @@ private String formatEdgeStyle(CustomEdgeStyle lineStyle) {
87111
.collect(Collectors.joining(" "));
88112
}
89113

90-
private CustomEdgeStyle getThreeWtStyle(CustomThreeWtStyles styles, ThreeWtEdge.Side side) {
114+
private EdgeStyle getThreeWtStyle(ThreeWtStyles styles, ThreeWtEdge.Side side) {
91115
return switch (side) {
92-
case ONE -> new CustomEdgeStyle(styles.edge1(), styles.width1(), styles.dash1());
93-
case TWO -> new CustomEdgeStyle(styles.edge2(), styles.width2(), styles.dash2());
94-
case THREE -> new CustomEdgeStyle(styles.edge3(), styles.width3(), styles.dash3());
116+
case ONE -> new EdgeStyle(styles.edge1(), styles.width1(), styles.dash1());
117+
case TWO -> new EdgeStyle(styles.edge2(), styles.width2(), styles.dash2());
118+
case THREE -> new EdgeStyle(styles.edge3(), styles.width3(), styles.dash3());
95119
};
96120
}
97121

network-area-diagram/src/test/java/com/powsybl/nad/svg/CustomStyleProviderTest.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
import com.powsybl.iidm.network.Network;
1212
import com.powsybl.nad.AbstractTest;
1313
import com.powsybl.nad.layout.LayoutParameters;
14-
import com.powsybl.nad.svg.CustomStyleProvider.CustomBusNodeStyles;
15-
import com.powsybl.nad.svg.CustomStyleProvider.CustomEdgeStyles;
16-
import com.powsybl.nad.svg.CustomStyleProvider.CustomThreeWtStyles;
14+
import com.powsybl.nad.svg.CustomStyleProvider.BusNodeStyles;
15+
import com.powsybl.nad.svg.CustomStyleProvider.EdgeStyles;
16+
import com.powsybl.nad.svg.CustomStyleProvider.ThreeWtStyles;
1717
import com.powsybl.nad.svg.iidm.DefaultLabelProvider;
1818
import org.junit.jupiter.api.BeforeEach;
1919
import org.junit.jupiter.api.Test;
@@ -53,19 +53,19 @@ protected LabelProvider getLabelProvider(Network network) {
5353
void testCustomStyleProvider() {
5454
Network network = Networks.createNodeBreakerNetworkWithBranchStatus("TestNodeDecorators", "test");
5555

56-
Map<String, CustomBusNodeStyles> busNodesStyles = new HashMap<>();
57-
busNodesStyles.put("VL1_10", new CustomBusNodeStyles("yellow", null, null));
58-
busNodesStyles.put("VL2_30", new CustomBusNodeStyles("red", "black", "4px"));
56+
Map<String, BusNodeStyles> busNodesStyles = new HashMap<>();
57+
busNodesStyles.put("VL1_10", new BusNodeStyles("yellow", null, null));
58+
busNodesStyles.put("VL2_30", new BusNodeStyles("red", "black", "4px"));
5959

60-
Map<String, CustomEdgeStyles> edgesStyles = new HashMap<>();
61-
edgesStyles.put("L11", new CustomEdgeStyles("blue", "2px", null, "blue", "2px", null));
62-
edgesStyles.put("L12", new CustomEdgeStyles("green", "4px", "8,4", "green", "4px", "8,4"));
63-
edgesStyles.put("T11", new CustomEdgeStyles("red", "8px", null, "brown", "8px", null));
64-
edgesStyles.put("T12", new CustomEdgeStyles("orange", null, null, "orange", null, null));
60+
Map<String, EdgeStyles> edgesStyles = new HashMap<>();
61+
edgesStyles.put("L11", new EdgeStyles("blue", "2px", null, "blue", "2px", null));
62+
edgesStyles.put("L12", new EdgeStyles("green", "4px", "8,4", "green", "4px", "8,4"));
63+
edgesStyles.put("T11", new EdgeStyles("red", "8px", null, "brown", "8px", null));
64+
edgesStyles.put("T12", new EdgeStyles("orange", null, null, "orange", null, null));
6565

66-
Map<String, CustomThreeWtStyles> threeWtsStyles = new HashMap<>();
66+
Map<String, ThreeWtStyles> threeWtsStyles = new HashMap<>();
6767
threeWtsStyles.put("T3_12",
68-
new CustomThreeWtStyles(
68+
new ThreeWtStyles(
6969
"gray", "4px", null,
7070
"purple", "4px", "4,4",
7171
"pink", "6px", null

0 commit comments

Comments
 (0)