From fe13be6dac3b9a019cd4ee7a4e1b3272ef922871 Mon Sep 17 00:00:00 2001 From: Kore Nordmann Date: Tue, 19 Sep 2006 13:29:02 +0000 Subject: - Added background and border to font configuration - Show value for highlighted datapoints in bar and line charts --- src/charts/line.php | 35 +++++++- src/driver/gd.php | 96 +++++++++++++++++++++- src/driver/svg.php | 110 ++++++++++++++++++++++++-- src/interfaces/renderer.php | 30 +++++++ src/options/font.php | 50 +++++++++++- src/options/line_chart.php | 65 ++++++++++++++- src/options/svg_driver.php | 2 +- src/renderer/2d.php | 189 +++++++++++++++++++++++++++++--------------- src/renderer/3d.php | 75 ++++++++++++++++++ 9 files changed, 577 insertions(+), 75 deletions(-) (limited to 'src') diff --git a/src/charts/line.php b/src/charts/line.php index 6d6f381..9732205 100644 --- a/src/charts/line.php +++ b/src/charts/line.php @@ -25,6 +25,7 @@ class ezcGraphLineChart extends ezcGraphChart public function __construct( array $options = array() ) { $this->options = new ezcGraphLineChartOptions( $options ); + $this->options->highlightFont = $this->options->font; parent::__construct(); @@ -152,6 +153,22 @@ class ezcGraphLineChart extends ezcGraphChart $yAxisNullPosition ); + if ( $data->highlight[$key] ) + { + $renderer->drawDataHighlightText( + $boundings, + new ezcGraphContext( $datasetName, $key ), + $point, + $yAxisNullPosition, + $nr[$data->displayType->default], + $count[$data->displayType->default], + $this->options->highlightFont, + $value, + $this->options->highlightSize, + ( $this->options->highlightLines ? $data->color[$key] : null ) + ); + } + $lastPoint = $point; } break; @@ -176,7 +193,7 @@ class ezcGraphLineChart extends ezcGraphChart $boundings, new ezcGraphContext( $datasetName, $key ), $data->color->default, - $this->elements['xAxis']->axisLabelRenderer->modifyChartDataPosition( + $point = $this->elements['xAxis']->axisLabelRenderer->modifyChartDataPosition( $this->elements['yAxis']->axisLabelRenderer->modifyChartDataPosition( $point ) @@ -187,6 +204,22 @@ class ezcGraphLineChart extends ezcGraphChart $data->symbol[$key], $yAxisNullPosition ); + + if ( $data->highlight[$key] ) + { + $renderer->drawDataHighlightText( + $boundings, + new ezcGraphContext( $datasetName, $key ), + $point, + $yAxisNullPosition, + $nr[$data->displayType->default], + $count[$data->displayType->default], + $this->options->highlightFont, + $value, + $this->options->highlightSize, + ( $this->options->highlightLines ? $data->color[$key] : null ) + ); + } } break; default: diff --git a/src/driver/gd.php b/src/driver/gd.php index 1e30e81..8629bfd 100644 --- a/src/driver/gd.php +++ b/src/driver/gd.php @@ -384,12 +384,18 @@ class ezcGraphGdDriver extends ezcGraphDriver public function drawTextBox( $string, ezcGraphCoordinate $position, $width, $height, $align ) { // Test font - // @TODO: try to find font at standard locations if no path was provided if ( !is_file( $this->options->font->path ) || !is_readable( $this->options->font->path ) ) { throw new ezcGraphGdDriverInvalidFontException( $this->options->font->path ); } + $padding = $this->options->font->padding + ( $this->options->font->border !== false ? $this->options->font->borderWidth : 0 ); + + $width -= $padding * 2; + $height -= $padding * 2; + $position->x += $padding; + $position->y += $padding; + // Try to get a font size for the text to fit into the box $maxSize = min( $height, $this->options->font->maxFontSize ); $result = false; @@ -453,6 +459,94 @@ class ezcGraphGdDriver extends ezcGraphDriver break; } + $padding = $text['font']->padding + $text['font']->borderWidth / 2; + if ( $this->options->font->minimizeBorder === true ) + { + // Calculate maximum width of text rows + $width = false; + foreach ( $text['text'] as $line ) + { + $string = implode( ' ', $line ); + $boundings = $this->getTextBoundings( $size, $text['font'], $string ); + if ( ( $width === false) || ( $boundings->width > $width ) ) + { + $width = $boundings->width; + } + } + + switch ( true ) + { + case ( $text['align'] & ezcGraph::LEFT ): + $xOffset = 0; + break; + case ( $text['align'] & ezcGraph::CENTER ): + $xOffset = ( $text['width'] - $width ) / 2; + break; + case ( $text['align'] & ezcGraph::RIGHT ): + $xOffset = $text['width'] - $width; + break; + } + + $borderPolygonArray = array( + new ezcGraphCoordinate( + $text['position']->x - $padding + $xOffset, + $text['position']->y - $padding + $yOffset + ), + new ezcGraphCoordinate( + $text['position']->x + $padding * 2 + $xOffset + $width, + $text['position']->y - $padding + $yOffset + ), + new ezcGraphCoordinate( + $text['position']->x + $padding * 2 + $xOffset + $width, + $text['position']->y + $padding * 2 + $yOffset + $completeHeight + ), + new ezcGraphCoordinate( + $text['position']->x - $padding + $xOffset, + $text['position']->y + $padding * 2 + $yOffset + $completeHeight + ), + ); + } + else + { + $borderPolygonArray = array( + new ezcGraphCoordinate( + $text['position']->x - $padding, + $text['position']->y - $padding + ), + new ezcGraphCoordinate( + $text['position']->x + $padding * 2 + $text['width'], + $text['position']->y - $padding + ), + new ezcGraphCoordinate( + $text['position']->x + $padding * 2 + $text['width'], + $text['position']->y + $padding * 2 + $text['height'] + ), + new ezcGraphCoordinate( + $text['position']->x - $padding, + $text['position']->y + $padding * 2 + $text['height'] + ), + ); + } + + if ( $text['font']->background !== false ) + { + $this->drawPolygon( + $borderPolygonArray, + $text['font']->background, + true + ); + } + + if ( $text['font']->border !== false ) + { + $this->drawPolygon( + $borderPolygonArray, + $text['font']->border, + false, + $text['font']->borderWidth + ); + } + // Render text with evaluated font size foreach ( $text['text'] as $line ) { diff --git a/src/driver/svg.php b/src/driver/svg.php index bcdd1a2..9fa4e5c 100644 --- a/src/driver/svg.php +++ b/src/driver/svg.php @@ -408,6 +408,13 @@ class ezcGraphSvgDriver extends ezcGraphDriver */ public function drawTextBox( $string, ezcGraphCoordinate $position, $width, $height, $align ) { + $padding = $this->options->font->padding + ( $this->options->font->border !== false ? $this->options->font->borderWidth : 0 ); + + $width -= $padding * 2; + $height -= $padding * 2; + $position->x += $padding; + $position->y += $padding; + // Try to get a font size for the text to fit into the box $maxSize = min( $height, $this->options->font->maxFontSize ); $result = false; @@ -428,7 +435,7 @@ class ezcGraphSvgDriver extends ezcGraphDriver 'width' => $width, 'height' => $height, 'align' => $align, - 'options' => $this->options->font, + 'font' => $this->options->font, ); return $id; @@ -438,8 +445,8 @@ class ezcGraphSvgDriver extends ezcGraphDriver { foreach ( $this->strings as $text ) { - $size = $text['options']->minimalUsedFont; - $font = $text['options']->name; + $size = $text['font']->minimalUsedFont; + $font = $text['font']->name; $completeHeight = count( $text['text'] ) * $size + ( count( $text['text'] ) - 1 ) * $this->options->lineSpacing; @@ -458,6 +465,93 @@ class ezcGraphSvgDriver extends ezcGraphDriver break; } + $padding = $text['font']->padding + $text['font']->borderWidth / 2; + if ( $this->options->font->minimizeBorder === true ) + { + // Calculate maximum width of text rows + $width = false; + foreach ( $text['text'] as $line ) + { + $string = implode( ' ', $line ); + if ( ( $strWidth = ( $size * strlen( $string ) * $this->options->assumedCharacterWidth ) ) > $width ) + { + $width = $strWidth; + } + } + + switch ( true ) + { + case ( $text['align'] & ezcGraph::LEFT ): + $xOffset = 0; + break; + case ( $text['align'] & ezcGraph::CENTER ): + $xOffset = ( $text['width'] - $width ) / 2; + break; + case ( $text['align'] & ezcGraph::RIGHT ): + $xOffset = $text['width'] - $width; + break; + } + + $borderPolygonArray = array( + new ezcGraphCoordinate( + $text['position']->x - $padding + $xOffset, + $text['position']->y - $padding + $yOffset + ), + new ezcGraphCoordinate( + $text['position']->x + $padding * 2 + $xOffset + $width, + $text['position']->y - $padding + $yOffset + ), + new ezcGraphCoordinate( + $text['position']->x + $padding * 2 + $xOffset + $width, + $text['position']->y + $padding * 2 + $yOffset + $completeHeight + ), + new ezcGraphCoordinate( + $text['position']->x - $padding + $xOffset, + $text['position']->y + $padding * 2 + $yOffset + $completeHeight + ), + ); + } + else + { + $borderPolygonArray = array( + new ezcGraphCoordinate( + $text['position']->x - $padding, + $text['position']->y - $padding + ), + new ezcGraphCoordinate( + $text['position']->x + $padding * 2 + $text['width'], + $text['position']->y - $padding + ), + new ezcGraphCoordinate( + $text['position']->x + $padding * 2 + $text['width'], + $text['position']->y + $padding * 2 + $text['height'] + ), + new ezcGraphCoordinate( + $text['position']->x - $padding, + $text['position']->y + $padding * 2 + $text['height'] + ), + ); + } + + if ( $text['font']->background !== false ) + { + $this->drawPolygon( + $borderPolygonArray, + $text['font']->background, + true + ); + } + + if ( $text['font']->border !== false ) + { + $this->drawPolygon( + $borderPolygonArray, + $text['font']->border, + false, + $text['font']->borderWidth + ); + } + // Render text with evaluated font size foreach ( $text['text'] as $line ) { @@ -496,11 +590,11 @@ class ezcGraphSvgDriver extends ezcGraphDriver sprintf( 'font-size: %dpx; font-family: %s; fill: #%02x%02x%02x; fill-opacity: %.2f; stroke: none;', $size, - $text['options']->name, - $text['options']->color->red, - $text['options']->color->green, - $text['options']->color->blue, - 1 - ( $text['options']->color->alpha / 255 ) + $text['font']->name, + $text['font']->color->red, + $text['font']->color->green, + $text['font']->color->blue, + 1 - ( $text['font']->color->alpha / 255 ) ) ); diff --git a/src/interfaces/renderer.php b/src/interfaces/renderer.php index 84907e0..46b5301 100644 --- a/src/interfaces/renderer.php +++ b/src/interfaces/renderer.php @@ -148,6 +148,36 @@ abstract class ezcGraphRenderer $axisPosition = 0., $thickness = 1 ); + + /** + * Draws a highlight textbox for a datapoint. + * + * A highlight textbox for line and bar charts means a box with the current + * value in the graph. + * + * @param ezcGraphBoundings $boundings Chart boundings + * @param ezcGraphContext $context Context of call + * @param ezcGraphCoordinate $end Ending point + * @param float $axisPosition Position of axis for drawing filled lines + * @param int $dataNumber Number of dataset + * @param int $dataCount Count of datasets in chart + * @param ezcGraphFontOptions $font Font used for highlight string + * @param string $text Acutual value + * @param int $size Size of highlight text + * @return void + */ + abstract public function drawDataHighlightText( + ezcGraphBoundings $boundings, + ezcGraphContext $context, + ezcGraphCoordinate $end, + $axisPosition = 0., + $dataNumber = 1, + $dataCount = 1, + ezcGraphFontOptions $font, + $text, + $size, + ezcGraphColor $markLines = null + ); /** * Draw legend diff --git a/src/options/font.php b/src/options/font.php index 2da92ad..f746f73 100644 --- a/src/options/font.php +++ b/src/options/font.php @@ -19,7 +19,6 @@ * - TTF_FONT Native TTF fonts * - PS_FONT PostScript Type1 fonts * - FT2_FONT FreeType 2 fonts - * - GD_FONT Native GD bitmap fonts * @property float $minFontSize * Minimum font size for displayed texts. * @property float $maxFontSize @@ -30,6 +29,18 @@ * Font color. * @property float $lineSpacing * Percent of font size used for line spacing + * @property ezcGraphColor $background + * Background color + * @property ezcGraphColor $border + * Border color + * @property int $borderWidth + * Border width + * @property int $padding + * Padding between text and border + * @property bool $minimizeBorder + * Fit the border exactly around the text, or use the complete + * possible space. + * * * @package Graph */ @@ -54,6 +65,12 @@ class ezcGraphFontOptions extends ezcBaseOptions $this->properties['lineSpacing'] = .1; $this->properties['color'] = ezcGraphColor::fromHex( '#000000' ); + $this->properties['background'] = false; + $this->properties['border'] = false; + $this->properties['borderWidth'] = 1; + $this->properties['padding'] = 0; + $this->properties['minimizeBorder'] = true; + parent::__construct( $options ); } @@ -93,6 +110,37 @@ class ezcGraphFontOptions extends ezcBaseOptions throw new ezcBaseValueException( $propertyName, $propertyValue, 'ezcGraphColor' ); } break; + + case 'background': + if ( $propertyValue instanceof ezcGraphColor ) + { + $this->properties['background'] = $propertyValue; + } + else + { + throw new ezcBaseValueException( $propertyName, $propertyValue, 'ezcGraphColor' ); + } + break; + case 'border': + if ( $propertyValue instanceof ezcGraphColor ) + { + $this->properties['border'] = $propertyValue; + } + else + { + throw new ezcBaseValueException( $propertyName, $propertyValue, 'ezcGraphColor' ); + } + break; + case 'borderWidth': + $this->properties['borderWidth'] = (int) $propertyValue; + break; + case 'padding': + $this->properties['padding'] = (int) $propertyValue; + break; + case 'minimizeBorder': + $this->properties['minimizeBorder'] = (bool) $propertyValue; + break; + case 'name': if ( is_string( $propertyValue ) ) { diff --git a/src/options/line_chart.php b/src/options/line_chart.php index 358f82a..c8eadb5 100644 --- a/src/options/line_chart.php +++ b/src/options/line_chart.php @@ -18,6 +18,13 @@ * - (int) Opacity used to fill up the space with the lines color. * @property int $symbolSize * Size of symbols in line chart. + * @property ezcGraphFontOptions $highlightFont + * Font configuration for highlight tests + * @property int $highlightSize + * Size of highlight blocks + * @property bool $highlightLines + * If true, it adds lines to highlight the values position on the + * axis. * * @package Graph */ @@ -35,7 +42,11 @@ class ezcGraphLineChartOptions extends ezcGraphChartOptions $this->properties['lineThickness'] = 2; $this->properties['fillLines'] = false; $this->properties['symbolSize'] = 8; - + $this->properties['highlightFont'] = new ezcGraphFontOptions(); + $this->properties['highlightFontCloned'] = false; + $this->properties['highlightSize'] = 14; + $this->properties['highlightLines'] = false; + parent::__construct( $options ); } @@ -68,10 +79,62 @@ class ezcGraphLineChartOptions extends ezcGraphChartOptions case 'symbolSize': $this->properties['symbolSize'] = max( 1, (int) $propertyValue ); break; + case 'highlightFont': + if ( $propertyValue instanceof ezcGraphFontOptions ) + { + $this->properties['highlightFont'] = $propertyValue; + } + elseif ( is_string( $propertyValue ) ) + { + if ( !$this->properties['highlightFontCloned'] ) + { + $this->properties['highlightFont'] = clone $this->font; + $this->properties['highlightFontCloned'] = true; + } + + $this->properties['highlightFont']->font = $propertyValue; + } + else + { + throw new ezcBaseValueException( $propertyValue, 'ezcGraphFontOptions' ); + } + break; + case 'highlightSize': + $this->properties['highlightSize'] = max( 1, (int) $propertyValue ); + break; + case 'highlightLines': + $this->properties['highlightLines'] = (bool) $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 'highlightFont': + // Clone font configuration when requested for this element + if ( !$this->properties['highlightFontCloned'] ) + { + $this->properties['highlightFont'] = clone $this->properties['font']; + $this->properties['highlightFontCloned'] = true; + } + return $this->properties['highlightFont']; + default: + return parent::__get( $propertyName ); + } + } } ?> diff --git a/src/options/svg_driver.php b/src/options/svg_driver.php index 4a83ca4..53d73d8 100644 --- a/src/options/svg_driver.php +++ b/src/options/svg_driver.php @@ -57,7 +57,7 @@ class ezcGraphSvgDriverOptions extends ezcGraphDriverOptions */ public function __construct( array $options = array() ) { - $this->properties['assumedCharacterWidth'] = .55; + $this->properties['assumedCharacterWidth'] = .55; // @TODO .6 seems to fit better $this->properties['strokeLineJoin'] = 'round'; $this->properties['strokeLineCap'] = 'round'; $this->properties['shapeRendering'] = 'geometricPrecision'; diff --git a/src/renderer/2d.php b/src/renderer/2d.php index e038aeb..57de7bd 100644 --- a/src/renderer/2d.php +++ b/src/renderer/2d.php @@ -72,14 +72,14 @@ class ezcGraphRenderer2d extends ezcGraphRenderer { // Calculate position and size of pie $center = new ezcGraphCoordinate( - $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) / 2, - $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) / 2 + $boundings->x0 + ( $boundings->width ) / 2, + $boundings->y0 + ( $boundings->height ) / 2 ); // Limit radius to fourth of width and half of height at maximum $radius = min( - ( $boundings->x1 - $boundings->x0 ) * $this->options->pieHorizontalSize, - ( $boundings->y1 - $boundings->y0 ) / $this->options->pieVerticalSize + ( $boundings->width ) * $this->options->pieHorizontalSize, + ( $boundings->height ) * $this->options->pieVerticalSize ) * ( 1 - $this->options->moveOut ); // Move pie segment out of the center @@ -193,21 +193,21 @@ class ezcGraphRenderer2d extends ezcGraphRenderer // Calculate position and size of pie $center = new ezcGraphCoordinate( - $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) / 2, - $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) / 2 + $boundings->x0 + ( $boundings->width ) / 2, + $boundings->y0 + ( $boundings->height ) / 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 + ( $boundings->width ) / 4, + ( $boundings->height ) / 2 ); $pieChartHeight = min( $radius * 2 + $this->options->maxLabelHeight * 2, - $boundings->y1 - $boundings->y0 + $boundings->height ); - $pieChartYPosition = $boundings->y0 + ( ( $boundings->y1 - $boundings->y0 ) - $pieChartHeight ) / 2; + $pieChartYPosition = $boundings->y0 + ( ( $boundings->height ) - $pieChartHeight ) / 2; // Calculate maximum height of labels $labelHeight = (int) round( min( @@ -219,7 +219,7 @@ class ezcGraphRenderer2d extends ezcGraphRenderer ? $pieChartHeight / count( $this->pieSegmentLabels[1] ) : $pieChartHeight ), - ( $boundings->y1 - $boundings->y0 ) * $this->options->maxLabelHeight + ( $boundings->height ) * $this->options->maxLabelHeight ) ); $symbolSize = $this->options->symbolSize; @@ -351,20 +351,20 @@ class ezcGraphRenderer2d extends ezcGraphRenderer $barPointArray = array( new ezcGraphCoordinate( - $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $position->x + $offset, - $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $axisPosition + $boundings->x0 + ( $boundings->width ) * $position->x + $offset, + $boundings->y0 + ( $boundings->height ) * $axisPosition ), new ezcGraphCoordinate( - $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $position->x + $offset, - $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $position->y + $boundings->x0 + ( $boundings->width ) * $position->x + $offset, + $boundings->y0 + ( $boundings->height ) * $position->y ), new ezcGraphCoordinate( - $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $position->x + $offset + $barWidth, - $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $position->y + $boundings->x0 + ( $boundings->width ) * $position->x + $offset + $barWidth, + $boundings->y0 + ( $boundings->height ) * $position->y ), new ezcGraphCoordinate( - $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $position->x + $offset + $barWidth, - $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $axisPosition + $boundings->x0 + ( $boundings->width ) * $position->x + $offset + $barWidth, + $boundings->y0 + ( $boundings->height ) * $axisPosition ), ); @@ -437,20 +437,20 @@ class ezcGraphRenderer2d extends ezcGraphRenderer $this->driver->drawPolygon( array( new ezcGraphCoordinate( - $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $start->x, - $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $start->y + $boundings->x0 + ( $boundings->width ) * $start->x, + $boundings->y0 + ( $boundings->height ) * $start->y ), new ezcGraphCoordinate( - $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $end->x, - $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $end->y + $boundings->x0 + ( $boundings->width ) * $end->x, + $boundings->y0 + ( $boundings->height ) * $end->y ), new ezcGraphCoordinate( - $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $end->x, - $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $axisPosition + $boundings->x0 + ( $boundings->width ) * $end->x, + $boundings->y0 + ( $boundings->height ) * $axisPosition ), new ezcGraphCoordinate( - $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $start->x, - $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $axisPosition + $boundings->x0 + ( $boundings->width ) * $start->x, + $boundings->y0 + ( $boundings->height ) * $axisPosition ), ), $fillColor, @@ -472,16 +472,16 @@ class ezcGraphRenderer2d extends ezcGraphRenderer $this->driver->drawPolygon( array( new ezcGraphCoordinate( - $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $start->x, - $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $axisPosition + $boundings->x0 + ( $boundings->width ) * $start->x, + $boundings->y0 + ( $boundings->height ) * $axisPosition ), new ezcGraphCoordinate( - $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $start->x, - $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $start->y + $boundings->x0 + ( $boundings->width ) * $start->x, + $boundings->y0 + ( $boundings->height ) * $start->y ), new ezcGraphCoordinate( - $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $cuttingPoint->x, - $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $cuttingPoint->y + $boundings->x0 + ( $boundings->width ) * $cuttingPoint->x, + $boundings->y0 + ( $boundings->height ) * $cuttingPoint->y ), ), $fillColor, @@ -491,16 +491,16 @@ class ezcGraphRenderer2d extends ezcGraphRenderer $this->driver->drawPolygon( array( new ezcGraphCoordinate( - $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $end->x, - $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $axisPosition + $boundings->x0 + ( $boundings->width ) * $end->x, + $boundings->y0 + ( $boundings->height ) * $axisPosition ), new ezcGraphCoordinate( - $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $end->x, - $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $end->y + $boundings->x0 + ( $boundings->width ) * $end->x, + $boundings->y0 + ( $boundings->height ) * $end->y ), new ezcGraphCoordinate( - $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $cuttingPoint->x, - $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $cuttingPoint->y + $boundings->x0 + ( $boundings->width ) * $cuttingPoint->x, + $boundings->y0 + ( $boundings->height ) * $cuttingPoint->y ), ), $fillColor, @@ -512,12 +512,12 @@ class ezcGraphRenderer2d extends ezcGraphRenderer // Draw line $this->driver->drawLine( new ezcGraphCoordinate( - $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $start->x, - $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $start->y + $boundings->x0 + ( $boundings->width ) * $start->x, + $boundings->y0 + ( $boundings->height ) * $start->y ), new ezcGraphCoordinate( - $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $end->x, - $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $end->y + $boundings->x0 + ( $boundings->width ) * $end->x, + $boundings->y0 + ( $boundings->height ) * $end->y ), $color, $thickness @@ -533,10 +533,10 @@ class ezcGraphRenderer2d extends ezcGraphRenderer $this->linePostSymbols[] = array( 'boundings' => new ezcGraphBoundings( - $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $end->x - $this->options->symbolSize / 2, - $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $end->y - $this->options->symbolSize / 2, - $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $end->x + $this->options->symbolSize / 2, - $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $end->y + $this->options->symbolSize / 2 + $boundings->x0 + ( $boundings->width ) * $end->x - $this->options->symbolSize / 2, + $boundings->y0 + ( $boundings->height ) * $end->y - $this->options->symbolSize / 2, + $boundings->x0 + ( $boundings->width ) * $end->x + $this->options->symbolSize / 2, + $boundings->y0 + ( $boundings->height ) * $end->y + $this->options->symbolSize / 2 ), 'color' => $symbolColor, 'context' => $context, @@ -546,6 +546,71 @@ class ezcGraphRenderer2d extends ezcGraphRenderer } /** + * Draws a highlight textbox for a datapoint. + * + * A highlight textbox for line and bar charts means a box with the current + * value in the graph. + * + * @param ezcGraphBoundings $boundings Chart boundings + * @param ezcGraphContext $context Context of call + * @param ezcGraphCoordinate $end Ending point + * @param float $axisPosition Position of axis for drawing filled lines + * @param int $dataNumber Number of dataset + * @param int $dataCount Count of datasets in chart + * @param ezcGraphFontOptions $font Font used for highlight string + * @param string $text Acutual value + * @param int $size Size of highlight text + * @return void + */ + public function drawDataHighlightText( + ezcGraphBoundings $boundings, + ezcGraphContext $context, + ezcGraphCoordinate $end, + $axisPosition = 0., + $dataNumber = 1, + $dataCount = 1, + ezcGraphFontOptions $font, + $text, + $size, + ezcGraphColor $markLines = null ) + { + $this->driver->options->font = $font; + $width = $boundings->width / $dataCount; + + $dataPoint = new ezcGraphCoordinate( + $boundings->x0 + ( $boundings->width ) * $end->x, + $boundings->y0 + ( $boundings->height ) * $end->y + ); + + if ( $end->y < $axisPosition ) + { + $this->driver->drawTextBox( + $text, + new ezcGraphCoordinate( + $dataPoint->x - $width / 2, + $dataPoint->y - $size - $font->padding - $this->options->symbolSize + ), + $width, + $size, + ezcGraph::CENTER | ezcGraph::BOTTOM + ); + } + else + { + $this->driver->drawTextBox( + $text, + new ezcGraphCoordinate( + $dataPoint->x - $width / 2, + $dataPoint->y + $font->padding + $this->options->symbolSize + ), + $width, + $size, + ezcGraph::CENTER | ezcGraph::TOP + ); + } + } + + /** * Draw legend * * Will draw a legend in the bounding box @@ -565,17 +630,17 @@ class ezcGraphRenderer2d extends ezcGraphRenderer // Calculate boundings of each label if ( $type & ezcGraph::VERTICAL ) { - $labelWidth = $boundings->x1 - $boundings->x0; + $labelWidth = $boundings->width; $labelHeight = min( - ( $boundings->y1 - $boundings->y0 ) / count( $labels ) - $legend->spacing, + ( $boundings->height ) / count( $labels ) - $legend->spacing, $legend->symbolSize + 2 * $legend->padding ); } else { - $labelWidth = ( $boundings->x1 - $boundings->x0 ) / count( $labels ) - $legend->spacing; + $labelWidth = ( $boundings->width ) / count( $labels ) - $legend->spacing; $labelHeight = min( - $boundings->x1 - $boundings->x0, + $boundings->width, $legend->symbolSize + 2 * $legend->padding ); } @@ -699,7 +764,7 @@ class ezcGraphRenderer2d extends ezcGraphRenderer $this->driver->drawTextBox( $title, new ezcGraphCoordinate( $boundings->x0, $boundings->y0 ), - $boundings->x1 - $boundings->x0, + $boundings->width, $titleSize, $this->options->titleAlignement ); @@ -711,7 +776,7 @@ class ezcGraphRenderer2d extends ezcGraphRenderer $this->driver->drawTextBox( $title, new ezcGraphCoordinate( $boundings->x0, $boundings->y1 - $titleSize ), - $boundings->x1 - $boundings->x0, + $boundings->width, $titleSize, $this->options->titleAlignement ); @@ -742,8 +807,8 @@ class ezcGraphRenderer2d extends ezcGraphRenderer $this->driver->drawTextBox( $text, new ezcGraphCoordinate( $boundings->x0, $boundings->y0 ), - $boundings->x1 - $boundings->x0, - $boundings->y1 - $boundings->y0, + $boundings->width, + $boundings->height, $align ); } @@ -831,11 +896,11 @@ class ezcGraphRenderer2d extends ezcGraphRenderer { case ezcGraph::TOP: case ezcGraph::BOTTOM: - $this->xAxisSpace = ( $boundings->x1 - $boundings->x0 ) * $axis->axisSpace; + $this->xAxisSpace = ( $boundings->width ) * $axis->axisSpace; break; case ezcGraph::LEFT: case ezcGraph::RIGHT: - $this->yAxisSpace = ( $boundings->y1 - $boundings->y0 ) * $axis->axisSpace; + $this->yAxisSpace = ( $boundings->height ) * $axis->axisSpace; break; } @@ -900,7 +965,7 @@ class ezcGraphRenderer2d extends ezcGraphRenderer // Draw axis label if ( $axis->label !== false ) { - $width = $boundings->x1 - $boundings->x0; + $width = $boundings->width; switch ( $axis->position ) { case ezcGraph::TOP: @@ -1014,8 +1079,8 @@ class ezcGraphRenderer2d extends ezcGraphRenderer $imageWidth = $imageData[0]; $imageHeight = $imageData[1]; - $imageWidth = min( $imageWidth, $boundings->x1 - $boundings->x0 ); - $imageHeight = min( $imageHeight, $boundings->y1 - $boundings->y0 ); + $imageWidth = min( $imageWidth, $boundings->width ); + $imageHeight = min( $imageHeight, $boundings->height ); $imagePosition = new ezcGraphCoordinate( $boundings->x0, @@ -1037,7 +1102,7 @@ class ezcGraphRenderer2d extends ezcGraphRenderer break; default: $imagePosition->x = max( - $boundings->x0 + ( $boundings->x1 - $boundings->x0 - $imageWidth ) / 2, + $boundings->x0 + ( $boundings->width - $imageWidth ) / 2, $boundings->x0 ); break; @@ -1058,7 +1123,7 @@ class ezcGraphRenderer2d extends ezcGraphRenderer break; default: $imagePosition->y = max( - $boundings->y0 + ( $boundings->y1 - $boundings->y0 - $imageHeight ) / 2, + $boundings->y0 + ( $boundings->height - $imageHeight ) / 2, $boundings->y0 ); break; diff --git a/src/renderer/3d.php b/src/renderer/3d.php index ffd382e..e30175c 100644 --- a/src/renderer/3d.php +++ b/src/renderer/3d.php @@ -1139,6 +1139,81 @@ class ezcGraphRenderer3d extends ezcGraphRenderer } /** + * Draws a highlight textbox for a datapoint. + * + * A highlight textbox for line and bar charts means a box with the current + * value in the graph. + * + * @param ezcGraphBoundings $boundings Chart boundings + * @param ezcGraphContext $context Context of call + * @param ezcGraphCoordinate $end Ending point + * @param float $axisPosition Position of axis for drawing filled lines + * @param int $dataNumber Number of dataset + * @param int $dataCount Count of datasets in chart + * @param ezcGraphFontOptions $font Font used for highlight string + * @param string $text Acutual value + * @param int $size Size of highlight text + * @return void + */ + public function drawDataHighlightText( + ezcGraphBoundings $boundings, + ezcGraphContext $context, + ezcGraphCoordinate $end, + $axisPosition = 0., + $dataNumber = 1, + $dataCount = 1, + ezcGraphFontOptions $font, + $text, + $size, + ezcGraphColor $markLines = null ) + { + $this->driver->options->font = $font; + $width = $this->dataBoundings->width / $dataCount; + + // Calculate line width based on options + if ( $this->options->seperateLines ) + { + $endDepth = ( 1 / $dataCount ) * ( $dataNumber + 1 ); + } + else + { + $endDepth = true; + } + + $dataPoint = new ezcGraphCoordinate( + $this->dataBoundings->x0 + $this->xAxisSpace + $end->x * ( $this->dataBoundings->x1 - ( $this->dataBoundings->x0 + 2 * $this->xAxisSpace ) ), + $this->dataBoundings->y0 + $this->yAxisSpace + $end->y * ( $this->dataBoundings->y1 - ( $this->dataBoundings->y0 + 2 * $this->yAxisSpace ) ) + ); + + if ( $end->y < $axisPosition ) + { + $this->driver->drawTextBox( + $text, + $this->get3dCoordinate( new ezcGraphCoordinate( + $dataPoint->x - $width / 2, + $dataPoint->y - $size - $font->padding - $this->options->symbolSize + ), $endDepth ), + $width * $this->xDepthFactor, + $size, + ezcGraph::CENTER | ezcGraph::BOTTOM + ); + } + else + { + $this->driver->drawTextBox( + $text, + $this->get3dCoordinate( new ezcGraphCoordinate( + $dataPoint->x - $width / 2, + $dataPoint->y + $font->padding + $this->options->symbolSize + ), $endDepth ), + $width * $this->xDepthFactor, + $size, + ezcGraph::CENTER | ezcGraph::TOP + ); + } + } + + /** * Draw legend * * Will draw a legend in the bounding box -- cgit v1.1