Skip to content

Commit 3225435

Browse files
CBiasuzziflo-dup
authored andcommitted
CustomStyleProvider does not extend TopologicalStyleProvider anymore
Signed-off-by: Christian Biasuzzi <christian.biasuzzi@soft.it>
1 parent e8131e8 commit 3225435

5 files changed

Lines changed: 361 additions & 147 deletions

File tree

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

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
66
* SPDX-License-Identifier: MPL-2.0
77
*/
8-
package com.powsybl.nad.svg.iidm;
8+
package com.powsybl.nad.svg;
99

10-
import com.powsybl.iidm.network.Network;
1110
import com.powsybl.nad.model.BranchEdge;
1211
import com.powsybl.nad.model.BusNode;
12+
import com.powsybl.nad.model.Edge;
1313
import com.powsybl.nad.model.ThreeWtEdge;
1414

1515
import java.util.*;
@@ -19,7 +19,7 @@
1919
/**
2020
* @author Christian Biasuzzi {@literal <christian.biasuzzi at soft.it>}
2121
*/
22-
public class CustomStyleProvider extends TopologicalStyleProvider {
22+
public class CustomStyleProvider extends AbstractStyleProvider {
2323

2424
final Map<String, CustomBusNodeStyles> busNodesStyles;
2525
final Map<String, CustomEdgeStyles> edgesStyles;
@@ -39,14 +39,18 @@ public record CustomThreeWtStyles(String edge1, String width1, String dash1, Str
3939
private record CustomEdgeStyle(String stroke, String strokeWidth, String dash) {
4040
}
4141

42-
public CustomStyleProvider(Network network, Map<String, CustomBusNodeStyles> busNodesStyles, Map<String, CustomEdgeStyles> edgesStyles,
42+
public CustomStyleProvider(Map<String, CustomBusNodeStyles> busNodesStyles, Map<String, CustomEdgeStyles> edgesStyles,
4343
Map<String, CustomThreeWtStyles> threeWtsStyles) {
44-
super(network);
4544
this.busNodesStyles = Objects.requireNonNull(busNodesStyles);
4645
this.edgesStyles = Objects.requireNonNull(edgesStyles);
4746
this.threeWtsStyles = Objects.requireNonNull(threeWtsStyles);
4847
}
4948

49+
@Override
50+
public List<String> getCssFilenames() {
51+
return Collections.singletonList("customStyle.css");
52+
}
53+
5054
@Override
5155
public String getBusNodeStyle(BusNode busNode) {
5256
CustomBusNodeStyles style = busNodesStyles.get(busNode.getEquipmentId());
@@ -105,4 +109,42 @@ public String getThreeWtEdgeStyle(ThreeWtEdge threeWtEdge) {
105109
.map(styles -> formatEdgeStyle(getThreeWtStyle(styles, side)))
106110
.orElse(null);
107111
}
112+
113+
@Override
114+
public List<String> getEdgeInfoStyleClasses(EdgeInfo info) {
115+
List<String> styles = new LinkedList<>();
116+
info.getDirection().ifPresent(direction -> styles.add(
117+
CLASSES_PREFIX + (direction == EdgeInfo.Direction.OUT ? "state-out" : "state-in")));
118+
return styles;
119+
}
120+
121+
@Override
122+
protected boolean isDisconnected(ThreeWtEdge threeWtEdge) {
123+
return false;
124+
}
125+
126+
@Override
127+
protected boolean isDisconnected(BranchEdge branchEdge) {
128+
return false;
129+
}
130+
131+
@Override
132+
protected boolean isDisconnected(BranchEdge edge, BranchEdge.Side side) {
133+
return false;
134+
}
135+
136+
@Override
137+
protected Optional<String> getBaseVoltageStyle(Edge edge) {
138+
return Optional.empty();
139+
}
140+
141+
@Override
142+
protected Optional<String> getBaseVoltageStyle(BranchEdge edge, BranchEdge.Side side) {
143+
return Optional.empty();
144+
}
145+
146+
@Override
147+
protected Optional<String> getBaseVoltageStyle(ThreeWtEdge threeWtEdge) {
148+
return Optional.empty();
149+
}
108150
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.nad-branch-edges .nad-edge-path, .nad-3wt-edges .nad-edge-path {stroke: var(--nad-vl-color, grey); stroke-width: 5; fill: none}
2+
.nad-branch-edges .nad-winding, .nad-3wt-nodes .nad-winding {stroke: var(--nad-vl-color, grey); stroke-width: 5; fill: none}
3+
.nad-text-edges {stroke: black; stroke-width: 3; stroke-dasharray: 6,7}
4+
.nad-vl-nodes .nad-busnode {fill: var(--nad-vl-color, lightgrey)}
5+
.nad-vl-nodes circle.nad-unknown-busnode {stroke: var(--nad-vl-color, #808080); stroke-width: 5; stroke-dasharray: 5,5; fill: none}
6+
.nad-hvdc-edge polyline.nad-hvdc {stroke: grey; stroke-width: 40}
7+
.nad-branch-edges .nad-tie-line-edge .nad-edge-path {stroke-width: 7}
8+
.nad-pst-arrow {stroke: #6a6a6a; stroke-width: 4; stroke-linecap: round; fill: none}
9+
path.nad-arrow-out:not(.nad-state-out .nad-arrow-out) {visibility: hidden}
10+
path.nad-arrow-in:not(.nad-state-in .nad-arrow-in) {visibility: hidden}
11+
.nad-text-background {flood-color: #90a4aeaa}
12+
.nad-text-nodes {font: 25px serif; fill: black; dominant-baseline: central}
13+
.nad-text-nodes foreignObject {overflow: visible; color: black}
14+
.nad-label-box {background-color: #6c6c6c20; width: max-content; padding: 10px; border-radius: 10px;}
15+
.nad-legend-square {width: 20px; height: 20px; background: var(--nad-vl-color, lightgrey);}
16+
.nad-edge-infos text, .nad-edge-label text {font: 20px serif; dominant-baseline:middle; stroke: #FFFFFFAA; stroke-width: 10; stroke-linejoin:round; paint-order: stroke}

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

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +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.iidm.CustomStyleProvider;
14+
import com.powsybl.nad.svg.CustomStyleProvider.CustomBusNodeStyles;
15+
import com.powsybl.nad.svg.CustomStyleProvider.CustomEdgeStyles;
16+
import com.powsybl.nad.svg.CustomStyleProvider.CustomThreeWtStyles;
1517
import com.powsybl.nad.svg.iidm.DefaultLabelProvider;
1618
import org.junit.jupiter.api.BeforeEach;
1719
import org.junit.jupiter.api.Test;
@@ -44,32 +46,41 @@ protected StyleProvider getStyleProvider(Network network) {
4446
@Override
4547
protected LabelProvider getLabelProvider(Network network) {
4648
return new DefaultLabelProvider(network, getSvgParameters());
49+
4750
}
4851

4952
@Test
50-
void testCustomLabelProvider() {
53+
void testCustomStyleProvider() {
5154
Network network = Networks.createNodeBreakerNetworkWithBranchStatus("TestNodeDecorators", "test");
5255

53-
Map<String, CustomStyleProvider.CustomBusNodeStyles> busNodesStyles = new HashMap<>();
54-
busNodesStyles.put("VL1_10", new CustomStyleProvider.CustomBusNodeStyles("yellow", "blue", null));
55-
busNodesStyles.put("VL2_30", new CustomStyleProvider.CustomBusNodeStyles("red", "black", "4px"));
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"));
5659

57-
Map<String, CustomStyleProvider.CustomEdgeStyles> edgesStyles = new HashMap<>();
58-
edgesStyles.put("L11", new CustomStyleProvider.CustomEdgeStyles("blue", "2px", null, "blue", "2px", null));
59-
edgesStyles.put("L12", new CustomStyleProvider.CustomEdgeStyles("green", "4px", "8,4", "green", "4px", "8,4"));
60-
edgesStyles.put("T11", new CustomStyleProvider.CustomEdgeStyles("red", "8px", null, "brown", "8px", null));
61-
edgesStyles.put("T12", new CustomStyleProvider.CustomEdgeStyles("orange", null, null, "orange", null, null));
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));
6265

63-
Map<String, CustomStyleProvider.CustomThreeWtStyles> threeWtsStyles = new HashMap<>();
66+
Map<String, CustomThreeWtStyles> threeWtsStyles = new HashMap<>();
6467
threeWtsStyles.put("T3_12",
65-
new CustomStyleProvider.CustomThreeWtStyles(
68+
new CustomThreeWtStyles(
6669
"gray", "4px", null,
6770
"purple", "4px", "4,4",
68-
"darkgray", "4px", null
71+
"pink", "6px", null
6972
)
7073
);
7174

72-
styleProvider = new CustomStyleProvider(network, busNodesStyles, edgesStyles, threeWtsStyles);
75+
styleProvider = new CustomStyleProvider(busNodesStyles, edgesStyles, threeWtsStyles);
7376
assertSvgEquals("/custom_style_provider.svg", network);
7477
}
78+
79+
@Test
80+
void testCustomStyleProviderEmpty() {
81+
Network network = Networks.createNodeBreakerNetworkWithBranchStatus("TestNodeDecorators", "test");
82+
styleProvider = new CustomStyleProvider(new HashMap<>(), new HashMap<>(), new HashMap<>());
83+
assertSvgEquals("/custom_style_provider_empty.svg", network);
84+
}
85+
7586
}

0 commit comments

Comments
 (0)