Skip to content

Commit

Permalink
Undefined value symbol as a parameter (instead of an em dash constant) (
Browse files Browse the repository at this point in the history
#483)

* undefined value symbol as a parameter (instead of an em dash constant) for sld and nad
* undefinedValueSymbol default value: empty string for nad, em dash for sld
* update test reference files

Signed-off-by: Sophie Frasnedo <sophie.frasnedo@rte-france.com>
  • Loading branch information
So-Fras authored Jan 27, 2023
1 parent b9e62ed commit f1056a5
Show file tree
Hide file tree
Showing 42 changed files with 2,402 additions and 2,368 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
* @author Florian Dupuy <florian.dupuy at rte-france.com>
*/
public class ValueFormatter {
/** em dash unicode for undefined value */
public static final String DASH_CHAR = "\u2014";

/** degree sign unicode for degree symbol */
private static final String DEGREE_CHAR = "\u00b0";
Expand All @@ -24,13 +22,15 @@ public class ValueFormatter {
private final int voltageValuePrecision;
private final int angleValuePrecision;
private final DecimalFormat format;
private final String undefinedValueSymbol;

public ValueFormatter(int powerValuePrecision, int voltageValuePrecision, int angleValuePrecision, Locale locale) {
public ValueFormatter(int powerValuePrecision, int voltageValuePrecision, int angleValuePrecision, Locale locale, String undefinedValueSymbol) {
this.powerValuePrecision = powerValuePrecision;
this.voltageValuePrecision = voltageValuePrecision;
this.angleValuePrecision = angleValuePrecision;
this.format = new DecimalFormat();
format.setDecimalFormatSymbols(DecimalFormatSymbols.getInstance(locale));
this.undefinedValueSymbol = undefinedValueSymbol;
}

public String formatVoltage(double voltage) {
Expand All @@ -39,7 +39,7 @@ public String formatVoltage(double voltage) {

public String formatVoltage(double voltage, String unit) {
setFractionDigits(voltageValuePrecision);
String valueFormatted = Double.isNaN(voltage) ? DASH_CHAR : format.format(voltage);
String valueFormatted = Double.isNaN(voltage) ? undefinedValueSymbol : format.format(voltage);
return valueFormatted + " " + unit;
}

Expand All @@ -49,13 +49,13 @@ public String formatPower(double power) {

public String formatPower(double power, String unit) {
setFractionDigits(powerValuePrecision);
String valueFormatted = Double.isNaN(power) ? DASH_CHAR : format.format(power);
String valueFormatted = Double.isNaN(power) ? undefinedValueSymbol : format.format(power);
return unit.isEmpty() ? valueFormatted : (valueFormatted + " " + unit);
}

public String formatAngleInDegrees(double angleInDegrees) {
setFractionDigits(angleValuePrecision);
String valueFormatted = Double.isNaN(angleInDegrees) ? DASH_CHAR : format.format(angleInDegrees);
String valueFormatted = Double.isNaN(angleInDegrees) ? undefinedValueSymbol : format.format(angleInDegrees);
return valueFormatted + DEGREE_CHAR;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class SvgParameters {
private int powerValuePrecision = 0;
private int angleValuePrecision = 1;
private double pstArrowHeadSize = 8;
private String undefinedValueSymbol = "";

public enum CssLocation {
INSERTED_IN_SVG, EXTERNAL_IMPORTED, EXTERNAL_NO_IMPORT
Expand Down Expand Up @@ -103,6 +104,7 @@ public SvgParameters(SvgParameters other) {
this.powerValuePrecision = other.powerValuePrecision;
this.angleValuePrecision = other.angleValuePrecision;
this.pstArrowHeadSize = other.pstArrowHeadSize;
this.undefinedValueSymbol = other.undefinedValueSymbol;
}

public Padding getDiagramPadding() {
Expand Down Expand Up @@ -437,7 +439,7 @@ public SvgParameters setAngleValuePrecision(int angleValuePrecision) {
}

public ValueFormatter createValueFormatter() {
return new ValueFormatter(powerValuePrecision, voltageValuePrecision, angleValuePrecision, Locale.forLanguageTag(languageTag));
return new ValueFormatter(powerValuePrecision, voltageValuePrecision, angleValuePrecision, Locale.forLanguageTag(languageTag), undefinedValueSymbol);
}

public double getPstArrowHeadSize() {
Expand All @@ -448,4 +450,13 @@ public SvgParameters setPstArrowHeadSize(double pstArrowHeadSize) {
this.pstArrowHeadSize = pstArrowHeadSize;
return this;
}

public String getUndefinedValueSymbol() {
return undefinedValueSymbol;
}

public SvgParameters setUndefinedValueSymbol(String undefinedValueSymbol) {
this.undefinedValueSymbol = undefinedValueSymbol;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public void test() {
.setVoltageValuePrecision(0)
.setAngleValuePrecision(2)
.setPowerValuePrecision(3)
.setPstArrowHeadSize(20);
.setPstArrowHeadSize(20)
.setUndefinedValueSymbol("\u002A");

SvgParameters svgParameters1 = new SvgParameters(svgParameters0);

Expand Down Expand Up @@ -98,5 +99,6 @@ public void test() {
assertEquals(svgParameters0.getAngleValuePrecision(), svgParameters1.getAngleValuePrecision());
assertEquals(svgParameters0.getPowerValuePrecision(), svgParameters1.getPowerValuePrecision());
assertEquals(svgParameters0.getPstArrowHeadSize(), svgParameters1.getPstArrowHeadSize(), 0);
assertEquals(svgParameters0.getUndefinedValueSymbol(), svgParameters1.getUndefinedValueSymbol());
}
}
12 changes: 6 additions & 6 deletions network-area-diagram/src/test/resources/3wt.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 6 additions & 6 deletions network-area-diagram/src/test/resources/3wt_disconnected.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions network-area-diagram/src/test/resources/3wt_partial.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit f1056a5

Please sign in to comment.