/** * Create the SVG representation from this Drawable * * @param RenderContext $ctx The context to use for rendering * @return DOMElement The SVG Element */ public function toSvg(RenderContext $ctx) { $coords = $ctx->toAbsolute($this->x, $this->y); $circle = $ctx->getDocument()->createElement('circle'); $circle->setAttribute('cx', Format::formatSVGNumber($coords[0])); $circle->setAttribute('cy', Format::formatSVGNumber($coords[1])); $circle->setAttribute('r', $this->radius); $circle->setAttribute('style', $this->getStyle()); $this->applyAttributes($circle); return $circle; }
/** * Create the SVG representation from this Drawable * * @param RenderContext $ctx The context to use for rendering * @return DOMElement The SVG Element */ public function toSvg(RenderContext $ctx) { $doc = $ctx->getDocument(); list($x1, $y1) = $ctx->toAbsolute($this->xStart, $this->yStart); list($x2, $y2) = $ctx->toAbsolute($this->xEnd, $this->yEnd); $line = $doc->createElement('line'); $line->setAttribute('x1', Format::formatSVGNumber($x1)); $line->setAttribute('x2', Format::formatSVGNumber($x2)); $line->setAttribute('y1', Format::formatSVGNumber($y1)); $line->setAttribute('y2', Format::formatSVGNumber($y2)); $line->setAttribute('style', $this->getStyle()); $this->applyAttributes($line); return $line; }
/** * Create the SVG representation from this Drawable * * @param RenderContext $ctx The context to use for rendering * * @return DOMElement The SVG Element */ public function toSvg(RenderContext $ctx) { list($x, $y) = $ctx->toAbsolute($this->x, $this->y); $text = $ctx->getDocument()->createElement('text'); $text->setAttribute('x', Format::formatSVGNumber($x - 15)); $text->setAttribute('style', $this->getStyle() . ';font-size:' . $this->fontSize . '; font-family: Ubuntu, Calibri, Trebuchet MS, Helvetica, Verdana, sans-serif' . ';font-weight: ' . $this->fontWeight . ';font-stretch: ' . $this->fontStretch . '; font-style: normal;' . 'text-anchor: ' . $this->alignment); $text->setAttribute('y', Format::formatSVGNumber($y)); $text->appendChild(new DOMText($this->text)); return $text; }
/** * Create the SVG representation from this Drawable * * @param RenderContext $ctx The context to use for rendering * * @return DOMElement The SVG Element */ public function toSvg(RenderContext $ctx) { $doc = $ctx->getDocument(); $rect = $doc->createElement('rect'); list($x, $y) = $ctx->toAbsolute($this->x, $this->y); if ($this->keepRatio) { $ctx->keepRatio(); } list($width, $height) = $ctx->toAbsolute($this->width, $this->height); if ($this->keepRatio) { $ctx->ignoreRatio(); } $rect->setAttribute('x', Format::formatSVGNumber($x)); $rect->setAttribute('y', Format::formatSVGNumber($y)); $rect->setAttribute('width', Format::formatSVGNumber($width)); $rect->setAttribute('height', Format::formatSVGNumber($height)); $rect->setAttribute('style', $this->getStyle()); $this->applyAttributes($rect); $this->appendAnimation($rect, $ctx); return $rect; }
/** * Create the path for the pie slice * * @param int $x The x position of the pie slice * @param int $y The y position of the pie slice * @param int $r The absolute radius of the pie slice * * @return string A SVG path string */ private function getPieSlicePath($x, $y, $r) { // The coordinate system is mirrored on the Y axis, so we have to flip cos and sin $xStart = $x + $r * sin($this->startRadian); $yStart = $y - $r * cos($this->startRadian); if ($this->endRadian - $this->startRadian == 2 * M_PI) { // To draw a full circle, adjust arc endpoint by a small (unvisible) value $this->endRadian -= 0.001; $pathString = 'M ' . Format::formatSVGNumber($xStart) . ' ' . Format::formatSVGNumber($yStart); } else { // Start at the center of the pieslice $pathString = 'M ' . $x . ' ' . $y; // Draw a straight line to the upper part of the arc $pathString .= ' L ' . Format::formatSVGNumber($xStart) . ' ' . Format::formatSVGNumber($yStart); } // Instead of directly connecting the upper part of the arc (leaving a triangle), draw a bow with the radius $pathString .= ' A ' . Format::formatSVGNumber($r) . ' ' . Format::formatSVGNumber($r); // These are the flags for the bow, see the SVG path documentation for details // http://www.w3.org/TR/SVG/paths.html#PathDataEllipticalArcCommands $pathString .= ' 0 ' . ($this->endRadian - $this->startRadian > M_PI ? '1' : '0 ') . ' 1'; // xEnd and yEnd are the lower point of the arc $xEnd = $x + $r * sin($this->endRadian); $yEnd = $y - $r * cos($this->endRadian); $pathString .= ' ' . Format::formatSVGNumber($xEnd) . ' ' . Format::formatSVGNumber($yEnd); return $pathString; }
/** * Return a string containing the SVG transform attribute values for the padding * * @param RenderContext $ctx The context to determine the translation coordinates * * @return string The transformation string */ public function getInnerTransform(RenderContext $ctx) { list($translateX, $translateY) = $ctx->toAbsolute($this->padding[self::PADDING_LEFT] + $this->getX(), $this->padding[self::PADDING_TOP] + $this->getY()); list($scaleX, $scaleY) = $ctx->paddingToScaleFactor($this->padding); $scaleX *= $this->getWidth() / 100; $scaleY *= $this->getHeight() / 100; return sprintf('translate(%s, %s) scale(%s, %s)', Format::formatSVGNumber($translateX), Format::formatSVGNumber($translateY), Format::formatSVGNumber($scaleX), Format::formatSVGNumber($scaleY)); }
/** * Create the SVG representation from this Drawable * * @param RenderContext $ctx The context to use for rendering * @return DOMElement The SVG Element */ public function toSvg(RenderContext $ctx) { $doc = $ctx->getDocument(); $group = $doc->createElement('g'); $pathDescription = ''; $tpl = self::TPL_MOVE; $lastPoint = null; foreach ($this->points as $point) { if (!$this->isAbsolute) { $point = $ctx->toAbsolute($point[0], $point[1]); } $point[0] = Format::formatSVGNumber($point[0]); $point[1] = Format::formatSVGNumber($point[1]); if ($lastPoint && $this->discrete) { $pathDescription .= sprintf($tpl, $point[0], $lastPoint[1]); } $pathDescription .= vsprintf($tpl, $point); $lastPoint = $point; $tpl = self::TPL_STRAIGHT; } $path = $doc->createElement('path'); if ($this->id) { $path->setAttribute('id', $this->id); } $path->setAttribute('d', $pathDescription); $path->setAttribute('style', $this->getStyle()); $this->applyAttributes($path); $group->appendChild($path); return $group; }