Beispiel #1
0
 protected function getChart()
 {
     $pie = new PieChartRenderer();
     $pie->alignTopLeft();
     $pie->disableLegend();
     $pie->drawPie(array('data' => $this->data, 'colors' => $this->colors, 'labels' => $this->labels));
     return $pie;
 }
Beispiel #2
0
 public function testPieChartCreation()
 {
     $chart = new PieChart();
     $chart->drawPie(array('label' => 'My bar', 'color' => 'black', 'green', 'red', 'data' => array(50, 50, 50)));
     $doc = new DOMDocument();
     $doc->preserveWhiteSpace = false;
     $doc->loadXML($chart->render());
     $xpath = new DOMXPath($doc);
     $xpath->registerNamespace('x', 'http://www.w3.org/2000/svg');
     $path = $xpath->query('//x:path[@data-icinga-graph-type="pieslice"]');
     $this->assertEquals(3, $path->length, 'Assert the correct number of datapoints being drawn as SVG bars');
 }
Beispiel #3
0
 public function render($output = true)
 {
     $pie = new PieChartRenderer();
     $pie->disableLegend();
     $pie->drawPie(array('data' => $this->data, 'colors' => $this->colors, 'labels' => $this->labels));
     $pie->setWidth($this->width)->setHeight($this->height);
     if ($output) {
         echo $pie->render();
     } else {
         return $pie->render();
     }
 }
Beispiel #4
0
 /**
  * Renders this widget via the given view and returns the
  * HTML as a string
  *
  * @return string
  */
 public function render()
 {
     if ($this->view()->layout()->getLayout() === 'pdf') {
         $pie = new PieChart();
         $pie->alignTopLeft();
         $pie->disableLegend();
         $pie->drawPie(array('data' => $this->data, 'colors' => $this->colors));
         try {
             $png = $pie->toPng($this->size, $this->size);
             return '<img class="inlinepie" src="data:image/png;base64,' . base64_encode($png) . '" />';
         } catch (IcingaException $_) {
             return '';
         }
     }
     $template = $this->template;
     // TODO: Check whether we are XHR and don't send
     $template = str_replace('{noscript}', $this->noscript, $template);
     $template = str_replace('{url}', $this->url, $template);
     $template = str_replace('{class}', $this->class, $template);
     // style
     $template = str_replace('{size}', isset($this->size) ? $this->size : 16, $template);
     $template = str_replace('{title}', $this->title, $template);
     $template = str_replace('{colors}', implode(',', $this->colors), $template);
     // Locale-ignorant string cast. Please. Do. NOT. Remove. This. Again.
     // Problem is that implode respects locales when casting floats. This means
     // that implode(',', array(1.1, 1.2)) would read '1,1,1,2'.
     $data = array();
     foreach ($this->data as $dat) {
         $data[] = sprintf('%F', $dat);
     }
     $template = str_replace('{data}', htmlspecialchars(implode(',', $data)), $template);
     return $template;
 }