Skip to content

Commit

Permalink
Normalise data set
Browse files Browse the repository at this point in the history
This update would normalise the data set so that the values are offset by the minimum value, so that 101, 102, 103 become 1, 2, 3

Closes #3
  • Loading branch information
jamiebicknell committed Dec 29, 2017
1 parent 31609c6 commit 852a799
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion sparkline.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,21 @@ function hexToRgb($hex)
$h *= $s;
$t *= $s;

$salt = 'v1.0.0';
$salt = 'v1.0.1';
$hash = md5($salt . $_SERVER['QUERY_STRING']);

$data = (count($data) < 2) ? array_fill(0, 2, $data[0]) : $data;
$count = count($data);
$step = $w / ($count - 1);

$min = min($data);
$max = max($data);
if ($max != $min) {
foreach ($data as $k => $v) {
$data[$k] -= $min;
}
$max = max($data);
}

if (!extension_loaded('gd')) {
die('GD extension is not installed');
Expand Down

0 comments on commit 852a799

Please sign in to comment.