From: <bra...@us...> - 2010-04-24 00:42:33
|
Revision: 3062 http://archive-access.svn.sourceforge.net/archive-access/?rev=3062&view=rev Author: bradtofel Date: 2010-04-24 00:42:27 +0000 (Sat, 24 Apr 2010) Log Message: ----------- INITIAL REV: Code to translate a mouse horizontal location within an image, into a date, given a "start date" at the left edge of the image, and an "end date" at the right edge. Added Paths: ----------- trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/js/graph-calc.js Added: trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/js/graph-calc.js =================================================================== --- trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/js/graph-calc.js (rev 0) +++ trunk/archive-access/projects/wayback/wayback-webapp/src/main/webapp/js/graph-calc.js 2010-04-24 00:42:27 UTC (rev 3062) @@ -0,0 +1,50 @@ +function getEventX(event) { + var posx = 0; + if (event.pageX || event.pageY) { + posx = event.pageX; + } + else if (event.clientX || event.clientY) { + posx = event.clientX + document.body.scrollLeft + + document.documentElement.scrollLeft; + } + return posx; +} +function getElementX(obj) { + var x = 0; + if (obj.offsetParent) { + do { + x += obj.offsetLeft; + } while (obj = obj.offsetParent); + } + return x; +} +function zeroPad(str,len) { + var i; + var pad = ""; + var s = str.toString(); + for(i=s.length; i < len; i++) { + pad = "0".toString() + pad.toString(); + } + return pad.toString() + s.toString(); +} + +function dateToTimestamp(date) { + return date.getFullYear() + + zeroPad(date.getMonth()+1,2) + + zeroPad(date.getDay()+1,2) + + zeroPad(date.getHours(),2) + + zeroPad(date.getMinutes(),2) + + zeroPad(date.getSeconds(),2); +} + +function calcTimestamp(event,element,firstMS,lastMS) { + var eventX = getEventX(event); + var elementX = getElementX(element); + var elementWidth = element.width; + var msWidth = lastMS - firstMS; + var x = eventX - elementX; + var pct = x / elementWidth; + var pctDate = pct * msWidth; + var date = pctDate + firstMS; + return dateToTimestamp(new Date(date)); +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |