PHP Class Piwik\Plugins\CoreVisualizations\Visualizations\Sparklines\Config

Inheritance: extends Piwik\ViewDataTable\Config
Show file Open project: piwik/piwik

Public Properties

Property Type Description
$title_attributes string Adds possibility to set html attributes on the sparklines title / headline. For example can be used to set an angular directive

Public Methods

Method Description
__construct ( )
addPlaceholder ( integer | null $order = null ) Adds a placeholder. In this case nothing will be shown, neither a sparkline nor any description. This can be useful if you want to have some kind of separator. Eg if you want to have a sparkline on the left side but not sparkline on the right side.
addSparkline ( array $requestParamsForSparkline, integer | float | string | array $value, string | array $description, array | null $evolution = null, integer $order = null ) Add a new sparkline to be displayed to the view.
addSparklineMetric ( string | array $metricName, integer | null $order = null ) Adds a new sparkline.
areSparklinesLinkable ( ) Detect whether sparklines are linkable with an evolution graph. {@link setNotLinkableWithAnyEvolutionGraph()}
getSortedSparklines ( ) : array
getSparklineMetrics ( ) : array
hasSparklineMetrics ( ) : boolean
removeSparklineMetric ( array | string $metricNames ) Removes an existing sparkline entry. Especially useful in dataTable filters in case sparklines should be not displayed depending on the fetched data.
replaceSparklineMetric ( array | string $metricNames, array | string $replacementColumns ) Replaces an existing sparkline entry with different columns. Especially useful in dataTable filters in case sparklines should be not displayed depending on the fetched data.
setNotLinkableWithAnyEvolutionGraph ( ) If there are sparklines and evolution graphs on one page, we try to connect them so that when you click on a sparkline, the evolution graph will update and show the evolution for that sparkline metric. In some cases we might falsely connect sparklines with an evolution graph that don't belong together. In this case you can mark all sparklines as "not linkable". This will prevent the sparklines being linked with an evolution graph.

Private Methods

Method Description
getGraphParamsModified ( array $paramsToSet = [] ) : array Returns the array of new processed parameters once the parameters are applied.
getSparklineOrder ( $order )
getUrlSparkline ( array $customParameters = [] ) : string Returns a URL to a sparkline image for a report served by the current plugin.

Method Details

__construct() public method

public __construct ( )

addPlaceholder() public method

Adds a placeholder. In this case nothing will be shown, neither a sparkline nor any description. This can be useful if you want to have some kind of separator. Eg if you want to have a sparkline on the left side but not sparkline on the right side.
public addPlaceholder ( integer | null $order = null )
$order integer | null Defines the order. The lower the order the earlier the sparkline will be displayed. By default the sparkline will be appended to the end.

addSparkline() public method

Each sparkline can consist of one or multiple metrics. One metric consists of a value and a description. By default the value is shown first, then the description. The description can optionally contain a '%s' in case the value shall be displayed within the description. If multiple metrics are given, they will be separated by a comma.
public addSparkline ( array $requestParamsForSparkline, integer | float | string | array $value, string | array $description, array | null $evolution = null, integer $order = null )
$requestParamsForSparkline array You need to at least set a module / action eg array('columns' => array('nb_visit'), 'module' => '', 'action' => '')
$value integer | float | string | array Either the metric value or an array of values.
$description string | array Either one description or an array of descriptions. If an array, both $value and $description need the same amount of array entries. $description[0] should be the description for $value[0]. $description should be already translated. If $value should appear somewhere within the text a `%s` can be used in the translation.
$evolution array | null Optional array containing at least the array keys 'currentValue' and 'pastValue' which are needed to calculate the correct percentage. An optional 'tooltip' can be set as well. Eg array('currentValue' => 10, 'pastValue' => 20, 'tooltip' => '10 visits in 2015-07-26 compared to 20 visits in 2015-07-25')
$order integer Defines the order. The lower the order the earlier the sparkline will be displayed. By default the sparkline will be appended to the end.

addSparklineMetric() public method

It will show a sparkline image, the value of the resolved metric name and a descrption. Optionally, multiple values can be shown after a sparkline image by passing multiple metric names (eg array('nb_visits', 'nb_actions')). The data will be requested from the configured api method see {@link Piwik\ViewDataTable\RequestConfig::$apiMethodToRequestDataTable}. Example: $config->addSparklineMetric('nb_visits'); $config->addTranslation('nb_visits', 'Visits'); Results in: [sparkline image] X visits Example: $config->addSparklineMetric(array('nb_visits', 'nb_actions')); $config->addTranslations(array('nb_visits' => 'Visits', 'nb_actions' => 'Actions')); Results in: [sparkline image] X visits, Y actions
public addSparklineMetric ( string | array $metricName, integer | null $order = null )
$metricName string | array Either one metric name (eg 'nb_visits') or an array of metric names
$order integer | null Defines the order. The lower the order the earlier the sparkline will be displayed. By default the sparkline will be appended to the end.

areSparklinesLinkable() public method

Detect whether sparklines are linkable with an evolution graph. {@link setNotLinkableWithAnyEvolutionGraph()}

getSortedSparklines() public method

public getSortedSparklines ( ) : array
return array

getSparklineMetrics() public method

public getSparklineMetrics ( ) : array
return array

hasSparklineMetrics() public method

public hasSparklineMetrics ( ) : boolean
return boolean

removeSparklineMetric() public method

Example: $config->addSparklineMetric('nb_users'); $config->filters[] = function ($dataTable) use ($config) { if ($dataTable->getFirstRow()->getColumn('nb_users') == 0) { do not show a sparkline if there are no recorded users $config->removeSparklineMetric('nb_users'); } }
public removeSparklineMetric ( array | string $metricNames )
$metricNames array | string The name of the metrics in the same format they were used when added via {@link addSparklineMetric}

replaceSparklineMetric() public method

Example: $config->addSparklineMetric('nb_users'); $config->filters[] = function ($dataTable) use ($config) { if ($dataTable->getFirstRow()->getColumn('nb_users') == 0) { instead of showing the sparklines for users, show a placeholder if there are no recorded users $config->replaceSparklineMetric(array('nb_users'), ''); } }
public replaceSparklineMetric ( array | string $metricNames, array | string $replacementColumns )
$metricNames array | string The name of the metrics in the same format they were used when added via {@link addSparklineMetric}
$replacementColumns array | string The removed columns will be replaced with these columns

setNotLinkableWithAnyEvolutionGraph() public method

If there are sparklines and evolution graphs on one page, we try to connect them so that when you click on a sparkline, the evolution graph will update and show the evolution for that sparkline metric. In some cases we might falsely connect sparklines with an evolution graph that don't belong together. In this case you can mark all sparklines as "not linkable". This will prevent the sparklines being linked with an evolution graph.

Property Details

$title_attributes public property

Adds possibility to set html attributes on the sparklines title / headline. For example can be used to set an angular directive
public string $title_attributes
return string