diff --git a/js/pMap.js b/js/pMap.js
index 2f486435f..1c73ba62d 100644
--- a/js/pMap.js
+++ b/js/pMap.js
@@ -24,7 +24,7 @@
var pMap_ImageID = "";
var pMap_MouseX = 0;
var pMap_MouseY = 0;
- var pMap_CurrentMap = -1;
+ var pMap_CurrentKey = -1;
var pMap_URL = "";
var pMap_Tries = 0;
var pMap_MaxTries = 5;
@@ -49,22 +49,58 @@
pMap_MouseX -= document.getElementById(pMap_ImageID).offsetLeft;
pMap_MouseY -= document.getElementById(pMap_ImageID).offsetTop;
- /* Check if we are flying over a map zone */
+ /* Check if we are flying over a map zone
+ * Lets use the following method to check if a given
+ * point is in any convex polygon.
+ * http://www.programmingforums.org/post168124-3.html
+ */
Found = false;
- for (Map in pMap_ImageMap)
+ for (Key in pMap_ImageMap)
{
- Values = pMap_ImageMap[Map].split(",");
- if ( pMap_MouseX>=Values[0] && pMap_MouseX<=Values[2])
+ Values = Key.split("--");
+ SeriesName = Values[0];
+ SeriesValue = Values[1];
+ SignSum = 0;
+ for (i = 0; i <= pMap_ImageMap[Key].length - 1; i++)
{
- if ( pMap_MouseY>=Values[1] && pMap_MouseY<=Values[3] )
- {
- Found = true;
- if ( pMap_CurrentMap != Map )
- { overlib(Values[5], CAPTION, Values[4], WIDTH, 80); pMap_CurrentMap = Map; }
- }
+ if (i == pMap_ImageMap[Key].length - 1)
+ {
+ index1 = i;
+ index2 = 0;
+ }
+ else
+ {
+ index1 = i;
+ index2 = i+1;
+ }
+ result = getDeterminant(
+ pMap_ImageMap[Key][index1][0],
+ pMap_ImageMap[Key][index1][1],
+ pMap_ImageMap[Key][index2][0],
+ pMap_ImageMap[Key][index2][1],
+ pMap_MouseX,
+ pMap_MouseY
+ );
+ if (result > 0) { SignSum += 1; } else { SignSum += -1; }
+ }
+ //console.log(Key+": "+SignSum);
+ if (Math.abs(SignSum) == pMap_ImageMap[Key].length)
+ {
+ Found = true;
+ if ( pMap_CurrentKey != Key )
+ { overlib(SeriesValue, CAPTION, SeriesName, WIDTH, 80); pMap_CurrentKey = Key; }
}
- if ( !Found && pMap_CurrentMap != -1 ) { nd(); pMap_CurrentMap = -1; }
}
+ if ( !Found && pMap_CurrentKey != -1 ) { nd(); pMap_CurrentKey = -1; }
}
- function LoadImageMap(ID, map) { pMap_ImageID = ID, pMap_ImageMap = map.split("-"); }
+ function getDeterminant(X1, Y1, X2, Y2, X3, Y3)
+ {
+ return (X2*Y3 - X3*Y2) - (X1*Y3 - X3*Y1) + (X1*Y2 - X2*Y1);
+ }
+
+ function LoadImageMap(ID, map)
+ {
+ pMap_ImageID = ID;
+ pMap_ImageMap = JSON.parse(map);
+ }
diff --git a/libraries/chart/pChart/pChart.class b/libraries/chart/pChart/pChart.class
index c5f739535..538617268 100644
--- a/libraries/chart/pChart/pChart.class
+++ b/libraries/chart/pChart/pChart.class
@@ -2748,6 +2748,25 @@
}
}
+ /* 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");
+
+ // 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");
+
+ // 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 */
for($Key=count($iValues)-1;$Key>=0;$Key--)
{
@@ -3371,9 +3390,17 @@
/* Add a box into the image map */
function addToImageMap($X1,$Y1,$X2,$Y2,$SerieName,$Value,$CallerFunction)
{
- if ( $this->MapFunction == NULL || $this->MapFunction == $CallerFunction )
- {
- $this->ImageMap[] = round($X1).",".round($Y1).",".round($X2).",".round($Y2).",".$SerieName.",".$Value;
+ $this->addPointToImageMap($X1,$Y1,$SerieName,$Value,$CallerFunction);
+ $this->addPointToImageMap($X2,$Y1,$SerieName,$Value,$CallerFunction);
+ $this->addPointToImageMap($X2,$Y2,$SerieName,$Value,$CallerFunction);
+ $this->addPointToImageMap($X1,$Y2,$SerieName,$Value,$CallerFunction);
+ }
+
+ function addPointToImageMap($X1,$Y1,$SerieName,$Value,$CallerFunction)
+ {
+ if ( $this->MapFunction == NULL || $this->MapFunction == $CallerFunction)
+ {
+ $this->ImageMap["$SerieName--$Value"][] = array(round($X1), round($Y1));
$this->MapFunction = $CallerFunction;
}
}
diff --git a/libraries/chart/pma_pchart_chart.php b/libraries/chart/pma_pchart_chart.php
index ebd9c562f..910d8040b 100644
--- a/libraries/chart/pma_pchart_chart.php
+++ b/libraries/chart/pma_pchart_chart.php
@@ -137,7 +137,7 @@ abstract class PMA_pChart_Chart extends PMA_Chart
$returnData = '
';
$returnData .= '
';