From 809c6ea4e17eb88259df92d7c9ad7fcb3dce89dd Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 30 Jun 2023 15:34:45 +1200 Subject: [PATCH 1/6] Use unifont for French if available, remove NNBSP if unifont not available, tweak graph margins --- plugins/ImageGraph/StaticGraph.php | 21 ++++++++++++++++++-- plugins/ImageGraph/StaticGraph/GridGraph.php | 12 +++++------ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/plugins/ImageGraph/StaticGraph.php b/plugins/ImageGraph/StaticGraph.php index c9dfaee5d54..7b1c0351a7d 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,15 @@ 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) +{ + return str_replace("\xE2\x80\xAF", " ", 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; } } From 57560fa03eb0b84dc2f7c7955f8a97d789c15f1d Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 30 Jun 2023 16:32:35 +1200 Subject: [PATCH 2/6] Updated UI test screenshots --- .../UI/expected-screenshots/ImageGraph_evolution_graph.png | 4 ++-- .../UI/expected-screenshots/ImageGraph_horizontal_bar.png | 4 ++-- .../tests/UI/expected-screenshots/ImageGraph_vertical_bar.png | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) 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..3520ed9d520 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:89d4d8d484c9c14f802dca4f3f3dc3421d245fd9b982cb41a6b8977d50a96f77 +size 12568 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..18312609102 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:dfdd3e31d772e3cf624519dde4ac4d7088bd5371d78e5de3ff3bfd6fa2442668 +size 16015 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..560d1d06aa3 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:6d30798aaacd2e3856b5601525f7ff1cbfdc76f98b583f59e8bb3bac7c9cc287 +size 7554 From 9f333e1688f5f456dfb91d7e8497da04cff2107a Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 30 Jun 2023 16:51:36 +1200 Subject: [PATCH 3/6] Replace with NBSP instead of normal space, add FR to list of unifont languages --- plugins/ImageGraph/API.php | 2 +- plugins/ImageGraph/StaticGraph.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/ImageGraph/API.php b/plugins/ImageGraph/API.php index 754952b2611..df921bb94f0 100644 --- a/plugins/ImageGraph/API.php +++ b/plugins/ImageGraph/API.php @@ -139,7 +139,7 @@ public function get( } $useUnicodeFont = array( - 'am', 'ar', 'el', 'fa', 'fi', 'he', 'ja', 'ka', 'ko', 'te', 'th', 'zh-cn', 'zh-tw', + 'am', 'ar', 'el', 'fa', 'fi', 'fr', 'he', 'ja', 'ka', 'ko', 'te', 'th', 'zh-cn', 'zh-tw', ); $languageLoaded = StaticContainer::get('Piwik\Translation\Translator')->getCurrentLanguage(); $font = self::getFontPath(self::DEFAULT_FONT); diff --git a/plugins/ImageGraph/StaticGraph.php b/plugins/ImageGraph/StaticGraph.php index 7b1c0351a7d..06f58854b81 100644 --- a/plugins/ImageGraph/StaticGraph.php +++ b/plugins/ImageGraph/StaticGraph.php @@ -401,5 +401,6 @@ function formatYAxis($value) */ function formatYAxisNonUnifont($value) { - return str_replace("\xE2\x80\xAF", " ", NumberFormatter::getInstance()->format($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)); } From 3c3db7faa79b34139e0623104fd23a09afc78ccc Mon Sep 17 00:00:00 2001 From: Ben Date: Thu, 6 Jul 2023 14:07:19 +1200 Subject: [PATCH 4/6] Do not use unicode font for French --- plugins/ImageGraph/API.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/ImageGraph/API.php b/plugins/ImageGraph/API.php index df921bb94f0..754952b2611 100644 --- a/plugins/ImageGraph/API.php +++ b/plugins/ImageGraph/API.php @@ -139,7 +139,7 @@ public function get( } $useUnicodeFont = array( - 'am', 'ar', 'el', 'fa', 'fi', 'fr', 'he', 'ja', 'ka', 'ko', 'te', 'th', 'zh-cn', 'zh-tw', + 'am', 'ar', 'el', 'fa', 'fi', 'he', 'ja', 'ka', 'ko', 'te', 'th', 'zh-cn', 'zh-tw', ); $languageLoaded = StaticContainer::get('Piwik\Translation\Translator')->getCurrentLanguage(); $font = self::getFontPath(self::DEFAULT_FONT); From 817edc5a94f50d55bb4138af20c04d0b72a1b23f Mon Sep 17 00:00:00 2001 From: sgiehl Date: Fri, 7 Jul 2023 14:16:53 +0200 Subject: [PATCH 5/6] use higher values for image graphs --- .../ImageGraph/tests/UI/ImageGraph_spec.js | 7 +++++- .../TestingEnvironmentManipulator.php | 24 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) 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/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; } From 27c1d7952fc943a1cfedd550191871abaa51b194 Mon Sep 17 00:00:00 2001 From: sgiehl Date: Fri, 7 Jul 2023 14:51:41 +0200 Subject: [PATCH 6/6] updates expected UI test files --- .../UI/expected-screenshots/ImageGraph_evolution_graph.png | 4 ++-- .../UI/expected-screenshots/ImageGraph_horizontal_bar.png | 4 ++-- .../tests/UI/expected-screenshots/ImageGraph_vertical_bar.png | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) 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 3520ed9d520..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:89d4d8d484c9c14f802dca4f3f3dc3421d245fd9b982cb41a6b8977d50a96f77 -size 12568 +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 18312609102..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:dfdd3e31d772e3cf624519dde4ac4d7088bd5371d78e5de3ff3bfd6fa2442668 -size 16015 +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 560d1d06aa3..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:6d30798aaacd2e3856b5601525f7ff1cbfdc76f98b583f59e8bb3bac7c9cc287 -size 7554 +oid sha256:ef94dc9390a72543f2f1effa33c1d8a0a10fe8608372915053f7f96e904aac74 +size 7727