Skip to content

Commit

Permalink
Refs #4041, modify tag cloud ViewDataTable to use _dataTable.twig w/ …
Browse files Browse the repository at this point in the history
…Visualization_Cloud as visualization..
  • Loading branch information
Benaka Moorthi committed Jul 27, 2013
1 parent 48b5de4 commit 93b301d
Show file tree
Hide file tree
Showing 11 changed files with 163 additions and 207 deletions.
35 changes: 35 additions & 0 deletions core/ViewDataTable.php
Expand Up @@ -163,6 +163,7 @@ public function __construct()
$this->viewProperties['request_parameters_to_modify'] = array();
$this->viewProperties['documentation'] = false;
$this->viewProperties['subtable_controller_action'] = false;
$this->viewProperties['datatable_css_class'] = $this->getDefaultDataTableCssClass();
$this->viewProperties['columns_to_display'] = array();

$columns = Piwik_Common::getRequestVar('columns', false);
Expand Down Expand Up @@ -1627,4 +1628,38 @@ private function dataTableColumnsContains($columns, $columnsToCheckFor)

return false;
}

protected function buildView($visualization, $template = false)
{
if ($template === false) {
$template = $this->dataTableTemplate;
}

$view = new Piwik_View($template);

if (!empty($this->loadingError)) {
$view->error = $this->loadingError;
}

$view->visualization = $visualization;

if (!$this->isDataAvailable) {
$view->dataTable = null;
} else {
$view->dataTable = $this->dataTable;

// if it's likely that the report data for this data table has been purged,
// set whether we should display a message to that effect.
$view->showReportDataWasPurgedMessage = $this->hasReportBeenPurged();
$view->deleteReportsOlderThan = Piwik_GetOption('delete_reports_older_than');
}
$view->javascriptVariablesToSet = $this->getJavascriptVariablesToSet();
$view->properties = $this->getViewProperties();
return $view;
}

public function getDefaultDataTableCssClass()
{
return false;
}
}
71 changes: 8 additions & 63 deletions core/ViewDataTable/Cloud.php
Expand Up @@ -18,11 +18,9 @@
*/
class Piwik_ViewDataTable_Cloud extends Piwik_ViewDataTable
{
protected $displayLogoInsteadOfLabel = false;

public function setDisplayLogoInTagCloud($bool)
{
$this->displayLogoInsteadOfLabel = $bool;
$this->viewProperties['display_logo_instead_of_label'] = $bool;
}

protected function getViewDataTableId()
Expand All @@ -33,10 +31,11 @@ protected function getViewDataTableId()
public function __construct()
{
parent::__construct();
$this->dataTableTemplate = '@CoreHome/_dataTableCloud';

$this->dataTableTemplate = '@CoreHome/_dataTable';
$this->disableOffsetInformation();
$this->disableExcludeLowPopulation();
$this->viewProperties['display_logo_instead_of_label'] = false;
}

/**
Expand All @@ -57,65 +56,11 @@ public function main()
} catch (Exception $e) {
$this->isDataAvailable = false;
}
$this->checkStandardDataTable();
$this->view = $this->buildView();
}

/**
* Returns the name of the first numeric column to be displayed
* (second column to be displayed will be returned, as first is always label)
*
* @return string
*/
public function getColumnToDisplay()
{
$columns = parent::getColumnsToDisplay();
// not label, but the first numeric column
return $columns[1];
}

protected function buildView()
{
$view = new Piwik_View($this->dataTableTemplate);
if (!$this->isDataAvailable) {
$view->cloudValues = array();
} else {
$columnToDisplay = $this->getColumnToDisplay();
$columnTranslation = $this->getColumnTranslation($columnToDisplay);
$values = $this->dataTable->getColumn($columnToDisplay);
$labels = $this->dataTable->getColumn('label');
$labelMetadata = array();
foreach ($this->dataTable->getRows() as $row) {
$logo = false;
if ($this->displayLogoInsteadOfLabel) {
$logo = $row->getMetadata('logo');
}
$labelMetadata[$row->getColumn('label')] = array(
'logo' => $logo,
'url' => $row->getMetadata('url'),
);
}
$cloud = new Piwik_Visualization_Cloud();
foreach ($labels as $i => $label) {
$cloud->addWord($label, $values[$i]);
}
$cloudValues = $cloud->render('array');
foreach ($cloudValues as &$value) {
$value['logoWidth'] = round(max(16, $value['percent']));
}
$view->columnTranslation = $columnTranslation;
$view->labelMetadata = $labelMetadata;
$view->cloudValues = $cloudValues;
}
$view->javascriptVariablesToSet = $this->getJavascriptVariablesToSet();
$view->properties = $this->getViewProperties();
$view->reportDocumentation = $this->getReportDocumentation();

// if it's likely that the report data for this data table has been purged,
// set whether we should display a message to that effect.
$view->showReportDataWasPurgedMessage = $this->hasReportBeenPurged();
$view->deleteReportsOlderThan = Piwik_GetOption('delete_reports_older_than');
$this->checkStandardDataTable();
$this->postDataTableLoadedFromAPI();

return $view;
$visualization = new Piwik_Visualization_Cloud();
$this->view = $this->buildView($visualization);
}
}
34 changes: 3 additions & 31 deletions core/ViewDataTable/HtmlTable.php
Expand Up @@ -40,7 +40,6 @@ public function __construct()
$this->handleLowPopulation();
$this->setSubtableTemplate("@CoreHome/_dataTable.twig");
$this->viewProperties['datatable_js_type'] = 'dataTable';
$this->viewProperties['datatable_css_class'] = $this->getDefaultDataTableCssClass();
}

