[Schmitzm-commits] r1200 - in trunk: src/schmitzm/jfree src/schmitzm/jfree/data src_junit/schmitzm/jfree/feature/style src_junit/schmitzm/swing
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Tue Nov 2 21:08:47 CET 2010
Author: mojays
Date: 2010-11-02 21:08:46 +0100 (Tue, 02 Nov 2010)
New Revision: 1200
Added:
trunk/src/schmitzm/jfree/data/
trunk/src/schmitzm/jfree/data/PipedXYDataset.java
trunk/src/schmitzm/jfree/data/RegressionDataset.java
trunk/src/schmitzm/jfree/data/RegressionDatasetImpl.java
Modified:
trunk/src/schmitzm/jfree/JFreeChartUtil.java
trunk/src_junit/schmitzm/jfree/feature/style/FeatureChartStyleTest.java
trunk/src_junit/schmitzm/swing/SwingUtilTest.java
trunk/src_junit/schmitzm/swing/TestingUtil.java
Log:
new RegressionDataset and RegressionDatasetImpl
Modified: trunk/src/schmitzm/jfree/JFreeChartUtil.java
===================================================================
--- trunk/src/schmitzm/jfree/JFreeChartUtil.java 2010-11-02 15:28:30 UTC (rev 1199)
+++ trunk/src/schmitzm/jfree/JFreeChartUtil.java 2010-11-02 20:08:46 UTC (rev 1200)
@@ -105,6 +105,8 @@
import schmitzm.jfree.chart.style.ChartStyle;
import schmitzm.jfree.chart.style.ChartStyleXMLFactory;
import schmitzm.jfree.chart.style.ChartType;
+import schmitzm.jfree.data.RegressionDataset;
+import schmitzm.jfree.data.RegressionDatasetImpl;
import schmitzm.jfree.feature.style.FeatureChartUtil;
import schmitzm.lang.LangUtil;
import schmitzm.lang.ResourceProvider;
@@ -1050,7 +1052,7 @@
* @param sampleCnt
* count of created samples
*/
- public static XYDataset createRegressionLineDataset(
+ public static RegressionDataset createRegressionLineDataset(
XYSeriesCollection dataset, int series, String seriesKey,
int sampleCount) {
@@ -1136,54 +1138,38 @@
* @param sampleCnt
* count of created samples
* @return {@code null} if the regression data could not be created (because
- * of an error
+ * of an error)
*/
- public static XYDataset createRegressionLineDataset(XYDataset dataset,
+ public static RegressionDataset createRegressionLineDataset(XYDataset dataset,
int series, String seriesKey, double startX, double endX,
int sampleCount) {
try {
- double[] coefficients = getOLSRegression(dataset, series);
-
- double r = coefficients[2];
- double rAbs = Math.abs(r);
- String negative = r < 0 ? ".neg" : "";
- String rFormatted = DecimalFormat.getInstance().format(r);
- if (rFormatted.startsWith("0"))
- rFormatted = rFormatted.substring(1);
+// double[] coefficients = getOLSRegression(dataset, series);
+// double r = coefficients[2];
+// String rFormatted = getRFormatted(r);
+// String rQuality = getRQuality(r);
+//
+// // Put additional legend informations in series key
+// // NOTE: The KECK projects parses this information!!
+// // So be aware of uncontrolled changes to this
+// // information (or its format)!!!
+// seriesKey += ", r=" + rFormatted;
+//
+// // Depending on the quality of the regression, we add a note
+// // (c) LAUX
+// seriesKey += " (" + rQuality + ")";
+//
+// Function2D curve = new LineFunction2D(coefficients[0],
+// coefficients[1]);
+//
+//// SK: Played around to make the line longer, but then the view will automatically get bigger also.. So it is probably OK the way it is
+//// return DatasetUtilities.sampleFunction2D(curve, startX-Math.abs(endX-startX)*10, endX+Math.abs(endX-startX)*10, 2,
+//// seriesKey);
+//
+// return DatasetUtilities.sampleFunction2D(curve, startX, endX, sampleCount,
+// seriesKey);
+ return RegressionDatasetImpl.create(dataset, series, seriesKey, startX, endX, sampleCount);
- if (rFormatted.startsWith("-0"))
- rFormatted = "-"+rFormatted.substring(2);
-
- seriesKey += ", r=" + rFormatted;
-
- // Depending on the quality of the regression, we add a note
- // (c) LAUX
- if (rAbs < 0.01) {
- seriesKey += " (" + RESOURCE.getString("regression.none") + ")";
- } else if (rAbs < 0.5) {
- seriesKey += " (" + RESOURCE.getString("regression.weak"+negative) + ")";
- } else if (rAbs < 0.7) {
- seriesKey += " (" + RESOURCE.getString("regression.medium"+negative)
- + ")";
- } else if (rAbs < 0.86) {
- seriesKey += " (" + RESOURCE.getString("regression.strong"+negative)
- + ")";
- } else if (rAbs < 1.) {
- seriesKey += " (" + RESOURCE.getString("regression.verystrong"+negative)
- + ")";
- } else
- seriesKey += " (" + RESOURCE.getString("regression.total"+negative) + ")";
-
- Function2D curve = new LineFunction2D(coefficients[0],
- coefficients[1]);
-
-// SK: Played around to make the line longer, but then the view will automatically get bigger also.. So it is probably OK the way it is
-// return DatasetUtilities.sampleFunction2D(curve, startX-Math.abs(endX-startX)*10, endX+Math.abs(endX-startX)*10, 2,
-// seriesKey);
-
- return DatasetUtilities.sampleFunction2D(curve, startX, endX, 2,
- seriesKey);
-
} catch (Exception err) {
// according to the data sometimes the regression
// dataset could not be created
@@ -1192,8 +1178,46 @@
return null;
}
}
+
+ /**
+ * Returns a quality representation of the R-value (e.g. weak,
+ * medium, strong, ...) according to LAUX.
+ */
+ public static String getRQuality(double r) {
+ double rAbs = Math.abs(r);
+ // Depending on the quality of the regression, we add a note
+ // (c) LAUX
+ String qualityKey = "";
+ String negativeKeySuffix = r < 0 ? ".neg" : "";
+ if (rAbs < 0.01) {
+ qualityKey = "regression.none";
+ } else if (rAbs < 0.5) {
+ qualityKey = "regression.weak"+negativeKeySuffix;
+ } else if (rAbs < 0.7) {
+ qualityKey = "regression.medium"+negativeKeySuffix;
+ } else if (rAbs < 0.86) {
+ qualityKey = "regression.strong"+negativeKeySuffix;
+ } else if (rAbs < 1.) {
+ qualityKey = "regression.verystrong"+negativeKeySuffix;
+ } else
+ qualityKey = "regression.total"+negativeKeySuffix;
+ return RESOURCE.getString(qualityKey);
+ }
+
/**
+ * Returns a formatted representation of the R-value.
+ */
+ public static String getRFormatted(double r) {
+ String rFormatted = DecimalFormat.getInstance().format(r);
+ if (rFormatted.startsWith("0"))
+ rFormatted = rFormatted.substring(1);
+ if (rFormatted.startsWith("-0"))
+ rFormatted = "-"+rFormatted.substring(2);
+ return rFormatted;
+ }
+
+ /**
* Adds a line plot for regression data to a plot.
*
* @param plot
Added: trunk/src/schmitzm/jfree/data/PipedXYDataset.java
===================================================================
--- trunk/src/schmitzm/jfree/data/PipedXYDataset.java 2010-11-02 15:28:30 UTC (rev 1199)
+++ trunk/src/schmitzm/jfree/data/PipedXYDataset.java 2010-11-02 20:08:46 UTC (rev 1200)
@@ -0,0 +1,177 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Martin O. J. Schmitz.
+ *
+ * This file is part of the SCHMITZM library - a collection of utility
+ * classes based on Java 1.6, focusing (not only) on Java Swing
+ * and the Geotools library.
+ *
+ * The SCHMITZM project is hosted at:
+ * http://wald.intevation.org/projects/schmitzm/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License (license.txt)
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * or try this link: http://www.gnu.org/licenses/lgpl.html
+ *
+ * Contributors:
+ * Martin O. J. Schmitz - initial API and implementation
+ * Stefan A. Krüger - additional utility classes
+ ******************************************************************************/
+
+package schmitzm.jfree.data;
+
+import org.jfree.data.DomainOrder;
+import org.jfree.data.general.DatasetChangeListener;
+import org.jfree.data.general.DatasetGroup;
+import org.jfree.data.xy.XYDataset;
+
+/**
+ * This class simply pipes the calls of an {@link XYDataset}.
+ * This class can be used to extend an existing {@link XYDataset}
+ * with new functionalities.
+ * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a>
+ */
+public class PipedXYDataset implements XYDataset {
+ /** Holds the original dataset */
+ protected XYDataset dataset = null;
+
+ /**
+ * Creates a new dataset.
+ * @param dataset the original data.
+ */
+ public PipedXYDataset(XYDataset dataset) {
+ this.dataset = dataset;
+ }
+
+ /**
+ * Returns the original data which is piped by this
+ * class.
+ */
+ public XYDataset getBaseDataset() {
+ return dataset;
+ }
+
+ /**
+ * Returns the series count.
+ */
+ @Override
+ public int getSeriesCount() {
+ return dataset.getSeriesCount();
+ }
+
+ /**
+ * Returns the series key of the i-th series.
+ */
+ @Override
+ public Comparable getSeriesKey(int series) {
+ return dataset.getSeriesKey(series);
+ }
+
+ /**
+ * Returns the series index for a given series key.
+ */
+ @Override
+ public int indexOf(Comparable seriesKey) {
+ return dataset.indexOf(seriesKey);
+ }
+
+ /**
+ * Adds a change listener to the dataset.
+ */
+ @Override
+ public void addChangeListener(DatasetChangeListener listener) {
+ dataset.addChangeListener(listener);
+ }
+
+ /**
+ * Removes a change listener from the dataset.
+ */
+ @Override
+ public void removeChangeListener(DatasetChangeListener listener) {
+ dataset.removeChangeListener(listener);
+ }
+
+ /**
+ * Returns the dataset group of the dataset.
+ */
+ @Override
+ public DatasetGroup getGroup() {
+ return dataset.getGroup();
+ }
+
+
+ /**
+ * Sets the dataset group of the dataset.
+ */
+ @Override
+ public void setGroup(DatasetGroup group) {
+ dataset.setGroup(group);
+ }
+
+ /**
+ * Returns the order of the domain (or X) values returned by the dataset.
+ */
+ @Override
+ public DomainOrder getDomainOrder() {
+ return dataset.getDomainOrder();
+ }
+
+ /**
+ * Returns the number of items in a series.
+ */
+ @Override
+ public int getItemCount(int series) {
+ return dataset.getItemCount(series);
+ }
+
+ /**
+ * Returns the x-value for an item within a series.
+ * @param series the series index
+ * @param item the item index within the series
+ */
+ @Override
+ public Number getX(int series, int item) {
+ return dataset.getX(series, item);
+ }
+
+ /**
+ * Returns the x-value for an item within a series.
+ * @param series the series index
+ * @param item the item index within the series
+ */
+ @Override
+ public double getXValue(int series, int item) {
+ return dataset.getXValue(series, item);
+ }
+
+ /**
+ * Returns the y-value for an item within a series.
+ * @param series the series index
+ * @param item the item index within the series
+ */
+ @Override
+ public Number getY(int series, int item) {
+ return dataset.getY(series, item);
+ }
+
+ /**
+ * Returns the y-value for an item within a series.
+ * @param series the series index
+ * @param item the item index within the series
+ */
+ @Override
+ public double getYValue(int series, int item) {
+ return dataset.getYValue(series, item);
+ }
+
+}
Added: trunk/src/schmitzm/jfree/data/RegressionDataset.java
===================================================================
--- trunk/src/schmitzm/jfree/data/RegressionDataset.java 2010-11-02 15:28:30 UTC (rev 1199)
+++ trunk/src/schmitzm/jfree/data/RegressionDataset.java 2010-11-02 20:08:46 UTC (rev 1200)
@@ -0,0 +1,84 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Martin O. J. Schmitz.
+ *
+ * This file is part of the SCHMITZM library - a collection of utility
+ * classes based on Java 1.6, focusing (not only) on Java Swing
+ * and the Geotools library.
+ *
+ * The SCHMITZM project is hosted at:
+ * http://wald.intevation.org/projects/schmitzm/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License (license.txt)
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * or try this link: http://www.gnu.org/licenses/lgpl.html
+ *
+ * Contributors:
+ * Martin O. J. Schmitz - initial API and implementation
+ * Stefan A. Krüger - additional utility classes
+ ******************************************************************************/
+
+package schmitzm.jfree.data;
+
+import org.jfree.data.function.Function2D;
+import org.jfree.data.xy.XYDataset;
+
+/**
+ * Dataset for a regression line. This class extends the
+ * {@link XYDataset} with additional informations about the
+ * regression line.
+ * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a>
+ */
+public interface RegressionDataset extends XYDataset {
+
+ /**
+ * Returns the R-value of the regression line, which is the
+ * product-moment-correlation coefficient and gives information
+ * about how strong the variables are related.
+ */
+ public double getR();
+
+ /**
+ * Returns a formatted representation of the R-value.
+ * @see #getR()
+ */
+ public String getRFormatted();
+
+ /**
+ * Returns a quality representation of the R-value (e.g. weak,
+ * medium, strong, ...).
+ * @see #getR()
+ */
+ public String getRQuality();
+
+ /**
+ * Returns the 2 regression coefficients: [0] = the intercept; [1] = the slope.
+ */
+ public double[] getOLSRegressionCoefficients();
+
+ /**
+ * Returns the slope of the regression line.
+ */
+ public double getRegressionLineSlope();
+
+ /**
+ * Returns the intercept of the regression line.
+ */
+ public double getRegressionLineIntercept();
+
+ /**
+ * Returns the regression line for the dataset.
+ */
+ public Function2D getRegressionLine();
+
+}
Added: trunk/src/schmitzm/jfree/data/RegressionDatasetImpl.java
===================================================================
--- trunk/src/schmitzm/jfree/data/RegressionDatasetImpl.java 2010-11-02 15:28:30 UTC (rev 1199)
+++ trunk/src/schmitzm/jfree/data/RegressionDatasetImpl.java 2010-11-02 20:08:46 UTC (rev 1200)
@@ -0,0 +1,162 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Martin O. J. Schmitz.
+ *
+ * This file is part of the SCHMITZM library - a collection of utility
+ * classes based on Java 1.6, focusing (not only) on Java Swing
+ * and the Geotools library.
+ *
+ * The SCHMITZM project is hosted at:
+ * http://wald.intevation.org/projects/schmitzm/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License (license.txt)
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * or try this link: http://www.gnu.org/licenses/lgpl.html
+ *
+ * Contributors:
+ * Martin O. J. Schmitz - initial API and implementation
+ * Stefan A. Krüger - additional utility classes
+ ******************************************************************************/
+
+package schmitzm.jfree.data;
+
+import java.util.Arrays;
+
+import org.jfree.data.function.Function2D;
+import org.jfree.data.function.LineFunction2D;
+import org.jfree.data.general.DatasetUtilities;
+import org.jfree.data.xy.XYDataset;
+
+import schmitzm.jfree.JFreeChartUtil;
+
+/**
+ * An implementation of {@link RegressionDataset}. Because of technical restrictions
+ * this class has only internal an constructor, so you have to create instances
+ * by calling {@link #create(XYDataset, int, String, double, double, int)}.
+ * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a>
+ */
+public class RegressionDatasetImpl extends PipedXYDataset implements RegressionDataset {
+ /** Holds the R value of the regression. */
+ protected double rValue = 0.0;
+ /** Holds the coefficients of the regression line (0 = intercept, 1 = slope). */
+ protected double[] olsCoefficients = null;
+ /** Holds the regression line. */
+ protected Function2D regrLine = null;
+
+ /**
+ * Constructs a new instance. Only the regression dateset
+ * is set by this constructor! The additional informations (R
+ * and coefficients) remains empty!!
+ * @param dataset
+ */
+ protected RegressionDatasetImpl(XYDataset dataset) {
+ super(dataset);
+ }
+
+ /**
+ * Creates a new {@link RegressionDataset}
+ * @param dataset the dataset which hold the data the regression line is calculated from
+ * @param series the series in the dataset the regression line is calculated for
+ * @param seriesKey the series key for the created dataset
+ * @param startX the first value the sample data is created for
+ * @param endX the last value the sample data is created for
+ * @param sampleCount count of created samples
+ */
+ public static RegressionDataset create(XYDataset dataset,
+ int series, String seriesKey, double startX, double endX,
+ int sampleCount) {
+
+ // (pre)calculate the parameters
+ double[] coefficients = JFreeChartUtil.getOLSRegression(dataset, series);
+ Function2D curve = new LineFunction2D(coefficients[0], coefficients[1]);
+ double r = coefficients[2];
+
+ // Put additional legend informations in series key
+ // NOTE: The KECK projects parses this information!!
+ // So be aware of uncontrolled changes to this
+ // information (or its format)!!!
+ seriesKey += ", r=" + JFreeChartUtil.getRFormatted(r);
+ seriesKey += " (" + JFreeChartUtil.getRQuality(r) + ")";
+
+ XYDataset regrData = DatasetUtilities.sampleFunction2D(
+ curve, startX, endX, sampleCount,seriesKey);
+
+ // create and initialize the regression dataset
+ RegressionDatasetImpl regrDataset = new RegressionDatasetImpl(regrData);
+ regrDataset.regrLine = curve;
+ regrDataset.olsCoefficients = new double[] {coefficients[0], coefficients[1]};
+ regrDataset.rValue = r;
+
+ return regrDataset;
+ }
+
+ /**
+ * Returns the regression line for the dataset.
+ */
+ public Function2D getRegressionLine() {
+ return regrLine;
+ }
+
+ /**
+ * Returns the R-Value of the regression line, which is the
+ * product-moment-correlation coefficient and gives information
+ * about how strong the variables are related.
+ */
+ @Override
+ public double getR() {
+ return rValue;
+ }
+
+ /**
+ * Returns the 2 regression coefficients: [0] = the intercept; [1] = the slope
+ * <b>Note</b>: Each call returns a new array instance!
+ */
+ @Override
+ public double[] getOLSRegressionCoefficients() {
+ return Arrays.copyOf(olsCoefficients,olsCoefficients.length);
+ }
+
+ /**
+ * Returns the slope of the regression line.
+ */
+ public double getRegressionLineSlope() {
+ return olsCoefficients[1];
+ }
+
+ /**
+ * Returns the intercept of the regression line.
+ */
+ public double getRegressionLineIntercept() {
+ return olsCoefficients[0];
+ }
+
+ /**
+ * Returns a formatted representation of the R-value.
+ * @see #getR()
+ * @see JFreeChartUtil#getRFormatted(double)
+ */
+ public String getRFormatted() {
+ return JFreeChartUtil.getRFormatted( getR() );
+ }
+
+ /**
+ * Returns a quality representation of the R-value (e.g. weak,
+ * medium, strong, ...).
+ * @see #getR()
+ * @see JFreeChartUtil#getRQuality(double)
+ */
+ public String getRQuality() {
+ return JFreeChartUtil.getRQuality( getR() );
+ }
+
+}
Modified: trunk/src_junit/schmitzm/jfree/feature/style/FeatureChartStyleTest.java
===================================================================
--- trunk/src_junit/schmitzm/jfree/feature/style/FeatureChartStyleTest.java 2010-11-02 15:28:30 UTC (rev 1199)
+++ trunk/src_junit/schmitzm/jfree/feature/style/FeatureChartStyleTest.java 2010-11-02 20:08:46 UTC (rev 1200)
@@ -26,8 +26,11 @@
import org.jfree.chart.axis.NumberTickUnit;
import org.jfree.chart.axis.TickUnits;
import org.jfree.chart.axis.ValueTick;
+import org.jfree.chart.plot.XYPlot;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
+import org.jfree.data.xy.XYDataset;
+import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.ui.RectangleEdge;
import org.jfree.ui.TextAnchor;
import org.junit.Ignore;
@@ -37,6 +40,8 @@
import schmitzm.io.IOUtil;
import schmitzm.jfree.JFreeChartUtil;
+import schmitzm.jfree.chart.SelectableChartPanel;
+import schmitzm.jfree.chart.SelectableChartPanel.WindowSelectionMode;
import schmitzm.jfree.chart.style.BasicChartStyle;
import schmitzm.jfree.chart.style.ChartAxisStyle;
import schmitzm.jfree.chart.style.ChartLabelStyle;
@@ -45,6 +50,8 @@
import schmitzm.jfree.chart.style.ChartStyle;
import schmitzm.jfree.chart.style.ChartStyleXMLFactory;
import schmitzm.jfree.chart.style.ChartType;
+import schmitzm.jfree.data.RegressionDataset;
+import schmitzm.jfree.data.RegressionDatasetImpl;
import schmitzm.jfree.table.AggregationFunction;
import schmitzm.swing.SwingUtil;
import schmitzm.swing.TestingUtil;
@@ -452,6 +459,63 @@
@Test
// @Ignore
+ public void testScatterChart() throws Throwable {
+
+ FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = TestingUtil.TestDatasets.kreise.getFeatureCollection();
+ SimpleFeatureType testDatenSchema = testFeatures.getSchema();
+
+ // Daten auf korrektheit überprüfen
+ String attr1Name = "dm_u3"; // Deutsche "Männer" unter 3 Jahren
+ assertNotNull(testDatenSchema.getDescriptor(attr1Name));
+ String attr2Name = "w_bev"; // Frauen Bevölkerung
+ assertNotNull(testDatenSchema.getDescriptor(attr2Name));
+
+ FeatureScatterChartStyle chartStyle = new FeatureScatterChartStyle(
+ "testScatterChart");
+ ChartPlotStyle plotStyle = new ChartPlotStyle();
+ chartStyle.setPlotStyle(plotStyle);
+ chartStyle.setPlotStyle(plotStyle);
+ chartStyle.setAttributeName(0, attr1Name);
+ chartStyle.setAttributeName(1, attr2Name);
+ 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 ( TestingUtil.INTERACTIVE ) {
+ SelectableChartPanel panel = new SelectableChartPanel(chart);
+ panel.setWindowSelectionMode( WindowSelectionMode.SELECT_SET );
+ 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");
+
+ }
+
+ @Test
+ // @Ignore
public void testBarChartDualAxis() throws Throwable {
FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = TestingUtil.TestDatasets.kreise
Modified: trunk/src_junit/schmitzm/swing/SwingUtilTest.java
===================================================================
--- trunk/src_junit/schmitzm/swing/SwingUtilTest.java 2010-11-02 15:28:30 UTC (rev 1199)
+++ trunk/src_junit/schmitzm/swing/SwingUtilTest.java 2010-11-02 20:08:46 UTC (rev 1200)
@@ -15,6 +15,7 @@
@Test
public void textExceptionDialog() {
+ ExceptionDialog.setMailDestinationAddress("test at test.com");
if ( !TestingUtil.isInteractive() )
return;
ExceptionDialog.show( new Exception("Test exception") );
Modified: trunk/src_junit/schmitzm/swing/TestingUtil.java
===================================================================
--- trunk/src_junit/schmitzm/swing/TestingUtil.java 2010-11-02 15:28:30 UTC (rev 1199)
+++ trunk/src_junit/schmitzm/swing/TestingUtil.java 2010-11-02 20:08:46 UTC (rev 1200)
@@ -45,6 +45,7 @@
import schmitzm.geotools.io.GeoImportUtil;
import schmitzm.io.IOUtil;
+import schmitzm.jfree.chart.SelectableChartPanel;
import schmitzm.lang.LangUtil;
/**
* Helpers to test Swing applications in general. <br/>
More information about the Schmitzm-commits
mailing list