NxTIC/test-charts/network.php

63 lines
1.6 KiB
PHP
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php define('__ROOT__', dirname(dirname(__FILE__)) );
require_once __ROOT__.'/manager/autoloader.php';
use \manager\ModuleRequest;
use \manager\ManagerError;
debug();
?>
<!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();
if( $res->error != ManagerError::Success )
var_dump( ManagerError::explicit($res->error) );
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
=========================================================*/
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]);
}
echo "</svg>";
?>
</body>
</html>