Author: Kore Nordmann
Date: 2006-06-19 21:34:53 +0200 (Mon, 19 Jun 2006)
New Revision: 3148
Log:
- Added option for maximum size for arrow heads
- Made possible to define custom labels for axis
- Made unused method ezcGraphChartElementAxis::drawLabels
Modified:
trunk/Graph/src/axis/labeled.php
trunk/Graph/src/axis/numeric.php
trunk/Graph/src/element/axis.php
trunk/Graph/tests/background_image_test.php
trunk/Graph/tests/labeled_axis_test.php
trunk/Graph/tests/line_test.php
trunk/Graph/tests/numeric_axis_test.php
Modified: trunk/Graph/src/axis/labeled.php
===================================================================
--- trunk/Graph/src/axis/labeled.php 2006-06-19 19:29:01 UTC (rev 3147)
+++ trunk/Graph/src/axis/labeled.php 2006-06-19 19:34:53 UTC (rev 3148)
@@ -220,7 +220,7 @@
for ( $i = 0; $i <= $steps; ++$i )
{
- $label = $this->getLabel( $i );
+ $label = sprintf( $this->formatString, $this->getLabel( $i ) );
switch ( $this->position )
{
Modified: trunk/Graph/src/axis/numeric.php
===================================================================
--- trunk/Graph/src/axis/numeric.php 2006-06-19 19:29:01 UTC (rev 3147)
+++ trunk/Graph/src/axis/numeric.php 2006-06-19 19:34:53 UTC (rev 3148)
@@ -358,7 +358,7 @@
// Draw label
if ( $i < $steps )
{
- $label = $this->getLabel( $i );
+ $label = sprintf( $this->formatString, $this->getLabel( $i ) );
switch ( $this->position )
{
Modified: trunk/Graph/src/element/axis.php
===================================================================
--- trunk/Graph/src/element/axis.php 2006-06-19 19:29:01 UTC (rev 3147)
+++ trunk/Graph/src/element/axis.php 2006-06-19 19:34:53 UTC (rev 3148)
@@ -80,6 +80,20 @@
*/
protected $minorScalingLineLength = 2;
+ /**
+ * Formatstring to use for labeling og the axis
+ *
+ * @var string
+ */
+ protected $formatString = '%s';
+
+ /**
+ * Maximum Size used to draw arrow heads
+ *
+ * @var integer
+ */
+ protected $maxArrowHeadSize = 8;
+
public function __construct( array $options = array() )
{
parent::__construct( $options );
@@ -158,6 +172,12 @@
}
$this->minorStep = (float) $propertyValue;
break;
+ case 'formatString':
+ $this->formatString = (string) $propertyValue;
+ break;
+ case 'maxArrowHeadSize':
+ $this->maxArrowHeadSize = max( 0, (int) $propertyValue );
+ break;
default:
parent::__set( $propertyName, $propertyValue );
break;
@@ -204,81 +224,8 @@
* @param ezcGraphBoundings $boundings
* @return void
*/
- protected function drawLabels( ezcGraphRenderer $renderer,
ezcGraphCoordinate $start, ezcGraphCoordinate $end, ezcGraphBoundings
$boundings )
- {
- // Draw major steps
- $steps = $this->getMajorStepCount();
+ abstract protected function drawLabels( ezcGraphRenderer $renderer,
ezcGraphCoordinate $start, ezcGraphCoordinate $end, ezcGraphBoundings
$boundings );
- // Calculate stepsize
- $xStepsize = ( $end->x - $start->x ) / $steps;
- $yStepsize = ( $end->y - $start->y ) / $steps;
-
- // Caluclate datafree chart border
- $xBorder = abs ( ( $boundings->x1 - $boundings->x0 ) * (
$this->axisSpace / 2 ) );
- $yBorder = abs ( ( $boundings->y1 - $boundings->y0 ) * (
$this->axisSpace / 2 ) );
-
- for ( $i = 0; $i <= $steps; ++$i )
- {
- // Draw label
- if ( $i < $steps )
- {
- $label = $this->getLabel( $i );
-
- switch ( $this->position )
- {
- case ezcGraph::LEFT:
- $renderer->drawTextBox(
- new ezcGraphCoordinate(
- (int) round( $start->x + $i * $xStepsize +
$this->labelPadding ),
- (int) round( $start->y + $i * $yStepsize +
$this->labelPadding )
- ),
- $label,
- (int) round( $xStepsize ) - $this->labelPadding,
- $yBorder - $this->labelPadding,
- ezcGraph::LEFT | ezcGraph::TOP
- );
- break;
- case ezcGraph::RIGHT:
- $renderer->drawTextBox(
- new ezcGraphCoordinate(
- (int) round( $start->x + $i * $xStepsize +
$xStepsize ),
- (int) round( $start->y + $i * $yStepsize +
$this->labelPadding )
- ),
- $label,
- (int) round( -$xStepsize ) - $this->labelPadding,
- $yBorder - $this->labelPadding,
- ezcGraph::RIGHT | ezcGraph::TOP
- );
- break;
- case ezcGraph::BOTTOM:
- $renderer->drawTextBox(
- new ezcGraphCoordinate(
- (int) round( $start->x + $i * $xStepsize -
$xBorder ),
- (int) round( $start->y + $i * $yStepsize +
$yStepsize )
- ),
- $label,
- $xBorder - $this->labelPadding,
- (int) round( -$yStepsize ) - $this->labelPadding,
- ezcGraph::RIGHT | ezcGraph::BOTTOM
- );
- break;
- case ezcGraph::TOP:
- $renderer->drawTextBox(
- new ezcGraphCoordinate(
- (int) round( $start->x + $i * $xStepsize -
$xBorder ),
- (int) round( $start->y + $i * $yStepsize +
$this->labelPadding )
- ),
- $label,
- $xBorder - $this->labelPadding,
- (int) round( $yStepsize ) - $this->labelPadding,
- ezcGraph::RIGHT | ezcGraph::TOP
- );
- break;
- }
- }
- }
- }
-
/**
* Draw a axis from a start point to an end point. They do not need to be
* placed in-plane.
@@ -310,7 +257,10 @@
);
// Draw small arrowhead
- $size = abs( ceil( ( ( $end->x - $start->x ) + ( $end->y - $start->y )
) * $this->axisSpace / 4 ) );
+ $size = min(
+ $this->maxArrowHeadSize,
+ abs( ceil( ( ( $end->x - $start->x ) + ( $end->y - $start->y ) ) *
$this->axisSpace / 4 ) )
+ );
$renderer->drawPolygon(
array(
Modified: trunk/Graph/tests/background_image_test.php
===================================================================
--- trunk/Graph/tests/background_image_test.php 2006-06-19 19:29:01 UTC (rev
3147)
+++ trunk/Graph/tests/background_image_test.php 2006-06-19 19:34:53 UTC (rev
3148)
@@ -176,7 +176,7 @@
);
$this->assertEquals(
- '17c3aac43de88a0a8ce620d5e72db40d',
+ '1d586728bba88ddd9a6c18d42449a948',
md5_file( $filename ),
'Incorrect image rendered.'
);
Modified: trunk/Graph/tests/labeled_axis_test.php
===================================================================
--- trunk/Graph/tests/labeled_axis_test.php 2006-06-19 19:29:01 UTC (rev
3147)
+++ trunk/Graph/tests/labeled_axis_test.php 2006-06-19 19:34:53 UTC (rev
3148)
@@ -327,8 +327,8 @@
->with(
$this->equalTo( array(
new ezcGraphCoordinate( 500, 190 ),
- new ezcGraphCoordinate( 490, 185 ),
- new ezcGraphCoordinate( 490, 195 ),
+ new ezcGraphCoordinate( 492, 186 ),
+ new ezcGraphCoordinate( 492, 194 ),
) ),
$this->equalTo( ezcGraphColor::fromHex( '#2E3436' ) ),
$this->equalTo( true )
@@ -502,6 +502,64 @@
$chart->render( 500, 200 );
}
+ public function testRenderNumericAxisCustomLabels()
+ {
+ $chart = ezcGraph::create( 'Line' );
+ $chart->sample = array( 2000 => 1045, 1300, 1012, 1450 );
+ $chart->sample2 = array( 2000 => 1270, 1170, 1610, 1370 );
+ $chart->xAxis->formatString = 'test';
+
+ $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array(
+ 'drawTextBox',
+ ) );
+
+ // X-Axis
+ $mockedRenderer
+ ->expects( $this->at( 2 ) )
+ ->method( 'drawTextBox' )
+ ->with(
+ $this->equalTo( new ezcGraphCoordinate( 122, 192 ) ),
+ $this->equalTo( 'test' ),
+ $this->equalTo( 88 ),
+ $this->equalTo( 8 ),
+ $this->equalTo( ezcGraph::LEFT | ezcGraph::TOP )
+ );
+ $mockedRenderer
+ ->expects( $this->at( 3 ) )
+ ->method( 'drawTextBox' )
+ ->with(
+ $this->equalTo( new ezcGraphCoordinate( 212, 192 ) ),
+ $this->equalTo( 'test' ),
+ $this->equalTo( 88 ),
+ $this->equalTo( 8 ),
+ $this->equalTo( ezcGraph::CENTER | ezcGraph::TOP )
+ );
+ $mockedRenderer
+ ->expects( $this->at( 4 ) )
+ ->method( 'drawTextBox' )
+ ->with(
+ $this->equalTo( new ezcGraphCoordinate( 303, 192 ) ),
+ $this->equalTo( 'test' ),
+ $this->equalTo( 88 ),
+ $this->equalTo( 8 ),
+ $this->equalTo( ezcGraph::CENTER | ezcGraph::TOP )
+ );
+ $mockedRenderer
+ ->expects( $this->at( 5 ) )
+ ->method( 'drawTextBox' )
+ ->with(
+ $this->equalTo( new ezcGraphCoordinate( 393, 192 ) ),
+ $this->equalTo( 'test' ),
+ $this->equalTo( 88 ),
+ $this->equalTo( 8 ),
+ $this->equalTo( ezcGraph::RIGHT | ezcGraph::TOP )
+ );
+
+ $chart->renderer = $mockedRenderer;
+
+ $chart->render( 500, 200 );
+ }
+
public function testRenderLabeledAxisWithManyPoints()
{
$data = array();
Modified: trunk/Graph/tests/line_test.php
===================================================================
--- trunk/Graph/tests/line_test.php 2006-06-19 19:29:01 UTC (rev 3147)
+++ trunk/Graph/tests/line_test.php 2006-06-19 19:34:53 UTC (rev 3148)
@@ -400,7 +400,7 @@
);
$this->assertEquals(
- 'ef4deac70fa8c0ca3d4149fd65e31131',
+ '9466947154bc1f6f908a1f5905c0b207',
md5_file( $filename ),
'Incorrect image rendered.'
);
Modified: trunk/Graph/tests/numeric_axis_test.php
===================================================================
--- trunk/Graph/tests/numeric_axis_test.php 2006-06-19 19:29:01 UTC (rev
3147)
+++ trunk/Graph/tests/numeric_axis_test.php 2006-06-19 19:34:53 UTC (rev
3148)
@@ -913,6 +913,54 @@
$chart->render( 500, 200 );
}
+ public function testRenderNumericAxisCustomLabels()
+ {
+ $chart = ezcGraph::create( 'Line' );
+ $chart->sample = array( 2000 => 1045, 1300, 1012, 1450 );
+ $chart->sample2 = array( 2000 => 1270, 1170, 1610, 1370 );
+ $chart->yAxis->formatString = 'test';
+
+ $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array(
+ 'drawTextBox',
+ ) );
+
+ // Y-Axis
+ $mockedRenderer
+ ->expects( $this->at( 7 ) )
+ ->method( 'drawTextBox' )
+ ->with(
+ $this->equalTo( new ezcGraphCoordinate( 100, 130 ) ),
+ $this->equalTo( 'test' ),
+ $this->equalTo( 18 ),
+ $this->equalTo( 58 ),
+ $this->equalTo( ezcGraph::RIGHT | ezcGraph::BOTTOM )
+ );
+ $mockedRenderer
+ ->expects( $this->at( 8 ) )
+ ->method( 'drawTextBox' )
+ ->with(
+ $this->equalTo( new ezcGraphCoordinate( 100, 70 ) ),
+ $this->equalTo( 'test' ),
+ $this->equalTo( 18 ),
+ $this->equalTo( 58 ),
+ $this->equalTo( ezcGraph::RIGHT | ezcGraph::BOTTOM )
+ );
+ $mockedRenderer
+ ->expects( $this->at( 9 ) )
+ ->method( 'drawTextBox' )
+ ->with(
+ $this->equalTo( new ezcGraphCoordinate( 100, 10 ) ),
+ $this->equalTo( 'test' ),
+ $this->equalTo( 18 ),
+ $this->equalTo( 58 ),
+ $this->equalTo( ezcGraph::RIGHT | ezcGraph::BOTTOM )
+ );
+
+ $chart->renderer = $mockedRenderer;
+
+ $chart->render( 500, 200 );
+ }
+
public function testRenderNumericXAndYAxisLabels()
{
$sin = array();
--
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components