Add axis labels to charts
authorBill Kuker <bkuker@billkuker.com>
Thu, 16 Feb 2012 01:03:52 +0000 (01:03 +0000)
committerBill Kuker <bkuker@billkuker.com>
Thu, 16 Feb 2012 01:03:52 +0000 (01:03 +0000)
gui/com/billkuker/rocketry/motorsim/fuel/AbstractFuelEditor.java
gui/com/billkuker/rocketry/motorsim/visual/BurnPanel.java
gui/com/billkuker/rocketry/motorsim/visual/Chart.java
gui/com/billkuker/rocketry/motorsim/visual/FuelPanel.java
gui/com/billkuker/rocketry/motorsim/visual/GrainPanel.java
gui/com/billkuker/rocketry/motorsim/visual/workbench/MultiMotorPressureChart.java

index 03fb5e7d0107a7590bcb004c3547847e60edb16e..9649b8b540bfffdc976896f4595a1fa8f17edc2a 100644 (file)
@@ -65,7 +65,7 @@ public abstract class AbstractFuelEditor  extends JSplitPane {
                                try {\r
                                        burnRate = new Chart<Pressure, Velocity>(\r
                                                        SI.MEGA(SI.PASCAL), SI.MILLIMETER.divide(SI.SECOND)\r
-                                                                       .asType(Velocity.class), f, "burnRate");\r
+                                                                       .asType(Velocity.class), f, "burnRate",  "Chamber Pressure", "Burn Rate");\r
                                } catch (NoSuchMethodException e) {\r
                                        throw new Error(e);\r
                                }\r
