1 34 35 package org.krysalis.jcharts.axisChart; 36 37 38 import org.krysalis.jcharts.chartData.interfaces.*; 39 import org.krysalis.jcharts.imageMap.CircleMapArea; 40 import org.krysalis.jcharts.properties.*; 41 42 import java.awt.*; 43 import java.awt.geom.*; 44 45 46 51 abstract class ScatterPlotChart 52 { 53 54 60 static void render( ScatterPlotAxisChart scatterPlotAxisChart, IScatterPlotDataSet iScatterPlotDataSet ) 61 { 62 float[][] xAxisCoordinates = new float[ iScatterPlotDataSet.getNumberOfDataSets() ][ iScatterPlotDataSet.getNumberOfDataItems() ]; 64 float[][] yAxisCoordinates = new float[ iScatterPlotDataSet.getNumberOfDataSets() ][ iScatterPlotDataSet.getNumberOfDataItems() ]; 65 66 67 69 for( int index = 0; index < iScatterPlotDataSet.getNumberOfDataItems(); index++ ) 71 { 72 for( int dataSet = 0; dataSet < yAxisCoordinates.length; dataSet++ ) 74 { 75 if( iScatterPlotDataSet.getValue( dataSet, index ) != null ) 76 { 77 xAxisCoordinates[ dataSet ][ index ] = scatterPlotAxisChart.getXAxis().computeAxisCoordinate( scatterPlotAxisChart.getXAxis().getOrigin(), 78 iScatterPlotDataSet.getValue( dataSet, index ).getX(), 79 scatterPlotAxisChart.getXAxis().getScaleCalculator().getMinValue() ); 80 81 yAxisCoordinates[ dataSet ][ index ] = scatterPlotAxisChart.getYAxis().computeAxisCoordinate( scatterPlotAxisChart.getYAxis().getOrigin(), 82 iScatterPlotDataSet.getValue( dataSet, index ).getY(), 83 scatterPlotAxisChart.getYAxis().getScaleCalculator().getMinValue() ); 84 85 87 if( scatterPlotAxisChart.getGenerateImageMapFlag() ) 89 { 90 scatterPlotAxisChart.getImageMap().addImageMapArea( new CircleMapArea( xAxisCoordinates[ dataSet ][ index ], 91 yAxisCoordinates[ dataSet ][ index ], 92 iScatterPlotDataSet.getValue( dataSet, index ), 93 iScatterPlotDataSet.getLegendLabel( dataSet ) ) ); 94 } 95 } 96 else 97 { 98 xAxisCoordinates[ dataSet ][ index ] = Float.NaN; 99 yAxisCoordinates[ dataSet ][ index ] = Float.NaN; 100 } 101 } 102 } 103 104 105 ScatterPlotProperties scatterPlotProperties = (ScatterPlotProperties) iScatterPlotDataSet.getChartTypeProperties(); 106 109 Graphics2D g2d = scatterPlotAxisChart.getGraphics2D(); 110 AffineTransform originalTransform = null; 111 double[] cornerXOffset = null; 112 double[] cornerYOffset = null; 113 114 if( scatterPlotProperties.getShapes() != null ) 116 { 117 cornerXOffset = new double[ iScatterPlotDataSet.getNumberOfDataSets() ]; 119 cornerYOffset = new double[ iScatterPlotDataSet.getNumberOfDataSets() ]; 120 121 originalTransform = g2d.getTransform(); 123 124 Rectangle2D rectangle; 125 126 for( int i = 0; i < iScatterPlotDataSet.getNumberOfDataSets(); i++ ) 129 { 130 if( scatterPlotProperties.getShapes()[ i ] != null ) 131 { 132 rectangle = scatterPlotProperties.getShapes()[ i ].getBounds2D(); 133 cornerXOffset[ i ] = rectangle.getWidth() / 2; 134 cornerYOffset[ i ] = rectangle.getHeight() / 2; 135 } 136 } 137 } 138 139 140 Line2D.Float line = new Line2D.Float( xAxisCoordinates[ 0 ][ 0 ], 142 yAxisCoordinates[ 0 ][ 0 ], 143 xAxisCoordinates[ 0 ][ 1 ], 144 yAxisCoordinates[ 0 ][ 1 ] ); 145 if( yAxisCoordinates[ 0 ].length > 1 ) 147 { 148 line.y2 = yAxisCoordinates[ 0 ][ 1 ]; 150 } 151 152 153 for( int i = 0; i < yAxisCoordinates.length; i++ ) 156 { 157 line.x1 = xAxisCoordinates[ i ][ 0 ]; 158 line.y1 = yAxisCoordinates[ i ][ 0 ]; 159 line.x2 = line.x1; 160 161 for( int j = 1; j < yAxisCoordinates[ 0 ].length; j++ ) 163 { 164 if( !Float.isNaN( yAxisCoordinates[ i ][ j ] ) ) 166 { 167 if( Float.isNaN( yAxisCoordinates[ i ][ j - 1 ] ) ) 169 { 170 line.x1 = xAxisCoordinates[ i ][ j ]; 171 line.y1 = yAxisCoordinates[ i ][ j ]; 172 line.x2 = xAxisCoordinates[ i ][ j ]; 173 line.y2 = yAxisCoordinates[ i ][ j ]; 174 continue; 175 } 176 177 178 line.x2 = xAxisCoordinates[ i ][ j ]; 179 line.y2 = yAxisCoordinates[ i ][ j ]; 180 181 g2d.setPaint( iScatterPlotDataSet.getPaint( i ) ); 182 g2d.setStroke( scatterPlotProperties.getLineStrokes()[ i ] ); 183 g2d.draw( line ); 184 185 if( scatterPlotProperties.getShapes()[ i ] != null ) 187 { 188 g2d.translate( line.x1 - cornerXOffset[ i ], line.y1 - cornerYOffset[ i ] ); 190 191 g2d.setPaint( iScatterPlotDataSet.getPaint( i ) ); 192 g2d.fill( scatterPlotProperties.getShapes()[ i ] ); 193 194 g2d.setTransform( originalTransform ); 196 } 197 198 line.x1 = line.x2; 199 line.y1 = line.y2; 200 } 201 else 202 { 203 if( (!Float.isNaN( yAxisCoordinates[ i ][ j - 1 ] )) && ( scatterPlotProperties.getShapes()[ i ] != null ) ) 204 { 205 g2d.translate( line.x1 - cornerXOffset[ i ], line.y1 - cornerYOffset[ i ] ); 207 208 g2d.setPaint( iScatterPlotDataSet.getPaint( i ) ); 209 g2d.fill( scatterPlotProperties.getShapes()[ i ] ); 210 211 g2d.setTransform( originalTransform ); 213 } 214 215 line.x2 = scatterPlotAxisChart.getXAxis().getScalePixelWidth(); 216 line.x1 = line.x2; 217 } 218 } 219 220 221 if( (!Float.isNaN( yAxisCoordinates[ i ][ yAxisCoordinates[ i ].length - 1 ] )) && ( scatterPlotProperties.getShapes()[ i ] != null ) ) 223 { 224 g2d.translate( line.x2 - cornerXOffset[ i ], line.y2 - cornerYOffset[ i ] ); 226 227 g2d.setPaint( iScatterPlotDataSet.getPaint( i ) ); 228 g2d.fill( scatterPlotProperties.getShapes()[ i ] ); 229 230 g2d.setTransform( originalTransform ); 232 } 233 } 234 } 235 236 237 } 238 | Popular Tags |