diff options
author | JulienMoumne <julien@piwik.org> | 2012-02-09 21:23:39 +0400 |
---|---|---|
committer | JulienMoumne <julien@piwik.org> | 2012-02-09 21:23:39 +0400 |
commit | 586387a008c90c517ea95831a3dd36ab5e1c5079 (patch) | |
tree | 0ee15c82a58a575905406a8940349251fceb78e6 /core | |
parent | a240a5c808de82187c987a2f4c73bbc2f22aadcd (diff) |
refs #2862 distinct static graph resolutions for portrait and landscape
git-svn-id: http://dev.piwik.org/svn/trunk@5792 59fd770c-687e-43c8-a1e3-f5a4ff64c105
Diffstat (limited to 'core')
-rw-r--r-- | core/ReportRenderer.php | 38 | ||||
-rw-r--r-- | core/ReportRenderer/Html.php | 23 | ||||
-rw-r--r-- | core/ReportRenderer/Pdf.php | 47 |
3 files changed, 62 insertions, 46 deletions
diff --git a/core/ReportRenderer.php b/core/ReportRenderer.php index 642161d786..87300cf685 100644 --- a/core/ReportRenderer.php +++ b/core/ReportRenderer.php @@ -116,16 +116,6 @@ abstract class Piwik_ReportRenderer abstract public function renderReport($processedReport); /** - * @param int height of the static graph drawn by the report renderer - */ - abstract public function getStaticGraphHeight(); - - /** - * @param int width of the static graph drawn by the report renderer - */ - abstract public function getStaticGraphWidth(); - - /** * Append $extension to $filename * * @static @@ -192,4 +182,32 @@ abstract class Piwik_ReportRenderer $reportColumns, ); } + + public static function getStaticGraph($imageGraphUrl, $width, $height) { + + $request = new Piwik_API_Request( + $imageGraphUrl . + '&outputType='.Piwik_ImageGraph_API::GRAPH_OUTPUT_PHP. + '&format=original&serialize=0'. + '&filter_truncate='. + '&width='.$width. + '&height='.$height + ); + + try { + $imageGraph = $request->process(); + + // Get image data as string + ob_start(); + imagepng($imageGraph); + $imageGraphData = ob_get_contents(); + ob_end_clean(); + imagedestroy($imageGraph); + + return $imageGraphData; + + } catch(Exception $e) { + throw new Exception("ImageGraph API returned an error: ".$e->getMessage()."\n"); + } + } } diff --git a/core/ReportRenderer/Html.php b/core/ReportRenderer/Html.php index d1666843ca..a3dec2d036 100644 --- a/core/ReportRenderer/Html.php +++ b/core/ReportRenderer/Html.php @@ -17,8 +17,8 @@ */ class Piwik_ReportRenderer_Html extends Piwik_ReportRenderer { - const IMAGE_GRAPH_HEIGHT = 200; const IMAGE_GRAPH_WIDTH = 700; + const IMAGE_GRAPH_HEIGHT = 200; const REPORT_TITLE_TEXT_SIZE = 11; const REPORT_TABLE_HEADER_TEXT_SIZE = 11; @@ -27,16 +27,6 @@ class Piwik_ReportRenderer_Html extends Piwik_ReportRenderer private $rendering = ""; - public function getStaticGraphHeight() - { - return self::IMAGE_GRAPH_HEIGHT; - } - - public function getStaticGraphWidth() - { - return self::IMAGE_GRAPH_WIDTH; - } - public function setLocale($locale) { //Nothing to do @@ -132,14 +122,15 @@ class Piwik_ReportRenderer_Html extends Piwik_ReportRenderer if($displayGraph) { - $smarty->assign("graphHeight", $this->getStaticGraphHeight()); - $smarty->assign("graphWidth", $this->getStaticGraphWidth()); + $smarty->assign("graphWidth", self::IMAGE_GRAPH_WIDTH); + $smarty->assign("graphHeight", self::IMAGE_GRAPH_HEIGHT); $smarty->assign("renderImageInline", $this->renderImageInline); if($this->renderImageInline) { - $generatedImageGraph = $processedReport['generatedImageGraph']; - $smarty->assign("generatedImageGraph", base64_encode($generatedImageGraph)); + $imageGraphUrl = $reportMetadata['imageGraphUrl']; + $staticGraph = parent::getStaticGraph($imageGraphUrl, self::IMAGE_GRAPH_WIDTH, self::IMAGE_GRAPH_HEIGHT); + $smarty->assign("generatedImageGraph", base64_encode($staticGraph)); unset($generatedImageGraph); } } @@ -151,4 +142,4 @@ class Piwik_ReportRenderer_Html extends Piwik_ReportRenderer { return PIWIK_USER_PATH . "/plugins/CoreHome/templates/" . $templateFile; } -} +}
\ No newline at end of file diff --git a/core/ReportRenderer/Pdf.php b/core/ReportRenderer/Pdf.php index a5d247a4ba..3d0510b651 100644 --- a/core/ReportRenderer/Pdf.php +++ b/core/ReportRenderer/Pdf.php @@ -23,8 +23,13 @@ require_once PIWIK_INCLUDE_PATH . '/core/TCPDF.php'; */ class Piwik_ReportRenderer_Pdf extends Piwik_ReportRenderer { - const IMAGE_GRAPH_HEIGHT = 330; - const IMAGE_GRAPH_WIDTH = 1150; + const IMAGE_GRAPH_WIDTH_LANDSCAPE = 1150; + const IMAGE_GRAPH_HEIGHT_LANDSCAPE = 330; + const IMAGE_GRAPH_WIDTH_PORTRAIT = 760; + const IMAGE_GRAPH_HEIGHT_PORTRAIT = 220; + + const LANDSCAPE = 'L'; + const PORTRAIT = 'P'; const MAX_ROW_COUNT = 28; const TABLE_HEADER_ROW_COUNT = 6; @@ -65,7 +70,7 @@ class Piwik_ReportRenderer_Pdf extends Piwik_ReportRenderer private $currentPage = 0; private $reportFont = Piwik_ReportRenderer::DEFAULT_REPORT_FONT; private $TCPDF; - private $orientation = 'P'; + private $orientation = self::PORTRAIT; public function __construct() { @@ -78,16 +83,6 @@ class Piwik_ReportRenderer_Pdf extends Piwik_ReportRenderer $this->tableBackgroundColor = preg_split("/,/", Piwik_ReportRenderer::TABLE_BG_COLOR); } - public function getStaticGraphHeight() - { - return self::IMAGE_GRAPH_HEIGHT; - } - - public function getStaticGraphWidth() - { - return self::IMAGE_GRAPH_WIDTH; - } - public function setLocale($locale) { switch ($locale) @@ -144,7 +139,7 @@ class Piwik_ReportRenderer_Pdf extends Piwik_ReportRenderer $this->TCPDF->setPrintHeader(false); // $this->SetMargins($left = , $top, $right=-1, $keepmargins=true) - $this->TCPDF->AddPage('P'); + $this->TCPDF->AddPage(self::PORTRAIT); $this->TCPDF->AddFont($this->reportFont, '', '', false); $this->TCPDF->SetFont($this->reportFont, $this->reportFontStyle, $this->reportSimpleFontSize); //Image($file, $x='', $y='', $w=0, $h=0, $type='', $link='', $align='', $resize=false, $dpi=300, $palign='', $ismask=false, $imgmask=false, $border=0, $fitbox=false, $hidden=false, $fitonpage=false) { @@ -223,12 +218,12 @@ class Piwik_ReportRenderer_Pdf extends Piwik_ReportRenderer if ($tableOnlyManyColumnReport) { $tableOnlyManyColumnReportRowCount = 0; - $this->orientation = 'L'; + $this->orientation = self::LANDSCAPE; } else { // Graph-only reports are always portrait - $this->orientation = $graphOnlyReport ? 'P' : ($columnCount > $this->maxColumnCountPortraitOrientation ? 'L' : 'P'); + $this->orientation = $graphOnlyReport ? self::PORTRAIT : ($columnCount > $this->maxColumnCountPortraitOrientation ? self::LANDSCAPE : self::PORTRAIT); } $this->TCPDF->setPageOrientation($this->orientation, '', $this->bottomMargin); @@ -275,7 +270,7 @@ class Piwik_ReportRenderer_Pdf extends Piwik_ReportRenderer if($this->displayGraph) { - $this->paintGraph($processedReport['generatedImageGraph']); + $this->paintGraph(); } if($this->displayGraph && $this->displayTable) @@ -383,8 +378,20 @@ class Piwik_ReportRenderer_Pdf extends Piwik_ReportRenderer $fill = !$fill; } } - private function paintGraph($imageGraph) + private function paintGraph() { + + if($this->orientation == self::PORTRAIT) { + $imageWidth = self::IMAGE_GRAPH_WIDTH_PORTRAIT; + $imageHeight = self::IMAGE_GRAPH_HEIGHT_PORTRAIT; + } else { + $imageWidth = self::IMAGE_GRAPH_WIDTH_LANDSCAPE; + $imageHeight = self::IMAGE_GRAPH_HEIGHT_LANDSCAPE; + } + + $imageGraphUrl = $this->reportMetadata['imageGraphUrl']; + $imageGraph = parent::getStaticGraph($imageGraphUrl, $imageWidth, $imageHeight); + $this->TCPDF->Image( '@'.$imageGraph, $x = '', @@ -428,11 +435,11 @@ class Piwik_ReportRenderer_Pdf extends Piwik_ReportRenderer $columnsCount = count($this->reportColumns); // Computes available column width - if ($this->orientation == 'P' + if ($this->orientation == self::PORTRAIT && $columnsCount <= 3) { $totalWidth = $this->reportWidthPortrait * 2 / 3; } - else if ($this->orientation == 'L') { + else if ($this->orientation == self::LANDSCAPE) { $totalWidth = $this->reportWidthLandscape; } else |