/[cvs]/nfo/php/libs/com.newsblob.phphtmllib/widgets/svg/SVGXYLineGraph.inc
ViewVC logotype

Contents of /nfo/php/libs/com.newsblob.phphtmllib/widgets/svg/SVGXYLineGraph.inc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations)
Thu May 6 16:27:53 2004 UTC (20 years, 3 months ago) by jonen
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +0 -0 lines
 updated all to v2.4.1 - Apr 01, 2004

1 <?php
2 /**
3 * This file holds the base Graph class for doing
4 * graphs on an XY coordinate system.
5 *
6 * $Id: SVGXYLineGraph.inc,v 1.6 2003/03/04 22:18:28 hemna Exp $
7 *
8 * @author Walter A. Boring IV <waboring@buildabetterweb.com>
9 * @package phpHtmlLib
10 * @subpackage SVG
11 */
12
13 /**
14 * we need the SVGGraph class
15 */
16 require_once($phphtmllib."/widgets/svg/SVGXYPlotGraph.inc");
17
18 /**
19 * This is the base Graph class for doing XY coordinate
20 * system based graphs in SVG.
21 *
22 * $Id: SVGXYLineGraph.inc,v 1.6 2003/03/04 22:18:28 hemna Exp $
23 *
24 * @author Walter A. Boring IV <waboring@buildabetterweb.com>
25 * @package phpHtmlLib
26 * @subpackage SVG
27 */
28 class SVGXYLineGraph extends SVGXYPlotGraph {
29
30
31 /**
32 * holds the colors for each of
33 * the lines
34 */
35 var $_line_colors = array();
36
37 /**
38 * This enables you to add another line
39 * to the graph
40 *
41 * @param string - the x coordinates
42 * @param string - the y coordinates
43 * @param string - the color for the line
44 */
45 function add_line($x_values, $y_values, $color="red") {
46 $this->add_x_values($x_values);
47 $this->add_y_values($y_values);
48 $this->_colors[] = $color;
49 }
50
51
52 /**
53 * This function does the work of
54 * building the graph itself
55 *
56 * @return Container
57 */
58 function graph_data() {
59 $container = container();
60
61 $num_lines = count($this->_x_data);
62 for( $i=0; $i<=$num_lines-1; $i++) {
63 $container->add( $this->_build_line($this->_x_data[$i],
64 $this->_y_data[$i],
65 $this->_colors[$i]) );
66 }
67 return $container;
68 }
69
70
71 function _build_line($x_data, $y_data, $color) {
72 $x_data = explode(",", $x_data);
73 $y_data = explode(",", $y_data);
74 $num_points = count($y_data);
75
76 $container = container();
77 $x0 = $this->_draw["x1"];
78 $y0 = $this->_draw["y2"];
79
80 for($i=0; $i<$num_points-1; $i++) {
81 $x1=$x0+($x_data[$i]-$this->_min_x)*$this->_draw["draw_width"]/($this->_max_x-$this->_min_x);
82 $x2=$x0+($x_data[$i+1]-$this->_min_x)*$this->_draw["draw_width"]/($this->_max_x-$this->_min_x);
83
84 $y1=$y0-($y_data[$i]-$this->_min_y)*$this->_draw["draw_height"]/($this->_max_y-$this->_min_y);
85 $y2=$y0-($y_data[$i+1]-$this->_min_y)*$this->_draw["draw_height"]/($this->_max_y-$this->_min_y);
86
87 $container->add( svg_line($x1, $y1, $x2, $y2, $color, 2) );
88
89 $container->add( $this->_build_point($x1, $y1, 2, $color, $color) );
90 $container->add( $this->_build_point($x2, $y2, 2, $color, $color) );
91
92 }
93
94 return $container;
95 }
96
97 }
98
99 ?>

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed