[Schmitzm-commits] r1205 - in trunk: doc src/schmitzm/jfree src/schmitzm/jfree/chart/style src_junit/schmitzm/jfree/feature/style

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Nov 3 00:12:24 CET 2010


Author: mojays
Date: 2010-11-03 00:12:18 +0100 (Wed, 03 Nov 2010)
New Revision: 1205

Modified:
   trunk/doc/Chart style XML structure.pdf
   trunk/src/schmitzm/jfree/JFreeChartUtil.java
   trunk/src/schmitzm/jfree/chart/style/ChartStyleXMLFactory.java
   trunk/src/schmitzm/jfree/chart/style/ScatterChartStyle.java
   trunk/src_junit/schmitzm/jfree/feature/style/FeatureChartStyleTest.java
Log:
ScatterChartStyle: new property to make the textual regression informations (in)visible
ChartStyleXMLFactory BugFix: scatter chart properties were not read correctly from XML

Modified: trunk/doc/Chart style XML structure.pdf
===================================================================
(Binary files differ)

Modified: trunk/src/schmitzm/jfree/JFreeChartUtil.java
===================================================================
--- trunk/src/schmitzm/jfree/JFreeChartUtil.java	2010-11-02 23:09:36 UTC (rev 1204)
+++ trunk/src/schmitzm/jfree/JFreeChartUtil.java	2010-11-02 23:12:18 UTC (rev 1205)
@@ -996,7 +996,7 @@
 	 */
 	public static JFreeChart createRegressionChart(XYDataset dataset,
 			String title, String xAxisTitle, String yAxisTitle,
-			boolean regressionLine) {
+			boolean regressionLine, boolean regressionInfo) {
 		if (regressionLine && !(dataset instanceof XYSeriesCollection))
 			throw new UnsupportedOperationException(
 					"Regression line can only be created for XYSeriesCollection!");
@@ -1030,7 +1030,8 @@
 								+ " "+RESOURCE.getString("regressionline"), 2);
 				if (regressionData != null) {
 					addRegressionLineToPlot(plot, regressionData, Color.blue);
-					addRegressionInfoToPlot(plot, regressionData);
+					if ( regressionInfo )
+					  addRegressionInfoToPlot(plot, regressionData);
 				}
 			} else {
 				LOGGER

Modified: trunk/src/schmitzm/jfree/chart/style/ChartStyleXMLFactory.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/style/ChartStyleXMLFactory.java	2010-11-02 23:09:36 UTC (rev 1204)
+++ trunk/src/schmitzm/jfree/chart/style/ChartStyleXMLFactory.java	2010-11-02 23:12:18 UTC (rev 1205)
@@ -200,6 +200,9 @@
 		// apply type specific properties
 		if (chartStyle instanceof BasicChartStyle)
 			applyStyleFromXML((BasicChartStyle) chartStyle, element);
+        // apply type specific properties
+        if (chartStyle instanceof ScatterChartStyle)
+            applyStyleFromXML((ScatterChartStyle) chartStyle, element);
 
 	}
 
@@ -224,7 +227,28 @@
 			chartStyle.setStacked(stacked);
 	}
 
