forked from LupusNobilis/java-org.hwo.ui
implemented TimePlotLabeler
parent
7e95a9d4f0
commit
f45db5f242
|
@ -0,0 +1,50 @@
|
||||||
|
package org.hwo.ui.diagram;
|
||||||
|
|
||||||
|
import org.hwo.ui.JDiagram;
|
||||||
|
|
||||||
|
public class TimePlotLabeler implements PlotLabeler{
|
||||||
|
|
||||||
|
@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) {
|
||||||
|
//pos == seconds
|
||||||
|
int hour, minute, second, millisecond;
|
||||||
|
hour = (int)(pos / 3600);
|
||||||
|
minute = ((int)(pos / 60) % 60);
|
||||||
|
second = (int)Math.round(pos) % 60;
|
||||||
|
millisecond = (int)(pos * 1000) % 1000;
|
||||||
|
String sh, sm, ss, sms;
|
||||||
|
sh = hour < 10? String.format("0%d", hour) : String.format("%d", hour);
|
||||||
|
sm = minute < 10? String.format("0%d", minute) : String.format("%d", minute);
|
||||||
|
ss = second < 10? String.format("0%d", second) : String.format("%d", second);
|
||||||
|
sms = millisecond < 10? String.format("0%d", millisecond) : String.format("%d", millisecond);
|
||||||
|
|
||||||
|
return sh + ":" + sm + ":" + ss + "." + sms;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue