public static function getInstance($x1, $y1, $x2, $y2, $id = null, $style = null) { $rect = new SVGLine('<line></line>'); $rect->setX1($x1); $rect->setX2($x2); $rect->setY1($y1); $rect->setY2($y2); $rect->setId($id); $rect->setStyle($style); 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'); }" ); */ }
$style2 = new SVGStyle(); $style2->setFill('none'); $style2->setStroke('blue', 3); $ellipse->setStyle($style2); $svg->addShape($ellipse); $style = new SVGStyle(); #create a style object #set fill and stroke $style->setFill('#f2f2f2'); $style->setStroke('#e1a100'); $style->setStrokeWidth(2); #create a text $text = SVGText::getInstance(22, 50, 'myText', 'This is a text', $style); $svg->addShape($text); #$svg->addShape( SVGPath::getInstance( array('m 58,480','639,1'), 'myPath', 'fill:none;stroke:#000000;stroke-width:1px;') );#create a path $svg->addShape(SVGLine::getInstance(50, 50, 500, 500, null, $style)); #many types of output try { $svg->asXML(getcwd() . '/output/output.svg'); #svg #example how to using SVG Inkscape #define('INKSCAPE_PATH', 'H:\ferramentas\Inkscape\inkscape' ); #$svg->export( getcwd() . '/output/inkscape.png', null, null, true, SVGDocument::EXPORT_TYPE_INKSCAPE ); #$svg->export( getcwd() . '/output/output.png' ); #png $svg->export(getcwd() . '/output/output.jpg'); #jpg $svg->export(getcwd() . '/output/output.gif'); #gif $svg->export(getcwd() . '/output/thumb16x16.png', 16, 16, true); #png resized using imagemagick $svg->export(getcwd() . '/output/thumb32x32.png', 32, 32, true);