/** Prepare metrics toggles with spark lines */ protected function getMetricsToggles($controller) { // calculate meta-metrics $subDataTables = $this->dataTable->getArray(); $firstDataTable = current($subDataTables); $firstDataTableRow = $firstDataTable->getFirstRow(); $lastDataTable = end($subDataTables); $lastDataTableRow = $lastDataTable->getFirstRow(); $maxValues = array(); $minValues = array(); foreach ($subDataTables as $subDataTable) { // $subDataTable is the report for one period, it has only one row $firstRow = $subDataTable->getFirstRow(); foreach ($this->availableMetrics as $metric => $label) { $value = $firstRow ? floatval($firstRow->getColumn($metric)) : 0; if (!isset($minValues[$metric]) || $minValues[$metric] > $value) { $minValues[$metric] = $value; } if (!isset($maxValues[$metric]) || $maxValues[$metric] < $value) { $maxValues[$metric] = $value; } } } $chart = new Piwik_Visualization_Chart_Evolution(); $colors = $chart->getSeriesColors(); // put together metric info $i = 0; $metrics = array(); foreach ($this->availableMetrics as $metric => $label) { if ($maxValues[$metric] == 0 && !$this instanceof Piwik_CoreHome_DataTableAction_MultiRowEvolution) { // series with only 0 cause trouble in js continue; } $first = $firstDataTableRow ? floatval($firstDataTableRow->getColumn($metric)) : 0; $last = $lastDataTableRow ? floatval($lastDataTableRow->getColumn($metric)) : 0; $changePercent = $first > 0 ? round($last / $first * 100 - 100) : 100; $changePercentHtml = $changePercent . '%'; if ($changePercent > 0) { $changePercentHtml = '+' . $changePercentHtml; $changeClass = 'up'; $changeImage = 'arrow_up'; } else { $changeClass = $changePercent < 0 ? 'down' : 'nochange'; $changeImage = $changePercent < 0 ? 'arrow_down' : false; } $changePercentHtml = '<span class="' . $changeClass . '">' . ($changeImage ? '<img src="plugins/MultiSites/images/' . $changeImage . '.png" /> ' : '') . $changePercentHtml . '</span>'; $details = Piwik_Translate('RowEvolution_MetricDetailsText', array($minValues[$metric], $maxValues[$metric], $changePercentHtml)); $color = $colors[$i % count($colors)]; $metrics[] = array('label' => $label, 'color' => $color, 'details' => $details, 'sparkline' => $this->getSparkline($metric, $controller)); $i++; } return $metrics; }
/** Prepare metrics toggles with spark lines */ protected function getMetricsToggles($controller) { $chart = new Piwik_Visualization_Chart_Evolution(); $colors = $chart->getSeriesColors(); $i = 0; $metrics = array(); foreach ($this->availableMetrics as $metric => $metricData) { $max = $metricData['max']; $min = $metricData['min']; $change = $metricData['change']; if ($max == 0 && !$this instanceof Piwik_CoreHome_DataTableAction_MultiRowEvolution) { // series with only 0 cause trouble in js continue; } if (substr($change, 0, 1) == '+') { $changeClass = 'up'; $changeImage = 'arrow_up'; } else { if (substr($change, 0, 1) == '-') { $changeClass = 'down'; $changeImage = 'arrow_down'; } else { $changeClass = 'nochange'; $changeImage = false; } } $change = '<span class="' . $changeClass . '">' . ($changeImage ? '<img src="plugins/MultiSites/images/' . $changeImage . '.png" /> ' : '') . $change . '</span>'; $details = Piwik_Translate('RowEvolution_MetricDetailsText', array($min, $max, $change)); $color = $colors[$i % count($colors)]; $metrics[] = array('label' => $metricData['name'], 'color' => $color, 'details' => $details, 'sparkline' => $this->getSparkline($metric, $controller)); $i++; } return $metrics; }
/** * Prepare metrics toggles with spark lines * @param $controller * @return array */ protected function getMetricsToggles($controller) { $chart = new Piwik_Visualization_Chart_Evolution(); $colors = $chart->getSeriesColors(); $i = 0; $metrics = array(); foreach ($this->availableMetrics as $metric => $metricData) { $max = isset($metricData['max']) ? $metricData['max'] : 0; $min = isset($metricData['min']) ? $metricData['min'] : 0; $change = isset($metricData['change']) ? $metricData['change'] : false; $unit = Piwik_API_API::getUnit($metric, $this->idSite); $min .= $unit; $max .= $unit; $details = Piwik_Translate('RowEvolution_MetricBetweenText', array($min, $max)); if ($change !== false) { $lowerIsBetter = Piwik_API_API::isLowerValueBetter($metric); if (substr($change, 0, 1) == '+') { $changeClass = $lowerIsBetter ? 'bad' : 'good'; $changeImage = $lowerIsBetter ? 'arrow_up_red' : 'arrow_up'; } else { if (substr($change, 0, 1) == '-') { $changeClass = $lowerIsBetter ? 'good' : 'bad'; $changeImage = $lowerIsBetter ? 'arrow_down_green' : 'arrow_down'; } else { $changeClass = 'neutral'; $changeImage = false; } } $change = '<span class="' . $changeClass . '">' . ($changeImage ? '<img src="plugins/MultiSites/images/' . $changeImage . '.png" /> ' : '') . $change . '</span>'; $details .= ', ' . Piwik_Translate('RowEvolution_MetricChangeText', $change); } $color = $colors[$i % count($colors)]; $newMetric = array('label' => $metricData['name'], 'color' => $color, 'details' => $details, 'sparkline' => $this->getSparkline($metric, $controller)); // Multi Rows, each metric can be for a particular row and display an icon if (!empty($metricData['logo'])) { $newMetric['logo'] = $metricData['logo']; } $metrics[] = $newMetric; $i++; } return $metrics; }