forked from LupusNobilis/java-org.hwo.ui
60 lines
1.1 KiB
Java
60 lines
1.1 KiB
Java
package org.hwo.ui.diagram;
|
|
|
|
import org.hwo.ui.JDiagram;
|
|
|
|
public class SimplePlotLabeler implements PlotLabeler {
|
|
|
|
private int decimals;
|
|
private String ordinateFormat;
|
|
|
|
|
|
public SimplePlotLabeler() {
|
|
this.setDecimals(2);
|
|
}
|
|
|
|
public SimplePlotLabeler(int decimals){
|
|
this.setDecimals(decimals);
|
|
}
|
|
|
|
public void setDecimals(int decimals) {
|
|
this.decimals = decimals;
|
|
this.ordinateFormat = String.format("%%.%df", decimals);
|
|
}
|
|
public int getDecimals() {
|
|
return decimals;
|
|
}
|
|
|
|
|
|
@Override
|
|
public String getOrdinateLabel(JDiagram diagram,int ordinate,Double value) {
|
|
if (value == null)
|
|
return "";
|
|
if (value.isNaN())
|
|
return "";
|
|
|
|
Double window = diagram.getScaler(ordinate).getWindow();
|
|
int digits = ((Double)Math.log10(window)).intValue();
|
|
digits -= 4;
|
|
|
|
if (digits < 0){
|
|
return String.format(
|
|
String.format("%%.%df",-digits),
|
|
value
|
|
);
|
|
} else if (digits == 0){
|
|
return String.format("%1.2f",value);
|
|
} else {
|
|
return String.format(
|
|
String.format("%%%d.2f",digits),
|
|
value
|
|
);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public String getAbzisseLabel(JDiagram diagram, Double pos) {
|
|
return String.format("%.4f", pos);
|
|
}
|
|
|
|
}
|