NxTIC/test-charts/network.php

63 lines
1.6 KiB
PHP
Raw Permalink Normal View History

<?php define('__ROOT__', dirname(dirname(__FILE__)) );
require_once __ROOT__.'/manager/autoloader.php';
use \manager\ModuleRequest;
use \manager\ManagerError;
debug();
?>
2016-05-25 17:03:13 +00:00
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Chart réseau</title>
<script type='text/javascript' src='/f/js/api-min/js/lib'></script> <!-- Gestion des transactions avec le serveur -->
</head>
<body style='display: flex; flex-direction: row; justify-content: space-around; flex-wrap: wrap;'>
<?php
/* [1] On récupère les données
=========================================================*/
$req = new ModuleRequest('chart/network', array('subject'=>1/*273*/));
$res = $req->dispatch();
2016-05-25 17:03:13 +00:00
if( $res->error != ManagerError::Success )
var_dump( ManagerError::explicit($res->error) );
2016-05-25 17:03:13 +00:00
var_dump($res->getAll());
/* [2] Gestion spatiale
=========================================================*/
function dot(&$node, $x, $y){
$node['x'] = $x;
$node['y'] = $y;
return "<circle cx='$x' cy='$y' r='5' fill='".(($node['type']=='phone')?'#1db247':'#4891df')."'/>";
}
/* [3] On affiche le contenu
=========================================================*/
2016-05-25 17:03:13 +00:00
echo "<?xml version='1.0' encoding='UTF-8' standalone='no'?>";
echo "<svg version='1.1' width='1000' height='1000' style='width: 40em; height: 40em;border:1px solid black'>";
$nodes = $res->get('nodes');
foreach($nodes as $n=>$node){
$r = array( floor(rand(10, 990)), floor(rand(10, 990)) );
echo dot($nodes[$n], $r[0], $r[1]);
}
2016-05-25 17:03:13 +00:00
echo "</svg>";
?>
</body>
</html>