function pSpring::firstPass in Visitors 7
Same name and namespace in other branches
- 7.2 pChart/class/pSpring.class.php \pSpring::firstPass()
1 call to pSpring::firstPass()
- pSpring::drawSpring in pChart/
class/ pSpring.class.php
File
- pChart/
class/ pSpring.class.php, line 294
Class
Code
function firstPass($Algorithm) {
$CenterX = ($this->X2 - $this->X1) / 2 + $this->X1;
$CenterY = ($this->Y2 - $this->Y1) / 2 + $this->Y1;
/* Check connections reciprocity */
foreach ($this->Data as $Key => $Settings) {
if (isset($Settings["Connections"])) {
foreach ($Settings["Connections"] as $ID => $ConnectionID) {
$this
->checkConnection($ConnectionID, $Key);
}
}
}
if ($this->AutoComputeFreeZone) {
$this
->autoFreeZone();
}
/* Get the max number of connections */
$MaxConnections = 0;
foreach ($this->Data as $Key => $Settings) {
if (isset($Settings["Connections"])) {
if ($MaxConnections < count($Settings["Connections"])) {
$MaxConnections = count($Settings["Connections"]);
}
}
}
if ($Algorithm == ALGORITHM_WEIGHTED) {
foreach ($this->Data as $Key => $Settings) {
if ($Settings["Type"] == NODE_TYPE_CENTRAL) {
$this->Data[$Key]["X"] = $CenterX;
$this->Data[$Key]["Y"] = $CenterY;
}
if ($Settings["Type"] == NODE_TYPE_FREE) {
if (isset($Settings["Connections"])) {
$Connections = count($Settings["Connections"]);
}
else {
$Connections = 0;
}
$Ring = $MaxConnections - $Connections;
$Angle = rand(0, 360);
$this->Data[$Key]["X"] = cos(deg2rad($Angle)) * ($Ring * $this->RingSize) + $CenterX;
$this->Data[$Key]["Y"] = sin(deg2rad($Angle)) * ($Ring * $this->RingSize) + $CenterY;
}
}
}
elseif ($Algorithm == ALGORITHM_CENTRAL) {
/* Put a weight on each nodes */
foreach ($this->Data as $Key => $Settings) {
if (isset($Settings["Connections"])) {
$this->Data[$Key]["Weight"] = count($Settings["Connections"]);
}
else {
$this->Data[$Key]["Weight"] = 0;
}
}
$MaxConnections = $MaxConnections + 1;
for ($i = $MaxConnections; $i >= 0; $i--) {
foreach ($this->Data as $Key => $Settings) {
if ($Settings["Type"] == NODE_TYPE_CENTRAL) {
$this->Data[$Key]["X"] = $CenterX;
$this->Data[$Key]["Y"] = $CenterY;
}
if ($Settings["Type"] == NODE_TYPE_FREE) {
if (isset($Settings["Connections"])) {
$Connections = count($Settings["Connections"]);
}
else {
$Connections = 0;
}
if ($Connections == $i) {
$BiggestPartner = $this
->getBiggestPartner($Key);
if ($BiggestPartner != "") {
$Ring = $this->Data[$BiggestPartner]["FreeZone"];
$Weight = $this->Data[$BiggestPartner]["Weight"];
$AngleDivision = 360 / $this->Data[$BiggestPartner]["Weight"];
$Done = FALSE;
$Tries = 0;
while (!$Done && $Tries <= $Weight * 2) {
$Tries++;
$Angle = floor(rand(0, $Weight) * $AngleDivision);
if (!isset($this->Data[$BiggestPartner]["Angular"][$Angle]) || !isset($this->Data[$BiggestPartner]["Angular"])) {
$this->Data[$BiggestPartner]["Angular"][$Angle] = $Angle;
$Done = TRUE;
}
}
if (!$Done) {
$Angle = rand(0, 360);
$this->Data[$BiggestPartner]["Angular"][$Angle] = $Angle;
}
$X = cos(deg2rad($Angle)) * $Ring + $this->Data[$BiggestPartner]["X"];
$Y = sin(deg2rad($Angle)) * $Ring + $this->Data[$BiggestPartner]["Y"];
$this->Data[$Key]["X"] = $X;
$this->Data[$Key]["Y"] = $Y;
}
}
}
}
}
}
elseif ($Algorithm == ALGORITHM_CIRCULAR) {
$MaxConnections = $MaxConnections + 1;
for ($i = $MaxConnections; $i >= 0; $i--) {
foreach ($this->Data as $Key => $Settings) {
if ($Settings["Type"] == NODE_TYPE_CENTRAL) {
$this->Data[$Key]["X"] = $CenterX;
$this->Data[$Key]["Y"] = $CenterY;
}
if ($Settings["Type"] == NODE_TYPE_FREE) {
if (isset($Settings["Connections"])) {
$Connections = count($Settings["Connections"]);
}
else {
$Connections = 0;
}
if ($Connections == $i) {
$Ring = $MaxConnections - $Connections;
$Angle = rand(0, 360);
$X = cos(deg2rad($Angle)) * ($Ring * $this->RingSize) + $CenterX;
$Y = sin(deg2rad($Angle)) * ($Ring * $this->RingSize) + $CenterY;
$MedianOffset = $this
->getMedianOffset($Key, $X, $Y);
$this->Data[$Key]["X"] = $MedianOffset["X"];
$this->Data[$Key]["Y"] = $MedianOffset["Y"];
}
}
}
}
}
elseif ($Algorithm == ALGORITHM_RANDOM) {
foreach ($this->Data as $Key => $Settings) {
if ($Settings["Type"] == NODE_TYPE_FREE) {
$this->Data[$Key]["X"] = $CenterX + rand(-20, 20);
$this->Data[$Key]["Y"] = $CenterY + rand(-20, 20);
}
if ($Settings["Type"] == NODE_TYPE_CENTRAL) {
$this->Data[$Key]["X"] = $CenterX;
$this->Data[$Key]["Y"] = $CenterY;
}
}
}
}