diff options
author | Ben Burgess <88810029+bx80@users.noreply.github.com> | 2022-06-15 16:17:22 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-15 16:17:22 +0300 |
commit | 1554431e5d557153417763a039d6b033e300d3df (patch) | |
tree | d94cd00750fd00b36f75d9ba3a9cff2591ac4b77 /plugins/CoreVisualizations | |
parent | 494533f8d46f2d33c73b03178458a0665b238762 (diff) |
Fix for zero average order value on charts (#19353)
* Changed evolution jqplot charts to not format metrics, added basic percent formatting for the jqplotDataGenerator
* Only show dollar and pound currency symbols as postfix for jqplot formatting
* Do not attempt to format jqplot percent values unless format_metrics = 0, UI test screenshot update
* Improve jqplot formatting, remove unnecessary format metrics default logic
* Revert format metrics default logic removal
Diffstat (limited to 'plugins/CoreVisualizations')
3 files changed, 43 insertions, 5 deletions
diff --git a/plugins/CoreVisualizations/JqplotDataGenerator/Chart.php b/plugins/CoreVisualizations/JqplotDataGenerator/Chart.php index dc396a4fb2..aa7d946de7 100644 --- a/plugins/CoreVisualizations/JqplotDataGenerator/Chart.php +++ b/plugins/CoreVisualizations/JqplotDataGenerator/Chart.php @@ -9,6 +9,8 @@ namespace Piwik\Plugins\CoreVisualizations\JqplotDataGenerator; use Piwik\Common; +use Piwik\Container\StaticContainer; +use Piwik\NumberFormatter; use Piwik\ProxyHttp; /** @@ -52,7 +54,14 @@ class Chart $this->axes['xaxis']['onclick'] = & $onClick; } - public function setAxisYValues(&$values, $seriesMetadata = null) + /** + * Set the series values + * + * @param $values + * @param null $seriesMetadata + * @param array|null $seriesUnits If the series units array is passed then the values will be formatted + */ + public function setAxisYValues(&$values, $seriesMetadata = null, ?array $seriesUnits = null) { foreach ($values as $label => &$data) { $seriesInfo = array( @@ -65,9 +74,13 @@ class Chart } $this->series[] = $seriesInfo; + $unit = (isset($seriesUnits[$label]) ? $seriesUnits[$label] : null); - array_walk($data, function (&$v) { + array_walk($data, function (&$v) use ($unit) { $v = (float) Common::forceDotAsSeparatorForDecimalPoint($v); + if ($unit === '%') { + $v = $v * 100; + } }); $this->data[] = & $data; } @@ -90,7 +103,25 @@ class Chart // generate jqplot axes config foreach ($axesIds as $unit => $axisId) { - $this->axes[$axisId]['tickOptions']['formatString'] = '%s' . $unit; + if ($unit === '$' || $unit === '£') { + $this->axes[$axisId]['tickOptions']['formatString'] = $unit . '%s'; + } else { + $this->axes[$axisId]['tickOptions']['formatString'] = '%s' . $unit; + } + } + + $currencies = StaticContainer::get('Piwik\Intl\Data\Provider\CurrencyDataProvider')->getCurrencyList(); + $currencies = array_column($currencies, 0); + + // generate jqplot axes config + foreach ($axesIds as $unit => $axisId) { + if ($unit === '%') { + $this->axes[$axisId]['tickOptions']['formatString'] = str_replace('0', '%s', NumberFormatter::getInstance()->formatPercent(0, 0, 0)); + } else if (in_array($unit, $currencies)) { + $this->axes[$axisId]['tickOptions']['formatString'] = str_replace('0', '%s', NumberFormatter::getInstance()->formatCurrency(0, $unit, 0)); + } else { + $this->axes[$axisId]['tickOptions']['formatString'] = '%s' . $unit; + } } // map each series to appropriate yaxis diff --git a/plugins/CoreVisualizations/JqplotDataGenerator/Evolution.php b/plugins/CoreVisualizations/JqplotDataGenerator/Evolution.php index ea71ab47be..dd827551e3 100644 --- a/plugins/CoreVisualizations/JqplotDataGenerator/Evolution.php +++ b/plugins/CoreVisualizations/JqplotDataGenerator/Evolution.php @@ -89,7 +89,11 @@ class Evolution extends JqplotDataGenerator $visualization->dataTable = $dataTable; $visualization->properties = $this->properties; - $visualization->setAxisYValues($allSeriesData, $seriesMetadata); + $units = null; + if ($visualization->properties['request_parameters_to_modify']['format_metrics'] === 0) { + $units = $seriesUnits; + } + $visualization->setAxisYValues($allSeriesData, $seriesMetadata, $units); $visualization->setAxisYUnits($seriesUnits); $xLabelStrs = []; diff --git a/plugins/CoreVisualizations/Visualizations/Graph.php b/plugins/CoreVisualizations/Visualizations/Graph.php index 296ea624a8..56ec6ee5ff 100644 --- a/plugins/CoreVisualizations/Visualizations/Graph.php +++ b/plugins/CoreVisualizations/Visualizations/Graph.php @@ -62,7 +62,10 @@ abstract class Graph extends Visualization $this->requestConfig->request_parameters_to_modify['filter_truncate'] = $this->config->max_graph_elements - 1; } - $this->requestConfig->request_parameters_to_modify['format_metrics'] = 1; + // Only default to formatting metrics if the request hasn't already been set to not format metrics + if (!isset($this->requestConfig->request_parameters_to_modify['format_metrics'])) { + $this->requestConfig->request_parameters_to_modify['format_metrics'] = 1; + } // if addTotalRow was called in GenerateGraphHTML, add a row containing totals of // different metrics |