X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=dygraph-utils.js;h=e03aaf8fb0251947d5311d69d420cac0539d4290;hb=22bce4f209d99203fcb3c3892ddf5ddb6d359b93;hp=2d43d2dddbe11661aee52877af17f2885f630288;hpb=dedb4f5fb17ad82b542784ef04048e80bac24a02;p=dygraphs.git diff --git a/dygraph-utils.js b/dygraph-utils.js index 2d43d2d..e03aaf8 100644 --- a/dygraph-utils.js +++ b/dygraph-utils.js @@ -1,4 +1,12 @@ +// Copyright 2011 Dan Vanderkam (danvdk@gmail.com) +// All Rights Reserved. +/** + * @fileoverview This file contains utility functions used by dygraphs. These + * are typically static (i.e. not related to any particular dygraph). Examples + * include date/time formatting functions, basic algorithms (e.g. binary + * search) and generic DOM-manipulation functions. + */ Dygraph.LOG_SCALE = 10; Dygraph.LN_TEN = Math.log(Dygraph.LOG_SCALE); @@ -164,36 +172,59 @@ Dygraph.hsvToRGB = function (hue, saturation, value) { // The following functions are from quirksmode.org with a modification for Safari from // http://blog.firetree.net/2005/07/04/javascript-find-position/ // http://www.quirksmode.org/js/findpos.html +// ... and modifications to support scrolling divs. -/** @private */ +/** + * Find the x-coordinate of the supplied object relative to the left side + * of the page. + * @private + */ Dygraph.findPosX = function(obj) { var curleft = 0; - if(obj.offsetParent) - while(1) - { - curleft += obj.offsetLeft; - if(!obj.offsetParent) + if(obj.offsetParent) { + var copyObj = obj; + while(1) { + curleft += copyObj.offsetLeft; + if(!copyObj.offsetParent) { break; - obj = obj.offsetParent; + } + copyObj = copyObj.offsetParent; } - else if(obj.x) + } else if(obj.x) { curleft += obj.x; + } + // This handles the case where the object is inside a scrolled div. + while(obj && obj != document.body) { + curleft -= obj.scrollLeft; + obj = obj.parentNode; + } return curleft; }; -/** @private */ +/** + * Find the y-coordinate of the supplied object relative to the top of the + * page. + * @private + */ Dygraph.findPosY = function(obj) { var curtop = 0; - if(obj.offsetParent) - while(1) - { - curtop += obj.offsetTop; - if(!obj.offsetParent) + if(obj.offsetParent) { + var copyObj = obj; + while(1) { + curtop += copyObj.offsetTop; + if(!copyObj.offsetParent) { break; - obj = obj.offsetParent; + } + copyObj = copyObj.offsetParent; } - else if(obj.y) + } else if(obj.y) { curtop += obj.y; + } + // This handles the case where the object is inside a scrolled div. + while(obj && obj != document.body) { + curtop -= obj.scrollTop; + obj = obj.parentNode; + } return curtop; };