/** * @dataProvider getLowerValuesBetter * @group Core */ public function testIsLowerValueBetter($column, $expected) { $actual = Metrics::isLowerValueBetter($column); $this->assertEquals($expected, $actual); }
/** * Prepare metrics toggles with spark lines * @return array */ protected function getMetricsToggles() { $i = 0; $metrics = array(); foreach ($this->availableMetrics as $metric => $metricData) { $unit = Metrics::getUnit($metric, $this->idSite); $change = isset($metricData['change']) ? $metricData['change'] : false; list($first, $last) = $this->getFirstAndLastDataPointsForMetric($metric); $details = Piwik::translate('RowEvolution_MetricBetweenText', array(NumberFormatter::getInstance()->format($first), NumberFormatter::getInstance()->format($last))); if ($change !== false) { $lowerIsBetter = Metrics::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); } // set metric min/max text (used as tooltip for details) $max = isset($metricData['max']) ? $metricData['max'] : 0; $min = isset($metricData['min']) ? $metricData['min'] : 0; $min .= $unit; $max .= $unit; $minmax = Piwik::translate('RowEvolution_MetricMinMax', array($metricData['name'], NumberFormatter::getInstance()->formatNumber($min), NumberFormatter::getInstance()->formatNumber($max))); $newMetric = array('label' => $metricData['name'], 'details' => $details, 'minmax' => $minmax, 'sparkline' => $this->getSparkline($metric)); // Multi Rows, each metric can be for a particular row and display an icon if (!empty($metricData['logo'])) { $newMetric['logo'] = $metricData['logo']; } // TODO: this check should be determined by metric metadata, not hardcoded here if ($metric == 'nb_users' && $first == 0 && $last == 0) { $newMetric['hide'] = true; } $metrics[] = $newMetric; $i++; } return $metrics; }