public static function getInstance($x, $y, $id, $width, $height, $style = null) { $rect = new SVGRect('<rect></rect>'); $rect->setX($x); $rect->setY($y); $rect->setWidth($width); $rect->setHeight($height); $rect->setId($id); $rect->setStyle($style); return $rect; }
* * @author Eduardo Bonfandini * *----------------------------------------------------------------------- * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as published * by the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this program; if not, access * http://www.fsf.org/licensing/licenses/lgpl.html or write to the * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *---------------------------------------------------------------------- */ require_once "../svglib/svglib.php"; $svg = SVGDocument::getInstance(); #start a svgDocument using default (minimal) svg document $svg->setTitle("Simple example"); #define the title $rect = SVGRect::getInstance(0, 5, 'myRect', 228, 185, new SVGStyle(array('fill' => 'blue', 'stroke' => 'gray'))); #create a new rect with, x and y position, id, width and heigth, and the style $svg->addShape($rect); #add the rect to svg $svg->output(); #output to browser, with header
#add some javascript functions $svg->addScript("\n function changeColor(evt, element)\n {\n destination = document.getElementById('destination');\n\n if ( evt.ctrlKey )\n {\n destination.style.stroke = element.style.fill;\n }\n else\n {\n destination.style.fill = element.style.fill;\n }\n\n evt.preventDefault();\n return false;\n }\n"); #mount a simple color array $colors[] = 'red'; $colors[] = 'green'; $colors[] = 'blue'; $colors[] = 'yellow'; $colors[] = 'orange'; $colors[] = 'gray'; $colors[] = 'black'; $colors[] = 'white'; $text = SVGText::getInstance(10, 25, null, 'Left click for fill - control click for stroke'); $svg->addShape($text); foreach ($colors as $line => $color) { $rect = SVGRect::getInstance($line * 60 + 10, 40, null, 50, 50); $style = new SVGStyle(); $style->setFill($color); $style->setStroke("darkGray", 1); $rect->setStyle($style); $rect->addOnclick("return changeColor(evt,this);"); $rect->addAttribute("onmouseover", "this.style.stroke = 'lightGray';"); $rect->addAttribute("onmouseout", "this.style.stroke = 'gray';"); $svg->addShape($rect); } $rect = SVGRect::getInstance(140, 100, 'destination', 200, 200); $style = new SVGStyle(); $style->setFill('none'); $style->setStroke("darkGray", 5); $rect->setStyle($style); $svg->addShape($rect); $svg->output();
* * You should have received a copy of the GNU Library General Public * License along with this program; if not, access * http://www.fsf.org/licensing/licenses/lgpl.html or write to the * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * ---------------------------------------------------------------------- */ require_once "../svglib/svglib.php"; $rotate = @$_REQUEST['rotate']; //rotate the square using passed angle $translate = @$_REQUEST['translate']; //rotate the square using passed angle $file = @$_REQUEST['file']; //load the file passed $fill = @$_REQUEST['fill'] ? @$_REQUEST['fill'] : 'red'; $stroke = @$_REQUEST['stroke'] ? @$_REQUEST['stroke'] : 'black'; $svg = SVGDocument::getInstance($file); $style = new SVGStyle(); $style->setFill($fill); $style->setStroke($stroke); $rect = SVGRect::getInstance(50, 50, 'myRect', 100, 100, $style); if ($rotate) { //uses the x and y properties to align the rect $rect->rotate($rotate, $rect->getX() * 2, $rect->getY() * 2); } if ($translate) { $translate = explode(',', $translate); $rect->translate($translate[0], $translate[1]); } $svg->addShape($rect); $svg->output();
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'); }" ); */ }
* You should have received a copy of the GNU Library General Public * License along with this program; if not, access * http://www.fsf.org/licensing/licenses/lgpl.html or write to the * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *---------------------------------------------------------------------- */ require_once "../svglib/svglib.php"; $svg = SVGDocument::getInstance(); #a way to create a stop $stop = SVGStop::getInstance(); $stop->setColor('red'); $stop->setOpacity(1); $stops[] = $stop; #a second way to create a stop $stops[] = SVGStop::getInstance(null, "stop-color:blue;stop-opacity:1"); $stops[] = SVGStop::getInstance(null, "stop-color:black;stop-opacity:1"); $gradient = SVGLinearGradient::getInstance(null, $stops); $svg->addDefs($gradient); $style = new SVGStyle(); $style->setFill($gradient); $svg->addShape(SVGRect::getInstance(10, 20, null, '100', '200', $style)); #second rect $stops2[] = SVGStop::getInstance(null, "stop-color:yellow;stop-opacity:1"); $stops2[] = SVGStop::getInstance(null, "stop-color:green;stop-opacity:1"); $radial = SVGRadialGradient::getInstance(null, $stops2); $svg->addDefs($radial); $style2 = new SVGStyle(); $style2->setFill($radial); $rect2 = SVGRect::getInstance(150, 20, null, 100, 200, $style2); $svg->addShape($rect2); $svg->output();