X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=dygraph-utils.js;h=63fc1e0a433a36d0a6845647d9282c9e76c14aee;hb=4e9b1418813cbafd5ee68a090e3e059b31ce602c;hp=0ca65855cc2790c23131b602158fad110eb56c21;hpb=55deb02f27185eb75dc110eb04a3fdbae958409b;p=dygraphs.git diff --git a/dygraph-utils.js b/dygraph-utils.js index 0ca6585..63fc1e0 100644 --- a/dygraph-utils.js +++ b/dygraph-utils.js @@ -776,6 +776,30 @@ Dygraph.createCanvas = function() { }; /** + * Returns the context's pixel ratio, which is the ratio between the device + * pixel ratio and the backing store ratio. Typically this is 1 for conventional + * displays, and > 1 for HiDPI displays (such as the Retina MBP). + * See http://www.html5rocks.com/en/tutorials/canvas/hidpi/ for more details. + * + * @param {!CanvasRenderingContext2D} context The canvas's 2d context. + * @return {number} The ratio of the device pixel ratio and the backing store + * ratio for the specified context. + */ +Dygraph.getContextPixelRatio = function(context) { + try { + var devicePixelRatio = window.devicePixelRatio || 1, + backingStoreRatio = context.webkitBackingStorePixelRatio || + context.mozBackingStorePixelRatio || + context.msBackingStorePixelRatio || + context.oBackingStorePixelRatio || + context.backingStorePixelRatio || 1; + return devicePixelRatio / backingStoreRatio; + } catch (e) { + return 1; + } +}; + +/** * Checks whether the user is on an Android browser. * Android does not fully support the tag, e.g. w/r/t/ clipping. * @return {boolean} @@ -1075,8 +1099,9 @@ Dygraph.IFrameTarp.prototype.cover = function() { var iframes = document.getElementsByTagName("iframe"); for (var i = 0; i < iframes.length; i++) { var iframe = iframes[i]; - var x = Dygraph.findPosX(iframe), - y = Dygraph.findPosY(iframe), + var pos = Dygraph.findPos(iframe), + x = pos.x, + y = pos.y, width = iframe.offsetWidth, height = iframe.offsetHeight; @@ -1202,7 +1227,7 @@ Dygraph.toRGB_ = function(colorStr) { div.style.backgroundColor = colorStr; div.style.visibility = 'hidden'; document.body.appendChild(div); - var rgbStr = window.getComputedStyle(div).backgroundColor; + var rgbStr = window.getComputedStyle(div, null).backgroundColor; document.body.removeChild(div); var bits = /^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/.exec(rgbStr); return {