[Schmitzm-commits] r852 - in branches/2.0-GP14/src_junit/schmitzm: . jfree jfree/feature jfree/feature/style jfree/feature/style/testLineChartShape

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri May 21 13:34:37 CEST 2010


Author: alfonx
Date: 2010-05-21 13:34:34 +0200 (Fri, 21 May 2010)
New Revision: 852

Added:
   branches/2.0-GP14/src_junit/schmitzm/jfree/
   branches/2.0-GP14/src_junit/schmitzm/jfree/feature/
   branches/2.0-GP14/src_junit/schmitzm/jfree/feature/style/
   branches/2.0-GP14/src_junit/schmitzm/jfree/feature/style/FeatureChartStyleTest.java
   branches/2.0-GP14/src_junit/schmitzm/jfree/feature/style/testLineChartShape/
   branches/2.0-GP14/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart2.dbf
   branches/2.0-GP14/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart2.prj
   branches/2.0-GP14/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart2.qpj
   branches/2.0-GP14/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart2.shp
   branches/2.0-GP14/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart2.shx
Log:
added a bugfix for bar charts not correctly saving/loading an aggregation function 


Added: branches/2.0-GP14/src_junit/schmitzm/jfree/feature/style/FeatureChartStyleTest.java
===================================================================
--- branches/2.0-GP14/src_junit/schmitzm/jfree/feature/style/FeatureChartStyleTest.java	2010-05-21 10:49:08 UTC (rev 851)
+++ branches/2.0-GP14/src_junit/schmitzm/jfree/feature/style/FeatureChartStyleTest.java	2010-05-21 11:34:34 UTC (rev 852)
@@ -0,0 +1,293 @@
+package schmitzm.jfree.feature.style;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.awt.Color;
+import java.awt.GraphicsEnvironment;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+
+import org.apache.log4j.Logger;
+import org.geotools.feature.FeatureCollection;
+import org.geotools.filter.text.cql2.CQLException;
+import org.jfree.chart.ChartFrame;
+import org.jfree.chart.JFreeChart;
+import org.junit.Test;
+import org.opengis.feature.simple.SimpleFeature;
+import org.opengis.feature.simple.SimpleFeatureType;
+
+import schmitzm.geotools.io.GeoImportUtil;
+import schmitzm.io.IOUtil;
+import schmitzm.jfree.chart.style.ChartAxisStyle;
+import schmitzm.jfree.chart.style.ChartLabelStyle;
+import schmitzm.jfree.chart.style.ChartRendererStyle;
+import schmitzm.jfree.chart.style.ChartType;
+import schmitzm.jfree.feature.AggregationFunction;
+
+public class FeatureChartStyleTest {
+	private static Logger log = Logger.getLogger(FeatureChartStyleTest.class);
+	
+	FeatureChartStyleXMLFactory xmlFactory = new FeatureChartStyleXMLFactory();
+
+	boolean INTERACTIVE = !GraphicsEnvironment.isHeadless();
+	String resLocation = "/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart2.shp";
+	
+	@Test
+	public void saveAndLoadWeightedChart() throws IOException {
+		FeatureBasicChartStyle weightChartStyle = new FeatureBasicChartStyle(
+				"testLineChart", ChartType.BAR);
+		weightChartStyle.setAttributeName(0, "attX");
+		weightChartStyle.setAttributeName(1, "attY");
+		weightChartStyle.setAttributeAggregation(1, AggregationFunction.AVG_WEIGHTED);
+		weightChartStyle.setAttributeAggregationWeightAttributeName(1, "weight");
+	
+		
+		// In XML schreiben
+		File testFile = File.createTempFile("testWeightChart", ".xml");
+		xmlFactory.writeStyleToFile(weightChartStyle, "testWeightedhart",
+				testFile);
+		
+		System.out.println(IOUtil.readFileAsString(testFile));
+		
+		// XML wieder einlesen
+		FeatureChartStyle weightChartAusXMLgelesen = xmlFactory.readStyleFromFile(testFile);
+		assertEquals(AggregationFunction.AVG_WEIGHTED, weightChartAusXMLgelesen.getAttributeAggregation(1));
+		assertEquals("weight", weightChartAusXMLgelesen.getAttributeAggregationWeightAttributeName(1));
+
+
+		// Nochmal in XML schreiben
+		File testFile2 = File.createTempFile("testWeightChart", ".xml");
+		xmlFactory.writeStyleToFile(weightChartStyle, "testWeightedhart",
+				testFile2);
+		
+		// XML wieder einlesen
+		FeatureChartStyle weightChartAusXMLgelesen2 = xmlFactory.readStyleFromFile(testFile2);
+		assertEquals("weight", weightChartAusXMLgelesen2.getAttributeAggregationWeightAttributeName(1));
+
+		assertEquals(
+				"Nachdem das Style geschrieben, gelesen und wieder geschrieben wurde ist das XML nicht gleich!",
+				IOUtil.readFileAsString(testFile), IOUtil.readFileAsString(testFile2));
+	}
+//
+//	@Test
+//	public void testBarChart() throws IOException, InterruptedException {
+//
+//		// Testdatenshape einlesen
+//		URL resourceUrl = FeatureChartStyleTest.class.getResource(
+//						resLocation);
+//		assertNotNull(resLocation+" wurde nicht gefunden!",
+//				resourceUrl);
+//		
+//		FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = GeoImportUtil
+//				.readFeaturesFromShapeURL(resourceUrl);
+//
+//		assertNotNull("Testfeatures konnten nicht aus " + resourceUrl
+//				+ " gelesen werden", testFeatures);
+//
+//		// Daten auf korrektheit überprüfen
+//		assertEquals("Testfeatures muss 2x3 Features enthalten", 2 * 3,
+//				testFeatures.size());
+//		String groupAttribName = "kgs5"; // KreisZahl
+//		SimpleFeatureType testDatenSchema = testFeatures.getSchema();
+//		assertNotNull(testDatenSchema.getDescriptor(groupAttribName));
+//		String variablenAttribName = "dm_u3"; // Deutsche "Männer" unter 3
+//		// Jahren
+//		assertNotNull(testDatenSchema.getDescriptor(variablenAttribName));
+//		String labelAttribName = "krs_name"; // Attribute mit Label für Series
+//		assertNotNull(testDatenSchema.getDescriptor(labelAttribName));
+//		String domainAttribName = "jahr"; // Diese Variable soll auf der X-Achse
+//		// angezeigt werden
+//		assertNotNull(testDatenSchema.getDescriptor(domainAttribName));
+//
+//		ChartAxisStyle domainAxisStyle = new ChartAxisStyle("jahreszahlen",
+//				Color.red, 0., 0.);
+//		ChartAxisStyle rangeAxisStyle = new ChartAxisStyle("deut. maenner",
+//				Color.green, 0., 0.);
+//
+//		FeatureBasicChartStyle lineChartStyle = new FeatureBasicChartStyle(
+//				"testLineChart", ChartType.BAR);
+//		lineChartStyle.setAxisStyle(0, domainAxisStyle);
+//		lineChartStyle.setAxisStyle(1, rangeAxisStyle);
+//
+//		// Jahreszahlen sollen nicht als zahlen interpretiert werden
+//		lineChartStyle.setForceCategories(true);
+//
+//		lineChartStyle.setAttributeName(0, domainAttribName);
+//		lineChartStyle.setAttributeName(1, variablenAttribName);
+//
+//		lineChartStyle.setTooltips(true);
+//
+////		lineChartStyle.setSeriesAttributeName(groupAttribName);
+//
+//		assertNull("Wenn nicht explizit gesetzt wird null geliefert",
+//				lineChartStyle.getRendererStyle(0));
+//
+//		ChartRendererStyle chartRendererStyle = new ChartRendererStyle();
+//
+//		chartRendererStyle.setSeriesLegendLabel(0, new ChartLabelStyle(
+//				"test 1. label"));
+//
+//		chartRendererStyle.setSeriesPaint(0, Color.green);
+//		chartRendererStyle.setSeriesPaint(1, Color.red);
+//		chartRendererStyle.setSeriesPaint(2, Color.GRAY);
+//		lineChartStyle.setRendererStyle(0, chartRendererStyle);
+//
+//		assertEquals(3, chartRendererStyle.getSeriesCount());
+//
+//		JFreeChart lineChart = lineChartStyle
+//				.applyToFeatureCollection(testFeatures);
+//		assertNotNull("applyToFeatureCollection liefte null!", lineChart);
+//
+//		BufferedImage chartpng = lineChart.createBufferedImage(600, 400);
+//		assertNotNull("Es konnte kein PNG aus dem Chart erstellt werden!",
+//				chartpng);
+//
+//		if (INTERACTIVE) {
+//			ChartFrame chartFrame = new ChartFrame(
+//					"test line chart: sollen drei Balken sein!", lineChart);
+//			chartFrame.pack();
+//			chartFrame.setVisible(true);
+//			while (chartFrame.isVisible()) {
+//				Thread.sleep(100);
+//			}
+//		}
+//	}
+//	
+//	@Test
+//	public void testLineChart() throws IOException, CQLException, InterruptedException {
+//
+//		// Testdatenshape einlesen
+//		URL resourceUrl = FeatureChartStyleTest.class.getResource(
+//						resLocation);
+//		assertNotNull(resLocation+" wurde nicht gefunden!",
+//				resourceUrl);
+//		
+//		FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = GeoImportUtil
+//				.readFeaturesFromShapeURL(resourceUrl);
+//
+//		assertNotNull("Testfeatures konnten nicht aus " + resourceUrl
+//				+ " gelesen werden", testFeatures);
+//
+//		// Daten auf korrektheit überprüfen
+//		assertEquals("Testfeatures muss 2x3 Features enthalten", 2 * 3,
+//				testFeatures.size());
+//		String groupAttribName = "kgs5"; // KreisZahl
+//		SimpleFeatureType testDatenSchema = testFeatures.getSchema();
+//		assertNotNull(testDatenSchema.getDescriptor(groupAttribName));
+//		String variablenAttribName = "dm_u3"; // Deutsche "Männer" unter 3
+//		// Jahren
+//		assertNotNull(testDatenSchema.getDescriptor(variablenAttribName));
+//		String labelAttribName = "krs_name"; // Attribute mit Label für Series
+//		assertNotNull(testDatenSchema.getDescriptor(labelAttribName));
+//		String domainAttribName = "jahr"; // Diese Variable soll auf der X-Achse
+//		// angezeigt werden
+//		assertNotNull(testDatenSchema.getDescriptor(domainAttribName));
+//
+//		ChartAxisStyle domainAxisStyle = new ChartAxisStyle("jahreszahlen",
+//				Color.red, 0., 0.);
+//		ChartAxisStyle rangeAxisStyle = new ChartAxisStyle("deut. maenner",
+//				Color.green, 0., 0.);
+//
+//		FeatureBasicChartStyle lineChartStyle = new FeatureBasicChartStyle(
+//				"testLineChart", ChartType.LINE);
+//		lineChartStyle.setAxisStyle(0, domainAxisStyle);
+//		lineChartStyle.setAxisStyle(1, rangeAxisStyle);
+//
+//		// Jahreszahlen sollen nicht als zahlen interpretiert werden
+//		lineChartStyle.setForceCategories(true);
+//
+//		lineChartStyle.setAttributeName(0, domainAttribName);
+//		lineChartStyle.setAttributeName(1, variablenAttribName);
+//
+//		lineChartStyle.setTooltips(true);
+//
+//		lineChartStyle.setSeriesAttributeName(groupAttribName);
+//
+//		assertNull("Wenn nicht explizit gesetzt wird null geliefert",
+//				lineChartStyle.getRendererStyle(0));
+//
+//		ChartRendererStyle chartRendererStyle = new ChartRendererStyle();
+//
+////		chartRendererStyle.setSeriesLegendLabel(0, new ChartLabelStyle(
+////				"test 1. label"));
+//
+//		chartRendererStyle.setDefaultPaint(Color.blue);
+//		
+//		chartRendererStyle.setSeriesPaint(0, Color.green);
+//		chartRendererStyle.setSeriesPaint(1, Color.red);
+//		chartRendererStyle.setSeriesPaint(2, Color.GRAY);
+//		lineChartStyle.setRendererStyle(0, chartRendererStyle);
+//
+//		assertEquals(3, chartRendererStyle.getSeriesCount());
+//
+//		JFreeChart lineChart = lineChartStyle
+//				.applyToFeatureCollection(testFeatures);
+//		assertNotNull("applyToFeatureCollection liefte null!", lineChart);
+//
+//		BufferedImage chartpng = lineChart.createBufferedImage(600, 400);
+//		assertNotNull("Es konnte kein PNG aus dem Chart erstellt werden!",
+//				chartpng);
+//
+//		if (INTERACTIVE) {
+//			ChartFrame chartFrame = new ChartFrame(
+//					"test line chart: sollen drei linien sein!", lineChart);
+//			chartFrame.pack();
+//			chartFrame.setVisible(true);
+//			while (chartFrame.isVisible()) {
+//				Thread.sleep(100);
+//			}
+//		}
+//
+//		// Jetzt nur soll noch eine Line kommen:
+//		chartRendererStyle.setSeriesLegendLabel(0, null);
+//		lineChartStyle.addSeriesAttributeNoDataValue("06532");
+//		lineChartStyle.addSeriesAttributeNoDataValue("06531");
+//		lineChart = lineChartStyle.applyToFeatureCollection(testFeatures);
+//		assertNotNull("applyToFeatureCollection liefte null!", lineChart);
+//		if (INTERACTIVE) {
+//			ChartFrame chartFrame = new ChartFrame(
+//					"test line chart: soll nur line 06533 existieren!",
+//					lineChart);
+//			chartFrame.pack();
+//			chartFrame.setVisible(true);
+//			while (chartFrame.isVisible()) {
+//				Thread.sleep(100);
+//			}
+//		}
+//
+//		
+//		File testFile = File.createTempFile("testLineChart", ".xml");
+//		xmlFactory.writeStyleToFile(lineChartStyle, "testLineChart", testFile);
+//
+//		assertTrue(testFile.getAbsolutePath() + " wurde nicht geschrieben!",
+//				testFile.exists());
+//
+//		String writtenXML = IOUtil.readFileAsString(testFile);
+//		System.out.println(writtenXML);
+//		assertTrue(
+//				"<seriesAttr name=\"kgs5\" nullAliases=\"06531;06532\" /> fehlt!",
+//				writtenXML
+//						.contains("<seriesAttr name=\"kgs5\" nullAliases=\"06531;06532\" />"));
+//
+//		assertTrue("Nodatawerte wurden mehr als einmal in das XML geschrieben",
+//				writtenXML.indexOf("06531;06532") == writtenXML
+//						.lastIndexOf("06531;06532"));
+//
+//		// XML wieder einlesen
+//		FeatureChartStyle lineChartAUsXMLgelesen = xmlFactory.readStyleFromFile(testFile);
+//		
+//		// Nochmal in XML schreiben
+//		File testFile2 = File.createTempFile("testLineChart", ".xml");
+//		xmlFactory.writeStyleToFile(lineChartAUsXMLgelesen, "testLineChart",
+//				testFile2);
+//		assertEquals(
+//				"Nachdem das Style geschrieben, gelesen und wieder geschrieben wurde ist das XML nicht gleich!",
+//				writtenXML, IOUtil.readFileAsString(testFile2));
+//	}
+
+}


