diff --git a/js/pMap.js b/js/pMap.js index 1c73ba62d..a40dee9e4 100644 --- a/js/pMap.js +++ b/js/pMap.js @@ -1,7 +1,9 @@ /* pMap - a JavaScript to add image map support to pChart graphs! Copyright (C) 2008 Jean-Damien POGOLOTTI + Copyright (C) 2010 Martynas Mickevicius Version 1.1 last updated on 08/20/08 + Version 1.2 last updated on 07/22/10 http://pchart.sourceforge.net @@ -19,88 +21,86 @@ along with this program. If not, see . */ - var pMap_IE = document.all?true:false; - var pMap_ImageMap = new Array(); - var pMap_ImageID = ""; - var pMap_MouseX = 0; - var pMap_MouseY = 0; - var pMap_CurrentKey = -1; - var pMap_URL = ""; - var pMap_Tries = 0; - var pMap_MaxTries = 5; - var pMap_HTTP_Timeout = 1000; - var pMap_MUTEX = false; - var pMap_MUTEX_Timeout = 100; +var imageMap = { + 'mouseMoved': function(event, cont) { + // get mouse coordinated relative to image + mouseX = event.pageX - cont.offsetLeft; + mouseY = event.pageY - cont.offsetTop; - if (!pMap_IE) { document.captureEvents(Event.MOUSEMOVE); } + //console.log("X: " + mouseX + ", Y: " + mouseY); - function getMousePosition(e) - { - /* Protect against event storm */ - if (pMap_MUTEX) { return(0);} - pMap_MUTEX = true; - setTimeout("pMap_MUTEX=false",pMap_MUTEX_Timeout); + //return; - /* Determine mouse position over the chart */ - if (pMap_IE) - { pMap_MouseX = event.clientX + document.body.scrollLeft; pMap_MouseY = event.clientY + document.body.scrollTop; } - else - { pMap_MouseX = e.pageX; pMap_MouseY = e.pageY; } - pMap_MouseX -= document.getElementById(pMap_ImageID).offsetLeft; - pMap_MouseY -= document.getElementById(pMap_ImageID).offsetTop; + /* 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 (key in this.imageMap) + { + values = key.split("--"); + seriesName = values[0]; + seriesValue = values[1]; - /* 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 (Key in pMap_ImageMap) - { - Values = Key.split("--"); - SeriesName = Values[0]; - SeriesValue = Values[1]; - SignSum = 0; - for (i = 0; i <= pMap_ImageMap[Key].length - 1; i++) - { - 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; } - } + signSum = 0; + for (i = 0; i <= this.imageMap[key].length - 1; i++) + { + if (i == this.imageMap[key].length - 1) + { + index1 = i; + index2 = 0; + } + else + { + index1 = i; + index2 = i+1; + } + result = this.getDeterminant( + this.imageMap[key][index1][0], + this.imageMap[key][index1][1], + this.imageMap[key][index2][0], + this.imageMap[key][index2][1], + mouseX, + mouseY + ); + if (result > 0) { signSum += 1; } else { signSum += -1; } + } + //console.log(Key+": "+SignSum); + if (Math.abs(signSum) == this.imageMap[key].length) + { + found = true; + if (this.currentKey != key) + { + overlib(seriesValue, CAPTION, seriesName, WIDTH, 80); + this.currentKey = key; + } + } + } + if (!found && this.currentKey != -1 ) + { + nd(); + this.currentKey = -1; + } + }, + + 'getDeterminant': function (X1, Y1, X2, Y2, X3, Y3) { + return (X2*Y3 - X3*Y2) - (X1*Y3 - X3*Y1) + (X1*Y2 - X2*Y1); + }, + + 'loadImageMap': function(map) { + imageMap.imageMap = JSON.parse(map); + }, + + 'init': function() { + $("img#chart").bind('mousemove',function(e) { + imageMap.mouseMoved(e, this); + }); + + this.currentKey = -1; } - if ( !Found && pMap_CurrentKey != -1 ) { nd(); pMap_CurrentKey = -1; } - } +}; - 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); - } +$(document).ready(function() { + imageMap.init() +}); diff --git a/libraries/chart/pma_pchart_chart.php b/libraries/chart/pma_pchart_chart.php index 910d8040b..dfba08169 100644 --- a/libraries/chart/pma_pchart_chart.php +++ b/libraries/chart/pma_pchart_chart.php @@ -134,10 +134,10 @@ abstract class PMA_pChart_Chart extends PMA_Chart $this->prepareChart(); $this->render(); - $returnData = ''; + $returnData = ''; $returnData .= ' ';