⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dataaxis.java

📁 jCharts是一个100%基于Java的制图工具
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/***********************************************************************************************
 * File: DataAxis - derived from YAxis.java
 * Last Modified: $Id: DataAxis.java,v 1.4 2003/03/09 22:42:10 nathaniel_auvil Exp $
 * Copyright (C) 2000
 * Author: John Thomsen
 * Contributor(s):
 *
 * Copyright 2002 (C) Nathaniel G. Auvil. All Rights Reserved.
 *
 * Redistribution and use of this software and associated documentation
 * ("Software"), with or without modification, are permitted provided
 * that the following conditions are met:
 *
 * 1. Redistributions of source code must retain copyright
 *    statements and notices.  Redistributions must also contain a
 *    copy of this document.
 *
 * 2. Redistributions in binary form must reproduce the
 *    above copyright notice, this list of conditions and the
 *    following disclaimer in the documentation and/or other
 *    materials provided with the distribution.
 *
 * 3. The name "jCharts" or "Nathaniel G. Auvil" must not be used to
 * 	  endorse or promote products derived from this Software without
 * 	  prior written permission of Nathaniel G. Auvil.  For written
 *    permission, please contact nathaniel_auvil@users.sourceforge.net
 *
 * 4. Products derived from this Software may not be called "jCharts"
 *    nor may "jCharts" appear in their names without prior written
 *    permission of Nathaniel G. Auvil. jCharts is a registered
 *    trademark of Nathaniel G. Auvil.
 *
 * 5. Due credit should be given to the jCharts Project
 *    (http://jcharts.sourceforge.net/).
 *
 * THIS SOFTWARE IS PROVIDED BY Nathaniel G. Auvil AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
 * jCharts OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 ************************************************************************************************/

package org.jCharts.axisChart.axis;


import org.jCharts.chartData.interfaces.IDataSeries;
import org.jCharts.chartData.processors.AxisChartDataProcessor;
import org.jCharts.test.HTMLGenerator;
import org.jCharts.test.HTMLTestable;
import org.jCharts.axisChart.AxisChart;


import java.awt.*;


/****
 *
 * @deprecated just using the YAxis Object
 */
public class DataAxis extends Axis implements HTMLTestable
{
	//---these values are not the same as the data set min and max;
	//---these are what is displayed on screen which includes padding.
	private double minValue;
	private double maxValue;

	//---Difference between the points on the axis.
	//---ie-> if 10 and the origin was 0, the values would be 0,10,20,30,etc...
	private double increment;


	//---multiplication value used to determine the coordinate location of values on YAxis
	//private double oneUnitPixelSize;

	//---not always equal to the origin as charts may not start at zero.
	protected float zeroLineCoordinate;


	/*****
	 *
	 * @param axisChart
	 * @deprecated this class is no longer used
	 */
	public DataAxis( AxisChart axisChart )
	{
		super( axisChart, 0 );
	}


	protected boolean amDataAxis()
	{
		return true;
	}


	protected boolean amLabelAxis()
	{
		return false;
	}


	/*************************************************************************************************
	 * Add all text labels to be display on this axis.
	 *
	 **************************************************************************************************/
	public void addTextTags()
	{
/*
		NumberFormat numberFormat;
		AxisProperties axisProperties = super.getAxisChart().getAxisProperties();

		Font font = axisProperties.getScaleFont();
		Font derivedFont = null;

		if( super.getVerticalScaleFlag() )
		{
			derivedFont = font.deriveFont( Axis.VERTICAL_LABEL_ROTATION );
		}

		this.textTagGroup = new TextTagGroup(
		   font,
		   derivedFont,
		   axisProperties.getScaleFontColor(),
		   super.getAxisChart().getGraphics2D().getFontRenderContext() );

		super.setNumberOfLabelsOnAxis( super.getAxisChart().getAxisProperties().getDataAxisNumItems() );

		if( showText() == false ) return;

		double value = this.minValue;

		//---DOLLAR SIGNS
		if( axisProperties.getDataAxisUseDollarSigns() )
		{
			numberFormat = NumberFormat.getCurrencyInstance();
		}
		else
		{
			numberFormat = NumberFormat.getInstance();
		}

		//---COMMAS
		if( axisProperties.getDataAxisUseCommas() )
		{
			numberFormat.setGroupingUsed( true );
		}
		else
		{
			numberFormat.setGroupingUsed( false );
		}

		//---TRIM OFF DECIMAL PLACES IF ROUND TO WHOLE NUMBER
		if( axisProperties.getDataAxisRoundValuesToNearest() >= 0 )
		{
			numberFormat.setMaximumFractionDigits( 0 );
			numberFormat.setMinimumFractionDigits( 0 );
		}
		else
		{
			numberFormat.setMaximumFractionDigits( -axisProperties.getDataAxisRoundValuesToNearest() );
			numberFormat.setMinimumFractionDigits( -axisProperties.getDataAxisRoundValuesToNearest() );
		}

		//LOOP
		for( int i = 0; i <= super.getAxisChart().getAxisProperties().getDataAxisNumItems(); i++ )
		{
			textTagGroup.addTextTag( numberFormat.format( value ) );

			value += this.increment;
		}

		super.setWidestLabel( textTagGroup.getWidestTextTag() );
		super.setTallestLabel( textTagGroup.getTallestTextTag() );
*/

	}


