From f45db5f24285f20f0df0776c65df344aba587427 Mon Sep 17 00:00:00 2001 From: Niclas Thobaben Date: Wed, 14 Feb 2018 11:10:42 +0100 Subject: [PATCH] implemented TimePlotLabeler --- src/org/hwo/ui/diagram/TimePlotLabeler.java | 50 +++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/org/hwo/ui/diagram/TimePlotLabeler.java diff --git a/src/org/hwo/ui/diagram/TimePlotLabeler.java b/src/org/hwo/ui/diagram/TimePlotLabeler.java new file mode 100644 index 0000000..f51047d --- /dev/null +++ b/src/org/hwo/ui/diagram/TimePlotLabeler.java @@ -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; + } + +}