diff --git a/core/ViewDataTable.php b/core/ViewDataTable.php index 8fb9c1f343419097fc80b8dbb8aebc3dea79cc89..7ef7943405f81702a1608c9784875be43fe9e00c 100644 --- a/core/ViewDataTable.php +++ b/core/ViewDataTable.php @@ -61,7 +61,7 @@ use Piwik\Plugins\API\API; class ViewDataTable { /** - * This event is called after a visualization is created. Plugins can use this event to + * This event is called before a visualization is created. Plugins can use this event to * override view properties for individual reports or visualizations. * * Themes can use this event to make sure reports look nice with their themes. Plugins @@ -1038,8 +1038,9 @@ class ViewDataTable protected function buildView() { - $visualization = new $this->visualizationClass($this); Piwik_PostEvent(self::CONFIGURE_VIEW_EVENT, array($this)); + + $visualization = new $this->visualizationClass($this); $this->overrideViewProperties(); try { diff --git a/plugins/TreemapVisualization/Treemap.php b/plugins/TreemapVisualization/Treemap.php index 186c04c7fab70a414865f9e109c8583218b09dd2..615e2a0f54a19a80951d74d7572390a8087247fe 100644 --- a/plugins/TreemapVisualization/Treemap.php +++ b/plugins/TreemapVisualization/Treemap.php @@ -74,7 +74,7 @@ class Treemap extends Graph public static function getDefaultPropertyValues() { $result = parent::getDefaultPropertyValues(); - $result['visualization_properties']['graph']['max_graph_elements'] = 6; + $result['visualization_properties']['graph']['max_graph_elements'] = 10; return $result; } diff --git a/plugins/TreemapVisualization/TreemapVisualization.php b/plugins/TreemapVisualization/TreemapVisualization.php index 49a43f8e98c43c9bc35c9c5b2508c5984feb11a7..60c300e4c930877627c597a4094d4719695f2a81 100644 --- a/plugins/TreemapVisualization/TreemapVisualization.php +++ b/plugins/TreemapVisualization/TreemapVisualization.php @@ -80,6 +80,11 @@ class TreemapVisualization extends \Piwik\Plugin && $view->getViewDataTableId() == Treemap::ID ) { $view->datatable_css_class = 'infoviz-treemap-full-width'; + $view->visualization_properties->max_graph_elements = 50; + } + } else { + if ($view->getViewDataTableId() == Treemap::ID) { + $view->visualization_properties->max_graph_elements = max(10, $view->visualization_properties->max_graph_elements); } } } diff --git a/plugins/TreemapVisualization/javascripts/treemapViz.js b/plugins/TreemapVisualization/javascripts/treemapViz.js index d74f0ec233252561e3e3d649c567c3bbd72fc5ef..e3571bb00119d19b00b2b5a748d1e2c26873e256 100644 --- a/plugins/TreemapVisualization/javascripts/treemapViz.js +++ b/plugins/TreemapVisualization/javascripts/treemapViz.js @@ -63,6 +63,9 @@ onCreateLabel: function (nodeElement, node) { self._initNode(nodeElement, node); }, + onPlaceLabel: function (nodeElement, node) { + self._toggleLabelBasedOnAvailableSpace(nodeElement, node); + }, }); this.data = JSON.parse(treemapContainer.attr('data-data')); @@ -87,6 +90,16 @@ } }, + /** + * Shows/hides the label depending on whether there's enough vertical space in the node + * to show it. + */ + _toggleLabelBasedOnAvailableSpace: function (nodeElement, node) { + var $nodeElement = $(nodeElement), + $label = $nodeElement.children('span'); + $label.toggle($nodeElement.height() > $label.height()); + }, + /** * Alters the ID of each node in tree so it will be unique even if more than one treemap * is displayed. @@ -154,6 +167,10 @@ * Enters a treemap node that is a node for an aggregate row. */ _enterOthersNode: function (node) { + if (node.data.loading) { + return; + } + if (!node.data.loaded) { var self = this; this._loadOthersNodeChildren(node, function (newNode) { @@ -168,6 +185,10 @@ * Enter a treemap node that is a node for a row w/ a subtable. */ _enterSubtable: function (node) { + if (node.data.loading) { + return; + } + if (!node.data.loaded) { var self = this; this._loadSubtableNodeChildren(node, function (newNode) { @@ -206,18 +227,21 @@ action: 'index', apiMethod: this.param.module + '.' + this.param.action, // TODO: will this work for all subtables? format: 'json', - columns: this.param.columns, + column: this.param.columns, filter_truncate: this.props.max_graph_elements - 1, filter_limit: -1 }); // make sure parallel load data requests aren't made - node.data.loaded = dataNode.data.loaded = true; + node.data.loading = dataNode.data.loading = true; var ajax = new ajaxHelper(); ajax.addParams(params, 'get'); ajax.setLoadingElement('#' + self.workingDivId + ' .loadingPiwikBelow'); ajax.setCallback(function (response) { + dataNode.loaded = true; + delete dataNode.loading; + self._prependDataTableIdToNodeIds(self.workingDivId, response); self._setTreemapColors(response);