function pDraw::processScale
Search API
5.x pDraw.class.php | pDraw::processScale($XMin, $XMax, $MaxDivs, $Factors, $AxisID) |
1 call to pDraw::processScale()
- pDraw::computeScale in inc/
pchart/ pchart/ class/ pDraw.class.php
File
- inc/
pchart/ pchart/ class/ pDraw.class.php, line 2526
Class
Code
function processScale($XMin, $XMax, $MaxDivs, $Factors, $AxisID)
{
$ScaleHeight = abs(ceil($XMax) -floor($XMin));
if (isset($this->DataSet->Data ["Axis"][$AxisID]["Format"])) {
$Format = $this->DataSet->Data ["Axis"][$AxisID]["Format"];
}
else {
$Format = NULL;
}
if (isset($this->DataSet->Data ["Axis"][$AxisID]["Display"])) {
$Mode = $this->DataSet->Data ["Axis"][$AxisID]["Display"];
}
else {
$Mode = AXIS_FORMAT_DEFAULT;
}
$Scale = "";
if ($XMin != $XMax)
{
$Found = FALSE;
$Rescaled = FALSE;
$Scaled10Factor = .0001;
$Result = 0;
while (!$Found)
{
foreach ($Factors as $Key => $Factor)
{
if (!$Found)
{
if (!($this->modulo($XMin, $Factor * $Scaled10Factor) == 0) || ($XMin != floor($XMin))) {
$XMinRescaled = floor($XMin / ($Factor * $Scaled10Factor)) * $Factor * $Scaled10Factor;
}
else {
$XMinRescaled = $XMin;
}
if (!($this->modulo($XMax, $Factor * $Scaled10Factor) == 0) || ($XMax != floor($XMax))) {
$XMaxRescaled = floor($XMax / ($Factor * $Scaled10Factor)) * $Factor * $Scaled10Factor + ($Factor * $Scaled10Factor);
}
else {
$XMaxRescaled = $XMax;
}
$ScaleHeightRescaled = abs($XMaxRescaled -$XMinRescaled);
if (!$Found && floor($ScaleHeightRescaled / ($Factor * $Scaled10Factor)) <= $MaxDivs) {
$Found = TRUE;
$Rescaled = TRUE;
$Result = $Factor * $Scaled10Factor;
}
}
}
$Scaled10Factor = $Scaled10Factor * 10;
}
/* ReCall Min / Max / Height */
if ($Rescaled) {
$XMin = $XMinRescaled;
$XMax = $XMaxRescaled;
$ScaleHeight = $ScaleHeightRescaled;
}
/* Compute rows size */
$Rows = floor($ScaleHeight / $Result);
if ($Rows == 0) {
$Rows = 1;
}
$RowHeight = $ScaleHeight / $Rows;
/* Return the results */
$Scale ["Rows"] = $Rows;
$Scale ["RowHeight"] = $RowHeight;
$Scale ["XMin"] = $XMin;
$Scale ["XMax"] = $XMax;
/* Compute the needed decimals for the metric view to avoid repetition of the same X Axis labels */
if ($Mode == AXIS_FORMAT_METRIC && $Format == NULL)
{
$Done = FALSE;
$GoodDecimals = 0;
for ($Decimals = 0; $Decimals <= 10; $Decimals++)
{
if (!$Done)
{
$LastLabel = "zob";
$ScaleOK = TRUE;
for ($i = 0; $i <= $Rows; $i++)
{
$Value = $XMin + $i * $RowHeight;
$Label = $this->scaleFormat($Value, AXIS_FORMAT_METRIC, $Decimals);
if ($LastLabel == $Label) {
$ScaleOK = FALSE;
}
$LastLabel = $Label;
}
if ($ScaleOK) {
$Done = TRUE;
$GoodDecimals = $Decimals;
}
}
}
$Scale ["Format"] = $GoodDecimals;
}
}
else
{
/* If all values are the same we keep a +1/-1 scale */
$Rows = 2;
$XMin = $XMax -1;
$XMax = $XMax + 1;
$RowHeight = 1;
/* Return the results */
$Scale ["Rows"] = $Rows;
$Scale ["RowHeight"] = $RowHeight;
$Scale ["XMin"] = $XMin;
$Scale ["XMax"] = $XMax;
}
return ($Scale);
}