001: /***********************************************************************************************
002: * Copyright 2002 (C) Nathaniel G. Auvil. All Rights Reserved.
003: *
004: * Redistribution and use of this software and associated documentation ("Software"), with or
005: * without modification, are permitted provided that the following conditions are met:
006: *
007: * 1. Redistributions of source code must retain copyright statements and notices.
008: * Redistributions must also contain a copy of this document.
009: *
010: * 2. Redistributions in binary form must reproduce the above copyright notice, this list of
011: * conditions and the following disclaimer in the documentation and/or other materials
012: * provided with the distribution.
013: *
014: * 3. The name "jCharts" or "Nathaniel G. Auvil" must not be used to endorse or promote
015: * products derived from this Software without prior written permission of Nathaniel G.
016: * Auvil. For written permission, please contact nathaniel_auvil@users.sourceforge.net
017: *
018: * 4. Products derived from this Software may not be called "jCharts" nor may "jCharts" appear
019: * in their names without prior written permission of Nathaniel G. Auvil. jCharts is a
020: * registered trademark of Nathaniel G. Auvil.
021: *
022: * 5. Due credit should be given to the jCharts Project (http://jcharts.sourceforge.net/).
023: *
024: * THIS SOFTWARE IS PROVIDED BY Nathaniel G. Auvil AND CONTRIBUTORS ``AS IS'' AND ANY
025: * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
026: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
027: * jCharts OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
028: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
029: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
030: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,STRICT LIABILITY, OR TORT
031: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
032: * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
033: ************************************************************************************************/package org.krysalis.jcharts.test;
034:
035: import java.awt.BasicStroke;
036: import java.awt.Paint;
037:
038: import org.krysalis.jcharts.chartData.ChartDataException;
039: import org.krysalis.jcharts.chartData.PieChartDataSet;
040: import org.krysalis.jcharts.imageMap.ImageMap;
041: import org.krysalis.jcharts.nonAxisChart.PieChart2D;
042: import org.krysalis.jcharts.properties.ChartProperties;
043: import org.krysalis.jcharts.properties.LegendProperties;
044: import org.krysalis.jcharts.properties.PieChart2DProperties;
045: import org.krysalis.jcharts.properties.PropertyException;
046: import org.krysalis.jcharts.properties.util.ChartStroke;
047:
048: /*************************************************************************************
049: *
050: * @author Nathaniel Auvil
051: * @version $Id: PieTestDriver.java,v 1.4 2003/08/08 08:51:27 nicolaken Exp $
052: ************************************************************************************/
053: public class PieTestDriver {
054:
055: /******************************************************************************************
056: * Test for PieChart2D
057: *
058: * @throws ChartDataException
059: ******************************************************************************************/
060: static void test() throws ChartDataException, PropertyException {
061: PieChart2D pieChart2D;
062: PieChartDataSet pieChartDataSet;
063: LegendProperties legendProperties;
064: ChartProperties chartProperties;
065:
066: int dataSize;
067: int width;
068: int height;
069: int numTestsToRun = 15;
070: String fileName;
071:
072: HTMLGenerator htmlGenerator = new HTMLGenerator(
073: ChartTestDriver.OUTPUT_PATH + "pieChart2dTest.html");
074:
075: for (int i = 0; i < numTestsToRun; i++) {
076: boolean createImageMap = true; //( TestDataGenerator.getRandomNumber( 1 ) > 0.5d );
077:
078: dataSize = (int) TestDataGenerator.getRandomNumber(1, 10);
079: pieChartDataSet = PieTestDriver.getPieChartDataSet(
080: dataSize, 1, 7);
081:
082: width = (int) TestDataGenerator.getRandomNumber(100, 600);
083: height = (int) TestDataGenerator.getRandomNumber(100, 600);
084:
085: legendProperties = new LegendProperties();
086: TestDataGenerator.randomizeLegend(legendProperties);
087: //legendProperties.setBorderStroke( new BasicStroke( 2.0f ) );
088:
089: chartProperties = new ChartProperties();
090: //areaProperties.setEdgePadding( (int) TestDataGenerator.getRandomNumber( 0, 50 ) );
091: chartProperties.setBackgroundPaint(TestDataGenerator
092: .getRandomPaint());
093: //chartProperties.setBorderStroke( new BasicStroke( 1f ) );
094:
095: pieChart2D = new PieChart2D(pieChartDataSet,
096: legendProperties, chartProperties, width, height);
097:
098: fileName = ChartTestDriver.OUTPUT_PATH + "pieChart2d" + i
099: + ChartTestDriver.EXTENSION;
100:
101: ImageMap imageMap;
102: if (createImageMap) {
103: pieChart2D.renderWithImageMap();
104: imageMap = pieChart2D.getImageMap();
105: } else {
106: imageMap = null;
107: }
108:
109: ChartTestDriver.exportImage(pieChart2D, fileName);
110:
111: htmlGenerator.chartTableStart("PieChart2D", fileName,
112: imageMap);
113: htmlGenerator.propertiesTableRowStart();
114: pieChartDataSet.toHTML(htmlGenerator);
115: htmlGenerator.propertiesTableRowStart();
116: pieChart2D.toHTML(htmlGenerator, fileName);
117:
118: htmlGenerator.addLineBreak();
119: }
120:
121: htmlGenerator.saveFile();
122: }
123:
124: /*****************************************************************************************
125: * Generates a random NonAxisChartDataSet
126: *
127: * @param numToCreate the number of doubles to generate
128: * @param minValue
129: * @param maxValue
130: * @return PieChartDataSet
131: ******************************************************************************************/
132: private static PieChartDataSet getPieChartDataSet(int numToCreate,
133: int minValue, int maxValue) throws ChartDataException {
134: PieChart2DProperties properties = new PieChart2DProperties();
135: //properties.setZeroDegreeOffset( (float) TestDataGenerator.getRandomNumber( 0, 500 ) );
136: properties.setBorderChartStroke(new ChartStroke(
137: new BasicStroke(1.0f), TestDataGenerator
138: .getRandomPaint()));
139:
140: String[] labels = TestDataGenerator.getRandomStrings(
141: numToCreate, (int) TestDataGenerator.getRandomNumber(3,
142: 20), false);
143: Paint[] paints = TestDataGenerator.getRandomPaints(numToCreate);
144:
145: return new PieChartDataSet("This is a test title",
146: TestDataGenerator.getRandomNumbers(numToCreate,
147: minValue, maxValue), labels, paints, properties);
148: }
149:
150: /***********************************************************************************************
151: *
152: * @param args
153: * @throws ChartDataException
154: * @throws PropertyException
155: ************************************************************************************************/
156: public static void main(String[] args) throws ChartDataException,
157: PropertyException {
158:
159: PieTestDriver.test();
160: /*
161: double[] data = {73.6d, 5.00d, 1.50d, 3.60d};
162: String[] labels = {"Equities", "Bonds", "Money Market", "Alternative Investments"};
163: Paint[] paints = {Color.lightGray, Color.green, Color.blue, Color.red};
164: */
165:
166: /*
167:
168:
169: double[] data = { 73.6d };
170: String[] labels = { "Alternative Investments"};
171: Paint[] paints = { Color.blue };
172:
173:
174:
175: PieChart2DProperties pieChart2DProperties = new PieChart2DProperties();
176: pieChart2DProperties.setPieLabelType( PieLabelType.VALUE_LABELS );
177: pieChart2DProperties.setTickLength( 5 );
178:
179: pieChart2DProperties.setZeroDegreeOffset( 10 );
180:
181: LegendProperties legendProperties = new LegendProperties();
182: legendProperties.setPlacement( LegendAreaProperties.TOP );
183: legendProperties.setNumColumns( 1 );
184: //legendProperties.setBorderStroke( null );
185:
186: PieChartDataSet pieChartDataSet = new PieChartDataSet( "Investment Categories", data, labels, paints, pieChart2DProperties );
187:
188: ChartProperties chartProperties = new ChartProperties();
189: chartProperties.setBorderStroke( ChartStroke.DEFAULT_CHART_OUTLINE );
190:
191: PieChart2D pieChart = new PieChart2D( pieChartDataSet, legendProperties, chartProperties, 600, 300 );
192: //PieChart2D pieChart = new PieChart2D( pieChartDataSet, legendProperties, chartProperties, 400, 300 );
193:
194: ChartTestDriver.exportImage( pieChart, "pie.png" );
195: */
196: }
197:
198: }
|