Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined value symbol as a parameter (instead of an em dash constant) #483

Merged
merged 5 commits into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -54,6 +54,9 @@ public class SvgParameters {
private int angleValuePrecision = 1;
private double pstArrowHeadSize = 8;

/** em dash unicode for undefined value */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you just forgot to remove the comment

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes indeed...

private String undefinedValueSymbol = "";

public enum CssLocation {
INSERTED_IN_SVG, EXTERNAL_IMPORTED, EXTERNAL_NO_IMPORT
}
Expand Down Expand Up @@ -103,6 +106,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 +441,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 +452,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