You are here

function pSpring::doPass in Visitors 7.2

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

File

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

Class

pSpring

Code

function doPass() {

  /* Compute vectors */
  foreach ($this->Data as $Key => $Settings) {
    if ($Settings["Type"] != NODE_TYPE_CENTRAL) {
      unset($this->Data[$Key]["Vectors"]);
      $X1 = $Settings["X"];
      $Y1 = $Settings["Y"];

      /* Repulsion vectors */
      foreach ($this->Data as $Key2 => $Settings2) {
        if ($Key != $Key2) {
          $X2 = $this->Data[$Key2]["X"];
          $Y2 = $this->Data[$Key2]["Y"];
          $FreeZone = $this->Data[$Key2]["FreeZone"];
          $Distance = $this
            ->getDistance($X1, $Y1, $X2, $Y2);
          $Angle = $this
            ->getAngle($X1, $Y1, $X2, $Y2) + 180;

          /* Nodes too close, repulsion occurs */
          if ($Distance < $FreeZone) {
            $Force = log(pow(2, $FreeZone - $Distance));
            if ($Force > 1) {
              $this->Data[$Key]["Vectors"][] = array(
                "Type" => "R",
                "Angle" => $Angle % 360,
                "Force" => $Force,
              );
            }
          }
        }
      }

      /* Attraction vectors */
      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"];
            $FreeZone = $this->Data[$Key2]["FreeZone"];
            $Distance = $this
              ->getDistance($X1, $Y1, $X2, $Y2);
            $Angle = $this
              ->getAngle($X1, $Y1, $X2, $Y2);
            if ($Distance > $FreeZone) {
              $Force = log($Distance - $FreeZone + 1);
            }
            else {
              $Force = log($FreeZone - $Distance + 1);
              $Angle = $Angle + 180;
            }
            if ($Force > 1) {
              $this->Data[$Key]["Vectors"][] = array(
                "Type" => "A",
                "Angle" => $Angle % 360,
                "Force" => $Force,
              );
            }
          }
        }
      }
    }
  }

  /* Move the nodes accoding to the vectors */
  foreach ($this->Data as $Key => $Settings) {
    $X = $Settings["X"];
    $Y = $Settings["Y"];
    if (isset($Settings["Vectors"]) && $Settings["Type"] != NODE_TYPE_CENTRAL) {
      foreach ($Settings["Vectors"] as $ID => $Vector) {
        $Type = $Vector["Type"];
        $Force = $Vector["Force"];
        $Angle = $Vector["Angle"];
        $Factor = $Type == "A" ? $this->MagneticForceA : $this->MagneticForceR;
        $X = cos(deg2rad($Angle)) * $Force * $Factor + $X;
        $Y = sin(deg2rad($Angle)) * $Force * $Factor + $Y;
      }
    }
    $this->Data[$Key]["X"] = $X;
    $this->Data[$Key]["Y"] = $Y;
  }
}