From a26370bb121a842ea9f485a2d9277915e6c98a0a Mon Sep 17 00:00:00 2001 From: Matthias Jentsch Date: Thu, 28 Aug 2014 18:25:19 +0200 Subject: [PATCH] Adjust PieCharts that are rendered without labels Center and resize PieCharts to use the full width and height of the available view port --- library/Icinga/Chart/Inline/PieChart.php | 2 +- library/Icinga/Chart/PieChart.php | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/library/Icinga/Chart/Inline/PieChart.php b/library/Icinga/Chart/Inline/PieChart.php index 7b2108720..f42034ebd 100644 --- a/library/Icinga/Chart/Inline/PieChart.php +++ b/library/Icinga/Chart/Inline/PieChart.php @@ -18,11 +18,11 @@ class PieChart extends Inline public function render($output = true) { $pie = new PieChartRenderer(); + $pie->alignTopLeft(); $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 { diff --git a/library/Icinga/Chart/PieChart.php b/library/Icinga/Chart/PieChart.php index ac3772428..cc51f85b3 100644 --- a/library/Icinga/Chart/PieChart.php +++ b/library/Icinga/Chart/PieChart.php @@ -122,11 +122,16 @@ class PieChart extends Chart */ public function toSvg(RenderContext $ctx) { - $outerBox = new Canvas('outerGraph', new LayoutBox(33, -5, 40, 40)); - $innerBox = new Canvas('graph', new LayoutBox(0, 0, 100, 100)); $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);