2016-04-28 16:29:16 +02:00
|
|
|
package org.hwo.ui.diagram;
|
|
|
|
|
2016-04-29 02:38:55 +02:00
|
|
|
import org.hwo.ui.JDiagram;
|
|
|
|
|
2016-04-28 16:29:16 +02:00
|
|
|
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
|
2016-06-08 23:05:45 +02:00
|
|
|
public String getOrdinateLabel(JDiagram diagram,int ordinate,Double value) {
|
2016-04-28 16:29:16 +02:00
|
|
|
if (value == null)
|
|
|
|
return "";
|
|
|
|
if (value.isNaN())
|
2016-06-08 23:05:45 +02:00
|
|
|
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
|
|
|
|
);
|
2016-11-17 16:35:01 +01:00
|
|
|
} else if (digits == 0){
|
|
|
|
return String.format("%1.2f",value);
|
2016-11-21 16:08:52 +01:00
|
|
|
} else {
|
2016-06-08 23:05:45 +02:00
|
|
|
return String.format(
|
2016-10-28 10:47:14 +02:00
|
|
|
String.format("%%%d.2f",digits),
|
2016-06-08 23:05:45 +02:00
|
|
|
value
|
2016-10-28 10:47:14 +02:00
|
|
|
);
|
2016-06-08 23:05:45 +02:00
|
|
|
}
|
2016-04-28 16:29:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-04-29 02:38:55 +02:00
|
|
|
public String getAbzisseLabel(JDiagram diagram, Double pos) {
|
|
|
|
return String.format("%.4f", pos);
|
2016-04-28 16:29:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|