[Schmitzm-commits] r870 - in trunk/src_junit/schmitzm/jfree/feature/style: . testLineChartShape
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Fri May 28 14:07:15 CEST 2010
Author: alfonx
Date: 2010-05-28 14:07:14 +0200 (Fri, 28 May 2010)
New Revision: 870
Added:
trunk/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart.dbf
trunk/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart.prj
trunk/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart.shp
trunk/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart.shx
Removed:
trunk/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart2.dbf
trunk/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart2.prj
trunk/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart2.qpj
trunk/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart2.shp
trunk/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart2.shx
Modified:
trunk/src_junit/schmitzm/jfree/feature/style/FeatureChartStyleTest.java
Log:
updated tests
Modified: trunk/src_junit/schmitzm/jfree/feature/style/FeatureChartStyleTest.java
===================================================================
--- trunk/src_junit/schmitzm/jfree/feature/style/FeatureChartStyleTest.java 2010-05-28 11:32:53 UTC (rev 869)
+++ trunk/src_junit/schmitzm/jfree/feature/style/FeatureChartStyleTest.java 2010-05-28 12:07:14 UTC (rev 870)
@@ -6,17 +6,30 @@
import static org.junit.Assert.assertTrue;
import java.awt.Color;
+import java.awt.Graphics2D;
import java.awt.GraphicsEnvironment;
+import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URL;
+import java.text.NumberFormat;
+import java.util.ArrayList;
+import java.util.List;
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.jfree.chart.axis.AxisState;
+import org.jfree.chart.axis.NumberAxis;
+import org.jfree.chart.axis.NumberTick;
+import org.jfree.chart.axis.NumberTickUnit;
+import org.jfree.chart.axis.TickUnits;
+import org.jfree.chart.axis.ValueTick;
+import org.jfree.ui.RectangleEdge;
+import org.jfree.ui.TextAnchor;
import org.junit.Test;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
@@ -34,9 +47,11 @@
FeatureChartStyleXMLFactory xmlFactory = new FeatureChartStyleXMLFactory();
+ /** If tests are run on a system with head, we may theoretically open dialgs, frames etc. **/
+
boolean INTERACTIVE = !GraphicsEnvironment.isHeadless();
- String resLocation = "/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart2.shp";
+ String resLocation = "/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart.shp";
@Test
public void saveAndLoadWeightedChart() throws IOException {
@@ -59,8 +74,8 @@
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",
@@ -76,7 +91,7 @@
}
@Test
- public void testBarChart() throws IOException, InterruptedException {
+ public void testBarChartForcedCategories() throws IOException, InterruptedException {
// Testdatenshape einlesen
URL resourceUrl = FeatureChartStyleTest.class.getResource(
@@ -91,15 +106,15 @@
+ " gelesen werden", testFeatures);
// Daten auf korrektheit überprüfen
- assertEquals("Testfeatures muss 2x3 Features enthalten", 2 * 3,
+ assertEquals("Testfeatures muss 3x3 Features enthalten", 3 * 3,
testFeatures.size());
- String groupAttribName = "kgs5"; // KreisZahl
+ String groupAttribName = "code"; // 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
+ String labelAttribName = "title"; // Attribute mit Label für Series
assertNotNull(testDatenSchema.getDescriptor(labelAttribName));
String domainAttribName = "jahr"; // Diese Variable soll auf der X-Achse
// angezeigt werden
@@ -150,7 +165,7 @@
if (INTERACTIVE) {
ChartFrame chartFrame = new ChartFrame(
- "test line chart: sollen drei Balken sein!", lineChart);
+ "Drei Balken sein, forcedCategory", lineChart);
chartFrame.pack();
chartFrame.setVisible(true);
while (chartFrame.isVisible()) {
@@ -160,7 +175,7 @@
}
@Test
- public void testLineChart() throws IOException, CQLException, InterruptedException {
+ public void testLineChartAsCategories() throws IOException, CQLException, InterruptedException {
// Testdatenshape einlesen
URL resourceUrl = FeatureChartStyleTest.class.getResource(
@@ -175,15 +190,13 @@
+ " gelesen werden", testFeatures);
// Daten auf korrektheit überprüfen
- assertEquals("Testfeatures muss 2x3 Features enthalten", 2 * 3,
- testFeatures.size());
- String groupAttribName = "kgs5"; // KreisZahl
+ String groupAttribName = "code"; // 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
+ String labelAttribName = "title"; // Attribute mit Label für Series
assertNotNull(testDatenSchema.getDescriptor(labelAttribName));
String domainAttribName = "jahr"; // Diese Variable soll auf der X-Achse
// angezeigt werden
@@ -236,7 +249,7 @@
if (INTERACTIVE) {
ChartFrame chartFrame = new ChartFrame(
- "test line chart: sollen drei linien sein!", lineChart);
+ "drei linien, forcedCategories", lineChart);
chartFrame.pack();
chartFrame.setVisible(true);
while (chartFrame.isVisible()) {
@@ -271,9 +284,9 @@
String writtenXML = IOUtil.readFileAsString(testFile);
System.out.println(writtenXML);
assertTrue(
- "<seriesAttr name=\"kgs5\" nullAliases=\"06531;06532\" /> fehlt!",
+ "<seriesAttr name=\"code\" nullAliases=\"06531;06532\" /> fehlt!",
writtenXML
- .contains("<seriesAttr name=\"kgs5\" nullAliases=\"06531;06532\" />"));
+ .contains("<seriesAttr name=\"code\" nullAliases=\"06531;06532\" />"));
assertTrue("Nodatawerte wurden mehr als einmal in das XML geschrieben",
writtenXML.indexOf("06531;06532") == writtenXML
@@ -291,4 +304,142 @@
writtenXML, IOUtil.readFileAsString(testFile2));
}
+
+
+
+
+ @Test
+ public void testLineChartNOTCategories() 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
+ String groupAttribName = "code"; // 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 = "title"; // 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);
+
+ 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.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);
+
+ lineChart.getXYPlot().getDomainAxis().setAutoTickUnitSelection(false);
+ TickUnits units = new TickUnits();
+ NumberFormat myNumberFormat = NumberFormat.getNumberInstance();
+ units.add(new NumberTickUnit(2005, myNumberFormat));
+ units.add(new NumberTickUnit(2007, myNumberFormat));
+ units.add(new NumberTickUnit(2008, myNumberFormat));
+// da = lineChart.getXYPlot().getDomainAxis();
+ NumberAxis numberAxis = new NumberAxis() {
+ @Override
+ public List refreshTicks(Graphics2D g2, AxisState state,
+ Rectangle2D dataArea, RectangleEdge edge) {
+
+ List<ValueTick> ticks = new ArrayList<ValueTick>();
+ TextAnchor ra = TextAnchor.CENTER;
+ TextAnchor ta = TextAnchor.CENTER;
+ ticks.add(new NumberTick(2005, "2005", ta, ra, 0.));
+ ticks.add(new NumberTick(2006, "2006", ta, ra, 0.));
+ ticks.add(new NumberTick(2007, "2007", ta, ra, 0.));
+ ticks.add(new NumberTick(2008, "2008", ta, ra, 0.));
+
+ return ticks;
+
+ }
+ };
+ lineChart.getXYPlot().setDomainAxis(numberAxis);
+ lineChartStyle.applyToChart(lineChart);
+
+ if (INTERACTIVE) {
+ ChartFrame chartFrame = new ChartFrame(
+ "drei linien sein, NOT categories", 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=\"code\" nullAliases=\"06531;06532\" /> fehlt!",
+ writtenXML
+ .contains("<seriesAttr name=\"code\" 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));
+ }
+
}
Added: trunk/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart.dbf
===================================================================
(Binary files differ)
Property changes on: trunk/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart.dbf
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart.prj
===================================================================
Added: trunk/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart.shp
===================================================================
(Binary files differ)
Property changes on: trunk/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart.shp
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart.shx
===================================================================
(Binary files differ)
Property changes on: trunk/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart.shx
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Deleted: trunk/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart2.dbf
===================================================================
(Binary files differ)
Deleted: trunk/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart2.prj
===================================================================
--- trunk/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart2.prj 2010-05-28 11:32:53 UTC (rev 869)
+++ trunk/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart2.prj 2010-05-28 12:07:14 UTC (rev 870)
@@ -1 +0,0 @@
-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
Deleted: trunk/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart2.qpj
===================================================================
--- trunk/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart2.qpj 2010-05-28 11:32:53 UTC (rev 869)
+++ trunk/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart2.qpj 2010-05-28 12:07:14 UTC (rev 870)
@@ -1 +0,0 @@
-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"]]
Deleted: trunk/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart2.shp
===================================================================
(Binary files differ)
Deleted: trunk/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart2.shx
===================================================================
(Binary files differ)
More information about the Schmitzm-commits
mailing list