Example #1
0
 /**
  * Render this stack in the correct order
  *
  * @param   RenderContext $ctx  The context to use for rendering
  *
  * @return  DOMElement          The SVG representation of this graph
  */
 public function toSvg(RenderContext $ctx)
 {
     $group = $ctx->getDocument()->createElement('g');
     $renderOrder = array_reverse($this->stack);
     foreach ($renderOrder as $stackElem) {
         $group->appendChild($stackElem->toSvg($ctx));
     }
     return $group;
 }
Example #2
0
 /**
  * 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;
 }
Example #3
0
 /**
  * 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)
 {
     $animate = $ctx->getDocument()->createElement('animate');
     $animate->setAttribute('attributeName', $this->attribute);
     $animate->setAttribute('attributeType', 'XML');
     $animate->setAttribute('from', $this->from);
     $animate->setAttribute('to', $this->to);
     $animate->setAttribute('begin', $this->begin . 's');
     $animate->setAttribute('dur', $this->duration . 's');
     $animate->setAttributE('fill', "freeze");
     return $animate;
 }
Example #4
0
 /**
  * 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;
 }
Example #5
0
 /**
  * Rotate the given element.
  *
  * @param RenderContext $ctx        The rendering context
  * @param DOMElement    $el         The element to rotate
  * @param               $degrees    The amount of degrees
  *
  * @return DOMElement   The rotated DOMElement
  */
 private function rotate(RenderContext $ctx, DOMElement $el, $degrees)
 {
     // Create a box containing the rotated element relative to the original element position
     $container = $ctx->getDocument()->createElement('g');
     $x = $el->getAttribute('x');
     $y = $el->getAttribute('y');
     $container->setAttribute('transform', 'translate(' . $x . ',' . $y . ')');
     $el->removeAttribute('x');
     $el->removeAttribute('y');
     // Put the element into a rotated group
     //$rotate = $ctx->getDocument()->createElement('g');
     $el->setAttribute('transform', 'rotate(' . $degrees . ')');
     //$rotate->appendChild($el);
     $container->appendChild($el);
     return $container;
 }
Example #6
0
 /**
  * Render this BarChart
  *
  * @param   RenderContext   $ctx    The rendering context to use for drawing
  *
  * @return  DOMElement      $dom    Element
  */
 public function toSvg(RenderContext $ctx)
 {
     $doc = $ctx->getDocument();
     $group = $doc->createElement('g');
     $idx = 0;
     foreach ($this->dataSet as $point) {
         $rect = new Rect($point[0] - 1, $point[1], $this->barWidth, 100 - $point[1]);
         $rect->setFill($this->fill);
         $rect->setStrokeWidth($this->strokeWidth);
         $rect->setStrokeColor('black');
         $rect->setAttribute('data-icinga-graph-index', $idx++);
         $rect->setAttribute('data-icinga-graph-type', 'bar');
         $rect->setAdditionalStyle('clip-path: url(#clip);');
         /*$rect->setAnimation(
               new Animation(
                   'y',
                   $ctx->yToAbsolute(100),
                   $ctx->yToAbsolute($point[1]),
                   rand(1, 1.5)/2
               )
           );*/
         $group->appendChild($rect->toSvg($ctx));
     }
     return $group;
 }
Example #7
0
 /**
  * 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;
 }
Example #8
0
 /**
  * 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;
 }
Example #9
0
 /**
  * Render this BarChart
  *
  * @param   RenderContext   $ctx    The rendering context to use for drawing
  *
  * @return  DOMElement      $dom    Element
  */
 public function toSvg(RenderContext $ctx)
 {
     $doc = $ctx->getDocument();
     $group = $doc->createElement('g');
     $idx = 0;
     if (count($this->dataSet) > 15) {
         $this->barWidth = 2;
     }
     if (count($this->dataSet) > 25) {
         $this->barWidth = 1;
     }
     foreach ($this->dataSet as $x => $point) {
         // add white background bar, to prevent other bars from altering transparency effects
         $bar = $this->drawSingleBar($point, $idx++, 'white', $this->strokeWidth, $idx)->toSvg($ctx);
         $group->appendChild($bar);
         // draw actual bar
         $bar = $this->drawSingleBar($point, null, $this->fill, $this->strokeWidth, $idx)->toSvg($ctx);
         $bar->setAttribute('class', 'chart-data');
         if (isset($this->tooltips[$x])) {
             $data = array('label' => isset($this->graphs[$this->order]['label']) ? strtolower($this->graphs[$this->order]['label']) : '', 'color' => isset($this->graphs[$this->order]['color']) ? strtolower($this->graphs[$this->order]['color']) : '#fff');
             $format = isset($this->graphs[$this->order]['tooltip']) ? $this->graphs[$this->order]['tooltip'] : null;
             $bar->setAttribute('title', $this->tooltips[$x]->renderNoHtml($this->order, $data, $format));
             $bar->setAttribute('data-title-rich', $this->tooltips[$x]->render($this->order, $data, $format));
         }
         $group->appendChild($bar);
     }
     return $group;
 }
