KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > krysalis > jcharts > axisChart > AreaChart


1 /***********************************************************************************************
2  * Copyright 2002 (C) Nathaniel G. Auvil. All Rights Reserved.
3  *
4  * Redistribution and use of this software and associated documentation ("Software"), with or
5  * without modification, are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain copyright statements and notices.
8  * Redistributions must also contain a copy of this document.
9  *
10  * 2. Redistributions in binary form must reproduce the above copyright notice, this list of
11  * conditions and the following disclaimer in the documentation and/or other materials
12  * provided with the distribution.
13  *
14  * 3. The name "jCharts" or "Nathaniel G. Auvil" must not be used to endorse or promote
15  * products derived from this Software without prior written permission of Nathaniel G.
16  * Auvil. For written permission, please contact nathaniel_auvil@users.sourceforge.net
17  *
18  * 4. Products derived from this Software may not be called "jCharts" nor may "jCharts" appear
19  * in their names without prior written permission of Nathaniel G. Auvil. jCharts is a
20  * registered trademark of Nathaniel G. Auvil.
21  *
22  * 5. Due credit should be given to the jCharts Project (http://jcharts.sourceforge.net/).
23  *
24  * THIS SOFTWARE IS PROVIDED BY Nathaniel G. Auvil AND CONTRIBUTORS ``AS IS'' AND ANY
25  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
27  * jCharts OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
32  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
33  ************************************************************************************************/

34
35 package org.krysalis.jcharts.axisChart;
36
37
38 import org.krysalis.jcharts.chartData.interfaces.IAxisChartDataSet;
39 import org.krysalis.jcharts.imageMap.ImageMapNotSupportedException;
40
41 import java.awt.*;
42 import java.awt.geom.Area JavaDoc;
43 import java.awt.geom.GeneralPath JavaDoc;
44
45
46 /*************************************************************************************
47  *
48  * @author Nathaniel Auvil
49  * @version $Id: AreaChart.java,v 1.3 2004/05/31 15:39:53 nathaniel_auvil Exp $
50  ************************************************************************************/

51 abstract class AreaChart
52 {
53
54     /********************************************************************************************
55      * Draws the chart
56      *
57      * @param axisChart
58      * @param iAxisChartDataSet
59      *********************************************************************************************/

60     static void render( AxisChart axisChart, IAxisChartDataSet iAxisChartDataSet )
61     {
62         //---hopefully eliminate support requests asking about this...
63
if( axisChart.getImageMap() != null )
64         {
65 //todo should we do a point image map?
66
throw new ImageMapNotSupportedException( "HTML client-side image maps are not supported on Area Charts." );
67         }
68
69
70         //AreaChartProperties areaChartProperties=(AreaChartProperties) iAxisChartDataSet.getChartTypeProperties();
71
float xPosition=axisChart.getXAxis().getTickStart();
72
73         GeneralPath JavaDoc generalPaths[]=new GeneralPath JavaDoc[ iAxisChartDataSet.getNumberOfDataSets() ];
74
75
76         //---AreaCharts can not be drawn on a horizontal axis so y-axis will always be the data axis
77
//DataAxisProperties dataAxisProperties= (DataAxisProperties) axisChart.getAxisProperties().getYAxisProperties();
78

79
80         //LOOP
81
//---initial postion of each line must be set with call to moveTo()
82
//---Do this here so every point does not have to check....if( i == 0 )... in loop
83
for( int i=0; i < generalPaths.length; i++ )
84         {
85             generalPaths[ i ]=new GeneralPath JavaDoc();
86             generalPaths[ i ].moveTo( xPosition, axisChart.getYAxis().getZeroLineCoordinate() );
87             generalPaths[ i ].lineTo( xPosition, axisChart.getYAxis().computeAxisCoordinate( axisChart.getYAxis().getOrigin(),
88                                                                                                                         iAxisChartDataSet.getValue( i, 0 ),
89                                                                                                                         axisChart.getYAxis().getScaleCalculator().getMinValue() ) );
90         }
91
92         //LOOP
93
for( int j=1; j < iAxisChartDataSet.getNumberOfDataItems(); j++ )
94         {
95             xPosition+=axisChart.getXAxis().getScalePixelWidth();
96
97             //LOOP
98
for( int i=0; i < generalPaths.length; i++ )
99             {
100                 generalPaths[ i ].lineTo( xPosition, axisChart.getYAxis().computeAxisCoordinate( axisChart.getYAxis().getOrigin(),
101                                                                                                                             iAxisChartDataSet.getValue( i, j ),
102                                                                                                                             axisChart.getYAxis().getScaleCalculator().getMinValue() ) );
103             }
104         }
105
106
107         Area JavaDoc[] areas=new Area JavaDoc[ generalPaths.length ];
108
109
110         //LOOP
111
//---close the path. Do this here so do not have to check if last every pass through above loop.
112
for( int i=0; i < generalPaths.length; i++ )
113         {
114             generalPaths[ i ].lineTo( xPosition, axisChart.getYAxis().getZeroLineCoordinate() );
115             generalPaths[ i ].closePath();
116
117             areas[ i ]=new Area JavaDoc( generalPaths[ i ] );
118         }
119
120         Graphics2D g2d=axisChart.getGraphics2D();
121
122         //LOOP
123
//---draw each path to the image
124
for( int i=0; i < areas.length; i++ )
125         {
126             g2d.setPaint( iAxisChartDataSet.getPaint( i ) );
127             g2d.fill( areas[ i ] );
128         }
129     }
130
131 }
132
Popular Tags