function value_as_bar($val, $max = 1, $color = '#00F', $format = "number", $label = "", $url = "")
 {
     if ($max == 0 || $format == 'percent') {
         $max = 1;
     }
     $percent = formatDecimalAsPercent($val / $max);
     if ($format == "percent") {
         $printvalue = $percent . "%";
     } else {
         if ($format == "dollars") {
             $printvalue = "\$" . formatLargeNumberShorthand($val);
         } else {
             $printvalue = formatLargeNumberShorthand($val);
         }
     }
     $printvalue = "<strong>" . $printvalue . "</strong>";
     if ($label != "") {
         $printvalue = $label . " " . $printvalue;
     }
     $ret = "";
     if ($url != "") {
         $ret .= "<a href='" . $url . "'>";
     }
     $ret .= "<table border=0 width=100% cellpadding=2px cellspacing=0 style='width;100%;border:none;padding:0.25em;margin:0'>";
     $ret .= "<tr>";
     $ret .= "<td width='" . max(1, $percent) . "%' bgcolor='" . $color . "' align='right' style='text-align:right'><font color='#FFF'>";
     $ret .= $printvalue;
     $ret .= "</font></td>";
     $ret .= "<td";
     if ($format == 'percent') {
         $ret .= " bgcolor='#DDD'";
     }
     $ret .= ">";
     $ret .= "</td>";
     $ret .= "</tr>";
     $ret .= "</table>";
     if ($url != "") {
         $ret .= "</a>";
     }
     return $ret;
 }
Exemplo n.º 2
0
function formatValue($value, $format = "text", $shorthand = false)
{
    if ($format == "percent") {
        $ret = formatDecimalAsPercent($value) . "%";
    } else {
        if (is_numeric($value)) {
            if ($shorthand) {
                $ret = formatLargeNumberShorthand($value);
            } else {
                $ret = number_format($value);
            }
            if ($format == "dollars") {
                $ret = "\$" . $ret;
            }
        } else {
            if ($format == "html") {
                $ret = $value;
            } else {
                $ret = formatTag($value);
            }
        }
    }
    return $ret;
}