title: Generating heatmap color base on clicks in php
body: <p>I want to generate heatmap based on clicks for my website in php.</p>
  
  <p>I made an array like below and normalized click counts between 0,1 (1 is for link with the highest click counts):</p>
  
  <pre><code>0 =&gt; [
      'count' =&gt; 290
      'normalCount' =&gt; 1 //normalized count between 0,1
      'link' =&gt; 'page/252'
      'color' =&gt; 'rgb(255, 255, 0)'
  ]
  1 =&gt; [
      'count' =&gt; 277
      'normalCount' =&gt; 0.95501730103806 //normalized count between 0,1
      'link' =&gt; '/page/255'
      'color' =&gt; 'rgb(255, 243.52941176471, 0)'
      ]
  ]
  2 =&gt; [
      'count' =&gt; 200
      'normalCount' =&gt; 0.68858131487889
      'link' =&gt; '/fa/page/253'
      'color' =&gt; 'rgb(255, 175.58823529412, 0)'
      ]
  ]
  </code></pre>
  
  <p>I used algorithm in <a href="https://stackoverflow.com/questions/35848025/php-red-to-green-rgb-color-heatmap">this question</a> and passed normalCount index of array to get color of each link.</p>
  
  <p>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.  </p>
  
  <p>Below is my function to generate color:</p>
  
  <pre><code>$value = $myArray[$i]['normalCount']
  $ratio = $value;
  if ($min &gt; 0 || $max &lt; 1) {
      if ($value &lt; $min) {
          $ratio = 1;
      } else if ($value &gt; $max) {
          $ratio = 0;
      } else {
          $range = $min - $max;
          $ratio = ($value - $max) / $range;
      }
  }
  
  $hue = ($ratio * 1.2) / 3.60;
  $rgb = $this-&gt;ColorHSLToRGB($hue, 1, .5);
  
  $r = round($rgb['r'], 0);
  $g = round($rgb['g'], 0);
  $b = round($rgb['b'], 0);
  
  return "rgb($r,$g,$b)";
  </code></pre>