From: Nathaniel G. A. <nat...@us...> - 2004-05-26 01:57:29
|
Update of /cvsroot/jcharts/krysalis-jcharts/src/java/org/krysalis/jcharts/axisChart In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11439/src/java/org/krysalis/jcharts/axisChart Modified Files: BarChart.java Log Message: image maps for zero values on vertical plots. Still need to test User Defined Scale. Index: BarChart.java =================================================================== RCS file: /cvsroot/jcharts/krysalis-jcharts/src/java/org/krysalis/jcharts/axisChart/BarChart.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** BarChart.java 17 May 2003 16:56:57 -0000 1.1 --- BarChart.java 26 May 2004 01:57:19 -0000 1.2 *************** *** 33,65 **** ************************************************************************************************/ - package org.krysalis.jcharts.axisChart; import org.krysalis.jcharts.axisChart.customRenderers.axisValue.AxisValueRenderEvent; import org.krysalis.jcharts.chartData.interfaces.IAxisChartDataSet; import org.krysalis.jcharts.imageMap.RectMapArea; import org.krysalis.jcharts.properties.BarChartProperties; import org.krysalis.jcharts.properties.DataAxisProperties; - import java.awt.*; - import java.awt.geom.Rectangle2D; - ! /************************************************************************************* ! * * @author Nathaniel Auvil * @version $Id$ ! ************************************************************************************/ abstract class BarChart { ! /******************************************************************************************** ! * Draws the chart ! * uses Rectangle2D......keep having rounding problems. ! * * @param axisChart * @param iAxisChartDataSet ! *********************************************************************************************/ static void render( AxisChart axisChart, IAxisChartDataSet iAxisChartDataSet ) { --- 33,63 ---- ************************************************************************************************/ package org.krysalis.jcharts.axisChart; + import java.awt.Graphics2D; + import java.awt.geom.Rectangle2D; + import org.krysalis.jcharts.axisChart.customRenderers.axisValue.AxisValueRenderEvent; import org.krysalis.jcharts.chartData.interfaces.IAxisChartDataSet; + import org.krysalis.jcharts.chartText.TextTagGroup; import org.krysalis.jcharts.imageMap.RectMapArea; import org.krysalis.jcharts.properties.BarChartProperties; import org.krysalis.jcharts.properties.DataAxisProperties; ! /***************************************************************************************** * @author Nathaniel Auvil * @version $Id$ ! ****************************************************************************************/ abstract class BarChart { ! /*************************************************************************************** ! * Draws the chart uses Rectangle2D......keep having rounding problems. ! * * @param axisChart * @param iAxisChartDataSet ! **************************************************************************************/ static void render( AxisChart axisChart, IAxisChartDataSet iAxisChartDataSet ) { *************** *** 76,80 **** float height; - if( axisChart.getAxisProperties().isPlotHorizontal() ) { --- 74,77 ---- *************** *** 88,92 **** Rectangle2D.Float rectangle = new Rectangle2D.Float( startingX, startingY, width, height ); ! BarChart.horizontalPlot( axisChart, iAxisChartDataSet, barChartProperties, dataAxisProperties, g2d, rectangle, startingX ); } else --- 85,95 ---- Rectangle2D.Float rectangle = new Rectangle2D.Float( startingX, startingY, width, height ); ! BarChart.horizontalPlot( axisChart, ! iAxisChartDataSet, ! barChartProperties, ! dataAxisProperties, ! g2d, ! rectangle, ! startingX ); } else *************** *** 101,111 **** Rectangle2D.Float rectangle = new Rectangle2D.Float( startingX, startingY, width, height ); ! BarChart.verticalPlot( axisChart, iAxisChartDataSet, barChartProperties, dataAxisProperties, g2d, rectangle, startingY ); } } ! /********************************************************************************************* ! * * @param axisChart * @param iAxisChartDataSet --- 104,119 ---- Rectangle2D.Float rectangle = new Rectangle2D.Float( startingX, startingY, width, height ); ! BarChart.verticalPlot( axisChart, ! iAxisChartDataSet, ! barChartProperties, ! dataAxisProperties, ! g2d, ! rectangle, ! startingY ); } } ! /*************************************************************************************** * @param axisChart * @param iAxisChartDataSet *************** *** 115,128 **** * @param rectangle * @param startingX ! *********************************************************************************************/ private static void horizontalPlot( AxisChart axisChart, ! IAxisChartDataSet iAxisChartDataSet, ! BarChartProperties barChartProperties, ! DataAxisProperties dataAxisProperties, ! Graphics2D g2d, ! Rectangle2D.Float rectangle, ! float startingX ) { ! int imageMapLabelIndex = axisChart.getYAxis().getNumberOfScaleItems() - 1; //---setup the total area rectangle --- 123,136 ---- * @param rectangle * @param startingX ! **************************************************************************************/ private static void horizontalPlot( AxisChart axisChart, ! IAxisChartDataSet iAxisChartDataSet, ! BarChartProperties barChartProperties, ! DataAxisProperties dataAxisProperties, ! Graphics2D g2d, ! Rectangle2D.Float rectangle, ! float startingX ) { ! int imageMapLabelIndex = axisChart.getYAxis().getNumberOfScaleItems() - 1; //---setup the total area rectangle *************** *** 133,148 **** totalItemArea.width = axisChart.getXAxis().getPixelLength() - 1; - //---reuse the same Object for pre and post render events. AxisValueRenderEvent axisValueRenderEvent = new AxisValueRenderEvent( axisChart, ! iAxisChartDataSet, ! g2d, ! totalItemArea, ! axisChart.getXAxis().getZeroLineCoordinate() ); //---there is only ever one data set for a regular bar chart axisValueRenderEvent.setDataSetIndex( 0 ); - //LOOP for( int i = 0; i < iAxisChartDataSet.getNumberOfDataItems(); i++ ) --- 141,154 ---- totalItemArea.width = axisChart.getXAxis().getPixelLength() - 1; //---reuse the same Object for pre and post render events. AxisValueRenderEvent axisValueRenderEvent = new AxisValueRenderEvent( axisChart, ! iAxisChartDataSet, ! g2d, ! totalItemArea, ! axisChart.getXAxis().getZeroLineCoordinate() ); //---there is only ever one data set for a regular bar chart axisValueRenderEvent.setDataSetIndex( 0 ); //LOOP for( int i = 0; i < iAxisChartDataSet.getNumberOfDataItems(); i++ ) *************** *** 159,163 **** barChartProperties.firePreRender( axisValueRenderEvent ); - //---if value == 0 do not plot anything. if( iAxisChartDataSet.getValue( 0, i ) != 0.0d ) --- 165,168 ---- *************** *** 166,171 **** { rectangle.x = axisChart.getXAxis().computeAxisCoordinate( axisChart.getXAxis().getOrigin(), ! iAxisChartDataSet.getValue( 0, i ), ! axisChart.getXAxis().getScaleCalculator().getMinValue() ); rectangle.width = startingX - rectangle.x; --- 171,178 ---- { rectangle.x = axisChart.getXAxis().computeAxisCoordinate( axisChart.getXAxis().getOrigin(), ! iAxisChartDataSet.getValue( 0, i ), ! axisChart .getXAxis() ! .getScaleCalculator() ! .getMinValue() ); rectangle.width = startingX - rectangle.x; *************** *** 177,181 **** rectangle.x = startingX; rectangle.width = BarChart.computeScaleHeightOfValue( iAxisChartDataSet.getValue( 0, i ), ! axisChart.getXAxis().getOneUnitPixelSize() ); //---set values for the postRender event --- 184,188 ---- rectangle.x = startingX; rectangle.width = BarChart.computeScaleHeightOfValue( iAxisChartDataSet.getValue( 0, i ), ! axisChart.getXAxis().getOneUnitPixelSize() ); //---set values for the postRender event *************** *** 183,197 **** } ! ! //---with a user defined scale, we could have non-zero data points with a height of zero. if( rectangle.width != 0 ) { ! /* ! System.out.println( "rectangle.x= " + rectangle.x ); ! System.out.println( "rectangle.y= " + rectangle.y ); ! System.out.println( "rectangle.width= " + rectangle.width ); ! System.out.println( "rectangle.height= " + rectangle.height ); ! */ g2d.fill( rectangle ); --- 190,204 ---- } ! //---with a user defined scale, we could have non-zero data points with a height ! // of zero. if( rectangle.width != 0 ) { ! /* ! * System.out.println( "rectangle.x= " + rectangle.x ); System.out.println( ! * "rectangle.y= " + rectangle.y ); System.out.println( "rectangle.width= " + ! * rectangle.width ); System.out.println( "rectangle.height= " + ! * rectangle.height ); ! */ g2d.fill( rectangle ); *************** *** 215,221 **** axisChart.getImageMap().addImageMapArea( new RectMapArea( rectangle, ! iAxisChartDataSet.getValue( 0, i ), ! label, ! iAxisChartDataSet.getLegendLabel( 0 ) ) ); imageMapLabelIndex--; --- 222,228 ---- axisChart.getImageMap().addImageMapArea( new RectMapArea( rectangle, ! iAxisChartDataSet.getValue( 0, i ), ! label, ! iAxisChartDataSet.getLegendLabel( 0 ) ) ); imageMapLabelIndex--; *************** *** 224,228 **** } - //---notify everyone we just rendered barChartProperties.firePostRender( axisValueRenderEvent ); --- 231,234 ---- *************** *** 234,239 **** ! /************************************************************************************** ! * * @param axisChart * @param iAxisChartDataSet --- 240,244 ---- ! /*************************************************************************************** * @param axisChart * @param iAxisChartDataSet *************** *** 245,256 **** **************************************************************************************/ private static void verticalPlot( AxisChart axisChart, ! IAxisChartDataSet iAxisChartDataSet, ! BarChartProperties barChartProperties, ! DataAxisProperties dataAxisProperties, ! Graphics2D g2d, ! Rectangle2D.Float rectangle, ! float startingY ) { - //---setup the total area rectangle Rectangle2D.Float totalItemArea = new Rectangle2D.Float(); --- 250,260 ---- **************************************************************************************/ private static void verticalPlot( AxisChart axisChart, ! IAxisChartDataSet iAxisChartDataSet, ! BarChartProperties barChartProperties, ! DataAxisProperties dataAxisProperties, ! Graphics2D g2d, ! Rectangle2D.Float rectangle, ! float startingY ) { //---setup the total area rectangle Rectangle2D.Float totalItemArea = new Rectangle2D.Float(); *************** *** 260,276 **** totalItemArea.height = axisChart.getYAxis().getPixelLength() - 1; - //---reuse the same Object for pre and post render events. AxisValueRenderEvent axisValueRenderEvent = new AxisValueRenderEvent( axisChart, ! iAxisChartDataSet, ! g2d, ! totalItemArea, ! axisChart.getYAxis().getZeroLineCoordinate() ); //---there is only ever one data set for a regular bar chart axisValueRenderEvent.setDataSetIndex( 0 ); - - //LOOP for( int i = 0; i < iAxisChartDataSet.getNumberOfDataItems(); i++ ) --- 264,277 ---- totalItemArea.height = axisChart.getYAxis().getPixelLength() - 1; //---reuse the same Object for pre and post render events. AxisValueRenderEvent axisValueRenderEvent = new AxisValueRenderEvent( axisChart, ! iAxisChartDataSet, ! g2d, ! totalItemArea, ! axisChart.getYAxis().getZeroLineCoordinate() ); //---there is only ever one data set for a regular bar chart axisValueRenderEvent.setDataSetIndex( 0 ); //LOOP for( int i = 0; i < iAxisChartDataSet.getNumberOfDataItems(); i++ ) *************** *** 287,291 **** barChartProperties.firePreRender( axisValueRenderEvent ); - //---if value == 0 do not plot anything. if( iAxisChartDataSet.getValue( 0, i ) != 0.0d ) --- 288,291 ---- *************** *** 294,299 **** { rectangle.y = startingY; ! rectangle.height = BarChart.computeScaleHeightOfValue( iAxisChartDataSet.getValue( 0, i ), ! axisChart.getYAxis().getOneUnitPixelSize() ); axisValueRenderEvent.setValueY( rectangle.y + rectangle.height ); --- 294,298 ---- { rectangle.y = startingY; ! rectangle.height = BarChart.computeScaleHeightOfValue( iAxisChartDataSet.getValue( 0, i ), axisChart.getYAxis().getOneUnitPixelSize() ); axisValueRenderEvent.setValueY( rectangle.y + rectangle.height ); *************** *** 309,312 **** --- 308,312 ---- } + //TODO not sure this makes sense. How could this be zero? //---with a user defined scale, we could have non-zero data points with a height of zero. if( rectangle.height != 0 ) *************** *** 319,343 **** g2d.setPaint( iAxisChartDataSet.getPaint( 0 ) ); } //---if we are generating an ImageMap, store the image coordinates if( axisChart.getGenerateImageMapFlag() ) { ! String label; ! if( axisChart.getXAxis().getAxisLabelsGroup() != null ) ! { ! label = axisChart.getXAxis().getAxisLabelsGroup().getTextTag( i ).getText(); ! } ! else ! { ! label = null; ! } ! axisChart.getImageMap().addImageMapArea( new RectMapArea( rectangle, ! iAxisChartDataSet.getValue( 0, i ), ! label, ! iAxisChartDataSet.getLegendLabel( 0 ) ) ); } } ! } //---notify everyone we just rendered --- 319,364 ---- g2d.setPaint( iAxisChartDataSet.getPaint( 0 ) ); } + } + + //---even if the bar is not visible, we still need to generate an ImageMapArea + if( axisChart.getGenerateImageMapFlag() ) + { + RectMapArea rectMapArea = createImageMapArea( axisChart.getXAxis().getAxisLabelsGroup(), + i, + rectangle, + iAxisChartDataSet.getValue( 0, i ), + iAxisChartDataSet.getLegendLabel( 0 ) ); + + axisChart.getImageMap().addImageMapArea( rectMapArea ); + } + } + else + { + // System.out.println( "value was zero" ); + + //---make sure zero is even visible on the scale + if( axisChart.getYAxis().getScaleCalculator().getMaxValue() >= 0 + && axisChart.getYAxis().getScaleCalculator().getMinValue() <= 0 ) + { + rectangle.y = startingY; + rectangle.height = 1; //---if we are generating an ImageMap, store the image coordinates if( axisChart.getGenerateImageMapFlag() ) { ! RectMapArea rectMapArea = createImageMapArea( axisChart.getXAxis().getAxisLabelsGroup(), ! i, ! rectangle, ! iAxisChartDataSet.getValue( 0, i ), ! iAxisChartDataSet.getLegendLabel( 0 ) ); ! axisChart.getImageMap().addImageMapArea( rectMapArea ); } } ! /* else ! { ! System.out.println( "Not in scale range so skip." ); ! } ! */ } //---notify everyone we just rendered *************** *** 350,362 **** ! /******************************************************************************************************* ! * Takes a value and determines the number of pixels it should fill on the screen. ! * If there is a user defined scale and the passed value is greater than the MAX or less than the MIN, ! * the height will be forced to the MAX or MIN respectively. ! * * @param value * @param oneUnitPixelSize * @return float the screen pixel coordinate ! ********************************************************************************************************/ static float computeScaleHeightOfValue( double value, double oneUnitPixelSize ) { --- 371,383 ---- ! /*************************************************************************************** ! * Takes a value and determines the number of pixels it should fill on the screen. If ! * there is a user defined scale and the passed value is greater than the MAX or less ! * than the MIN, the height will be forced to the MAX or MIN respectively. ! * * @param value * @param oneUnitPixelSize * @return float the screen pixel coordinate ! **************************************************************************************/ static float computeScaleHeightOfValue( double value, double oneUnitPixelSize ) { *************** *** 364,366 **** } ! } --- 385,414 ---- } ! ! /*************************************************************************************** ! * @param axisLabelsGroup ! * @param index ! * @param rectangle ! * @param value ! * @param legendLabel ! * @return ! **************************************************************************************/ ! private static RectMapArea createImageMapArea( TextTagGroup axisLabelsGroup, ! int index, ! Rectangle2D.Float rectangle, ! double value, ! String legendLabel ) ! { ! String label; ! if( axisLabelsGroup != null ) ! { ! label = axisLabelsGroup.getTextTag( index ).getText(); ! } ! else ! { ! label = null; ! } ! ! return new RectMapArea( rectangle, value, label, legendLabel ); ! } ! } \ No newline at end of file |