-	/**
+    /**
+     * Applies the {@link ScatterChartStyle} properties from XML (<b>not the
+     * {@link ChartStyle} properties!)</b>) to an existing
+     * {@link ScatterChartStyle} object.
+     * 
+     * @param chartStyle
+     *            an existing chart style ({@code null} not permitted!)
+     * @param element
+     *            element to read the properties from
+     */
+    private void applyStyleFromXML(ScatterChartStyle chartStyle, Element element) {
+        // visibility of regression line
+        Boolean regrLineVisible = XMLUtil.getBooleanAttribute(element, "regrLineVisible");
+        if (regrLineVisible != null)
+            chartStyle.setRegressionLineVisible(regrLineVisible);
+        // visibility of textual regression informations
+        Boolean regrInfoVisible = XMLUtil.getBooleanAttribute(element, "regrInfoVisible");
+        if (regrInfoVisible != null)
+            chartStyle.setRegressionInfoVisible(regrInfoVisible);
+    }
+
+    /**
 	 * Reads the {@link ChartLabelStyle} properties from an XML element.
 	 * <ul>
 	 * <li>Attribute "paint": color of the label</li>
@@ -649,11 +673,14 @@
 			root.setAttribute("stacked",
 					String.valueOf(((BasicChartStyle) style).isStacked()));
 		}
-		if (style instanceof ScatterChartStyle)
+		if (style instanceof ScatterChartStyle) {
 			root.setAttribute("regrLineVisible", String
 					.valueOf(((ScatterChartStyle) style)
 							.isRegressionLineVisible()));
-
+            root.setAttribute("regrInfoVisible", String
+                .valueOf(((ScatterChartStyle) style)
+                        .isRegressionInfoVisible()));
+		}
 		return root;
 	}
 

Modified: trunk/src/schmitzm/jfree/chart/style/ScatterChartStyle.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/style/ScatterChartStyle.java	2010-11-02 23:09:36 UTC (rev 1204)
+++ trunk/src/schmitzm/jfree/chart/style/ScatterChartStyle.java	2010-11-02 23:12:18 UTC (rev 1205)
@@ -53,6 +53,11 @@
    *  data points is shown. */
   protected boolean regrLineVisible = true;
 
