html_graphs.php

来自「GForge 3.0 协作开发平台 支持CVS, mailing lists, 」· PHP 代码 · 共 849 行 · 第 1/2 页

PHP
849
字号
   {    if (! $vals["vfcolor"]) { $vals["vfcolor"]="#000000"; }    if (! $vals["hfcolor"]) { $vals["hfcolor"]="#000000"; }    if (! $vals["vbgcolor"]) { $vals["vbgcolor"]="#ffffff"; }    if (! $vals["hbgcolor"]) { $vals["hbgcolor"]="#ffffff"; }    if (! $vals["cellpadding"]) { $vals["cellpadding"]=0; }    if (! $vals["cellspacing"]) { $vals["cellspacing"]=0; }    if (! $vals["border"]) { $vals["border"]=0; }    if (! $vals["scale"]) { $vals["scale"]=1; }    if (! $vals["namebgcolor"]) { $vals["namebgcolor"]="#ffffff"; }    if (! $vals["valuebgcolor"]) { $vals["valuebgcolor"]="#ffffff"; }    if (! $vals["namefcolor"]) { $vals["namefcolor"]="#000000"; }    if (! $vals["valuefcolor"]) { $vals["valuefcolor"]="#000000"; }    if (! $vals["doublefcolor"]) { $vals["doublefcolor"]="#886666"; }    return ($vals);   }/*####################################################################### ##  Function:  horizontal_graph($names, $values, $bars, $vals) ##   Purpose:  Prints out the actual data for the horizontal chart. ######################################################################## */function horizontal_graph($names, $values, $bars, $vals)    {    for( $i=0;$i<SizeOf($values);$i++ )       { ?>	<tr>	<td align="right" <?php        // If a background was choosen don't print cell BGCOLOR        if (! $vals["background"]) { print ' style="background-color:' . $vals["namebgcolor"] . '"'; }?>>		<span style="font-size: -1;color:"<?php			echo $vals["namefcolor"];		?>;<?php			echo $vals["namefstyle"];	echo "\">";        echo "\n".$names[$i]; ?>		</span>	</td>	<td  align="left" <?php        // If a background was choosen don't print cell BGCOLOR        if (! $vals["background"]) { print ' style="background-color:' . $vals["valuebgcolor"] . '"'; }	echo ">";        // Decide if the value in bar is a color code or image.        if (ereg("^#", $bars[$i]))           { ?>		<table align="left" cellpadding="0" cellspacing="0" style="background-color:<?php echo $bars[$i] ?>" width="<?php echo $values[$i] * $vals["scale"] ?>">			<tr><td>&nbsp;</td></tr>		</table><?php            }         else            {             print '<img src="' . $bars[$i] . '"';             print ' height="10" width="' . $values[$i] * $vals["scale"] . '" alt= "" />';            }        if (! $vals["noshowvals"])           {            print '		<em><span style="font-size: -2;color:' . $vals["valuefcolor"] . ';'            . $vals["valuefstyle"] . '">(';            print $values[$i] . ")</span></em>";           }?>	</td>	</tr><?php       } // endfor   } // end horizontal_graph/*####################################################################### ##  Function:  vertical_graph($names, $values, $bars, $vals) ##   Purpose:  Prints out the actual data for the vertical chart. ######################################################################## */function vertical_graph($names, $values, $bars, $vals)    {    print "<tr>";    for( $i=0;$i<SizeOf($values);$i++ )       {         print '<td  align="center" valign="bottom" ';        // If a background was choosen don't print cell BGCOLOR        if (! $vals["background"]) { print ' style="background-color:' . $vals["valuebgcolor"] . '"'; }        print ">";        if (! $vals["noshowvals"])           {            print '<em><span style="font-size: -2;color:' . $vals["valuefcolor"] . ';'            . $vals["valuefstyle"] . '">(';            print $values[$i] . ")</span></em><br />";           }?>         <img src="<?php echo $bars[$i] ?>" width="5" height="<?php        // Values of zero are displayed wrong because a image height of zero         // gives a strange behavior in Netscape. For this reason the height         // is set at 1 pixel if the value is zero. - Jan Diepens        if ($values[$i] != 0)           {            echo $values[$i] * $vals["scale"];           }         else            {             echo "1";           } ?>" alt="" />         </td><?php       } // endfor    print "</tr><tr>";    for( $i=0;$i<SizeOf($values);$i++ )       { ?>        <td align="center" valign="top"<?php        // If a background was choosen don't print cell BGCOLOR        if (! $vals["background"]) { print ' style="background-color:' . $vals["namebgcolor"] . '"'; }?>         >		 <span style="font-size: -1;color:<?php echo $vals["namefcolor"] ?>;<?php echo $vals["namefstyle"] ?>">         <?php echo $names[$i] ?>         </span>        </td><?php       } // endfor   } // end vertical_graph /*####################################################################### ##  Function:  double_horizontal_graph($names, $values, $bars, #                                     $vals, $dvalues, $dbars) ##   Purpose:  Prints out the actual data for the double horizontal chart. ######################################################################## */function double_horizontal_graph($names, $values, $bars, $vals, $dvalues, $dbars)    {    for( $i=0;$i<SizeOf($values);$i++ )       { ?>       <tr>        <td align="right"<?php        // If a background was choosen don't print cell BGCOLOR        if (! $vals["background"]) { print ' style="background-color:' . $vals["namebgcolor"] . '"'; }?>         >		 <span style="font-size: -1;color:<?php echo $vals["namefcolor"] ?>;<?php echo $vals["namefstyle"] ?>">         <?php echo $names[$i] ?>         </span>        </td>        <td  align="left"<?php        // If a background was choosen don't print cell BGCOLOR        if (! $vals["background"]) { print ' style="background-color:' . $vals["valuebgcolor"] . '"'; }?>         >         <table align="left" cellpadding="0" cellspacing="0" width="<?php echo $dvalues[$i] * $vals["scale"] ?>">          <tr><td<?php        // Set background to a color if it starts with # or        // an image otherwise.        if (ereg("^#", $dbars[$i])) { print 'style="background-color:' . $dbars[$i] . '">'; }        else { print 'background="' . $dbars[$i] . '">'; }?>           <nowrap><?php        // Decide if the value in bar is a color code or image.        if (ereg("^#", $bars[$i]))           { ?>            <table align="left" cellpadding="0" cellspacing="0"             style="background-color:"<?php echo $bars[$i] ?>"             width="<?php echo $values[$i] * $vals["scale"] ?>">             <tr><td>&nbsp</td></tr>            </table><?php            }         else            {             print '<img src="' . $bars[$i] . '"';             print ' height="10" width="' . $values[$i] * $vals["scale"] . '" alt="" />';            }                  if (! $vals["noshowvals"])           {            print '<em><span style="font-size: -3:color:' . $vals["valuefcolor"] . ';'            . $vals["valuefstyle"] . '">(';            print $values[$i] . ")</span></em>";           }?>           </nowrap>          </td></tr>         </table><?php        if (! $vals["noshowvals"])           {            print '<em><span style="font-size:-3;color:' . $vals["doublefcolor"] . ';'            . $vals["valuefstyle"] . '">(';            print $dvalues[$i] . ")</span></em>";           }?>        </td>       </tr><?php       } // endfor   } // end double_horizontal_graph/*####################################################################### ##  Function:  double_vertical_graph($names, $values, $bars, $vals, $dvalues, $dbars) ##   Purpose:  Prints out the actual data for the double vertical chart. ##    Author: Jan Diepens######################################################################## */function double_vertical_graph($names, $values, $bars, $vals, $dvalues, $dbars)    {   // print "<tr>";    for( $i=0;$i<SizeOf($values);$i++ )       {         print '<td align="center" valign="bottom" ';        // If a background was choosen don't print cell BGCOLOR        if (! $vals["background"]) { print ' style="background-color:' . $vals["valuebgcolor"] . '"'; }        print ">";	print '<table><tr><td align="center" valign="bottom" ';        // If a background was choosen don't print cell BGCOLOR        if (! $vals["background"]) { print ' style="background-color:' . $vals["valuebgcolor"] . '"'; }        print ">";        if (! $vals["noshowvals"])           {            print '<em><span style="font-size:-2;color:' . $vals["valuefcolor"] . ';'            . $vals["valuefstyle"] . '">(';            print $values[$i] . ")</span></em><br />";           }?>         <img src="<?php echo $bars[$i] ?>" width="10" height="<?php if ($values[$i]!=0){		echo $values[$i] * $vals["scale"];		} else { echo "1";} ?>" alt="" />         </td><td align="center" valign="bottom"<?php         // If a background was choosen don't print cell BGCOLOR        if (! $vals["background"]) { print ' style="background-color:' . $vals["valuebgcolor"] . '"'; }        print ">";        if (! $vals["noshowvals"])           {            print '<em><span style="font-size:-2;color:' . $vals["doublefcolor"] . ';'            . $vals["valuefstyle"] . '">(';            print $dvalues[$i] . ")</span></em><br />";           }?>         <img src="<?php echo $dbars[$i] ?>" width="10" height="<?php if ($dvalues[$i]!=0){		echo $dvalues[$i] * $vals["scale"];		} else { echo "1";} ?>" alt="" />         </td></tr></table>	 </td><?php       } // endfor    print "</tr><tr>";    for( $i=0;$i<SizeOf($values);$i++ )       { ?>        <td align="center" valign="top"<?php        // If a background was choosen don't print cell BGCOLOR        if (! $vals["background"]) { print ' style="background-color:' . $vals["namebgcolor"] . '"'; }?>         >		 <span style="font-size:-1;color:<?php echo $vals["namefcolor"] ?>;<?php echo $vals["namefstyle"] ?>">         <?php echo $names[$i] ?>         </span>        </td><?php       } // endfor   } // end double_vertical_graph/*#########################################################################  Function:  horizontal_absolute_multi_graph($names, $multi_rows,#                                             $colors, $vals,#                                             $additive)#	      $multi_rows - array of arrays of values (may be seen as#             array of columns - column for first color, for second, etc.)#             $colors - array of color names or codes#	      $additive - treat data as absolute values (will be#             differentiated for drawing, and hence should be non-decreasing#             sequence) or additive (just stick one on another).##   Purpose:  Prints out the actual data for the horizontal chart of#             bars with multiple sections########################################################################*/function horizontal_multisection_graph($names, $multi_rows, $colors, $vals, $additive=false)   {    $subbars_num=SizeOf($multi_rows);    for( $i=0;$i<SizeOf($names);$i++ )       {?>	<tr>	<td align="right" <?php        // If a background was choosen don't print cell BGCOLOR        if (! $vals["background"]) { print ' style="background-color:' . $vals["namebgcolor"] . '"'; }?>>		<span style="font-size:-1;color:<?php echo $vals["namefcolor"]; ?>;<?php echo $vals["namefstyle"]; ?>"><?php        echo "\n".$names[$i]; ?>		</span>	</td>	<td  align="left" <?php        // If a background was choosen don't print cell BGCOLOR        if (! $vals["background"]) { print ' style="background-color:' . $vals["valuebgcolor"] . '"'; }	echo ">";        echo '<table align="left" border="0" cellpadding="0" cellspacing="0"><tr>'."\n";        $prev_val=0;        $shown=0;	for( $j=0;$j<$subbars_num;$j++ ) {        	$width=$multi_rows[$j][$i];                if (!$additive) $width-=$prev_val;                if ($width<=0 && ($j!=$subbars_num-1 || shown)) continue;                // make sure that we show at least stump, but only one                $shown=1;                $prev_val=$multi_rows[$j][$i];                $pix_width=$width * $vals["scale"];                echo "<td style=\"background-color:".$colors[$j]."\" width=\"".$pix_width."\">&nbsp;</td>";        }        echo '</tr></table>';        if (! $vals["noshowvals"])           {                print '		<em><span style="font-size:-2;color:' . $vals["valuefcolor"] . ';'                . $vals["valuefstyle"] . '">&nbsp;(';        	for( $j=0;$j<SizeOf($multi_rows);$j++ ) {                        if ($j) print "/";                        print $multi_rows[$j][$i];                }                print ")</span></em>";           }?>	</td>	</tr><?php       } // endfor   } // end horizontal_graphfunction graph_calculate_scale($multi_rows,$width) {	$max_value=0;        $rows_num=count($multi_rows);        for ($row_i = 0; $row_i < $rows_num; $row_i++) {                $row=$multi_rows[$row_i];               	$counter=count($row);		for ($i = 0; $i < $counter; $i++) {			if ($row[$i] > $max_value) {				$max_value=$row[$i];			}		}        }	if ($max_value < 1) {		$max_value=1;	}	$scale=($width/$max_value);        return $scale;}?>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?