Skip to content

Commit

Permalink
Refs matomo-org#4077, truncate in treemap before queued filters are a…
Browse files Browse the repository at this point in the history
…pplied.
  • Loading branch information
Benaka Moorthi committed Sep 16, 2013
1 parent 85f67e8 commit e1d8b32
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
34 changes: 25 additions & 9 deletions plugins/TreemapVisualization/Treemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Piwik\Common;
use Piwik\View;
use Piwik\Period;
use Piwik\Period\Range;
use Piwik\DataTable\Map;
use Piwik\Visualization\Graph;
Expand Down Expand Up @@ -67,17 +68,37 @@ public function __construct($view)
$view->datatable_js_type = 'TreemapDataTable';
$view->request_parameters_to_modify['expanded'] = 1;
$view->request_parameters_to_modify['depth'] = $view->visualization_properties->depth;
$view->request_parameters_to_modify['disable_queued_filters'] = true;
$view->show_pagination_control = false;
$view->show_offset_information = false;
$view->show_flatten_table = false;

$self = $this;
$view->filters[] = function ($dataTable, $view) use ($self) {
$view->custom_parameters['columns'] = $self->getMetricToGraph($view->columns_to_display);
$metric = $this->getMetricToGraph($view->columns_to_display);
$view->filters[] = function ($dataTable, $view) use ($metric) {
$view->custom_parameters['columns'] = $metric;
};

$this->handleShowEvolutionValues($view);
$this->handleDynamicTruncation($view, $metric);
}

private function handleDynamicTruncation($view, $metric)
{
$currentPeriod = Period::makePeriodFromQueryParams(
$timezone = null, $period = Common::getRequestVar('period'), $date = Common::getRequestVar('date'));

$self = $this;
$doTruncate = function ($dataTable) use ($self, $metric, $currentPeriod) {
// only truncate current data
if ($dataTable->getMetadata('period')->getRangeString() != $currentPeriod->getRangeString()) {
return;
}

$truncateAfter = $self->getDynamicMaxElementCount($dataTable, $metric);
if ($truncateAfter > 0) {
$dataTable->filter('Truncate', array($truncateAfter));
}
};
$view->filters[] = array($doTruncate, array(), $priority = true);
}

/**
Expand Down Expand Up @@ -134,11 +155,6 @@ private function getGraphData($dataTable, $properties)
$generator->showEvolutionValues();
}

$truncateAfter = $this->getDynamicMaxElementCount($this->getCurrentData($dataTable), $metric);
if ($truncateAfter > 0) {
$generator->setTruncateAfter($truncateAfter);
}

return Common::json_encode($generator->generate($dataTable));
}

Expand Down
14 changes: 5 additions & 9 deletions plugins/TreemapVisualization/TreemapDataGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,6 @@ public function setTruncateAfter($truncateAfter)
*/
public function generate($dataTable)
{
// handle extra truncation
if ($this->truncateAfter) {
$dataTable->filter('Truncate', array($this->truncateAfter));
}

// now that truncation is done we can apply queued filters. doing it before will result in
// sumRow errors.
$dataTable->applyQueuedFilters();

// sanity check: if the dataTable is not a Map, we don't have the data to calculate evolution
// values, so make sure we don't try
if (!($dataTable instanceof Map)) {
Expand All @@ -161,6 +152,11 @@ public function generate($dataTable)
$this->pastDataDate = $pastData->getMetadata('period')->getLocalizedShortString();
}

// handle extra truncation (only for current data)
if ($this->truncateAfter) {
$dataTable->filter('Truncate', array($this->truncateAfter));
}

$root = $this->makeNode('treemap-root', $this->rootName);
$this->addDataTableToNode($root, $dataTable, $pastData, $tableId = '', $this->firstRowOffset);
return $root;
Expand Down

0 comments on commit e1d8b32

Please sign in to comment.