From: Chris M. <ki...@us...> - 2004-06-14 01:24:25
|
Update of /cvsroot/jcharts/krysalis-jcharts/src/java/org/krysalis/jcharts/axisChart/axis In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7285/src/java/org/krysalis/jcharts/axisChart/axis Modified Files: XAxis.java Log Message: Addition of X axis label rotation functionality. New method added to AxisTypeProperties: e.g.: call with axisProperties.getXAxisProperties().setLabelRotationAngle(30); Index: XAxis.java =================================================================== RCS file: /cvsroot/jcharts/krysalis-jcharts/src/java/org/krysalis/jcharts/axisChart/axis/XAxis.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** XAxis.java 29 Jun 2003 14:14:28 -0000 1.3 --- XAxis.java 14 Jun 2004 01:24:15 -0000 1.4 *************** *** 47,50 **** --- 47,51 ---- import java.awt.*; import java.awt.geom.Line2D; + import java.awt.geom.AffineTransform; import java.lang.reflect.Field; import java.util.Iterator; *************** *** 99,108 **** else { ! //---tallest label for horizontal labels ! //heightNeeded = axisChartDataProcessor.getAxisLabelProcessor().getTallestLabel(); ! heightNeeded = super.getAxisLabelsGroup().getTallestLabel(); ! //---not sure why i need more padding ! heightNeeded += 3; } } --- 100,122 ---- else { ! if ( axisTypeProperties.getLabelRotationAngle() != 0 ) ! { // heightNeeded is calculated for positioning X axis title ! //---widest label for rotated labels converted to vertical distance ! // A special thanks to the Oswego School District maths prep exam web page (http://regentsprep.org/Regents/math/rtritrig/Ltrig.htm) ! heightNeeded = super.getAxisLabelsGroup().getWidestLabel() ! * (float)Math.abs(Math.sin(Math.toRadians(axisTypeProperties.getLabelRotationAngle()))); ! // height is currently at top of characters calculate vertical for text height ! heightNeeded += super.getAxisLabelsGroup().getTallestLabel() ! * (float)Math.abs(Math.cos(Math.toRadians(axisTypeProperties.getLabelRotationAngle()))); ! } ! else ! { ! //---tallest label for horizontal labels ! //heightNeeded = axisChartDataProcessor.getAxisLabelProcessor().getTallestLabel(); ! heightNeeded = super.getAxisLabelsGroup().getTallestLabel(); ! //---not sure why i need more padding ! heightNeeded += 3; ! } } } *************** *** 257,261 **** /********************************************************************************************* ! * Renders the YAxis on the passes Graphics2D object * * @param graphics2D --- 271,275 ---- /********************************************************************************************* ! * Renders the XAxis on the passed Graphics2D object * * @param graphics2D *************** *** 298,303 **** if( !axisProperties.xAxisLabelsAreVertical() ) { ! stringY += super.getAxisLabelsGroup().getTallestLabel(); ! graphics2D.setFont( axisTypeProperties.getScaleChartFont().getFont() ); } else --- 312,328 ---- if( !axisProperties.xAxisLabelsAreVertical() ) { ! 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() ); ! } ! else ! { ! stringY += super.getAxisLabelsGroup().getTallestLabel(); ! graphics2D.setFont( axisTypeProperties.getScaleChartFont().getFont() ); ! } } else *************** *** 357,367 **** 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 ); } } --- 382,419 ---- if( !axisProperties.xAxisLabelsAreVertical() ) { ! if ( axisTypeProperties.getLabelRotationAngle() != 0) ! { ! // 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. ! AffineTransform originalTransform=graphics2D.getTransform(); ! // Position to tick mark and down the required height, then back half the horizontal label width ! // 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())); ! // draw the label text ! super.getAxisLabelsGroup().getTextTag( i ).render( graphics2D, 0, 0 ); ! ! //---translate back to the original position ! graphics2D.setTransform( originalTransform ); ! } ! } ! else { ! //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 ); ! } } } |