X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=dygraph-utils.js;h=63fc1e0a433a36d0a6845647d9282c9e76c14aee;hb=160183e57e3e5c39fab0a2952e56ed6cf7d3caf3;hp=36ad10e78dbfda865fae53f97623c8fa375b5720;hpb=e1242d5b540803a1848481ce75932a85693de74c;p=dygraphs.git diff --git a/dygraph-utils.js b/dygraph-utils.js index 36ad10e..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}