mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-24 10:22:18 +00:00
EZ-Components
This commit is contained in:
@@ -0,0 +1,438 @@
|
||||
<?php
|
||||
/**
|
||||
* File containing the abstract ezcGraphChartElementAxis 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
|
||||
*/
|
||||
/**
|
||||
* Basic axis class
|
||||
*
|
||||
* @property float $nullPosition
|
||||
* The position of the null value.
|
||||
* @property float $axisSpace
|
||||
* Percent of the chart space used to display axis labels and
|
||||
* arrowheads instead of data values.
|
||||
* @property ezcGraphColor $majorGrid
|
||||
* Color of major majorGrid.
|
||||
* @property ezcGraphColor $minorGrid
|
||||
* Color of minor majorGrid.
|
||||
* @property mixed $majorStep
|
||||
* Labeled major steps displayed on the axis. @TODO: Should be moved
|
||||
* to numeric axis.
|
||||
* @property mixed $minorStep
|
||||
* Non labeled minor steps on the axis. @TODO: Should be moved to
|
||||
* numeric axis.
|
||||
* @property string $formatString
|
||||
* Formatstring to use for labeling of the axis.
|
||||
* @property string $label
|
||||
* Axis label
|
||||
* @property int $labelSize
|
||||
* Size of axis label
|
||||
* @property int $labelMargin
|
||||
* Distance between label an axis
|
||||
* @property int $minArrowHeadSize
|
||||
* Minimum Size used to draw arrow heads.
|
||||
* @property int $maxArrowHeadSize
|
||||
* Maximum Size used to draw arrow heads.
|
||||
* @property ezcGraphAxisLabelRenderer $axisLabelRenderer
|
||||
* AxisLabelRenderer used to render labels and grid on this axis.
|
||||
* @property callback $labelCallback
|
||||
* Callback function to format chart labels.
|
||||
* Function will receive two parameters and should return a
|
||||
* reformatted label.
|
||||
* string function( label, step )
|
||||
* @property float $chartPosition
|
||||
* Position of the axis in the chart. Only useful for additional
|
||||
* axis. The basic chart axis will be automatically positioned.
|
||||
* @property-read bool $initialized
|
||||
* Property indicating if some values were associated with axis, or a
|
||||
* scaling has been set manually.
|
||||
*
|
||||
* @version 1.3
|
||||
* @package Graph
|
||||
*/
|
||||
abstract class ezcGraphChartElementAxis extends ezcGraphChartElement
|
||||
{
|
||||
/**
|
||||
* Axis label renderer class
|
||||
*
|
||||
* @var ezcGraphAxisLabelRenderer
|
||||
*/
|
||||
protected $axisLabelRenderer;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $options Default option array
|
||||
* @return void
|
||||
* @ignore
|
||||
*/
|
||||
public function __construct( array $options = array() )
|
||||
{
|
||||
$this->properties['nullPosition'] = false;
|
||||
$this->properties['axisSpace'] = .1;
|
||||
$this->properties['majorGrid'] = false;
|
||||
$this->properties['minorGrid'] = false;
|
||||
$this->properties['majorStep'] = null;
|
||||
$this->properties['minorStep'] = null;
|
||||
$this->properties['formatString'] = '%s';
|
||||
$this->properties['label'] = false;
|
||||
$this->properties['labelSize'] = 14;
|
||||
$this->properties['labelMargin'] = 2;
|
||||
$this->properties['minArrowHeadSize'] = 4;
|
||||
$this->properties['maxArrowHeadSize'] = 8;
|
||||
$this->properties['labelCallback'] = null;
|
||||
$this->properties['chartPosition'] = null;
|
||||
$this->properties['initialized'] = false;
|
||||
|
||||
parent::__construct( $options );
|
||||
|
||||
if ( !isset( $this->axisLabelRenderer ) )
|
||||
{
|
||||
$this->axisLabelRenderer = new ezcGraphAxisExactLabelRenderer();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set colors and border fro this element
|
||||
*
|
||||
* @param ezcGraphPalette $palette Palette
|
||||
* @return void
|
||||
*/
|
||||
public function setFromPalette( ezcGraphPalette $palette )
|
||||
{
|
||||
$this->border = $palette->axisColor;
|
||||
$this->padding = $palette->padding;
|
||||
$this->margin = $palette->margin;
|
||||
$this->majorGrid = $palette->majorGridColor;
|
||||
$this->minorGrid = $palette->minorGridColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* __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
|
||||
*/
|
||||
public function __set( $propertyName, $propertyValue )
|
||||
{
|
||||
switch ( $propertyName )
|
||||
{
|
||||
case 'nullPosition':
|
||||
$this->properties['nullPosition'] = (float) $propertyValue;
|
||||
break;
|
||||
case 'axisSpace':
|
||||
if ( !is_numeric( $propertyValue ) ||
|
||||
( $propertyValue < 0 ) ||
|
||||
( $propertyValue > 1 ) )
|
||||
{
|
||||
throw new ezcBaseValueException( $propertyName, $propertyValue, '0 <= float <= 1' );
|
||||
}
|
||||
|
||||
$this->properties['axisSpace'] = (float) $propertyValue;
|
||||
break;
|
||||
case 'majorGrid':
|
||||
$this->properties['majorGrid'] = ezcGraphColor::create( $propertyValue );
|
||||
break;
|
||||
case 'minorGrid':
|
||||
$this->properties['minorGrid'] = ezcGraphColor::create( $propertyValue );
|
||||
break;
|
||||
case 'majorStep':
|
||||
if ( !is_numeric( $propertyValue ) ||
|
||||
( $propertyValue <= 0 ) )
|
||||
{
|
||||
throw new ezcBaseValueException( $propertyName, $propertyValue, 'float > 0' );
|
||||
}
|
||||
|
||||
$this->properties['majorStep'] = (float) $propertyValue;
|
||||
break;
|
||||
case 'minorStep':
|
||||
if ( !is_numeric( $propertyValue ) ||
|
||||
( $propertyValue <= 0 ) )
|
||||
{
|
||||
throw new ezcBaseValueException( $propertyName, $propertyValue, 'float > 0' );
|
||||
}
|
||||
|
||||
$this->properties['minorStep'] = (float) $propertyValue;
|
||||
break;
|
||||
case 'formatString':
|
||||
$this->properties['formatString'] = (string) $propertyValue;
|
||||
break;
|
||||
case 'label':
|
||||
$this->properties['label'] = (string) $propertyValue;
|
||||
break;
|
||||
case 'labelSize':
|
||||
if ( !is_numeric( $propertyValue ) ||
|
||||
( $propertyValue <= 6 ) )
|
||||
{
|
||||
throw new ezcBaseValueException( $propertyName, $propertyValue, 'int >= 6' );
|
||||
}
|
||||
|
||||
$this->properties['labelSize'] = (int) $propertyValue;
|
||||
break;
|
||||
case 'labelMargin':
|
||||
if ( !is_numeric( $propertyValue ) ||
|
||||
( $propertyValue <= 0 ) )
|
||||
{
|
||||
throw new ezcBaseValueException( $propertyName, $propertyValue, 'int >= 0' );
|
||||
}
|
||||
|
||||
$this->properties['labelMargin'] = (int) $propertyValue;
|
||||
break;
|
||||
case 'maxArrowHeadSize':
|
||||
if ( !is_numeric( $propertyValue ) ||
|
||||
( $propertyValue <= 0 ) )
|
||||
{
|
||||
throw new ezcBaseValueException( $propertyName, $propertyValue, 'int >= 0' );
|
||||
}
|
||||
|
||||
$this->properties['maxArrowHeadSize'] = (int) $propertyValue;
|
||||
break;
|
||||
case 'minArrowHeadSize':
|
||||
if ( !is_numeric( $propertyValue ) ||
|
||||
( $propertyValue <= 0 ) )
|
||||
{
|
||||
throw new ezcBaseValueException( $propertyName, $propertyValue, 'int >= 0' );
|
||||
}
|
||||
|
||||
$this->properties['minArrowHeadSize'] = (int) $propertyValue;
|
||||
break;
|
||||
case 'axisLabelRenderer':
|
||||
if ( $propertyValue instanceof ezcGraphAxisLabelRenderer )
|
||||
{
|
||||
$this->axisLabelRenderer = $propertyValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ezcBaseValueException( $propertyName, $propertyValue, 'ezcGraphAxisLabelRenderer' );
|
||||
}
|
||||
break;
|
||||
case 'labelCallback':
|
||||
if ( is_callable( $propertyValue ) )
|
||||
{
|
||||
$this->properties['labelCallback'] = $propertyValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ezcBaseValueException( $propertyName, $propertyValue, 'callback function' );
|
||||
}
|
||||
break;
|
||||
case 'chartPosition':
|
||||
if ( !is_numeric( $propertyValue ) ||
|
||||
( $propertyValue < 0 ) ||
|
||||
( $propertyValue > 1 ) )
|
||||
{
|
||||
throw new ezcBaseValueException( $propertyName, $propertyValue, '0 <= float <= 1' );
|
||||
}
|
||||
|
||||
$this->properties['chartPosition'] = (float) $propertyValue;
|
||||
break;
|
||||
default:
|
||||
parent::__set( $propertyName, $propertyValue );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* __get
|
||||
*
|
||||
* @param mixed $propertyName
|
||||
* @throws ezcBasePropertyNotFoundException
|
||||
* If a the value for the property options is not an instance of
|
||||
* @return mixed
|
||||
* @ignore
|
||||
*/
|
||||
public function __get( $propertyName )
|
||||
{
|
||||
switch ( $propertyName )
|
||||
{
|
||||
case 'axisLabelRenderer':
|
||||
return $this->axisLabelRenderer;
|
||||
default:
|
||||
return parent::__get( $propertyName );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get coordinate for a dedicated value on the chart
|
||||
*
|
||||
* @param float $value Value to determine position for
|
||||
* @return float Position on chart
|
||||
*/
|
||||
abstract public function getCoordinate( $value );
|
||||
|
||||
/**
|
||||
* Return count of minor steps
|
||||
*
|
||||
* @return integer Count of minor steps
|
||||
*/
|
||||
abstract public function getMinorStepCount();
|
||||
|
||||
/**
|
||||
* Return count of major steps
|
||||
*
|
||||
* @return integer Count of major steps
|
||||
*/
|
||||
abstract public function getMajorStepCount();
|
||||
|
||||
/**
|
||||
* Get label for a dedicated step on the axis
|
||||
*
|
||||
* @param integer $step Number of step
|
||||
* @return string label
|
||||
*/
|
||||
abstract public function getLabel( $step );
|
||||
|
||||
/**
|
||||
* Return array of steps on this axis
|
||||
*
|
||||
* @return array( ezcGraphAxisStep )
|
||||
*/
|
||||
public function getSteps()
|
||||
{
|
||||
$majorSteps = $this->getMajorStepCount();
|
||||
$minorStepsPerMajorStepCount = ( $this->getMinorStepCount() / $majorSteps );
|
||||
|
||||
$majorStepSize = 1 / $majorSteps;
|
||||
$minorStepSize = ( $minorStepsPerMajorStepCount > 0 ? $majorStepSize / $minorStepsPerMajorStepCount : 0 );
|
||||
|
||||
$steps = array();
|
||||
for ( $major = 0; $major <= $majorSteps; ++$major )
|
||||
{
|
||||
$majorStep = new ezcGraphAxisStep(
|
||||
$majorStepSize * $major,
|
||||
$majorStepSize,
|
||||
$this->getLabel( $major ),
|
||||
array(),
|
||||
$this->isZeroStep( $major ),
|
||||
( $major === $majorSteps )
|
||||
);
|
||||
|
||||
if ( ( $minorStepsPerMajorStepCount > 0 ) &&
|
||||
( $major < $majorSteps ) )
|
||||
{
|
||||
// Do not add minor steps at major steps positions
|
||||
for( $minor = 1; $minor < $minorStepsPerMajorStepCount; ++$minor )
|
||||
{
|
||||
$majorStep->childs[] = new ezcGraphAxisStep(
|
||||
( $majorStepSize * $major ) + ( $minorStepSize * $minor ),
|
||||
$minorStepSize
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$steps[] = $majorStep;
|
||||
}
|
||||
|
||||
return $steps;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is zero step
|
||||
*
|
||||
* Returns true if the given step is the one on the initial axis position
|
||||
*
|
||||
* @param int $step Number of step
|
||||
* @return bool Status If given step is initial axis position
|
||||
*/
|
||||
abstract public function isZeroStep( $step );
|
||||
|
||||
/**
|
||||
* Add data for this axis
|
||||
*
|
||||
* @param array $values
|
||||
* @return void
|
||||
*/
|
||||
abstract public function addData( array $values );
|
||||
|
||||
/**
|
||||
* Calculate axis bounding values on base of the assigned values
|
||||
*
|
||||
* @abstract
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
abstract public function calculateAxisBoundings();
|
||||
|
||||
/**
|
||||
* Render the axis
|
||||
*
|
||||
* @param ezcGraphRenderer $renderer Renderer
|
||||
* @param ezcGraphBoundings $boundings Boundings for the axis
|
||||
* @return ezcGraphBoundings Remaining boundings
|
||||
*/
|
||||
public function render( ezcGraphRenderer $renderer, ezcGraphBoundings $boundings )
|
||||
{
|
||||
switch ( $this->position )
|
||||
{
|
||||
case ezcGraph::TOP:
|
||||
$start = new ezcGraphCoordinate(
|
||||
( $boundings->x1 - $boundings->x0 ) * $this->axisSpace +
|
||||
$this->nullPosition * ( $boundings->x1 - $boundings->x0 ) * ( 1 - 2 * $this->axisSpace ),
|
||||
0
|
||||
);
|
||||
$end = new ezcGraphCoordinate(
|
||||
( $boundings->x1 - $boundings->x0 ) * $this->axisSpace +
|
||||
$this->nullPosition * ( $boundings->x1 - $boundings->x0 ) * ( 1 - 2 * $this->axisSpace ),
|
||||
$boundings->y1 - $boundings->y0
|
||||
);
|
||||
break;
|
||||
case ezcGraph::BOTTOM:
|
||||
$start = new ezcGraphCoordinate(
|
||||
( $boundings->x1 - $boundings->x0 ) * $this->axisSpace +
|
||||
$this->nullPosition * ( $boundings->x1 - $boundings->x0 ) * ( 1 - 2 * $this->axisSpace ),
|
||||
$boundings->y1 - $boundings->y0
|
||||
);
|
||||
$end = new ezcGraphCoordinate(
|
||||
( $boundings->x1 - $boundings->x0 ) * $this->axisSpace +
|
||||
$this->nullPosition * ( $boundings->x1 - $boundings->x0 ) * ( 1 - 2 * $this->axisSpace ),
|
||||
0
|
||||
);
|
||||
break;
|
||||
case ezcGraph::LEFT:
|
||||
$start = new ezcGraphCoordinate(
|
||||
0,
|
||||
( $boundings->y1 - $boundings->y0 ) * $this->axisSpace +
|
||||
$this->nullPosition * ( $boundings->y1 - $boundings->y0 ) * ( 1 - 2 * $this->axisSpace )
|
||||
);
|
||||
$end = new ezcGraphCoordinate(
|
||||
$boundings->x1 - $boundings->x0,
|
||||
( $boundings->y1 - $boundings->y0 ) * $this->axisSpace +
|
||||
$this->nullPosition * ( $boundings->y1 - $boundings->y0 ) * ( 1 - 2 * $this->axisSpace )
|
||||
);
|
||||
break;
|
||||
case ezcGraph::RIGHT:
|
||||
$start = new ezcGraphCoordinate(
|
||||
$boundings->x1 - $boundings->x0,
|
||||
( $boundings->y1 - $boundings->y0 ) * $this->axisSpace +
|
||||
$this->nullPosition * ( $boundings->y1 - $boundings->y0 ) * ( 1 - 2 * $this->axisSpace )
|
||||
);
|
||||
$end = new ezcGraphCoordinate(
|
||||
0,
|
||||
( $boundings->y1 - $boundings->y0 ) * $this->axisSpace +
|
||||
$this->nullPosition * ( $boundings->y1 - $boundings->y0 ) * ( 1 - 2 * $this->axisSpace )
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
$renderer->drawAxis(
|
||||
$boundings,
|
||||
$start,
|
||||
$end,
|
||||
$this,
|
||||
$this->axisLabelRenderer
|
||||
);
|
||||
|
||||
return $boundings;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,202 @@
|
||||
<?php
|
||||
/**
|
||||
* File containing the ezcGraphChartElementBackground 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
|
||||
*/
|
||||
/**
|
||||
* Chart element representing the background. In addition to the standard
|
||||
* background and border for chart elements it can draw an image on the chart
|
||||
* background, and optionally repeat it. The position will be used for the
|
||||
* repetition offset.
|
||||
*
|
||||
* <code>
|
||||
* $chart->background->image = 'background.png';
|
||||
*
|
||||
* // Image will be repeated horizontal at the top of the background
|
||||
* $chart->background->repeat = ezcGraph::HORIZONTAL;
|
||||
* $chart->background->postion = ezcGraph::TOP;
|
||||
*
|
||||
* // Image will be placed once in the center
|
||||
* $chart->background->repeat = ezcGraph::NO_REPEAT; // default;
|
||||
* $chart->background->position = ezcGraph::CENTER | ezcGraph::MIDDLE;
|
||||
*
|
||||
* // Image will be repeated all over
|
||||
* $chart->background->repeat = ezcGraph::HORIZONTAL | ezcGraph::VERTICAL;
|
||||
* // The position is not relevant here.
|
||||
* </code>
|
||||
*
|
||||
* @property string $image
|
||||
* Filename of the file to use for background
|
||||
* @property int $repeat
|
||||
* Defines how the background image gets repeated
|
||||
*
|
||||
* @version 1.3
|
||||
* @package Graph
|
||||
* @mainclass
|
||||
*/
|
||||
class ezcGraphChartElementBackground extends ezcGraphChartElement
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $options Default option array
|
||||
* @return void
|
||||
* @ignore
|
||||
*/
|
||||
public function __construct( array $options = array() )
|
||||
{
|
||||
$this->properties['image'] = false;
|
||||
$this->properties['repeat'] = ezcGraph::NO_REPEAT;
|
||||
|
||||
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 'image':
|
||||
// Check for existance of file
|
||||
if ( !is_file( $propertyValue ) || !is_readable( $propertyValue ) )
|
||||
{
|
||||
throw new ezcBaseFileNotFoundException( $propertyValue );
|
||||
}
|
||||
|
||||
// Check for beeing an image file
|
||||
$data = getImageSize( $propertyValue );
|
||||
if ( $data === false )
|
||||
{
|
||||
throw new ezcGraphInvalidImageFileException( $propertyValue );
|
||||
}
|
||||
|
||||
// SWF files are useless..
|
||||
if ( $data[2] === 4 )
|
||||
{
|
||||
throw new ezcGraphInvalidImageFileException( 'We cant use SWF files like <' . $propertyValue . '>.' );
|
||||
}
|
||||
|
||||
$this->properties['image'] = $propertyValue;
|
||||
break;
|
||||
case 'repeat':
|
||||
if ( ( $propertyValue >= 0 ) && ( $propertyValue <= 3 ) )
|
||||
{
|
||||
$this->properties['repeat'] = (int) $propertyValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ezcBaseValueException( $propertyName, $propertyValue, '0 <= int <= 3' );
|
||||
}
|
||||
break;
|
||||
case 'position':
|
||||
// Overwrite parent position setter, to be able to use
|
||||
// combination of positions like
|
||||
// ezcGraph::TOP | ezcGraph::CENTER
|
||||
if ( is_int( $propertyValue ) )
|
||||
{
|
||||
$this->properties['position'] = $propertyValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ezcBaseValueException( $propertyName, $propertyValue, 'integer' );
|
||||
}
|
||||
break;
|
||||
case 'color':
|
||||
// Use color as an alias to set background color for background
|
||||
$this->__set( 'background', $propertyValue );
|
||||
break;
|
||||
default:
|
||||
return parent::__set( $propertyName, $propertyValue );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* __get
|
||||
*
|
||||
* @param mixed $propertyName
|
||||
* @throws ezcBasePropertyNotFoundException
|
||||
* If a the value for the property options is not an instance of
|
||||
* @return mixed
|
||||
* @ignore
|
||||
*/
|
||||
public function __get( $propertyName )
|
||||
{
|
||||
switch ( $propertyName )
|
||||
{
|
||||
case 'color':
|
||||
// Use color as an alias to set background color for background
|
||||
return $this->properties['background'];
|
||||
default:
|
||||
return parent::__get( $propertyName );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set colors and border for this element
|
||||
*
|
||||
* Method is overwritten because we do not ant to apply the global padding
|
||||
* and margin here.
|
||||
*
|
||||
* @param ezcGraphPalette $palette Palette
|
||||
* @return void
|
||||
*/
|
||||
public function setFromPalette( ezcGraphPalette $palette )
|
||||
{
|
||||
$this->border = $palette->chartBorderColor;
|
||||
$this->borderWidth = $palette->chartBorderWidth;
|
||||
$this->background = $palette->chartBackground;
|
||||
$this->padding = 0;
|
||||
$this->margin = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the background
|
||||
*
|
||||
* @param ezcGraphRenderer $renderer Renderer
|
||||
* @param ezcGraphBoundings $boundings Boundings
|
||||
* @return ezcGraphBoundings Remaining boundings
|
||||
*/
|
||||
public function render( ezcGraphRenderer $renderer, ezcGraphBoundings $boundings )
|
||||
{
|
||||
$boundings = $renderer->drawBox(
|
||||
$boundings,
|
||||
$this->background,
|
||||
$this->border,
|
||||
$this->borderWidth,
|
||||
$this->margin,
|
||||
$this->padding
|
||||
);
|
||||
|
||||
if ( $this->image === false )
|
||||
{
|
||||
return $boundings;
|
||||
}
|
||||
|
||||
$renderer->drawBackgroundImage(
|
||||
$boundings,
|
||||
$this->image,
|
||||
$this->position,
|
||||
$this->repeat
|
||||
);
|
||||
|
||||
return $boundings;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,298 @@
|
||||
<?php
|
||||
/**
|
||||
* File containing the abstract ezcGraphChartElementLegend 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
|
||||
*/
|
||||
/**
|
||||
* Class to represent a legend as a chart element
|
||||
*
|
||||
* @property float $portraitSize
|
||||
* Size of a portrait style legend in percent of the size of the
|
||||
* complete chart.
|
||||
* @property float $landscapeSize
|
||||
* Size of a landscape style legend in percent of the size of the
|
||||
* complete chart.
|
||||
* @property int $symbolSize
|
||||
* Standard size of symbols and text in legends.
|
||||
* @property float $minimumSymbolSize
|
||||
* Scale symbol size up to to percent of complete legends size for
|
||||
* very big legends.
|
||||
* @property int $spacing
|
||||
* Space between labels elements in pixel.
|
||||
*
|
||||
* @version 1.3
|
||||
* @package Graph
|
||||
* @mainclass
|
||||
*/
|
||||
class ezcGraphChartElementLegend extends ezcGraphChartElement
|
||||
{
|
||||
|
||||
/**
|
||||
* Contains data which should be shown in the legend
|
||||
* array(
|
||||
* array(
|
||||
* 'label' => (string) 'Label of data element',
|
||||
* 'color' => (ezcGraphColor) $color,
|
||||
* 'symbol' => (integer) ezcGraph::DIAMOND,
|
||||
* ),
|
||||
* ...
|
||||
* )
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $labels;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $options Default option array
|
||||
* @return void
|
||||
* @ignore
|
||||
*/
|
||||
public function __construct( array $options = array() )
|
||||
{
|
||||
$this->properties['portraitSize'] = .2;
|
||||
$this->properties['landscapeSize'] = .1;
|
||||
$this->properties['symbolSize'] = 14;
|
||||
$this->properties['padding'] = 1;
|
||||
$this->properties['minimumSymbolSize'] = .05;
|
||||
$this->properties['spacing'] = 2;
|
||||
|
||||
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 'padding':
|
||||
if ( !is_numeric( $propertyValue ) ||
|
||||
( $propertyValue < 0 ) )
|
||||
{
|
||||
throw new ezcBaseValueException( $propertyName, $propertyValue, 'int >= 0' );
|
||||
}
|
||||
|
||||
$this->properties['padding'] = (int) $propertyValue;
|
||||
break;
|
||||
case 'symbolSize':
|
||||
if ( !is_numeric( $propertyValue ) ||
|
||||
( $propertyValue < 1 ) )
|
||||
{
|
||||
throw new ezcBaseValueException( $propertyName, $propertyValue, 'int >= 1' );
|
||||
}
|
||||
|
||||
$this->properties['symbolSize'] = (int) $propertyValue;
|
||||
break;
|
||||
case 'landscapeSize':
|
||||
if ( !is_numeric( $propertyValue ) ||
|
||||
( $propertyValue < 0 ) ||
|
||||
( $propertyValue > 1 ) )
|
||||
{
|
||||
throw new ezcBaseValueException( $propertyName, $propertyValue, '0 <= int <= 1' );
|
||||
}
|
||||
|
||||
$this->properties['landscapeSize'] = (float) $propertyValue;
|
||||
break;
|
||||
case 'portraitSize':
|
||||
if ( !is_numeric( $propertyValue ) ||
|
||||
( $propertyValue < 0 ) ||
|
||||
( $propertyValue > 1 ) )
|
||||
{
|
||||
throw new ezcBaseValueException( $propertyName, $propertyValue, '0 <= int <= 1' );
|
||||
}
|
||||
|
||||
$this->properties['portraitSize'] = (float) $propertyValue;
|
||||
break;
|
||||
case 'minimumSymbolSize':
|
||||
if ( !is_numeric( $propertyValue ) ||
|
||||
( $propertyValue < 0 ) ||
|
||||
( $propertyValue > 1 ) )
|
||||
{
|
||||
throw new ezcBaseValueException( $propertyName, $propertyValue, '0 <= int <= 1' );
|
||||
}
|
||||
|
||||
$this->properties['minimumSymbolSize'] = (float) $propertyValue;
|
||||
break;
|
||||
case 'spacing':
|
||||
if ( !is_numeric( $propertyValue ) ||
|
||||
( $propertyValue < 0 ) )
|
||||
{
|
||||
throw new ezcBaseValueException( $propertyName, $propertyValue, 'int >= 0' );
|
||||
}
|
||||
|
||||
$this->properties['spacing'] = (int) $propertyValue;
|
||||
break;
|
||||
default:
|
||||
parent::__set( $propertyName, $propertyValue );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* __get
|
||||
*
|
||||
* @param mixed $propertyName
|
||||
* @throws ezcBasePropertyNotFoundException
|
||||
* If a the value for the property options is not an instance of
|
||||
* @return mixed
|
||||
* @ignore
|
||||
*/
|
||||
public function __get( $propertyName )
|
||||
{
|
||||
switch ( $propertyName )
|
||||
{
|
||||
case 'labels':
|
||||
return $this->labels;
|
||||
default:
|
||||
return parent::__get( $propertyName );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate legend from several datasets with on entry per dataset
|
||||
*
|
||||
* @param ezcGraphChartDataContainer $datasets
|
||||
* @return void
|
||||
*/
|
||||
public function generateFromDataSets( ezcGraphChartDataContainer $datasets )
|
||||
{
|
||||
$this->labels = array();
|
||||
foreach ( $datasets as $dataset )
|
||||
{
|
||||
$this->labels[] = array(
|
||||
'label' => $dataset->label->default,
|
||||
'url' => $dataset->url->default,
|
||||
'color' => $dataset->color->default,
|
||||
'symbol' => ( $dataset->symbol->default === null ?
|
||||
ezcGraph::NO_SYMBOL :
|
||||
$dataset->symbol->default ),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate legend from single dataset with on entry per data element
|
||||
*
|
||||
* @param ezcGraphDataSet $dataset
|
||||
* @return void
|
||||
*/
|
||||
public function generateFromDataSet( ezcGraphDataSet $dataset )
|
||||
{
|
||||
$this->labels = array();
|
||||
foreach ( $dataset as $label => $data )
|
||||
{
|
||||
$this->labels[] = array(
|
||||
'label' => $label,
|
||||
'url' => $dataset->url[$label],
|
||||
'color' => $dataset->color[$label],
|
||||
'symbol' => ( $dataset->symbol[$label] === null ?
|
||||
ezcGraph::NO_SYMBOL :
|
||||
$dataset->symbol[$label] ),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculated boundings needed for the legend.
|
||||
*
|
||||
* Uses the position and the configured horizontal or vertical size of a
|
||||
* legend to calculate the boundings for the legend.
|
||||
*
|
||||
* @param ezcGraphBoundings $boundings Avalable boundings
|
||||
* @return ezcGraphBoundings Remaining boundings
|
||||
*/
|
||||
protected function calculateBoundings( ezcGraphBoundings $boundings )
|
||||
{
|
||||
$this->properties['boundings'] = clone $boundings;
|
||||
|
||||
switch ( $this->position )
|
||||
{
|
||||
case ezcGraph::LEFT:
|
||||
$size = ( $boundings->width ) * $this->portraitSize;
|
||||
|
||||
$boundings->x0 += $size;
|
||||
$this->boundings->x1 = $boundings->x0;
|
||||
break;
|
||||
case ezcGraph::RIGHT:
|
||||
$size = ( $boundings->width ) * $this->portraitSize;
|
||||
|
||||
$boundings->x1 -= $size;
|
||||
$this->boundings->x0 = $boundings->x1;
|
||||
break;
|
||||
case ezcGraph::TOP:
|
||||
$size = ( $boundings->height ) * $this->landscapeSize;
|
||||
|
||||
$boundings->y0 += $size;
|
||||
$this->boundings->y1 = $boundings->y0;
|
||||
break;
|
||||
case ezcGraph::BOTTOM:
|
||||
$size = ( $boundings->height ) * $this->landscapeSize;
|
||||
|
||||
$boundings->y1 -= $size;
|
||||
$this->boundings->y0 = $boundings->y1;
|
||||
break;
|
||||
}
|
||||
|
||||
return $boundings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a legend
|
||||
*
|
||||
* @param ezcGraphRenderer $renderer Renderer
|
||||
* @param ezcGraphBoundings $boundings Boundings for the axis
|
||||
* @return ezcGraphBoundings Remaining boundings
|
||||
*/
|
||||
public function render( ezcGraphRenderer $renderer, ezcGraphBoundings $boundings )
|
||||
{
|
||||
$boundings = $this->calculateBoundings( $boundings );
|
||||
|
||||
if ( $this->position === ezcGraph::LEFT || $this->position === ezcGraph::RIGHT )
|
||||
{
|
||||
$type = ezcGraph::VERTICAL;
|
||||
}
|
||||
else
|
||||
{
|
||||
$type = ezcGraph::HORIZONTAL;
|
||||
}
|
||||
|
||||
// Render standard elements
|
||||
$this->properties['boundings'] = $renderer->drawBox(
|
||||
$this->properties['boundings'],
|
||||
$this->properties['background'],
|
||||
$this->properties['border'],
|
||||
$this->properties['borderWidth'],
|
||||
$this->properties['margin'],
|
||||
$this->properties['padding'],
|
||||
$this->properties['title'],
|
||||
$this->getTitleSize( $this->properties['boundings'], $type )
|
||||
);
|
||||
|
||||
// Render legend
|
||||
$renderer->drawLegend(
|
||||
$this->boundings,
|
||||
$this,
|
||||
$type
|
||||
);
|
||||
|
||||
return $boundings;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
/**
|
||||
* File containing the ezcGraphChartElementText 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
|
||||
*/
|
||||
/**
|
||||
* Chart element to display texts in a chart
|
||||
*
|
||||
* @property float $maxHeight
|
||||
* Maximum percent of bounding used to display the text.
|
||||
*
|
||||
* @version 1.3
|
||||
* @package Graph
|
||||
* @mainclass
|
||||
*/
|
||||
class ezcGraphChartElementText extends ezcGraphChartElement
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $options Default option array
|
||||
* @return void
|
||||
* @ignore
|
||||
*/
|
||||
public function __construct( array $options = array() )
|
||||
{
|
||||
$this->properties['maxHeight'] = .1;
|
||||
|
||||
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
|
||||
*/
|
||||
public function __set( $propertyName, $propertyValue )
|
||||
{
|
||||
switch ( $propertyName )
|
||||
{
|
||||
case 'maxHeight':
|
||||
if ( !is_numeric( $propertyValue ) ||
|
||||
( $propertyValue < 0 ) ||
|
||||
( $propertyValue > 1 ) )
|
||||
{
|
||||
throw new ezcBaseValueException( $propertyName, $propertyValue, '0 <= float <= 1' );
|
||||
}
|
||||
|
||||
$this->properties['maxHeight'] = (float) $propertyValue;
|
||||
break;
|
||||
default:
|
||||
parent::__set( $propertyName, $propertyValue );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the text
|
||||
*
|
||||
* @param ezcGraphRenderer $renderer Renderer
|
||||
* @param ezcGraphBoundings $boundings Boundings for the axis
|
||||
* @return ezcGraphBoundings Remaining boundings
|
||||
*/
|
||||
public function render( ezcGraphRenderer $renderer, ezcGraphBoundings $boundings )
|
||||
{
|
||||
$height = (int) min(
|
||||
round( $this->properties['maxHeight'] * ( $boundings->y1 - $boundings->y0 ) ),
|
||||
$this->properties['font']->maxFontSize + $this->padding * 2 + $this->margin * 2
|
||||
);
|
||||
|
||||
switch ( $this->properties['position'] )
|
||||
{
|
||||
case ezcGraph::TOP:
|
||||
$textBoundings = new ezcGraphBoundings(
|
||||
$boundings->x0,
|
||||
$boundings->y0,
|
||||
$boundings->x1,
|
||||
$boundings->y0 + $height
|
||||
);
|
||||
$boundings->y0 += $height + $this->properties['margin'];
|
||||
break;
|
||||
case ezcGraph::BOTTOM:
|
||||
$textBoundings = new ezcGraphBoundings(
|
||||
$boundings->x0,
|
||||
$boundings->y1 - $height,
|
||||
$boundings->x1,
|
||||
$boundings->y1
|
||||
);
|
||||
$boundings->y1 -= $height + $this->properties['margin'];
|
||||
break;
|
||||
}
|
||||
|
||||
$textBoundings = $renderer->drawBox(
|
||||
$textBoundings,
|
||||
$this->properties['background'],
|
||||
$this->properties['border'],
|
||||
$this->properties['borderWidth'],
|
||||
$this->properties['margin'],
|
||||
$this->properties['padding']
|
||||
);
|
||||
|
||||
$renderer->drawText(
|
||||
$textBoundings,
|
||||
$this->properties['title'],
|
||||
ezcGraph::CENTER | ezcGraph::MIDDLE
|
||||
);
|
||||
|
||||
return $boundings;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user