altosuilib: Deal with AltosUnits API change
[fw/altos] / altosuilib / AltosUISeries.java
index 26679471a0ff39b80c24fb412464f2a62b92ed68..441eba2b33587c47790f4e21870629f06e7b6b05 100644 (file)
@@ -22,7 +22,7 @@ import java.util.ArrayList;
 
 import java.awt.*;
 import javax.swing.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 
 import org.jfree.ui.*;
 import org.jfree.chart.*;
@@ -34,6 +34,24 @@ import org.jfree.chart.labels.*;
 import org.jfree.data.xy.*;
 import org.jfree.data.*;
 
+class AltosUITime extends AltosUnits {
+       public double value(double v, boolean imperial_units) { return v; }
+
+       public double inverse(double v, boolean imperial_unis) { return v; }
+       
+       public String show_units(boolean imperial_units) { return "s"; }
+
+       public String say_units(boolean imperial_units) { return "seconds"; }
+
+       public int show_fraction(int width, boolean imperial_units) {
+               if (width < 5)
+                       return 0;
+               return width - 5;
+       }
+
+       public int say_fraction(boolean imperial_units) { return 0; }
+}
+
 public class AltosUISeries extends XYSeries implements AltosUIGrapher {
        AltosUIAxis     axis;
        String          label;
@@ -47,11 +65,12 @@ public class AltosUISeries extends XYSeries implements AltosUIGrapher {
                axis.set_units();
                StandardXYToolTipGenerator      ttg;
 
-               String  example = units.graph_format(4);
+               String  time_example = (new AltosUITime()).graph_format(7);
+               String  example = units.graph_format(7);
 
                ttg = new StandardXYToolTipGenerator(String.format("{1}s: {2}%s ({0})",
                                                                   units.show_units()),
-                                                    new java.text.DecimalFormat(example),
+                                                    new java.text.DecimalFormat(time_example),
                                                     new java.text.DecimalFormat(example));
                renderer.setBaseToolTipGenerator(ttg);
        }
@@ -65,7 +84,10 @@ public class AltosUISeries extends XYSeries implements AltosUIGrapher {
        }
 
        public void add(AltosUIDataPoint dataPoint) {
-               super.add(dataPoint.x(), dataPoint.y(fetch));
+               try {
+                       super.add(dataPoint.x(), units.value(dataPoint.y(fetch)));
+               } catch (AltosUIDataMissing dm) {
+               }
        }
 
        public AltosUISeries (String label, int fetch, AltosUnits units, Color color,
@@ -82,18 +104,7 @@ public class AltosUISeries extends XYSeries implements AltosUIGrapher {
 
                renderer = new XYLineAndShapeRenderer(true, false);
                renderer.setSeriesPaint(0, color);
+               renderer.setSeriesVisible(0, enable);
                set_units();
        }
-
-       public AltosUISeries (String label, int fetch, AltosUnits units, Color color, boolean enable) {
-               this(label, fetch, units, color,
-                    enable,
-                    new AltosUIAxis(label, units, color));
-       }
-
-       public AltosUISeries (String label, int fetch, AltosUnits units, Color color) {
-               this(label, fetch, units, color,
-                    true,
-                    new AltosUIAxis(label, units, color));
-       }
 }