	/*******************************************************************************************
	 * Calculates the axis scale increment.
	 *
	 * If the user does not specify a scale, it is auto computed in the followin way:
	 *  <LI>if all values are positive, the MIN value will be zero.</LI>
	 *  <LI>if all values are negative, the MAX value will be zero.</LI>
	 *  <LI>Padding is done by either adding or subtracting the increment by the rounding power of ten
	 *  specified in the properties.</LI>
	 *
	 * @param axisChartDataProcessor need to get the min/max
	 ********************************************************************************************/
	void computeScaleIncrement( AxisChartDataProcessor axisChartDataProcessor )
	{
/*
		AxisProperties axisProperties = super.getAxisChart().getAxisProperties();

		int numScaleItems = axisProperties.getDataAxisNumItems();
		double powerOfTen = Math.pow( 10.0d, Math.abs( (double) super.getAxisChart().getAxisProperties().getDataAxisRoundValuesToNearest() ) );

		if( axisProperties.hasUserDefinedScale() )
		{
			this.increment = this.round( axisProperties.getUserDefinedDataAxisIncrement(), powerOfTen );

			//---if we round this down to zero, force it to the power of ten.
			//---for example, round to nearest 100, value = 35...would push down to 0 which is illegal.
			if( this.increment == 0 )
			{
				this.increment = powerOfTen;
			}

			this.minValue = this.round( axisProperties.getUserDefinedDataAxisMinimum(), powerOfTen );
			this.maxValue = this.minValue + ( this.increment * numScaleItems );
		}
		//---else, we will determine the axis scale to use
		else
		{


			double range;

			//---if MIN >= 0, MAX is the range, if MAX < 0, -MIN is the range
			if( ( axisChartDataProcessor.getMinValue() >= 0 ) || ( axisChartDataProcessor.getMaxValue() < 0 ) )
			{
				range = Math.max( axisChartDataProcessor.getMaxValue(), -axisChartDataProcessor.getMinValue() );

				this.increment = range / numScaleItems;
				this.roundTheIncrement( powerOfTen );

				if( axisChartDataProcessor.getMinValue() >= 0 )
				{
					this.minValue = 0.0d;
					this.maxValue = this.increment * numScaleItems;
				}
				else
				{
					this.maxValue = 0.0d;
					this.minValue = -( this.increment * numScaleItems );
				}

			// data is the double[][] with the chart values.  getMax just finds the largest point anywhere in the array.
			double yMax = this.maxValue;
			double yMin = this.minValue;

			// In the following line, note that Math.log is actually Natural Logarithm.
			// log base a of b = ln b / ln a => log base 10 of x = ln 10 / ln x
			//double yDelta = Math.pow( 10.0, Math.round( Math.log( yMax - yMin ) / Math.log( 10 ) ) );
			double yDelta = Math.pow( 10.0, Math.round( Math.log( range ) / Math.log( 10 ) ) );
			double yStart = yMin - ( yMin % yDelta );
			double yEnd = yMax - ( yMax % yDelta ) + yDelta;

			// Count the number of segments this gives us.  Shoot for 20 segments or so.
			int segments = (int) ( ( yEnd - yStart ) / yDelta );
			if( segments <= 2 )
			{
				// we need 10 times this many
				yDelta = yDelta / 10.0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -