private static function parseNode($node) { $type = $node->getName(); if ($type === 'g') { $element = new SVGGroup(); $children = $node->children(); foreach ($children as $child) { $element->addChild(self::parseNode($child)); } } else { if ($type === 'rect') { $w = isset($node['width']) ? $node['width'] : 0; $h = isset($node['height']) ? $node['height'] : 0; $x = isset($node['x']) ? $node['x'] : 0; $y = isset($node['y']) ? $node['y'] : 0; $element = new SVGRect($x, $y, $w, $h); } else { if ($type === 'circle') { $cx = isset($node['cx']) ? $node['cx'] : 0; $cy = isset($node['cy']) ? $node['cy'] : 0; $r = isset($node['r']) ? $node['r'] : 0; $element = new SVGCircle($cx, $cy, $r); } else { if ($type === 'ellipse') { $cx = isset($node['cx']) ? $node['cx'] : 0; $cy = isset($node['cy']) ? $node['cy'] : 0; $rx = isset($node['rx']) ? $node['rx'] : 0; $ry = isset($node['ry']) ? $node['ry'] : 0; $element = new SVGEllipse($cx, $cy, $rx, $ry); } else { if ($type === 'line') { $x1 = isset($node['x1']) ? $node['x1'] : 0; $y1 = isset($node['y1']) ? $node['y1'] : 0; $x2 = isset($node['x2']) ? $node['x2'] : 0; $y2 = isset($node['y2']) ? $node['y2'] : 0; $element = new SVGLine($x1, $y1, $x2, $y2); } else { if ($type === 'polygon' || $type === 'polyline') { $element = $type === 'polygon' ? new SVGPolygon() : new SVGPolyline(); $points = isset($node['points']) ? preg_split('/[\\s,]+/', $node['points']) : array(); for ($i = 0, $n = floor(count($points) / 2); $i < $n; $i++) { $element->addPoint($points[$i * 2], $points[$i * 2 + 1]); } } else { if ($type === 'path') { $d = isset($node['d']) ? $node['d'] : ''; $element = new SVGPath($d); } } } } } } } if (!isset($element)) { return false; } $attributes = $node->attributes(); $ignoredAttributes = array('x', 'y', 'width', 'height', 'x1', 'y1', 'x2', 'y2', 'cx', 'cy', 'r', 'rx', 'ry', 'points', 'style'); foreach ($attributes as $attribute => $value) { if (in_array($attribute, $ignoredAttributes)) { continue; } $element->setStyle($attribute, $value); } if (isset($node['style'])) { $styles = self::parseStyles($node['style']); foreach ($styles as $style => $value) { $element->setStyle($style, $value); } } return $element; }
public static function getInstance($id) { $rect = new SVGGroup('<g></g>'); $rect->setId($id); return $rect; }
public function onCreate() { if (!$this->getMaxY()) { $this->findMaxY(); } if (!$this->getMaxX()) { $this->findMaxX(); } $this->setWidth($this->getMaxX() + 100 . 'px'); $this->setHeight($this->getMaxY() + 100 . 'px'); $this->setDefaultViewBox(); $clipPath = SVGClipPath::getInstance('clipPath'); $clipRect = SVGRect::getInstance(0, 0, null, $this->getWidth(), $this->getHeight()); $clipPath->addShape($clipRect); $this->addDefs($clipPath); $backGroup = SVGGroup::getInstance('backGroup'); $line1 = SVGLine::getInstance($this->startX, $this->startY, $this->startX, $this->maxY + $this->startY, null, new SVGStyle(array('stroke' => 'black', 'stroke-width' => 1))); $line2 = SVGLine::getInstance($this->startX, $this->maxY + $this->startY, $this->maxX + $this->startX, $this->maxY + $this->startY, null, new SVGStyle(array('stroke' => 'black', 'stroke-width' => 1))); $backGroup->addShape($line1); $backGroup->addShape($line2); #vertical counter for ($i = 0; $i <= $this->maxY; $i += 25) { $text = SVGText::getInstance($this->startX - 30, $this->startY + $i, null, $this->maxY - $i); $text->setStyle("font-family:Arial"); $backGroup->addShape($text); } #horizontal counter for ($i = 0; $i <= $this->maxX; $i += 50) { $text = SVGText::getInstance($this->startX + $i, $this->startY + $this->maxY + 20, null, $i); $text->setStyle("font-family:Arial"); $backGroup->addShape($text); } $data = $this->getData(); $mainGroup = SVGGroup::getInstance('mainGroup'); $mainGroup->setStyle(new SVGStyle(array('clip-path' => 'url(#clipPath)'))); if (is_array($data)) { foreach ($data as $obj) { $itemData = $obj->data; $style = $obj->style; if (!$style) { $style = new SVGStyle(array('stroke' => 'blue', 'fill' => 'blue', 'stroke-width' => 1)); } if (is_array($itemData)) { foreach ($itemData as $line => $info) { $previous = $this->normalizeLineData(@$itemData[$line - 1]); $info = $this->normalizeLineData($info); $line = SVGLine::getInstance($previous[0], $previous[1], $info[0], $info[1], null, $style); //$this->addShape( $line ); $mainGroup->addShape($line); $circle = SVGCircle::getInstance($info[0], $info[1], 3, null, $style); $circle->setTitle($info[0] . ',' . $info[1]); $circle->addAttribute("onmouseover", "this.style.stroke = 'lightGray';"); $circle->addAttribute("onmouseout", "this.style.stroke = 'gray';"); //$this->addShape( $circle ); $mainGroup->addShape($circle); } } } } $this->addShape($backGroup); $this->addShape($mainGroup); $this->addScript("\n var width = \$('svg').attr('width').replace('px','');\n \$('svg #clippath rect').attr('width',0);\n var anim = setInterval('slideRight()', 1);\n\n function slideRight()\n {\n var currentWidth = parseInt( \$('svg #clippath rect').attr('width') );\n currentWidth += 1;\n\n \$('svg #clippath rect').attr('width',currentWidth );\n\n if ( currentWidth >= width )\n {\n clearInterval(anim);\n }\n }\n"); /* $this->addScript( " $('svg #mainGroup').hide(); setTimeout('showGraph()', 500); function showGraph() { $('svg #mainGroup').hide(); $('svg #mainGroup').show('slow'); }" ); */ }