diff options
author | Stefan Giehl <stefan@matomo.org> | 2022-03-08 11:52:10 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-08 11:52:10 +0300 |
commit | a6a7cf70af86bda997b1faae1573e78db4e818a8 (patch) | |
tree | 609409b8d87f67d84855c9707a026d0debf201eb /plugins/CoreVisualizations | |
parent | 4c04cd1ed3deb8228fcc9ff503ce013506f8d807 (diff) |
Fix comparison trends might be displayed incorrect for certain languages (#18832)
* Fix comparison trends might be displayed incorrect for certain languages
* update tests
* include trend values only when requested
* updates expected tests files
* add some code comments
* Adds ui tests for comparison sparklines in other language
* init sparklines after document fully loaded
Co-authored-by: diosmosis <diosmosis@users.noreply.github.com>
Diffstat (limited to 'plugins/CoreVisualizations')
-rw-r--r-- | plugins/CoreVisualizations/Visualizations/Sparklines.php | 16 | ||||
-rw-r--r-- | plugins/CoreVisualizations/templates/macros.twig | 6 |
2 files changed, 16 insertions, 6 deletions
diff --git a/plugins/CoreVisualizations/Visualizations/Sparklines.php b/plugins/CoreVisualizations/Visualizations/Sparklines.php index ad9373f329..4a2b4a69ee 100644 --- a/plugins/CoreVisualizations/Visualizations/Sparklines.php +++ b/plugins/CoreVisualizations/Visualizations/Sparklines.php @@ -82,6 +82,15 @@ class Sparklines extends ViewDataTable $this->requestConfig->request_parameters_to_modify['columns'] = $columnsList; $this->requestConfig->request_parameters_to_modify['format_metrics'] = '1'; + /** + * This special request parameter is used to include trend indication columns for all evolution columns + * this is done to be able to determine safely in the view if an evolution is positive or negative, as this + * can't be done with formatted evolution values due to language specific signs being used. + * + * @see DataComparisonFilter::compareChangePercents + */ + $this->requestConfig->request_parameters_to_modify['include_trends'] = '1'; + $request = $this->getRequestArray(); if ($this->isComparing() && !empty($request['comparePeriods']) @@ -192,7 +201,7 @@ class Sparklines extends ViewDataTable $columnToUse = $this->removeUniqueVisitorsIfNotEnabledForPeriod($column, $period); - list($compareValues, $compareDescriptions, $evolutions) = $this->getValuesAndDescriptions($compareRow, $columnToUse, '_change'); + list($compareValues, $compareDescriptions, $evolutions) = $this->getValuesAndDescriptions($compareRow, $columnToUse, '_change', '_trend'); foreach ($compareValues as $i => $value) { $metricInfo = [ @@ -261,7 +270,7 @@ class Sparklines extends ViewDataTable $table->applyQueuedFilters(); } - private function getValuesAndDescriptions($firstRow, $columns, $evolutionColumnNameSuffix = null) + private function getValuesAndDescriptions($firstRow, $columns, $evolutionColumnNameSuffix = null, $trendColumnNameSuffix = null) { if (!is_array($columns)) { $columns = array($columns); @@ -285,8 +294,9 @@ class Sparklines extends ViewDataTable if ($evolutionColumnNameSuffix !== null) { $evolution = $firstRow->getColumn($col . $evolutionColumnNameSuffix); + $trend = $firstRow->getColumn($col . $trendColumnNameSuffix); if ($evolution !== false) { - $evolutions[] = ['percent' => ltrim($evolution, '+'), 'tooltip' => '']; + $evolutions[] = ['percent' => ltrim($evolution, '+'), 'trend' => $trend, 'tooltip' => '']; } } diff --git a/plugins/CoreVisualizations/templates/macros.twig b/plugins/CoreVisualizations/templates/macros.twig index d6c5ad9f56..8ded71264d 100644 --- a/plugins/CoreVisualizations/templates/macros.twig +++ b/plugins/CoreVisualizations/templates/macros.twig @@ -1,11 +1,11 @@ {% macro sparklineEvolution(evolution) %} {% set evolutionPretty = evolution.percent %} - - {% if evolution.percent < 0 %} + {% set compareValue = evolution.trend is defined ? evolution.trend : evolution.percent %} + {% if compareValue < 0 %} {% set evolutionClass = 'negative-evolution' %} {% set evolutionIcon = 'arrow_down.png' %} - {% elseif evolution.percent == 0 or evolution.percent == '0%' %} + {% elseif compareValue == 0 or compareValue == '0%' %} {% set evolutionClass = 'neutral-evolution' %} {% set evolutionIcon = 'stop.png' %} {% else %} |