From 00a2d225a2d01edae0af8625f38a71ea89c7e1ae Mon Sep 17 00:00:00 2001 From: Matthias Jentsch Date: Thu, 28 Aug 2014 16:42:31 +0200 Subject: [PATCH] Ensure that PieCharts are centered and that labels dont leave the viewBox Add scaling and transformations to move the PieChart into a valid coordinate system and reduce the offset of the labels to make more efficient use of available space. --- library/Icinga/Chart/PieChart.php | 2 +- library/Icinga/Chart/Primitive/PieSlice.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library/Icinga/Chart/PieChart.php b/library/Icinga/Chart/PieChart.php index 7e80738ac..ac3772428 100644 --- a/library/Icinga/Chart/PieChart.php +++ b/library/Icinga/Chart/PieChart.php @@ -122,7 +122,7 @@ class PieChart extends Chart */ public function toSvg(RenderContext $ctx) { - $outerBox = new Canvas('outerGraph', new LayoutBox(0, 0, 100, 100)); + $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) { diff --git a/library/Icinga/Chart/Primitive/PieSlice.php b/library/Icinga/Chart/Primitive/PieSlice.php index 631013d69..33f3cbee7 100644 --- a/library/Icinga/Chart/Primitive/PieSlice.php +++ b/library/Icinga/Chart/Primitive/PieSlice.php @@ -159,7 +159,7 @@ class PieSlice extends Animatable implements Drawable // Draw the handle $path = new Path(array($midX, $midY)); - $midX += ($addOffset + $r/1.8) * ($midRadius > M_PI ? -1 : 1); + $midX += ($addOffset + $r/3) * ($midRadius > M_PI ? -1 : 1); $path->append(array($midX, $midY))->toAbsolute(); $midX += intval($r/2 * sin(M_PI/9)) * ($midRadius > M_PI ? -1 : 1);