Ejemplo 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;
 }
Ejemplo n.º 2
0
 /**
  * Draw a single rectangle
  *
  * @param array     $point          The
  * @param null      $index
  * @param string    $fill           The fill color to use
  * @param           $strokeWidth
  *
  * @return Rect
  */
 private function drawSingleBar($point, $index = null, $fill, $strokeWidth)
 {
     $rect = new Rect($point[0] - $this->barWidth / 2, $point[1], $this->barWidth, 100 - $point[1]);
     $rect->setFill($fill);
     $rect->setStrokeWidth($strokeWidth);
     $rect->setStrokeColor('black');
     if (isset($index)) {
         $rect->setAttribute('data-icinga-graph-index', $index);
     }
     $rect->setAttribute('data-icinga-graph-type', 'bar');
     $rect->setAdditionalStyle('clip-path: url(#clip);');
     return $rect;
 }
Ejemplo n.º 3
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;
 }