function pSpring::center in Visitors 7.2
Same name and namespace in other branches
- 7 pChart/class/pSpring.class.php \pSpring::center()
1 call to pSpring::center()
- pSpring::drawSpring in pChart/
class/ pSpring.class.php
File
- pChart/
class/ pSpring.class.php, line 602
Class
Code
function center() {
/* Determine the real center */
$TargetCenterX = ($this->X2 - $this->X1) / 2 + $this->X1;
$TargetCenterY = ($this->Y2 - $this->Y1) / 2 + $this->Y1;
/* Get current boundaries */
$XMin = $this->X2;
$XMax = $this->X1;
$YMin = $this->Y2;
$YMax = $this->Y1;
foreach ($this->Data as $Key => $Settings) {
$X = $Settings["X"];
$Y = $Settings["Y"];
if ($X < $XMin) {
$XMin = $X;
}
if ($X > $XMax) {
$XMax = $X;
}
if ($Y < $YMin) {
$YMin = $Y;
}
if ($Y > $YMax) {
$YMax = $Y;
}
}
$CurrentCenterX = ($XMax - $XMin) / 2 + $XMin;
$CurrentCenterY = ($YMax - $YMin) / 2 + $YMin;
/* Compute the offset to apply */
$XOffset = $TargetCenterX - $CurrentCenterX;
$YOffset = $TargetCenterY - $CurrentCenterY;
/* Correct the points position */
foreach ($this->Data as $Key => $Settings) {
$this->Data[$Key]["X"] = $Settings["X"] + $XOffset;
$this->Data[$Key]["Y"] = $Settings["Y"] + $YOffset;
}
}