public function Fetch($header = TRUE, $defer_javascript = TRUE)
{
$content = '';
if ($header) {
$content .= '<?xml version="1.0"';
// encoding comes before standalone
if (strlen($this->encoding) > 0) {
$content .= " encoding=\"{$this->encoding}\"";
}
// '>' is with \n so as not to confuse syntax highlighting
$content .= " standalone=\"no\"?" . ">\n";
if ($this->doctype) {
$content .= '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" ' . '"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">' . "\n";
}
}
// set the precision - PHP default is 14 digits!
$old_precision = ini_set('precision', $this->precision);
// display title and description if available
$heading = '';
if ($this->title) {
$heading .= $this->Element('title', NULL, NULL, $this->title);
}
if ($this->description) {
$heading .= $this->Element('desc', NULL, NULL, $this->description);
}
try {
$this->CheckValues($this->values);
// get the body content from the subclass
$body = $this->DrawGraph();
} catch (Exception $e) {
$body = $this->ErrorText($e->getMessage());
}
$svg = array('width' => $this->width, 'height' => $this->height, 'version' => '1.1', 'xmlns:xlink' => 'http://www.w3.org/1999/xlink');
if (!$defer_javascript) {
$js = $this->FetchJavascript();
if ($js != '') {
$heading .= $js;
$onload = Graph::$javascript->GetOnload();
if ($onload != '') {
$svg['onload'] = $onload;
}
}
}
// insert any gradients that are used
foreach ($this->gradients as $key => $gradient_id) {
$this->defs[] = $this->MakeLinearGradient($gradient_id, $this->colours[$key]);
}
// show defs and body content
$heading .= $this->Element('defs', NULL, NULL, implode('', $this->defs));
if ($this->namespace) {
$svg['xmlns:svg'] = "http://www.w3.org/2000/svg";
} else {
$svg['xmlns'] = "http://www.w3.org/2000/svg";
}
// add any extra namespaces
foreach ($this->namespaces as $ns => $url) {
$svg['xmlns:' . $ns] = $url;
}
// display version string
if ($this->show_version) {
$text = array('x' => $this->pad_left, 'y' => $this->height - 3);
$style = array('font-family' => 'monospace', 'font-size' => '12px', 'font-weight' => 'bold');
$body .= $this->ContrastText($text['x'], $text['y'], SVGGRAPH_VERSION, 'blue', 'white', $style);
}
$content .= $this->Element('svg', $svg, NULL, $heading . $body);
// replace PHP's precision
ini_set('precision', $old_precision);
return $content;
}