EZ-Components

This commit is contained in:
Andreas Österreicher
2009-02-17 15:27:43 +00:00
parent 359c3c55c9
commit 0a8e90a8b3
572 changed files with 64490 additions and 0 deletions
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,227 @@
<?php
/**
* File containing the ezcGraphAxisBoxedLabelRenderer class
*
* @package Graph
* @version 1.3
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
*/
/**
* Renders axis labels centered between two axis steps like normally used for
* bar charts. Used with other chart types this axis label renderer may cause
* unexpected results. You may use this renderer by assigning it to one of the
* charts axis.
*
* <code>
* $chart->xAxis->axisLabelRenderer = new ezcGraphAxisBoxedLabelRenderer();
* </code>
*
* @version 1.3
* @package Graph
* @mainclass
*/
class ezcGraphAxisBoxedLabelRenderer extends ezcGraphAxisLabelRenderer
{
/**
* Store step array for later coordinate modifications
*
* @var array(ezcGraphStep)
*/
protected $steps;
/**
* Store direction for later coordinate modifications
*
* @var ezcGraphVector
*/
protected $direction;
/**
* Store coordinate width modifier for later coordinate modifications
*
* @var float
*/
protected $widthModifier;
/**
* Constructor
*
* @param array $options Default option array
* @return void
* @ignore
*/
public function __construct( array $options = array() )
{
parent::__construct( $options );
$this->properties['outerStep'] = true;
}
/**
* Render Axis labels
*
* Render labels for an axis.
*
* @param ezcGraphRenderer $renderer Renderer used to draw the chart
* @param ezcGraphBoundings $boundings Boundings of the axis
* @param ezcGraphCoordinate $start Axis starting point
* @param ezcGraphCoordinate $end Axis ending point
* @param ezcGraphChartElementAxis $axis Axis instance
* @return void
*/
public function renderLabels(
ezcGraphRenderer $renderer,
ezcGraphBoundings $boundings,
ezcGraphCoordinate $start,
ezcGraphCoordinate $end,
ezcGraphChartElementAxis $axis )
{
// receive rendering parameters from axis
$steps = $axis->getSteps();
$this->steps = $steps;
$axisBoundings = new ezcGraphBoundings(
$start->x, $start->y,
$end->x, $end->y
);
// Determine normalized axis direction
$this->direction = new ezcGraphVector(
$start->x - $end->x,
$start->y - $end->y
);
$this->direction->unify();
if ( $this->outerGrid )
{
$gridBoundings = $boundings;
}
else
{
$gridBoundings = new ezcGraphBoundings(
$boundings->x0 + $renderer->xAxisSpace * abs( $this->direction->y ),
$boundings->y0 + $renderer->yAxisSpace * abs( $this->direction->x ),
$boundings->x1 - $renderer->xAxisSpace * abs( $this->direction->y ),
$boundings->y1 - $renderer->yAxisSpace * abs( $this->direction->x )
);
}
// Determine additional required axis space by boxes
$firstStep = reset( $steps );
$lastStep = end( $steps );
$this->widthModifier = 1 + $firstStep->width / 2 + $lastStep->width / 2;
// Draw steps and grid
foreach ( $steps as $nr => $step )
{
$position = new ezcGraphCoordinate(
$start->x + ( $end->x - $start->x ) * ( $step->position + $step->width ) / $this->widthModifier,
$start->y + ( $end->y - $start->y ) * ( $step->position + $step->width ) / $this->widthModifier
);
$stepWidth = $step->width / $this->widthModifier;
$stepSize = new ezcGraphCoordinate(
$axisBoundings->width * $stepWidth,
$axisBoundings->height * $stepWidth
);
if ( $this->showLabels )
{
// Calculate label boundings
switch ( true )
{
case ( abs( $this->direction->x ) > abs( $this->direction->y ) ) &&
( $this->direction->x <= 0 ):
$labelBoundings = new ezcGraphBoundings(
$position->x - $stepSize->x + $this->labelPadding,
$position->y + $this->labelPadding,
$position->x - $this->labelPadding,
$position->y + $renderer->yAxisSpace - $this->labelPadding
);
$alignement = ezcGraph::CENTER | ezcGraph::TOP;
break;
case ( abs( $this->direction->x ) > abs( $this->direction->y ) ) &&
( $this->direction->x > 0 ):
$labelBoundings = new ezcGraphBoundings(
$position->x + $this->labelPadding,
$position->y + $this->labelPadding,
$position->x + $stepSize->x - $this->labelPadding,
$position->y + $renderer->yAxisSpace - $this->labelPadding
);
$alignement = ezcGraph::CENTER | ezcGraph::TOP;
break;
case ( $this->direction->y <= 0 ):
$labelBoundings = new ezcGraphBoundings(
$position->x - $renderer->xAxisSpace + $this->labelPadding,
$position->y - $stepSize->y + $this->labelPadding,
$position->x - $this->labelPadding,
$position->y - $this->labelPadding
);
$alignement = ezcGraph::MIDDLE | ezcGraph::RIGHT;
break;
case ( $this->direction->y > 0 ):
$labelBoundings = new ezcGraphBoundings(
$position->x - $renderer->xAxisSpace + $this->labelPadding,
$position->y + $this->labelPadding,
$position->x - $this->labelPadding,
$position->y + $stepSize->y - $this->labelPadding
);
$alignement = ezcGraph::MIDDLE | ezcGraph::RIGHT;
break;
}
$renderer->drawText( $labelBoundings, $step->label, $alignement );
}
// major grid
if ( $axis->majorGrid )
{
$this->drawGrid(
$renderer,
$gridBoundings,
$position,
$stepSize,
$axis->majorGrid
);
}
// major step
$this->drawStep(
$renderer,
$position,
$this->direction,
$axis->position,
$this->majorStepSize,
$axis->border
);
}
}
/**
* Modify chart data position
*
* Optionally additionally modify the coodinate of a data point
*
* @param ezcGraphCoordinate $coordinate Data point coordinate
* @return ezcGraphCoordinate Modified coordinate
*/
public function modifyChartDataPosition( ezcGraphCoordinate $coordinate )
{
$firstStep = reset( $this->steps );
$offset = $firstStep->width / 2 / $this->widthModifier;
return new ezcGraphCoordinate(
$coordinate->x * abs( $this->direction->y ) +
( $coordinate->x / $this->widthModifier + $offset ) * abs( $this->direction->x ),
$coordinate->y * abs( $this->direction->x ) +
( $coordinate->y / $this->widthModifier + $offset ) * abs( $this->direction->y )
);
}
}
?>
@@ -0,0 +1,275 @@
<?php
/**
* File containing the ezcGraphAxisCenteredLabelRenderer class
*
* @package Graph
* @version 1.3
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
*/
/**
* Renders axis labels centered below the axis steps.
*
* <code>
* $chart->xAxis->axisLabelRenderer = new ezcGraphAxisCenteredLabelRenderer();
* </code>
*
* @property bool $showZeroValue
* Show the value at the zero point of an axis. This value might be
* crossed by the other axis which would result in an unreadable
* label.
*
* @version 1.3
* @package Graph
* @mainclass
*/
class ezcGraphAxisCenteredLabelRenderer extends ezcGraphAxisLabelRenderer
{
/**
* Constructor
*
* @param array $options Default option array
* @return void
* @ignore
*/
public function __construct( array $options = array() )
{
$this->properties['showZeroValue'] = false;
parent::__construct( $options );
}
/**
* __set
*
* @param mixed $propertyName
* @param mixed $propertyValue
* @throws ezcBaseValueException
* If a submitted parameter was out of range or type.
* @throws ezcBasePropertyNotFoundException
* If a the value for the property options is not an instance of
* @return void
* @ignore
*/
public function __set( $propertyName, $propertyValue )
{
switch ( $propertyName )
{
case 'showZeroValue':
if ( !is_bool( $propertyValue ) )
{
throw new ezcBaseValueException( $propertyName, $propertyValue, 'bool' );
}
$this->properties['showZeroValue'] = (bool) $propertyValue;
break;
default:
return parent::__set( $propertyName, $propertyValue );
}
}
/**
* Render Axis labels
*
* Render labels for an axis.
*
* @param ezcGraphRenderer $renderer Renderer used to draw the chart
* @param ezcGraphBoundings $boundings Boundings of the axis
* @param ezcGraphCoordinate $start Axis starting point
* @param ezcGraphCoordinate $end Axis ending point
* @param ezcGraphChartElementAxis $axis Axis instance
* @return void
*/
public function renderLabels(
ezcGraphRenderer $renderer,
ezcGraphBoundings $boundings,
ezcGraphCoordinate $start,
ezcGraphCoordinate $end,
ezcGraphChartElementAxis $axis )
{
// receive rendering parameters from axis
$steps = $axis->getSteps();
$axisBoundings = new ezcGraphBoundings(
$start->x, $start->y,
$end->x, $end->y
);
// Determine normalized axis direction
$direction = new ezcGraphVector(
$start->x - $end->x,
$start->y - $end->y
);
$direction->unify();
if ( $this->outerGrid )
{
$gridBoundings = $boundings;
}
else
{
$gridBoundings = new ezcGraphBoundings(
$boundings->x0 + $renderer->xAxisSpace * abs( $direction->y ),
$boundings->y0 + $renderer->yAxisSpace * abs( $direction->x ),
$boundings->x1 - $renderer->xAxisSpace * abs( $direction->y ),
$boundings->y1 - $renderer->yAxisSpace * abs( $direction->x )
);
}
// Draw steps and grid
foreach ( $steps as $nr => $step )
{
$position = new ezcGraphCoordinate(
$start->x + ( $end->x - $start->x ) * $step->position,
$start->y + ( $end->y - $start->y ) * $step->position
);
$stepSize = new ezcGraphCoordinate(
$axisBoundings->width * $step->width,
$axisBoundings->height * $step->width
);
if ( ! $step->isZero )
{
// major grid
if ( $axis->majorGrid )
{
$this->drawGrid(
$renderer,
$gridBoundings,
$position,
$stepSize,
$axis->majorGrid
);
}
// major step
$this->drawStep(
$renderer,
$position,
$direction,
$axis->position,
$this->majorStepSize,
$axis->border
);
}
// draw label
if ( $this->showLabels && ( $this->showZeroValue || ! $step->isZero ) )
{
// Calculate label boundings
if ( abs( $direction->x ) > abs( $direction->y ) )
{
// Horizontal labels
switch ( true )
{
case ( $nr === 0 ):
// First label
$labelSize = min(
$renderer->xAxisSpace * 2,
$step->width * $axisBoundings->width
);
break;
case ( $step->isLast ):
// Last label
$labelSize = min(
$renderer->xAxisSpace * 2,
$steps[$nr - 1]->width * $axisBoundings->width
);
break;
default:
$labelSize = min(
$step->width * $axisBoundings->width,
$steps[$nr - 1]->width * $axisBoundings->width
);
break;
}
$labelBoundings = new ezcGraphBoundings(
$position->x - $labelSize / 2 + $this->labelPadding,
$position->y + $this->labelPadding,
$position->x + $labelSize / 2 - $this->labelPadding,
$position->y + $renderer->yAxisSpace - $this->labelPadding
);
$alignement = ezcGraph::CENTER | ezcGraph::TOP;
}
else
{
// Vertical labels
switch ( true )
{
case ( $nr === 0 ):
// First label
$labelSize = min(
$renderer->yAxisSpace * 2,
$step->width * $axisBoundings->height
);
break;
case ( $step->isLast ):
// Last label
$labelSize = min(
$renderer->yAxisSpace * 2,
$steps[$nr - 1]->width * $axisBoundings->height
);
break;
default:
$labelSize = min(
$step->width * $axisBoundings->height,
$steps[$nr - 1]->width * $axisBoundings->height
);
break;
}
$labelBoundings = new ezcGraphBoundings(
$position->x - $renderer->xAxisSpace + $this->labelPadding,
$position->y - $labelSize / 2 + $this->labelPadding,
$position->x - $this->labelPadding,
$position->y + $labelSize / 2 - $this->labelPadding
);
$alignement = ezcGraph::MIDDLE | ezcGraph::RIGHT;
}
$renderer->drawText( $labelBoundings, $step->label, $alignement );
}
// Iterate over minor steps
if ( !$step->isLast )
{
foreach ( $step->childs as $minorStep )
{
$minorStepPosition = new ezcGraphCoordinate(
$start->x + ( $end->x - $start->x ) * $minorStep->position,
$start->y + ( $end->y - $start->y ) * $minorStep->position
);
$minorStepSize = new ezcGraphCoordinate(
$axisBoundings->width * $minorStep->width,
$axisBoundings->height * $minorStep->width
);
if ( $axis->minorGrid )
{
$this->drawGrid(
$renderer,
$gridBoundings,
$minorStepPosition,
$minorStepSize,
$axis->minorGrid
);
}
// major step
$this->drawStep(
$renderer,
$minorStepPosition,
$direction,
$axis->position,
$this->minorStepSize,
$axis->border
);
}
}
}
}
}
?>
@@ -0,0 +1,279 @@
<?php
/**
* File containing the ezcGraphAxisExactLabelRenderer class
*
* @package Graph
* @version 1.3
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
*/
/**
* Renders axis labels like known from charts drawn in analysis
*
* <code>
* $chart->xAxis->axisLabelRenderer = new ezcGraphAxisExactLabelRenderer();
* </code>
*
* @property bool $showLastValue
* Show the last value on the axis, which will be aligned different
* than all other values, to not interfere with the arrow head of
* the axis.
*
* @version 1.3
* @package Graph
* @mainclass
*/
class ezcGraphAxisExactLabelRenderer extends ezcGraphAxisLabelRenderer
{
/**
* Constructor
*
* @param array $options Default option array
* @return void
* @ignore
*/
public function __construct( array $options = array() )
{
$this->properties['showLastValue'] = true;
parent::__construct( $options );
}
/**
* __set
*
* @param mixed $propertyName
* @param mixed $propertyValue
* @throws ezcBaseValueException
* If a submitted parameter was out of range or type.
* @throws ezcBasePropertyNotFoundException
* If a the value for the property options is not an instance of
* @return void
* @ignore
*/
public function __set( $propertyName, $propertyValue )
{
switch ( $propertyName )
{
case 'showLastValue':
if ( !is_bool( $propertyValue ) )
{
throw new ezcBaseValueException( $propertyName, $propertyValue, 'bool' );
}
$this->properties['showLastValue'] = (bool) $propertyValue;
break;
default:
return parent::__set( $propertyName, $propertyValue );
}
}
/**
* Render Axis labels
*
* Render labels for an axis.
*
* @param ezcGraphRenderer $renderer Renderer used to draw the chart
* @param ezcGraphBoundings $boundings Boundings of the axis
* @param ezcGraphCoordinate $start Axis starting point
* @param ezcGraphCoordinate $end Axis ending point
* @param ezcGraphChartElementAxis $axis Axis instance
* @return void
*/
public function renderLabels(
ezcGraphRenderer $renderer,
ezcGraphBoundings $boundings,
ezcGraphCoordinate $start,
ezcGraphCoordinate $end,
ezcGraphChartElementAxis $axis )
{
// receive rendering parameters from axis
$steps = $axis->getSteps();
$axisBoundings = new ezcGraphBoundings(
$start->x, $start->y,
$end->x, $end->y
);
// Determine normalized axis direction
$direction = new ezcGraphVector(
$start->x - $end->x,
$start->y - $end->y
);
$direction->unify();
if ( $this->outerGrid )
{
$gridBoundings = $boundings;
}
else
{
$gridBoundings = new ezcGraphBoundings(
$boundings->x0 + $renderer->xAxisSpace * abs( $direction->y ),
$boundings->y0 + $renderer->yAxisSpace * abs( $direction->x ),
$boundings->x1 - $renderer->xAxisSpace * abs( $direction->y ),
$boundings->y1 - $renderer->yAxisSpace * abs( $direction->x )
);
}
// Draw steps and grid
foreach ( $steps as $nr => $step )
{
$position = new ezcGraphCoordinate(
$start->x + ( $end->x - $start->x ) * $step->position,
$start->y + ( $end->y - $start->y ) * $step->position
);
$stepSize = new ezcGraphCoordinate(
$axisBoundings->width * $step->width,
$axisBoundings->height * $step->width
);
if ( ! $step->isZero )
{
// major grid
if ( $axis->majorGrid )
{
$this->drawGrid(
$renderer,
$gridBoundings,
$position,
$stepSize,
$axis->majorGrid
);
}
// major step
$this->drawStep(
$renderer,
$position,
$direction,
$axis->position,
$this->majorStepSize,
$axis->border
);
}
if ( $this->showLabels )
{
switch ( $axis->position )
{
case ezcGraph::RIGHT:
case ezcGraph::LEFT:
$labelWidth = $axisBoundings->width *
$steps[$nr - $step->isLast]->width /
( $this->showLastValue + 1 );
$labelHeight = $renderer->yAxisSpace;
break;
case ezcGraph::BOTTOM:
case ezcGraph::TOP:
$labelWidth = $renderer->xAxisSpace;
$labelHeight = $axisBoundings->height *
$steps[$nr - $step->isLast]->width /
( $this->showLastValue + 1 );
break;
}
$showLabel = true;
switch ( true )
{
case ( !$this->showLastValue && $step->isLast ):
// Skip last step if showLastValue is false
$showLabel = false;
break;
// Draw label at top left of step
case ( ( $axis->position === ezcGraph::BOTTOM ) &&
( !$step->isLast ) ) ||
( ( $axis->position === ezcGraph::TOP ) &&
( $step->isLast ) ):
$labelBoundings = new ezcGraphBoundings(
$position->x - $labelWidth + $this->labelPadding,
$position->y - $labelHeight + $this->labelPadding,
$position->x - $this->labelPadding,
$position->y - $this->labelPadding
);
$alignement = ezcGraph::RIGHT | ezcGraph::BOTTOM;
break;
// Draw label at bottom right of step
case ( ( $axis->position === ezcGraph::LEFT ) &&
( !$step->isLast ) ) ||
( ( $axis->position === ezcGraph::RIGHT ) &&
( $step->isLast ) ):
$labelBoundings = new ezcGraphBoundings(
$position->x + $this->labelPadding,
$position->y + $this->labelPadding,
$position->x + $labelWidth - $this->labelPadding,
$position->y + $labelHeight - $this->labelPadding
);
$alignement = ezcGraph::LEFT | ezcGraph::TOP;
break;
// Draw label at bottom left of step
case ( ( $axis->position === ezcGraph::TOP ) &&
( !$step->isLast ) ) ||
( ( $axis->position === ezcGraph::RIGHT ) &&
( !$step->isLast ) ) ||
( ( $axis->position === ezcGraph::BOTTOM ) &&
( $step->isLast ) ) ||
( ( $axis->position === ezcGraph::LEFT ) &&
( $step->isLast ) ):
$labelBoundings = new ezcGraphBoundings(
$position->x - $labelWidth + $this->labelPadding,
$position->y + $this->labelPadding,
$position->x - $this->labelPadding,
$position->y + $labelHeight - $this->labelPadding
);
$alignement = ezcGraph::RIGHT | ezcGraph::TOP;
break;
}
if ( $showLabel )
{
$renderer->drawText(
$labelBoundings,
$step->label,
$alignement
);
}
}
if ( !$step->isLast )
{
// Iterate over minor steps
foreach ( $step->childs as $minorStep )
{
$minorStepPosition = new ezcGraphCoordinate(
$start->x + ( $end->x - $start->x ) * $minorStep->position,
$start->y + ( $end->y - $start->y ) * $minorStep->position
);
$minorStepSize = new ezcGraphCoordinate(
$axisBoundings->width * $minorStep->width,
$axisBoundings->height * $minorStep->width
);
if ( $axis->minorGrid )
{
$this->drawGrid(
$renderer,
$gridBoundings,
$minorStepPosition,
$minorStepSize,
$axis->minorGrid
);
}
// major step
$this->drawStep(
$renderer,
$minorStepPosition,
$direction,
$axis->position,
$this->minorStepSize,
$axis->border
);
}
}
}
}
}
?>
@@ -0,0 +1,44 @@
<?php
/**
* File containing the abstract ezcGraphAxisNoLabelRenderer class
*
* @package Graph
* @version 1.3
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
*/
/**
* Omits axis labels, steps and grid.
*
* <code>
* $chart->xAxis->axisLabelRenderer = new ezcGraphAxisNoLabelRenderer();
* </code>
*
* @version 1.3
* @package Graph
*/
class ezcGraphAxisNoLabelRenderer extends ezcGraphAxisLabelRenderer
{
/**
* Render Axis labels
*
* Render labels for an axis.
*
* @param ezcGraphRenderer $renderer Renderer used to draw the chart
* @param ezcGraphBoundings $boundings Boundings of the axis
* @param ezcGraphCoordinate $start Axis starting point
* @param ezcGraphCoordinate $end Axis ending point
* @param ezcGraphChartElementAxis $axis Axis instance
* @return void
*/
public function renderLabels(
ezcGraphRenderer $renderer,
ezcGraphBoundings $boundings,
ezcGraphCoordinate $start,
ezcGraphCoordinate $end,
ezcGraphChartElementAxis $axis )
{
return true;
}
}
?>
@@ -0,0 +1,322 @@
<?php
/**
* File containing the ezcGraphAxisRadarLabelRenderer class
*
* @package Graph
* @version 1.3
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
*/
/**
* Renders axis labels and grid optimized for radar charts. May cause
* unexpected results when used with other chart types.
*
* <code>
* $chart->xAxis->axisLabelRenderer = new ezcGraphAxisRadarLabelRenderer();
* </code>
*
* @property float $lastStep
* Position of last step on the axis to calculate the grid.
*
* @version 1.3
* @package Graph
* @mainclass
*/
class ezcGraphAxisRadarLabelRenderer extends ezcGraphAxisLabelRenderer
{
/**
* Constructor
*
* @param array $options Default option array
* @return void
* @ignore
*/
public function __construct( array $options = array() )
{
$this->properties['lastStep'] = null;
parent::__construct( $options );
}
/**
* __set
*
* @param mixed $propertyName
* @param mixed $propertyValue
* @throws ezcBaseValueException
* If a submitted parameter was out of range or type.
* @throws ezcBasePropertyNotFoundException
* If a the value for the property options is not an instance of
* @return void
* @ignore
*/
public function __set( $propertyName, $propertyValue )
{
switch ( $propertyName )
{
case 'lastStep':
if ( !is_null( $propertyValue ) &&
( !is_float( $propertyValue ) ||
( $propertyValue < 0 ) ||
( $propertyValue > 1 ) ) )
{
throw new ezcBaseValueException( $propertyName, $propertyValue, '0 <= float <= 1' );
}
$this->properties['lastStep'] = $propertyValue;
break;
default:
return parent::__set( $propertyName, $propertyValue );
}
}
/**
* Render Axis labels
*
* Render labels for an axis.
*
* @param ezcGraphRenderer $renderer Renderer used to draw the chart
* @param ezcGraphBoundings $boundings Boundings of the axis
* @param ezcGraphCoordinate $start Axis starting point
* @param ezcGraphCoordinate $end Axis ending point
* @param ezcGraphChartElementAxis $axis Axis instance
* @return void
*/
public function renderLabels(
ezcGraphRenderer $renderer,
ezcGraphBoundings $boundings,
ezcGraphCoordinate $start,
ezcGraphCoordinate $end,
ezcGraphChartElementAxis $axis )
{
// receive rendering parameters from axis
$steps = $axis->getSteps();
$axisBoundings = new ezcGraphBoundings(
$start->x, $start->y,
$end->x, $end->y
);
// Determine normalized axis direction
$direction = new ezcGraphVector(
$start->x - $end->x,
$start->y - $end->y
);
$direction->unify();
// Draw steps and grid
foreach ( $steps as $nr => $step )
{
$position = new ezcGraphCoordinate(
$start->x + ( $end->x - $start->x ) * $step->position,
$start->y + ( $end->y - $start->y ) * $step->position
);
$stepSize = new ezcGraphCoordinate(
$axisBoundings->width * $step->width,
$axisBoundings->height * $step->width
);
// Draw major grid
if ( ( $this->lastStep !== null ) && $axis->majorGrid )
{
$this->drawGrid(
$renderer,
$boundings,
$position,
$stepSize,
$axis->majorGrid,
$step->position
);
}
// major step
$this->drawStep(
$renderer,
$position,
$direction,
$axis->position,
$this->majorStepSize,
$axis->border
);
// draw label
if ( $this->showLabels && ( $this->lastStep === null ) )
{
// Calculate label boundings
if ( abs( $direction->x ) > abs( $direction->y ) )
{
// Horizontal labels
switch ( true )
{
case ( $nr === 0 ):
// First label
$labelSize = min(
$renderer->xAxisSpace * 2,
$step->width * $axisBoundings->width
);
break;
case ( $step->isLast ):
// Last label
$labelSize = min(
$renderer->xAxisSpace * 2,
$steps[$nr - 1]->width * $axisBoundings->width
);
break;
default:
$labelSize = min(
$step->width * $axisBoundings->width,
$steps[$nr - 1]->width * $axisBoundings->width
);
break;
}
$labelBoundings = new ezcGraphBoundings(
$position->x - $labelSize / 2 + $this->labelPadding,
$position->y + $this->labelPadding,
$position->x + $labelSize / 2 - $this->labelPadding,
$position->y + $renderer->yAxisSpace - $this->labelPadding
);
$alignement = ezcGraph::CENTER | ezcGraph::TOP;
}
else
{
// Vertical labels
switch ( true )
{
case ( $nr === 0 ):
// First label
$labelSize = min(
$renderer->yAxisSpace * 2,
$step->width * $axisBoundings->height
);
break;
case ( $step->isLast ):
// Last label
$labelSize = min(
$renderer->yAxisSpace * 2,
$steps[$nr - 1]->width * $axisBoundings->height
);
break;
default:
$labelSize = min(
$step->width * $axisBoundings->height,
$steps[$nr - 1]->width * $axisBoundings->height
);
break;
}
$labelBoundings = new ezcGraphBoundings(
$position->x - $renderer->xAxisSpace + $this->labelPadding,
$position->y - $labelSize / 2 + $this->labelPadding,
$position->x - $this->labelPadding,
$position->y + $labelSize / 2 - $this->labelPadding
);
$alignement = ezcGraph::MIDDLE | ezcGraph::RIGHT;
}
$renderer->drawText( $labelBoundings, $step->label, $alignement );
}
// Iterate over minor steps
if ( !$step->isLast )
{
foreach ( $step->childs as $minorStep )
{
$minorStepPosition = new ezcGraphCoordinate(
$start->x + ( $end->x - $start->x ) * $minorStep->position,
$start->y + ( $end->y - $start->y ) * $minorStep->position
);
$minorStepSize = new ezcGraphCoordinate(
$axisBoundings->width * $minorStep->width,
$axisBoundings->height * $minorStep->width
);
if ( ( $this->lastStep !== null ) && $axis->minorGrid )
{
$this->drawGrid(
$renderer,
$boundings,
$minorStepPosition,
$minorStepSize,
$axis->minorGrid,
$minorStep->position
);
}
// major step
$this->drawStep(
$renderer,
$minorStepPosition,
$direction,
$axis->position,
$this->minorStepSize,
$axis->border
);
}
}
}
}
/**
* Draw grid
*
* Draws a grid line at the current position
*
* @param ezcGraphRenderer $renderer Renderer to draw the grid with
* @param ezcGraphBoundings $boundings Boundings of axis
* @param ezcGraphCoordinate $position Position of step
* @param ezcGraphCoordinate $direction Direction of axis
* @param ezcGraphColor $color Color of axis
* @param int $stepPosition
* @return void
*/
protected function drawGrid( ezcGraphRenderer $renderer, ezcGraphBoundings $boundings, ezcGraphCoordinate $position, ezcGraphCoordinate $direction, ezcGraphColor $color, $stepPosition = null )
{
// Calculate position on last axis
$start = new ezcGraphCoordinate(
$boundings->x0 + $width = ( $boundings->width / 2 ),
$boundings->y0 + $height = ( $boundings->height / 2 )
);
$lastAngle = $this->lastStep * 2 * M_PI;
$end = new ezcGraphCoordinate(
$start->x + sin( $lastAngle ) * $width,
$start->y - cos( $lastAngle ) * $height
);
$direction = new ezcGraphVector(
$end->x - $start->x,
$end->y - $start->y
);
$direction->unify();
// Convert elipse to circle for correct angle calculation
$direction->y *= ( $renderer->xAxisSpace / $renderer->yAxisSpace );
$angle = $direction->angle( new ezcGraphVector( 0, 1 ) );
$movement = new ezcGraphVector(
sin( $angle ) * $renderer->xAxisSpace
* ( $direction->x < 0 ? -1 : 1 ),
cos( $angle ) * $renderer->yAxisSpace
);
$start->x += $movement->x;
$start->y += $movement->y;
$end->x -= $movement->x;
$end->y -= $movement->y;
$lastPosition = new ezcGraphCoordinate(
$start->x + ( $end->x - $start->x ) * $stepPosition,
$start->y + ( $end->y - $start->y ) * $stepPosition
);
$renderer->drawGridLine(
$position,
$lastPosition,
$color
);
}
}
?>
@@ -0,0 +1,428 @@
<?php
/**
* File containing the ezcGraphAxisRotatedLabelRenderer class
*
* @package Graph
* @version 1.3
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
*/
/**
* Can render axis labels rotated, so that more axis labels fit on one axis.
* Produces best results if the axis space was increased, so that more spcae is
* available below the axis.
*
* <code>
* $chart->xAxis->axisLabelRenderer = new ezcGraphAxisRotatedLabelRenderer();
*
* // Define angle manually in degree
* $chart->xAxis->axisLabelRenderer->angle = 45;
*
* // Increase axis space
* $chart->xAxis->axisSpace = .2;
* </code>
*
* @property float $angle
* Angle of labels on axis in degrees.
*
* @version 1.3
* @package Graph
* @mainclass
*/
class ezcGraphAxisRotatedLabelRenderer extends ezcGraphAxisLabelRenderer
{
/**
* Store step array for later coordinate modifications
*
* @var array(ezcGraphStep)
*/
protected $steps;
/**
* Store direction for later coordinate modifications
*
* @var ezcGraphVector
*/
protected $direction;
/**
* Store coordinate width modifier for later coordinate modifications
*
* @var float
*/
protected $widthModifier;
/**
* Store coordinate offset for later coordinate modifications
*
* @var float
*/
protected $offset;
/**
* Constructor
*
* @param array $options Default option array
* @return void
* @ignore
*/
public function __construct( array $options = array() )
{
parent::__construct( $options );
$this->properties['angle'] = null;
}
/**
* __set
*
* @param mixed $propertyName
* @param mixed $propertyValue
* @throws ezcBaseValueException
* If a submitted parameter was out of range or type.
* @throws ezcBasePropertyNotFoundException
* If a the value for the property options is not an instance of
* @return void
* @ignore
*/
public function __set( $propertyName, $propertyValue )
{
switch ( $propertyName )
{
case 'angle':
if ( !is_numeric( $propertyValue ) )
{
throw new ezcBaseValueException( $propertyName, $propertyValue, '0 <= float < 360' );
}
$reducement = (int) ( $propertyValue - $propertyValue % 360 );
$this->properties['angle'] = (float) $propertyValue - $reducement;
break;
default:
return parent::__set( $propertyName, $propertyValue );
}
}
/**
* Render Axis labels
*
* Render labels for an axis.
*
* @param ezcGraphRenderer $renderer Renderer used to draw the chart
* @param ezcGraphBoundings $boundings Boundings of the axis
* @param ezcGraphCoordinate $start Axis starting point
* @param ezcGraphCoordinate $end Axis ending point
* @param ezcGraphChartElementAxis $axis Axis instance
* @return void
*/
public function renderLabels(
ezcGraphRenderer $renderer,
ezcGraphBoundings $boundings,
ezcGraphCoordinate $start,
ezcGraphCoordinate $end,
ezcGraphChartElementAxis $axis )
{
// receive rendering parameters from axis
$steps = $axis->getSteps();
$this->steps = $steps;
$axisBoundings = new ezcGraphBoundings(
$start->x, $start->y,
$end->x, $end->y
);
// Determine normalized axis direction
$this->direction = new ezcGraphVector(
$end->x - $start->x,
$end->y - $start->y
);
$this->direction->unify();
$axisAngle = -$this->direction->angle( new ezcGraphVector( 1, 0 ) );
if ( $this->outerGrid )
{
$gridBoundings = $boundings;
}
else
{
$gridBoundings = new ezcGraphBoundings(
$boundings->x0 + $renderer->xAxisSpace,
$boundings->y0 + $renderer->yAxisSpace,
$boundings->x1 - $renderer->xAxisSpace,
$boundings->y1 - $renderer->yAxisSpace
);
}
// Determine optimal angle if none specified
if ( $this->angle === null )
{
$minimumStepWidth = null;
foreach ( $steps as $nr => $step )
{
if ( ( $minimumStepWidth === null ) ||
( $step->width < $minimumStepWidth ) )
{
$minimumStepWidth = $step->width;
}
}
$width = abs(
$axisBoundings->width * $minimumStepWidth * $this->direction->x +
$axisBoundings->height * $minimumStepWidth * $this->direction->y
);
$height = abs(
$renderer->yAxisSpace * $this->direction->x +
$renderer->xAxisSpace * $this->direction->y
);
$length = sqrt( pow( $width, 2 ) + pow( $height, 2 ) );
$this->angle = rad2deg( acos( $height / $length ) );
}
// Determine additional required axis space by boxes
$firstStep = reset( $steps );
$lastStep = end( $steps );
$textAngle = $axisAngle +
deg2rad( $this->angle ) +
( $axis->position & ( ezcGraph::TOP | ezcGraph::BOTTOM ) ? deg2rad( 270 ) : deg2rad( 90 ) );
// Ensure angle between 0 and 360 degrees
$degTextAngle = rad2deg( $textAngle );
while ( $degTextAngle < 0 )
{
$degTextAngle += 360.;
}
$this->offset =
( $this->angle < 0 ? -1 : 1 ) *
( $axis->position & ( ezcGraph::TOP | ezcGraph::LEFT ) ? 1 : -1 ) *
( 1 - cos( deg2rad( $this->angle * 2 ) ) );
$axisSpaceFactor = abs(
( $this->direction->x == 0 ? 0 :
$this->direction->x * $renderer->yAxisSpace / $axisBoundings->width ) +
( $this->direction->y == 0 ? 0 :
$this->direction->y * $renderer->xAxisSpace / $axisBoundings->height )
);
$start = new ezcGraphCoordinate(
$start->x + max( 0., $axisSpaceFactor * $this->offset ) * ( $end->x - $start->x ),
$start->y + max( 0., $axisSpaceFactor * $this->offset ) * ( $end->y - $start->y )
);
$end = new ezcGraphCoordinate(
$end->x + min( 0., $axisSpaceFactor * $this->offset ) * ( $end->x - $start->x ),
$end->y + min( 0., $axisSpaceFactor * $this->offset ) * ( $end->y - $start->y )
);
$labelLength = sqrt(
pow(
$renderer->xAxisSpace * $this->direction->y +
$axisSpaceFactor * $this->offset * ( $end->x - $start->x ),
2 ) +
pow(
$renderer->yAxisSpace * $this->direction->x +
$axisSpaceFactor * $this->offset * ( $end->y - $start->y ),
2 )
);
$this->offset *= $axisSpaceFactor;
// Draw steps and grid
foreach ( $steps as $nr => $step )
{
$position = new ezcGraphCoordinate(
$start->x + ( $end->x - $start->x ) * $step->position * abs( $this->direction->x ),
$start->y + ( $end->y - $start->y ) * $step->position * abs( $this->direction->y )
);
$stepSize = new ezcGraphCoordinate(
( $end->x - $start->x ) * $step->width,
( $end->y - $start->y ) * $step->width
);
// Calculate label boundings
switch ( true )
{
case ( $nr === 0 ):
$labelSize = min(
abs(
$renderer->xAxisSpace * 2 * $this->direction->x +
$renderer->yAxisSpace * 2 * $this->direction->y ),
abs(
$step->width * $axisBoundings->width * $this->direction->x +
$step->width * $axisBoundings->height * $this->direction->y )
);
break;
case ( $step->isLast ):
$labelSize = min(
abs(
$renderer->xAxisSpace * 2 * $this->direction->x +
$renderer->yAxisSpace * 2 * $this->direction->y ),
abs(
$steps[$nr - 1]->width * $axisBoundings->width * $this->direction->x +
$steps[$nr - 1]->width * $axisBoundings->height * $this->direction->y )
);
break;
default:
$labelSize = min(
abs(
$step->width * $axisBoundings->width * $this->direction->x +
$step->width * $axisBoundings->height * $this->direction->y ),
abs(
$steps[$nr - 1]->width * $axisBoundings->width * $this->direction->x +
$steps[$nr - 1]->width * $axisBoundings->height * $this->direction->y )
);
break;
}
$labelSize = $labelSize * cos( deg2rad( $this->angle ) );
$lengthReducement = min(
abs( tan( deg2rad( $this->angle ) ) * ( $labelSize / 2 ) ),
abs( $labelLength / 2 )
);
switch ( true )
{
case ( ( ( $degTextAngle >= 0 ) &&
( $degTextAngle < 90 ) &&
( ( $axis->position === ezcGraph::LEFT ) ||
( $axis->position === ezcGraph::RIGHT )
)
) ||
( ( $degTextAngle >= 270 ) &&
( $degTextAngle < 360 ) &&
( ( $axis->position === ezcGraph::TOP ) ||
( $axis->position === ezcGraph::BOTTOM )
)
)
):
$labelBoundings = new ezcGraphBoundings(
$position->x,
$position->y,
$position->x + abs( $labelLength ) - $lengthReducement,
$position->y + $labelSize
);
$labelAlignement = ezcGraph::LEFT | ezcGraph::TOP;
$labelRotation = $degTextAngle;
break;
case ( ( ( $degTextAngle >= 90 ) &&
( $degTextAngle < 180 ) &&
( ( $axis->position === ezcGraph::LEFT ) ||
( $axis->position === ezcGraph::RIGHT )
)
) ||
( ( $degTextAngle >= 180 ) &&
( $degTextAngle < 270 ) &&
( ( $axis->position === ezcGraph::TOP ) ||
( $axis->position === ezcGraph::BOTTOM )
)
)
):
$labelBoundings = new ezcGraphBoundings(
$position->x - abs( $labelLength ) + $lengthReducement,
$position->y,
$position->x,
$position->y + $labelSize
);
$labelAlignement = ezcGraph::RIGHT | ezcGraph::TOP;
$labelRotation = $degTextAngle - 180;
break;
case ( ( ( $degTextAngle >= 180 ) &&
( $degTextAngle < 270 ) &&
( ( $axis->position === ezcGraph::LEFT ) ||
( $axis->position === ezcGraph::RIGHT )
)
) ||
( ( $degTextAngle >= 90 ) &&
( $degTextAngle < 180 ) &&
( ( $axis->position === ezcGraph::TOP ) ||
( $axis->position === ezcGraph::BOTTOM )
)
)
):
$labelBoundings = new ezcGraphBoundings(
$position->x - abs( $labelLength ) + $lengthReducement,
$position->y - $labelSize,
$position->x,
$position->y
);
$labelAlignement = ezcGraph::RIGHT | ezcGraph::BOTTOM;
$labelRotation = $degTextAngle - 180;
break;
case ( ( ( $degTextAngle >= 270 ) &&
( $degTextAngle < 360 ) &&
( ( $axis->position === ezcGraph::LEFT ) ||
( $axis->position === ezcGraph::RIGHT )
)
) ||
( ( $degTextAngle >= 0 ) &&
( $degTextAngle < 90 ) &&
( ( $axis->position === ezcGraph::TOP ) ||
( $axis->position === ezcGraph::BOTTOM )
)
)
):
$labelBoundings = new ezcGraphBoundings(
$position->x,
$position->y + $labelSize,
$position->x + abs( $labelLength ) - $lengthReducement,
$position->y
);
$labelAlignement = ezcGraph::LEFT | ezcGraph::BOTTOM;
$labelRotation = $degTextAngle;
break;
}
$renderer->drawText(
$labelBoundings,
$step->label,
$labelAlignement,
new ezcGraphRotation(
$labelRotation,
$position
)
);
// major grid
if ( $axis->majorGrid )
{
$this->drawGrid(
$renderer,
$gridBoundings,
$position,
$stepSize,
$axis->majorGrid
);
}
// major step
$this->drawStep(
$renderer,
$position,
$this->direction,
$axis->position,
$this->majorStepSize,
$axis->border
);
}
}
/**
* Modify chart data position
*
* Optionally additionally modify the coodinate of a data point
*
* @param ezcGraphCoordinate $coordinate Data point coordinate
* @return ezcGraphCoordinate Modified coordinate
*/
public function modifyChartDataPosition( ezcGraphCoordinate $coordinate )
{
return new ezcGraphCoordinate(
$coordinate->x * abs( $this->direction->y ) +
( $coordinate->x * ( 1 - abs( $this->offset ) ) + max( 0, $this->offset ) ) * abs( $this->direction->x ),
$coordinate->y * abs( $this->direction->x ) +
( $coordinate->y * ( 1 - abs( $this->offset ) ) + max( 0, $this->offset ) ) * abs( $this->direction->y )
);
}
}
?>