KickJava   Java API By Example, From Geeks To Geeks.

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


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

39
40 package org.krysalis.jcharts.chartData.processors;
41
42
43 import org.krysalis.jcharts.axisChart.AxisChart;
44 import org.krysalis.jcharts.chartData.interfaces.IScatterPlotDataSeries;
45 import org.krysalis.jcharts.chartData.interfaces.IScatterPlotDataSet;
46 import org.krysalis.jcharts.types.ChartType;
47
48 import java.awt.font.FontRenderContext JavaDoc;
49 import java.awt.geom.Point2D JavaDoc;
50
51
52 /*******************************************************************************************
53  *
54  ********************************************************************************************/

55 public final class ScatterPlotDataProcessor extends AxisChartDataProcessor
56 {
57     private double yMax;
58     private double yMin;
59
60
61     /******************************************************************************************
62      * Constructor
63      *
64      *******************************************************************************************/

65     public ScatterPlotDataProcessor()
66     {
67
68     }
69
70
71     /******************************************************************************************
72      * Method to perform all chart data processing.
73      *
74      * @param axisChart
75      ******************************************************************************************/

76     public void processData( AxisChart axisChart, FontRenderContext JavaDoc fontRenderContext )
77     {
78 //todo would it make sense to do this and do the axis titles?
79
/*
80        if( axisChart.getIDataSeries().getChartTitle() != null )
81         {
82             this.titleTextLayout= new TextLayout( axisChart.getIDataSeries().getChartTitle(),
83                                                                 axisChart.getChartProperties().getTitleFont(),
84                                                                 fontRenderContext );
85         }
86         */

87
88         IScatterPlotDataSeries iScatterPlotDataSeries = (IScatterPlotDataSeries) axisChart.getIAxisDataSeries();
89         this.processDataSet( iScatterPlotDataSeries );
90
91 //todo does it make sense to do the legend label processing here?
92
/*
93         if( axisChart.hasLegend() )
94         {
95             //this.lengendLabelProcessor= new TextProcessor();
96           // this.lengendLabelProcessor
97         }
98         */

99     }
100
101
102     /******************************************************************************************
103      * Processes the numeric values in the chart data. If there is a user defined scale
104      * there is no need to call this.
105      *
106      * @param iScatterPlotDataSeries
107      ******************************************************************************************/

108     private void processDataSet( IScatterPlotDataSeries iScatterPlotDataSeries )
109     {
110         IScatterPlotDataSet iScatterPlotDataSet = (IScatterPlotDataSet) iScatterPlotDataSeries.getIAxisPlotDataSet( ChartType.SCATTER_PLOT );
111
112         Point2D.Double JavaDoc point;
113
114         for( int dataSet = 0; dataSet < iScatterPlotDataSet.getNumberOfDataSets(); dataSet++ )
115         {
116             for( int index = 0; index < iScatterPlotDataSet.getNumberOfDataItems(); index++ )
117             {
118                 point = iScatterPlotDataSet.getValue( dataSet, index );
119
120                 if( point == null )
121                 {
122                     continue;
123                 }
124
125                 if( point.getX() > super.getMaxValue() )
126                 {
127                     super.setMaxValue( point.getX() );
128                 }
129
130                 if( point.getX() < super.getMinValue() )
131                 {
132                     super.setMinValue( point.getX() );
133                 }
134
135                 if( point.getY() > this.getyMax() )
136                 {
137                     this.setyMax( point.getY() );
138                 }
139
140                 if( point.getY() < this.getyMin() )
141                 {
142                     this.setyMin( point.getY() );
143                 }
144             }
145         }
146
147         //System.out.println( this.toString() );
148
}
149
150
151     /******************************************************************************************
152      *
153      ******************************************************************************************/

154     public double getyMax()
155     {
156         return yMax;
157     }
158
159
160     /******************************************************************************************
161      *
162      ******************************************************************************************/

163     public void setyMax( double yMax )
164     {
165         this.yMax = yMax;
166     }
167
168
169     /******************************************************************************************
170      *
171      ******************************************************************************************/

172     public double getyMin()
173     {
174         return yMin;
175     }
176
177
178     /******************************************************************************************
179      *
180      ******************************************************************************************/

181     public void setyMin( double yMin )
182     {
183         this.yMin = yMin;
184     }
185
186
187     /******************************************************************************************
188      *
189      ******************************************************************************************/

190     public String JavaDoc toString()
191     {
192         StringBuffer JavaDoc s= new StringBuffer JavaDoc( 60 );
193         s.append( this.getClass().getName() );
194         s.append( ": xMin= " + super.getMinValue() );
195         s.append( " xMax= " + super.getMaxValue() );
196         s.append( " yMin= " + this.yMin );
197         s.append( " yMax= " + this.yMax );
198         return s.toString();
199     }
200
201
202     /*********************************************************************************************
203      * Enables the testing routines to display the contents of this Object.
204      *
205      * @param htmlGenerator
206      **********************************************************************************************
207      public void toHTML( HTMLGenerator htmlGenerator )
208      {
209      super.toHTML( htmlGenerator );
210
211      String name= this.getClass().getSuperclass().getName() + "->";
212
213      //---calling on instance of YAxis or XAxis
214      Field[] fields= this.getClass().getSuperclass().getDeclaredFields();
215      for( int i=0; i< fields.length; i++ )
216      {
217      htmlGenerator.addField( name + fields[ i ].getName(), fields[ i ].get( this ) );
218      }
219      }
220      */

221 }
222
Popular Tags