krysalis-jcharts/src/java/org/krysalis/jcharts/axisChart/axis XAxis.java,1.6,1.7

Gann Bierner <[email protected]> Tue, 16 Nov 2004 06:39:36 +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-serv8971/src/java/org/krysalis/jcharts/axisChart/axis

Modified Files:
	XAxis.java 
Log Message:
Added ability to align rotated X-labels at the top rather the bottom.  This also causes the tops to point directly to the matching points on the X axis rather than be centered below them.  Finally, just like with purely vertical labels, we only need consider the text height rather than width to figure out how many to show in this case.

Index: XAxis.java
===================================================================
RCS file: /cvsroot/jcharts/krysalis-jcharts/src/java/org/krysalis/jcharts/axisChart/axis/XAxis.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** XAxis.java	13 Aug 2004 01:46:23 -0000	1.6
--- XAxis.java	16 Nov 2004 06:39:34 -0000	1.7
***************
*** 316,323 ****
  				if ( axisTypeProperties.getLabelRotationAngle() != 0 )
  				{
! 					stringY += super.getAxisLabelsGroup().getWidestLabel() 
! 						* (float)Math.abs(Math.sin(Math.toRadians(axisTypeProperties.getLabelRotationAngle())));                                // Find the vertical drop of the tallest text label
! 					stringY += super.getAxisLabelsGroup().getTallestLabel()
! 						* (float)Math.abs(Math.cos(Math.toRadians(axisTypeProperties.getLabelRotationAngle())));
  					graphics2D.setFont( axisTypeProperties.getScaleChartFont().getFont() );
  				}
--- 316,327 ----
  				if ( axisTypeProperties.getLabelRotationAngle() != 0 )
  				{
!                                         if (! axisTypeProperties.getRotatedLabelAlignTop()) {
!                                         
!                                                 stringY += super.getAxisLabelsGroup().getWidestLabel() 
!                                                 	* (float)Math.abs(Math.sin(Math.toRadians(axisTypeProperties.getLabelRotationAngle())));                                // Find the vertical drop of the tallest text label
!                                                 stringY += super.getAxisLabelsGroup().getTallestLabel()
!                                                         * (float)Math.abs(Math.cos(Math.toRadians(axisTypeProperties.getLabelRotationAngle())));
!                                                 
!                                         }
  					graphics2D.setFont( axisTypeProperties.getScaleChartFont().getFont() );
  				}
***************
*** 387,393 ****
  					{
  						// x1 is the 1/2 the horizontal width of the rotated label
! 						float x1 = (super.getAxisLabelsGroup().getTextTag( i ).getWidth() / 2) * (float)Math.abs(Math.cos(Math.toRadians(axisTypeProperties.getLabelRotationAngle()))); 
! 						//---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( stringX + x1 < super.getAxisChart().getImageWidth() )
  						{
  							//---get the original transform so we can reset it.
--- 391,402 ----
  					{
  						// x1 is the 1/2 the horizontal width of the rotated label
!                                                 float x1 = axisTypeProperties.getRotatedLabelAlignTop() ?
!                                                         (super.getAxisLabelsGroup().getTextTag( i ).getWidth()) * (float)Math.abs(Math.cos(Math.toRadians(axisTypeProperties.getLabelRotationAngle()))) :
!                                                         (super.getAxisLabelsGroup().getTextTag( i ).getWidth() / 2) * (float)Math.abs(Math.cos(Math.toRadians(axisTypeProperties.getLabelRotationAngle()))); 
!                                                 
!                                                 //---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.
!                                                 // Gann: only need to add x1 if it's not the full text width.
!                                                 float extraWidth = axisTypeProperties.getRotatedLabelAlignTop() ? 0 : x1;
!                                                 if( stringX + extraWidth < super.getAxisChart().getImageWidth() )
  						{
  							//---get the original transform so we can reset it.
***************
*** 397,402 ****
  							// calculate the X coord to center the top of the label text to the axis tick as opposed to the bottom
  							// x2 takes this into account
! 							float x2 = super.getAxisLabelsGroup().getTextTag( i ).getFontDescent() * (float)Math.abs(Math.sin(Math.toRadians(axisTypeProperties.getLabelRotationAngle()))); 
! 							graphics2D.translate(stringX - x1 + x2, stringY);
  							// rotate entire context
  							graphics2D.rotate(Math.toRadians(-axisTypeProperties.getLabelRotationAngle()));
--- 406,418 ----
  							// calculate the X coord to center the top of the label text to the axis tick as opposed to the bottom
  							// x2 takes this into account
! 							float x2 = super.getAxisLabelsGroup().getTextTag( i ).getFontDescent() * (float)Math.abs(Math.sin(Math.toRadians(axisTypeProperties.getLabelRotationAngle())));
!                                                         if (axisTypeProperties.getRotatedLabelAlignTop()) {
!                                                                 float y = super.getAxisLabelsGroup().getTextTag( i ).getWidth() * (float)Math.abs(Math.sin(Math.toRadians(axisTypeProperties.getLabelRotationAngle())));
!                                                                 graphics2D.translate(stringX - x1 + x2, stringY + y);
!                                                                 
!                                                         } else {
!                                                                 graphics2D.translate(stringX - x1 + x2, stringY);
!                                                         }
!                                                         
  							// rotate entire context
  							graphics2D.rotate(Math.toRadians(-axisTypeProperties.getLabelRotationAngle()));
***************
*** 486,490 ****
  			AxisTypeProperties axisTypeProperties = super.getAxisChart().getAxisProperties().getXAxisProperties();
  
! 			if( super.getAxisChart().getAxisProperties().xAxisLabelsAreVertical() )
  			{
  				widestLabelSize = super.getAxisLabelsGroup().getTallestLabel();
--- 502,518 ----
  			AxisTypeProperties axisTypeProperties = super.getAxisChart().getAxisProperties().getXAxisProperties();
  
!                         if ( axisTypeProperties.getLabelRotationAngle() != 0) {
!                                 // if we are aligning our rotated labels at the top rather and therefore they are
!                                 // "pointing" at the proper point on the axis axis (rather than being centered below
!                                 // it, then these are effectively just like vertical labels.  If they are centered,
!                                 // then it's best to separate them by the full bounding box of the labels.
!                                 if ( axisTypeProperties.getRotatedLabelAlignTop() ) {
!                                         widestLabelSize = super.getAxisLabelsGroup().getTallestLabel();
!                                 } else {
!                                         widestLabelSize = (super.getAxisLabelsGroup().getWidestLabel()) * (float)Math.abs(Math.cos(Math.toRadians(axisTypeProperties.getLabelRotationAngle())));
!                                 
!                                 }
!                         }
!                         else if( super.getAxisChart().getAxisProperties().xAxisLabelsAreVertical() )
  			{
  				widestLabelSize = super.getAxisLabelsGroup().getTallestLabel();



-------------------------------------------------------
This SF.Net email is sponsored by: InterSystems CACHE
FREE OODBMS DOWNLOAD - A multidimensional database that combines
robust object and relational technologies, making it a perfect match
for Java, C++,COM, XML, ODBC and JDBC. www.intersystems.com/match8