From 557eb2096bedb5f46f49d10b8e3349f7273d4fe3 Mon Sep 17 00:00:00 2001 From: Martynas Mickevicius Date: Wed, 21 Jul 2010 19:32:17 +0300 Subject: [PATCH] added tooltips for radar charts. --- libraries/chart/pChart/pChart.class | 47 ++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/libraries/chart/pChart/pChart.class b/libraries/chart/pChart/pChart.class index 538617268..6298c595c 100644 --- a/libraries/chart/pChart/pChart.class +++ b/libraries/chart/pChart/pChart.class @@ -2198,6 +2198,28 @@ { $XOffset = -$Width; } imagettftext($this->Picture,$this->FontSize,0,$X+$XOffset,$Y+$YOffset,$C_TextColor,$this->FontName,$Label); + + if ( $this->BuildMap ) + { + $vecX = $X - $XCenter; + $vecY = $Y - $YCenter; + + // get a perpendicular vector + $vecXtemp = $vecX; + $vecX = -$vecY; + $vecY = $vecXtemp; + + // normalization + $vecLength = sqrt($vecX * $vecX + $vecY * $vecY); + $vecX = $vecX / $vecLength; + $vecY = $vecY / $vecLength; + + $offset = 10; + $this->addPointToImageMap($X+$vecX*-$offset,$Y+$vecY*-$offset,$Label,'Value','Radar'); + $this->addPointToImageMap($X+$vecX*+$offset,$Y+$vecY*+$offset,$Label,'Value','Radar'); + $this->addPointToImageMap($XCenter+$vecX*+$offset,$YCenter+$vecY*+$offset,$Label,'Value','Radar'); + $this->addPointToImageMap($XCenter+$vecX*-$offset,$YCenter+$vecY*-$offset,$Label,'Value','Radar'); + } } } @@ -2748,23 +2770,26 @@ } } + if ( $this->BuildMap ) + { /* Add points to Image Map. * The center point abd the first, middle and last of the arc is taken. */ - foreach ($TopPlots as $key => $PointArr) - { - // last point of the arc - $this->addPointToImageMap($PointArr[count($PointArr)-4],$PointArr[count($PointArr)-3],$Data[$key][$DataDescription['Values'][1]],$Data[$key][$DataDescription['Values'][0]],"Pie"); + foreach ($TopPlots as $key => $PointArr) + { + // last point of the arc + $this->addPointToImageMap($PointArr[count($PointArr)-4],$PointArr[count($PointArr)-3],$Data[$key][$DataDescription['Values'][1]],$Data[$key][$DataDescription['Values'][0]],"Pie"); - // the point at the middle - $this->addPointToImageMap($PointArr[0],$PointArr[1],$Data[$key][$DataDescription['Values'][1]],$Data[$key][$DataDescription['Values'][0]],"Pie"); + // the point at the middle + $this->addPointToImageMap($PointArr[0],$PointArr[1],$Data[$key][$DataDescription['Values'][1]],$Data[$key][$DataDescription['Values'][0]],"Pie"); - // firs point in the arc - $this->addPointToImageMap($PointArr[2],$PointArr[3],$Data[$key][$DataDescription['Values'][1]],$Data[$key][$DataDescription['Values'][0]],"Pie"); + // firs point in the arc + $this->addPointToImageMap($PointArr[2],$PointArr[3],$Data[$key][$DataDescription['Values'][1]],$Data[$key][$DataDescription['Values'][0]],"Pie"); - // point in the middle of the arc - $middle = count($PointArr)/2; - $this->addPointToImageMap($PointArr[$middle + ($middle % 2)],$PointArr[$middle + ($middle % 2)+1],$Data[$key][$DataDescription['Values'][1]],$Data[$key][$DataDescription['Values'][0]],"Pie"); + // point in the middle of the arc + $middle = count($PointArr)/2; + $this->addPointToImageMap($PointArr[$middle + ($middle % 2)],$PointArr[$middle + ($middle % 2)+1],$Data[$key][$DataDescription['Values'][1]],$Data[$key][$DataDescription['Values'][0]],"Pie"); + } } /* Draw Top polygons */