1 34 35 36 package org.krysalis.jcharts.axisChart.axis; 37 38 39 import org.krysalis.jcharts.axisChart.AxisChart; 40 import org.krysalis.jcharts.axisChart.axis.scale.ScaleCalculator; 41 import org.krysalis.jcharts.chartText.TextTagGroup; 42 import org.krysalis.jcharts.properties.util.ChartFont; 43 import org.krysalis.jcharts.properties.AxisTypeProperties; 44 import org.krysalis.jcharts.properties.DataAxisProperties; 45 import org.krysalis.jcharts.test.HTMLGenerator; 46 import org.krysalis.jcharts.test.HTMLTestable; 47 48 import java.awt.font.TextLayout ; 49 import java.io.Serializable ; 50 import java.lang.reflect.Field ; 51 52 53 58 abstract public class Axis implements HTMLTestable, Serializable 59 { 60 private AxisChart axisChart; 62 63 private float scalePixelWidth; 65 66 private float pixelLength; 68 69 private float origin; 71 72 73 private float titleHeight; 74 private float titleWidth; 75 76 private float minimumWidthNeeded; 77 private float minimumHeightNeeded; 78 79 private TextTagGroup axisLabelsGroup; 81 82 private TextTagGroup axisLabelsGroupRight; 86 87 private int numberOfScaleItems; 89 90 private float tickStart; 92 93 94 private double oneUnitPixelSize; 96 97 private float zeroLineCoordinate; 98 99 100 private ScaleCalculator scaleCalculator; 101 102 103 109 public Axis( AxisChart axisChart, int numberOfScaleItems ) 110 { 111 this.axisChart = axisChart; 112 this.numberOfScaleItems= numberOfScaleItems; 113 } 114 115 116 121 public final AxisChart getAxisChart() 122 { 123 return this.axisChart; 124 } 125 126 127 public int getNumberOfScaleItems() 128 { 129 return numberOfScaleItems; 130 } 131 132 133 public TextTagGroup getAxisLabelsGroup() 134 { 135 return axisLabelsGroup; 136 } 137 138 139 public void setAxisLabelsGroup( TextTagGroup axisLabelsGroup ) 140 { 141 this.axisLabelsGroup = axisLabelsGroup; 142 } 143 144 145 public TextTagGroup getAxisLabelsGroupRight() 147 { 148 return axisLabelsGroupRight; 149 } 150 151 public void setAxisLabelsGroupRight( TextTagGroup axisLabelsGroupRight ) 152 { 153 this.axisLabelsGroupRight = axisLabelsGroupRight; 154 } 155 156 public final float getTitleWidth() 157 { 158 return this.titleWidth; 159 } 160 161 162 public final float getTitleHeight() 163 { 164 return this.titleHeight; 165 } 166 167 168 public final float getPixelLength() 169 { 170 return this.pixelLength; 171 } 172 173 174 public final void setPixelLength( float pixelLength ) 175 { 176 this.pixelLength = pixelLength; 177 } 178 179 180 public final float getOrigin() 181 { 182 return this.origin; 183 } 184 185 186 public final void setOrigin( float origin ) 187 { 188 this.origin = origin; 189 } 190 191 192 public final float getMinimumWidthNeeded() 193 { 194 return this.minimumWidthNeeded; 195 } 196 197 198 public final void setMinimumWidthNeeded( float minimumWidthNeeded ) 199 { 200 this.minimumWidthNeeded = minimumWidthNeeded; 201 } 202 203 204 public final float getMinimumHeightNeeded() 205 { 206 return this.minimumHeightNeeded; 207 } 208 209 210 public final void setMinimumHeightNeeded( float minimumHeightNeeded ) 211 { 212 this.minimumHeightNeeded = minimumHeightNeeded; 213 } 214 215 216 public final float getScalePixelWidth() 217 { 218 return this.scalePixelWidth; 219 } 220 221 222 public final void setScalePixelWidth( float scalePixelWidth ) 223 { 224 this.scalePixelWidth = scalePixelWidth; 225 } 226 227 228 public float getTickStart() 229 { 230 return tickStart; 231 } 232 233 234 public void setTickStart( float tickStart ) 235 { 236 this.tickStart = tickStart; 237 } 238 239 240 public ScaleCalculator getScaleCalculator() 241 { 242 return scaleCalculator; 243 } 244 245 246 public void setScaleCalculator( ScaleCalculator scaleCalculator ) 247 { 248 this.scaleCalculator = scaleCalculator; 249 } 250 251 252 258 public final void computeAxisTitleDimensions( String title, ChartFont axisTitleFont ) 259 { 260 TextLayout textLayout = new TextLayout ( title, 261 axisTitleFont.getFont(), 262 this.getAxisChart().getGraphics2D().getFontRenderContext() ); 263 264 this.titleWidth = textLayout.getAdvance(); 265 this.titleHeight = textLayout.getAscent() + textLayout.getDescent(); 266 } 267 268 269 276 public void toHTML( HTMLGenerator htmlGenerator ) 277 { 278 String name = this.getClass().getSuperclass().getName() + "->"; 279 280 Field [] fields = this.getClass().getSuperclass().getDeclaredFields(); 282 for( int i = 0; i < fields.length; i++ ) 283 { 284 try 285 { 286 htmlGenerator.addField( name + fields[ i ].getName(), fields[ i ].get( this ) ); 287 } 288 catch( IllegalAccessException illegalAccessException ) 289 { 290 illegalAccessException.printStackTrace(); 291 } 292 } 293 } 294 295 296 300 public void computeScalePixelWidth( AxisTypeProperties axisTypeProperties ) 301 { 302 setScalePixelWidth( getPixelLength() / this.getNumberOfScaleItems() ); 303 } 304 305 306 310 public void computeScalePixelWidthDataAxis( AxisTypeProperties axisTypeProperties ) 311 { 312 if( axisTypeProperties instanceof DataAxisProperties ) { 315 setScalePixelWidth( (getPixelLength() - 5) / ( this.numberOfScaleItems - 1) ); 316 } 317 else { 318 setScalePixelWidth( (getPixelLength() ) / ( this.numberOfScaleItems - 1 ) ); 319 } 320 } 321 322 323 public void setOneUnitPixelSize( double oneUnitPixelSize ) 324 { 325 this.oneUnitPixelSize = oneUnitPixelSize; 326 } 327 328 329 334 public double getOneUnitPixelSize() 335 { 336 return this.oneUnitPixelSize; 337 } 338 339 340 347 public float getZeroLineCoordinate() 348 { 349 return this.zeroLineCoordinate; 350 } 351 352 353 359 public void setZeroLineCoordinate( float value ) 360 { 361 this.zeroLineCoordinate = value; 362 } 363 364 365 372 public void computeOneUnitPixelSize( float scalePixelLength, double increment ) 373 { 374 this.oneUnitPixelSize = scalePixelLength / increment; 375 } 376 377 378 } 379 | Popular Tags |