Skip to content

Commit

Permalink
refs #3994 added example for evolution graph
Browse files Browse the repository at this point in the history
  • Loading branch information
tsteur committed Oct 2, 2013
1 parent f689733 commit 11d2794
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
25 changes: 16 additions & 9 deletions plugins/ExampleUI/Controller.php
Expand Up @@ -11,6 +11,8 @@
namespace Piwik\Plugins\ExampleUI;

use Piwik\Common;
use Piwik\Piwik;
use Piwik\Site;
use Piwik\ViewDataTable;
use Piwik\View;

Expand Down Expand Up @@ -47,20 +49,25 @@ public function dataTables()

public function evolutionGraph()
{
echo "<h2>Evolution of server temperatures over the last few days</h2>";
$this->echoEvolutionGraph();
$view = new View('@ExampleUI/evolutiongraph');

$this->setPeriodVariablesView($view);
$view->evolutionGraph = $this->getEvolutionGraph(true, array('server1', 'server2'));

echo $view->render();
}

public function echoEvolutionGraph()
public function getEvolutionGraph($fetch = false, array $columns = array())
{
$view = ViewDataTable::factory(
'graphEvolution', 'ExampleUI.getTemperaturesEvolution', $controllerAction = 'ExampleUI.echoEvolutionGraph');
if (empty($columns)) {
$columns = Common::getRequestVar('columns');
$columns = Piwik::getArrayFromApiParameter($columns);
}

$view->y_axis_unit = '°C'; // useful if the user requests the bar graph
$view->translations['server1'] = "Temperature server piwik.org";
$view->translations['server2'] = "Temperature server dev.piwik.org";
$view = $this->getLastUnitGraphAcrossPlugins($this->pluginName, __FUNCTION__, $columns,
$selectableColumns = array('server1', 'server2'), 'My documentation', 'ExampleUI.getTemperaturesEvolution');

echo $view->render();
return $this->renderView($view, $fetch);
}

public function barGraph()
Expand Down
1 change: 1 addition & 0 deletions plugins/ExampleUI/ExampleUI.php
Expand Up @@ -35,6 +35,7 @@ function addMenus()
$this->addSubMenu('Pie graph', 'pieGraph', 3);
$this->addSubMenu('Tag clouds', 'tagClouds', 4);
$this->addSubMenu('Sparklines', 'sparklines', 5);
$this->addSubMenu('Evolution Graph', 'evolutionGraph', 6);
}

private function addSubMenu($subMenu, $action, $order)
Expand Down
3 changes: 3 additions & 0 deletions plugins/ExampleUI/templates/evolutiongraph.twig
@@ -0,0 +1,3 @@
<h2>Evolution of server temperatures over the last few days</h2>

{{ evolutionGraph|raw }}

0 comments on commit 11d2794

Please sign in to comment.