You are here

function pSpring::lastPass in Visitors 7.2

Same name and namespace in other branches
  1. 7 pChart/class/pSpring.class.php \pSpring::lastPass()
1 call to pSpring::lastPass()
pSpring::drawSpring in pChart/class/pSpring.class.php

File

pChart/class/pSpring.class.php, line 526

Class

pSpring

Code

function lastPass() {

  /* Put everything inside the graph area */
  foreach ($this->Data as $Key => $Settings) {
    $X = $Settings["X"];
    $Y = $Settings["Y"];
    if ($X < $this->X1) {
      $X = $this->X1;
    }
    if ($X > $this->X2) {
      $X = $this->X2;
    }
    if ($Y < $this->Y1) {
      $Y = $this->Y1;
    }
    if ($Y > $this->Y2) {
      $Y = $this->Y2;
    }
    $this->Data[$Key]["X"] = $X;
    $this->Data[$Key]["Y"] = $Y;
  }

  /* Dump all links */
  $Links = "";
  foreach ($this->Data as $Key => $Settings) {
    $X1 = $Settings["X"];
    $Y1 = $Settings["Y"];
    if (isset($Settings["Connections"])) {
      foreach ($Settings["Connections"] as $ID => $NodeID) {
        if (isset($this->Data[$NodeID])) {
          $X2 = $this->Data[$NodeID]["X"];
          $Y2 = $this->Data[$NodeID]["Y"];
          $Links[] = array(
            "X1" => $X1,
            "Y1" => $Y1,
            "X2" => $X2,
            "Y2" => $Y2,
            "Source" => $Settings["Name"],
            "Destination" => $this->Data[$NodeID]["Name"],
          );
        }
      }
    }
  }

  /* Check collisions */
  $Conflicts = 0;
  foreach ($this->Data as $Key => $Settings) {
    $X1 = $Settings["X"];
    $Y1 = $Settings["Y"];
    if (isset($Settings["Connections"])) {
      foreach ($Settings["Connections"] as $ID => $NodeID) {
        if (isset($this->Data[$NodeID])) {
          $X2 = $this->Data[$NodeID]["X"];
          $Y2 = $this->Data[$NodeID]["Y"];
          foreach ($Links as $IDLinks => $Link) {
            $X3 = $Link["X1"];
            $Y3 = $Link["Y1"];
            $X4 = $Link["X2"];
            $Y4 = $Link["Y2"];
            if (!($X1 == $X3 && $X2 == $X4 && $Y1 == $Y3 && $Y2 == $Y4)) {
              if ($this
                ->intersect($X1, $Y1, $X2, $Y2, $X3, $Y3, $X4, $Y4)) {
                if ($Link["Source"] != $Settings["Name"] && $Link["Source"] != $this->Data[$NodeID]["Name"] && $Link["Destination"] != $Settings["Name"] && $Link["Destination"] != $this->Data[$NodeID]["Name"]) {
                  $Conflicts++;
                }
              }
            }
          }
        }
      }
    }
  }
  return $Conflicts / 2;
}