krysalis-jcharts/src/java/org/krysalis/jcharts/axisChart/axis YAxis.java,1.5,1.6
Chris McKay <[email protected]> Thu, 01 Jul 2004 01:33:31 +0000
| Newsgroups | gmane.comp.krysalis.jcharts.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/jcharts/krysalis-jcharts/src/java/org/krysalis/jcharts/axisChart/axis
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7278/src/java/org/krysalis/jcharts/axisChart/axis
Modified Files:
YAxis.java
Log Message:
Dual Y axis changes
Index: YAxis.java
===================================================================
RCS file: /cvsroot/jcharts/krysalis-jcharts/src/java/org/krysalis/jcharts/axisChart/axis/YAxis.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** YAxis.java 31 May 2004 16:29:47 -0000 1.5
--- YAxis.java 1 Jul 2004 01:33:29 -0000 1.6
***************
*** 46,49 ****
--- 46,50 ----
import java.awt.geom.Line2D;
import java.lang.reflect.Field;
+ import java.awt.font.TextLayout;
***************
*** 86,118 ****
*
**************************************************************************************************/
! public void computeMinimumWidthNeeded( String yAxisTitle )
{
AxisTypeProperties axisTypeProperties= super.getAxisChart().getAxisProperties().getYAxisProperties();
! float widthNeeded = 0;
!
//---if we are displaying axis scale labels, add width of widest label
! if( axisTypeProperties.showAxisLabels() )
! {
! // Dual Y axis changes integrated CMC 25Aug03
! //widthNeeded+= super.getAxisLabelsGroup().getWidestLabel();
! if ( axisTypeProperties.getShowRightAxis() )
! {
! if ( super.getAxisLabelsGroupRight().getWidestLabel()>super.getAxisLabelsGroup().getWidestLabel())
! {
! widthNeeded+= super.getAxisLabelsGroupRight().getWidestLabel();
! }
! else
! {
! widthNeeded+= super.getAxisLabelsGroup().getWidestLabel();
! }
! }
! else
! {
! widthNeeded+= super.getAxisLabelsGroup().getWidestLabel();
! }
! }
--- 87,120 ----
*
**************************************************************************************************/
! public void computeMinimumWidthNeeded( String yAxisTitle, String rightYAxisTitle )
{
+ float widthNeeded = 0;
AxisTypeProperties axisTypeProperties= super.getAxisChart().getAxisProperties().getYAxisProperties();
+ AxisTypeProperties rightAxisTypeProperties = super.getAxisChart().getAxisProperties().getRightYAxisProperties();
+
+ // Right hand axis calc.
+ if ( rightAxisTypeProperties.getShowAxis() ) {
+ if( rightAxisTypeProperties.showAxisLabels() )
+ widthNeeded+= super.getAxisLabelsGroupRight().getWidestLabel();
+
+ widthNeeded += getAxisWidth(rightAxisTypeProperties, rightYAxisTitle);
+ }
+ super.setMinimumRHSWidthNeeded( widthNeeded );
! // Left Hand Axis calc. must be done after RHS as some LHS title sizes are set
! widthNeeded = 0;
//---if we are displaying axis scale labels, add width of widest label
! if( axisTypeProperties.showAxisLabels() ) {
! widthNeeded+= super.getAxisLabelsGroup().getWidestLabel();
! }
! widthNeeded += getAxisWidth(axisTypeProperties, yAxisTitle);
! super.setMinimumLHSWidthNeeded(widthNeeded);
! }
!
! private float getAxisWidth(AxisTypeProperties axisTypeProperties, String axisTitle) {
!
! float widthNeeded = 0;
***************
*** 137,153 ****
//---include axis title height if needed. Remember it is vertical for y-axis
//if( super.getAxisChart().getAxisProperties().getShowAxisTitle( AxisProperties.Y_AXIS ) )
! if( yAxisTitle != null )
{
! super.computeAxisTitleDimensions( yAxisTitle, axisTypeProperties.getTitleChartFont() );
widthNeeded += super.getTitleHeight();
widthNeeded += axisTypeProperties.getPaddingBetweenAxisTitleAndLabels();
}
!
! super.setMinimumWidthNeeded( widthNeeded );
}
/****************************************************************************************************
! *
* @param axisTitle
* @param graphics2D
--- 139,154 ----
//---include axis title height if needed. Remember it is vertical for y-axis
//if( super.getAxisChart().getAxisProperties().getShowAxisTitle( AxisProperties.Y_AXIS ) )
! if( axisTitle != null )
{
! super.computeAxisTitleDimensions( axisTitle, axisTypeProperties.getTitleChartFont() );
widthNeeded += super.getTitleHeight();
widthNeeded += axisTypeProperties.getPaddingBetweenAxisTitleAndLabels();
}
! return widthNeeded;
}
/****************************************************************************************************
! * This is the LHS Axis title
* @param axisTitle
* @param graphics2D
***************
*** 159,163 ****
{
float titleY; // = super.getAxisChart().getChartProperties().getEdgePadding();
! float titleX = super.getAxisChart().getXAxis().getOrigin() - super.getMinimumWidthNeeded() + super.getTitleHeight();
//---if YAxis title is larger than the YAxis itself, center it on image.
--- 160,164 ----
{
float titleY; // = super.getAxisChart().getChartProperties().getEdgePadding();
! float titleX = super.getAxisChart().getXAxis().getOrigin() - super.getMinimumLHSWidthNeeded() + super.getTitleHeight();
//---if YAxis title is larger than the YAxis itself, center it on image.
***************
*** 180,183 ****
--- 181,221 ----
}
+ /****************************************************************************************************
+ * This is the RHS Axis title
+ * @param axisTitle
+ * @param graphics2D
+ * @param axisTypeProperties
+ ***************************************************************************************************/
+ private void renderRightAxisTitle( String axisTitle, Graphics2D graphics2D, AxisTypeProperties axisTypeProperties )
+ {
+ if( axisTitle != null )
+ {
+ FontMetrics fm = graphics2D.getFontMetrics(axisTypeProperties.getAxisTitleChartFont().getFont());
+
+ TextLayout textLayout = new TextLayout( axisTitle,
+ axisTypeProperties.getAxisTitleChartFont().getFont(),
+ graphics2D.getFontRenderContext() );
+
+ float axisTitleWidth = textLayout.getAdvance();
+ float titleY;
+ float titleX = super.getAxisChart().getXAxis().getOrigin() + super.getAxisChart().getXAxis().getPixelLength() + super.getMinimumRHSWidthNeeded();// - fm.getDescent();
+ //---if YAxis title is larger than the YAxis itself, center it on image.
+ if( axisTitleWidth > super.getPixelLength() )
+ {
+ titleY = super.getAxisChart().getImageHeight() - ( ( super.getAxisChart().getImageHeight() - axisTitleWidth ) / 2 );
+ }
+ //---else, center on YAxis.
+ else
+ {
+ titleY = this.getOrigin() - ( ( super.getPixelLength() - axisTitleWidth ) / 2 );
+ }
+
+ //TODO this should use a TextTag
+ graphics2D.setFont( axisTypeProperties.getAxisTitleChartFont().getFont().deriveFont( ChartFont.VERTICAL_ROTATION ) );
+ graphics2D.setPaint( axisTypeProperties.getAxisTitleChartFont().getPaint() );
+ graphics2D.drawString( axisTitle, titleX, titleY );
+ }
+ }
+
/*********************************************************************************************
***************
*** 188,199 ****
* @param yAxisTitle
**********************************************************************************************/
! public void render( Graphics2D graphics2D, AxisProperties axisProperties, String yAxisTitle )
{
AxisTypeProperties axisTypeProperties = axisProperties.getYAxisProperties();
!
//---AXIS TITLE
! this.renderAxisTitle( yAxisTitle, graphics2D, axisProperties.getYAxisProperties() );
!
Line2D.Float line2D;
--- 226,237 ----
* @param yAxisTitle
**********************************************************************************************/
! public void render( Graphics2D graphics2D, AxisProperties axisProperties, String yAxisTitle, String rightYAxisTitle )
{
AxisTypeProperties axisTypeProperties = axisProperties.getYAxisProperties();
! AxisTypeProperties rightAxisTypeProperties = axisProperties.getRightYAxisProperties();
//---AXIS TITLE
! this.renderAxisTitle( yAxisTitle, graphics2D, axisTypeProperties );
! this.renderRightAxisTitle( rightYAxisTitle, graphics2D, rightAxisTypeProperties );
Line2D.Float line2D;
***************
*** 333,385 ****
}
! // Dual Y axis changes integrated CMC 25Aug03
! //---if AXIS at the right----------------------------------------------------------------------
! if (axisTypeProperties.getShowRightAxis())
! {
! line2D.x1 = super.getAxisChart().getXAxis().getOrigin() + super.getAxisChart().getXAxis().getPixelLength();
! line2D.x2 = line2D.x1;
! line2D.y1 = super.getOrigin() - super.getPixelLength() - 10 ;
! line2D.y2 = super.getOrigin();
! axisTypeProperties.getAxisStroke().draw( graphics2D, line2D );
! float tickRightX1 = super.getAxisChart().getXAxis().getOrigin() + super.getAxisChart().getXAxis().getPixelLength();
! float tickRightX2 = tickRightX1 + axisTypeProperties.getAxisTickMarkPixelLength();
! line2D.y1 = super.getOrigin();
! line2D.y2 = line2D.y1;
! stringY = super.getOrigin() + ( super.getAxisLabelsGroupRight().getTallestLabel() / 4 );
! stringX = super.getAxisChart().getXAxis().getOrigin() + axisTypeProperties.getAxisTickMarkPixelLength()
! + super.getAxisChart().getXAxis().getPixelLength();
! stringX+= axisTypeProperties.getPaddingBetweenLabelsAndTicks();
! for( int i = 0; i < super.getNumberOfScaleItems(); i++ )
! {
! //---TICK MARKS at the right
! if( axisTypeProperties.getShowTicks() != AxisTypeProperties.TICKS_NONE )
! {
! line2D.x1 = tickRightX1;
! line2D.x2 = tickRightX2;
! axisTypeProperties.getTickChartStroke().draw( graphics2D, line2D );
! }
! line2D.y1 -= super.getScalePixelWidth();
! line2D.y2 = line2D.y1;
! //---AXIS LABEL at the right
! if( axisTypeProperties.showAxisLabels() )
! {
! // Font and Paint set in TextTagGroup object in 1.0 it seems CMC 25Aug03
! //graphics2D.setFont( axisTypeProperties.getScaleChartFontRight().getFont());
! //graphics2D.setPaint( axisTypeProperties.getScaleChartFontRight().getPaint() );
! super.getAxisLabelsGroupRight().render( i, graphics2D, stringX , stringY );
! }
! stringY -= super.getScalePixelWidth();
! }
! }
}
--- 371,427 ----
}
! //---if AXIS at the right----------------------------------------------------------------------
! if (rightAxisTypeProperties.getShowAxis())
! {
! line2D.x1 = super.getAxisChart().getXAxis().getOrigin() + super.getAxisChart().getXAxis().getPixelLength();
! line2D.x2 = line2D.x1;
! line2D.y1 = super.getOrigin() - super.getPixelLength() - 10 ;
! line2D.y2 = super.getOrigin();
! rightAxisTypeProperties.getAxisStroke().draw( graphics2D, line2D );
! float tickRightX1 = super.getAxisChart().getXAxis().getOrigin() + super.getAxisChart().getXAxis().getPixelLength();
! float tickRightX2 = tickRightX1 + rightAxisTypeProperties.getAxisTickMarkPixelLength();
! line2D.y1 = super.getOrigin();
! line2D.y2 = line2D.y1;
! stringY = super.getOrigin() + ( super.getAxisLabelsGroupRight().getTallestLabel() / 4 );
! stringX = super.getAxisChart().getXAxis().getOrigin() + axisTypeProperties.getAxisTickMarkPixelLength()
! + super.getAxisChart().getXAxis().getPixelLength();
! float pixelStep = 0;
! // CMC XXX Really need a setNumberOfRightScaleItems value to use here.
! if( axisTypeProperties instanceof DataAxisProperties ) {
! pixelStep = (super.getPixelLength() - 5) / ( super.getAxisLabelsGroupRight().size() - 1);
! }
! else {
! pixelStep = super.getPixelLength() / ( super.getAxisLabelsGroupRight().size() - 1 );
! }
+ // for( int i = 0; i < super.getNumberOfScaleItems(); i++ )
+ for( int i = 0; i < super.getAxisLabelsGroupRight().size(); i++ )
+ {
+ //---TICK MARKS at the right
+ if( rightAxisTypeProperties.getShowTicks() != AxisTypeProperties.TICKS_NONE )
+ {
+ line2D.x1 = tickRightX1;
+ line2D.x2 = tickRightX2;
+ rightAxisTypeProperties.getTickChartStroke().draw( graphics2D, line2D );
+ }
! line2D.y1 -= pixelStep;
! line2D.y2 = line2D.y1;
! //---AXIS LABEL at the right
! if( rightAxisTypeProperties.showAxisLabels() )
! {
! super.getAxisLabelsGroupRight().render( i, graphics2D, stringX , stringY );
! }
! stringY -= pixelStep;
! }
! }
}
-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
digital self defense, top technical experts, no vendor pitches,
unmatched networking opportunities. Visit www.blackhat.com