index 619944641350f28629e76a12cb911dfa6f7cd53b..bfe5a795b6b592938fe60845bba794841215db44 100644 (file)
@@ -42,21 +42,21 @@ public class BurnPanel extends JPanel {
                                        SI.SECOND,\r
                                        SI.MEGA(SI.PASCAL),\r
                                        b,\r
-                                       "pressure");\r
+                                       "pressure", "Time", "Chamber Pressure");\r
                        pressure.setDomain(burn.getData().keySet());\r
                        \r
                        thrust = new Chart<Duration, Force>(\r
                                        SI.SECOND,\r
                                        SI.NEWTON,\r
                                        b,\r
-                                       "thrust");\r
+                                       "thrust", "Time", "Thrust");\r
                        thrust.setDomain(burn.getData().keySet());\r
                        \r
                        burnRate = new Chart<Pressure, Velocity>(\r
                                        SI.MEGA(SI.PASCAL),\r
                                        SI.METERS_PER_SECOND,\r
                                        burn.getMotor().getFuel(),\r
-                                       "burnRate");\r
+                                       "burnRate", "Chamber Pressure", "Burn Rate");\r
                        burnRate.setDomain(\r
                                        burnRate.new IntervalDomain(\r
                                                        Amount.valueOf(0, SI.MEGA(SI.PASCAL)),\r
index 08f60000663ba5820ed8946da9d0db99a53d4bb8..945f5470ffecc1336df2ed2e0144f53c67a37045 100644 (file)
@@ -118,12 +118,15 @@ public class Chart<X extends Quantity, Y extends Quantity> extends JPanel implem
        Unit<X> xUnit;\r
        Unit<Y> yUnit;\r
 \r
+       String xLabel;\r
+       String yLabel;\r
+       \r
        Object source;\r
        Method f;\r
        \r
        Iterable<Amount<X>> domain;\r
-\r
-       public Chart(Unit<X> xUnit, Unit<Y> yUnit, Object source, String method)\r
+       \r
+       public Chart(Unit<X> xUnit, Unit<Y> yUnit, Object source, String method, String xLabel, String yLabel)\r
                        throws NoSuchMethodException {\r
                super(new BorderLayout());\r
                f = source.getClass().getMethod(method, Amount.class);\r
@@ -132,12 +135,22 @@ public class Chart<X extends Quantity, Y extends Quantity> extends JPanel implem
                \r
                this.xUnit = xUnit;\r
                this.yUnit = yUnit;\r
+               \r
+               this.xLabel = xLabel;\r
+               this.yLabel = yLabel;\r
 \r
                RocketScience.addUnitPreferenceListener(this);\r
                \r
                setup();\r
        }\r
        \r
+       private static String toTitle(Method f) {\r
+               String ret = f.getName().substring(0, 1).toUpperCase()\r
+                               + f.getName().substring(1);\r
+               ret = ret.replaceAll("(\\p{Ll})(\\p{Lu})", "$1 $2");\r
+               return ret;\r
+       }\r
+       \r
        private void setup(){\r
                removeAll();\r
                this.xUnit = RocketScience.UnitPreference.getUnitPreference()\r
@@ -145,11 +158,10 @@ public class Chart<X extends Quantity, Y extends Quantity> extends JPanel implem
                this.yUnit = RocketScience.UnitPreference.getUnitPreference()\r
                                .getPreferredUnit(yUnit);\r
 \r
-               chart = ChartFactory.createXYLineChart(f.getName().substring(0, 1)\r
-                               .toUpperCase()\r
-                               + f.getName().substring(1), // Title\r
-                               this.xUnit.toString(), // x-axis Label\r
-                               this.yUnit.toString(), // y-axis Label\r
+               chart = ChartFactory.createXYLineChart(\r
+                               toTitle(f), // Title\r
+                               xLabel + " (" + xUnit.toString() + ")", // x-axis Label\r
+                               yLabel + " (" + yUnit.toString() + ")", // y-axis Label\r
                                dataset, PlotOrientation.VERTICAL, // Plot Orientation\r
                                false, // Show Legend\r
                                true, // Use tool tips\r
@@ -167,9 +179,9 @@ public class Chart<X extends Quantity, Y extends Quantity> extends JPanel implem
                                                sb.append(f.getName().substring(0, 1).toUpperCase()\r
                                                                + f.getName().substring(1));\r
                                                sb.append("\n");\r
-                                               sb.append(Chart.this.xUnit.toString());\r
+                                               sb.append(Chart.this.chart.getXYPlot().getDomainAxis().getLabel());\r
                                                sb.append(",");\r
-                                               sb.append(Chart.this.yUnit.toString());\r
+                                               sb.append(Chart.this.chart.getXYPlot().getRangeAxis().getLabel());\r
                                                sb.append("\n");\r
                                                for (int i = 0; i < s.getItemCount(); i++) {\r
                                                        sb.append(s.getX(i));\r
@@ -395,7 +407,7 @@ public class Chart<X extends Quantity, Y extends Quantity> extends JPanel implem
                g.setID(Amount.valueOf(10, SI.MILLIMETER));\r
 \r
                Chart<Length, Area> c = new Chart<Length, Area>(SI.MILLIMETER,\r
-                               SI.MILLIMETER.pow(2).asType(Area.class), g, "surfaceArea");\r
+                               SI.MILLIMETER.pow(2).asType(Area.class), g, "surfaceArea", "Regression", "Area");\r
 \r
                c.setDomain(c.new IntervalDomain(Amount.valueOf(0, SI.CENTIMETER), g\r
                                .webThickness()));\r
index 2a9ca060ab3f0b3fc9c061a6f35880d8401455a8..873ee17f14db7f2556c282e1d7101a00665c6c0b 100644 (file)
@@ -20,7 +20,7 @@ public class FuelPanel extends JSplitPane {
                Chart<Pressure, Velocity> burnRate;
                try {
                        burnRate = new Chart<Pressure, Velocity>(SI.MEGA(SI.PASCAL),
-                                       SI.METERS_PER_SECOND, f, "burnRate");
+                                       SI.METERS_PER_SECOND, f, "burnRate",  "Chamber Pressure", "Burn Rate");
                } catch (NoSuchMethodException e) {
                        throw new Error(e);
                }
index 0e42dd8a6f89fe86a2bed1a12841e041edc323c3..7276a26e53bf4ab90c769dac9df20f54e372d901 100644 (file)
@@ -65,14 +65,14 @@ public class GrainPanel extends JPanel {
                                        SI.MILLIMETER,\r
                                        SI.MILLIMETER.pow(2).asType(Area.class),\r
                                        grain,\r
-                                       "surfaceArea");\r
+                                       "surfaceArea", "Regression", "Area");\r
                        area.setDomain(area.new IntervalDomain(Amount.valueOf(0, SI.MILLIMETER), grain.webThickness()));\r
                        \r
                        volume = new Chart<Length, Volume>(\r
                                        SI.MILLIMETER,\r
                                        SI.MILLIMETER.pow(3).asType(Volume.class),\r
                                        grain,\r
-                                       "volume");\r
+                                       "volume", "Regression", "Volume");\r
                        volume.setDomain(volume.new IntervalDomain(Amount.valueOf(0, SI.MILLIMETER), grain.webThickness()));\r
 \r
                        area.setMaximumSize(new Dimension(200,100));\r
index 8eeba3295c09c6aa7c60f9dfa358cd5a3b5a3be2..362b399c868d41498272102c7476e9be7d4d6fc4 100644 (file)
@@ -65,7 +65,7 @@ public class MultiMotorPressureChart extends JPanel implements BurnWatcher {
                JFreeChart chart = ChartFactory.createXYLineChart(
                                "", // Title
                                "Time (" + time.toString() + ")", // x-axis Label
-                               "Pressure (" + pressureUnit.toString() + ")", // y-axis Label
+                               "Chamber Pressure (" + pressureUnit.toString() + ")", // y-axis Label
                                dataset, PlotOrientation.VERTICAL, // Plot Orientation
                                true, // Show Legend
                                true, // Use tool tips