-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathAPI.php
101 lines (86 loc) · 3.33 KB
/
API.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Plugins\TreemapVisualization;
use Piwik\API\Request;
use Piwik\Common;
use Piwik\DataTable;
use Piwik\Metrics;
use Piwik\Period\Range;
use Piwik\Plugins\TreemapVisualization\Visualizations\Treemap;
/**
* Class API
* @method static \Piwik\Plugins\TreemapVisualization\API getInstance()
*/
class API extends \Piwik\Plugin\API
{
/**
* Gets report data and converts it into data that can be used with the JavaScript Infovis
* Toolkit's treemap visualization.
*
* @param string $apiMethod The API module & action to call. The result of this method is converted
* to data usable by the treemap visualization. E.g.
* 'Actions.getPageUrls'.
* @param string $column The column to generate metric data for. If more than one column is
* supplied, the first is used and the rest discarded.
* @param string $period
* @param string $date
* @param bool $availableWidth Available screen width in pixels.
* @param bool $availableHeight Available screen height in pixels.
* @param int|bool $show_evolution_values Whether to calculate evolution values for each row or not.
*
* @return array
*/
public function getTreemapData(
$apiMethod,
$column,
$period,
$date,
$availableWidth = false,
$availableHeight = false,
$show_evolution_values = false
) {
if (!Request::isCurrentApiRequestTheRootApiRequest()) {
return [];
}
if (
$period == 'range'
|| Common::getRequestVar('idSubtable', false)
) {
$show_evolution_values = false;
}
$params = array();
if ($show_evolution_values) {
list($previousDate, $ignore) = Range::getLastDate($date, $period);
$params['date'] = $previousDate . ',' . $date;
}
$params['filter_limit'] = false;
$params['disable_queued_filters'] = true;
$dataTable = Request::processRequest("$apiMethod", $params);
if (!$dataTable instanceof DataTable) {
return [];
}
$columns = explode(',', $column);
$column = reset($columns);
$translations = Metrics::getDefaultMetricTranslations();
$translation = empty($translations[$column]) ? $column : $translations[$column];
$generator = new TreemapDataGenerator($column, $translation);
$generator->setInitialRowOffset(Common::getRequestVar('filter_offset', 0, 'int'));
$generator->setAvailableDimensions($availableWidth, $availableHeight);
if ($show_evolution_values) {
$generator->showEvolutionValues();
}
$generator->truncateBasedOnAvailableSpace($dataTable);
$dataTable->applyQueuedFilters();
list($module, $method) = explode('.', $apiMethod);
if ($module == 'Actions') {
Treemap::configureGeneratorIfActionsUrlReport($generator, $method);
}
return $generator->generate($dataTable);
}
}