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.axisChart.axis.scale;
034:
035: import org.krysalis.jcharts.axisChart.axis.scale.ScaleCalculator;
036:
037: /*************************************************************************************
038: *
039: * @author Nathaniel Auvil, Mike Lissick
040: * @version $Id: UserDefinedScaleCalculator.java,v 1.1 2003/05/17 16:54:37 nathaniel_auvil Exp $
041: ************************************************************************************/
042: public class UserDefinedScaleCalculator extends ScaleCalculator {
043: private double userDefinedMinimum;
044: private double userDefinedIncrement;
045:
046: /****************************************************************************************
047: *
048: * It would seem to make sense to pass in the min and the max, but we want to allow
049: * people to use custom implementations which will be created when the AxisChart
050: * constructor gets called and we will not have looped the data to find the min
051: * and max yet. No sense in making people do that when we will do that already.
052: *
053: * @param userDefinedMinimum
054: * @param userDefinedIncrement
055: ***************************************************************************************/
056: public UserDefinedScaleCalculator(double userDefinedMinimum,
057: double userDefinedIncrement) {
058: this .userDefinedMinimum = userDefinedMinimum;
059: this .userDefinedIncrement = userDefinedIncrement;
060: }
061:
062: /*********************************************************************************************
063: * Computes the axis increment WITHOUT taking into account the user specified rounding
064: * criteria and sets it to the super class increment variable. You can extend this class
065: * and override this method to compute you own scale.
066: *
067: ********************************************************************************************/
068: protected void computeIncrement() {
069: super .increment = this .userDefinedIncrement;
070:
071: double powerOfTen = Math.pow(10, Math.abs(this
072: .getRoundingPowerOfTen()));
073:
074: //---round the increment according to user defined power
075: super .increment = super .round(super .increment, powerOfTen);
076:
077: //---if we round this down to zero, force it to the power of ten.
078: //---for example, round to nearest 100, value = 35...would push down to 0 which is illegal.
079: if (super .increment == 0) {
080: super .increment = powerOfTen;
081: }
082:
083: super .setMinValue(super .round(this .userDefinedMinimum,
084: powerOfTen));
085: super .setMaxValue(super .getMinValue()
086: + (super .increment * super .getNumberOfScaleItems()));
087:
088: }
089:
090: /*********************************************************************************************
091: * Drives the computation of the axis increment and related values taking into account the
092: * user specified rounding criteria and sets it to the super class increment variable.
093: *
094: * So if you specify to round to the nearest 100 and give an increment of 2.5, the increment
095: * will become 100.
096: *
097: * @param numberOfScaleItems
098: ********************************************************************************************
099: public void roundScaleValues( double powerOfTen, int numberOfScaleItems )
100: {
101: //---round the increment according to user defined power
102: super.increment = super.round( super.increment, powerOfTen );
103:
104: //---if we round this down to zero, force it to the power of ten.
105: //---for example, round to nearest 100, value = 35...would push down to 0 which is illegal.
106: if( super.increment == 0 )
107: {
108: super.increment = powerOfTen;
109: }
110:
111: super.setMinValue( super.round( this.userDefinedMinimum, powerOfTen ) );
112: super.setMaxValue( super.getMinValue() + ( super.increment * numberOfScaleItems ) );
113: }
114: */
115: }
|