|
|
<?php
|
|
|
|
|
|
use codeagent\treemap\Treemap;
|
|
|
use codeagent\treemap\presenter\ImagePresenter;
|
|
|
use codeagent\treemap\presenter\NodeInfo;
|
|
|
use codeagent\treemap\Gradient;
|
|
|
|
|
|
// ---
|
|
|
// --- Local fonctions
|
|
|
// ---
|
|
|
function rgb2hex($rgb) {
|
|
|
$hex = "#";
|
|
|
$hex .= str_pad(dechex($rgb[0]), 2, "0", STR_PAD_LEFT);
|
|
|
$hex .= str_pad(dechex($rgb[1]), 2, "0", STR_PAD_LEFT);
|
|
|
$hex .= str_pad(dechex($rgb[2]), 2, "0", STR_PAD_LEFT);
|
|
|
|
|
|
return $hex; // returns the hex value including the number sign (#)
|
|
|
}
|
|
|
|
|
|
function hex2rgb($color){
|
|
|
$color = str_replace('#', '', $color);
|
|
|
if (strlen($color) != 6){ return array(0,0,0); }
|
|
|
$rgb = array();
|
|
|
for ($x=0;$x<3;$x++){
|
|
|
$rgb[$x] = hexdec(substr($color,(2*$x),2));
|
|
|
}
|
|
|
return $rgb;
|
|
|
}
|
|
|
|
|
|
class topisto_treemap
|
|
|
{
|
|
|
private static function getRGB($methode, $gradient, $factor)
|
|
|
{
|
|
|
switch($methode)
|
|
|
{
|
|
|
case 0:
|
|
|
$rgb = [rand(0,255),rand(0,255),rand(0,255)];
|
|
|
break;
|
|
|
|
|
|
case 1:
|
|
|
$rgb = [80,80,80];
|
|
|
break;
|
|
|
|
|
|
case 2:
|
|
|
$factor=rand(0,100);
|
|
|
$rgb = [255,255,255];
|
|
|
if ($factor < 50 ) $rgb = [255,0,0];
|
|
|
if ($factor < 25 ) $rgb = [0,0,255];
|
|
|
if ($factor < 10 ) $rgb = [255,255,0];
|
|
|
break;
|
|
|
|
|
|
case 3:
|
|
|
$rgb = hex2rgb($gradient[1]->color($factor));
|
|
|
break;
|
|
|
|
|
|
case 4:
|
|
|
$rgb = hex2rgb($gradient[2]->color($factor));
|
|
|
break;
|
|
|
|
|
|
case 999:
|
|
|
$rgb = hex2rgb($gradient[3]->color($factor));
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
$rgb = hex2rgb($gradient[0]->color($factor));
|
|
|
}
|
|
|
|
|
|
return $rgb;
|
|
|
}
|
|
|
|
|
|
public static function DrawBlock($the_block, $vImage, $parametres)
|
|
|
{
|
|
|
$type = 1;
|
|
|
|
|
|
if (isset($parametres['x'])) $x = $parametres['x'];
|
|
|
if (isset($parametres['y'])) $y = $parametres['y'];
|
|
|
if (isset($parametres['width'])) $width = $parametres['width'];
|
|
|
if (isset($parametres['height'])) $height = $parametres['height'];
|
|
|
if (isset($parametres['methode'])) $mode = $parametres['methode'];
|
|
|
if (isset($parametres['type'])) $type = $parametres['type'];
|
|
|
if (isset($parametres['font_color'])) $vBgColor = $parametres['font_color'];
|
|
|
if (isset($parametres['background_color'])) $vFgColor = $parametres['background_color'];
|
|
|
|
|
|
imagefilledrectangle($vImage, $x, $y, $x+$width, $y+$height, $vFgColor);
|
|
|
|
|
|
$full_area = $width * $height;
|
|
|
if ($full_area == 0) $full_area = 1;
|
|
|
|
|
|
$data = blockchain::getTransactionData($the_block, $type);
|
|
|
|
|
|
$treemap = new Treemap($data, $width, $height);
|
|
|
$map = $treemap->getMap();
|
|
|
$m = count($map);
|
|
|
$flag_contour = true;
|
|
|
for($mm = 0; $mm < $m; $mm++)
|
|
|
{
|
|
|
$tx = $map[$mm];
|
|
|
$factor = (($tx['_rectangle']->width * $tx['_rectangle']->height) / $full_area)*100.0;
|
|
|
|
|
|
$x1 = $x + $tx['_rectangle']->left;
|
|
|
$y1 = $y + $tx['_rectangle']->top;
|
|
|
|
|
|
$x2 = $x1 + $tx['_rectangle']->width;
|
|
|
$y2 = $y1 + $tx['_rectangle']->height;
|
|
|
|
|
|
if ($x1 > ($x+$width)) $x1 = ($x+$width);
|
|
|
if ($y1 > ($y+$height)) $y1 = ($y+$height);
|
|
|
if ($x2 > ($x+$width)) $x2 = ($x+$width);
|
|
|
if ($y2 > ($y+$height)) $y2 = ($y+$height);
|
|
|
|
|
|
imagerectangle($vImage, $x1, $y1, $x2, $y2, $vBgColor);
|
|
|
}
|
|
|
|
|
|
imagerectangle($vImage, $x, $y, $x+$width-1, $y+$height, $vBgColor);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
?>
|