1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851
|
<?php
/**
* SourceForge: Breaking Down the Barriers to Open Source Development
* Copyright 1999-2001 (c) VA Linux Systems
* http://sourceforge.net
*
* @author Tim Perdue <tperdue@valnux.com>
* @version $Id: HTML_Graphs.php 3442 2004-10-08 21:39:22Z gsmet $
* @date $Date: 2004-10-08 23:39:22 +0200 (ven, 08 oct 2004) $
*
* Ryan T. Sammartino made several changes to make the output XHTML 1.0
* Transitional.
*/
/*
#######################################################################
#
# $Source$
# $Revision: 3442 $
# $State$
#
# Revision 1.5 1998/11/05 06:15:52 pdavis
# Added error_reporting setting per Jean-Pierre Arneodo's request.
# (Though redundant) Added html_graph_init() to initialize vars array.
#
# Revision 1.4 1998/07/08 05:24:25 pdavis
# Add double_vertical_graph from Jan Diepens.
# Added "max" function to find $largest in examples page.
# Added code to increase values of zero to one.
# Added double_vertical_graph example
# Combined all source into one zip.
#
# Revision 1.3 1998/06/17 23:37:19 pdavis
# Added mixed color codes and images to double graph.
#
# Revision 1.2 1998/06/17 21:20:20 pdavis
# Fixed Background problem, added mixed color codes and graphics.
#
# Revision 1.1 1998/06/17 15:52:41 pdavis
# Initial revision
#
#
#######################################################################
#
# *
# * Phil Davis
# *
# * Smyrna, Tennessee 37167 USA
# *
# * pdavis@pobox.com
# * http://www.pobox.com/~pdavis/
# *
#
# (C) Copyright 1998
# Phil Davis
# Printed in the United States of America
#
# This program is free software; you can redistribute it
# and/or modify it under the terms of the GNU General
# Public License version 2 as published by the Free
# Software Foundation.
#
# This program is distributed in the hope that it will
# be useful, but WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# Released under GNU Public License v2.0, available
# at www.fsf.org. The author hereby disclaims all
# warranties relating to this software, express or implied,
# including with no limitation any implied warranties of
# merchantability, quality performance, or fitness for a
# particular purpose. The author and their distributors
# shall not be liable for any special, incidental,
# consequential, indirect or similar damages due to loss
# of data, even if an agent of the author has been found
# to be the source of loss or damage. In no event shall the
# author's liability for any damages ever exceed the price
# paid for the license to use software, regardless of the
# form of the claim. The person using the software bears all
# risk as to the quality and performance of the software.
#
# Swim at your own risk!
#
# This software program, documentation, accompanying
# written and disk-based notes and specifications, and all
# referenced and related program files, screen display
# renditions, and text files, are the property of the
# author.
#
# The authors have done their best to insure that the
# material found in this document is both useful and
# accurate. However, please be aware that errors may exist,
# the author does not make any guarantee concerning the
# accuracy of the information found here or in the uses
# to which it may be put.
#
#######################################################################
#
# About:
#
# The following PHP3 code provides a nice class interface for
# html graphs. It provides a single, reasonably consistent
# interface for creating HTML based graphs. The idea behind
# this code is that the user of the class sets up four or five
# arrays and pass these to html_graph() which then takes
# care of all the messy HTML layout. I am reasonably happy
# with the outcome of this interface. The HTML that must be
# generated for HTML graphs *is* messy, and the interface is
# very clean and flexible. I think that once you generate
# one graph with it, you'll never look at creating HTML graphs
# the same. The arrays that must be set up consist of:
#
# * A names array containing column/row identifiers ($names)
# * One or two values arrays containg corresponding
# values to the column/row names ($values & $dvalues)
# * One or two bars array which also corresponds to the names
# array. The values in these arrays are URLS to graphics
# or color codes starting with a # which will be used to
# generate the graph bar. Color codes and graphics may
# be mixed in the same chart, although color codes can't
# be used on Vertical charts. ($bars & $dbars)
# * The heart of customization... a vals array. If this
# array isn't created then html_graphs will use all
# default values for the chart. Items that are customizable
# include font styles & colors, backgrounds, graphics,
# labels, cellspacing, cellpadding, borders, anotations
# and scaling factor. ($vals)
#
#######################################################################
#
# Known Bugs:
#
# * Currently the $vals["background"] tag element doesn't
# work in Netscape.
#
#######################################################################
#
# To Do:
#
# * Would like to make the $vals array to html_graph() completely
# optional. Currently it has to at least be an empty array.
#
#######################################################################
#
# Contributors:
#
# Jan Diepens - Eindhoven University of Technologie
# Jean-Pierre Arneodo
#
#######################################################################
#
# Contact:
#
# If you have questions, suggestions, bugs, bug fixes, or enhancements
# please send them to pdavis@pobox.com so that they may be wrapped into
# future versions of HTML_Graph.
#
#######################################################################
#
# Examples:
#
# See http://www.pobox.com/~pdavis/programs/
#
#######################################################################
*/
/*
#######################################################################
#
# Function: html_graph($names, $values, $bars, $vals[, $dvalues, $dbars])
#
# Purpose: Calls routines to initialize defaults, set up table
# print data, and close table.
#
# Arguments:
# $names - Array of element names.
# $values - Array of corresponding values for elements.
# $bars - Array of corresponding graphic image names
# or color codes (begining with a #) for elements.
# Color codes can't be used on vertical charts.
# $dvalues - Array of corresponding values for elements.
# This set is required only in the double graph.
# $dbars - Array of corresponding graphic image names
# or color codes (begining with a #) for elements.
# This set is required only in the double graph.
#
# $vals - array("vlabel"=>"",
# "hlabel"=>"",
# "type"=>"",
# "cellpadding"=>"",
# "cellspacing"=>"",
# "border"=>"",
# "width"=>"",
# "background"=>"",
# "vfcolor"=>"",
# "hfcolor"=>"",
# "vbgcolor"=>"",
# "hbgcolor"=>"",
# "vfstyle"=>"",
# "hfstyle"=>"",
# "noshowvals"=>"",
# "scale"=>"",
# "namebgcolor"=>"",
# "valuebgcolor"=>"",
# "namefcolor"=>"",
# "valuefcolor"=>"",
# "namefstyle"=>"",
# "valuefstyle"=>"",
# "doublefcolor"=>"")
#
# Where:
#
# vlabel - Vertical Label to apply
# default is NUL
# hlabel - Horizontal Label to apply
# default is NUL
# type - Type of graph
# 0 = horizontal
# 1 = vertical
# 2 = double horizontal
# 3 = double vertical
# default is 0
# cellpadding - Padding for the overall table
# default is 0
# cellspacing - Space for the overall table
# default is 0
# border - Border size for the overall table
# default is 0
# width - Width of the overall table
# default is NUL
# background - Background image for the overall table
# If this value exists then no BGCOLOR
# codes will be added to table elements.
# default is NUL
# vfcolor - Vertical label font color
# default is #000000
# hfcolor - Horizontal label font color
# default is #000000
# vbgcolor - Vertical label background color
# Not used if background is set
# default is #FFFFFF
# hbgcolor - Horizontal label background color
# Not used if background is set
# default is #FFFFFF
# vfstyle - Vertical label font style
# default is NUL
# hfstyle - Horizontal label font style
# default is NUL
# noshowvals - Don't show numeric value at end of graphic
# Boolean value, default is FALSE
# scale - Scale values by some number.
# default is 1.
# namebgcolor - Color code for element name cells
# Not used if background is set
# default is "#000000"
# valuebgcolor - Color code for value cells
# Not used if background is set
# default is "#000000"
# namefcolor - Color code for font of name element
# default is "#FFFFFF"
# valuefcolor - Color code for font of value element
# default is "#000000"
# namefstyle - Style code for font of name element
# default is NUL
# valuefstyle - Style code for font of value element
# default is NUL
# doublefcolor - Color code for font of second element value
# default is "#886666"
#
#######################################################################
*/
function html_graph($names, $values, $bars, $vals, $dvalues=0, $dbars=0)
{
// Set the error level on entry and exit so as not to interfear
// with anyone elses error checking.
$er = error_reporting(1);
// Set the values that the user didn't
$vals = hv_graph_defaults($vals);
start_graph($vals, $names);
if ($vals["type"] == 0)
{
horizontal_graph($names, $values, $bars, $vals);
}
elseif ($vals["type"] == 1)
{
vertical_graph($names, $values, $bars, $vals);
}
elseif ($vals["type"] == 2)
{
double_horizontal_graph($names, $values, $bars, $vals, $dvalues, $dbars);
}
elseif ($vals["type"] == 3)
{
double_vertical_graph($names, $values, $bars, $vals, $dvalues, $dbars);
}
end_graph();
// Set the error level back to where it was.
error_reporting($er);
}
/*
#######################################################################
#
# Function: html_graph_init()
#
# Purpose: Sets up the $vals array by initializing all values to
# null. Used to avoid warnings from error_reporting being
# set high. This routine only needs to be called if you
# are woried about using uninitialized variables.
#
# Returns: The initialized $vals array
#
#######################################################################
*/
function html_graph_init()
{
$vals = array("vlabel"=>"",
"hlabel"=>"",
"type"=>"",
"cellpadding"=>"",
"cellspacing"=>"",
"border"=>"",
"width"=>"",
"background"=>"",
"vfcolor"=>"",
"hfcolor"=>"",
"vbgcolor"=>"",
"hbgcolor"=>"",
"vfstyle"=>"",
"hfstyle"=>"",
"noshowvals"=>"",
"scale"=>"",
"namebgcolor"=>"",
"valuebgcolor"=>"",
"namefcolor"=>"",
"valuefcolor"=>"",
"namefstyle"=>"",
"valuefstyle"=>"",
"doublefcolor"=>"");
return($vals);
}
/*
#######################################################################
#
# Function: start_graph($vals, $names)
#
# Purpose: Prints out the table header and graph labels.
#
#######################################################################
*/
function start_graph($vals, $names)
{
print "<!-- Start Inner Graph Table -->\n\n<table";
print ' cellpadding="' . $vals["cellpadding"] . '"';
print ' cellspacing="' . $vals["cellspacing"] . '"';
print ' border="' . $vals["border"] . '"';
if ($vals["width"] != 0) { print ' width="' . $vals["width"] . '"'; }
if ($vals["background"]) { print ' background="' . $vals["background"] . '"'; }
print '>';
if (($vals["vlabel"]) || ($vals["hlabel"]))
{
if (($vals["type"] == 0) || ($vals["type"] == 2 ))// horizontal chart
{
$rowspan = SizeOf($names) + 1;
$colspan = 3;
}
elseif ($vals["type"] == 1 || ($vals["type"] == 3 )) // vertical chart
{
$rowspan = 3;
$colspan = SizeOf($names) + 1;
}
print '<tr><td align="center" valign="center" ';
// If a background was choosen don't print cell BGCOLOR
if (! $vals["background"]) { print 'style="background-color:' . $vals["hbgcolor"] . '"'; }
print ' colspan="' . $colspan . '">';
print '<span style="color:' . $vals["hfcolor"] . '; ' . $vals["hfstyle"] . '">';
print "<strong>" . $vals["hlabel"] . "</strong>";
print '</span></td></tr>';
print '<tr><td align="center" valign="center" ';
// If a background was choosen don't print cell BGCOLOR
if (! $vals["background"]) { print 'style="background-color:' . $vals["vbgcolor"] . '"'; }
print ' rowspan="' . $rowspan . '">';
print '<span style="color:' . $vals["vfcolor"] . '; ' . $vals["vfstyle"] . '">';
print "<strong>" . $vals["vlabel"] . "</strong>";
print '</span></td>';
}
}
/*
#######################################################################
#
# Function: end_graph()
#
# Purpose: Prints out the table footer.
#
#######################################################################
*/
function end_graph()
{
print "\n</table>\n\n<!-- end inner graph table -->\n\n";
}
/*
#######################################################################
#
# Function: hv_graph_defaults($vals)
#
# Purpose: Sets the default values for the $vals array
#
#######################################################################
*/
function hv_graph_defaults($vals)
{
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> </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> </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."\"> </td>";
}
echo '</tr></table>';
if (! $vals["noshowvals"])
{
print ' <em><span style="font-size:-2;color:' . $vals["valuefcolor"] . ';'
. $vals["valuefstyle"] . '"> (';
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_graph
function 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;
}
?>
|