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
|
<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Plugins\PagePerformance\Visualizations\JqplotGraph;
use Piwik\Common;
use Piwik\Period\Range;
use Piwik\Plugins\PagePerformance\JqplotDataGenerator;
use Piwik\Plugins\CoreVisualizations\Visualizations\JqplotGraph\Evolution;
use Piwik\Site;
/**
* Visualization that renders HTML for a line graph using jqPlot.
*
* @property Evolution\Config $config
*/
class StackedBarEvolution extends Evolution
{
public const ID = 'graphStackedBarEvolution';
public const FOOTER_ICON_TITLE = '';
public const FOOTER_ICON = '';
public function beforeRender()
{
parent::beforeRender();
$this->checkRequestIsOnlyForMultiplePeriods();
$this->config->show_flatten_table = false;
$this->config->show_limit_control = false;
$this->config->datatable_js_type = 'JqplotStackedBarEvolutionGraphDataTable';
}
public function beforeLoadDataTable()
{
$this->calculateEvolutionDateRange();
parent::beforeLoadDataTable();
// period will be overridden when 'range' is requested in the UI
// but the graph will display for each day of the range.
// Default 'range' behavior is to return the 'sum' for the range
if (Common::getRequestVar('period', false) == 'range') {
$this->requestConfig->request_parameters_to_modify['period'] = 'day';
}
$this->config->custom_parameters['columns'] = $this->config->columns_to_display;
}
protected function makeDataGenerator($properties)
{
return new JqplotDataGenerator\StackedBarEvolution($properties, 'evolution', $this);
}
/**
* Based on the period, date and evolution_{$period}_last_n query parameters,
* calculates the date range this evolution chart will display data for.
*/
private function calculateEvolutionDateRange()
{
$period = Common::getRequestVar('period');
$idSite = Common::getRequestVar('idSite');
$timezone = Site::getTimezoneFor($idSite);
$defaultLastN = self::getDefaultLastN($period);
$originalDate = Common::getRequestVar('date', 'last' . $defaultLastN, 'string');
if ('range' != $period) { // show evolution limit if the period is not a range
// set the evolution_{$period}_last_n query param
if (Range::parseDateRange($originalDate)) {
// if a multiple period
// overwrite last_n param using the date range
$oPeriod = new Range($period, $originalDate, $timezone);
$lastN = count($oPeriod->getSubperiods());
} else {
// if not a multiple period
list($newDate, $lastN) = self::getDateRangeAndLastN($period, $originalDate, $defaultLastN);
$this->requestConfig->request_parameters_to_modify['date'] = $newDate;
$this->config->custom_parameters['dateUsedInGraph'] = $newDate;
}
$lastNParamName = self::getLastNParamName($period);
$this->config->custom_parameters[$lastNParamName] = $lastN;
}
}
public function supportsComparison()
{
return false;
}
}
|