| 1 |
<?php |
| 2 |
/** |
| 3 |
* This file holds the base Graph class for doing |
| 4 |
* SVG graphs |
| 5 |
* |
| 6 |
* $Id: SVGGraph.inc,v 1.5 2003/03/04 22:15:18 hemna Exp $ |
| 7 |
* |
| 8 |
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
| 9 |
* @package phpHtmlLib |
| 10 |
* @subpackage SVG |
| 11 |
*/ |
| 12 |
|
| 13 |
/** |
| 14 |
* This is the base Graph class for doing |
| 15 |
* SVG graphs |
| 16 |
* |
| 17 |
* $Id: SVGGraph.inc,v 1.5 2003/03/04 22:15:18 hemna Exp $ |
| 18 |
* |
| 19 |
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
| 20 |
* @package phpHtmlLib |
| 21 |
* @subpackage SVG |
| 22 |
*/ |
| 23 |
class SVGGraph extends BaseWidget { |
| 24 |
|
| 25 |
|
| 26 |
/** |
| 27 |
* This array holds various |
| 28 |
* config options for this graph |
| 29 |
*/ |
| 30 |
var $_options = array("title" => "", |
| 31 |
"title_style" => "font-size:20px;font-weight:bold;font-family: geneva, trebuchet ms", |
| 32 |
"width" => 100, |
| 33 |
"height" => 100, |
| 34 |
"left_margin" => 5, |
| 35 |
"right_margin" => 0, |
| 36 |
"top_margin" => 20, |
| 37 |
"bottom_margin" => 0, |
| 38 |
"title_font_width" => 10, |
| 39 |
"title_font_height" => 20, |
| 40 |
"axis_font_width" => 5, |
| 41 |
"axis_font_height" => 8, |
| 42 |
"axis_label_font_width" => 12, |
| 43 |
"axis_label_font_height" => 12); |
| 44 |
|
| 45 |
|
| 46 |
/** |
| 47 |
* Various calculated image properties |
| 48 |
* |
| 49 |
*/ |
| 50 |
var $_draw = array(); |
| 51 |
|
| 52 |
|
| 53 |
function SVGGraph($title, $width, $height) { |
| 54 |
$this->set_title($title); |
| 55 |
$this->set_width($width); |
| 56 |
$this->set_height($height); |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
function render($indent_level=0, $output_debug=0) { |
| 61 |
//do any data parsing/munging/calculating |
| 62 |
$this->_prepare_data(); |
| 63 |
|
| 64 |
$container = container(); |
| 65 |
$container->add( $this->_build_titles() ); |
| 66 |
$container->add( $this->_build_graph() ); |
| 67 |
return $container->render($indent_level, $output_debug); |
| 68 |
} |
| 69 |
|
| 70 |
/** |
| 71 |
* This is a stub meant to provide a means |
| 72 |
* for doing any data parsing/munging |
| 73 |
* prior to actually building the svg |
| 74 |
* for the graph output. |
| 75 |
* |
| 76 |
*/ |
| 77 |
function _prepare_data() { |
| 78 |
return NULL; |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
/** |
| 83 |
* This is a stub for building the title(s) |
| 84 |
* for the graph |
| 85 |
* |
| 86 |
* @return Container |
| 87 |
*/ |
| 88 |
function _build_titles() { |
| 89 |
return $this->_build_title(); |
| 90 |
} |
| 91 |
|
| 92 |
/** |
| 93 |
* This is a stub that the child class |
| 94 |
* must override to build the actual |
| 95 |
* graph |
| 96 |
* |
| 97 |
* @return Container |
| 98 |
*/ |
| 99 |
function _build_graph() { |
| 100 |
return NULL; |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
/****************************/ |
| 105 |
/* options functions */ |
| 106 |
/****************************/ |
| 107 |
|
| 108 |
|
| 109 |
/** |
| 110 |
* This function is used to set |
| 111 |
* a particular option for the |
| 112 |
* graph |
| 113 |
* |
| 114 |
* @param string - the option name |
| 115 |
* @param mixed - the value |
| 116 |
*/ |
| 117 |
function set_option( $name, $value ) { |
| 118 |
$this->_options[$name] = $value; |
| 119 |
} |
| 120 |
|
| 121 |
/** |
| 122 |
* This function retuns the value |
| 123 |
* of 1 option |
| 124 |
* |
| 125 |
* @param string - the option name |
| 126 |
* @return mixed - the value |
| 127 |
*/ |
| 128 |
function get_option($name) { |
| 129 |
return $this->_options[$name]; |
| 130 |
} |
| 131 |
|
| 132 |
/** |
| 133 |
* This returns the array of ALL |
| 134 |
* of the options for this graph |
| 135 |
* |
| 136 |
* @return array |
| 137 |
*/ |
| 138 |
function get_options() { |
| 139 |
return $this->_options; |
| 140 |
} |
| 141 |
|
| 142 |
|
| 143 |
/** |
| 144 |
* This method sets the title for |
| 145 |
* the graph |
| 146 |
* |
| 147 |
* @param string - the graph's title |
| 148 |
*/ |
| 149 |
function set_title($title) { |
| 150 |
$this->_options["title"] = $title; |
| 151 |
} |
| 152 |
|
| 153 |
/** |
| 154 |
* This method sets the title for |
| 155 |
* the graph |
| 156 |
* |
| 157 |
* @param string - the graph's title |
| 158 |
*/ |
| 159 |
function set_title_style($style) { |
| 160 |
$this->_options["title_style"] = $style; |
| 161 |
} |
| 162 |
|
| 163 |
/** |
| 164 |
* This method sets the width |
| 165 |
* of the graph |
| 166 |
* |
| 167 |
* @param int - the width |
| 168 |
*/ |
| 169 |
function set_width($width) { |
| 170 |
$this->_options["width"] = $width; |
| 171 |
} |
| 172 |
|
| 173 |
/** |
| 174 |
* This method sets the height |
| 175 |
* of the graph |
| 176 |
* |
| 177 |
* @param int - the height |
| 178 |
*/ |
| 179 |
function set_height($height) { |
| 180 |
$this->_options["height"] = $height; |
| 181 |
} |
| 182 |
|
| 183 |
/** |
| 184 |
* This method sets the width |
| 185 |
* of font in pixels for the |
| 186 |
* Graph Title. |
| 187 |
* |
| 188 |
* @param int - the width |
| 189 |
*/ |
| 190 |
function set_title_font_width($width) { |
| 191 |
$this->_options["title_font_width"] = $width; |
| 192 |
} |
| 193 |
|
| 194 |
/** |
| 195 |
* This method sets the height |
| 196 |
* of font in pixels for the |
| 197 |
* Graph Title. |
| 198 |
* |
| 199 |
* @param int - the height |
| 200 |
*/ |
| 201 |
function set_title_font_height($height) { |
| 202 |
$this->_options["title_font_height"] = $height; |
| 203 |
} |
| 204 |
|
| 205 |
|
| 206 |
/** |
| 207 |
* This method sets the width |
| 208 |
* of font used in calculating |
| 209 |
* the x and y axis point fonts. |
| 210 |
* |
| 211 |
* @param int - the width |
| 212 |
*/ |
| 213 |
function set_axis_font_width($width) { |
| 214 |
$this->_options["axis_font_width"] = $width; |
| 215 |
} |
| 216 |
|
| 217 |
/** |
| 218 |
* This method sets the height |
| 219 |
* of font used in calculating |
| 220 |
* the x and y axis point fonts. |
| 221 |
* |
| 222 |
* @param int - the height |
| 223 |
*/ |
| 224 |
function set_axis_font_height($height) { |
| 225 |
$this->_options["axis_font_height"] = $height; |
| 226 |
} |
| 227 |
|
| 228 |
|
| 229 |
/** |
| 230 |
* This function will format the axis label |
| 231 |
* |
| 232 |
* @param string - the number |
| 233 |
* @return string - the formated # |
| 234 |
*/ |
| 235 |
function format_label($number) { |
| 236 |
return sprintf("%.2f",$number); |
| 237 |
} |
| 238 |
|
| 239 |
|
| 240 |
/** |
| 241 |
* This method builds the text title area |
| 242 |
* that lives on top of the graph |
| 243 |
* |
| 244 |
* @return TEXTsvgtag |
| 245 |
*/ |
| 246 |
function _build_title() { |
| 247 |
$x = ($this->_draw["x2"] - $this->_draw["x1"])/2 - |
| 248 |
((strlen($this->_options["title"])*$this->_options["title_font_width"])/4); |
| 249 |
$text = svg_text($x,20); |
| 250 |
$text->set_style($this->_options["title_style"]); |
| 251 |
$text->add( $this->_options["title"] ); |
| 252 |
$text->set_collapse(); |
| 253 |
return $text; |
| 254 |
} |
| 255 |
} |
| 256 |
?> |