KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > krysalis > jcharts > chartData > processors > AxisChartDataProcessor


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

47
48 package org.krysalis.jcharts.chartData.processors;
49
50
51 import java.awt.font.FontRenderContext JavaDoc;
52 import java.util.Iterator JavaDoc;
53
54 import org.krysalis.jcharts.axisChart.AxisChart;
55 import org.krysalis.jcharts.chartData.interfaces.IAxisChartDataSet;
56 import org.krysalis.jcharts.chartData.interfaces.IAxisPlotDataSet;
57 import org.krysalis.jcharts.chartData.interfaces.IDataSeries;
58 import org.krysalis.jcharts.chartData.interfaces.IStockChartDataSet;
59 import org.krysalis.jcharts.properties.DataAxisProperties;
60 import org.krysalis.jcharts.types.ChartType;
61
62
63 /*******************************************************************************************
64  *
65  ********************************************************************************************/

66 public class AxisChartDataProcessor
67 {
68     private double max;
69     private double min;
70
71     //private TextLayout titleTextLayout;
72

73
74     //---need this so know how many items are on the 'label' axis.
75
private int numberOfElementsInADataSet;
76
77
78
79     /******************************************************************************************
80      * Constructor
81      *
82      *******************************************************************************************/

83     public AxisChartDataProcessor()
84     {
85
86     }
87
88
89
90     /******************************************************************************************
91      * Method to perform all chart data processing.
92      *
93      * @param axisChart
94      ******************************************************************************************/

95     public void processData( AxisChart axisChart, FontRenderContext JavaDoc fontRenderContext )
96     {
97 //todo would it make sense to do this and do the axis titles?
98
/*
99        if( axisChart.getIDataSeries().getChartTitle() != null )
100         {
101             this.titleTextLayout= new TextLayout( axisChart.getIDataSeries().getChartTitle(),
102                                                                 axisChart.getChartProperties().getTitleFont(),
103                                                                 fontRenderContext );
104         }
105         */

106
107         DataAxisProperties dataAxisProperties;
108         if( axisChart.getAxisProperties().isPlotHorizontal() )
109         {
110             dataAxisProperties= (DataAxisProperties) axisChart.getAxisProperties().getXAxisProperties();
111         }
112         else
113         {
114             dataAxisProperties= (DataAxisProperties) axisChart.getAxisProperties().getYAxisProperties();
115         }
116
117
118         //---if there is a user defined scale, there is no reason to process the data.
119
if( ! dataAxisProperties.hasUserDefinedScale() )
120         {
121             this.processDataSet( (IDataSeries) axisChart.getIAxisDataSeries() );
122         }
123
124
125         //---need to set the number of items on the scale in case there are no labels displayed
126
Iterator JavaDoc iterator = axisChart.getIAxisDataSeries().getIAxisPlotDataSetIterator();
127         IAxisPlotDataSet iAxisPlotDataSet = ( IAxisPlotDataSet ) iterator.next();
128         this.numberOfElementsInADataSet= iAxisPlotDataSet.getNumberOfDataItems();
129
130
131 //todo does it make sense to do the legend label processing here?
132
/*
133         if( axisChart.hasLegend() )
134         {
135             //this.lengendLabelProcessor= new TextProcessor();
136           // this.lengendLabelProcessor
137         }
138         */

139     }
140
141
142     /******************************************************************************************
143      * Processes the numeric values in the chart data. If there is a user defined scale
144      * there is no need to call this.
145      *
146      * @param iDataSeries
147      ******************************************************************************************/

148     private void processDataSet( IDataSeries iDataSeries )
149     {
150         IAxisPlotDataSet iAxisPlotDataSet;
151         Iterator JavaDoc iterator = iDataSeries.getIAxisPlotDataSetIterator();
152
153         //LOOP
154
while( iterator.hasNext() )
155         {
156             iAxisPlotDataSet = ( IAxisPlotDataSet ) iterator.next();
157
158             if( iAxisPlotDataSet.getChartType().isStacked() )
159             {
160                 //---StockChartDataSet is NEVER stacked!!!!
161
StackedDataProcessor.processData( ( IAxisChartDataSet ) iAxisPlotDataSet, this );
162             }
163             else
164             {
165                 //---stock charts dont fit well here as the data comes in structured.
166
//---in this case only care about the high and low; no need to search close, open, volume
167
if( iAxisPlotDataSet.getChartType().equals( ChartType.STOCK ) )
168                 {
169                     StockDataProcessor.processData( ( IStockChartDataSet ) iAxisPlotDataSet, this );
170                 }
171                 else
172                 {
173                     NonStackedDataProcessor.processData( ( IAxisChartDataSet ) iAxisPlotDataSet, this );
174                 }
175             }
176         }
177     }
178
179
180     /******************************************************************************************
181      *
182      *
183      ******************************************************************************************/

184     void setMaxValue( double max )
185     {
186         this.max = max;
187     }
188
189
190     /******************************************************************************************
191      *
192      *
193      *
194      ******************************************************************************************/

195     public double getMaxValue()
196     {
197         return this.max;
198     }
199
200
201     /******************************************************************************************
202      *
203      *
204      ******************************************************************************************/

205     void setMinValue( double min )
206     {
207         this.min = min;
208     }
209
210
211     /******************************************************************************************
212      *
213      *
214      *
215      ******************************************************************************************/

216     public double getMinValue()
217     {
218         return this.min;
219     }
220
221
222     public int getNumberOfElementsInADataSet()
223     {
224         return numberOfElementsInADataSet;
225     }
226
227
228     /*********************************************************************************************
229      * Enables the testing routines to display the contents of this Object.
230      *
231      * @param htmlGenerator
232      **********************************************************************************************
233      public void toHTML( HTMLGenerator htmlGenerator )
234      {
235      super.toHTML( htmlGenerator );
236
237      String name= this.getClass().getSuperclass().getName() + "->";
238
239      //---calling on instance of YAxis or XAxis
240      Field[] fields= this.getClass().getSuperclass().getDeclaredFields();
241      for( int i=0; i< fields.length; i++ )
242      {
243      htmlGenerator.addField( name + fields[ i ].getName(), fields[ i ].get( this ) );
244      }
245      }
246      */

247 }
248
Popular Tags