protected function initChartObjectData() { // if the loaded datatable is a simple DataTable, it is most likely a plugin plotting some custom data // we don't expect plugin developers to return a well defined Piwik_DataTable_Array if ($this->dataTable instanceof Piwik_DataTable) { return parent::initChartObjectData(); } $this->dataTable->applyQueuedFilters(); if (!$this->dataTable instanceof Piwik_DataTable_Array) { throw new Exception("Expecting a DataTable_Array with custom format to draw an evolution chart"); } // the X label is extracted from the 'period' object in the table's metadata $xLabels = $uniqueIdsDataTable = array(); foreach ($this->dataTable->getArray() as $idDataTable => $metadataDataTable) { //eg. "Aug 2009" $xLabels[] = $metadataDataTable->getMetadata('period')->getLocalizedShortString(); // we keep track of all unique data table that we need to set a Y value for $uniqueIdsDataTable[] = $idDataTable; } $idSite = Piwik_Common::getRequestVar('idSite', null, 'int'); $requestedColumnNames = $this->getColumnsToDisplay(); $units = $this->getUnitsForColumnsToDisplay(); $yAxisLabelToUnit = array(); $yAxisLabelToValue = array(); foreach ($this->dataTable->getArray() as $idDataTable => $dataTable) { foreach ($dataTable->getRows() as $row) { $rowLabel = $row->getColumn('label'); // put together configuration for row picker. // do this for every data table in the array because rows do not // have to present for each date. if ($this->rowPicker !== false) { $rowVisible = $this->handleRowForRowPicker($rowLabel); if (!$rowVisible) { continue; } } // build data for request columns foreach ($requestedColumnNames as $requestedColumnName) { $yAxisLabel = $this->getSeriesLabel($rowLabel, $requestedColumnName); if (($columnValue = $row->getColumn($requestedColumnName)) !== false) { $yAxisLabelToValue[$yAxisLabel][$idDataTable] = $columnValue; $yAxisLabelToUnit[$yAxisLabel] = $units[$requestedColumnName]; } } } } // make sure all column values are set to at least zero (no gap in the graph) $yAxisLabelToValueCleaned = array(); foreach ($uniqueIdsDataTable as $uniqueIdDataTable) { foreach ($yAxisLabelToValue as $yAxisLabel => $idDataTableToColumnValue) { if (isset($idDataTableToColumnValue[$uniqueIdDataTable])) { $columnValue = $idDataTableToColumnValue[$uniqueIdDataTable]; } else { $columnValue = 0; } $yAxisLabelToValueCleaned[$yAxisLabel][] = $columnValue; } } $this->view->setAxisXLabels($xLabels); $this->view->setAxisYValues($yAxisLabelToValueCleaned); $this->view->setAxisYUnits($yAxisLabelToUnit); $countGraphElements = $this->dataTable->getRowsCount(); $dataTables = $this->dataTable->getArray(); $firstDatatable = reset($dataTables); $period = $firstDatatable->getMetadata('period'); $stepSize = $this->getXAxisStepSize($period->getLabel(), $countGraphElements); $this->view->setXSteps($stepSize); if ($this->isLinkEnabled()) { $axisXOnClick = array(); $queryStringAsHash = $this->getQueryStringAsHash(); foreach ($this->dataTable->getArray() as $idDataTable => $metadataDataTable) { $period = $metadataDataTable->getMetadata('period'); $dateInUrl = $period->getDateStart(); $parameters = array('idSite' => $idSite, 'period' => $period->getLabel(), 'date' => $dateInUrl->toString(), 'segment' => Piwik_ViewDataTable::getRawSegmentFromRequest()); $hash = ''; if (!empty($queryStringAsHash)) { $hash = '#' . Piwik_Url::getQueryStringFromParameters($queryStringAsHash + $parameters); } $link = 'index.php?' . Piwik_Url::getQueryStringFromParameters(array('module' => 'CoreHome', 'action' => 'index') + $parameters) . $hash; $axisXOnClick[] = $link; } $this->view->setAxisXOnClick($axisXOnClick); } $this->addSeriesPickerToView(); if ($this->rowPicker !== false) { // configure the row picker $this->view->setSelectableRows(array_values($this->rowPickerConfig)); } }