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

📄 xaxis.java

📁 jCharts是一个100%基于Java的制图工具
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/***********************************************************************************************
 * File Info: $Id: XAxis.java,v 1.20 2003/10/15 03:23:15 nathaniel_auvil Exp $
 * Copyright (C) 2002
 * Author: Nathaniel G. Auvil
 * Contributor(s): John Thomsen
 *
 * 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.axisChart.AxisChart;
import org.jCharts.properties.*;
import org.jCharts.test.HTMLGenerator;
import org.jCharts.test.HTMLTestable;
import org.jCharts.chartData.interfaces.IAxisPlotDataSet;
import org.jCharts.chartData.interfaces.IAxisDataSeries;
import org.jCharts.types.ChartType;

import java.awt.*;
import java.awt.geom.Line2D;
import java.lang.reflect.Field;
import java.util.Iterator;


public final class XAxis extends Axis implements HTMLTestable
{
	//---indicates which labels to display 1=every, 2=every other, 3=every third, etc...
	private int xLabelFilter = 1;

	//---for some charts such as line, point, area, etc... we want to start plot at y-axis
	private boolean startTicksAtAxis;


	/**************************************************************************************************
	 *
	 * @param axisChart
	 * @param numberOfScaleItems
	 ***************************************************************************************************/
	public XAxis( AxisChart axisChart, int numberOfScaleItems )
	{
		super( axisChart, numberOfScaleItems );
	}


	/*************************************************************************************************
	 * Computes the minimum pixel height required for the X-Axis.
	 *  Includes space, if needed, for: axis title + padding, axis values + tick padding, and tick marks.
	 *
	 * @param axisTitle
	 **************************************************************************************************/
	public void computeMinimumHeightNeeded( String axisTitle )
	{
		float heightNeeded = 0;
		AxisProperties axisProperties = super.getAxisChart().getAxisProperties();
		AxisTypeProperties axisTypeProperties = axisProperties.getXAxisProperties();


		if( axisTypeProperties.showAxisLabels() )
		{
			if( axisProperties.xAxisLabelsAreVertical() )
			{
				//---widest label for vertical labels
				//heightNeeded = axisChartDataProcessor.getAxisLabelProcessor().getWidestLabel();
				heightNeeded = super.getAxisLabelsGroup().getWidestLabel();
			}
			else
			{
				//---tallest label for horizontal labels
				//heightNeeded = axisChartDataProcessor.getAxisLabelProcessor().getTallestLabel();
				heightNeeded = super.getAxisLabelsGroup().getTallestLabel();

				//---not sure why i need more padding
				heightNeeded += 3;
			}
		}


		if( axisTypeProperties.getShowTicks() != AxisTypeProperties.TICKS_NONE )
		{
			if( axisTypeProperties.showAxisLabels() )
			{
				//---add the padding between scale labels and tick marks
				heightNeeded += axisTypeProperties.getPaddingBetweenLabelsAndTicks();
			}

			//---add width of tick marks
			heightNeeded += axisTypeProperties.getAxisTickMarkPixelLength();
		}
		else
		{
			//---use specified distance between labels and axis
			heightNeeded += axisTypeProperties.getPaddingBetweenAxisAndLabels();
		}


		//---include axis title height if needed. Remember it is vertical for y-axis
		if( axisTitle != null )
		{
			super.computeAxisTitleDimensions( axisTitle, axisTypeProperties.getTitleChartFont() );
			heightNeeded += super.getTitleHeight();
			heightNeeded += axisTypeProperties.getPaddingBetweenAxisTitleAndLabels();
		}

		super.setMinimumHeightNeeded( heightNeeded );
	}


	/*************************************************************************************************
	 * Computes the number of pixels between each value on the axis.
	 *
	 **************************************************************************************************
	 public void computeScalePixelWidth( int numberOfValuesOnXAxis )
	 {
	 super.setScalePixelWidth( super.getPixelLength() / numberOfValuesOnXAxis );
	 }


	 /****************************************************************************************************
	 *
	 * @param axisTitle
	 * @param graphics2D
	 * @param axisTypeProperties
	 ***************************************************************************************************/
	private void renderAxisTitle( String axisTitle, Graphics2D graphics2D, AxisTypeProperties axisTypeProperties )
	{
		if( axisTitle != null )
		{
			float titleX;
			float titleY = super.getAxisChart().getYAxis().getOrigin() + this.getMinimumHeightNeeded() - super.getTitleHeight();

			//---if title is larger than the axis itself, place at top.
			if( super.getTitleWidth() > super.getPixelLength() )
			{
				titleX = ((super.getAxisChart().getImageWidth() - super.getTitleWidth()) / 2);
			}
			//---else, center on XAxis.
			else
			{
				titleX = super.getOrigin() + ((super.getPixelLength() - super.getTitleWidth()) / 2);
			}


			axisTypeProperties.getAxisTitleChartFont().setupGraphics2D( graphics2D );
			graphics2D.drawString( axisTitle, titleX, titleY );
		}
	}


	/***************************************************************************************
	 * Determines if we should start x-axis ticks at the y-axis or space it out a half
	 * 	a scale item width.
	 *
	 * @param iAxisDataSeries
	 * @param axisTypeProperties
	 **************************************************************************************/
	public void computeShouldTickStartAtYAxis( IAxisDataSeries iAxisDataSeries,
															 AxisTypeProperties axisTypeProperties )
	{
		//---if horizontal plot, x-axis is the data axis, so always start data points at y-axis
		if( axisTypeProperties instanceof DataAxisProperties )
		{
			this.startTicksAtAxis= true;
		}
		else
		{
			this.startTicksAtAxis= true;

			//---else, there are a couple of plots we do not start x-axis values at the y-axis
			IAxisPlotDataSet iAxisPlotDataSet;
			Iterator iterator= iAxisDataSeries.getIAxisPlotDataSetIterator();

			while( iterator.hasNext() )
			{
				iAxisPlotDataSet= (IAxisPlotDataSet) iterator.next();
				if( iAxisPlotDataSet.getChartType().equals( ChartType.BAR )
					|| iAxisPlotDataSet.getChartType().equals( ChartType.BAR_CLUSTERED )
					|| iAxisPlotDataSet.getChartType().equals( ChartType.BAR_STACKED )
					|| iAxisPlotDataSet.getChartType().equals( ChartType.LINE )
					|| iAxisPlotDataSet.getChartType().equals( ChartType.POINT )
					|| iAxisPlotDataSet.getChartType().equals( ChartType.STOCK ) )
				{
					this.startTicksAtAxis= false;
					break;
				}
			}
		}
	}


	/***************************************************************************************
	 * Computes the screen pixel location of the first tick mark
	 *
	 **************************************************************************************/
	public void computeTickStart()
	{
		float tickStart= super.getOrigin();

		if( ! this.startTicksAtAxis )
		{
			tickStart+= (super.getScalePixelWidth() / 2);
		}

      super.setTickStart( tickStart );
	}


	/*************************************************************************************************
	 * Computes the number of pixels between each value on the axis.
	 *
	 **************************************************************************************************/
	public void computeScalePixelWidth()
	{
		if( this.startTicksAtAxis )
		{
			super.computeScalePixelWidthDataAxis();
		}

⌨️ 快捷键说明

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