📄 xaxis.java
字号:
else
{
super.setScalePixelWidth( getPixelLength() / this.getNumberOfScaleItems() );
}
}
/*********************************************************************************************
* Renders the YAxis on the passes Graphics2D object
*
* @param graphics2D
* @param axisProperties
* @param axisTitle
**********************************************************************************************/
public void render( Graphics2D graphics2D,
AxisProperties axisProperties,
String axisTitle )
{
AxisTypeProperties axisTypeProperties = axisProperties.getXAxisProperties();
//---AXIS TITLE
this.renderAxisTitle( axisTitle, graphics2D, axisTypeProperties );
Line2D.Float line2D = new Line2D.Float( super.getTickStart(), 0.0f, super.getTickStart(), 0.0f );
float tickY1 = super.getAxisChart().getYAxis().getOrigin();
float tickY2 = super.getAxisChart().getYAxis().getOrigin() + axisTypeProperties.getAxisTickMarkPixelLength();
float gridLineY1 = super.getAxisChart().getYAxis().getOrigin();
float gridLineY2 = super.getAxisChart().getYAxis().getOrigin() - super.getAxisChart().getYAxis().getPixelLength();
float stringX = super.getTickStart();
float stringY = super.getAxisChart().getYAxis().getOrigin();
if( axisTypeProperties.getShowTicks() != AxisTypeProperties.TICKS_NONE )
{
stringY += axisTypeProperties.getAxisTickMarkPixelLength() + axisTypeProperties.getPaddingBetweenLabelsAndTicks();
}
else
{
stringY += axisTypeProperties.getPaddingBetweenAxisAndLabels();
}
if( axisTypeProperties.showAxisLabels() )
{
//---if the scale labels are horizontal, simply add the tallest label height.
//---Otherwise we will have to calculate it when we draw the label
if( !axisProperties.xAxisLabelsAreVertical() )
{
stringY += super.getAxisLabelsGroup().getTallestLabel();
graphics2D.setFont( axisTypeProperties.getScaleChartFont().getFont() );
}
else
{
stringX -= super.getAxisLabelsGroup().getTextTag( 0 ).getFontDescent();
graphics2D.setFont( axisTypeProperties.getScaleChartFont().deriveFont() );
}
}
//LOOP
//for( int i = 0; i < super.getAxisLabelsGroup().size(); i++ )
for( int i = 0; i < super.getNumberOfScaleItems(); i++ )
{
//---GRID LINES
if( axisTypeProperties.getShowGridLines() != AxisTypeProperties.GRID_LINES_NONE )
{
if( ( i == 0 && !( axisTypeProperties instanceof DataAxisProperties ) )
|| ( i > 0 && ( (axisTypeProperties.getShowGridLines() == AxisTypeProperties.GRID_LINES_ALL) || (axisTypeProperties.getShowGridLines() == AxisTypeProperties.GRID_LINES_ONLY_WITH_LABELS && (i % this.xLabelFilter == 0)) ) ) )
{
line2D.y1 = gridLineY1;
line2D.y2 = gridLineY2;
if( i < super.getAxisLabelsGroup().size()
|| (i == super.getAxisLabelsGroup().size() && !axisTypeProperties.getShowEndBorder()) )
{
axisTypeProperties.getGridLineChartStroke().draw( graphics2D, line2D );
}
}
}
//---TICK MARKS
//if( i != super.getAxisLabelsGroup().size() )
if( i != super.getNumberOfScaleItems() )
{
if( (axisTypeProperties.getShowTicks() == AxisTypeProperties.TICKS_ALL)
|| (axisTypeProperties.getShowTicks() == AxisTypeProperties.TICKS_ONLY_WITH_LABELS
&& (i % this.xLabelFilter == 0)) )
{
line2D.y1 = tickY1;
line2D.y2 = tickY2;
axisTypeProperties.getTickChartStroke().setupGraphics2D( graphics2D );
graphics2D.draw( line2D );
}
}
line2D.x1 += super.getScalePixelWidth();
line2D.x2 = line2D.x1;
//---AXIS LABEL
if( axisTypeProperties.showAxisLabels() && (i % this.xLabelFilter == 0) )
{
graphics2D.setPaint( axisTypeProperties.getScaleChartFont().getPaint() );
if( !axisProperties.xAxisLabelsAreVertical() )
{
//graphics2D.drawString( iDataSeries.getXAxisLabel( i ), stringX - super.getAxisLabelsGroup().getTextTag( i ).getWidth() / 2, stringY );
float x = stringX - super.getAxisLabelsGroup().getTextTag( i ).getWidth() / 2;
//---we can not only look at the last label as there could be a filter and labels near the last might go off the edge of the screen.
if( x + super.getAxisLabelsGroup().getTextTag( i ).getWidth() < super.getAxisChart().getImageWidth() )
{
super.getAxisLabelsGroup().getTextTag( i ).render( graphics2D, x, stringY );
}
}
else
{
float x = stringX + super.getAxisLabelsGroup().getTextTag( i ).getHeight() / 2;
//---we can not only look at the last label as there could be a filter and labels near the last might go off the edge of the screen.
if( x + super.getAxisLabelsGroup().getTextTag( i ).getHeight() < super.getAxisChart().getImageWidth() )
{
graphics2D.drawString( super.getAxisLabelsGroup().getTextTag( i ).getText(), x, stringY + super.getAxisLabelsGroup().getTextTag( i ).getWidth() );
}
}
}
stringX += super.getScalePixelWidth();
}
//---RIGHT BORDER-----------------------------------------------------------
if( axisTypeProperties.getShowEndBorder() )
{
//---make sure no rounding errors
line2D.x1 = super.getOrigin() + super.getPixelLength() + 1;
line2D.x2 = line2D.x1;
line2D.y1 = gridLineY1;
line2D.y2 = gridLineY2;
axisProperties.getYAxisProperties().getAxisStroke().draw( graphics2D, line2D );
}
//---AXIS-------------------------------------------------------------------
line2D.x1 = super.getOrigin();
line2D.x2 = super.getOrigin() + super.getPixelLength();
line2D.y1 = super.getAxisChart().getYAxis().getOrigin();
line2D.y2 = line2D.y1;
axisTypeProperties.getAxisStroke().setupGraphics2D( graphics2D );
graphics2D.draw( line2D );
//---ZERO LINE-----------------------------------------------------------------
if( axisTypeProperties instanceof DataAxisProperties )
{
DataAxisProperties dataAxisProperties = (DataAxisProperties) axisTypeProperties;
if( dataAxisProperties.showZeroLine()
&& super.getScaleCalculator().getMinValue() < 0.0d
&& super.getScaleCalculator().getMaxValue() > 0.0d )
{
line2D.x1 = super.getZeroLineCoordinate();
line2D.x2 = line2D.x1;
line2D.y1 = super.getAxisChart().getYAxis().getOrigin();
line2D.y2 = super.getAxisChart().getYAxis().getOrigin() - super.getAxisChart().getYAxis().getPixelLength();
dataAxisProperties.getZeroLineChartStroke().draw( graphics2D, line2D );
}
}
}
/************************************************************************************************
* Method to compute the filter to use on the x-axis label display so labels do not overlap
*
*************************************************************************************************/
public void computeLabelFilter()
{
if( super.getAxisChart().getAxisProperties().getXAxisProperties().showAxisLabels() )
{
float widestLabelSize;
AxisTypeProperties axisTypeProperties = super.getAxisChart().getAxisProperties().getXAxisProperties();
if( super.getAxisChart().getAxisProperties().xAxisLabelsAreVertical() )
{
widestLabelSize = super.getAxisLabelsGroup().getTallestLabel();
}
else
{
widestLabelSize = super.getAxisLabelsGroup().getWidestLabel();
}
double numberLabelsCanDisplay = this.getPixelLength() / (widestLabelSize + axisTypeProperties.getPaddingBetweenAxisLabels());
this.xLabelFilter = (int) Math.ceil( super.getAxisLabelsGroup().size() / numberLabelsCanDisplay );
}
else
{
this.xLabelFilter= 1;
}
}
/*********************************************************************************************
* Enables the testing routines to display the contents of this Object.
*
* @param htmlGenerator
**********************************************************************************************/
public void toHTML( HTMLGenerator htmlGenerator )
{
htmlGenerator.propertiesTableStart( this.getClass().getName() );
super.toHTML( htmlGenerator );
Field[] fields = this.getClass().getDeclaredFields();
for( int i = 0; i < fields.length; i++ )
{
try
{
htmlGenerator.addField( fields[ i ].getName(), fields[ i ].get( this ) );
}
catch( IllegalAccessException illegalAccessException )
{
illegalAccessException.printStackTrace();
}
}
htmlGenerator.propertiesTableEnd();
}
/*************************************************************************************************
* Takes a value and determines the screen coordinate it should be drawn at. THe only difference
* between this and the y-axis is we add to the origin versus subtract from it.
*
* @param origin
* @param value
* @param axisMinValue the minimum value on the axis
* @return float the screen pixel coordinate
**************************************************************************************************/
public float computeAxisCoordinate( float origin, double value, double axisMinValue )
{
double returnValue = origin + (value - axisMinValue) * this.getOneUnitPixelSize();
//System.out.println( "computeAxisCoordinate( " + origin + ", " + value + ", " + axisMinValue + " ) = " + returnValue );
return (float) returnValue;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -