diff options
author | diosmosis <diosmosis@users.noreply.github.com> | 2019-03-12 08:04:41 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-12 08:04:41 +0300 |
commit | 7edf461477aa2f732c3e1fda506d7a476d93b62d (patch) | |
tree | ee19bdeaf131d691967d3719d4eee6a46a6a94a0 /plugins/CoreHome/DataTableRowAction | |
parent | 88aa9391c6fcb0282656a7d7f31728fa6e57980c (diff) |
Sparklines do not show correct values if values are close to 1.0. (#14006)
* Scale sparkline values if they have floats.
* Coerce value to int/float.
* Check if numeric before coercing.
* In RowEvoluton format fractional values correctly.
* updates screenshots
Diffstat (limited to 'plugins/CoreHome/DataTableRowAction')
-rw-r--r-- | plugins/CoreHome/DataTableRowAction/RowEvolution.php | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/plugins/CoreHome/DataTableRowAction/RowEvolution.php b/plugins/CoreHome/DataTableRowAction/RowEvolution.php index 0fc5e880fb..4e33840894 100644 --- a/plugins/CoreHome/DataTableRowAction/RowEvolution.php +++ b/plugins/CoreHome/DataTableRowAction/RowEvolution.php @@ -236,9 +236,11 @@ class RowEvolution $change = isset($metricData['change']) ? $metricData['change'] : false; list($first, $last) = $this->getFirstAndLastDataPointsForMetric($metric); + $fractionDigits = max($this->getFractionDigits($first), $this->getFractionDigits($last)); + $details = Piwik::translate('RowEvolution_MetricBetweenText', array( - NumberFormatter::getInstance()->format($first) . $unit, - NumberFormatter::getInstance()->format($last) . $unit + NumberFormatter::getInstance()->format($first, $fractionDigits, $fractionDigits) . $unit, + NumberFormatter::getInstance()->format($last, $fractionDigits, $fractionDigits) . $unit, )); if ($change !== false) { @@ -264,12 +266,10 @@ class RowEvolution // 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) + NumberFormatter::getInstance()->formatNumber($min, $fractionDigits, $fractionDigits) . $unit, + NumberFormatter::getInstance()->formatNumber($max, $fractionDigits, $fractionDigits) . $unit, )); $newMetric = array( @@ -367,4 +367,11 @@ class RowEvolution } return $rowLabel; } + + private function getFractionDigits($value) + { + $value = (string) $value; + $fraction = substr(strrchr($value, "."), 1); + return strlen($fraction); + } } |