Skip to content

Commit

Permalink
More CSS classes for discriminating text elements (#427)
Browse files Browse the repository at this point in the history
* Add unit test for formatting value
* Add specific CSS classes for discriminating text elements
* Update unit tests references

Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
  • Loading branch information
flo-dup authored Nov 15, 2022
1 parent 23183b5 commit a91e63f
Show file tree
Hide file tree
Showing 64 changed files with 1,275 additions and 1,024 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@
import com.powsybl.sld.model.coordinate.Direction;
import com.powsybl.sld.model.graphs.Graph;
import com.powsybl.sld.model.graphs.VoltageLevelGraph;
import com.powsybl.sld.model.nodes.BranchEdge;
import com.powsybl.sld.model.nodes.Edge;
import com.powsybl.sld.model.nodes.FeederNode;
import com.powsybl.sld.model.nodes.Node;
import com.powsybl.sld.model.nodes.SwitchNode;
import com.powsybl.sld.model.nodes.*;

import java.net.URL;
import java.util.*;
Expand Down Expand Up @@ -145,4 +141,19 @@ public List<String> getCellStyles(Cell cell) {
public List<String> getBusStyles(String busId, VoltageLevelGraph graph) {
return Collections.singletonList(NODE_INFOS);
}

@Override
public Optional<String> getBusInfoStyle(BusInfo info) {
return Optional.empty();
}

@Override
public List<String> getFeederInfoStyles(FeederInfo info) {
List<String> styles = new ArrayList<>();
styles.add(FEEDER_INFO);
if (info instanceof DirectionalFeederInfo) {
styles.add(((DirectionalFeederInfo) info).getDirection() == DiagramLabelProvider.LabelDirection.OUT ? OUT_CLASS : IN_CLASS);
}
return styles;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ private void drawFeederInfo(String prefixId, FeederNode feederNode, List<Point>
// we draw the feeder info
double rotationAngle = points.get(0).getY() > points.get(1).getY() ? 180 : 0;
insertFeederInfoSVGIntoDocumentSVG(feederInfo, prefixId, g, rotationAngle);
styleProvider.getFeederInfoStyle(feederInfo).ifPresent(styles::add);
styles.addAll(styleProvider.getFeederInfoStyles(feederInfo));

// we draw the right label only if present
feederInfo.getRightLabel().ifPresent(s -> {
Expand Down Expand Up @@ -1171,7 +1171,7 @@ private void drawNodeInfos(ElectricalNodeInfo nodeInfo, double xShift, double yS

labelV.setAttribute("x", String.valueOf(xShift - CIRCLE_RADIUS_NODE_INFOS_SIZE));
labelV.setAttribute("y", String.valueOf(yShift + 2.5 * CIRCLE_RADIUS_NODE_INFOS_SIZE));
labelV.setAttribute(CLASS, LABEL_STYLE_CLASS);
labelV.setAttribute(CLASS, VOLTAGE);
Text textV = g.getOwnerDocument().createTextNode(valueV);
labelV.appendChild(textV);
g.appendChild(labelV);
Expand All @@ -1183,7 +1183,7 @@ private void drawNodeInfos(ElectricalNodeInfo nodeInfo, double xShift, double yS

labelAngle.setAttribute("x", String.valueOf(xShift - CIRCLE_RADIUS_NODE_INFOS_SIZE));
labelAngle.setAttribute("y", String.valueOf(yShift + 4 * CIRCLE_RADIUS_NODE_INFOS_SIZE));
labelAngle.setAttribute(CLASS, LABEL_STYLE_CLASS);
labelAngle.setAttribute(CLASS, ANGLE);
Text textAngle = g.getOwnerDocument().createTextNode(valueAngle);
labelAngle.appendChild(textAngle);
g.appendChild(labelAngle);
Expand All @@ -1192,19 +1192,23 @@ private void drawNodeInfos(ElectricalNodeInfo nodeInfo, double xShift, double yS
private void drawNodesInfos(String prefixId, Element root, VoltageLevelGraph graph,
GraphMetadata metadata, DiagramLabelProvider initProvider, DiagramStyleProvider styleProvider) {

Element nodesInfosNode = root.getOwnerDocument().createElement(GROUP);
root.appendChild(nodesInfosNode);
nodesInfosNode.setAttribute(CLASS, LEGEND);

double xInitPos = layoutParameters.getDiagramPadding().getLeft() + CIRCLE_RADIUS_NODE_INFOS_SIZE;
double yPos = graph.getY() - layoutParameters.getVoltageLevelPadding().getTop() + graph.getHeight() + CIRCLE_RADIUS_NODE_INFOS_SIZE;

double xShift = graph.getX() + xInitPos;
for (ElectricalNodeInfo node : initProvider.getElectricalNodesInfos(graph)) {
String idNode = prefixId + "NODE_" + node.getBusId();
Element gNode = root.getOwnerDocument().createElement(GROUP);
Element gNode = nodesInfosNode.getOwnerDocument().createElement(GROUP);
gNode.setAttribute("id", idNode);

List<String> styles = styleProvider.getBusStyles(node.getBusId(), graph);
drawNodeInfos(node, xShift, yPos, gNode, idNode, styles);

root.appendChild(gNode);
nodesInfosNode.appendChild(gNode);

metadata.addElectricalNodeInfoMetadata(new GraphMetadata.ElectricalNodeInfoMetadata(idNode, node.getUserDefinedId()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
import java.util.List;
import java.util.Optional;

import static com.powsybl.sld.svg.DiagramStyles.IN_CLASS;
import static com.powsybl.sld.svg.DiagramStyles.OUT_CLASS;

/**
* @author Giovanni Ferrari <giovanni.ferrari at techrain.eu>
* @author Franck Lecuyer <franck.lecuyer at rte-france.com>
Expand All @@ -45,16 +42,9 @@ public interface DiagramStyleProvider {

List<String> getBusStyles(String busId, VoltageLevelGraph graph);

default Optional<String> getBusInfoStyle(BusInfo info) {
return Optional.empty();
}
Optional<String> getBusInfoStyle(BusInfo info);

default Optional<String> getFeederInfoStyle(FeederInfo info) {
if (info instanceof DirectionalFeederInfo) {
return Optional.of(((DirectionalFeederInfo) info).getDirection() == DiagramLabelProvider.LabelDirection.OUT ? OUT_CLASS : IN_CLASS);
}
return Optional.empty();
}
List<String> getFeederInfoStyles(FeederInfo info);

List<String> getCellStyles(Cell cell);
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public final class DiagramStyles {
public static final String INTERN_CELL = STYLE_PREFIX + "intern-cell";
public static final String SHUNT_CELL = STYLE_PREFIX + "shunt-cell";
public static final String CELL_SHAPE_PREFIX = STYLE_PREFIX + "cell-shape-";
public static final String LEGEND = STYLE_PREFIX + "legend";
public static final String VOLTAGE = STYLE_PREFIX + "voltage";
public static final String ANGLE = STYLE_PREFIX + "angle";
public static final String FEEDER_INFO = STYLE_PREFIX + "feeder-info";

private static final String ID_PREFIX = "id";

private DiagramStyles() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,17 @@
/* Stroke none & fill: --sld-vl-color */
.sld-node-infos {stroke: none; fill: var(--sld-vl-color, black)}
/* Stroke none & fill: black */
.sld-label {stroke: none; fill: black; font: 8px "Verdana"}
.sld-graph-label {stroke: none; fill: black; font: 12px "Verdana"}
.sld-node {stroke: none; fill: black}
.sld-flash {stroke: none; fill: black}
.sld-lock {stroke: none; fill: black}
/* Fonts */
.sld-label {stroke: none; fill: black; font: 8px "Verdana"}
.sld-angle, .sld-voltage {font: 10px "Verdana"}
.sld-graph-label {font: 12px "Verdana"}
/* Specific */
.sld-grid {stroke: #003700; stroke-dasharray: 1,10}
.sld-arrow-p {fill:black}
.sld-arrow-q {fill:blue}
.sld-feeder-info.sld-active-power {fill:black}
.sld-feeder-info.sld-reactive-power {fill:blue}
.sld-frame {fill: var(--sld-background-color, transparent)}
/* Stroke maroon for fictitious switch */
.sld-breaker.sld-fictitious {stroke: maroon}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@
"fileName" : "arrow-down.svg",
"styleClass" : "sld-arrow-in"
} ],
"styleClass" : "sld-arrow-p"
"styleClass" : "sld-active-power"
}, {
"type" : "ARROW_REACTIVE",
"size" : {
Expand All @@ -392,6 +392,6 @@
"fileName" : "arrow-down.svg",
"styleClass" : "sld-arrow-in"
} ],
"styleClass" : "sld-arrow-q"
"styleClass" : "sld-reactive-power"
} ]
}
4 changes: 2 additions & 2 deletions single-line-diagram-core/src/main/resources/tautologies.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
.sld-hidden-node {visibility: hidden}
.sld-top-feeder .sld-label {dominant-baseline: auto}
.sld-bottom-feeder .sld-label {dominant-baseline: hanging}
.sld-arrow-p .sld-label {dominant-baseline: middle}
.sld-arrow-q .sld-label {dominant-baseline: middle}
.sld-active-power .sld-label {dominant-baseline: middle}
.sld-reactive-power .sld-label {dominant-baseline: middle}
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@
*
* @author Thomas Adam <tadam at silicom.fr>
*/
public class TestCase14UpToNFeederInfos extends AbstractTestCaseIidm {

private DiagramLabelProvider manyFeederInfoProvider;
public class TestFeederInfos extends AbstractTestCaseIidm {

@Before
public void setUp() {
Expand All @@ -56,17 +54,29 @@ public void setUp() {
createLoad(vl, "l", "l", "l", 0, ConnectablePosition.Direction.TOP, 2, 10, 10);
createSwitch(vl, "d", "d", SwitchKind.DISCONNECTOR, false, false, false, 0, 1);
createSwitch(vl, "b", "b", SwitchKind.BREAKER, false, false, false, 1, 2);
}

@Test
public void testManyFeederInfos() {
// build graph
VoltageLevelGraph g = graphBuilder.buildVoltageLevelGraph(vl.getId());

layoutParameters.setSpaceForFeederInfos(100)
.setFeederInfosIntraMargin(5)
.setPowerValuePrecision(3);

// Run layout
voltageLevelGraphLayout(g);

// many feeder values provider example for the test :
//
manyFeederInfoProvider = new DefaultDiagramLabelProvider(network, componentLibrary, layoutParameters) {
DiagramLabelProvider manyFeederInfoProvider = new DefaultDiagramLabelProvider(network, componentLibrary, layoutParameters) {

@Override
public List<FeederInfo> getFeederInfos(FeederNode node) {
List<FeederInfo> feederInfos = Arrays.asList(
new DirectionalFeederInfo(ARROW_ACTIVE, 10.967543, valueFormatter::formatPower, null),
new DirectionalFeederInfo(ARROW_ACTIVE, 1000.967543, valueFormatter::formatPower, null),
new DirectionalFeederInfo(ARROW_REACTIVE, Double.NaN, valueFormatter::formatPower, null),
new DirectionalFeederInfo(ARROW_REACTIVE, LabelDirection.IN, null, "30", null),
new DirectionalFeederInfo(ARROW_REACTIVE, LabelDirection.IN, null, "3000", null),
new DirectionalFeederInfo(ARROW_ACTIVE, LabelDirection.OUT, null, "40", null), // Not displayed
new DirectionalFeederInfo(ARROW_ACTIVE, LabelDirection.OUT, null, "50", null));
boolean feederArrowSymmetry = node.getDirection() == Direction.TOP || layoutParameters.isFeederInfoSymmetry();
Expand All @@ -81,21 +91,25 @@ public List<DiagramLabelProvider.NodeDecorator> getNodeDecorators(Node node, Dir
return new ArrayList<>();
}
};
// write SVG and compare to reference
assertEquals(toString("/TestFeederInfos.svg"), toSVG(g, "/TestFeederInfos.svg", manyFeederInfoProvider, new BasicStyleProvider()));
}

@Test
public void test() {
public void testFrenchFormatting() {
// Add power values to the load
network.getLoad("l").getTerminal().setP(1200.29);
network.getLoad("l").getTerminal().setQ(-1);

layoutParameters.setLanguageTag("fr").setPowerValuePrecision(1);

// build graph
VoltageLevelGraph g = graphBuilder.buildVoltageLevelGraph(vl.getId());

layoutParameters.setSpaceForFeederInfos(100)
.setFeederInfosIntraMargin(5)
.setPowerValuePrecision(3);

// Run layout
voltageLevelGraphLayout(g);

// write SVG and compare to reference
assertEquals(toString("/TestCase14UpToNFeederInfos.svg"), toSVG(g, "/TestCase14UpToNFeederInfos.svg", manyFeederInfoProvider, new BasicStyleProvider()));
assertEquals(toString("/TestFormattingFeederInfos.svg"), toSVG(g, "/TestFormattingFeederInfos.svg"));
}
}
Loading

0 comments on commit a91e63f

Please sign in to comment.