+  /** Stores whether textual regression informations are shown in the
+   *  plot. The property only takes effect if the regression line is
+   *  also visible! */
+  protected boolean regrInfoVisible = true;
+
   /**
    * Creates a scatter chart style (with vertical orientation) a regression line shown.
    * @param id   a (unique) ID for the style
@@ -106,6 +111,23 @@
     this.regrLineVisible = visible;
   }
   
+  /**
+   * Returns whether textual regression informations are
+   * shown in the plot. This property only takes effect if the
+   * regression line is also visible!
+   */
+  public boolean isRegressionInfoVisible() {
+    return regrInfoVisible;
+  }
+  
+  /**
+   * Sets whether textual regression informations are
+   * shown in the plot. This property only takes effect if the
+   * regression line is also visible! 
+   */
+  public void setRegressionInfoVisible(boolean visible) {
+    this.regrInfoVisible = visible;
+  }
 
   /**
    * Creates a scatter chart for the given {@link Dataset} and applies the style.
@@ -123,7 +145,7 @@
 
     // create default scatter chart
     JFreeChart chart = JFreeChartUtil.createRegressionChart(
-        (XYDataset)dataset[0], "", "", "", isRegressionLineVisible()
+        (XYDataset)dataset[0], "", "", "", isRegressionLineVisible(), isRegressionInfoVisible()
     );
     
     // apply style
@@ -152,7 +174,8 @@
       // Add regression line to plot (with default color)
       if ( regressionData != null ) {
         JFreeChartUtil.addRegressionLineToPlot(chart.getXYPlot(), regressionData, Color.blue);
-        JFreeChartUtil.addRegressionInfoToPlot(chart.getXYPlot(), regressionData);
+        if ( isRegressionInfoVisible() )
+          JFreeChartUtil.addRegressionInfoToPlot(chart.getXYPlot(), regressionData);
       }
     }
 

Modified: trunk/src_junit/schmitzm/jfree/feature/style/FeatureChartStyleTest.java
===================================================================
--- trunk/src_junit/schmitzm/jfree/feature/style/FeatureChartStyleTest.java	2010-11-02 23:09:36 UTC (rev 1204)
+++ trunk/src_junit/schmitzm/jfree/feature/style/FeatureChartStyleTest.java	2010-11-02 23:12:18 UTC (rev 1205)
@@ -474,37 +474,43 @@
 	  chartStyle.setPlotStyle(plotStyle);
 	  chartStyle.setAttributeName(0, attr1Name);
 	  chartStyle.setAttributeName(1, attr2Name);
-//	  chartStyle.getPlotStyle().setCenterOriginSymetrically(true);
-//      chartStyle.getPlotStyle().setCrosshairVisible(true);
+	  chartStyle.setRegressionInfoVisible(true);
+      chartStyle.setRegressionLineVisible(true);
+	  chartStyle.getPlotStyle().setCenterOriginSymetrically(true);
+      chartStyle.getPlotStyle().setCrosshairVisible(true);
 
 	  JFreeChart chart = chartStyle.applyToFeatureCollection(testFeatures);
 	  assertNotNull("applyToFeatureCollection lieferte null!", chart);
 	  assertTrue( chart.getPlot() instanceof XYPlot );
-	  assertTrue( chart.getXYPlot().getDataset(1) instanceof RegressionDataset );
 	  
-	  RegressionDataset regrDataset = (RegressionDataset)chart.getXYPlot().getDataset(1);
-	  double[] coeff = regrDataset.getOLSRegressionCoefficients();
-	  double   r     = regrDataset.getR();
-	  assertEquals( 0.995, r, 0.001);
-	  System.out.println( coeff[1]+"x + "+coeff[0] );
+
+	  if ( chartStyle.isRegressionLineVisible() ) {
+	    assertTrue( chart.getXYPlot().getDataset(1) instanceof RegressionDataset );
+	    RegressionDataset regrDataset = (RegressionDataset)chart.getXYPlot().getDataset(1);
+	    double[] coeff = regrDataset.getOLSRegressionCoefficients();
+	    double   r     = regrDataset.getR();
+	    assertEquals( 0.995, r, 0.001);
+	    System.out.println( coeff[1]+"x + "+coeff[0] );
+
+	    // add the intercept coefficient to the dataset an create a new
+	    // regression dataset
+	    // -> the coefficients must still be the same!
+	    // -> R must become stronger (greater)
+	    XYSeriesCollection dataset2 = (XYSeriesCollection)chart.getXYPlot().getDataset();
+	    dataset2.getSeries(0).add(0, regrDataset.getRegressionLineIntercept());
+	    
+	    RegressionDataset regrDataset2 = JFreeChartUtil.createRegressionLineDataset(dataset2, 0, "regression line 2", 2);
+	    assertTrue("R must become stronger",regrDataset.getR() < regrDataset2.getR());
+	    assertEquals(regrDataset.getRegressionLineIntercept(), regrDataset2.getRegressionLineIntercept(), 0.00000001);
+	    assertEquals(regrDataset.getRegressionLineSlope(), regrDataset2.getRegressionLineSlope(), 0.00000001);
+	  }
 	  
 	  if  ( TestingUtil.INTERACTIVE ) {
 	    SelectableChartPanel panel = new SelectableChartPanel(chart);
 	    panel.setWindowSelectionMode( WindowSelectionMode.SELECT_SET );
-        TestingUtil.testGui(panel, "scatter chart",-1);
+	    TestingUtil.testGui(panel, "scatter chart",-1);
 	  }
 	  
-	  // add the intercept coefficient to the dataset an create a new
-	  // regression dataset
-	  // -> the coefficients must still be the same!
-	  // -> R must become stronger (greater)
-	  XYSeriesCollection dataset2 = (XYSeriesCollection)chart.getXYPlot().getDataset();
-	  dataset2.getSeries(0).add(0, regrDataset.getRegressionLineIntercept());
-	  
-	  RegressionDataset regrDataset2 = JFreeChartUtil.createRegressionLineDataset(dataset2, 0, "regression line 2", 2);
-      assertTrue("R must become stronger",regrDataset.getR() < regrDataset2.getR());
-      assertEquals(regrDataset.getRegressionLineIntercept(), regrDataset2.getRegressionLineIntercept(), 0.00000001);
-      assertEquals(regrDataset.getRegressionLineSlope(), regrDataset2.getRegressionLineSlope(), 0.00000001);
 
       // Check the XML output
       assertXMLOutputAndInput(xmlFactoryFeature, chartStyle, "testScatter");



More information about the Schmitzm-commits mailing list