* Draws the chart
*
************************************************************************************************/
protected void renderChart()
{
PieChart2DProperties properties = (PieChart2DProperties) this.iPieChartDataSet.getChartTypeProperties();
FontRenderContext fontRenderContext = super.getGraphics2D().getFontRenderContext();
this.pieChartDataProcessor = new PieChartDataProcessor( this.iPieChartDataSet );
this.pieChartDataProcessor.processData();
//---cache calcs used more than once
float edgePaddingTimesTwo = super.getChartProperties().getEdgePadding() * 2;
float halfImageWidth = super.getImageWidth() / 2;
float halfImageHeight = super.getImageHeight() / 2;
//---render the TITLE. If no title, this will return zero.
float chartTitleHeightPlusPadding = super.renderChartTitle( this.iPieChartDataSet.getChartTitle(), fontRenderContext );
//---figure out what size is needed to hold all the components of the pie chart, then size the pie accordingly
float widthAvailable = super.getImageWidth() - edgePaddingTimesTwo;
float heightAvailable = super.getImageHeight() - edgePaddingTimesTwo;
heightAvailable -= chartTitleHeightPlusPadding;
//---take labels sizing into consideration if needed.
if( !properties.getPieLabelType().equals( PieLabelType.NO_LABELS ) )
{
this.pieLabels = new PieLabels( properties, this.iPieChartDataSet, fontRenderContext );
//---if there is only one item in pie, label will be below plot so width is not a concern
if( iPieChartDataSet.getNumberOfDataItems() != 1 )
{
widthAvailable -= this.pieLabels.getWidestLabelTimesTwo();
widthAvailable -= ( properties.getTickLength() * 2 );
}
heightAvailable -= this.pieLabels.getTallestLabelTimesTwo();
heightAvailable -= ( properties.getTickLength() * 2 );
}
//---if there is a legend...
if( this.getLegend() != null )
{
float legendX = 0f;
float legendY = 0f;
//---calculate all the legend rendering coordinates and positions.
this.getLegend().calculateDrawingValues( iPieChartDataSet );
//---adjust width and height based on the Legend size.
if( ( this.getLegend().getLegendProperties().getPlacement() == LegendAreaProperties.RIGHT )
|| ( this.getLegend().getLegendProperties().getPlacement() == LegendAreaProperties.LEFT ) )
{
widthAvailable -= this.getLegend().getWidth();
widthAvailable -= this.getLegend().getLegendProperties().getChartPadding();
//---diameter of pie will be at least one pixel, even if the legend takes up the whole image.
//---this will keep the renderer from blowing up.
this.diameter = Math.max( widthAvailable, 1.0f );
//---make sure we do not make the pie diameter taller than the image
this.diameter = Math.min( this.diameter, heightAvailable );
//---calculate the entire width of everything to be drawn so can center everything
float plotWidth = this.diameter;
plotWidth += this.getLegend().getWidth();
plotWidth += this.getLegend().getLegendProperties().getChartPadding();
if( this.pieLabels != null )
{
plotWidth += ( this.pieLabels.getWidestLabel() * 2 );
plotWidth += ( properties.getTickLength() * 2 );
}
if( this.getLegend().getLegendProperties().getPlacement() == LegendAreaProperties.RIGHT )
{
//---pie's diameter may not fill image width as may be image height constrained.
this.pieX = halfImageWidth - ( plotWidth / 2 );
if( this.pieLabels != null )
{
this.pieX += this.pieLabels.getWidestLabel();
this.pieX += properties.getTickLength();
legendX += this.pieLabels.getWidestLabel();
legendX += properties.getTickLength();
}
//---position legend based on the pie position
legendX += this.pieX + this.diameter;
legendX += this.getLegend().getLegendProperties().getChartPadding();
}
else
{
legendX = halfImageWidth - ( plotWidth / 2 );
if( this.pieLabels != null )
{
this.pieX = legendX;
this.pieX += this.getLegend().getWidth();
this.pieX += this.getLegend().getLegendProperties().getChartPadding();
this.pieX += this.pieLabels.getWidestLabel();
this.pieX += properties.getTickLength();
}
}
//---center the legend vertically
legendY = halfImageHeight - ( this.getLegend().getHeight() / 2 );
//---center the pie vertically
this.pieY = halfImageHeight - ( this.diameter / 2 );
}
//---else the legend is either under or on top of the pie
else
{
heightAvailable-= this.getLegend().getHeight();
heightAvailable-= this.getLegend().getLegendProperties().getChartPadding();
//---diameter of pie will be at least one pixel, even if the legend takes up the whole image.
//---this will keep the renderer from blowing up.
this.diameter = Math.max( heightAvailable, 1.0f );
//---make sure we do not make the pie diameter wider than the image
this.diameter = Math.min( this.diameter, widthAvailable );
if( this.getLegend().getLegendProperties().getPlacement() == LegendAreaProperties.BOTTOM )
{
this.pieY = super.getChartProperties().getEdgePadding();
this.pieY += chartTitleHeightPlusPadding;
legendY+= this.diameter;
if( this.pieLabels != null )
{
//---adds label height from top of pie
this.pieY += this.pieLabels.getTallestLabel();
this.pieY += properties.getTickLength();
//---add label hight from bottom of pie
legendY += this.pieLabels.getTallestLabel();
legendY += properties.getTickLength();
}
legendY += this.pieY;
legendY+= this.getLegend().getLegendProperties().getChartPadding();
}
else
{
legendY = super.getChartProperties().getEdgePadding();
legendY += chartTitleHeightPlusPadding;
this.pieY= legendY;
this.pieY+= this.getLegend().getHeight();
this.pieY+= this.getLegend().getLegendProperties().getChartPadding();
if( this.pieLabels != null )
{
//---adds label height from top of pie
this.pieY += this.pieLabels.getTallestLabel();
this.pieY += properties.getTickLength();
}
}
//---center the legend horizontally
legendX = halfImageWidth - ( this.getLegend().getWidth() / 2 );