Commit ae084aa4 authored by Nico Mack's avatar Nico Mack

Added support to dynamically omit variable units

parent f02dedd1
......@@ -177,10 +177,10 @@ public class NumericalVariable extends Variable<Double> {
// ---------------------------------------------------------------------------
private String stringify(double rawValue) {
private String stringify(double rawValue, boolean showUnit) {
StringBuilder builder = new StringBuilder(format.format(rawValue / scale));
if ((unit != null) && (unit.length() > 0)) {
if (showUnit && (unit != null) && (unit.length() > 0)) {
builder.append(" ").append(unit); //$NON-NLS-1$
}
return builder.toString();
......@@ -210,7 +210,7 @@ public class NumericalVariable extends Variable<Double> {
@Override
public String toString() {
return this.stringify(value / scale);
return this.stringify(value / scale, true);
}
// ---------------------------------------------------------------------------
......@@ -224,9 +224,9 @@ public class NumericalVariable extends Variable<Double> {
*/
// ---------------------------------------------------------------------------
public String toString(boolean capped) {
public String toString(boolean capped, boolean showUnit) {
double displayValue = (capped) ? (this.normalizedValue * this.valueRange) : this.value;
return this.stringify(displayValue / scale);
return this.stringify(displayValue / scale, showUnit);
}
// ---------------------------------------------------------------------------
......
......@@ -376,7 +376,7 @@ public class ArcGraph extends ValueCorona {
if (textFont != null) {
StringBuilder labelBuilder = new StringBuilder(this.title).append(" "); //$NON-NLS-1$
labelBuilder.append(this.variable.toString(this.cappedDisplay));
labelBuilder.append(this.variable.toString(this.cappedDisplay, true));
this.label = labelBuilder.toString();
this.labelMetrics = textFont.getLineMetrics(this.label, new FontRenderContext(null, true, true));
......
......@@ -47,7 +47,7 @@ public class SectorDisplay extends Sector implements VariableBased, InputChangeL
public SectorDisplay(BaseSectorDisplayBuilder<?> builder) {
super(builder);
this.variable = builder.variable;
this.renderLabel(this.variable.toString(false));
this.updateDisplay();
}
// ---------------------------------------------------------------------------
......@@ -70,6 +70,14 @@ public class SectorDisplay extends Sector implements VariableBased, InputChangeL
// ***************************************************************************
// ---------------------------------------------------------------------------
private void updateDisplay() {
boolean doesFit;
doesFit = this.renderLabel(this.variable.toString(false, true));
if (!doesFit) {
this.renderLabel(this.variable.toString(false, false));
}
}
// ---------------------------------------------------------------------------
// ***************************************************************************
......@@ -142,7 +150,7 @@ public class SectorDisplay extends Sector implements VariableBased, InputChangeL
/** {@inheritDoc} */
@Override
public void inputChanged(InputEvent input) {
this.renderLabel(this.variable.toString(false));
this.updateDisplay();
}
// ---------------------------------------------------------------------------
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment