Esempio n. 1
0
 /**
  * Render the SVG-document
  *
  * @return string The resulting XML structure
  */
 public function render()
 {
     $this->createRootDocument();
     $ctx = $this->createRenderContext();
     $this->svg->appendChild($this->rootCanvas->toSvg($ctx));
     $this->document->formatOutput = true;
     return $this->document->saveXML();
 }
Esempio n. 2
0
 /**
  * Render the legend to an SVG object
  *
  * @param   RenderContext $ctx  The context to use for rendering this legend
  *
  * @return  DOMElement          The SVG representation of this legend
  */
 public function toSvg(RenderContext $ctx)
 {
     $outer = new Canvas('legend', new LayoutBox(0, 0, 100, 100));
     $outer->getLayout()->setPadding(2, 2, 2, 2);
     $nrOfColumns = 4;
     $topstep = 10 / $nrOfColumns + 2;
     $top = 0;
     $left = 0;
     $lastLabelEndPos = -1;
     foreach ($this->dataset as $color => $text) {
         $leftstep = 100 / $nrOfColumns + strlen($text);
         // Make sure labels don't overlap each other
         while ($lastLabelEndPos >= $left) {
             $left += $leftstep;
         }
         // When a label is longer than the available space, use the next line
         if ($left + strlen($text) > 100) {
             $top += $topstep;
             $left = 0;
         }
         $colorBox = new Rect($left, $top, 2, 2);
         $colorBox->setFill($color)->setStrokeWidth(2);
         $colorBox->keepRatio();
         $outer->addElement($colorBox);
         $textBox = new Text($left + 5, $top + 2, $text);
         $textBox->setFontSize('2em');
         $outer->addElement($textBox);
         // readjust layout
         $lastLabelEndPos = $left + strlen($text);
         $left += $leftstep;
     }
     $svg = $outer->toSvg($ctx);
     return $svg;
 }
Esempio n. 3
0
 /**
  * Render this GridChart to SVG
  *
  * @param   RenderContext $ctx The context to use for rendering
  *
  * @return  DOMElement
  */
 public function toSvg(RenderContext $ctx)
 {
     $outerBox = new Canvas('outerGraph', new LayoutBox(0, 0, 100, 100));
     $innerBox = new Canvas('graph', new LayoutBox(0, 0, 95, 90));
     $maxPadding = array(0, 0, 0, 0);
     foreach ($this->axis as $axis) {
         $padding = $axis->getRequiredPadding();
         for ($i = 0; $i < count($padding); $i++) {
             $maxPadding[$i] = max($maxPadding[$i], $padding[$i]);
         }
         $innerBox->addElement($axis);
     }
     $this->renderGraphContent($innerBox);
     $innerBox->getLayout()->setPadding($maxPadding[0], $maxPadding[1], $maxPadding[2], $maxPadding[3]);
     $this->createContentClipBox($innerBox);
     $outerBox->addElement($innerBox);
     if ($this->legend) {
         $outerBox->addElement($this->legend);
     }
     return $outerBox->toSvg($ctx);
 }
Esempio n. 4
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);
 }
Esempio n. 5
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);
 }