summaryrefslogtreecommitdiffstats
path: root/src/charts/pie.php
diff options
context:
space:
mode:
authorKore Nordmann <github@kore-nordmann.de>2006-07-11 08:49:26 +0000
committerKore Nordmann <github@kore-nordmann.de>2006-07-11 08:49:26 +0000
commit6f359d97e38932b0da23abb0940f32bf5380c0d8 (patch)
treebc6221534bf65aa6777245e7f555e943cdd2bbc6 /src/charts/pie.php
parent663493a7224dc7869c6c63d770016f9fd8850e2a (diff)
downloadzetacomponents-graph-6f359d97e38932b0da23abb0940f32bf5380c0d8.zip
zetacomponents-graph-6f359d97e38932b0da23abb0940f32bf5380c0d8.tar.gz
- Refactored ezcGraphRenderer
# Most test run again, but complete result is still errnous
Diffstat (limited to 'src/charts/pie.php')
-rw-r--r--src/charts/pie.php134
1 files changed, 13 insertions, 121 deletions
diff --git a/src/charts/pie.php b/src/charts/pie.php
index 3dd397f..d163238 100644
--- a/src/charts/pie.php
+++ b/src/charts/pie.php
@@ -63,131 +63,18 @@ class ezcGraphPieChart extends ezcGraphChart
{
$sum += $value;
}
-
- // Calculate position and size of pie
- $center = new ezcGraphCoordinate(
- (int) round( $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) / 2 ),
- (int) round( $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) / 2 )
- );
- // Limit radius to fourth of width and half of height at maximum
- $radius = min(
- ( $boundings->x1 - $boundings->x0 ) / 4,
- ( $boundings->y1 - $boundings->y0 ) / 2
- );
-
- // Draw all data
- $angle = 0.;
- $labels = array();
+ $angle = 0;
foreach ( $dataset as $label => $value )
{
$renderer->drawPieSegment(
+ $boundings,
$dataset->color[$label],
- $center,
- $radius * ( 1 - $this->options->moveOut ),
$angle,
- $endAngle = $angle + $value / $sum * 360,
- ( $dataset->highlight[$label] ? $radius * $this->options->moveOut : 0 )
+ $angle += $value / $sum * 360,
+ $label,
+ $dataset->highlight[$label]
);
-
- // Determine position of label
- $middle = $angle + ( $endAngle - $angle ) / 2;
- $pieSegmentCenter = new ezcGraphCoordinate(
- (int) round( cos( deg2rad( $middle ) ) * $radius + $center->x ),
- (int) round( sin( deg2rad( $middle ) ) * $radius + $center->y )
- );
-
- // Split labels up into left an right size and index them on their
- // y position
- $labels[(int) ($pieSegmentCenter->x > $center->x)][$pieSegmentCenter->y] = array(
- new ezcGraphCoordinate(
- (int) round( cos( deg2rad( $middle ) ) * $radius * 2 / 3 + $center->x ),
- (int) round( sin( deg2rad( $middle ) ) * $radius * 2 / 3 + $center->y )
- ),
- sprintf( $this->options->label, $label, $value, $value * 100 / $sum )
- );
- $angle = $endAngle;
- }
-
- $labelHeight = (int) round( min(
- ( $boundings->y1 - $boundings->y0 ) / count( $labels[0] ),
- ( $boundings->y1 - $boundings->y0 ) / count( $labels[1] ),
- ( $boundings->y1 - $boundings->y0 ) * $this->options->maxLabelHeight
- ) );
-
- $symbolSize = $this->options->symbolSize;
-
- // Finally draw labels
- foreach ( $labels as $side => $labelPart )
- {
- $minHeight = $boundings->y0;
- $toShare = ( $boundings->y1 - $boundings->y0 ) - count( $labelPart ) * $labelHeight;
-
- // Sort to draw topmost label first
- ksort( $labelPart );
- $sign = ( $side ? -1 : 1 );
-
- foreach ( $labelPart as $height => $label )
- {
- // Determine position of label
- $minHeight += round( max( 0, $height - $minHeight ) / ( $boundings->y1 - $boundings->y0 ) * $toShare );
- $labelPosition = new ezcGraphCoordinate(
- (int) round(
- $center->x -
- $sign * (
- cos ( asin ( ( $center->y - $minHeight - $labelHeight / 2 ) / $radius ) ) * $radius +
- $symbolSize * (int) $this->options->showSymbol
- )
- ),
- (int) round( $minHeight + $labelHeight / 2 )
- );
-
- if ( $this->options->showSymbol )
- {
- // Draw label
- $renderer->drawLine(
- $this->options->font->color,
- $label[0],
- $labelPosition,
- false
- );
-
- $renderer->drawSymbol(
- $this->options->font->color,
- new ezcGraphCoordinate(
- $label[0]->x - $symbolSize / 2,
- $label[0]->y - $symbolSize / 2
- ),
- $symbolSize,
- $symbolSize,
- ezcGraph::BULLET
- );
- $renderer->drawSymbol(
- $this->options->font->color,
- new ezcGraphCoordinate(
- $labelPosition->x - $symbolSize / 2,
- $labelPosition->y - $symbolSize / 2
- ),
- $symbolSize,
- $symbolSize,
- ezcGraph::BULLET
- );
- }
-
- $renderer->drawTextBox(
- new ezcGraphCoordinate(
- ( !$side ? $boundings->x0 : $labelPosition->x + $symbolSize ),
- $minHeight
- ),
- $label[1],
- (int) round( !$side ? $labelPosition->x - $boundings->x0 - $symbolSize : $boundings->x1 - $labelPosition->x - $symbolSize ),
- $labelHeight,
- ( !$side ? ezcGraph::RIGHT : ezcGraph::LEFT ) | ezcGraph::MIDDLE
- );
-
- // Add used space to minHeight
- $minHeight += $labelHeight;
- }
}
}
@@ -216,9 +103,14 @@ class ezcGraphPieChart extends ezcGraphChart
$boundings->y1 = $this->options->height;
// Render border and background
- $boundings = $this->renderBorder( $boundings );
- $boundings = $this->options->backgroundImage->render( $this->renderer, $boundings );
- $boundings = $this->renderBackground( $boundings );
+ $boundings = $this->renderer->drawBox(
+ $boundings,
+ $this->options->background,
+ $this->options->border,
+ $this->options->borderWidth,
+ $this->options->margin,
+ $this->options->padding
+ );
// Render subelements
foreach ( $this->elements as $name => $element )
OpenPOWER on IntegriCloud