diff options
author | Kore Nordmann <github@kore-nordmann.de> | 2006-11-30 11:11:42 +0000 |
---|---|---|
committer | Kore Nordmann <github@kore-nordmann.de> | 2006-11-30 11:11:42 +0000 |
commit | f7ffcb314f4cbb09e3ae16653a944f11201dd1d1 (patch) | |
tree | ef5c140bb6448c1a595fc8b79c0fbc4812eab49b | |
parent | 52e8f6cd727f0fd0bbd735d2c72fe7cffff8f565 (diff) | |
download | zetacomponents-graph-f7ffcb314f4cbb09e3ae16653a944f11201dd1d1.zip zetacomponents-graph-f7ffcb314f4cbb09e3ae16653a944f11201dd1d1.tar.gz |
- Implemented #9647 (Add render to output method)
-rw-r--r-- | ChangeLog | 1 | ||||
-rw-r--r-- | src/driver/flash.php | 10 | ||||
-rw-r--r-- | src/driver/gd.php | 31 | ||||
-rw-r--r-- | src/driver/svg.php | 10 | ||||
-rw-r--r-- | src/driver/verbose.php | 10 | ||||
-rw-r--r-- | src/interfaces/driver.php | 22 | ||||
-rw-r--r-- | tests/data/compare/ezcGraphFlashDriverTest_testRenderToOutput.swf | bin | 0 -> 80 bytes | |||
-rw-r--r-- | tests/data/compare/ezcGraphGdDriverTest_testRenderJpegToOutput.jpeg | bin | 0 -> 1563 bytes | |||
-rw-r--r-- | tests/data/compare/ezcGraphGdDriverTest_testRenderPngToOutput.png | bin | 0 -> 504 bytes | |||
-rw-r--r-- | tests/data/compare/ezcGraphSvgDriverTest_testRenderToOutput.svg | 2 | ||||
-rw-r--r-- | tests/driver_flash_test.php | 27 | ||||
-rw-r--r-- | tests/driver_gd_test.php | 59 | ||||
-rw-r--r-- | tests/driver_svg_test.php | 27 |
13 files changed, 199 insertions, 0 deletions
@@ -5,6 +5,7 @@ - Renamed pie chart options percentTreshHold to percentThreshold and absoluteTreshHold to absoluteThreshold +- Added feature #9647: Add render to output method - Fixed issue #9612: Element links for SVG image in the legend require you to click on exactly the text. - Fixed issue #9586: No data rendered with string keys on date axis. diff --git a/src/driver/flash.php b/src/driver/flash.php index 51f55fb..2b9380e 100644 --- a/src/driver/flash.php +++ b/src/driver/flash.php @@ -813,6 +813,16 @@ class ezcGraphFlashDriver extends ezcGraphDriver } /** + * Return mime type for current image format + * + * @return string + */ + public function getMimeType() + { + return 'application/x-shockwave-flash'; + } + + /** * Finally save image * * @param string $file Destination filename diff --git a/src/driver/gd.php b/src/driver/gd.php index ba92bcd..0ef190d 100644 --- a/src/driver/gd.php +++ b/src/driver/gd.php @@ -981,6 +981,37 @@ class ezcGraphGdDriver extends ezcGraphDriver } /** + * Return mime type for current image format + * + * @return string + */ + public function getMimeType() + { + switch ( $this->options->imageFormat ) + { + case IMG_PNG: + return 'image/png'; + case IMG_JPEG: + return 'image/jpeg'; + } + } + + /** + * Render image directly to output + * + * The method renders the image directly to the standard output. You + * normally do not want to use this function, because it makes it harder + * to proper cache the generated graphs. + * + * @return void + */ + public function renderToOutput() + { + header( 'Content-Type: ' . $this->getMimeType() ); + $this->render( null ); + } + + /** * Finally save image * * @param string $file Destination filename diff --git a/src/driver/svg.php b/src/driver/svg.php index 4965a51..dd14912 100644 --- a/src/driver/svg.php +++ b/src/driver/svg.php @@ -982,6 +982,16 @@ class ezcGraphSvgDriver extends ezcGraphDriver } /** + * Return mime type for current image format + * + * @return string + */ + public function getMimeType() + { + return 'image/svg+xml'; + } + + /** * Finally save image * * @param string $file Destination filename diff --git a/src/driver/verbose.php b/src/driver/verbose.php index 82716e8..8f5a5ce 100644 --- a/src/driver/verbose.php +++ b/src/driver/verbose.php @@ -186,6 +186,16 @@ class ezcGraphVerboseDriver extends ezcGraphDriver } /** + * Return mime type for current image format + * + * @return string + */ + public function getMimeType() + { + return 'text/plain'; + } + + /** * Finally save image * * @param mixed $file diff --git a/src/interfaces/driver.php b/src/interfaces/driver.php index b646d0c..bb4773b 100644 --- a/src/interfaces/driver.php +++ b/src/interfaces/driver.php @@ -252,6 +252,28 @@ abstract class ezcGraphDriver abstract public function drawImage( $file, ezcGraphCoordinate $position, $width, $height ); /** + * Return mime type for current image format + * + * @return string + */ + abstract public function getMimeType(); + + /** + * Render image directly to output + * + * The method renders the image directly to the standard output. You + * normally do not want to use this function, because it makes it harder + * to proper cache the generated graphs. + * + * @return void + */ + public function renderToOutput() + { + header( 'Content-Type: ' . $this->getMimeType() ); + $this->render( 'php://output' ); + } + + /** * Finally save image * * @param string $file Destination filename diff --git a/tests/data/compare/ezcGraphFlashDriverTest_testRenderToOutput.swf b/tests/data/compare/ezcGraphFlashDriverTest_testRenderToOutput.swf Binary files differnew file mode 100644 index 0000000..e9cc0be --- /dev/null +++ b/tests/data/compare/ezcGraphFlashDriverTest_testRenderToOutput.swf diff --git a/tests/data/compare/ezcGraphGdDriverTest_testRenderJpegToOutput.jpeg b/tests/data/compare/ezcGraphGdDriverTest_testRenderJpegToOutput.jpeg Binary files differnew file mode 100644 index 0000000..3b1cbc1 --- /dev/null +++ b/tests/data/compare/ezcGraphGdDriverTest_testRenderJpegToOutput.jpeg diff --git a/tests/data/compare/ezcGraphGdDriverTest_testRenderPngToOutput.png b/tests/data/compare/ezcGraphGdDriverTest_testRenderPngToOutput.png Binary files differnew file mode 100644 index 0000000..efb27b8 --- /dev/null +++ b/tests/data/compare/ezcGraphGdDriverTest_testRenderPngToOutput.png diff --git a/tests/data/compare/ezcGraphSvgDriverTest_testRenderToOutput.svg b/tests/data/compare/ezcGraphSvgDriverTest_testRenderToOutput.svg new file mode 100644 index 0000000..e543df0 --- /dev/null +++ b/tests/data/compare/ezcGraphSvgDriverTest_testRenderToOutput.svg @@ -0,0 +1,2 @@ +<?xml version="1.0"?> +<svg xmlns="http://www.w3.org/2000/svg" width="200" height="100" version="1.0" id="ezcGraph"><defs/><g id="ezcGraphChart" color-rendering="optimizeQuality" shape-rendering="geometricPrecision" text-rendering="optimizeLegibility"><path d=" M 12.0000,45.0000 L 134.0000,12.0000" style="fill: none; stroke: #3465a4; stroke-width: 1; stroke-opacity: 1.00; stroke-linecap: round; stroke-linejoin: round;" id="ezcGraphLine_1"/></g></svg> diff --git a/tests/driver_flash_test.php b/tests/driver_flash_test.php index 6047391..8045612 100644 --- a/tests/driver_flash_test.php +++ b/tests/driver_flash_test.php @@ -1472,5 +1472,32 @@ class ezcGraphFlashDriverTest extends ezcTestCase $this->fail( 'Expected ezcBaseValueException.' ); } + + public function testRenderToOutput() + { + $filename = $this->tempDir . __FUNCTION__ . '.swf'; + + $this->driver->drawLine( + new ezcGraphCoordinate( 12, 45 ), + new ezcGraphCoordinate( 134, 12 ), + ezcGraphColor::fromHex( '#3465A4' ) + ); + + $this->assertEquals( + $this->driver->getMimeType(), + 'application/x-shockwave-flash', + 'Wrong mime type returned.' + ); + + ob_start(); + // Suppress header already sent warning + @$this->driver->renderToOutput(); + file_put_contents( $filename, ob_get_clean() ); + + $this->compare( + $filename, + $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.swf' + ); + } } ?> diff --git a/tests/driver_gd_test.php b/tests/driver_gd_test.php index 2a4bc59..3bc0d97 100644 --- a/tests/driver_gd_test.php +++ b/tests/driver_gd_test.php @@ -62,6 +62,65 @@ class ezcGraphGdDriverTest extends ezcImageTestCase } } + public function testRenderPngToOutput() + { + $filename = $this->tempDir . __FUNCTION__ . '.png'; + + $this->driver->options->imageFormat = IMG_PNG; + $this->driver->drawLine( + new ezcGraphCoordinate( 12, 45 ), + new ezcGraphCoordinate( 134, 12 ), + ezcGraphColor::fromHex( '#3465A4' ) + ); + + $this->assertEquals( + $this->driver->getMimeType(), + 'image/png', + 'Wrong mime type returned.' + ); + + ob_start(); + // Suppress header already sent warning + @$this->driver->renderToOutput(); + file_put_contents( $filename, ob_get_clean() ); + + $this->assertImageSimilar( + $filename, + $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.png', + 'Image does not look as expected.', + 2000 + ); + } + + public function testRenderJpegToOutput() { + $filename = $this->tempDir . __FUNCTION__ . '.jpeg'; + + $this->driver->options->imageFormat = IMG_JPEG; + $this->driver->drawLine( + new ezcGraphCoordinate( 12, 45 ), + new ezcGraphCoordinate( 134, 12 ), + ezcGraphColor::fromHex( '#3465A4' ) + ); + + $this->assertEquals( + $this->driver->getMimeType(), + 'image/jpeg', + 'Wrong mime type returned.' + ); + + ob_start(); + // Suppress header already sent warning + @$this->driver->renderToOutput(); + file_put_contents( $filename, ob_get_clean() ); + + $this->assertImageSimilar( + $filename, + $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.jpeg', + 'Image does not look as expected.', + 2000 + ); + } + public function testDrawLine() { $filename = $this->tempDir . __FUNCTION__ . '.png'; diff --git a/tests/driver_svg_test.php b/tests/driver_svg_test.php index eeb8dcd..88da61d 100644 --- a/tests/driver_svg_test.php +++ b/tests/driver_svg_test.php @@ -81,6 +81,33 @@ class ezcGraphSvgDriverTest extends ezcTestCase } } + public function testRenderToOutput() + { + $filename = $this->tempDir . __FUNCTION__ . '.svg'; + + $this->driver->drawLine( + new ezcGraphCoordinate( 12, 45 ), + new ezcGraphCoordinate( 134, 12 ), + ezcGraphColor::fromHex( '#3465A4' ) + ); + + $this->assertEquals( + $this->driver->getMimeType(), + 'image/svg+xml', + 'Wrong mime type returned.' + ); + + ob_start(); + // Suppress header already sent warning + @$this->driver->renderToOutput(); + file_put_contents( $filename, ob_get_clean() ); + + $this->compare( + $filename, + $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg' + ); + } + public function testDrawLine() { $filename = $this->tempDir . __FUNCTION__ . '.svg'; |