X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=dashed-canvas.js;h=cec77298a8441fe6c69daf729e092efd7be32abb;hb=ad617f174a6b4ec2aea3d06553534dcaf278a2bb;hp=af2470e4f56907345ea7acf2cd016d25768b5a5a;hpb=7e1f9ca38a4d105ead9e965069344ca935a8499a;p=dygraphs.git diff --git a/dashed-canvas.js b/dashed-canvas.js index af2470e..cec7729 100644 --- a/dashed-canvas.js +++ b/dashed-canvas.js @@ -40,12 +40,14 @@ * property and "uninstallPattern" method to this particular canvas context. * You must call uninstallPattern() before calling installPattern() again. * - * @param {pattern | Array} A description of the stroke pattern. Even + * @param {Array.} pattern A description of the stroke pattern. Even * indices indicate a draw and odd indices indicate a gap (in pixels). The * array should have a even length as any odd lengthed array could be expressed * as a smaller even length array. */ CanvasRenderingContext2D.prototype.installPattern = function(pattern) { + "use strict"; + if (typeof(this.isPatternInstalled) !== 'undefined') { throw "Must un-install old line pattern before installing a new one."; } @@ -63,6 +65,7 @@ CanvasRenderingContext2D.prototype.installPattern = function(pattern) { var realMoveTo = this.moveTo; var realStroke = this.stroke; + /** @type {function()|undefined} */ this.uninstallPattern = function() { this.beginPath = realBeginPath; this.lineTo = realLineTo; @@ -115,10 +118,10 @@ CanvasRenderingContext2D.prototype.installPattern = function(pattern) { // Set last pattern index we used for this pattern. var patternIndex = dashedLineToHistory[0]; - x = 0; + var x = 0; while (len > x) { // Get the length of the pattern segment we are dealing with. - segment = pattern[patternIndex]; + var segment = pattern[patternIndex]; // If our last draw didn't complete the pattern segment all the way // we will try to finish it. Otherwise we will try to do the whole // segment. @@ -161,3 +164,13 @@ CanvasRenderingContext2D.prototype.installPattern = function(pattern) { segments = []; }; }; + +/** + * Removes the previously-installed pattern. + * You must call installPattern() before calling this. You can install at most + * one pattern at a time--there is no pattern stack. + */ +CanvasRenderingContext2D.prototype.uninstallPattern = function() { + // This will be replaced by a non-error version when a pattern is installed. + throw "Must install a line pattern before uninstalling it."; +}