diff --git a/plugins/ImageGraph/StaticGraph.php b/plugins/ImageGraph/StaticGraph.php index c9dfaee5d54..06f58854b81 100644 --- a/plugins/ImageGraph/StaticGraph.php +++ b/plugins/ImageGraph/StaticGraph.php @@ -248,7 +248,12 @@ protected function initpData() } } - $this->pData->setAxisDisplay(0, AXIS_FORMAT_CUSTOM, '\\Piwik\\Plugins\\ImageGraph\\formatYAxis'); + // Use a different formating method if not using unifont + $formatMethodName = 'formatYAxis'; + if (strpos($this->font, 'unifont') === false) { + $formatMethodName = 'formatYAxisNonUnifont'; + } + $this->pData->setAxisDisplay(0, AXIS_FORMAT_CUSTOM, '\\Piwik\\Plugins\\ImageGraph\\' . $formatMethodName); $this->pData->addPoints($this->abscissaSeries, self::ABSCISSA_SERIE_NAME); $this->pData->setAbscissa(self::ABSCISSA_SERIE_NAME); @@ -376,7 +381,7 @@ private static function hex2rgb($hexColor) } /** - * Global format method + * Global format method - unifont * * required to format y axis values using CpChart internal format callbacks * @param $value @@ -386,3 +391,16 @@ function formatYAxis($value) { return NumberFormatter::getInstance()->format($value); } + +/** + * Global format method - non-unifont + * + * required to format y axis values using CpChart internal format callbacks + * @param $value + * @return mixed + */ +function formatYAxisNonUnifont($value) +{ + // Replace any narrow non-breaking spaces with non-breaking spaces as some fonts may not support it + return str_replace("\xE2\x80\xAF", "\xC2\xA0", NumberFormatter::getInstance()->format($value)); +} diff --git a/plugins/ImageGraph/StaticGraph/GridGraph.php b/plugins/ImageGraph/StaticGraph/GridGraph.php index dfc90f41082..e7c6e691273 100644 --- a/plugins/ImageGraph/StaticGraph/GridGraph.php +++ b/plugins/ImageGraph/StaticGraph/GridGraph.php @@ -22,10 +22,10 @@ abstract class GridGraph extends StaticGraph const DEFAULT_TICK_ALPHA = 20; const DEFAULT_SERIE_WEIGHT = 0.5; - const LEFT_GRID_MARGIN = 4; + const LEFT_GRID_MARGIN = 20; const BOTTOM_GRID_MARGIN = 10; - const TOP_GRID_MARGIN_HORIZONTAL_GRAPH = 1; - const RIGHT_GRID_MARGIN_HORIZONTAL_GRAPH = 4; + const TOP_GRID_MARGIN_HORIZONTAL_GRAPH = 10; + const RIGHT_GRID_MARGIN_HORIZONTAL_GRAPH = 20; const OUTER_TICK_WIDTH = 5; const INNER_TICK_WIDTH = 0; const LABEL_SPACE_VERTICAL_GRAPH = 7; @@ -33,7 +33,7 @@ abstract class GridGraph extends StaticGraph const HORIZONTAL_LEGEND_TOP_MARGIN = 5; const HORIZONTAL_LEGEND_LEFT_MARGIN = 10; const HORIZONTAL_LEGEND_BOTTOM_MARGIN = 10; - const VERTICAL_LEGEND_TOP_MARGIN = 8; + const VERTICAL_LEGEND_TOP_MARGIN = 10; const VERTICAL_LEGEND_LEFT_MARGIN = 6; const VERTICAL_LEGEND_MAX_WIDTH_PCT = 0.70; const LEGEND_LINE_BULLET_WIDTH = 14; @@ -358,7 +358,7 @@ protected function getGridTopMargin($horizontalGraph, $verticalLegend) if ($horizontalGraph) { $topMargin = $ordinateMaxHeight + self::TOP_GRID_MARGIN_HORIZONTAL_GRAPH + self::OUTER_TICK_WIDTH; } else { - $topMargin = $ordinateMaxHeight / 2; + $topMargin = $ordinateMaxHeight / 2 + self::TOP_GRID_MARGIN_HORIZONTAL_GRAPH; } if ($this->showLegend && !$verticalLegend) { @@ -398,7 +398,7 @@ protected function getGridRightMargin($horizontalGraph) list($ordinateMaxWidth, $ordinateMaxHeight) = $this->getMaximumTextWidthHeight($this->ordinateSeries); return self::RIGHT_GRID_MARGIN_HORIZONTAL_GRAPH + $ordinateMaxWidth; } else { - return 0; + return self::RIGHT_GRID_MARGIN_HORIZONTAL_GRAPH; } } diff --git a/plugins/ImageGraph/tests/UI/ImageGraph_spec.js b/plugins/ImageGraph/tests/UI/ImageGraph_spec.js index c7fb5bb4023..1f039c0e058 100644 --- a/plugins/ImageGraph/tests/UI/ImageGraph_spec.js +++ b/plugins/ImageGraph/tests/UI/ImageGraph_spec.js @@ -10,6 +10,11 @@ describe("ImageGraph", function () { this.timeout(0); + before(function () { + testEnvironment.multiplicateTableResults = 169856; + testEnvironment.save(); + }); + function getImageGraphUrl(apiModule, apiAction, graphType, period, date) { return "index.php?module=API&method=ImageGraph.get&idSite=1&width=500&height=250&apiModule=" + apiModule + "&apiAction=" + apiAction + "&graphType=" + graphType + "&period=" + period + "&date=" + date; @@ -38,4 +43,4 @@ describe("ImageGraph", function () { expect(await page.screenshot({ fullPage: true })).to.matchImage('pie'); }); -}); \ No newline at end of file +}); diff --git a/plugins/ImageGraph/tests/UI/expected-screenshots/ImageGraph_evolution_graph.png b/plugins/ImageGraph/tests/UI/expected-screenshots/ImageGraph_evolution_graph.png index 10c4541eca9..d3e3f81c234 100644 --- a/plugins/ImageGraph/tests/UI/expected-screenshots/ImageGraph_evolution_graph.png +++ b/plugins/ImageGraph/tests/UI/expected-screenshots/ImageGraph_evolution_graph.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f81b1118d44f7adecc784b54f4b22060403f9acb83c2a2616214ae01d5120d3b -size 12980 +oid sha256:106ef366a106fa05c46aaddc5b0c1f2b966b6d2fb3666a26e5fb6cbe6e92b091 +size 13371 diff --git a/plugins/ImageGraph/tests/UI/expected-screenshots/ImageGraph_horizontal_bar.png b/plugins/ImageGraph/tests/UI/expected-screenshots/ImageGraph_horizontal_bar.png index 4939c65cfb1..4a2bd505326 100644 --- a/plugins/ImageGraph/tests/UI/expected-screenshots/ImageGraph_horizontal_bar.png +++ b/plugins/ImageGraph/tests/UI/expected-screenshots/ImageGraph_horizontal_bar.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:15e259bc5d40c8c0f5e8fca3cbda446d44b898183b81e292bc23fdd4420ff646 -size 16027 +oid sha256:8901f6690c21dbd009318875613b92e1d503cdf0baaf979b4940b42473894619 +size 17354 diff --git a/plugins/ImageGraph/tests/UI/expected-screenshots/ImageGraph_vertical_bar.png b/plugins/ImageGraph/tests/UI/expected-screenshots/ImageGraph_vertical_bar.png index fff451c2e11..1d5c2715810 100644 --- a/plugins/ImageGraph/tests/UI/expected-screenshots/ImageGraph_vertical_bar.png +++ b/plugins/ImageGraph/tests/UI/expected-screenshots/ImageGraph_vertical_bar.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ca29b9fe3d652b6bce68d4a0393e72b90964a74e99cfc09732c7997b0aebdb21 -size 7474 +oid sha256:ef94dc9390a72543f2f1effa33c1d8a0a10fe8608372915053f7f96e904aac74 +size 7727 diff --git a/tests/PHPUnit/Framework/TestingEnvironmentManipulator.php b/tests/PHPUnit/Framework/TestingEnvironmentManipulator.php index ef90a94c88d..a78d9d8b224 100644 --- a/tests/PHPUnit/Framework/TestingEnvironmentManipulator.php +++ b/tests/PHPUnit/Framework/TestingEnvironmentManipulator.php @@ -13,6 +13,8 @@ use Piwik\Application\Kernel\GlobalSettingsProvider; use Piwik\Application\Kernel\PluginList; use Piwik\Config; +use Piwik\DataTable; +use Piwik\DataTable\DataTableInterface; use Piwik\DbHelper; use Piwik\Option; use Piwik\Plugin; @@ -203,6 +205,28 @@ public function getExtraDefinitions() }), ); + if (!empty($this->vars->multiplicateTableResults)) { + $diConfigs[] = [ + 'observers.global' => \Piwik\DI::add([ + ['API.Request.dispatch.end', \Piwik\DI::value(function($returnedValue) { + if ($returnedValue instanceof DataTableInterface) { + $returnedValue->filter(function(DataTable $dataTable) { + foreach ($dataTable->getRows() as $row) { + $columns = $row->getColumns(); + foreach($columns as $name => &$value) { + if ($name !== 'label' && is_numeric($value)) { + $value *= $this->vars->multiplicateTableResults; + } + } + $row->setColumns($columns); + } + }); + } + }) + ]]) + ]; + } + return $diConfigs; }