hide map for Character groups Quest Stations when there are no stations
102
www/analytics/plugins/ExampleUI/API.php
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*
|
||||
*/
|
||||
namespace Piwik\Plugins\ExampleUI;
|
||||
|
||||
use Piwik\DataTable;
|
||||
use Piwik\Date;
|
||||
use Piwik\Period\Range;
|
||||
|
||||
/**
|
||||
* ExampleUI API is also an example API useful if you are developing a Piwik plugin.
|
||||
*
|
||||
* The functions listed in this API are returning the data used in the Controller to draw graphs and
|
||||
* display tables. See also the ExampleAPI plugin for an introduction to Piwik APIs.
|
||||
*
|
||||
* @method static \Piwik\Plugins\ExampleUI\API getInstance()
|
||||
*/
|
||||
class API extends \Piwik\Plugin\API
|
||||
{
|
||||
public static $disableRandomness = false;
|
||||
|
||||
public function getTemperaturesEvolution($date, $period)
|
||||
{
|
||||
$temperatures = array();
|
||||
|
||||
$date = Date::factory('2013-10-10', 'UTC');
|
||||
$period = new Range($period, 'last30');
|
||||
$period->setDefaultEndDate($date);
|
||||
|
||||
foreach ($period->getSubperiods() as $subPeriod) {
|
||||
if (self::$disableRandomness) {
|
||||
$server1 = 50;
|
||||
$server2 = 40;
|
||||
} else {
|
||||
$server1 = mt_rand(50, 90);
|
||||
$server2 = mt_rand(40, 110);
|
||||
}
|
||||
|
||||
$value = array('server1' => $server1, 'server2' => $server2);
|
||||
|
||||
$temperatures[$subPeriod->getLocalizedShortString()] = $value;
|
||||
}
|
||||
|
||||
return DataTable::makeFromIndexedArray($temperatures);
|
||||
}
|
||||
|
||||
public function getTemperatures()
|
||||
{
|
||||
$xAxis = array(
|
||||
'0h', '1h', '2h', '3h', '4h', '5h', '6h', '7h', '8h', '9h', '10h', '11h',
|
||||
'12h', '13h', '14h', '15h', '16h', '17h', '18h', '19h', '20h', '21h', '22h', '23h',
|
||||
);
|
||||
|
||||
$temperatureValues = array_slice(range(50, 90), 0, count($xAxis));
|
||||
if (!self::$disableRandomness) {
|
||||
shuffle($temperatureValues);
|
||||
}
|
||||
|
||||
$temperatures = array();
|
||||
foreach ($xAxis as $i => $xAxisLabel) {
|
||||
$temperatures[$xAxisLabel] = $temperatureValues[$i];
|
||||
}
|
||||
|
||||
return DataTable::makeFromIndexedArray($temperatures);
|
||||
}
|
||||
|
||||
public function getPlanetRatios()
|
||||
{
|
||||
$planetRatios = array(
|
||||
'Mercury' => 0.382,
|
||||
'Venus' => 0.949,
|
||||
'Earth' => 1.00,
|
||||
'Mars' => 0.532,
|
||||
'Jupiter' => 11.209,
|
||||
'Saturn' => 9.449,
|
||||
'Uranus' => 4.007,
|
||||
'Neptune' => 3.883,
|
||||
);
|
||||
|
||||
return DataTable::makeFromIndexedArray($planetRatios);
|
||||
}
|
||||
|
||||
public function getPlanetRatiosWithLogos()
|
||||
{
|
||||
$planetsDataTable = $this->getPlanetRatios();
|
||||
|
||||
foreach ($planetsDataTable->getRows() as $row) {
|
||||
$logo = sprintf('plugins/ExampleUI/images/icons-planet/%s.png', strtolower($row->getColumn('label')));
|
||||
$url = sprintf('http://en.wikipedia.org/wiki/%s', $row->getColumn('label'));
|
||||
|
||||
$row->addMetadata('logo', $logo);
|
||||
$row->addMetadata('url', $url);
|
||||
}
|
||||
|
||||
return $planetsDataTable;
|
||||
}
|
||||
}
|
||||
196
www/analytics/plugins/ExampleUI/Controller.php
Normal file
|
|
@ -0,0 +1,196 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*
|
||||
*/
|
||||
namespace Piwik\Plugins\ExampleUI;
|
||||
|
||||
use Piwik\Common;
|
||||
use Piwik\Notification;
|
||||
use Piwik\Piwik;
|
||||
use Piwik\View;
|
||||
use Piwik\ViewDataTable\Factory as ViewDataTableFactory;
|
||||
|
||||
/**
|
||||
*/
|
||||
class Controller extends \Piwik\Plugin\Controller
|
||||
{
|
||||
public function dataTables()
|
||||
{
|
||||
$controllerAction = $this->pluginName . '.' . __FUNCTION__;
|
||||
$apiAction = 'ExampleUI.getTemperatures';
|
||||
|
||||
$view = ViewDataTableFactory::build('table', $apiAction, $controllerAction);
|
||||
|
||||
$view->config->translations['value'] = 'Temperature in °C';
|
||||
$view->config->translations['label'] = 'Hour of day';
|
||||
$view->requestConfig->filter_sort_column = 'label';
|
||||
$view->requestConfig->filter_sort_order = 'asc';
|
||||
$view->requestConfig->filter_limit = 24;
|
||||
$view->config->columns_to_display = array('label', 'value');
|
||||
$view->config->y_axis_unit = '°C'; // useful if the user requests the bar graph
|
||||
$view->config->show_exclude_low_population = false;
|
||||
$view->config->show_table_all_columns = false;
|
||||
$view->config->disable_row_evolution = true;
|
||||
$view->config->max_graph_elements = 24;
|
||||
$view->config->metrics_documentation = array('value' => 'Documentation for temperature metric');
|
||||
|
||||
return $view->render();
|
||||
}
|
||||
|
||||
public function evolutionGraph()
|
||||
{
|
||||
$view = new View('@ExampleUI/evolutiongraph');
|
||||
|
||||
$this->setPeriodVariablesView($view);
|
||||
$view->evolutionGraph = $this->getEvolutionGraph(array('server1', 'server2'));
|
||||
|
||||
return $view->render();
|
||||
}
|
||||
|
||||
public function notifications()
|
||||
{
|
||||
$notification = new Notification('Lorem ipsum dolor sit amet, consectetur adipiscing elit.');
|
||||
Notification\Manager::notify('ExampleUI_InfoSimple', $notification);
|
||||
|
||||
$notification = new Notification('Neque porro quisquam est qui dolorem ipsum quia dolor sit amet.');
|
||||
$notification->title = 'Warning:';
|
||||
$notification->context = Notification::CONTEXT_WARNING;
|
||||
$notification->flags = null;
|
||||
Notification\Manager::notify('ExampleUI_warningWithClose', $notification);
|
||||
|
||||
$notification = new Notification('Phasellus tincidunt arcu at justo faucibus, et lacinia est accumsan. ');
|
||||
$notification->title = 'Well done';
|
||||
$notification->context = Notification::CONTEXT_SUCCESS;
|
||||
$notification->type = Notification::TYPE_TOAST;
|
||||
Notification\Manager::notify('ExampleUI_successToast', $notification);
|
||||
|
||||
$notification = new Notification('Phasellus tincidunt arcu at justo <a href="#">faucibus</a>, et lacinia est accumsan. ');
|
||||
$notification->raw = true;
|
||||
$notification->context = Notification::CONTEXT_ERROR;
|
||||
Notification\Manager::notify('ExampleUI_error', $notification);
|
||||
|
||||
$view = new View('@ExampleUI/notifications');
|
||||
$this->setGeneralVariablesView($view);
|
||||
return $view->render();
|
||||
}
|
||||
|
||||
public function getEvolutionGraph(array $columns = array())
|
||||
{
|
||||
if (empty($columns)) {
|
||||
$columns = Common::getRequestVar('columns');
|
||||
$columns = Piwik::getArrayFromApiParameter($columns);
|
||||
}
|
||||
|
||||
$view = $this->getLastUnitGraphAcrossPlugins($this->pluginName, __FUNCTION__, $columns,
|
||||
$selectableColumns = array('server1', 'server2'), 'My documentation', 'ExampleUI.getTemperaturesEvolution');
|
||||
$view->requestConfig->filter_sort_column = 'label';
|
||||
|
||||
return $this->renderView($view);
|
||||
}
|
||||
|
||||
public function barGraph()
|
||||
{
|
||||
$view = ViewDataTableFactory::build(
|
||||
'graphVerticalBar', 'ExampleUI.getTemperatures', $controllerAction = 'ExampleUI.barGraph');
|
||||
|
||||
$view->config->y_axis_unit = '°C';
|
||||
$view->config->show_footer = false;
|
||||
$view->config->translations['value'] = "Temperature";
|
||||
$view->config->selectable_columns = array("value");
|
||||
$view->config->max_graph_elements = 24;
|
||||
|
||||
return $view->render();
|
||||
}
|
||||
|
||||
public function pieGraph()
|
||||
{
|
||||
$view = ViewDataTableFactory::build(
|
||||
'graphPie', 'ExampleUI.getPlanetRatios', $controllerAction = 'ExampleUI.pieGraph');
|
||||
|
||||
$view->config->columns_to_display = array('value');
|
||||
$view->config->translations['value'] = "times the diameter of Earth";
|
||||
$view->config->show_footer_icons = false;
|
||||
$view->config->selectable_columns = array("value");
|
||||
$view->config->max_graph_elements = 10;
|
||||
|
||||
return $view->render();
|
||||
}
|
||||
|
||||
public function tagClouds()
|
||||
{
|
||||
$output = "<h2>Simple tag cloud</h2>";
|
||||
$output .= $this->echoSimpleTagClouds();
|
||||
|
||||
$output .= "<br /><br /><h2>Advanced tag cloud: with logos and links</h2>
|
||||
<ul style='list-style-type:disc;margin-left:50px'>
|
||||
<li>The logo size is proportional to the value returned by the API</li>
|
||||
<li>The logo is linked to a specific URL</li>
|
||||
</ul><br /><br />";
|
||||
$output .= $this->echoAdvancedTagClouds();
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
public function echoSimpleTagClouds()
|
||||
{
|
||||
$view = ViewDataTableFactory::build(
|
||||
'cloud', 'ExampleUI.getPlanetRatios', $controllerAction = 'ExampleUI.echoSimpleTagClouds');
|
||||
|
||||
$view->config->columns_to_display = array('label', 'value');
|
||||
$view->config->translations['value'] = "times the diameter of Earth";
|
||||
$view->config->show_footer = false;
|
||||
|
||||
return $view->render();
|
||||
}
|
||||
|
||||
public function echoAdvancedTagClouds()
|
||||
{
|
||||
$view = ViewDataTableFactory::build(
|
||||
'cloud', 'ExampleUI.getPlanetRatiosWithLogos', $controllerAction = 'ExampleUI.echoAdvancedTagClouds');
|
||||
|
||||
$view->config->display_logo_instead_of_label = true;
|
||||
$view->config->columns_to_display = array('label', 'value');
|
||||
$view->config->translations['value'] = "times the diameter of Earth";
|
||||
|
||||
return $view->render();
|
||||
}
|
||||
|
||||
public function sparklines()
|
||||
{
|
||||
$view = new View('@ExampleUI/sparklines');
|
||||
$view->urlSparkline1 = $this->getUrlSparkline('generateSparkline', array('server' => 'server1', 'rand' => mt_rand()));
|
||||
$view->urlSparkline2 = $this->getUrlSparkline('generateSparkline', array('server' => 'server2', 'rand' => mt_rand()));
|
||||
|
||||
return $view->render();
|
||||
}
|
||||
|
||||
public function generateSparkline()
|
||||
{
|
||||
$view = ViewDataTableFactory::build(
|
||||
'sparkline', 'ExampleUI.getTemperaturesEvolution', $controllerAction = 'ExampleUI.generateSparkline');
|
||||
|
||||
$serverRequested = Common::getRequestVar('server', false);
|
||||
if (false !== $serverRequested) {
|
||||
$view->config->columns_to_display = array($serverRequested);
|
||||
}
|
||||
|
||||
return $view->render();
|
||||
}
|
||||
|
||||
public function treemap()
|
||||
{
|
||||
$view = ViewDataTableFactory::build(
|
||||
'infoviz-treemap', 'ExampleUI.getTemperatures', $controllerAction = 'ExampleUI.treemap');
|
||||
|
||||
$view->config->translations['value'] = "Temperature";
|
||||
$view->config->columns_to_display = array("label", "value");
|
||||
$view->config->selectable_columns = array("value");
|
||||
$view->config->show_evolution_values = 0;
|
||||
|
||||
return $view->render();
|
||||
}
|
||||
}
|
||||
55
www/analytics/plugins/ExampleUI/ExampleUI.php
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Piwik\Plugins\ExampleUI;
|
||||
use Piwik\Menu\MenuMain;
|
||||
use Piwik\Menu\MenuTop;
|
||||
|
||||
/**
|
||||
*/
|
||||
class ExampleUI extends \Piwik\Plugin
|
||||
{
|
||||
/**
|
||||
* @see Piwik\Plugin::getListHooksRegistered
|
||||
*/
|
||||
public function getListHooksRegistered()
|
||||
{
|
||||
return array(
|
||||
'Menu.Reporting.addItems' => 'addReportingMenuItems',
|
||||
'Menu.Top.addItems' => 'addTopMenuItems',
|
||||
);
|
||||
}
|
||||
|
||||
function addReportingMenuItems()
|
||||
{
|
||||
MenuMain::getInstance()->add('UI Framework', '', array('module' => 'ExampleUI', 'action' => 'dataTables'), true, 30);
|
||||
|
||||
$this->addSubMenu('Data tables', 'dataTables', 1);
|
||||
$this->addSubMenu('Bar graph', 'barGraph', 2);
|
||||
$this->addSubMenu('Pie graph', 'pieGraph', 3);
|
||||
$this->addSubMenu('Tag clouds', 'tagClouds', 4);
|
||||
$this->addSubMenu('Sparklines', 'sparklines', 5);
|
||||
$this->addSubMenu('Evolution Graph', 'evolutionGraph', 6);
|
||||
|
||||
if (\Piwik\Plugin\Manager::getInstance()->isPluginActivated('TreemapVisualization')) {
|
||||
$this->addSubMenu('Treemap', 'treemap', 7);
|
||||
}
|
||||
}
|
||||
|
||||
function addTopMenuItems()
|
||||
{
|
||||
$urlParams = array('module' => 'ExampleUI', 'action' => 'notifications');
|
||||
MenuTop::getInstance()->addEntry('UI Notifications', $urlParams, $displayedForCurrentUser = true, $order = 3);
|
||||
}
|
||||
|
||||
private function addSubMenu($subMenu, $action, $order)
|
||||
{
|
||||
MenuMain::getInstance()->add('UI Framework', $subMenu, array('module' => 'ExampleUI', 'action' => $action), true, $order);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
Author : Dan Wiersema
|
||||
License: Free for non-commercial use.
|
||||
http://www.iconspedia.com/icon/neptune-4672.html
|
||||
BIN
www/analytics/plugins/ExampleUI/images/icons-planet/earth.png
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
www/analytics/plugins/ExampleUI/images/icons-planet/jupiter.png
Normal file
|
After Width: | Height: | Size: 10 KiB |
BIN
www/analytics/plugins/ExampleUI/images/icons-planet/mars.png
Normal file
|
After Width: | Height: | Size: 9.6 KiB |
BIN
www/analytics/plugins/ExampleUI/images/icons-planet/mercury.png
Normal file
|
After Width: | Height: | Size: 10 KiB |
BIN
www/analytics/plugins/ExampleUI/images/icons-planet/neptune.png
Normal file
|
After Width: | Height: | Size: 9.5 KiB |
BIN
www/analytics/plugins/ExampleUI/images/icons-planet/saturn.png
Normal file
|
After Width: | Height: | Size: 10 KiB |
BIN
www/analytics/plugins/ExampleUI/images/icons-planet/uranus.png
Normal file
|
After Width: | Height: | Size: 10 KiB |
BIN
www/analytics/plugins/ExampleUI/images/icons-planet/venus.png
Normal file
|
After Width: | Height: | Size: 10 KiB |
15
www/analytics/plugins/ExampleUI/plugin.json
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"name": "ExampleUI",
|
||||
"description": "Example Plugin: This plugin showcases the Piwik User Interface framework, how to easily display custom data tables, graphs, and more.",
|
||||
"version": "1.0.1",
|
||||
"keywords": ["example", "framework", "platform", "ui", "visualization"],
|
||||
"homepage": "http://piwik.org",
|
||||
"license": "GPL v3+",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Piwik",
|
||||
"email": "hello@piwik.org",
|
||||
"homepage": "http://piwik.org"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
<h2>Evolution of server temperatures over the last few days</h2>
|
||||
|
||||
{{ evolutionGraph|raw }}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
{% extends 'dashboard.twig' %}
|
||||
|
||||
{% block content %}
|
||||
<h2>Inline notification example:</h2>
|
||||
|
||||
<div style="display:inline-block;margin-top:10px;" id="exampleUI_notifications">
|
||||
{{ 'This is an example for an inline notification. Have you noticed the success message disappeared after a few seconds?'|notification({'placeAt': '#exampleUI_notifications', 'title': 'Info: ', 'noclear': true, 'context': 'info'}) }}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
<div class="sparkline">
|
||||
{{ sparkline(urlSparkline1) }}
|
||||
Evolution of temperature for server piwik.org
|
||||
</div>
|
||||
<div class="sparkline">
|
||||
{{ sparkline(urlSparkline2) }}
|
||||
Evolution of temperature for server dev.piwik.org
|
||||
</div>
|
||||
|
||||