diff options
author | Stefan Giehl <stefan@matomo.org> | 2019-10-13 23:44:31 +0300 |
---|---|---|
committer | Thomas Steur <tsteur@users.noreply.github.com> | 2019-10-13 23:44:31 +0300 |
commit | b6683b5b60d6a98cc063a0ea61aae1445a7e39e1 (patch) | |
tree | 0752588c99a1649a5cfec27ec4e44edf2f383dbd /plugins/CoreVisualizations/Visualizations | |
parent | 608cfdb34341d0f07aa4bacef913975e3799e028 (diff) |
Hide unavailable metrics in graphs (#14996)
Diffstat (limited to 'plugins/CoreVisualizations/Visualizations')
-rw-r--r-- | plugins/CoreVisualizations/Visualizations/Graph.php | 15 | ||||
-rw-r--r-- | plugins/CoreVisualizations/Visualizations/JqplotGraph/Evolution.php | 10 |
2 files changed, 24 insertions, 1 deletions
diff --git a/plugins/CoreVisualizations/Visualizations/Graph.php b/plugins/CoreVisualizations/Visualizations/Graph.php index bc37ea8747..fc04c48608 100644 --- a/plugins/CoreVisualizations/Visualizations/Graph.php +++ b/plugins/CoreVisualizations/Visualizations/Graph.php @@ -8,6 +8,7 @@ */ namespace Piwik\Plugins\CoreVisualizations\Visualizations; +use Piwik\Common; use Piwik\DataTable; use Piwik\DataTable\Row; use Piwik\Plugin\Metric; @@ -15,6 +16,7 @@ use Piwik\Plugins\AbTesting\Columns\Metrics\ProcessedMetric; use Piwik\Plugins\CoreVisualizations\Metrics\Formatter\Numeric; use Piwik\Piwik; use Piwik\Plugin\Visualization; +use Piwik\SettingsPiwik; /** * This is an abstract visualization that should be the base of any 'graph' visualization. @@ -236,7 +238,7 @@ abstract class Graph extends Visualization $allColumns = $this->getDefaultColumnsToDisplay(); } - $this->config->columns_to_display = array_intersect($columnsToDisplay, $allColumns); + $this->config->columns_to_display = $this->removeUnavailableMetrics(array_intersect($columnsToDisplay, $allColumns)); } private function getDefaultColumnsToDisplay() @@ -248,4 +250,15 @@ abstract class Graph extends Visualization 'nb_users' ); } + + private function removeUnavailableMetrics($metrics) + { + $currentPeriod = Common::getRequestVar('period', false); + + if (!SettingsPiwik::isUniqueVisitorsEnabled($currentPeriod)) { + $metrics = array_diff($metrics, ['nb_uniq_visitors', 'nb_users']); + } + + return $metrics; + } } diff --git a/plugins/CoreVisualizations/Visualizations/JqplotGraph/Evolution.php b/plugins/CoreVisualizations/Visualizations/JqplotGraph/Evolution.php index 2082700c88..c93a44c12b 100644 --- a/plugins/CoreVisualizations/Visualizations/JqplotGraph/Evolution.php +++ b/plugins/CoreVisualizations/Visualizations/JqplotGraph/Evolution.php @@ -238,4 +238,14 @@ class Evolution extends JqplotGraph { return true; } + + protected function ensureValidColumnsToDisplay() + { + parent::ensureValidColumnsToDisplay(); + + $columnsToDisplay = $this->config->columns_to_display; + + // Use a sensible default if the columns_to_display is empty + $this->config->columns_to_display = $columnsToDisplay ? : array('nb_visits'); + } } |