function pDraw::scaleFormat

5.x pDraw.class.php pDraw::scaleFormat($Value, $Mode = NULL, $Format = NULL, $Unit = NULL)
12 calls to pDraw::scaleFormat()
pDraw::drawAreaChart in inc/pchart/pchart/class/pDraw.class.php
pDraw::drawBarChart in inc/pchart/pchart/class/pDraw.class.php
pDraw::drawFilledSplineChart in inc/pchart/pchart/class/pDraw.class.php
pDraw::drawLineChart in inc/pchart/pchart/class/pDraw.class.php
pDraw::drawPlotChart in inc/pchart/pchart/class/pDraw.class.php

... See full list

File

inc/pchart/pchart/class/pDraw.class.php, line 3129

Class

pDraw

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);
}