Ejemplo n.º 1
0
 /**
  * Render this BarChart
  *
  * @param   RenderContext   $ctx    The rendering context to use for drawing
  *
  * @return  DOMElement      $dom    Element
  */
 public function toSvg(RenderContext $ctx)
 {
     $path = new Path($this->dataset);
     if ($this->isDiscrete) {
         $path->setDiscrete(true);
     }
     $path->setStrokeColor($this->strokeColor);
     $path->setStrokeWidth($this->strokeWidth);
     $path->setAttribute('data-icinga-graph-type', 'line');
     if ($this->fill !== 'none') {
         $firstX = $this->dataset[0][0];
         $lastX = $this->dataset[count($this->dataset) - 1][0];
         $path->prepend(array($firstX, 100))->append(array($lastX, 100));
         $path->setFill($this->fill);
     }
     $path->setAdditionalStyle('clip-path: url(#clip);');
     $path->setId($this->id);
     $group = $path->toSvg($ctx);
     if ($this->showDataPoints === true) {
         foreach ($this->dataset as $point) {
             $dot = new Circle($point[0], $point[1], $this->strokeWidth * 5);
             $dot->setFill('black');
             $group->appendChild($dot->toSvg($ctx));
         }
     }
     return $group;
 }
Ejemplo n.º 2
0
 /**
  * Draw the label handler and the text for this pie slice
  *
  * @param   RenderContext $ctx  The rendering context to use for coordinate translation
  * @param   int           $r    The radius of the pie in absolute coordinates
  *
  * @return  DOMElement          The group DOMElement containing the handle and label
  */
 private function drawDescriptionLabel(RenderContext $ctx, $r)
 {
     $group = $ctx->getDocument()->createElement('g');
     $rOuter = ($ctx->xToAbsolute($this->outerCaptionBound) + $ctx->yToAbsolute($this->outerCaptionBound)) / 2;
     $addOffset = $rOuter - $r;
     if ($addOffset < 0) {
         $addOffset = 0;
     }
     list($x, $y) = $ctx->toAbsolute($this->x, $this->y);
     $midRadius = $this->startRadian + ($this->endRadian - $this->startRadian) / 2;
     list($offsetX, $offsetY) = $ctx->toAbsolute($this->captionOffset, $this->captionOffset);
     $midX = $x + intval(($offsetX + $r) / 2 * sin($midRadius));
     $midY = $y - intval(($offsetY + $r) / 2 * cos($midRadius));
     // Draw the handle
     $path = new Path(array($midX, $midY));
     $midX += ($addOffset + $r / 1.8) * ($midRadius > M_PI ? -1 : 1);
     $path->append(array($midX, $midY))->toAbsolute();
     $midX += intval($r / 2 * sin(M_PI / 9)) * ($midRadius > M_PI ? -1 : 1);
     $midY -= intval($r / 2 * cos(M_PI / 3)) * ($midRadius < M_PI * 1.4 && $midRadius > M_PI / 3 ? -1 : 1);
     if ($ctx->ytoRelative($midY) > 100) {
         $midY = $ctx->yToAbsolute(100);
     } elseif ($ctx->ytoRelative($midY) < 0) {
         $midY = $ctx->yToAbsolute($ctx->ytoRelative(100 + $midY));
     }
     $path->append(array($midX, $midY));
     $rel = $ctx->toRelative($midX, $midY);
     // Draw the text box
     $text = new Text($rel[0] + 1.5, $rel[1], $this->caption);
     $text->setFontSize('2.5em');
     $text->setAlignment($midRadius > M_PI ? Text::ALIGN_END : Text::ALIGN_START);
     $group->appendChild($path->toSvg($ctx));
     $group->appendChild($text->toSvg($ctx));
     return $group;
 }
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)
 {
     $path = new Path($this->dataset);
     if ($this->isDiscrete) {
         $path->setDiscrete(true);
     }
     $path->setStrokeColor($this->strokeColor);
     $path->setStrokeWidth($this->strokeWidth);
     $path->setAttribute('data-icinga-graph-type', 'line');
     if ($this->fill !== 'none') {
         $firstX = $this->dataset[0][0];
         $lastX = $this->dataset[count($this->dataset) - 1][0];
         $path->prepend(array($firstX, 100))->append(array($lastX, 100));
         $path->setFill($this->fill);
     }
     $path->setAdditionalStyle('clip-path: url(#clip);');
     $path->setId($this->id);
     $group = $path->toSvg($ctx);
     foreach ($this->dataset as $x => $point) {
         if ($this->showDataPoints === true) {
             $dot = new Circle($point[0], $point[1], $this->dotWith);
             $dot->setFill($this->strokeColor);
             $group->appendChild($dot->toSvg($ctx));
         }
         // Draw invisible circle for tooltip hovering
         $invisible = new Circle($point[0], $point[1], 20);
         $invisible->setFill($this->strokeColor);
         $invisible->setAdditionalStyle('opacity: 0.0;');
         $invisible->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;
             $invisible->setAttribute('title', $this->tooltips[$x]->renderNoHtml($this->order, $data, $format));
             $invisible->setAttribute('data-title-rich', $this->tooltips[$x]->render($this->order, $data, $format));
         }
         $group->appendChild($invisible->toSvg($ctx));
     }
     return $group;
 }