Example #10
0
 /**
  * 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();
     if ($this->isClipPath) {
         $outer = $doc->createElement('defs');
         $innerContainer = $element = $doc->createElement('clipPath');
         $outer->appendChild($element);
     } else {
         $outer = $element = $doc->createElement('g');
         $innerContainer = $doc->createElement('g');
         $innerContainer->setAttribute('x', 0);
         $innerContainer->setAttribute('y', 0);
         $innerContainer->setAttribute('id', $this->name . '_inner');
         $innerContainer->setAttribute('transform', $this->rect->getInnerTransform($ctx));
         $element->appendChild($innerContainer);
     }
     $element->setAttribute('id', $this->name);
     foreach ($this->children as $child) {
         $innerContainer->appendChild($child->toSvg($ctx));
     }
     if (isset($this->ariaRole)) {
         $outer->setAttribute('role', $this->ariaRole);
     }
     return $outer;
 }
Example #11
0
 /**
  * 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');
     $r = ($ctx->xToAbsolute($this->radius) + $ctx->yToAbsolute($this->radius)) / 2;
     list($x, $y) = $ctx->toAbsolute($this->x, $this->y);
     $slicePath = $doc->createElement('path');
     $slicePath->setAttribute('d', $this->getPieSlicePath($x, $y, $r));
     $slicePath->setAttribute('style', $this->getStyle());
     $slicePath->setAttribute('data-icinga-graph-type', 'pieslice');
     $this->applyAttributes($slicePath);
     $group->appendChild($slicePath);
     if ($this->caption != "") {
         $lblGroup = $this->labelGroup ? $this->labelGroup : $group;
         $lblGroup->appendChild($this->drawDescriptionLabel($ctx, $r));
     }
     return $group;
 }
Example #12
0
 /**
  * Return the SVG representation of this graph
  *
  * @param RenderContext $ctx    The context to use for drawings
  *
  * @return DOMElement           The SVG representation of this graph
  */
 public function toSvg(RenderContext $ctx)
 {
     $outerBox = new Canvas('outerGraph', new LayoutBox(0, 0, 100, 100));
     $innerBox = new Canvas('graph', new LayoutBox(0, 0, 100, 100));
     $labelBox = $ctx->getDocument()->createElement('g');
     if (!$this->noCaption) {
         $innerBox->getLayout()->setPadding(10, 10, 10, 10);
     }
     $this->createContentClipBox($innerBox);
     $this->renderPies($innerBox, $labelBox);
     $innerBox->addElement(new RawElement($labelBox));
     $outerBox->addElement($innerBox);
     return $outerBox->toSvg($ctx);
 }
Example #13
0
 /**
  * Return the SVG representation of this object
  *
  * @param   RenderContext $ctx The context to use for calculations
  *
  * @return  DOMElement
  * @see     Drawable::toSvg
  */
 public function toSvg(RenderContext $ctx)
 {
     $group = $ctx->getDocument()->createElement('g');
     $this->renderHorizontalAxis($ctx, $group);
     $this->renderVerticalAxis($ctx, $group);
     return $group;
 }
Example #14
0
 /**
  * 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));
 }
Example #15
0
 /**
  * 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;
 }
Example #16
0
 /**
  * Return the SVG representation of this graph
  *
  * @param RenderContext $ctx    The context to use for drawings
  *
  * @return DOMElement           The SVG representation of this graph
  */
 public function toSvg(RenderContext $ctx)
 {
     $labelBox = $ctx->getDocument()->createElement('g');
     if (!$this->noCaption) {
         // Scale SVG to make room for captions
         $outerBox = new Canvas('outerGraph', new LayoutBox(33, -5, 40, 40));
         $innerBox = new Canvas('graph', new LayoutBox(0, 0, 100, 100));
         $innerBox->getLayout()->setPadding(10, 10, 10, 10);
     } else {
         $outerBox = new Canvas('outerGraph', new LayoutBox(1.5, -10, 124, 124));
         $innerBox = new Canvas('graph', new LayoutBox(0, 0, 100, 100));
         $innerBox->getLayout()->setPadding(0, 0, 0, 0);
     }
     $this->createContentClipBox($innerBox);
     $this->renderPies($innerBox, $labelBox);
     $innerBox->addElement(new RawElement($labelBox));
     $outerBox->addElement($innerBox);
     return $outerBox->toSvg($ctx);
 }