X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=gui%2Fcom%2Fbillkuker%2Frocketry%2Fmotorsim%2Fvisual%2FChart.java;h=945f5470ffecc1336df2ed2e0144f53c67a37045;hb=bc49119f120181946d9ab66c7b911e6fda326f08;hp=08f60000663ba5820ed8946da9d0db99a53d4bb8;hpb=a86f988b6988e421823f4454f6c68c8cc3730976;p=sw%2Fmotorsim diff --git a/gui/com/billkuker/rocketry/motorsim/visual/Chart.java b/gui/com/billkuker/rocketry/motorsim/visual/Chart.java index 08f6000..945f547 100644 --- a/gui/com/billkuker/rocketry/motorsim/visual/Chart.java +++ b/gui/com/billkuker/rocketry/motorsim/visual/Chart.java @@ -118,12 +118,15 @@ public class Chart extends JPanel implem Unit xUnit; Unit yUnit; + String xLabel; + String yLabel; + Object source; Method f; Iterable> domain; - - public Chart(Unit xUnit, Unit yUnit, Object source, String method) + + public Chart(Unit xUnit, Unit yUnit, Object source, String method, String xLabel, String yLabel) throws NoSuchMethodException { super(new BorderLayout()); f = source.getClass().getMethod(method, Amount.class); @@ -132,12 +135,22 @@ public class Chart extends JPanel implem this.xUnit = xUnit; this.yUnit = yUnit; + + this.xLabel = xLabel; + this.yLabel = yLabel; RocketScience.addUnitPreferenceListener(this); setup(); } + private static String toTitle(Method f) { + String ret = f.getName().substring(0, 1).toUpperCase() + + f.getName().substring(1); + ret = ret.replaceAll("(\\p{Ll})(\\p{Lu})", "$1 $2"); + return ret; + } + private void setup(){ removeAll(); this.xUnit = RocketScience.UnitPreference.getUnitPreference() @@ -145,11 +158,10 @@ public class Chart extends JPanel implem this.yUnit = RocketScience.UnitPreference.getUnitPreference() .getPreferredUnit(yUnit); - chart = ChartFactory.createXYLineChart(f.getName().substring(0, 1) - .toUpperCase() - + f.getName().substring(1), // Title - this.xUnit.toString(), // x-axis Label - this.yUnit.toString(), // y-axis Label + chart = ChartFactory.createXYLineChart( + toTitle(f), // Title + xLabel + " (" + xUnit.toString() + ")", // x-axis Label + yLabel + " (" + yUnit.toString() + ")", // y-axis Label dataset, PlotOrientation.VERTICAL, // Plot Orientation false, // Show Legend true, // Use tool tips @@ -167,9 +179,9 @@ public class Chart extends JPanel implem sb.append(f.getName().substring(0, 1).toUpperCase() + f.getName().substring(1)); sb.append("\n"); - sb.append(Chart.this.xUnit.toString()); + sb.append(Chart.this.chart.getXYPlot().getDomainAxis().getLabel()); sb.append(","); - sb.append(Chart.this.yUnit.toString()); + sb.append(Chart.this.chart.getXYPlot().getRangeAxis().getLabel()); sb.append("\n"); for (int i = 0; i < s.getItemCount(); i++) { sb.append(s.getX(i)); @@ -395,7 +407,7 @@ public class Chart extends JPanel implem g.setID(Amount.valueOf(10, SI.MILLIMETER)); Chart c = new Chart(SI.MILLIMETER, - SI.MILLIMETER.pow(2).asType(Area.class), g, "surfaceArea"); + SI.MILLIMETER.pow(2).asType(Area.class), g, "surfaceArea", "Regression", "Area"); c.setDomain(c.new IntervalDomain(Amount.valueOf(0, SI.CENTIMETER), g .webThickness()));