1 34 35 36 package org.krysalis.jcharts.axisChart; 37 38 39 import org.krysalis.jcharts.axisChart.axis.*; 40 import org.krysalis.jcharts.axisChart.axis.scale.*; 41 import org.krysalis.jcharts.chartData.interfaces.*; 42 import org.krysalis.jcharts.chartData.processors.AxisChartDataProcessor; 43 import org.krysalis.jcharts.chartData.processors.ScatterPlotDataProcessor; 44 import org.krysalis.jcharts.chartText.NumericTagGroup; 45 import org.krysalis.jcharts.imageMap.ImageMap; 46 import org.krysalis.jcharts.properties.*; 47 import org.krysalis.jcharts.test.HTMLChartTestable; 48 import org.krysalis.jcharts.test.HTMLGenerator; 49 import org.krysalis.jcharts.types.ChartType; 50 51 import java.awt.font.FontRenderContext ; 52 53 54 55 62 public class ScatterPlotAxisChart extends AxisChart implements HTMLChartTestable 63 { 64 65 75 public ScatterPlotAxisChart( IScatterPlotDataSeries iScatterPlotDataSeries, 76 ChartProperties chartProperties, 77 AxisProperties axisProperties, 78 LegendProperties legendProperties, 79 int pixelWidth, 80 int pixelHeight ) 81 { 82 super( iScatterPlotDataSeries, chartProperties, axisProperties, legendProperties, pixelWidth, pixelHeight ); 83 } 84 85 86 92 public AxisChartDataProcessor createAxisChartDataProcessor() 93 { 94 return new ScatterPlotDataProcessor(); 95 } 96 97 98 107 protected NumericTagGroup setupDataAxisProperties( Axis axis, 108 DataAxisProperties dataAxisProperties, 109 AxisChartDataProcessor axisChartDataProcessor, 110 FontRenderContext fontRenderContext ) 111 { 112 ScatterPlotDataProcessor scatterPlotDataProcessor= (ScatterPlotDataProcessor) axisChartDataProcessor; 114 115 if( dataAxisProperties.getScaleCalculator() == null ) 116 { 117 ScaleCalculator s; 118 119 if( dataAxisProperties.hasUserDefinedScale() ) 120 { 121 s = new UserDefinedScaleCalculator( dataAxisProperties.getUserDefinedMinimumValue(), dataAxisProperties.getUserDefinedIncrement() ); 122 } 123 else 124 { 125 s = new AutomaticScaleCalculator(); 126 if( axis instanceof XAxis ) 127 { 128 s.setMaxValue( scatterPlotDataProcessor.getMaxValue() ); 129 s.setMinValue( scatterPlotDataProcessor.getMinValue() ); 130 } 131 else 132 { 133 s.setMaxValue( scatterPlotDataProcessor.getyMax() ); 134 s.setMinValue( scatterPlotDataProcessor.getyMin() ); 135 } 136 } 137 138 axis.setScaleCalculator( s ); 139 } 140 else 141 { 142 axis.setScaleCalculator( dataAxisProperties.getScaleCalculator() ); 143 144 if( axis instanceof XAxis ) 145 { 146 axis.getScaleCalculator().setMaxValue( scatterPlotDataProcessor.getMaxValue() ); 147 axis.getScaleCalculator().setMinValue( scatterPlotDataProcessor.getMinValue() ); 148 } 149 else 150 { 151 axis.getScaleCalculator().setMaxValue( scatterPlotDataProcessor.getyMax() ); 152 axis.getScaleCalculator().setMinValue( scatterPlotDataProcessor.getyMin() ); 153 } 154 } 155 156 axis.getScaleCalculator().setRoundingPowerOfTen( dataAxisProperties.getRoundToNearest() ); 157 axis.getScaleCalculator().setNumberOfScaleItems( dataAxisProperties.getNumItems() ); 158 axis.getScaleCalculator().computeScaleValues(); 159 160 161 NumericTagGroup numericTagGroup = new NumericTagGroup( dataAxisProperties.getScaleChartFont(), 163 fontRenderContext, 164 dataAxisProperties.useDollarSigns(), 165 dataAxisProperties.usePercentSigns(), 166 dataAxisProperties.useCommas(), 167 dataAxisProperties.getRoundToNearest() ); 168 169 numericTagGroup.createAxisScaleLabels( axis.getScaleCalculator() ); 170 171 return numericTagGroup; 172 } 173 174 175 181 protected void setupAxis( AxisChartDataProcessor axisChartDataProcessor, FontRenderContext fontRenderContext ) 182 { 183 DataAxisProperties dataAxisProperties = (DataAxisProperties) this.getAxisProperties().getXAxisProperties(); 185 this.xAxis = new XAxis( this, dataAxisProperties.getNumItems() ); 186 NumericTagGroup numericTagGroup = this.setupDataAxisProperties( this.xAxis, dataAxisProperties, axisChartDataProcessor, fontRenderContext ); 187 this.xAxis.setAxisLabelsGroup( numericTagGroup ); 188 189 dataAxisProperties = (DataAxisProperties) this.getAxisProperties().getYAxisProperties(); 191 this.yAxis = new YAxis( this, dataAxisProperties.getNumItems() ); 192 numericTagGroup = this.setupDataAxisProperties( this.yAxis, dataAxisProperties, axisChartDataProcessor, fontRenderContext ); 193 this.yAxis.setAxisLabelsGroup( numericTagGroup ); 194 195 196 this.yAxis.computeMinimumWidthNeeded( super.getIAxisDataSeries().getYAxisTitle() ); 198 this.xAxis.computeMinimumHeightNeeded( super.getIAxisDataSeries().getXAxisTitle() ); 199 } 200 201 202 205 protected void deriveAxisValues() 206 { 207 this.xAxis.computeLabelFilter(); 211 212 this.xAxis.computeShouldTickStartAtYAxis( super.getIAxisDataSeries(), this.axisProperties.getXAxisProperties() ); 213 214 215 this.xAxis.computeScalePixelWidthDataAxis( this.axisProperties.getXAxisProperties() ); 218 this.xAxis.computeOneUnitPixelSize( this.xAxis.getScalePixelWidth(), this.xAxis.getScaleCalculator().getIncrement() ); 219 220 float zeroLineCoordinate = (float) (this.xAxis.getOrigin() + (this.xAxis.getScalePixelWidth() * (-this.xAxis.getScaleCalculator().getMinValue())) / this.xAxis.getScaleCalculator().getIncrement()); 222 this.xAxis.setZeroLineCoordinate( zeroLineCoordinate ); 223 224 225 this.yAxis.computeScalePixelWidthDataAxis( this.axisProperties.getYAxisProperties() ); 228 this.yAxis.computeOneUnitPixelSize( this.yAxis.getScalePixelWidth(), this.yAxis.getScaleCalculator().getIncrement() ); 229 230 zeroLineCoordinate = (float) (this.yAxis.getOrigin() - (this.yAxis.getScalePixelWidth() * (-this.yAxis.getScaleCalculator().getMinValue())) / this.yAxis.getScaleCalculator().getIncrement()); 232 this.yAxis.setZeroLineCoordinate( zeroLineCoordinate ); 233 234 this.xAxis.computeTickStart(); 235 } 236 237 238 244 protected void overlayCharts() throws PropertyException 245 { 246 IAxisPlotDataSet iAxisPlotDataSet = super.getIAxisDataSeries().getIAxisPlotDataSet( ChartType.SCATTER_PLOT ); 247 ScatterPlotChart.render( this, (IScatterPlotDataSet) iAxisPlotDataSet ); 248 } 249 250 251 259 public void toHTML( HTMLGenerator htmlGenerator, String imageFileName, ImageMap imageMap ) 260 { 261 htmlGenerator.chartTableStart( this.getClass().getName(), imageFileName, imageMap ); 262 263 269 270 htmlGenerator.chartTableRowStart(); 272 this.axisProperties.toHTML( htmlGenerator ); 273 htmlGenerator.chartTableRowEnd(); 274 275 276 htmlGenerator.chartTableRowStart(); 278 this.xAxis.toHTML( htmlGenerator ); 279 htmlGenerator.chartTableRowEnd(); 280 281 htmlGenerator.chartTableRowStart(); 283 this.yAxis.toHTML( htmlGenerator ); 284 htmlGenerator.chartTableRowEnd(); 285 286 287 htmlGenerator.chartTableRowStart(); 289 super.getChartProperties().toHTML( htmlGenerator ); 290 htmlGenerator.chartTableRowEnd(); 291 292 293 if( super.getLegend() != null ) 294 { 295 htmlGenerator.chartTableRowStart(); 296 this.getLegend().toHTML( htmlGenerator ); 297 htmlGenerator.chartTableRowEnd(); 298 } 299 300 htmlGenerator.chartTableEnd(); 301 } 302 303 } 304 | Popular Tags |