summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKore Nordmann <github@kore-nordmann.de>2009-07-21 11:25:18 +0000
committerKore Nordmann <github@kore-nordmann.de>2009-07-21 11:25:18 +0000
commit73061d5af4bcddd2df8169dccca17dfea5bb8477 (patch)
treedd1a19fe8c644a3f53d5f276ef5facfd5c6b57d6 /src
parent9ce834beee81194e02525a6cb836516dc379eeb7 (diff)
downloadzetacomponents-graph-73061d5af4bcddd2df8169dccca17dfea5bb8477.zip
zetacomponents-graph-73061d5af4bcddd2df8169dccca17dfea5bb8477.tar.gz
- Implemented: #15133: Better configurable axis spaces.
# Large number of tests added. Had to go through all sensible combinations of # axis and axis spaces to ensure it works correctly.
Diffstat (limited to 'src')
-rw-r--r--src/charts/line.php18
-rw-r--r--src/element/axis.php42
-rw-r--r--src/renderer/axis_label_rotated.php76
3 files changed, 71 insertions, 65 deletions
diff --git a/src/charts/line.php b/src/charts/line.php
index 4c0ba14..4d0fc84 100644
--- a/src/charts/line.php
+++ b/src/charts/line.php
@@ -627,25 +627,17 @@ class ezcGraphLineChart extends ezcGraphChart
// Calculate inner data boundings of chart
$innerBoundings = new ezcGraphBoundings(
$boundings->x0 + $boundings->width *
- ( ( ( $this->elements['yAxis']->outerAxisSpace === null ) ||
- ( $this->elements['xAxis']->position === ezcGraph::LEFT ) ) ?
- $this->elements['yAxis']->axisSpace :
- $this->elements['yAxis']->outerAxisSpace ),
+ $this->elements['yAxis']->axisSpace,
$boundings->y0 + $boundings->height *
- ( ( ( $this->elements['xAxis']->outerAxisSpace === null ) ||
- ( $this->elements['yAxis']->position === ezcGraph::TOP ) ) ?
+ ( ( $this->elements['xAxis']->outerAxisSpace === null ) ?
$this->elements['xAxis']->axisSpace :
- $this->elements['yAxis']->outerAxisSpace ),
+ $this->elements['xAxis']->outerAxisSpace ),
$boundings->x1 - $boundings->width *
- ( ( ( $this->elements['yAxis']->outerAxisSpace === null ) ||
- ( $this->elements['xAxis']->position === ezcGraph::RIGHT ) ) ?
+ ( ( $this->elements['yAxis']->outerAxisSpace === null ) ?
$this->elements['yAxis']->axisSpace :
$this->elements['yAxis']->outerAxisSpace ),
$boundings->y1 - $boundings->height *
- ( ( ( $this->elements['xAxis']->outerAxisSpace === null ) ||
- ( $this->elements['yAxis']->position === ezcGraph::BOTTOM ) ) ?
- $this->elements['xAxis']->axisSpace :
- $this->elements['yAxis']->outerAxisSpace )
+ $this->elements['xAxis']->axisSpace
);
// Render axis
diff --git a/src/element/axis.php b/src/element/axis.php
index 4f38761..0f6af3f 100644
--- a/src/element/axis.php
+++ b/src/element/axis.php
@@ -221,7 +221,6 @@ abstract class ezcGraphChartElementAxis extends ezcGraphChartElement
$this->properties['axisSpace'] = (float) $propertyValue;
break;
- /* Do not yet allow to modify this value, this need further testing.
case 'outerAxisSpace':
if ( !is_null( $propertyValue ) &&
( !is_numeric( $propertyValue ) ||
@@ -233,7 +232,6 @@ abstract class ezcGraphChartElementAxis extends ezcGraphChartElement
$this->properties['outerAxisSpace'] = $propertyValue;
break;
- */
case 'majorGrid':
$this->properties['majorGrid'] = ezcGraphColor::create( $propertyValue );
break;
@@ -482,50 +480,50 @@ abstract class ezcGraphChartElementAxis extends ezcGraphChartElement
{
case ezcGraph::TOP:
$start = new ezcGraphCoordinate(
- ( $boundings->x1 - $boundings->x0 ) * $startSpace +
- $this->nullPosition * ( $boundings->x1 - $boundings->x0 ) * ( 1 - 2 * $startSpace ),
+ $boundings->width * $startSpace +
+ $this->nullPosition * $boundings->width * ( 1 - ( $startSpace + $endSpace ) ),
0
);
$end = new ezcGraphCoordinate(
- ( $boundings->x1 - $boundings->x0 ) * $endSpace +
- $this->nullPosition * ( $boundings->x1 - $boundings->x0 ) * ( 1 - 2 * $endSpace ),
- $boundings->y1 - $boundings->y0
+ $boundings->width * $startSpace +
+ $this->nullPosition * $boundings->width * ( 1 - ( $startSpace + $endSpace ) ),
+ $boundings->height
);
break;
case ezcGraph::BOTTOM:
$start = new ezcGraphCoordinate(
- ( $boundings->x1 - $boundings->x0 ) * $startSpace +
- $this->nullPosition * ( $boundings->x1 - $boundings->x0 ) * ( 1 - 2 * $startSpace ),
- $boundings->y1 - $boundings->y0
+ $boundings->width * $startSpace +
+ $this->nullPosition * $boundings->width * ( 1 - ( $startSpace + $endSpace ) ),
+ $boundings->height
);
$end = new ezcGraphCoordinate(
- ( $boundings->x1 - $boundings->x0 ) * $endSpace +
- $this->nullPosition * ( $boundings->x1 - $boundings->x0 ) * ( 1 - 2 * $endSpace ),
+ $boundings->width * $startSpace +
+ $this->nullPosition * $boundings->width * ( 1 - ( $startSpace + $endSpace ) ),
0
);
break;
case ezcGraph::LEFT:
$start = new ezcGraphCoordinate(
0,
- ( $boundings->y1 - $boundings->y0 ) * $startSpace +
- $this->nullPosition * ( $boundings->y1 - $boundings->y0 ) * ( 1 - 2 * $startSpace )
+ $boundings->height * $endSpace +
+ $this->nullPosition * $boundings->height * ( 1 - ( $startSpace + $endSpace ) )
);
$end = new ezcGraphCoordinate(
- $boundings->x1 - $boundings->x0,
- ( $boundings->y1 - $boundings->y0 ) * $endSpace +
- $this->nullPosition * ( $boundings->y1 - $boundings->y0 ) * ( 1 - 2 * $endSpace )
+ $boundings->width,
+ $boundings->height * $endSpace +
+ $this->nullPosition * $boundings->height * ( 1 - ( $startSpace + $endSpace ) )
);
break;
case ezcGraph::RIGHT:
$start = new ezcGraphCoordinate(
- $boundings->x1 - $boundings->x0,
- ( $boundings->y1 - $boundings->y0 ) * $startSpace +
- $this->nullPosition * ( $boundings->y1 - $boundings->y0 ) * ( 1 - 2 * $startSpace )
+ $boundings->width,
+ $boundings->height * $endSpace +
+ $this->nullPosition * $boundings->height * ( 1 - ( $startSpace + $endSpace ) )
);
$end = new ezcGraphCoordinate(
0,
- ( $boundings->y1 - $boundings->y0 ) * $endSpace +
- $this->nullPosition * ( $boundings->y1 - $boundings->y0 ) * ( 1 - 2 * $endSpace )
+ $boundings->height * $endSpace +
+ $this->nullPosition * $boundings->height * ( 1 - ( $startSpace + $endSpace ) )
);
break;
}
diff --git a/src/renderer/axis_label_rotated.php b/src/renderer/axis_label_rotated.php
index 547bfdd..6187494 100644
--- a/src/renderer/axis_label_rotated.php
+++ b/src/renderer/axis_label_rotated.php
@@ -114,6 +114,43 @@ class ezcGraphAxisRotatedLabelRenderer extends ezcGraphAxisLabelRenderer
}
/**
+ * Determine label angle
+ *
+ * Determine the optiomal angle for the axis labels, of no angle has been
+ * provided by the user.
+ *
+ * @param array $steps
+ * @return void
+ */
+ protected function determineAngle( array $steps, $xSpace, $ySpace, ezcGraphBoundings $axisBoundings )
+ {
+ 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(
+ $ySpace * $this->direction->x +
+ $xSpace * $this->direction->y
+ );
+
+ $length = sqrt( pow( $width, 2 ) + pow( $height, 2 ) );
+ $this->angle = rad2deg( acos( $height / $length ) );
+ }
+ }
+
+ /**
* Render Axis labels
*
* Render labels for an axis.
@@ -155,30 +192,7 @@ class ezcGraphAxisRotatedLabelRenderer extends ezcGraphAxisLabelRenderer
list( $xSpace, $ySpace ) = $this->getAxisSpace( $renderer, $boundings, $axis, $innerBoundings, $gridBoundings );
// 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(
- $ySpace * $this->direction->x +
- $xSpace * $this->direction->y
- );
-
- $length = sqrt( pow( $width, 2 ) + pow( $height, 2 ) );
- $this->angle = rad2deg( acos( $height / $length ) );
- }
+ $this->determineAngle( $steps, $xSpace, $ySpace, $axisBoundings );
// Determine additional required axis space by boxes
$firstStep = reset( $steps );
@@ -369,11 +383,11 @@ class ezcGraphAxisRotatedLabelRenderer extends ezcGraphAxisLabelRenderer
):
$labelBoundings = new ezcGraphBoundings(
$position->x,
- $position->y + $labelSize,
- $position->x + abs( $labelLength ) - $lengthReducement,
- $position->y
+ $position->y,
+ $position->x - abs( $labelLength ) + $lengthReducement,
+ $position->y + $labelSize
);
- $labelAlignement = ezcGraph::LEFT | ezcGraph::BOTTOM;
+ $labelAlignement = ezcGraph::LEFT | ezcGraph::TOP;
$labelRotation = $degTextAngle;
break;
}
@@ -424,9 +438,11 @@ class ezcGraphAxisRotatedLabelRenderer extends ezcGraphAxisLabelRenderer
{
return new ezcGraphCoordinate(
$coordinate->x * abs( $this->direction->y ) +
- ( $coordinate->x * ( 1 - abs( $this->offset ) ) + max( 0, $this->offset ) ) * abs( $this->direction->x ),
+ ( $coordinate->x * ( 1 - abs( $this->offset ) ) * abs( $this->direction->x ) ) +
+ ( abs( $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 )
+ ( $coordinate->y * ( 1 - abs( $this->offset ) ) * abs( $this->direction->y ) ) +
+ ( abs( $this->offset ) * abs( $this->direction->y ) )
);
}
}
OpenPOWER on IntegriCloud