Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Burgess <88810029+bx80@users.noreply.github.com>2022-05-24 10:51:06 +0300
committerGitHub <noreply@github.com>2022-05-24 10:51:06 +0300
commitfdbcb562ef9e200c860fa3d40f664cac873ea8e8 (patch)
tree303d03c08977daa3603b443b637ba50c331a76fc /plugins/VisitsSummary/Reports/Get.php
parent72f3d296d2b7dc6bb4348f401fa427262d72b374 (diff)
Show sparkline evolution figures for visits, goals and ecommerce overviews (#19057)
* Add evolution to sparklines on the visits overview and the goals overview * Add evolution to sparklines on the ecommerce overview * Updated UI test screenshots * Update submodule * Fix for tooltip date formatting, improved translation lookup and callback method extra parameter documentation * Sparklines API calls modified to return unformatted values, formatting added to the sparkline visualization and overview reports * update submodule * Updated inherited method signature * Code improvements, added forcedParams parameter to ViewDataTable / Visualization loadDataTableFromAPI methods * Revert change to loadDataTableFromAPI method signature in ViewDataTable and Visualization classes * Remove incorrectly added file * Improve international handling of plus symbol in ecommerce overview template * Always use gigabytes when formatting byte values for evolution charts * update sumbodule * built vue files * System test updates * UI test screenshot updates * Update submodule * Test fix * Test fixes * Update system tests * Rerun tests * Fix for unformatted metrics when comparing * Update UI test screenshots for sparkline comparisons * apply some fixes * Update submodule Co-authored-by: sgiehl <stefan@matomo.org> Co-authored-by: sgiehl <sgiehl@users.noreply.github.com>
Diffstat (limited to 'plugins/VisitsSummary/Reports/Get.php')
-rw-r--r--plugins/VisitsSummary/Reports/Get.php65
1 files changed, 63 insertions, 2 deletions
diff --git a/plugins/VisitsSummary/Reports/Get.php b/plugins/VisitsSummary/Reports/Get.php
index 1ee4492817..7b482cac12 100644
--- a/plugins/VisitsSummary/Reports/Get.php
+++ b/plugins/VisitsSummary/Reports/Get.php
@@ -8,9 +8,16 @@
*/
namespace Piwik\Plugins\VisitsSummary\Reports;
+use Piwik\API\Request;
use Piwik\Common;
use Piwik\DataTable;
+use Piwik\DataTable\Filter\CalculateEvolutionFilter;
use Piwik\DbHelper;
+use Piwik\Metrics;
+use Piwik\Metrics\Formatter as MetricFormatter;
+use Piwik\Period;
+use Piwik\Period\Month;
+use Piwik\Period\Range;
use Piwik\Piwik;
use Piwik\Plugin\ViewDataTable;
use Piwik\Plugins\CoreHome\Columns\Metrics\ActionsPerVisit;
@@ -109,6 +116,55 @@ class Get extends \Piwik\Plugin\Report
}
};
+ // Add evolution values to sparklines
+ list($lastPeriodDate, $ignore) = Range::getLastDate();
+ if ($lastPeriodDate !== false) {
+
+ $currentPeriod = Period\Factory::build(Piwik::getPeriod(), Common::getRequestVar('date'));
+ $currentPrettyDate = ($currentPeriod instanceof Month ? $currentPeriod->getLocalizedLongString() : $currentPeriod->getPrettyString());
+ $lastPeriod = Period\Factory::build(Piwik::getPeriod(), $lastPeriodDate);
+ $lastPrettyDate = ($currentPeriod instanceof Month ? $lastPeriod->getLocalizedLongString() : $lastPeriod->getPrettyString());
+
+ /** @var DataTable $previousData */
+ $previousData = Request::processRequest('API.get', ['date' => $lastPeriodDate, 'format_metrics' => '0']);
+ $previousDataRow = $previousData->getFirstRow();
+
+ $view->config->compute_evolution = function ($columns, $metrics) use ($currentPrettyDate, $lastPrettyDate, $previousDataRow) {
+ $value = reset($columns);
+ $columnName = key($columns);
+ $pastValue = $previousDataRow->getColumn($columnName);
+
+ // Format
+ $formatter = new MetricFormatter();
+ $currentValueFormatted = $value;
+ $pastValueFormatted = $pastValue;
+ foreach ($metrics as $metric) {
+ if ($metric->getName() == $columnName) {
+ $pastValueFormatted = $metric->format($pastValue, $formatter);
+ $currentValueFormatted = $metric->format($value, $formatter);
+ break;
+ }
+ }
+
+ $columnTranslations = Metrics::getDefaultMetricTranslations();
+ $columnTranslation = '';
+ if (array_key_exists($columnName, $columnTranslations)) {
+ $columnTranslation = $columnTranslations[$columnName];
+ }
+
+ return [
+ 'currentValue' => $value,
+ 'pastValue' => $pastValue,
+ 'tooltip' => Piwik::translate('General_EvolutionSummaryGeneric', [
+ $currentValueFormatted.' '.$columnTranslation,
+ $currentPrettyDate,
+ $pastValueFormatted.' '.$columnTranslation,
+ $lastPrettyDate,
+ CalculateEvolutionFilter::calculate($value, $pastValue, $precision = 1)])
+ ];
+ };
+ }
+
// Remove metric tooltips
$view->config->metrics_documentation['nb_actions'] = '';
$view->config->metrics_documentation['nb_visits'] = '';
@@ -130,9 +186,9 @@ class Get extends \Piwik\Plugin\Report
}
}
- private function getSparklineTranslations()
+ private function getSparklineTranslationsKeys()
{
- $translations = array(
+ return array(
'nb_actions' => 'NbActionsDescription',
'nb_visits' => 'NbVisitsDescription',
'nb_users' => 'NbUsersDescription',
@@ -152,6 +208,11 @@ class Get extends \Piwik\Plugin\Report
'bounce_rate' => 'NbVisitsBounced',
);
+ }
+
+ private function getSparklineTranslations()
+ {
+ $translations = $this->getSparklineTranslationsKeys();
foreach ($translations as $metric => $key) {
$translations[$metric] = Piwik::translate('VisitsSummary_' . $key);
}