config->datatable_js_type = 'TreemapDataTable'; $this->config->show_flatten_table = false; $this->config->show_pagination_control = false; $this->config->show_offset_information = false; if ('ExampleUI' == $this->requestConfig->getApiModuleToRequest()) { $this->config->show_evolution_values = false; } if ('Actions' === $this->requestConfig->getApiModuleToRequest()) { $this->configureForActionsReports(); } $this->assignTemplateVar('generator', $this->generator); } public function configureForActionsReports() { $this->config->show_all_views_icons = true; $this->config->show_bar_chart = false; $this->config->show_pie_chart = false; $this->config->show_tag_cloud = false; $method = $this->requestConfig->getApiMethodToRequest(); // for some actions reports, use all available space if (in_array($method, self::$fullWidthActionsReports)) { $this->config->datatable_css_class = 'infoviz-treemap-full-width'; $this->config->max_graph_elements = 50; } else { $this->config->max_graph_elements = max(10, $this->config->max_graph_elements); } self::configureGeneratorIfActionsUrlReport($this->generator, $method); } public static function configureGeneratorIfActionsUrlReport($generator, $method) { if (in_array($method, self::$actionsUrlReports)) { $generator->setLabelFormatter(function ($row, $label) { if ($row->getIdSubDataTable() !== null) { return $label . '/'; } else { return $label; } }); } } public function beforeLoadDataTable() { $this->config->max_graph_elements = false; parent::beforeLoadDataTable(); $metric = $this->getMetricToGraph($this->config->columns_to_display); $translation = empty($this->config->translations[$metric]) ? $metric : $this->config->translations[$metric]; $this->generator = new TreemapDataGenerator($metric, $translation); $filterOffset = $this->requestConfig->filter_offset ? : 0; $this->generator->setInitialRowOffset($filterOffset); $this->handleShowEvolutionValues(); $availableWidth = Common::getRequestVar('availableWidth', false); $availableHeight = Common::getRequestVar('availableHeight', false); $this->generator->setAvailableDimensions($availableWidth, $availableHeight); $this->assignTemplateVar('availableWidth', $availableWidth); $this->assignTemplateVar('availableHeight', $availableHeight); } public function afterGenericFiltersAreAppliedToLoadedDataTable() { $this->generator->truncateBasedOnAvailableSpace($this->getCurrentData($this->dataTable)); } public function beforeGenericFiltersAreAppliedToLoadedDataTable() { $this->config->custom_parameters['columns'] = $this->getMetricToGraph($this->config->columns_to_display); } /** * Checks if the data obtained by ViewDataTable has data or not. Since we get the last period * when calculating evolution, we need this hook to determine if there's data in the latest * table. * * @return bool */ public function isThereDataToDisplay() { return $this->getCurrentData($this->dataTable)->getRowsCount() != 0; } private function getCurrentData($dataTable) { if ($dataTable instanceof Map) { // will be true if calculating evolution values $childTables = $dataTable->getDataTables(); return end($childTables); } else { return $dataTable; } } public function getMetricToGraph($columnsToDisplay) { $firstColumn = reset($columnsToDisplay); if ('label' == $firstColumn) { $firstColumn = next($columnsToDisplay); } return $firstColumn; } private function handleShowEvolutionValues() { // evolution values cannot be calculated if range period is used or subtable is being loaded $period = Common::getRequestVar('period'); if ($period == 'range' || $this->requestConfig->idSubtable ) { return; } if ($this->config->show_evolution_values) { $date = Common::getRequestVar('date'); list($previousDate, $ignore) = Range::getLastDate($date, $period); $this->requestConfig->request_parameters_to_modify['date'] = $previousDate . ',' . $date; $this->generator->showEvolutionValues(); } } }