Skip to content

Commit

Permalink
refs #3994 this is an example how to make a customized existing visua…
Browse files Browse the repository at this point in the history
…lization reusable
  • Loading branch information
tsteur committed Oct 3, 2013
1 parent a963a87 commit 955ef7c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 21 deletions.
29 changes: 8 additions & 21 deletions plugins/ExampleUI/Controller.php
Expand Up @@ -23,28 +23,15 @@ class Controller extends \Piwik\Controller
{
public function dataTables()
{
$view = ViewDataTable::factory('table', 'ExampleUI.getTemperatures', $controllerAction = 'ExampleUI.dataTables');

$view->translations['value'] = "Temperature in °C";
$view->translations['label'] = "Hour of day";
$view->filter_sort_column = 'label';
$view->filter_sort_order = 'asc';
$view->filter_limit = 24;
$view->y_axis_unit = '°C'; // useful if the user requests the bar graph
$view->show_exclude_low_population = false;
$view->show_table_all_columns = false;
$view->visualization_properties->setForVisualization(
'Piwik\\Plugins\\CoreVisualizations\\Visualizations\\HtmlTable',
'disable_row_evolution',
true
);
$view->visualization_properties->setForVisualization(
'Piwik\\Plugins\\CoreVisualizations\\Visualizations\\JqplotGraph',
'max_graph_elements',
24
);
$controllerAction = $this->pluginName . '.' . __FUNCTION__;
$apiAction = 'ExampleUI.getTemperatures';

echo $view->render();
/**
* this is an example how you can make a custom visualization reusable.
*/
$table = new CustomDataTable();

echo $table->render('Temperature in °C', 'Hour of day', $apiAction, $controllerAction);
}

public function evolutionGraph()
Expand Down
44 changes: 44 additions & 0 deletions plugins/ExampleUI/CustomDataTable.php
@@ -0,0 +1,44 @@
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
* @category Piwik_Plugins
* @package ExampleUI
*/

namespace Piwik\Plugins\ExampleUI;

use Piwik\ViewDataTable;

class CustomDataTable
{
public function render($value, $label, $apiAction, $controllerAction)
{
$view = ViewDataTable::factory('exampleui-customtable', $apiAction, $controllerAction);

$view->translations['value'] = $value;
$view->translations['label'] = $label;
$view->filter_sort_column = 'label';
$view->filter_sort_order = 'asc';
$view->filter_limit = 24;
$view->y_axis_unit = '°C'; // useful if the user requests the bar graph
$view->show_exclude_low_population = false;
$view->show_table_all_columns = false;
$view->visualization_properties->setForVisualization(
'Piwik\\Plugins\\CoreVisualizations\\Visualizations\\HtmlTable',
'disable_row_evolution',
true
);
$view->visualization_properties->setForVisualization(
'Piwik\\Plugins\\CoreVisualizations\\Visualizations\\JqplotGraph',
'max_graph_elements',
24
);

return $view->render();
}

}

0 comments on commit 955ef7c

Please sign in to comment.