Exemplo n.º 1
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;
 }
Exemplo n.º 2
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();
 }
Exemplo n.º 3
0
 /**
  * Render the content of the graph, i.e. the draw stack
  *
  * @param Canvas $innerBox The inner canvas of the graph to add the content to
  */
 private function renderGraphContent(Canvas $innerBox)
 {
     foreach ($this->graphs as $axisName => $graphs) {
         $axis = $this->axis[$axisName];
         $graphObj = null;
         foreach ($graphs as $dataset => $graph) {
             // determine the type and create a graph object for it
             switch ($graph['graphType']) {
                 case self::TYPE_BAR:
                     $graphObj = new BarGraph($axis->transform($graph['data']), $graphs, $dataset, $this->tooltips);
                     break;
                 case self::TYPE_LINE:
                     $graphObj = new LineGraph($axis->transform($graph['data']), $graphs, $dataset, $this->tooltips);
                     break;
                 default:
                     continue;
             }
             $el = $this->setupGraph($graphObj, $graph);
             if ($el) {
                 $innerBox->addElement($el);
             }
         }
     }
 }
Exemplo n.º 4
0
 /**
  * Create the content for this PieChart
  *
  * @param Canvas $innerBox      The innerbox to add the clip mask to
  */
 private function createContentClipBox(Canvas $innerBox)
 {
     $clipBox = new Canvas('clip', new LayoutBox(0, 0, 100, 100));
     $clipBox->toClipPath();
     $innerBox->addElement($clipBox);
     $rect = new Rect(0.1, 0, 100, 99.90000000000001);
     $clipBox->addElement($rect);
 }