protected function getUnitsForColumnsToDisplay() { // the bar charts contain the labels a first series // this series has to be removed from the units $units = parent::getUnitsForColumnsToDisplay(); array_shift($units); return $units; }
/** * Manipulate the configuration of the series picker since only one metric is selectable * for pie charts * @param bool $multiSelect */ protected function addSeriesPickerToView($multiSelect = false) { // force $multiSelect=false parent::addSeriesPickerToView(false); }
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->metadata as $idDataTable => $metadataDataTable) { //eg. "Aug 2009" $xLabels[] = $metadataDataTable['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(); $firstDatatable = reset($this->dataTable->metadata); $period = $firstDatatable['period']; switch ($period->getLabel()) { case 'day': $steps = 7; break; case 'week': $steps = 10; break; case 'month': $steps = 6; break; case 'year': $steps = 2; break; default: $steps = 10; break; } // For Custom Date Range, when the number of elements plotted can be small, make sure the X legend is useful if ($countGraphElements <= 20) { $steps = 2; } $this->view->setXSteps($steps); if ($this->isLinkEnabled()) { $axisXOnClick = array(); $queryStringAsHash = $this->getQueryStringAsHash(); foreach ($this->dataTable->metadata as $idDataTable => $metadataDataTable) { $period = $metadataDataTable['period']; $dateInUrl = $period->getDateStart(); $parameters = array('idSite' => $idSite, 'period' => $period->getLabel(), 'date' => $dateInUrl->toString()); $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)); } }
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->metadata as $idDataTable => $metadataDataTable) { //eg. "Aug 2009" $xLabels[] = html_entity_decode($metadataDataTable['period']->getLocalizedShortString(), ENT_COMPAT, 'UTF-8'); // we keep track of all unique data table that we need to set a Y value for $uniqueIdsDataTable[] = $idDataTable; } $requestedColumnNames = $this->getColumnsToDisplay(); $yAxisLabelToValue = array(); foreach ($this->dataTable->getArray() as $idDataTable => $dataTable) { foreach ($dataTable->getRows() as $row) { $rowLabel = $row->getColumn('label'); foreach ($requestedColumnNames as $requestedColumnName) { $metricLabel = $this->getColumnTranslation($requestedColumnName); if ($rowLabel !== false) { // eg. "Yahoo! (Visits)" $yAxisLabel = "{$rowLabel} ({$metricLabel})"; } else { // eg. "Visits" $yAxisLabel = $metricLabel; } if (($columnValue = $row->getColumn($requestedColumnName)) !== false) { $yAxisLabelToValue[$yAxisLabel][$idDataTable] = $columnValue; } } } } // make sure all column values are set to at least zero (no gap in the graph) $yAxisLabelToValueCleaned = array(); $yAxisLabels = array(); foreach ($uniqueIdsDataTable as $uniqueIdDataTable) { foreach ($yAxisLabelToValue as $yAxisLabel => $idDataTableToColumnValue) { $yAxisLabels[$yAxisLabel] = $yAxisLabel; if (isset($idDataTableToColumnValue[$uniqueIdDataTable])) { $columnValue = $idDataTableToColumnValue[$uniqueIdDataTable]; } else { $columnValue = 0; } $yAxisLabelToValueCleaned[$yAxisLabel][] = $columnValue; } } $unit = $this->yAxisUnit; if (empty($unit)) { $unit = $this->guessUnitFromRequestedColumnNames($requestedColumnNames); } $this->view->setAxisXLabels($xLabels); $this->view->setAxisYValues($yAxisLabelToValueCleaned); $this->view->setAxisYLabels($yAxisLabels); $this->view->setAxisYUnit($unit); $firstDatatable = reset($this->dataTable->metadata); $period = $firstDatatable['period']; switch ($period->getLabel()) { case 'day': $steps = 7; break; case 'week': $steps = 10; break; case 'month': $steps = 6; break; case 'year': $steps = 2; break; default: $steps = 10; break; } $this->view->setXSteps($steps); if ($this->isLinkEnabled()) { $axisXOnClick = array(); foreach ($this->dataTable->metadata as $idDataTable => $metadataDataTable) { $period = $metadataDataTable['period']; $dateInUrl = $period->getDateStart(); $link = Piwik_Url::getCurrentUrlWithoutQueryString() . '?' . Piwik_Url::getQueryStringFromParameters(array('module' => 'CoreHome', 'action' => 'index', 'idSite' => Piwik_Common::getRequestVar('idSite'), 'period' => $period->getLabel(), 'date' => $dateInUrl)); $axisXOnClick[] = $link; } $this->view->setAxisXOnClick($axisXOnClick); } }