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:
authordiosmosis <benaka@piwik.pro>2014-09-21 00:14:13 +0400
committerdiosmosis <benaka@piwik.pro>2014-09-21 03:02:40 +0400
commit8d0205e32a430d4bb028ec14877ff7a7d7b5d22e (patch)
treec0af7e79f9cd11b0e34006b5a3bdae2e0f0aee22 /core/DataTable/Filter/PivotByDimension.php
parentb1968947d69b0da7bfc8c2eea6c8311c3b6be433 (diff)
Refs #6078, order pivot table columns by sum, descending and aggregate cut-off columns into 'Others' column.
Diffstat (limited to 'core/DataTable/Filter/PivotByDimension.php')
-rw-r--r--core/DataTable/Filter/PivotByDimension.php47
1 files changed, 30 insertions, 17 deletions
diff --git a/core/DataTable/Filter/PivotByDimension.php b/core/DataTable/Filter/PivotByDimension.php
index 902c03f1b5..ba4f0220f6 100644
--- a/core/DataTable/Filter/PivotByDimension.php
+++ b/core/DataTable/Filter/PivotByDimension.php
@@ -17,6 +17,7 @@ use Piwik\DataTable\BaseFilter;
use Piwik\DataTable\Row;
use Piwik\Log;
use Piwik\Metrics;
+use Piwik\Piwik;
use Piwik\Plugin\Report;
use Piwik\Plugin\Segment;
@@ -211,22 +212,10 @@ class PivotByDimension extends BaseFilter
Log::debug("PivotByDimension::%s: pivoted columns set: %s", __FUNCTION__, $columnSet);
- // limit columns
- if ($this->pivotByColumnLimit > 0) {
- arsort($columnSet);
- $columnSet = array_slice($columnSet, 0, $this->pivotByColumnLimit, $preserveKeys = true);
- }
-
- // sort columns by name (to ensure deterministic ordering)
- ksort($columnSet);
+ $others = Piwik::translate('General_Others');
+ $defaultRow = $this->getPivotTableDefaultRowFromColumnSummary($columnSet, $others);
- // remove column sums from array so it can be used as a default row
- $columnSet = array_map(function () { return false; }, $columnSet);
-
- // make sure label column is first
- $columnSet = array_merge(array('label' => false), $columnSet);
-
- Log::debug("PivotByDimension::%s: processed pivoted columns: %s", __FUNCTION__, $columnSet);
+ Log::debug("PivotByDimension::%s: processed pivoted columns: %s", __FUNCTION__, $defaultRow);
// post process pivoted datatable
foreach ($table->getRows() as $row) {
@@ -234,11 +223,13 @@ class PivotByDimension extends BaseFilter
$row->removeSubtable();
$row->deleteMetadata('idsubdatatable_in_db');
- // use default row to ensure column ordering and add missing columns
- $orderedColumns = $columnSet;
+ // use default row to ensure column ordering and add missing columns/aggregate cut-off columns
+ $orderedColumns = $defaultRow;
foreach ($row->getColumns() as $name => $value) {
if (isset($orderedColumns[$name])) {
$orderedColumns[$name] = $value;
+ } else {
+ $orderedColumns[$others] += $value;
}
}
$row->setColumns($orderedColumns);
@@ -432,6 +423,28 @@ class PivotByDimension extends BaseFilter
return $params;
}
+ private function getPivotTableDefaultRowFromColumnSummary($columnSet, $othersRowLabel)
+ {
+ // sort columns by sum (to ensure deterministic ordering)
+ arsort($columnSet);
+
+ // limit columns if necessary (adding aggregate Others column at end)
+ if ($this->pivotByColumnLimit > 0
+ && count($columnSet) > $this->pivotByColumnLimit
+ ) {
+ $columnSet = array_slice($columnSet, 0, $this->pivotByColumnLimit - 1, $preserveKeys = true);
+ $columnSet[$othersRowLabel] = 0;
+ }
+
+ // remove column sums from array so it can be used as a default row
+ $columnSet = array_map(function () { return false; }, $columnSet);
+
+ // make sure label column is first
+ $columnSet = array_merge(array('label' => false), $columnSet);
+
+ return $columnSet;
+ }
+
/**
* Returns true if pivoting by subtable is supported for a report. Will return true if the report
* has a subtable dimension and if the subtable dimension is different than the report's dimension.