001: /***********************************************************************************************
002: * File Info: $Id: AxisChartTestBase.java,v 1.3 2004/05/27 02:14:59 nathaniel_auvil Exp $
003: * Copyright (C) 2000
004: * Author: Nathaniel G. Auvil
005: * Contributor(s):
006: *
007: * Copyright 2002 (C) Nathaniel G. Auvil. All Rights Reserved.
008: *
009: * Redistribution and use of this software and associated documentation ("Software"), with or
010: * without modification, are permitted provided that the following conditions are met:
011: *
012: * 1. Redistributions of source code must retain copyright statements and notices.
013: * Redistributions must also contain a copy of this document.
014: *
015: * 2. Redistributions in binary form must reproduce the above copyright notice, this list of
016: * conditions and the following disclaimer in the documentation and/or other materials
017: * provided with the distribution.
018: *
019: * 3. The name "jCharts" or "Nathaniel G. Auvil" must not be used to endorse or promote
020: * products derived from this Software without prior written permission of Nathaniel G.
021: * Auvil. For written permission, please contact nathaniel_auvil@users.sourceforge.net
022: *
023: * 4. Products derived from this Software may not be called "jCharts" nor may "jCharts" appear
024: * in their names without prior written permission of Nathaniel G. Auvil. jCharts is a
025: * registered trademark of Nathaniel G. Auvil.
026: *
027: * 5. Due credit should be given to the jCharts Project (http://jcharts.sourceforge.net/).
028: *
029: * THIS SOFTWARE IS PROVIDED BY Nathaniel G. Auvil AND CONTRIBUTORS ``AS IS'' AND ANY
030: * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
031: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
032: * jCharts OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
033: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
034: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
035: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,STRICT LIABILITY, OR TORT
036: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
037: * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
038: ************************************************************************************************/package org.krysalis.jcharts.test;
039:
040: import org.krysalis.jcharts.axisChart.AxisChart;
041: import org.krysalis.jcharts.chartData.*;
042: import org.krysalis.jcharts.properties.*;
043: import org.krysalis.jcharts.types.ChartType;
044: import org.krysalis.jcharts.imageMap.ImageMap;
045:
046: import java.awt.*;
047:
048: /******************************************************************************************
049: *
050: *
051: *******************************************************************************************/
052: abstract class AxisChartTestBase {
053:
054: public AxisChartTestBase() {
055: System.out.println("Running: " + this .getClass().getName());
056: }
057:
058: abstract DataSeries getDataSeries() throws ChartDataException;
059:
060: abstract boolean supportsImageMap();
061:
062: /******************************************************************************************
063: * Test for LineChart
064: *
065: ******************************************************************************************/
066: static void axisChartTest(String name,
067: AxisChartTestBase axisChartTestBase)
068: throws ChartDataException, PropertyException {
069: LegendProperties legendProperties;
070: ChartProperties chartProperties;
071: AxisProperties axisProperties;
072: AxisChart axisChart;
073:
074: int numTestsToRun = 10;
075: String fileName;
076:
077: HTMLGenerator htmlGenerator = new HTMLGenerator(
078: ChartTestDriver.OUTPUT_PATH + name + "Test.html");
079:
080: for (int i = 0; i < numTestsToRun; i++) {
081: DataSeries dataSeries = axisChartTestBase.getDataSeries();
082:
083: boolean horizontalPlot = true; //( TestDataGenerator.getRandomNumber( 1 ) > 0.5d );
084: boolean createImageMap = true; //( TestDataGenerator.getRandomNumber( 1 ) > 0.5d );
085:
086: axisProperties = new AxisProperties(horizontalPlot);
087: axisProperties.setXAxisLabelsAreVertical((TestDataGenerator
088: .getRandomNumber(1) > 0.5d));
089:
090: TestDataGenerator.randomizeAxisProperties(axisProperties);
091: //axisProperties.setYAxisNumItems( 6 );
092:
093: DataAxisProperties dataAxisProperties;
094: LabelAxisProperties labelAxisProperties;
095:
096: if (horizontalPlot) {
097: dataAxisProperties = (DataAxisProperties) axisProperties
098: .getXAxisProperties();
099: labelAxisProperties = (LabelAxisProperties) axisProperties
100: .getYAxisProperties();
101: } else {
102: dataAxisProperties = (DataAxisProperties) axisProperties
103: .getYAxisProperties();
104: labelAxisProperties = (LabelAxisProperties) axisProperties
105: .getXAxisProperties();
106: }
107:
108: dataAxisProperties.setRoundToNearest(1);
109: //dataAxisProperties.setUserDefinedScale( 10, 500 );
110:
111: //---if the labels are NULL, force to zero.
112: if (dataSeries.getNumberOfAxisLabels() == 0) {
113: labelAxisProperties.setShowAxisLabels(false);
114: } else {
115: labelAxisProperties
116: .setShowAxisLabels((TestDataGenerator
117: .getRandomNumber(1) > 0.3d));
118: }
119:
120: int width = (int) TestDataGenerator.getRandomNumber(500,
121: 1000);
122: int height = (int) TestDataGenerator.getRandomNumber(300,
123: 800);
124:
125: legendProperties = new LegendProperties();
126: TestDataGenerator.randomizeLegend(legendProperties);
127: //legendProperties.setPlacement( LegendAreaProperties.RIGHT );
128:
129: chartProperties = new ChartProperties();
130: //chartProperties.setBorderStroke( new BasicStroke( 1f ) );
131:
132: axisChart = new AxisChart(dataSeries, chartProperties,
133: axisProperties, legendProperties, width, height);
134:
135: fileName = ChartTestDriver.OUTPUT_PATH + name + i
136: + ChartTestDriver.EXTENSION;
137:
138: ImageMap imageMap;
139: if (createImageMap && axisChartTestBase.supportsImageMap()) {
140: axisChart.renderWithImageMap();
141: imageMap = axisChart.getImageMap();
142: } else {
143: imageMap = null;
144: }
145:
146: try {
147: ChartTestDriver.exportImage(axisChart, fileName);
148: } catch (NullPointerException nullPointerException) {
149: nullPointerException.printStackTrace();
150: System.out.println();
151: }
152:
153: axisChart.toHTML(htmlGenerator, fileName, imageMap);
154: htmlGenerator.addLineBreak();
155: }
156:
157: htmlGenerator.saveFile();
158: }
159:
160: /*****************************************************************************************************
161: *
162: *
163: *****************************************************************************************************/
164: final DataSeries createDataSeries(int numberOfValuesToCreate) {
165: String[] xAxisLabels = null;
166: if ((TestDataGenerator.getRandomNumber(1) > 0.3d)) {
167: xAxisLabels = TestDataGenerator.getRandomStrings(
168: numberOfValuesToCreate, (int) TestDataGenerator
169: .getRandomNumber(10), false);
170: }
171: String xAxisTitle = TestDataGenerator.getRandomString(15, true);
172: String yAxisTitle = TestDataGenerator.getRandomString(15, true);
173:
174: return new DataSeries(
175: xAxisLabels,
176: xAxisTitle,
177: yAxisTitle,
178: "This is a test title that is so freaking long is is going to wrap around the image for sure. lfksjg;ljs; dflgkjdfgsdgdg dsgdsgsdfg dsfgsdfgsdfgs dfgdsfgd");
179: }
180:
181: /*****************************************************************************************
182: * Generates a random MultiDataSet
183: *
184: * @param numberOfDataSets
185: * @param numberOfValuesToCreate the number of doubles to generate
186: * @param minValue
187: * @param maxValue
188: * @return AxisChartDataSet
189: ******************************************************************************************/
190: AxisChartDataSet createAxisChartDataSet(ChartType chartType,
191: ChartTypeProperties chartTypeProperties,
192: int numberOfDataSets, int numberOfValuesToCreate,
193: int minValue, int maxValue) throws ChartDataException {
194: double[][] data = TestDataGenerator.getRandomNumbers(
195: numberOfDataSets, numberOfValuesToCreate, minValue,
196: maxValue);
197: String[] legendLabels = TestDataGenerator.getRandomStrings(
198: numberOfDataSets, 10, false);
199: Paint[] paints = TestDataGenerator
200: .getRandomPaints(numberOfDataSets);
201:
202: /*
203: //data[ 0 ][ 0 ]= Double.NaN;
204: data[ 0 ][ 1 ]= Double.NaN;
205:
206:
207: data[ 0 ][ 4 ]= Double.NaN;
208: data[ 0 ][ 6 ]= Double.NaN;
209:
210: //data[ 0 ][ data[ 0 ].length - 1 ]= Double.NaN;
211: data[ 0 ][ data[ 0 ].length - 2 ]= Double.NaN;
212: */
213:
214: return new AxisChartDataSet(data, legendLabels, paints,
215: chartType, chartTypeProperties);
216: }
217: }
|