I want to generate heatmap based on clicks for my website in php.
I made an array like below and normalized click counts between 0,1 (1 is for link with the highest click counts):
0 => [
'count' => 290
'normalCount' => 1 //normalized count between 0,1
'link' => 'page/252'
'color' => 'rgb(255, 255, 0)'
]
1 => [
'count' => 277
'normalCount' => 0.95501730103806 //normalized count between 0,1
'link' => '/page/255'
'color' => 'rgb(255, 243.52941176471, 0)'
]
]
2 => [
'count' => 200
'normalCount' => 0.68858131487889
'link' => '/fa/page/253'
'color' => 'rgb(255, 175.58823529412, 0)'
]
]
I used algorithm in this question and passed normalCount index of array to get color of each link.
But It's not generating right color, for example for link "page/252" with normalCount 1, I expect red color(warmest) but it's yellow now.
Below is my function to generate color:
$value = $myArray[$i]['normalCount']
$ratio = $value;
if ($min > 0 || $max < 1) {
if ($value < $min) {
$ratio = 1;
} else if ($value > $max) {
$ratio = 0;
} else {
$range = $min - $max;
$ratio = ($value - $max) / $range;
}
}
$hue = ($ratio * 1.2) / 3.60;
$rgb = $this->ColorHSLToRGB($hue, 1, .5);
$r = round($rgb['r'], 0);
$g = round($rgb['g'], 0);
$b = round($rgb['b'], 0);
return "rgb($r,$g,$b)";