From d66704f7f451e680a263f8499d9c023bd59854f2 Mon Sep 17 00:00:00 2001 From: Thomas ADAM Date: Wed, 20 Apr 2022 14:55:10 +0200 Subject: [PATCH 1/4] Add precision on FeederInfo constructor with double value Signed-off-by: Thomas ADAM --- .../powsybl/sld/svg/DirectionalFeederInfo.java | 16 +++++++++++++--- .../sld/iidm/TestCase14UpToNFeederInfos.java | 6 +++--- .../resources/TestCase14UpToNFeederInfos.svg | 4 ++-- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DirectionalFeederInfo.java b/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DirectionalFeederInfo.java index 2449015d1..da5bd090b 100644 --- a/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DirectionalFeederInfo.java +++ b/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DirectionalFeederInfo.java @@ -1,5 +1,7 @@ package com.powsybl.sld.svg; +import org.apache.commons.math3.util.Precision; + import java.util.Objects; /** @@ -22,11 +24,19 @@ public DirectionalFeederInfo(String componentType, DiagramLabelProvider.LabelDir } public DirectionalFeederInfo(String componentType, double value) { - this(componentType, value, null); + this(componentType, value, 0, null); + } + + public DirectionalFeederInfo(String componentType, double value, int precision) { + this(componentType, value, precision, null); } - public DirectionalFeederInfo(String componentType, double value, String userDefinedId) { - this(componentType, value > 0 ? DiagramLabelProvider.LabelDirection.OUT : DiagramLabelProvider.LabelDirection.IN, null, String.valueOf(Math.round(value)), userDefinedId); + public DirectionalFeederInfo(String componentType, double value, int precision, String userDefinedId) { + this(componentType, + value > 0 ? DiagramLabelProvider.LabelDirection.OUT : DiagramLabelProvider.LabelDirection.IN, + null, + precision == 0 || Double.isNaN(value) ? String.valueOf(Math.round(value)) : String.valueOf(Precision.round(value, precision)), + userDefinedId); } public DiagramLabelProvider.LabelDirection getDirection() { diff --git a/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCase14UpToNFeederInfos.java b/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCase14UpToNFeederInfos.java index 7f1fe6bb6..fc1ddef2f 100644 --- a/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCase14UpToNFeederInfos.java +++ b/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCase14UpToNFeederInfos.java @@ -64,10 +64,10 @@ public void setUp() { @Override public List getFeederInfos(FeederNode node) { List feederInfos = Arrays.asList( - new DirectionalFeederInfo(ARROW_ACTIVE, LabelDirection.OUT, null, "10"), - new DirectionalFeederInfo(ARROW_REACTIVE, LabelDirection.IN, null, "20", null), + new DirectionalFeederInfo(ARROW_ACTIVE, 10.967543, 3, null), + new DirectionalFeederInfo(ARROW_REACTIVE, Double.NaN, 0, null), new DirectionalFeederInfo(ARROW_REACTIVE, LabelDirection.IN, null, "30", null), - new DirectionalFeederInfo(ARROW_ACTIVE, LabelDirection.OUT, null, "40", 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(); if (!feederArrowSymmetry) { diff --git a/single-line-diagram-core/src/test/resources/TestCase14UpToNFeederInfos.svg b/single-line-diagram-core/src/test/resources/TestCase14UpToNFeederInfos.svg index 40d6c71ed..d0904f4ca 100644 --- a/single-line-diagram-core/src/test/resources/TestCase14UpToNFeederInfos.svg +++ b/single-line-diagram-core/src/test/resources/TestCase14UpToNFeederInfos.svg @@ -100,12 +100,12 @@ - 10 + 10.968 - 20 + 0 From 56d011bede9c0df5051757cde4c51a53d2d0be29 Mon Sep 17 00:00:00 2001 From: Thomas ADAM Date: Mon, 16 May 2022 15:32:20 +0200 Subject: [PATCH 2/4] Use DecimalFormat instead of Precision Signed-off-by: Thomas ADAM --- .../sld/svg/DirectionalFeederInfo.java | 12 +- .../resources/InternalBranchesBusBreaker.svg | 48 ++++---- .../resources/InternalBranchesNodeBreaker.svg | 36 +++--- .../NodeDecoratorsBranchStatusBusBreaker.svg | 48 ++++---- .../NodeDecoratorsBranchStatusNodeBreaker.svg | 40 +++---- .../test/resources/NodeDecoratorsSwitches.svg | 36 +++--- .../TestCase11SubstationGraphHFirst.svg | 108 +++++++++--------- .../TestCase11SubstationGraphHLast.svg | 108 +++++++++--------- .../TestCase11SubstationGraphHMiddle.svg | 108 +++++++++--------- .../TestCase11SubstationGraphHNone.svg | 108 +++++++++--------- ...ase12GraphWithNodesInfosNominalVoltage.svg | 60 +++++----- ...stCase12GraphWithNodesInfosTopological.svg | 60 +++++----- .../resources/TestCase14UpToNFeederInfos.svg | 2 +- .../TestCase15GraphWithVoltageIndicator.svg | 16 +-- ...15GraphWithVoltageIndicatorTopological.svg | 16 +-- ...TestCase15GraphWithoutVoltageIndicator.svg | 16 +-- .../test/resources/TestCaseFictitiousBus.svg | 12 +- .../TestCaseFictitiousBusTopological.svg | 12 +- .../test/resources/TestSldClassSubstation.svg | 16 +-- .../src/test/resources/TestSldClassVl.svg | 8 +- .../src/test/resources/consecutive_shunts.svg | 8 +- .../src/test/resources/feederInfoTest.svg | 4 +- .../topological_style_substation.svg | 24 ++-- 23 files changed, 458 insertions(+), 448 deletions(-) diff --git a/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DirectionalFeederInfo.java b/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DirectionalFeederInfo.java index da5bd090b..cfb3c1b7b 100644 --- a/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DirectionalFeederInfo.java +++ b/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DirectionalFeederInfo.java @@ -2,6 +2,9 @@ import org.apache.commons.math3.util.Precision; +import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; +import java.util.Locale; import java.util.Objects; /** @@ -35,10 +38,17 @@ public DirectionalFeederInfo(String componentType, double value, int precision, this(componentType, value > 0 ? DiagramLabelProvider.LabelDirection.OUT : DiagramLabelProvider.LabelDirection.IN, null, - precision == 0 || Double.isNaN(value) ? String.valueOf(Math.round(value)) : String.valueOf(Precision.round(value, precision)), + format(value, precision), userDefinedId); } + private static String format(double value, int precision) { + // build pattern + String pattern = precision == 0 ? "#;#" : "#.0" + "#".repeat(precision - 1); + String formattedValue = new DecimalFormat(pattern, DecimalFormatSymbols.getInstance(Locale.ENGLISH)).format(value); + return formattedValue.replaceAll("^-(?=0(\\.0*)?$)", ""); // Avoid negative zero + } + public DiagramLabelProvider.LabelDirection getDirection() { return arrowDirection; } diff --git a/single-line-diagram-core/src/test/resources/InternalBranchesBusBreaker.svg b/single-line-diagram-core/src/test/resources/InternalBranchesBusBreaker.svg index 09fdae14e..fcc9888f2 100644 --- a/single-line-diagram-core/src/test/resources/InternalBranchesBusBreaker.svg +++ b/single-line-diagram-core/src/test/resources/InternalBranchesBusBreaker.svg @@ -158,12 +158,12 @@ - 0 + NaN - 0 + NaN @@ -191,12 +191,12 @@ - 0 + NaN - 0 + NaN @@ -224,12 +224,12 @@ - 0 + NaN - 0 + NaN @@ -257,12 +257,12 @@ - 0 + NaN - 0 + NaN @@ -290,12 +290,12 @@ - 0 + NaN - 0 + NaN @@ -303,12 +303,12 @@ - 0 + NaN - 0 + NaN @@ -344,12 +344,12 @@ - 0 + NaN - 0 + NaN @@ -377,12 +377,12 @@ - 0 + NaN - 0 + NaN @@ -410,12 +410,12 @@ - 0 + NaN - 0 + NaN @@ -445,12 +445,12 @@ - 0 + NaN - 0 + NaN @@ -478,12 +478,12 @@ - 0 + NaN - 0 + NaN @@ -491,12 +491,12 @@ - 0 + NaN - 0 + NaN diff --git a/single-line-diagram-core/src/test/resources/InternalBranchesNodeBreaker.svg b/single-line-diagram-core/src/test/resources/InternalBranchesNodeBreaker.svg index a4fa1f875..dddbe0829 100644 --- a/single-line-diagram-core/src/test/resources/InternalBranchesNodeBreaker.svg +++ b/single-line-diagram-core/src/test/resources/InternalBranchesNodeBreaker.svg @@ -149,12 +149,12 @@ - 0 + NaN - 0 + NaN @@ -190,12 +190,12 @@ - 0 + NaN - 0 + NaN @@ -231,12 +231,12 @@ - 0 + NaN - 0 + NaN @@ -313,12 +313,12 @@ - 0 + NaN - 0 + NaN @@ -326,12 +326,12 @@ - 0 + NaN - 0 + NaN @@ -375,12 +375,12 @@ - 0 + NaN - 0 + NaN @@ -416,12 +416,12 @@ - 0 + NaN - 0 + NaN @@ -541,12 +541,12 @@ - 0 + NaN - 0 + NaN @@ -554,12 +554,12 @@ - 0 + NaN - 0 + NaN diff --git a/single-line-diagram-core/src/test/resources/NodeDecoratorsBranchStatusBusBreaker.svg b/single-line-diagram-core/src/test/resources/NodeDecoratorsBranchStatusBusBreaker.svg index cd2f6f10c..3d8cdef2c 100644 --- a/single-line-diagram-core/src/test/resources/NodeDecoratorsBranchStatusBusBreaker.svg +++ b/single-line-diagram-core/src/test/resources/NodeDecoratorsBranchStatusBusBreaker.svg @@ -144,12 +144,12 @@ - 0 + NaN - 0 + NaN @@ -180,12 +180,12 @@ - 0 + NaN - 0 + NaN @@ -216,12 +216,12 @@ - 0 + NaN - 0 + NaN @@ -252,12 +252,12 @@ - 0 + NaN - 0 + NaN @@ -285,12 +285,12 @@ - 0 + NaN - 0 + NaN @@ -298,12 +298,12 @@ - 0 + NaN - 0 + NaN @@ -342,12 +342,12 @@ - 0 + NaN - 0 + NaN @@ -378,12 +378,12 @@ - 0 + NaN - 0 + NaN @@ -414,12 +414,12 @@ - 0 + NaN - 0 + NaN @@ -452,12 +452,12 @@ - 0 + NaN - 0 + NaN @@ -485,12 +485,12 @@ - 0 + NaN - 0 + NaN @@ -498,12 +498,12 @@ - 0 + NaN - 0 + NaN diff --git a/single-line-diagram-core/src/test/resources/NodeDecoratorsBranchStatusNodeBreaker.svg b/single-line-diagram-core/src/test/resources/NodeDecoratorsBranchStatusNodeBreaker.svg index 78dd95778..10dce608a 100644 --- a/single-line-diagram-core/src/test/resources/NodeDecoratorsBranchStatusNodeBreaker.svg +++ b/single-line-diagram-core/src/test/resources/NodeDecoratorsBranchStatusNodeBreaker.svg @@ -163,12 +163,12 @@ - 0 + NaN - 0 + NaN @@ -207,12 +207,12 @@ - 0 + NaN - 0 + NaN @@ -251,12 +251,12 @@ - 0 + NaN - 0 + NaN @@ -339,12 +339,12 @@ - 0 + NaN - 0 + NaN @@ -383,12 +383,12 @@ - 0 + NaN - 0 + NaN @@ -427,12 +427,12 @@ - 0 + NaN - 0 + NaN @@ -559,12 +559,12 @@ - 0 + NaN - 0 + NaN @@ -623,12 +623,12 @@ - 0 + NaN - 0 + NaN @@ -667,12 +667,12 @@ - 0 + NaN - 0 + NaN @@ -755,12 +755,12 @@ - 0 + NaN - 0 + NaN diff --git a/single-line-diagram-core/src/test/resources/NodeDecoratorsSwitches.svg b/single-line-diagram-core/src/test/resources/NodeDecoratorsSwitches.svg index d1c145019..2a0394cff 100644 --- a/single-line-diagram-core/src/test/resources/NodeDecoratorsSwitches.svg +++ b/single-line-diagram-core/src/test/resources/NodeDecoratorsSwitches.svg @@ -158,12 +158,12 @@ - 0 + NaN - 0 + NaN @@ -205,12 +205,12 @@ - 0 + NaN - 0 + NaN @@ -252,12 +252,12 @@ - 0 + NaN - 0 + NaN @@ -346,12 +346,12 @@ - 0 + NaN - 0 + NaN @@ -359,12 +359,12 @@ - 0 + NaN - 0 + NaN @@ -414,12 +414,12 @@ - 0 + NaN - 0 + NaN @@ -461,12 +461,12 @@ - 0 + NaN - 0 + NaN @@ -604,12 +604,12 @@ - 0 + NaN - 0 + NaN @@ -617,12 +617,12 @@ - 0 + NaN - 0 + NaN diff --git a/single-line-diagram-core/src/test/resources/TestCase11SubstationGraphHFirst.svg b/single-line-diagram-core/src/test/resources/TestCase11SubstationGraphHFirst.svg index 00f7364e3..5d1015449 100644 --- a/single-line-diagram-core/src/test/resources/TestCase11SubstationGraphHFirst.svg +++ b/single-line-diagram-core/src/test/resources/TestCase11SubstationGraphHFirst.svg @@ -304,12 +304,12 @@ - 0 + NaN - 0 + NaN @@ -345,12 +345,12 @@ - 0 + NaN - 0 + NaN @@ -386,12 +386,12 @@ - 0 + NaN - 0 + NaN @@ -427,12 +427,12 @@ - 0 + NaN - 0 + NaN @@ -468,12 +468,12 @@ - 0 + NaN - 0 + NaN @@ -512,12 +512,12 @@ - 0 + NaN - 0 + NaN @@ -553,12 +553,12 @@ - 0 + NaN - 0 + NaN @@ -594,12 +594,12 @@ - 0 + NaN - 0 + NaN @@ -638,12 +638,12 @@ - 0 + NaN - 0 + NaN @@ -679,12 +679,12 @@ - 0 + NaN - 0 + NaN @@ -720,12 +720,12 @@ - 0 + NaN - 0 + NaN @@ -764,12 +764,12 @@ - 0 + NaN - 0 + NaN @@ -805,12 +805,12 @@ - 0 + NaN - 0 + NaN @@ -892,12 +892,12 @@ - 0 + NaN - 0 + NaN @@ -933,12 +933,12 @@ - 0 + NaN - 0 + NaN @@ -974,12 +974,12 @@ - 0 + NaN - 0 + NaN @@ -1015,12 +1015,12 @@ - 0 + NaN - 0 + NaN @@ -1059,12 +1059,12 @@ - 0 + NaN - 0 + NaN @@ -1100,12 +1100,12 @@ - 0 + NaN - 0 + NaN @@ -1141,12 +1141,12 @@ - 0 + NaN - 0 + NaN @@ -1182,12 +1182,12 @@ - 0 + NaN - 0 + NaN @@ -1223,12 +1223,12 @@ - 0 + NaN - 0 + NaN @@ -1274,12 +1274,12 @@ - 0 + NaN - 0 + NaN @@ -1315,12 +1315,12 @@ - 0 + NaN - 0 + NaN @@ -1356,12 +1356,12 @@ - 0 + NaN - 0 + NaN @@ -1397,12 +1397,12 @@ - 0 + NaN - 0 + NaN @@ -1438,12 +1438,12 @@ - 0 + NaN - 0 + NaN diff --git a/single-line-diagram-core/src/test/resources/TestCase11SubstationGraphHLast.svg b/single-line-diagram-core/src/test/resources/TestCase11SubstationGraphHLast.svg index 475150ce5..4cc2c499c 100644 --- a/single-line-diagram-core/src/test/resources/TestCase11SubstationGraphHLast.svg +++ b/single-line-diagram-core/src/test/resources/TestCase11SubstationGraphHLast.svg @@ -304,12 +304,12 @@ - 0 + NaN - 0 + NaN @@ -345,12 +345,12 @@ - 0 + NaN - 0 + NaN @@ -386,12 +386,12 @@ - 0 + NaN - 0 + NaN @@ -427,12 +427,12 @@ - 0 + NaN - 0 + NaN @@ -468,12 +468,12 @@ - 0 + NaN - 0 + NaN @@ -512,12 +512,12 @@ - 0 + NaN - 0 + NaN @@ -553,12 +553,12 @@ - 0 + NaN - 0 + NaN @@ -594,12 +594,12 @@ - 0 + NaN - 0 + NaN @@ -638,12 +638,12 @@ - 0 + NaN - 0 + NaN @@ -679,12 +679,12 @@ - 0 + NaN - 0 + NaN @@ -720,12 +720,12 @@ - 0 + NaN - 0 + NaN @@ -764,12 +764,12 @@ - 0 + NaN - 0 + NaN @@ -805,12 +805,12 @@ - 0 + NaN - 0 + NaN @@ -892,12 +892,12 @@ - 0 + NaN - 0 + NaN @@ -933,12 +933,12 @@ - 0 + NaN - 0 + NaN @@ -974,12 +974,12 @@ - 0 + NaN - 0 + NaN @@ -1015,12 +1015,12 @@ - 0 + NaN - 0 + NaN @@ -1059,12 +1059,12 @@ - 0 + NaN - 0 + NaN @@ -1100,12 +1100,12 @@ - 0 + NaN - 0 + NaN @@ -1141,12 +1141,12 @@ - 0 + NaN - 0 + NaN @@ -1182,12 +1182,12 @@ - 0 + NaN - 0 + NaN @@ -1223,12 +1223,12 @@ - 0 + NaN - 0 + NaN @@ -1274,12 +1274,12 @@ - 0 + NaN - 0 + NaN @@ -1315,12 +1315,12 @@ - 0 + NaN - 0 + NaN @@ -1356,12 +1356,12 @@ - 0 + NaN - 0 + NaN @@ -1397,12 +1397,12 @@ - 0 + NaN - 0 + NaN @@ -1438,12 +1438,12 @@ - 0 + NaN - 0 + NaN diff --git a/single-line-diagram-core/src/test/resources/TestCase11SubstationGraphHMiddle.svg b/single-line-diagram-core/src/test/resources/TestCase11SubstationGraphHMiddle.svg index 80a92b234..8e04b4d75 100644 --- a/single-line-diagram-core/src/test/resources/TestCase11SubstationGraphHMiddle.svg +++ b/single-line-diagram-core/src/test/resources/TestCase11SubstationGraphHMiddle.svg @@ -304,12 +304,12 @@ - 0 + NaN - 0 + NaN @@ -345,12 +345,12 @@ - 0 + NaN - 0 + NaN @@ -386,12 +386,12 @@ - 0 + NaN - 0 + NaN @@ -427,12 +427,12 @@ - 0 + NaN - 0 + NaN @@ -468,12 +468,12 @@ - 0 + NaN - 0 + NaN @@ -512,12 +512,12 @@ - 0 + NaN - 0 + NaN @@ -553,12 +553,12 @@ - 0 + NaN - 0 + NaN @@ -594,12 +594,12 @@ - 0 + NaN - 0 + NaN @@ -638,12 +638,12 @@ - 0 + NaN - 0 + NaN @@ -679,12 +679,12 @@ - 0 + NaN - 0 + NaN @@ -720,12 +720,12 @@ - 0 + NaN - 0 + NaN @@ -764,12 +764,12 @@ - 0 + NaN - 0 + NaN @@ -805,12 +805,12 @@ - 0 + NaN - 0 + NaN @@ -892,12 +892,12 @@ - 0 + NaN - 0 + NaN @@ -933,12 +933,12 @@ - 0 + NaN - 0 + NaN @@ -974,12 +974,12 @@ - 0 + NaN - 0 + NaN @@ -1015,12 +1015,12 @@ - 0 + NaN - 0 + NaN @@ -1059,12 +1059,12 @@ - 0 + NaN - 0 + NaN @@ -1100,12 +1100,12 @@ - 0 + NaN - 0 + NaN @@ -1141,12 +1141,12 @@ - 0 + NaN - 0 + NaN @@ -1182,12 +1182,12 @@ - 0 + NaN - 0 + NaN @@ -1223,12 +1223,12 @@ - 0 + NaN - 0 + NaN @@ -1274,12 +1274,12 @@ - 0 + NaN - 0 + NaN @@ -1315,12 +1315,12 @@ - 0 + NaN - 0 + NaN @@ -1356,12 +1356,12 @@ - 0 + NaN - 0 + NaN @@ -1397,12 +1397,12 @@ - 0 + NaN - 0 + NaN @@ -1438,12 +1438,12 @@ - 0 + NaN - 0 + NaN diff --git a/single-line-diagram-core/src/test/resources/TestCase11SubstationGraphHNone.svg b/single-line-diagram-core/src/test/resources/TestCase11SubstationGraphHNone.svg index 00f7364e3..5d1015449 100644 --- a/single-line-diagram-core/src/test/resources/TestCase11SubstationGraphHNone.svg +++ b/single-line-diagram-core/src/test/resources/TestCase11SubstationGraphHNone.svg @@ -304,12 +304,12 @@ - 0 + NaN - 0 + NaN @@ -345,12 +345,12 @@ - 0 + NaN - 0 + NaN @@ -386,12 +386,12 @@ - 0 + NaN - 0 + NaN @@ -427,12 +427,12 @@ - 0 + NaN - 0 + NaN @@ -468,12 +468,12 @@ - 0 + NaN - 0 + NaN @@ -512,12 +512,12 @@ - 0 + NaN - 0 + NaN @@ -553,12 +553,12 @@ - 0 + NaN - 0 + NaN @@ -594,12 +594,12 @@ - 0 + NaN - 0 + NaN @@ -638,12 +638,12 @@ - 0 + NaN - 0 + NaN @@ -679,12 +679,12 @@ - 0 + NaN - 0 + NaN @@ -720,12 +720,12 @@ - 0 + NaN - 0 + NaN @@ -764,12 +764,12 @@ - 0 + NaN - 0 + NaN @@ -805,12 +805,12 @@ - 0 + NaN - 0 + NaN @@ -892,12 +892,12 @@ - 0 + NaN - 0 + NaN @@ -933,12 +933,12 @@ - 0 + NaN - 0 + NaN @@ -974,12 +974,12 @@ - 0 + NaN - 0 + NaN @@ -1015,12 +1015,12 @@ - 0 + NaN - 0 + NaN @@ -1059,12 +1059,12 @@ - 0 + NaN - 0 + NaN @@ -1100,12 +1100,12 @@ - 0 + NaN - 0 + NaN @@ -1141,12 +1141,12 @@ - 0 + NaN - 0 + NaN @@ -1182,12 +1182,12 @@ - 0 + NaN - 0 + NaN @@ -1223,12 +1223,12 @@ - 0 + NaN - 0 + NaN @@ -1274,12 +1274,12 @@ - 0 + NaN - 0 + NaN @@ -1315,12 +1315,12 @@ - 0 + NaN - 0 + NaN @@ -1356,12 +1356,12 @@ - 0 + NaN - 0 + NaN @@ -1397,12 +1397,12 @@ - 0 + NaN - 0 + NaN @@ -1438,12 +1438,12 @@ - 0 + NaN - 0 + NaN diff --git a/single-line-diagram-core/src/test/resources/TestCase12GraphWithNodesInfosNominalVoltage.svg b/single-line-diagram-core/src/test/resources/TestCase12GraphWithNodesInfosNominalVoltage.svg index fcd712cbd..07757b399 100644 --- a/single-line-diagram-core/src/test/resources/TestCase12GraphWithNodesInfosNominalVoltage.svg +++ b/single-line-diagram-core/src/test/resources/TestCase12GraphWithNodesInfosNominalVoltage.svg @@ -205,12 +205,12 @@ - 0 + NaN - 0 + NaN @@ -248,12 +248,12 @@ - 0 + NaN - 0 + NaN @@ -291,12 +291,12 @@ - 0 + NaN - 0 + NaN @@ -332,12 +332,12 @@ - 0 + NaN - 0 + NaN @@ -345,12 +345,12 @@ - 0 + NaN - 0 + NaN @@ -394,12 +394,12 @@ - 0 + NaN - 0 + NaN @@ -437,12 +437,12 @@ - 0 + NaN - 0 + NaN @@ -478,12 +478,12 @@ - 0 + NaN - 0 + NaN @@ -491,12 +491,12 @@ - 0 + NaN - 0 + NaN @@ -540,12 +540,12 @@ - 0 + NaN - 0 + NaN @@ -583,12 +583,12 @@ - 0 + NaN - 0 + NaN @@ -624,12 +624,12 @@ - 0 + NaN - 0 + NaN @@ -637,12 +637,12 @@ - 0 + NaN - 0 + NaN @@ -686,12 +686,12 @@ - 0 + NaN - 0 + NaN @@ -729,12 +729,12 @@ - 0 + NaN - 0 + NaN diff --git a/single-line-diagram-core/src/test/resources/TestCase12GraphWithNodesInfosTopological.svg b/single-line-diagram-core/src/test/resources/TestCase12GraphWithNodesInfosTopological.svg index c369fd45f..1ec8b3e76 100644 --- a/single-line-diagram-core/src/test/resources/TestCase12GraphWithNodesInfosTopological.svg +++ b/single-line-diagram-core/src/test/resources/TestCase12GraphWithNodesInfosTopological.svg @@ -269,12 +269,12 @@ - 0 + NaN - 0 + NaN @@ -312,12 +312,12 @@ - 0 + NaN - 0 + NaN @@ -355,12 +355,12 @@ - 0 + NaN - 0 + NaN @@ -396,12 +396,12 @@ - 0 + NaN - 0 + NaN @@ -409,12 +409,12 @@ - 0 + NaN - 0 + NaN @@ -458,12 +458,12 @@ - 0 + NaN - 0 + NaN @@ -501,12 +501,12 @@ - 0 + NaN - 0 + NaN @@ -542,12 +542,12 @@ - 0 + NaN - 0 + NaN @@ -555,12 +555,12 @@ - 0 + NaN - 0 + NaN @@ -604,12 +604,12 @@ - 0 + NaN - 0 + NaN @@ -647,12 +647,12 @@ - 0 + NaN - 0 + NaN @@ -688,12 +688,12 @@ - 0 + NaN - 0 + NaN @@ -701,12 +701,12 @@ - 0 + NaN - 0 + NaN @@ -750,12 +750,12 @@ - 0 + NaN - 0 + NaN @@ -793,12 +793,12 @@ - 0 + NaN - 0 + NaN diff --git a/single-line-diagram-core/src/test/resources/TestCase14UpToNFeederInfos.svg b/single-line-diagram-core/src/test/resources/TestCase14UpToNFeederInfos.svg index d0904f4ca..95c43979a 100644 --- a/single-line-diagram-core/src/test/resources/TestCase14UpToNFeederInfos.svg +++ b/single-line-diagram-core/src/test/resources/TestCase14UpToNFeederInfos.svg @@ -105,7 +105,7 @@ - 0 + NaN diff --git a/single-line-diagram-core/src/test/resources/TestCase15GraphWithVoltageIndicator.svg b/single-line-diagram-core/src/test/resources/TestCase15GraphWithVoltageIndicator.svg index 8028d7097..643bea1ba 100644 --- a/single-line-diagram-core/src/test/resources/TestCase15GraphWithVoltageIndicator.svg +++ b/single-line-diagram-core/src/test/resources/TestCase15GraphWithVoltageIndicator.svg @@ -142,12 +142,12 @@ - 0 + NaN - 0 + NaN @@ -196,12 +196,12 @@ - 0 + NaN - 0 + NaN @@ -262,12 +262,12 @@ - 0 + NaN - 0 + NaN @@ -302,12 +302,12 @@ - 0 + NaN - 0 + NaN diff --git a/single-line-diagram-core/src/test/resources/TestCase15GraphWithVoltageIndicatorTopological.svg b/single-line-diagram-core/src/test/resources/TestCase15GraphWithVoltageIndicatorTopological.svg index 31e477daa..a98182b71 100644 --- a/single-line-diagram-core/src/test/resources/TestCase15GraphWithVoltageIndicatorTopological.svg +++ b/single-line-diagram-core/src/test/resources/TestCase15GraphWithVoltageIndicatorTopological.svg @@ -232,12 +232,12 @@ - 0 + NaN - 0 + NaN @@ -286,12 +286,12 @@ - 0 + NaN - 0 + NaN @@ -352,12 +352,12 @@ - 0 + NaN - 0 + NaN @@ -392,12 +392,12 @@ - 0 + NaN - 0 + NaN diff --git a/single-line-diagram-core/src/test/resources/TestCase15GraphWithoutVoltageIndicator.svg b/single-line-diagram-core/src/test/resources/TestCase15GraphWithoutVoltageIndicator.svg index c8edb646c..93958ae22 100644 --- a/single-line-diagram-core/src/test/resources/TestCase15GraphWithoutVoltageIndicator.svg +++ b/single-line-diagram-core/src/test/resources/TestCase15GraphWithoutVoltageIndicator.svg @@ -126,12 +126,12 @@ - 0 + NaN - 0 + NaN @@ -180,12 +180,12 @@ - 0 + NaN - 0 + NaN @@ -246,12 +246,12 @@ - 0 + NaN - 0 + NaN @@ -286,12 +286,12 @@ - 0 + NaN - 0 + NaN diff --git a/single-line-diagram-core/src/test/resources/TestCaseFictitiousBus.svg b/single-line-diagram-core/src/test/resources/TestCaseFictitiousBus.svg index f598d4f9b..00a927b16 100644 --- a/single-line-diagram-core/src/test/resources/TestCaseFictitiousBus.svg +++ b/single-line-diagram-core/src/test/resources/TestCaseFictitiousBus.svg @@ -95,12 +95,12 @@ - 0 + NaN - 0 + NaN @@ -128,12 +128,12 @@ - 0 + NaN - 0 + NaN @@ -161,12 +161,12 @@ - 0 + NaN - 0 + NaN diff --git a/single-line-diagram-core/src/test/resources/TestCaseFictitiousBusTopological.svg b/single-line-diagram-core/src/test/resources/TestCaseFictitiousBusTopological.svg index 07b057794..117b49502 100644 --- a/single-line-diagram-core/src/test/resources/TestCaseFictitiousBusTopological.svg +++ b/single-line-diagram-core/src/test/resources/TestCaseFictitiousBusTopological.svg @@ -173,12 +173,12 @@ - 0 + NaN - 0 + NaN @@ -206,12 +206,12 @@ - 0 + NaN - 0 + NaN @@ -239,12 +239,12 @@ - 0 + NaN - 0 + NaN diff --git a/single-line-diagram-core/src/test/resources/TestSldClassSubstation.svg b/single-line-diagram-core/src/test/resources/TestSldClassSubstation.svg index 7bc8fe387..5ae2d2ca4 100644 --- a/single-line-diagram-core/src/test/resources/TestSldClassSubstation.svg +++ b/single-line-diagram-core/src/test/resources/TestSldClassSubstation.svg @@ -171,12 +171,12 @@ - 0 + NaN - 0 + NaN @@ -212,12 +212,12 @@ - 0 + NaN - 0 + NaN @@ -263,12 +263,12 @@ - 0 + NaN - 0 + NaN @@ -304,12 +304,12 @@ - 0 + NaN - 0 + NaN diff --git a/single-line-diagram-core/src/test/resources/TestSldClassVl.svg b/single-line-diagram-core/src/test/resources/TestSldClassVl.svg index fdacc8814..68bb1b1ea 100644 --- a/single-line-diagram-core/src/test/resources/TestSldClassVl.svg +++ b/single-line-diagram-core/src/test/resources/TestSldClassVl.svg @@ -168,12 +168,12 @@ - 0 + NaN - 0 + NaN @@ -211,12 +211,12 @@ - 0 + NaN - 0 + NaN diff --git a/single-line-diagram-core/src/test/resources/consecutive_shunts.svg b/single-line-diagram-core/src/test/resources/consecutive_shunts.svg index fb58b4940..2aad4bbae 100644 --- a/single-line-diagram-core/src/test/resources/consecutive_shunts.svg +++ b/single-line-diagram-core/src/test/resources/consecutive_shunts.svg @@ -690,7 +690,7 @@ - 0 + NaN @@ -1130,7 +1130,7 @@ - 0 + NaN @@ -1173,7 +1173,7 @@ - 0 + NaN @@ -1253,7 +1253,7 @@ - 0 + NaN diff --git a/single-line-diagram-core/src/test/resources/feederInfoTest.svg b/single-line-diagram-core/src/test/resources/feederInfoTest.svg index 94564dfb9..509db66b3 100644 --- a/single-line-diagram-core/src/test/resources/feederInfoTest.svg +++ b/single-line-diagram-core/src/test/resources/feederInfoTest.svg @@ -174,12 +174,12 @@ - 0 + NaN - 0 + NaN diff --git a/single-line-diagram-core/src/test/resources/topological_style_substation.svg b/single-line-diagram-core/src/test/resources/topological_style_substation.svg index 3682dd1fb..7b35c8e55 100644 --- a/single-line-diagram-core/src/test/resources/topological_style_substation.svg +++ b/single-line-diagram-core/src/test/resources/topological_style_substation.svg @@ -204,12 +204,12 @@ - 0 + NaN - 0 + NaN @@ -245,12 +245,12 @@ - 0 + NaN - 0 + NaN @@ -286,12 +286,12 @@ - 0 + NaN - 0 + NaN @@ -334,12 +334,12 @@ - 0 + NaN - 0 + NaN @@ -375,12 +375,12 @@ - 0 + NaN - 0 + NaN @@ -423,12 +423,12 @@ - 0 + NaN - 0 + NaN From 0eeed137fb16ed9f1a126fc267771cbec42bd4d5 Mon Sep 17 00:00:00 2001 From: Thomas ADAM Date: Mon, 16 May 2022 16:24:09 +0200 Subject: [PATCH 3/4] Add FeederInfoPrecision into LayoutParameters Signed-off-by: Thomas ADAM --- .../com/powsybl/sld/layout/LayoutParameters.java | 16 +++++++++++++++- .../sld/svg/DefaultDiagramLabelProvider.java | 12 ++++++------ .../sld/iidm/TestCase14UpToNFeederInfos.java | 7 ++++--- .../powsybl/sld/layout/LayoutParametersTest.java | 4 +++- .../TestSldClassSubstationMetadata.json | 3 ++- .../test/resources/TestSldClassVlMetadata.json | 3 ++- .../src/test/resources/substDiag_metadata.json | 3 ++- .../src/test/resources/vlDiag_metadata.json | 3 ++- 8 files changed, 36 insertions(+), 15 deletions(-) diff --git a/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/LayoutParameters.java b/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/LayoutParameters.java index 705c4631e..44147a1fa 100644 --- a/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/LayoutParameters.java +++ b/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/LayoutParameters.java @@ -86,6 +86,8 @@ public class LayoutParameters { */ private double busInfoMargin = 0.0; + private int feederInfoPrecision = 0; + @JsonIgnore private Map componentsSize; @@ -128,7 +130,8 @@ public LayoutParameters(@JsonProperty("voltageLevelPadding") Padding voltageLeve @JsonProperty("useName") boolean useName, @JsonProperty("feederInfosIntraMargin") double feederInfosIntraMargin, @JsonProperty("busInfoMargin") double busInfoMargin, - @JsonProperty("busbarsAlignment") Alignment busbarsAlignment) { + @JsonProperty("busbarsAlignment") Alignment busbarsAlignment, + @JsonProperty("feederInfoPrecision") int feederInfoPrecision) { this.diagramPadding = diagramPadding; this.voltageLevelPadding = voltageLevelPadding; this.verticalSpaceBus = verticalSpaceBus; @@ -164,6 +167,7 @@ public LayoutParameters(@JsonProperty("voltageLevelPadding") Padding voltageLeve this.feederInfosIntraMargin = feederInfosIntraMargin; this.busInfoMargin = busInfoMargin; this.busbarsAlignment = busbarsAlignment; + this.feederInfoPrecision = feederInfoPrecision; } public LayoutParameters(LayoutParameters other) { @@ -204,6 +208,7 @@ public LayoutParameters(LayoutParameters other) { feederInfosIntraMargin = other.feederInfosIntraMargin; busInfoMargin = other.busInfoMargin; busbarsAlignment = other.busbarsAlignment; + feederInfoPrecision = other.feederInfoPrecision; } public double getVerticalSpaceBus() { @@ -534,6 +539,15 @@ public LayoutParameters setBusbarsAlignment(Alignment busbarsAlignment) { return this; } + public int getFeederInfoPrecision() { + return feederInfoPrecision; + } + + public LayoutParameters setFeederInfoPrecision(int feederInfoPrecision) { + this.feederInfoPrecision = feederInfoPrecision; + return this; + } + public enum Alignment { FIRST, LAST, MIDDLE, NONE; } diff --git a/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DefaultDiagramLabelProvider.java b/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DefaultDiagramLabelProvider.java index 8099ccbd7..c29f1c3ce 100644 --- a/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DefaultDiagramLabelProvider.java +++ b/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DefaultDiagramLabelProvider.java @@ -243,19 +243,19 @@ private LabelPosition getBusLabelPosition() { private List buildFeederInfos(ThreeWindingsTransformer transformer, ThreeWindingsTransformer.Side side) { return Arrays.asList( - new DirectionalFeederInfo(ARROW_ACTIVE, transformer.getTerminal(side).getP()), - new DirectionalFeederInfo(ARROW_REACTIVE, transformer.getTerminal(side).getQ())); + new DirectionalFeederInfo(ARROW_ACTIVE, transformer.getTerminal(side).getP(), layoutParameters.getFeederInfoPrecision()), + new DirectionalFeederInfo(ARROW_REACTIVE, transformer.getTerminal(side).getQ(), layoutParameters.getFeederInfoPrecision())); } private List buildFeederInfos(Injection injection) { return Arrays.asList( - new DirectionalFeederInfo(ARROW_ACTIVE, injection.getTerminal().getP()), - new DirectionalFeederInfo(ARROW_REACTIVE, injection.getTerminal().getQ())); + new DirectionalFeederInfo(ARROW_ACTIVE, injection.getTerminal().getP(), layoutParameters.getFeederInfoPrecision()), + new DirectionalFeederInfo(ARROW_REACTIVE, injection.getTerminal().getQ(), layoutParameters.getFeederInfoPrecision())); } private List buildFeederInfos(Branch branch, Branch.Side side) { return Arrays.asList( - new DirectionalFeederInfo(ARROW_ACTIVE, branch.getTerminal(side).getP()), - new DirectionalFeederInfo(ARROW_REACTIVE, branch.getTerminal(side).getQ())); + new DirectionalFeederInfo(ARROW_ACTIVE, branch.getTerminal(side).getP(), layoutParameters.getFeederInfoPrecision()), + new DirectionalFeederInfo(ARROW_REACTIVE, branch.getTerminal(side).getQ(), layoutParameters.getFeederInfoPrecision())); } } diff --git a/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCase14UpToNFeederInfos.java b/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCase14UpToNFeederInfos.java index fc1ddef2f..d7a628de2 100644 --- a/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCase14UpToNFeederInfos.java +++ b/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCase14UpToNFeederInfos.java @@ -64,8 +64,8 @@ public void setUp() { @Override public List getFeederInfos(FeederNode node) { List feederInfos = Arrays.asList( - new DirectionalFeederInfo(ARROW_ACTIVE, 10.967543, 3, null), - new DirectionalFeederInfo(ARROW_REACTIVE, Double.NaN, 0, null), + new DirectionalFeederInfo(ARROW_ACTIVE, 10.967543, layoutParameters.getFeederInfoPrecision(), null), + new DirectionalFeederInfo(ARROW_REACTIVE, Double.NaN, layoutParameters.getFeederInfoPrecision(), null), new DirectionalFeederInfo(ARROW_REACTIVE, LabelDirection.IN, null, "30", null), new DirectionalFeederInfo(ARROW_ACTIVE, LabelDirection.OUT, null, "40", null), // Not displayed new DirectionalFeederInfo(ARROW_ACTIVE, LabelDirection.OUT, null, "50", null)); @@ -89,7 +89,8 @@ public void test() { VoltageLevelGraph g = graphBuilder.buildVoltageLevelGraph(vl.getId()); layoutParameters.setSpaceForFeederInfos(100) - .setFeederInfosIntraMargin(5); + .setFeederInfosIntraMargin(5) + .setFeederInfoPrecision(3); // Run layout voltageLevelGraphLayout(g); diff --git a/single-line-diagram-core/src/test/java/com/powsybl/sld/layout/LayoutParametersTest.java b/single-line-diagram-core/src/test/java/com/powsybl/sld/layout/LayoutParametersTest.java index aa0a0445f..50af7a50f 100644 --- a/single-line-diagram-core/src/test/java/com/powsybl/sld/layout/LayoutParametersTest.java +++ b/single-line-diagram-core/src/test/java/com/powsybl/sld/layout/LayoutParametersTest.java @@ -54,7 +54,8 @@ public void test() { .setUseName(true) .setFeederInfosIntraMargin(21) .setBusInfoMargin(22) - .setBusbarsAlignment(LayoutParameters.Alignment.LAST); + .setBusbarsAlignment(LayoutParameters.Alignment.LAST) + .setFeederInfoPrecision(12); LayoutParameters layoutParameters2 = new LayoutParameters(layoutParameters); @@ -99,5 +100,6 @@ public void test() { assertEquals(layoutParameters.getFeederInfosIntraMargin(), layoutParameters2.getFeederInfosIntraMargin(), 0); assertEquals(layoutParameters.getBusInfoMargin(), layoutParameters2.getBusInfoMargin(), 0); assertEquals(layoutParameters.getBusbarsAlignment(), layoutParameters2.getBusbarsAlignment()); + assertEquals(layoutParameters.getFeederInfoPrecision(), layoutParameters2.getFeederInfoPrecision()); } } diff --git a/single-line-diagram-core/src/test/resources/TestSldClassSubstationMetadata.json b/single-line-diagram-core/src/test/resources/TestSldClassSubstationMetadata.json index 02d9ae02e..c20317ab9 100644 --- a/single-line-diagram-core/src/test/resources/TestSldClassSubstationMetadata.json +++ b/single-line-diagram-core/src/test/resources/TestSldClassSubstationMetadata.json @@ -572,6 +572,7 @@ "useName" : false, "feederInfosIntraMargin" : 10.0, "busInfoMargin" : 0.0, - "busbarsAlignment" : "FIRST" + "busbarsAlignment" : "FIRST", + "feederInfoPrecision" : 0 } } \ No newline at end of file diff --git a/single-line-diagram-core/src/test/resources/TestSldClassVlMetadata.json b/single-line-diagram-core/src/test/resources/TestSldClassVlMetadata.json index c0b16b3b3..062cfb0e0 100644 --- a/single-line-diagram-core/src/test/resources/TestSldClassVlMetadata.json +++ b/single-line-diagram-core/src/test/resources/TestSldClassVlMetadata.json @@ -335,6 +335,7 @@ "useName" : false, "feederInfosIntraMargin" : 10.0, "busInfoMargin" : 0.0, - "busbarsAlignment" : "FIRST" + "busbarsAlignment" : "FIRST", + "feederInfoPrecision" : 0 } } \ No newline at end of file diff --git a/single-line-diagram-core/src/test/resources/substDiag_metadata.json b/single-line-diagram-core/src/test/resources/substDiag_metadata.json index f2c7e2438..58eb4ad3c 100644 --- a/single-line-diagram-core/src/test/resources/substDiag_metadata.json +++ b/single-line-diagram-core/src/test/resources/substDiag_metadata.json @@ -2926,6 +2926,7 @@ "useName" : true, "feederInfosIntraMargin" : 10.0, "busInfoMargin" : 0.0, - "busbarsAlignment" : "FIRST" + "busbarsAlignment" : "FIRST", + "feederInfoPrecision" : 0 } } \ No newline at end of file diff --git a/single-line-diagram-core/src/test/resources/vlDiag_metadata.json b/single-line-diagram-core/src/test/resources/vlDiag_metadata.json index dcacd4e35..6b76257b7 100644 --- a/single-line-diagram-core/src/test/resources/vlDiag_metadata.json +++ b/single-line-diagram-core/src/test/resources/vlDiag_metadata.json @@ -1471,6 +1471,7 @@ "useName" : true, "feederInfosIntraMargin" : 10.0, "busInfoMargin" : 0.0, - "busbarsAlignment" : "FIRST" + "busbarsAlignment" : "FIRST", + "feederInfoPrecision" : 0 } } \ No newline at end of file From 251fbe84b9f0da95513acb5e9b4f951dbf9a85f0 Mon Sep 17 00:00:00 2001 From: Thomas ADAM Date: Tue, 17 May 2022 14:15:41 +0200 Subject: [PATCH 4/4] Use DecomalFormat.setMaximumFractionDigits & keep negative zero Signed-off-by: Thomas ADAM --- .../com/powsybl/sld/svg/DirectionalFeederInfo.java | 11 +++++------ .../src/test/resources/consecutive_shunts.svg | 4 ++-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DirectionalFeederInfo.java b/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DirectionalFeederInfo.java index cfb3c1b7b..e7ad5374d 100644 --- a/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DirectionalFeederInfo.java +++ b/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DirectionalFeederInfo.java @@ -1,7 +1,5 @@ package com.powsybl.sld.svg; -import org.apache.commons.math3.util.Precision; - import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.util.Locale; @@ -43,10 +41,11 @@ public DirectionalFeederInfo(String componentType, double value, int precision, } private static String format(double value, int precision) { - // build pattern - String pattern = precision == 0 ? "#;#" : "#.0" + "#".repeat(precision - 1); - String formattedValue = new DecimalFormat(pattern, DecimalFormatSymbols.getInstance(Locale.ENGLISH)).format(value); - return formattedValue.replaceAll("^-(?=0(\\.0*)?$)", ""); // Avoid negative zero + DecimalFormat format = new DecimalFormat(); + format.setMaximumFractionDigits(precision); + // Floating representation with point + format.setDecimalFormatSymbols(DecimalFormatSymbols.getInstance(Locale.ENGLISH)); + return format.format(value); } public DiagramLabelProvider.LabelDirection getDirection() { diff --git a/single-line-diagram-core/src/test/resources/consecutive_shunts.svg b/single-line-diagram-core/src/test/resources/consecutive_shunts.svg index 2aad4bbae..7e31efda7 100644 --- a/single-line-diagram-core/src/test/resources/consecutive_shunts.svg +++ b/single-line-diagram-core/src/test/resources/consecutive_shunts.svg @@ -1168,7 +1168,7 @@ - 0 + -0 @@ -1248,7 +1248,7 @@ - 0 + -0