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 ++++++++ ...raphGdDriverTest_testDrawTextWithBackground.png | Bin 0 -> 3847 bytes ...ezcGraphGdDriverTest_testDrawTextWithBorder.png | Bin 0 -> 3533 bytes ...WithMinimizedBorderAndBackgroundBottomRight.png | Bin 0 -> 3902 bytes ...ithMinimizedBorderAndBackgroundMiddleCenter.png | Bin 0 -> 3902 bytes ...TextWithMinimizedBorderAndBackgroundTopLeft.png | Bin 0 -> 3901 bytes ...Test_testRenderLineChartWithHighlightedData.svg | 2 + ...Test_testRenderLineChartWithHighlightedData.svg | 2 + ...aphSvgDriverTest_testDrawTextWithBackground.svg | 2 + ...zcGraphSvgDriverTest_testDrawTextWithBorder.svg | 2 + ...WithMinimizedBorderAndBackgroundBottomRight.svg | 2 + ...ithMinimizedBorderAndBackgroundMiddleCenter.svg | 2 + ...TextWithMinimizedBorderAndBackgroundTopLeft.svg | 2 + tests/driver_gd_test.php | 156 +++++++++++++++++ tests/driver_svg_test.php | 125 +++++++++++++- tests/pie_test.php | 4 +- tests/renderer_2d_test.php | 30 ++++ tests/renderer_3d_test.php | 32 ++++ 26 files changed, 934 insertions(+), 79 deletions(-) create mode 100644 tests/data/compare/ezcGraphGdDriverTest_testDrawTextWithBackground.png create mode 100644 tests/data/compare/ezcGraphGdDriverTest_testDrawTextWithBorder.png create mode 100644 tests/data/compare/ezcGraphGdDriverTest_testDrawTextWithMinimizedBorderAndBackgroundBottomRight.png create mode 100644 tests/data/compare/ezcGraphGdDriverTest_testDrawTextWithMinimizedBorderAndBackgroundMiddleCenter.png create mode 100644 tests/data/compare/ezcGraphGdDriverTest_testDrawTextWithMinimizedBorderAndBackgroundTopLeft.png create mode 100644 tests/data/compare/ezcGraphRenderer2dTest_testRenderLineChartWithHighlightedData.svg create mode 100644 tests/data/compare/ezcGraphRenderer3dTest_testRenderLineChartWithHighlightedData.svg create mode 100644 tests/data/compare/ezcGraphSvgDriverTest_testDrawTextWithBackground.svg create mode 100644 tests/data/compare/ezcGraphSvgDriverTest_testDrawTextWithBorder.svg create mode 100644 tests/data/compare/ezcGraphSvgDriverTest_testDrawTextWithMinimizedBorderAndBackgroundBottomRight.svg create mode 100644 tests/data/compare/ezcGraphSvgDriverTest_testDrawTextWithMinimizedBorderAndBackgroundMiddleCenter.svg create mode 100644 tests/data/compare/ezcGraphSvgDriverTest_testDrawTextWithMinimizedBorderAndBackgroundTopLeft.svg 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 diff --git a/tests/data/compare/ezcGraphGdDriverTest_testDrawTextWithBackground.png b/tests/data/compare/ezcGraphGdDriverTest_testDrawTextWithBackground.png new file mode 100644 index 0000000..b40d162 Binary files /dev/null and b/tests/data/compare/ezcGraphGdDriverTest_testDrawTextWithBackground.png differ diff --git a/tests/data/compare/ezcGraphGdDriverTest_testDrawTextWithBorder.png b/tests/data/compare/ezcGraphGdDriverTest_testDrawTextWithBorder.png new file mode 100644 index 0000000..517ceb9 Binary files /dev/null and b/tests/data/compare/ezcGraphGdDriverTest_testDrawTextWithBorder.png differ diff --git a/tests/data/compare/ezcGraphGdDriverTest_testDrawTextWithMinimizedBorderAndBackgroundBottomRight.png b/tests/data/compare/ezcGraphGdDriverTest_testDrawTextWithMinimizedBorderAndBackgroundBottomRight.png new file mode 100644 index 0000000..39f1898 Binary files /dev/null and b/tests/data/compare/ezcGraphGdDriverTest_testDrawTextWithMinimizedBorderAndBackgroundBottomRight.png differ diff --git a/tests/data/compare/ezcGraphGdDriverTest_testDrawTextWithMinimizedBorderAndBackgroundMiddleCenter.png b/tests/data/compare/ezcGraphGdDriverTest_testDrawTextWithMinimizedBorderAndBackgroundMiddleCenter.png new file mode 100644 index 0000000..797e162 Binary files /dev/null and b/tests/data/compare/ezcGraphGdDriverTest_testDrawTextWithMinimizedBorderAndBackgroundMiddleCenter.png differ diff --git a/tests/data/compare/ezcGraphGdDriverTest_testDrawTextWithMinimizedBorderAndBackgroundTopLeft.png b/tests/data/compare/ezcGraphGdDriverTest_testDrawTextWithMinimizedBorderAndBackgroundTopLeft.png new file mode 100644 index 0000000..8592407 Binary files /dev/null and b/tests/data/compare/ezcGraphGdDriverTest_testDrawTextWithMinimizedBorderAndBackgroundTopLeft.png differ diff --git a/tests/data/compare/ezcGraphRenderer2dTest_testRenderLineChartWithHighlightedData.svg b/tests/data/compare/ezcGraphRenderer2dTest_testRenderLineChartWithHighlightedData.svg new file mode 100644 index 0000000..f62fe67 --- /dev/null +++ b/tests/data/compare/ezcGraphRenderer2dTest_testRenderLineChartWithHighlightedData.svg @@ -0,0 +1,2 @@ + +Line 1Line 2sample 1sample 2sample 3sample 4sample 5-2500250500750234-21324-1201613 diff --git a/tests/data/compare/ezcGraphRenderer3dTest_testRenderLineChartWithHighlightedData.svg b/tests/data/compare/ezcGraphRenderer3dTest_testRenderLineChartWithHighlightedData.svg new file mode 100644 index 0000000..5739c43 --- /dev/null +++ b/tests/data/compare/ezcGraphRenderer3dTest_testRenderLineChartWithHighlightedData.svg @@ -0,0 +1,2 @@ + +Line 1Line 2sample 1sample 2sample 3sample 4sample 5-2500250500750234-21324-1201613 diff --git a/tests/data/compare/ezcGraphSvgDriverTest_testDrawTextWithBackground.svg b/tests/data/compare/ezcGraphSvgDriverTest_testDrawTextWithBackground.svg new file mode 100644 index 0000000..05d55f4 --- /dev/null +++ b/tests/data/compare/ezcGraphSvgDriverTest_testDrawTextWithBackground.svg @@ -0,0 +1,2 @@ + +Some test string diff --git a/tests/data/compare/ezcGraphSvgDriverTest_testDrawTextWithBorder.svg b/tests/data/compare/ezcGraphSvgDriverTest_testDrawTextWithBorder.svg new file mode 100644 index 0000000..2f19f01 --- /dev/null +++ b/tests/data/compare/ezcGraphSvgDriverTest_testDrawTextWithBorder.svg @@ -0,0 +1,2 @@ + +Some test string diff --git a/tests/data/compare/ezcGraphSvgDriverTest_testDrawTextWithMinimizedBorderAndBackgroundBottomRight.svg b/tests/data/compare/ezcGraphSvgDriverTest_testDrawTextWithMinimizedBorderAndBackgroundBottomRight.svg new file mode 100644 index 0000000..f5aeb63 --- /dev/null +++ b/tests/data/compare/ezcGraphSvgDriverTest_testDrawTextWithMinimizedBorderAndBackgroundBottomRight.svg @@ -0,0 +1,2 @@ + +Some test string diff --git a/tests/data/compare/ezcGraphSvgDriverTest_testDrawTextWithMinimizedBorderAndBackgroundMiddleCenter.svg b/tests/data/compare/ezcGraphSvgDriverTest_testDrawTextWithMinimizedBorderAndBackgroundMiddleCenter.svg new file mode 100644 index 0000000..d14c9ec --- /dev/null +++ b/tests/data/compare/ezcGraphSvgDriverTest_testDrawTextWithMinimizedBorderAndBackgroundMiddleCenter.svg @@ -0,0 +1,2 @@ + +Some test string diff --git a/tests/data/compare/ezcGraphSvgDriverTest_testDrawTextWithMinimizedBorderAndBackgroundTopLeft.svg b/tests/data/compare/ezcGraphSvgDriverTest_testDrawTextWithMinimizedBorderAndBackgroundTopLeft.svg new file mode 100644 index 0000000..9d36eda --- /dev/null +++ b/tests/data/compare/ezcGraphSvgDriverTest_testDrawTextWithMinimizedBorderAndBackgroundTopLeft.svg @@ -0,0 +1,2 @@ + +Some test string diff --git a/tests/driver_gd_test.php b/tests/driver_gd_test.php index 45c0382..ee87bc8 100644 --- a/tests/driver_gd_test.php +++ b/tests/driver_gd_test.php @@ -1594,6 +1594,162 @@ class ezcGraphGdDriverTest extends ezcImageTestCase $this->fail( 'Expected ezcGraphFontRenderingException.' ); } + + public function testDrawTextWithBackground() + { + $filename = $this->tempDir . __FUNCTION__ . '.png'; + + $this->driver->options->font->background = ezcGraphColor::fromHex( '#DDDDDD' ); + $this->driver->options->font->minimizeBorder = false; + + $this->driver->drawTextBox( + 'Some test string', + new ezcGraphCoordinate( 10, 10 ), + 150, + 70, + ezcGraph::LEFT | ezcGraph::MIDDLE + ); + + $this->driver->render( $filename ); + + $this->assertTrue( + file_exists( $filename ), + 'No image was generated.' + ); + + $this->assertImageSimilar( + $filename, + $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.png', + 'Image does not look as expected.', + 2000 + ); + } + + public function testDrawTextWithBorder() + { + $filename = $this->tempDir . __FUNCTION__ . '.png'; + + $this->driver->options->font->border = ezcGraphColor::fromHex( '#555555' ); + $this->driver->options->font->minimizeBorder = false; + + $this->driver->drawTextBox( + 'Some test string', + new ezcGraphCoordinate( 10, 10 ), + 150, + 70, + ezcGraph::LEFT | ezcGraph::MIDDLE + ); + + $this->driver->render( $filename ); + + $this->assertTrue( + file_exists( $filename ), + 'No image was generated.' + ); + + $this->assertImageSimilar( + $filename, + $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.png', + 'Image does not look as expected.', + 2000 + ); + } + + public function testDrawTextWithMinimizedBorderAndBackgroundTopLeft() + { + $filename = $this->tempDir . __FUNCTION__ . '.png'; + + $this->driver->options->font->border = ezcGraphColor::fromHex( '#555555' ); + $this->driver->options->font->background = ezcGraphColor::fromHex( '#DDDDDD' ); + $this->driver->options->font->minimizeBorder = true; + $this->driver->options->font->padding = 2; + + $this->driver->drawTextBox( + 'Some test string', + new ezcGraphCoordinate( 10, 10 ), + 150, + 70, + ezcGraph::LEFT | ezcGraph::TOP + ); + + $this->driver->render( $filename ); + + $this->assertTrue( + file_exists( $filename ), + 'No image was generated.' + ); + + $this->assertImageSimilar( + $filename, + $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.png', + 'Image does not look as expected.', + 2000 + ); + } + + public function testDrawTextWithMinimizedBorderAndBackgroundMiddleCenter() + { + $filename = $this->tempDir . __FUNCTION__ . '.png'; + + $this->driver->options->font->border = ezcGraphColor::fromHex( '#555555' ); + $this->driver->options->font->background = ezcGraphColor::fromHex( '#DDDDDD' ); + $this->driver->options->font->minimizeBorder = true; + $this->driver->options->font->padding = 2; + + $this->driver->drawTextBox( + 'Some test string', + new ezcGraphCoordinate( 10, 10 ), + 150, + 70, + ezcGraph::CENTER | ezcGraph::MIDDLE + ); + + $this->driver->render( $filename ); + + $this->assertTrue( + file_exists( $filename ), + 'No image was generated.' + ); + + $this->assertImageSimilar( + $filename, + $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.png', + 'Image does not look as expected.', + 2000 + ); + } + + public function testDrawTextWithMinimizedBorderAndBackgroundBottomRight() + { + $filename = $this->tempDir . __FUNCTION__ . '.png'; + + $this->driver->options->font->border = ezcGraphColor::fromHex( '#555555' ); + $this->driver->options->font->background = ezcGraphColor::fromHex( '#DDDDDD' ); + $this->driver->options->font->minimizeBorder = true; + $this->driver->options->font->padding = 2; + + $this->driver->drawTextBox( + 'Some test string', + new ezcGraphCoordinate( 10, 10 ), + 150, + 70, + ezcGraph::RIGHT | ezcGraph::BOTTOM + ); + + $this->driver->render( $filename ); + + $this->assertTrue( + file_exists( $filename ), + 'No image was generated.' + ); + + $this->assertImageSimilar( + $filename, + $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.png', + 'Image does not look as expected.', + 2000 + ); + } } ?> diff --git a/tests/driver_svg_test.php b/tests/driver_svg_test.php index cd64e49..b23c405 100644 --- a/tests/driver_svg_test.php +++ b/tests/driver_svg_test.php @@ -25,7 +25,7 @@ class ezcGraphSvgDriverTest extends ezcTestCase protected $testFiles = array( 'jpeg' => 'jpeg.jpg', - 'png' => 'png.png', + 'svg' => 'png.png', ); public static function suite() @@ -433,7 +433,7 @@ class ezcGraphSvgDriverTest extends ezcTestCase $filename = $this->tempDir . __FUNCTION__ . '.svg'; $this->driver->drawImage( - $this->basePath . $this->testFiles['png'], + $this->basePath . $this->testFiles['svg'], new ezcGraphCoordinate( 10, 10 ), 100, 50 @@ -949,6 +949,127 @@ class ezcGraphSvgDriverTest extends ezcTestCase $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg' ); } + + public function testDrawTextWithBackground() + { + $filename = $this->tempDir . __FUNCTION__ . '.svg'; + + $this->driver->options->font->background = ezcGraphColor::fromHex( '#DDDDDD' ); + $this->driver->options->font->minimizeBorder = false; + + $this->driver->drawTextBox( + 'Some test string', + new ezcGraphCoordinate( 10, 10 ), + 150, + 70, + ezcGraph::LEFT | ezcGraph::MIDDLE + ); + + $this->driver->render( $filename ); + + $this->compare( + $filename, + $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg' + ); + } + + public function testDrawTextWithBorder() + { + $filename = $this->tempDir . __FUNCTION__ . '.svg'; + + $this->driver->options->font->border = ezcGraphColor::fromHex( '#555555' ); + $this->driver->options->font->minimizeBorder = false; + + $this->driver->drawTextBox( + 'Some test string', + new ezcGraphCoordinate( 10, 10 ), + 150, + 70, + ezcGraph::LEFT | ezcGraph::MIDDLE + ); + + $this->driver->render( $filename ); + + $this->compare( + $filename, + $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg' + ); + } + + public function testDrawTextWithMinimizedBorderAndBackgroundTopLeft() + { + $filename = $this->tempDir . __FUNCTION__ . '.svg'; + + $this->driver->options->font->border = ezcGraphColor::fromHex( '#555555' ); + $this->driver->options->font->background = ezcGraphColor::fromHex( '#DDDDDD' ); + $this->driver->options->font->minimizeBorder = true; + $this->driver->options->font->padding = 2; + + $this->driver->drawTextBox( + 'Some test string', + new ezcGraphCoordinate( 10, 10 ), + 150, + 70, + ezcGraph::LEFT | ezcGraph::TOP + ); + + $this->driver->render( $filename ); + + $this->compare( + $filename, + $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg' + ); + } + + public function testDrawTextWithMinimizedBorderAndBackgroundMiddleCenter() + { + $filename = $this->tempDir . __FUNCTION__ . '.svg'; + + $this->driver->options->font->border = ezcGraphColor::fromHex( '#555555' ); + $this->driver->options->font->background = ezcGraphColor::fromHex( '#DDDDDD' ); + $this->driver->options->font->minimizeBorder = true; + $this->driver->options->font->padding = 2; + + $this->driver->drawTextBox( + 'Some test string', + new ezcGraphCoordinate( 10, 10 ), + 150, + 70, + ezcGraph::CENTER | ezcGraph::MIDDLE + ); + + $this->driver->render( $filename ); + + $this->compare( + $filename, + $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg' + ); + } + + public function testDrawTextWithMinimizedBorderAndBackgroundBottomRight() + { + $filename = $this->tempDir . __FUNCTION__ . '.svg'; + + $this->driver->options->font->border = ezcGraphColor::fromHex( '#555555' ); + $this->driver->options->font->background = ezcGraphColor::fromHex( '#DDDDDD' ); + $this->driver->options->font->minimizeBorder = true; + $this->driver->options->font->padding = 2; + + $this->driver->drawTextBox( + 'Some test string', + new ezcGraphCoordinate( 10, 10 ), + 150, + 70, + ezcGraph::RIGHT | ezcGraph::BOTTOM + ); + + $this->driver->render( $filename ); + + $this->compare( + $filename, + $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg' + ); + } } ?> diff --git a/tests/pie_test.php b/tests/pie_test.php index b7b1c14..c3d5883 100644 --- a/tests/pie_test.php +++ b/tests/pie_test.php @@ -213,8 +213,8 @@ class ezcGraphPieChartTest extends ezcImageTestCase $chart->data['Skien'] = new ezcGraphArrayDataSet( array( 'Norwegian' => 10, 'Dutch' => 3, 'German' => 2, 'French' => 2, 'Hindi' => 1, 'Taiwanese' => 1, 'Brazilian' => 1, 'Venezuelan' => 1, 'Japanese' => 1, 'Czech' => 1, 'Hungarian' => 1, 'Romanian' => 1 ) ); $chart->data['Skien']->highlight['Norwegian'] = true; - $chart->renderer->options->pieVerticalSize = .1; - $chart->renderer->options->pieHorizontalSize = .1; + $chart->renderer->options->pieVerticalSize = .2; + $chart->renderer->options->pieHorizontalSize = .2; $chart->render( 500, 200, $filename ); diff --git a/tests/renderer_2d_test.php b/tests/renderer_2d_test.php index 6e92989..6acc6e2 100644 --- a/tests/renderer_2d_test.php +++ b/tests/renderer_2d_test.php @@ -1859,6 +1859,36 @@ class ezcGraphRenderer2dTest extends ezcTestCase $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg' ); } + + public function testRenderLineChartWithHighlightedData() + { + $filename = $this->tempDir . __FUNCTION__ . '.svg'; + + $chart = new ezcGraphLineChart(); + $chart->palette = new ezcGraphPaletteBlack(); + + $chart->data['Line 1'] = new ezcGraphArrayDataSet( array( 'sample 1' => 234, 'sample 2' => -21, 'sample 3' => 324, 'sample 4' => -120, 'sample 5' => 1) ); + $chart->data['Line 2'] = new ezcGraphArrayDataSet( array( 'sample 1' => 543, 'sample 2' => 234, 'sample 3' => 298, 'sample 4' => 5, 'sample 5' => 613) ); + + $chart->data['Line 1']->highlight = true; + $chart->data['Line 2']->highlight['sample 5'] = true; + + $chart->data['Line 1']->displayType = ezcGraph::BAR; + + $chart->options->highlightSize = 12; + $chart->options->highlightFont->color = ezcGraphColor::fromHex( '#3465A4' ); + $chart->options->highlightFont->background = ezcGraphColor::fromHex( '#D3D7CF' ); + $chart->options->highlightFont->border = ezcGraphColor::fromHex( '#888A85' ); + + $chart->xAxis->axisLabelRenderer = new ezcGraphAxisBoxedLabelRenderer(); + + $chart->render( 500, 200, $filename ); + + $this->compare( + $filename, + $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg' + ); + } } ?> diff --git a/tests/renderer_3d_test.php b/tests/renderer_3d_test.php index a851e03..3204b0c 100644 --- a/tests/renderer_3d_test.php +++ b/tests/renderer_3d_test.php @@ -1079,6 +1079,38 @@ class ezcGraphRenderer3dTest extends ezcImageTestCase $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg' ); } + + public function testRenderLineChartWithHighlightedData() + { + $filename = $this->tempDir . __FUNCTION__ . '.svg'; + + $chart = new ezcGraphLineChart(); + $chart->palette = new ezcGraphPaletteBlack(); + + $chart->data['Line 1'] = new ezcGraphArrayDataSet( array( 'sample 1' => 234, 'sample 2' => -21, 'sample 3' => 324, 'sample 4' => -120, 'sample 5' => 1) ); + $chart->data['Line 2'] = new ezcGraphArrayDataSet( array( 'sample 1' => 543, 'sample 2' => 234, 'sample 3' => 298, 'sample 4' => 5, 'sample 5' => 613) ); + + $chart->data['Line 1']->highlight = true; + $chart->data['Line 2']->highlight['sample 5'] = true; + + $chart->options->highlightSize = 12; + $chart->options->highlightFont->color = ezcGraphColor::fromHex( '#3465A4' ); + $chart->options->highlightFont->background = ezcGraphColor::fromHex( '#D3D7CF' ); + $chart->options->highlightFont->border = ezcGraphColor::fromHex( '#888A85' ); + + $chart->xAxis->axisLabelRenderer = new ezcGraphAxisBoxedLabelRenderer(); + + $chart->renderer = new ezcGraphRenderer3d(); + $chart->renderer->options->barChartGleam = .5; + $chart->renderer->options->legendSymbolGleam = .5; + + $chart->render( 500, 200, $filename ); + + $this->compare( + $filename, + $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg' + ); + } } ?> -- cgit v1.1