Property changes on: branches/2.0-GP14/src_junit/schmitzm/jfree/feature/style/FeatureChartStyleTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id URL
Name: svn:eol-style
   + native

Added: branches/2.0-GP14/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart2.dbf
===================================================================
(Binary files differ)


Property changes on: branches/2.0-GP14/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart2.dbf
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: branches/2.0-GP14/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart2.prj
===================================================================
--- branches/2.0-GP14/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart2.prj	2010-05-21 10:49:08 UTC (rev 851)
+++ branches/2.0-GP14/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart2.prj	2010-05-21 11:34:34 UTC (rev 852)
@@ -0,0 +1 @@
+GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]
\ No newline at end of file

Added: branches/2.0-GP14/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart2.qpj
===================================================================
--- branches/2.0-GP14/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart2.qpj	2010-05-21 10:49:08 UTC (rev 851)
+++ branches/2.0-GP14/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart2.qpj	2010-05-21 11:34:34 UTC (rev 852)
@@ -0,0 +1 @@
+GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9108"]],AUTHORITY["EPSG","4326"]]

Added: branches/2.0-GP14/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart2.shp
===================================================================
(Binary files differ)


Property changes on: branches/2.0-GP14/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart2.shp
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: branches/2.0-GP14/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart2.shx
===================================================================
(Binary files differ)


Property changes on: branches/2.0-GP14/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart2.shx
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream



More information about the Schmitzm-commits mailing list