1 34 35 package org.krysalis.jcharts.axisChart; 36 37 38 import org.krysalis.jcharts.chartData.interfaces.IAxisChartDataSet; 39 import org.krysalis.jcharts.chartData.interfaces.IDataSeries; 40 import org.krysalis.jcharts.imageMap.CircleMapArea; 41 import org.krysalis.jcharts.properties.*; 42 43 import java.awt.*; 44 import java.awt.geom.*; 45 46 47 52 abstract class LineChart 53 { 54 55 62 static void render( AxisChart axisChart, IAxisChartDataSet iAxisChartDataSet ) throws PropertyException 63 { 64 Graphics2D g2d=axisChart.getGraphics2D(); 65 66 LineChartProperties lineChartProperties=(LineChartProperties) iAxisChartDataSet.getChartTypeProperties(); 67 lineChartProperties.validate( iAxisChartDataSet ); 68 69 IDataSeries iDataSeries= (IDataSeries) axisChart.getIAxisDataSeries(); 71 72 float[][] yAxisCoordinates=new float[ iAxisChartDataSet.getNumberOfDataSets() ][ iAxisChartDataSet.getNumberOfDataItems() ]; 74 75 float xMapCoordinate=axisChart.getXAxis().getTickStart(); 77 78 79 for( int j=0; j < iAxisChartDataSet.getNumberOfDataItems(); j++ ) 81 { 82 for( int i=0; i < yAxisCoordinates.length; i++ ) 84 { 85 if( iAxisChartDataSet.getValue( i, j ) != Double.NaN ) 86 { 87 92 yAxisCoordinates[ i ][ j ]= axisChart.getYAxis().computeAxisCoordinate( axisChart.getYAxis().getOrigin(), 96 iAxisChartDataSet.getValue( i, j )*axisChart.axisProperties.getYAxisProperties().getSecondScaleRight(), 97 axisChart.getYAxis().getScaleCalculator().getMinValue() ); 98 99 if( axisChart.getGenerateImageMapFlag() ) 101 { 102 String label; 103 if( axisChart.getXAxis().getAxisLabelsGroup() != null ) 104 { 105 label = axisChart.getXAxis().getAxisLabelsGroup().getTextTag( j ).getText(); 106 } 107 else 108 { 109 label = null; 110 } 111 112 axisChart.getImageMap().addImageMapArea( new CircleMapArea( xMapCoordinate, 113 yAxisCoordinates[ i ][ j ], 114 iAxisChartDataSet.getValue( i, j ), 115 label, 116 iAxisChartDataSet.getLegendLabel( i ) ) ); 117 } 118 } 119 else 120 { 121 yAxisCoordinates[ i ][ j ]=Float.NaN; 122 } 123 } 124 125 xMapCoordinate+=axisChart.getXAxis().getScalePixelWidth(); 126 } 127 128 129 AffineTransform originalTransform=null; 130 double[] cornerXOffset=null; 131 double[] cornerYOffset=null; 132 133 if( lineChartProperties.getShapes() != null ) 135 { 136 cornerXOffset=new double[ iAxisChartDataSet.getNumberOfDataSets() ]; 138 cornerYOffset=new double[ iAxisChartDataSet.getNumberOfDataSets() ]; 139 140 originalTransform=g2d.getTransform(); 142 143 Rectangle2D rectangle; 144 145 for( int i=0; i < iAxisChartDataSet.getNumberOfDataSets(); i++ ) 148 { 149 if( lineChartProperties.getShapes()[ i ] != null ) 150 { 151 rectangle=lineChartProperties.getShapes()[ i ].getBounds2D(); 152 cornerXOffset[ i ]=rectangle.getWidth() / 2; 153 cornerYOffset[ i ]=rectangle.getHeight() / 2; 154 } 155 } 156 } 157 158 159 Line2D.Float line=new Line2D.Float( axisChart.getXAxis().getTickStart(), 161 yAxisCoordinates[ 0 ][ 0 ], 162 axisChart.getXAxis().getTickStart(), 163 yAxisCoordinates[ 0 ][ 0 ] ); 164 if( yAxisCoordinates[ 0 ].length > 1 ) 166 { 167 line.y2= yAxisCoordinates[ 0 ][ 1 ]; 168 } 169 170 171 for( int i=0; i < yAxisCoordinates.length; i++ ) 174 { 175 line.x1=axisChart.getXAxis().getTickStart(); 176 line.y1=yAxisCoordinates[ i ][ 0 ]; 177 line.x2=line.x1; 178 179 for( int j=1; j < yAxisCoordinates[ 0 ].length; j++ ) 181 { 182 if( !Float.isNaN( yAxisCoordinates[ i ][ j ] ) ) 184 { 185 if( Float.isNaN( yAxisCoordinates[ i ][ j - 1 ] ) ) 187 { 188 line.x2+=axisChart.getXAxis().getScalePixelWidth(); 189 line.x1=line.x2; 190 line.y1=yAxisCoordinates[ i ][ j ]; 191 line.y2=yAxisCoordinates[ i ][ j ]; 192 193 continue; 194 } 195 196 197 line.x2+=axisChart.getXAxis().getScalePixelWidth(); 198 line.y2=yAxisCoordinates[ i ][ j ]; 199 200 g2d.setPaint( iAxisChartDataSet.getPaint( i ) ); 201 g2d.setStroke( lineChartProperties.getLineStrokes()[ i ] ); 202 g2d.draw( line ); 203 204 if( lineChartProperties.getShapes()[ i ] != null ) 206 { 207 g2d.translate( line.x1 - cornerXOffset[ i ], line.y1 - cornerYOffset[ i ] ); 209 210 g2d.setPaint( iAxisChartDataSet.getPaint( i ) ); 211 g2d.fill( lineChartProperties.getShapes()[ i ] ); 212 213 g2d.setTransform( originalTransform ); 215 } 216 217 line.x1=line.x2; 218 line.y1=line.y2; 219 } 220 else 221 { 222 if( ( !Float.isNaN( yAxisCoordinates[ i ][ j - 1 ] ) ) && ( lineChartProperties.getShapes()[ i ] != null ) ) 223 { 224 g2d.translate( line.x1 - cornerXOffset[ i ], line.y1 - cornerYOffset[ i ] ); 226 227 g2d.setPaint( iAxisChartDataSet.getPaint( i ) ); 228 g2d.fill( lineChartProperties.getShapes()[ i ] ); 229 230 g2d.setTransform( originalTransform ); 232 } 233 234 line.x2+=axisChart.getXAxis().getScalePixelWidth(); 235 line.x1=line.x2; 236 } 237 } 238 239 240 if( ( !Float.isNaN( yAxisCoordinates[ i ][ yAxisCoordinates[ i ].length - 1 ] ) ) && ( lineChartProperties.getShapes()[ i ] != null ) ) 242 { 243 g2d.translate( line.x2 - cornerXOffset[ i ], line.y2 - cornerYOffset[ i ] ); 245 246 g2d.setPaint( iAxisChartDataSet.getPaint( i ) ); 247 g2d.fill( lineChartProperties.getShapes()[ i ] ); 248 249 g2d.setTransform( originalTransform ); 251 } 252 } 253 } 254 255 256 } 257 | Popular Tags |