001: /***********************************************************************************************
002: * File Info: $Id: AxisChartDataProcessor.java,v 1.2 2003/08/08 08:51:27 nicolaken Exp $
003: * Copyright (C) 2000
004: * Author: Nathaniel G. Auvil
005: * Contributor(s):
006: *
007: * Copyright 2002 (C) Nathaniel G. Auvil. All Rights Reserved.
008: *
009: * Redistribution and use of this software and associated documentation
010: * ("Software"), with or without modification, are permitted provided
011: * that the following conditions are met:
012: *
013: * 1. Redistributions of source code must retain copyright
014: * statements and notices. Redistributions must also contain a
015: * copy of this document.
016: *
017: * 2. Redistributions in binary form must reproduce the
018: * above copyright notice, this list of conditions and the
019: * following disclaimer in the documentation and/or other
020: * materials provided with the distribution.
021: *
022: * 3. The name "jCharts" or "Nathaniel G. Auvil" must not be used to
023: * endorse or promote products derived from this Software without
024: * prior written permission of Nathaniel G. Auvil. For written
025: * permission, please contact nathaniel_auvil@users.sourceforge.net
026: *
027: * 4. Products derived from this Software may not be called "jCharts"
028: * nor may "jCharts" appear in their names without prior written
029: * permission of Nathaniel G. Auvil. jCharts is a registered
030: * trademark of Nathaniel G. Auvil.
031: *
032: * 5. Due credit should be given to the jCharts Project (http://jcharts.sourceforge.net/).
033: *
034: * THIS SOFTWARE IS PROVIDED BY Nathaniel G. Auvil AND CONTRIBUTORS
035: * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
036: * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
037: * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
038: * jCharts OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
039: * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
040: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
041: * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
042: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
043: * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
044: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
045: * OF THE POSSIBILITY OF SUCH DAMAGE.
046: ************************************************************************************************/package org.krysalis.jcharts.chartData.processors;
047:
048: import java.awt.font.FontRenderContext;
049: import java.util.Iterator;
050:
051: import org.krysalis.jcharts.axisChart.AxisChart;
052: import org.krysalis.jcharts.chartData.interfaces.IAxisChartDataSet;
053: import org.krysalis.jcharts.chartData.interfaces.IAxisPlotDataSet;
054: import org.krysalis.jcharts.chartData.interfaces.IDataSeries;
055: import org.krysalis.jcharts.chartData.interfaces.IStockChartDataSet;
056: import org.krysalis.jcharts.properties.DataAxisProperties;
057: import org.krysalis.jcharts.types.ChartType;
058:
059: /*******************************************************************************************
060: *
061: ********************************************************************************************/
062: public class AxisChartDataProcessor {
063: private double max;
064: private double min;
065:
066: //private TextLayout titleTextLayout;
067:
068: //---need this so know how many items are on the 'label' axis.
069: private int numberOfElementsInADataSet;
070:
071: /******************************************************************************************
072: * Constructor
073: *
074: *******************************************************************************************/
075: public AxisChartDataProcessor() {
076:
077: }
078:
079: /******************************************************************************************
080: * Method to perform all chart data processing.
081: *
082: * @param axisChart
083: ******************************************************************************************/
084: public void processData(AxisChart axisChart,
085: FontRenderContext fontRenderContext) {
086: //todo would it make sense to do this and do the axis titles?
087: /*
088: if( axisChart.getIDataSeries().getChartTitle() != null )
089: {
090: this.titleTextLayout= new TextLayout( axisChart.getIDataSeries().getChartTitle(),
091: axisChart.getChartProperties().getTitleFont(),
092: fontRenderContext );
093: }
094: */
095:
096: DataAxisProperties dataAxisProperties;
097: if (axisChart.getAxisProperties().isPlotHorizontal()) {
098: dataAxisProperties = (DataAxisProperties) axisChart
099: .getAxisProperties().getXAxisProperties();
100: } else {
101: dataAxisProperties = (DataAxisProperties) axisChart
102: .getAxisProperties().getYAxisProperties();
103: }
104:
105: //---if there is a user defined scale, there is no reason to process the data.
106: if (!dataAxisProperties.hasUserDefinedScale()) {
107: this .processDataSet((IDataSeries) axisChart
108: .getIAxisDataSeries());
109: }
110:
111: //---need to set the number of items on the scale in case there are no labels displayed
112: Iterator iterator = axisChart.getIAxisDataSeries()
113: .getIAxisPlotDataSetIterator();
114: IAxisPlotDataSet iAxisPlotDataSet = (IAxisPlotDataSet) iterator
115: .next();
116: this .numberOfElementsInADataSet = iAxisPlotDataSet
117: .getNumberOfDataItems();
118:
119: //todo does it make sense to do the legend label processing here?
120: /*
121: if( axisChart.hasLegend() )
122: {
123: //this.lengendLabelProcessor= new TextProcessor();
124: // this.lengendLabelProcessor
125: }
126: */
127: }
128:
129: /******************************************************************************************
130: * Processes the numeric values in the chart data. If there is a user defined scale
131: * there is no need to call this.
132: *
133: * @param iDataSeries
134: ******************************************************************************************/
135: private void processDataSet(IDataSeries iDataSeries) {
136: IAxisPlotDataSet iAxisPlotDataSet;
137: Iterator iterator = iDataSeries.getIAxisPlotDataSetIterator();
138:
139: //LOOP
140: while (iterator.hasNext()) {
141: iAxisPlotDataSet = (IAxisPlotDataSet) iterator.next();
142:
143: if (iAxisPlotDataSet.getChartType().isStacked()) {
144: //---StockChartDataSet is NEVER stacked!!!!
145: StackedDataProcessor.processData(
146: (IAxisChartDataSet) iAxisPlotDataSet, this );
147: } else {
148: //---stock charts dont fit well here as the data comes in structured.
149: //---in this case only care about the high and low; no need to search close, open, volume
150: if (iAxisPlotDataSet.getChartType().equals(
151: ChartType.STOCK)) {
152: StockDataProcessor
153: .processData(
154: (IStockChartDataSet) iAxisPlotDataSet,
155: this );
156: } else {
157: NonStackedDataProcessor.processData(
158: (IAxisChartDataSet) iAxisPlotDataSet, this );
159: }
160: }
161: }
162: }
163:
164: /******************************************************************************************
165: *
166: *
167: ******************************************************************************************/
168: void setMaxValue(double max) {
169: this .max = max;
170: }
171:
172: /******************************************************************************************
173: *
174: *
175: *
176: ******************************************************************************************/
177: public double getMaxValue() {
178: return this .max;
179: }
180:
181: /******************************************************************************************
182: *
183: *
184: ******************************************************************************************/
185: void setMinValue(double min) {
186: this .min = min;
187: }
188:
189: /******************************************************************************************
190: *
191: *
192: *
193: ******************************************************************************************/
194: public double getMinValue() {
195: return this .min;
196: }
197:
198: public int getNumberOfElementsInADataSet() {
199: return numberOfElementsInADataSet;
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: }
|