function rows_as_chart($dbrows, $xvaluefield, $yvaluefields, $colors = array(), $formats = array(), $showSeriesLabel = false, $showMetricLabel = false)
 {
     $ret = "<table border=0 width=100%>";
     $totalmax = getMaxFromAssoc($dbrows, $yvaluefields);
     $url = "";
     if (!empty($dbrows) && is_array($dbrows)) {
         foreach ($dbrows as $idx => $dbrow) {
             if (isset($colors[$idx])) {
                 $color = $colors[$idx];
             } else {
                 if (isset($colors[0])) {
                     $color = $colors[0];
                 } else {
                     $color = "#00F";
                 }
             }
             $countrows = 0;
             $label = "";
             foreach ($yvaluefields as $idx => $yvaluefield) {
                 $xvalue = "";
                 $yvalue = 0;
                 $ret .= "<tr>";
                 $xtext = "";
                 if ($idx == 0) {
                     $xformat = "text";
                     if (isset($formats[$xvaluefield])) {
                         $xformat = $formats[$xvaluefield];
                     }
                     if (isset($dbrow[strtoupper($xvaluefield)])) {
                         $xvalue = $dbrow[strtoupper($xvaluefield)];
                     } elseif (isset($dbrow[strtolower($xvaluefield)])) {
                         $xvalue = $dbrow[strtolower($xvaluefield)];
                     }
                     if ($xvalue != "") {
                         $xtext = $xvalue;
                         $url = getUrlFromString($xvalue);
                         $ret .= "<td style='width:1px;white-space: nowrap;' rowspan='" . count($yvaluefields) . "'>" . $xtext . "</td>";
                         if ($showSeriesLabel) {
                             $label = iconToText($xvalue);
                         }
                     }
                 }
                 if (!empty($formats) && isset($formats[$yvaluefield])) {
                     $format = $formats[$yvaluefield];
                 } else {
                     $format = "number";
                 }
                 if ($format == "percent") {
                     $max = 1;
                 } else {
                     $max = $totalmax;
                 }
                 if (isset($dbrow[strtoupper($yvaluefield)])) {
                     $yvalue = $dbrow[strtoupper($yvaluefield)];
                 } elseif (isset($dbrow[strtolower($yvaluefield)])) {
                     $yvalue = $dbrow[strtolower($yvaluefield)];
                 }
                 if ($showMetricLabel) {
                     $label = formatTag($yvaluefield);
                 }
                 if ($xvaluefield != $yvaluefield && isset($yvalue) && is_numeric($yvalue)) {
                     $color = alterColor($color, $countrows, 'dark');
                     $ret .= "<td>" . $this->value_as_bar($yvalue, $max, $color, $format, $label, $url) . "</td>";
                     $countrows++;
                 }
                 $ret .= "</tr>";
             }
         }
     }
     $ret .= "</table>";
     return $ret;
 }
Пример #2
0
function alterColors($array, $amount = 0, $alteration = "dark", $increasing = false)
{
    $ret = array();
    $counter = 0;
    if (!empty($array)) {
        foreach ($array as $color) {
            $totalAmount = $amount;
            if ($increasing) {
                $totalAmount += $counter;
            }
            $newColor = alterColor($color, $totalAmount, $alteration);
            $ret[] = $newColor;
            $counter++;
        }
    }
    return $ret;
}