001: /***********************************************************************************************
002: * File Info: $Id: ScatterPlotTestDriver.java,v 1.3 2003/08/08 08:51:27 nicolaken Exp $
003: * Copyright (C) 2002
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 java.awt.BasicStroke;
041: import java.awt.Paint;
042: import java.awt.Shape;
043: import java.awt.Stroke;
044: import java.awt.geom.Point2D;
045:
046: import org.krysalis.jcharts.axisChart.ScatterPlotAxisChart;
047: import org.krysalis.jcharts.chartData.ChartDataException;
048: import org.krysalis.jcharts.chartData.DataSeries;
049: import org.krysalis.jcharts.chartData.ScatterPlotDataSeries;
050: import org.krysalis.jcharts.chartData.ScatterPlotDataSet;
051: import org.krysalis.jcharts.properties.AxisProperties;
052: import org.krysalis.jcharts.properties.ChartProperties;
053: import org.krysalis.jcharts.properties.DataAxisProperties;
054: import org.krysalis.jcharts.properties.LegendProperties;
055: import org.krysalis.jcharts.properties.LineChartProperties;
056: import org.krysalis.jcharts.properties.PointChartProperties;
057: import org.krysalis.jcharts.properties.PropertyException;
058: import org.krysalis.jcharts.properties.ScatterPlotProperties;
059:
060: /******************************************************************************************
061: * This file provides examples of how to create all the different chart types provided by
062: * this package.
063: *
064: *******************************************************************************************/
065: public class ScatterPlotTestDriver extends AxisChartTestBase {
066: boolean supportsImageMap() {
067: return true;
068: }
069:
070: /******************************************************************************************
071: * Separate this so can use for combo chart test
072: *
073: * @param numberOfDataSets
074: ******************************************************************************************/
075: private ScatterPlotProperties getScatterPlotProperties(
076: int numberOfDataSets) {
077: Stroke[] strokes = new Stroke[numberOfDataSets];
078: for (int j = 0; j < numberOfDataSets; j++) {
079: strokes[j] = LineChartProperties.DEFAULT_LINE_STROKE;
080: }
081: strokes[0] = new BasicStroke(3.0f);
082:
083: Shape[] shapes = new Shape[numberOfDataSets];
084: for (int j = 0; j < numberOfDataSets; j++) {
085: shapes[j] = PointChartProperties.SHAPE_DIAMOND;
086: }
087: shapes[0] = PointChartProperties.SHAPE_CIRCLE;
088:
089: return new ScatterPlotProperties(strokes, shapes);
090: }
091:
092: /*****************************************************************************************
093: * Generates a random MultiDataSet
094: *
095: * @param numberOfDataSets
096: * @param numberOfValuesToCreate the number of doubles to generate
097: * @param xMinValue
098: * @param xMaxValue
099: * @param yMinValue
100: * @param yMaxValue
101: * @return AxisChartDataSet
102: ******************************************************************************************/
103: private ScatterPlotDataSet createScatterPlotDataSet(
104: int numberOfDataSets, int numberOfValuesToCreate,
105: int xMinValue, int xMaxValue, int yMinValue, int yMaxValue)
106: throws ChartDataException {
107: //Point2D.Double[] points= TestDataGenerator.getRandomPoints( numberOfValuesToCreate, xMinValue, xMaxValue, yMinValue, yMaxValue );
108:
109: Point2D.Double[] points = new Point2D.Double[20];
110: for (int x = 0; x < 20; x++) {
111: //--- y = x^2
112: points[x] = new Point2D.Double();
113: points[x].setLocation(x, Math.pow(x, 2));
114: }
115:
116: String[] legendLabels = TestDataGenerator.getRandomStrings(1,
117: 12, false);
118: // Paint[] paints = TestDataGenerator.getRandomPaints( numberOfDataSets );
119: Paint paint = TestDataGenerator.getRandomPaint();
120:
121: ScatterPlotDataSet scatterPlotDataSet = new ScatterPlotDataSet(
122: this .getScatterPlotProperties(1));
123: scatterPlotDataSet
124: .addDataPoints(points, paint, legendLabels[0]);
125:
126: System.out.println("legendLabels[ 0 ]= " + legendLabels[0]);
127: return scatterPlotDataSet;
128: }
129:
130: /******************************************************************************************
131: *
132: *
133: ******************************************************************************************/
134: DataSeries getDataSeries() throws ChartDataException {
135: DataSeries dataSeries = null;
136:
137: int dataSize = (int) TestDataGenerator.getRandomNumber(3, 3);
138: int numberOfDataSets = (int) TestDataGenerator.getRandomNumber(
139: 1, 1);
140:
141: //ScatterPlotDataSet scatterPlotDataSet= this.createScatterPlotDataSet( )
142:
143: //String[] xAxisLabels = TestDataGenerator.getRandomStrings( numberOfValuesToCreate, ( int ) TestDataGenerator.getRandomNumber( 10 ), false );
144: String xAxisTitle = TestDataGenerator.getRandomString(15, true);
145: String yAxisTitle = TestDataGenerator.getRandomString(15, true);
146: //dataSeries = new DataSeries( xAxisLabels, xAxisTitle, yAxisTitle, "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" );
147:
148: //dataSeries.addIAxisPlotDataSet( axisChartDataSet );
149:
150: return dataSeries;
151: }
152:
153: /******************************************************************************************
154: *
155: *
156: ******************************************************************************************
157: DataSeries getDataSeries() throws ChartDataException
158: {
159: String[] xAxisLabels={"1", "2", "3", "4", "5"};
160: DataSeries dataSeries=new DataSeries( xAxisLabels, "numbers", "numbers", "Bug #559177" );
161: AxisChartDataSet axisChartDataSet;
162:
163: double[][] data={{1, 2, 3, 4, 5},
164: {7, 8, Double.NaN, Double.NaN, Double.NaN},
165: {Double.NaN, Double.NaN, Double.NaN, Double.NaN, 2}};
166:
167: String[] legendLabels={"set 1", "set 2", "set 3"};
168: Paint[] paints={Color.blue, Color.red, Color.green};
169:
170: axisChartDataSet=new AxisChartDataSet( data,
171: legendLabels,
172: paints,
173: ChartType.LINE,
174: this.getChartTypeProperties( 3 ) );
175:
176: dataSeries.addIAxisPlotDataSet( axisChartDataSet );
177:
178: return dataSeries;
179:
180: }
181: */
182:
183: public static void main(String[] args) throws ChartDataException,
184: PropertyException {
185: ScatterPlotTestDriver s = new ScatterPlotTestDriver();
186:
187: ScatterPlotDataSet scatterPlotDataSet = s
188: .createScatterPlotDataSet(1, 5, -1000, 3000, 200, 500);
189: ScatterPlotDataSeries scatterPlotDataSeries = new ScatterPlotDataSeries(
190: scatterPlotDataSet, "X-Axis Title", "Y-Axis Title",
191: "Chart Title");
192:
193: DataAxisProperties xAxisProperties = new DataAxisProperties();
194: xAxisProperties.setUserDefinedScale(-5, 3);
195: xAxisProperties.setNumItems(10);
196: xAxisProperties.setRoundToNearest(0);
197:
198: DataAxisProperties yAxisProperties = new DataAxisProperties();
199: yAxisProperties.setUserDefinedScale(-30, 50);
200: yAxisProperties.setNumItems(10);
201: yAxisProperties.setRoundToNearest(1);
202:
203: AxisProperties axisProperties = new AxisProperties(
204: xAxisProperties, yAxisProperties);
205: ChartProperties chartProperties = new ChartProperties();
206: LegendProperties legendProperties = new LegendProperties();
207:
208: ScatterPlotAxisChart scatterPlotAxisChart = new ScatterPlotAxisChart(
209: scatterPlotDataSeries, chartProperties, axisProperties,
210: legendProperties, 500, 400);
211:
212: ChartTestDriver.exportImage(scatterPlotAxisChart,
213: "ScatterPlotTest.png");
214: }
215:
216: }
|