public function getJavaScriptProperties()
Expand Down Expand Up @@ -80,7 +79,9 @@ public function main()
}

$this->postDataTableLoadedFromAPI();
$this->view = $this->buildView();

$template = $this->idSubtable ? $this->viewProperties['subtable_template'] : $this->dataTableTemplate;
$this->view = $this->buildView(new Piwik_Visualization_HtmlTable(), $template);
}

public function getDefaultDataTableCssClass()
Expand Down Expand Up @@ -108,35 +109,6 @@ public function showExpanded()
$this->viewProperties['show_expanded'] = true;
}

/**
* @return Piwik_View with all data set
*/
protected function buildView()
{
$template = $this->idSubtable ? $this->viewProperties['subtable_template'] : $this->dataTableTemplate;
$view = new Piwik_View($template);

if (!empty($this->loadingError)) {
$view->error = $this->loadingError;
}

$view->visualization = new Piwik_Visualization_HtmlTable($this->viewProperties);

if (!$this->isDataAvailable) {
$view->dataTable = null;
} else {
$view->dataTable = $this->dataTable;

// if it's likely that the report data for this data table has been purged,
// set whether we should display a message to that effect.
$view->showReportDataWasPurgedMessage = $this->hasReportBeenPurged();
$view->deleteReportsOlderThan = Piwik_GetOption('delete_reports_older_than');
}
$view->javascriptVariablesToSet = $this->getJavascriptVariablesToSet();
$view->properties = $this->getViewProperties();
return $view;
}

protected function handleLowPopulation($columnToApplyFilter = null)
{
if (Piwik_Common::getRequestVar('enable_filter_excludelowpop', '0', 'string') == '0') {
Expand Down
44 changes: 41 additions & 3 deletions core/Visualization/Cloud.php
Expand Up @@ -18,7 +18,7 @@
* @package Piwik
* @subpackage Piwik_Visualization
*/
class Piwik_Visualization_Cloud implements Piwik_View_Interface
class Piwik_Visualization_Cloud
{
/** Used by integration tests to make sure output is consistent. */
public static $debugDisableShuffle = false;
Expand All @@ -32,7 +32,7 @@ class Piwik_Visualization_Cloud implements Piwik_View_Interface
* @param int $value
* @return string
*/
function addWord($word, $value = 1)
public function addWord($word, $value = 1)
{
if (isset($this->wordsArray[$word])) {
$this->wordsArray[$word] += $value;
Expand All @@ -41,7 +41,45 @@ function addWord($word, $value = 1)
}
}

public function render()
/**
* Renders this visualization.
*
* @param Piwik_DataTable $dataTable
*/
public function render($dataTable, $properties)
{
$view = new Piwik_View("@CoreHome/_dataTableViz_tagCloud.twig");
$view->properties = $properties;

$columnToDisplay = $properties['columns_to_display'][1];

$labelMetadata = array();
foreach ($dataTable->getRows() as $row) {
$logo = false;
if ($properties['display_logo_instead_of_label']) {
$logo = $row->getMetadata('logo');
}

$label = $row->getColumn('label');

$labelMetadata[$label] = array(
'logo' => $logo,
'url' => $row->getMetadata('url'),
);

$this->addWord($label, $row->getColumn($columnToDisplay));
}
$cloudValues = $this->getCloudValues();
foreach ($cloudValues as &$value) {
$value['logoWidth'] = round(max(16, $value['percent']));
}
$view->labelMetadata = $labelMetadata;
$view->cloudValues = $cloudValues;

return $view->render();
}

private function getCloudValues()
{
$this->shuffleCloud();
$return = array();
Expand Down
21 changes: 2 additions & 19 deletions core/Visualization/HtmlTable.php
Expand Up @@ -14,32 +14,15 @@
*/
class Piwik_Visualization_HtmlTable
{
/**
* View properties.
*
* @var array
*/
private $properties;

/**
* Constructor.
*
* @param array $viewProperties
*/
public function __construct($viewProperties)
{
$this->properties = $viewProperties;
}

/**
* Renders this visualization.
*
* @param Piwik_DataTable $dataTable
*/
public function render($dataTable)
public function render($dataTable, $properties)
{
$view = new Piwik_View("@CoreHome/_dataTableViz_htmlTable.twig");
$view->properties = $this->properties;
$view->properties = $properties;
$view->dataTable = $dataTable;
return $view->render();
}
Expand Down

0 comments on commit 93b301d

Please sign in to comment.