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 org.krysalis.jcharts.chartData.ChartDataException;
036: import org.krysalis.jcharts.chartData.PieChartDataSet;
037: import org.krysalis.jcharts.imageMap.ImageMap;
038: import org.krysalis.jcharts.nonAxisChart.PieChart2D;
039: import org.krysalis.jcharts.nonAxisChart.PieChart3D;
040: import org.krysalis.jcharts.properties.ChartProperties;
041: import org.krysalis.jcharts.properties.LegendAreaProperties;
042: import org.krysalis.jcharts.properties.LegendProperties;
043: import org.krysalis.jcharts.properties.PieChart2DProperties;
044: import org.krysalis.jcharts.properties.PieChart3DProperties;
045: import org.krysalis.jcharts.properties.PropertyException;
046: import org.krysalis.jcharts.properties.util.ChartStroke;
047: import org.krysalis.jcharts.types.PieLabelType;
048:
049: import java.awt.*;
050:
051: /*************************************************************************************
052: *
053: * @author Nathaniel Auvil
054: * @version $Id: Pie3DTestDriver.java,v 1.5 2003/06/25 01:39:48 nathaniel_auvil Exp $
055: ************************************************************************************/
056: public class Pie3DTestDriver {
057:
058: /******************************************************************************************
059: * Test for PieChart2D
060: *
061: * @throws ChartDataException
062: ******************************************************************************************/
063: static void test() throws ChartDataException, PropertyException {
064: PieChart2D pieChart2D;
065: PieChartDataSet pieChartDataSet;
066: LegendProperties legendProperties;
067: ChartProperties chartProperties;
068:
069: int dataSize;
070: int width;
071: int height;
072: int numTestsToRun = 15;
073: String fileName;
074:
075: HTMLGenerator htmlGenerator = new HTMLGenerator(
076: ChartTestDriver.OUTPUT_PATH + "pieChart2dTest.html");
077:
078: for (int i = 0; i < numTestsToRun; i++) {
079: boolean createImageMap = true; //( TestDataGenerator.getRandomNumber( 1 ) > 0.5d );
080:
081: dataSize = (int) TestDataGenerator.getRandomNumber(1, 10);
082: pieChartDataSet = Pie3DTestDriver.getPieChartDataSet(
083: dataSize, 1, 7);
084:
085: width = (int) TestDataGenerator.getRandomNumber(100, 600);
086: height = (int) TestDataGenerator.getRandomNumber(100, 600);
087:
088: legendProperties = new LegendProperties();
089: TestDataGenerator.randomizeLegend(legendProperties);
090: //legendProperties.setBorderStroke( new BasicStroke( 2.0f ) );
091:
092: chartProperties = new ChartProperties();
093: //areaProperties.setEdgePadding( (int) TestDataGenerator.getRandomNumber( 0, 50 ) );
094: chartProperties.setBackgroundPaint(TestDataGenerator
095: .getRandomPaint());
096: //chartProperties.setBorderStroke( new BasicStroke( 1f ) );
097:
098: pieChart2D = new PieChart2D(pieChartDataSet,
099: legendProperties, chartProperties, width, height);
100:
101: fileName = ChartTestDriver.OUTPUT_PATH + "pieChart2d" + i
102: + ChartTestDriver.EXTENSION;
103:
104: ImageMap imageMap;
105: if (createImageMap) {
106: pieChart2D.renderWithImageMap();
107: imageMap = pieChart2D.getImageMap();
108: } else {
109: imageMap = null;
110: }
111:
112: ChartTestDriver.exportImage(pieChart2D, fileName);
113:
114: htmlGenerator.chartTableStart("PieChart2D", fileName,
115: imageMap);
116: htmlGenerator.propertiesTableRowStart();
117: pieChartDataSet.toHTML(htmlGenerator);
118: htmlGenerator.propertiesTableRowStart();
119: pieChart2D.toHTML(htmlGenerator, fileName);
120:
121: htmlGenerator.addLineBreak();
122: }
123:
124: htmlGenerator.saveFile();
125: }
126:
127: /*****************************************************************************************
128: * Generates a random NonAxisChartDataSet
129: *
130: * @param numToCreate the number of doubles to generate
131: * @param minValue
132: * @param maxValue
133: * @return PieChartDataSet
134: ******************************************************************************************/
135: private static PieChartDataSet getPieChartDataSet(int numToCreate,
136: int minValue, int maxValue) throws ChartDataException {
137: PieChart2DProperties properties = new PieChart2DProperties();
138: //properties.setZeroDegreeOffset( (float) TestDataGenerator.getRandomNumber( 0, 500 ) );
139: properties.setBorderChartStroke(new ChartStroke(
140: new BasicStroke(1.0f), TestDataGenerator
141: .getRandomPaint()));
142:
143: String[] labels = TestDataGenerator.getRandomStrings(
144: numToCreate, (int) TestDataGenerator.getRandomNumber(3,
145: 20), false);
146: Paint[] paints = TestDataGenerator.getRandomPaints(numToCreate);
147:
148: return new PieChartDataSet("This is a test title",
149: TestDataGenerator.getRandomNumbers(numToCreate,
150: minValue, maxValue), labels, paints, properties);
151: }
152:
153: /***********************************************************************************************
154: *
155: * @param args
156: * @throws ChartDataException
157: * @throws PropertyException
158: ************************************************************************************************/
159: public static void main(String[] args) throws ChartDataException,
160: PropertyException {
161:
162: double[] data = { 45.00d, 90.00d, 45.00d, 180d };
163: String[] labels = { "Equities", "Bonds", "Money Market",
164: "Alternative Investments" };
165: //Paint[] paints = TestDataGenerator.getRandomPaints( data.length );
166:
167: //Paint[] paints = { new Color( 200, 0, 0 ), new Color( 0, 200, 0 ), new Color( 0, 0, 200 ), new Color( 200, 200, 0 ) };
168: Paint[] paints = { new Color(200, 0, 0, 20),
169: new Color(0, 200, 0, 220), new Color(0, 0, 200, 20),
170: new Color(200, 200, 0, 20) };
171:
172: /*
173: double[] data = { 73.6d };
174: String[] labels = { "Alternative Investments"};
175: Paint[] paints = { Color.blue };
176: */
177:
178: PieChart3DProperties pieChart3DProperties = new PieChart3DProperties();
179: pieChart3DProperties
180: .setPieLabelType(PieLabelType.LEGEND_LABELS);
181: pieChart3DProperties.setTickLength(5);
182:
183: pieChart3DProperties.setZeroDegreeOffset(60);
184:
185: pieChart3DProperties.setDepth(15);
186:
187: LegendProperties legendProperties = new LegendProperties();
188: legendProperties.setPlacement(LegendAreaProperties.RIGHT);
189: legendProperties.setNumColumns(1);
190: //legendProperties.setBorderStroke( null );
191:
192: PieChartDataSet pieChartDataSet = new PieChartDataSet(
193: "Investment Categories", data, labels, paints,
194: pieChart3DProperties);
195:
196: ChartProperties chartProperties = new ChartProperties();
197: chartProperties
198: .setBorderStroke(ChartStroke.DEFAULT_CHART_OUTLINE);
199:
200: PieChart3D pieChart = new PieChart3D(pieChartDataSet,
201: legendProperties, chartProperties, 600, 200);
202: //PieChart2D pieChart = new PieChart2D( pieChartDataSet, legendProperties, chartProperties, 400, 300 );
203:
204: ChartTestDriver.exportImage(pieChart, "pie3d.png");
205: }
206:
207: }
|