function pDraw::scaleFormat in Visitors 7
Same name and namespace in other branches
- 7.2 pChart/class/pDraw.class.php \pDraw::scaleFormat()
12 calls to pDraw::scaleFormat()
- pDraw::drawAreaChart in pChart/
class/ pDraw.class.php - pDraw::drawBarChart in pChart/
class/ pDraw.class.php - pDraw::drawFilledSplineChart in pChart/
class/ pDraw.class.php - pDraw::drawLineChart in pChart/
class/ pDraw.class.php - pDraw::drawPlotChart in pChart/
class/ pDraw.class.php
File
- pChart/
class/ pDraw.class.php, line 3129
Class
Code
function scaleFormat($Value, $Mode = NULL, $Format = NULL, $Unit = NULL) {
if ($Value == VOID) {
return "";
}
if ($Mode == AXIS_FORMAT_TRAFFIC) {
if ($Value == 0) {
return "0B";
}
$Units = array(
"B",
"KB",
"MB",
"GB",
"TB",
"PB",
);
$Sign = "";
if ($Value < 0) {
$Value = abs($Value);
$Sign = "-";
}
$Value = number_format($Value / pow(1024, $Scale = floor(log($Value, 1024))), 2, ",", ".");
return $Sign . $Value . " " . $Units[$Scale];
}
if ($Mode == AXIS_FORMAT_CUSTOM) {
if (function_exists($Format)) {
return call_user_func($Format, $Value);
}
}
if ($Mode == AXIS_FORMAT_DATE) {
if ($Format == NULL) {
$Pattern = "d/m/Y";
}
else {
$Pattern = $Format;
}
return gmdate($Pattern, $Value);
}
if ($Mode == AXIS_FORMAT_TIME) {
if ($Format == NULL) {
$Pattern = "H:i:s";
}
else {
$Pattern = $Format;
}
return gmdate($Pattern, $Value);
}
if ($Mode == AXIS_FORMAT_CURRENCY) {
return $Format . number_format($Value, 2);
}
if ($Mode == AXIS_FORMAT_METRIC) {
if (abs($Value) > 1000000000) {
return round($Value / 1000000000, $Format) . "g" . $Unit;
}
if (abs($Value) > 1000000) {
return round($Value / 1000000, $Format) . "m" . $Unit;
}
elseif (abs($Value) >= 1000) {
return round($Value / 1000, $Format) . "k" . $Unit;
}
}
return $Value . $Unit;
}