1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | <?php include_once("../lib/common.inc.php"); echo '<style> div { padding: 5px; display: inline-block; } </style>'; // http://www.herethere.net/~samson/php/color_gradient/color_gradient_generator.php.txt // return the interpolated value between pBegin and pEnd function interpolate($pBegin, $pEnd, $pStep, $pMax) { if ($pBegin < $pEnd) { return (($pEnd - $pBegin) * ($pStep / $pMax)) + $pBegin; } else { return (($pBegin - $pEnd) * (1 - ($pStep / $pMax))) + $pEnd; } } function Gradient($HexFrom, $HexTo, $ColorSteps) { $theColorBegin = hexdec($HexFrom); $theColorEnd = hexdec($HexTo); $theNumSteps = intval($ColorSteps); $theR0 = ($theColorBegin & 0xff0000) >> 16; $theG0 = ($theColorBegin & 0x00ff00) >> 8; $theB0 = ($theColorBegin & 0x0000ff) >> 0; $theR1 = ($theColorEnd & 0xff0000) >> 16; $theG1 = ($theColorEnd & 0x00ff00) >> 8; $theB1 = ($theColorEnd & 0x0000ff) >> 0; $GradientColors = array(); // generate gradient swathe now for ($i = 0; $i <= $theNumSteps; $i++) { $theR = interpolate($theR0, $theR1, $i, $theNumSteps); $theG = interpolate($theG0, $theG1, $i, $theNumSteps); $theB = interpolate($theB0, $theB1, $i, $theNumSteps); $theVal = ((($theR << 8) | $theG) << 8) | $theB; $GradientColors[] = sprintf("%06X", $theVal); } return $GradientColors; } $Gradients = Gradient("66FF00" , "FF0000" , 10); $query = 'select max(sum) from (SELECT sum(heuristic_value) as sum FROM heuristic_results group by "CNID") as a'; $result = $conn->query($query); $r = $result->fetch(); $maxVal = $r[0]; $query = 'SELECT sum(heuristic_value) as sum, "CNID" FROM heuristic_results group by "CNID" order by sum DESC LIMIT 300'; $result = $conn->query($query); foreach ($result->fetchAll() as $r) { echo '<div style="background: #'.$Gradients[floor(($r['sum']/$maxVal) * 10)].';">'; echo '<a title="'.$r['sum'].'" href="../displayContract.php?CNID='.$r['CNID'].'">X</a>'; echo "</div>"; } ?> |