diff options
Diffstat (limited to 'js/RrdGfxCanvas.js')
| -rw-r--r-- | js/RrdGfxCanvas.js | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/js/RrdGfxCanvas.js b/js/RrdGfxCanvas.js index 324b655..6ba71bb 100644 --- a/js/RrdGfxCanvas.js +++ b/js/RrdGfxCanvas.js | |||
| @@ -28,6 +28,9 @@ var RrdGfxCanvas = function(canvasId) | |||
| 28 | { | 28 | { |
| 29 | this.canvas = document.getElementById(canvasId); | 29 | this.canvas = document.getElementById(canvasId); |
| 30 | this.ctx = this.canvas.getContext('2d'); | 30 | this.ctx = this.canvas.getContext('2d'); |
| 31 | this.dash = false; | ||
| 32 | this.dash_offset = null; | ||
| 33 | this.dash_array = null; | ||
| 31 | }; | 34 | }; |
| 32 | 35 | ||
| 33 | RrdGfxCanvas.prototype.size = function (width, height) | 36 | RrdGfxCanvas.prototype.size = function (width, height) |
| @@ -38,7 +41,22 @@ RrdGfxCanvas.prototype.size = function (width, height) | |||
| 38 | 41 | ||
| 39 | RrdGfxCanvas.prototype.set_dash = function (dashes, n, offset) | 42 | RrdGfxCanvas.prototype.set_dash = function (dashes, n, offset) |
| 40 | { | 43 | { |
| 44 | this.dash = true; | ||
| 45 | this.dash_array = dashes; | ||
| 46 | this.dash_offset = offset; | ||
| 47 | }; | ||
| 41 | 48 | ||
| 49 | RrdGfxCanvas.prototype._set_dash = function () | ||
| 50 | { | ||
| 51 | if (this.dash_array != undefined && this.dash_array.length > 0) { | ||
| 52 | this.ctx.setLineDash(this.dash_array); | ||
| 53 | if (this.dash_offset > 0) { | ||
| 54 | this.ctx.lineDashOffset = this.dash_offset; | ||
| 55 | } | ||
| 56 | } | ||
| 57 | this.dash = false; | ||
| 58 | this.dash_array = null; | ||
| 59 | this.dash_offset = 0; | ||
| 42 | }; | 60 | }; |
| 43 | 61 | ||
| 44 | RrdGfxCanvas.prototype.line = function (X0, Y0, X1, Y1, width, color) | 62 | RrdGfxCanvas.prototype.line = function (X0, Y0, X1, Y1, width, color) |
| @@ -58,6 +76,7 @@ RrdGfxCanvas.prototype.line = function (X0, Y0, X1, Y1, width, color) | |||
| 58 | this.ctx.save(); | 76 | this.ctx.save(); |
| 59 | this.ctx.lineWidth = width; | 77 | this.ctx.lineWidth = width; |
| 60 | this.ctx.strokeStyle = color; | 78 | this.ctx.strokeStyle = color; |
| 79 | if (this.dash) this._set_dash(); | ||
| 61 | this.ctx.beginPath(); | 80 | this.ctx.beginPath(); |
| 62 | this.ctx.moveTo(X0, Y0); | 81 | this.ctx.moveTo(X0, Y0); |
| 63 | this.ctx.lineTo(X1, Y1); | 82 | this.ctx.lineTo(X1, Y1); |
| @@ -136,6 +155,7 @@ RrdGfxCanvas.prototype.rectangle = function (X0, Y0, X1, Y1, width, style) | |||
| 136 | 155 | ||
| 137 | this.ctx.save(); | 156 | this.ctx.save(); |
| 138 | this.ctx.beginPath(); | 157 | this.ctx.beginPath(); |
| 158 | if (this.dash) this._set_dash(); | ||
| 139 | this.ctx.lineWidth = width; | 159 | this.ctx.lineWidth = width; |
| 140 | this.ctx.moveTo(X0, Y0); | 160 | this.ctx.moveTo(X0, Y0); |
| 141 | this.ctx.lineTo(X1, Y0); | 161 | this.ctx.lineTo(X1, Y0); |
| @@ -179,6 +199,7 @@ RrdGfxCanvas.prototype.stroke_begin = function (width, style) | |||
| 179 | { | 199 | { |
| 180 | this.ctx.save(); | 200 | this.ctx.save(); |
| 181 | this.ctx.beginPath(); | 201 | this.ctx.beginPath(); |
| 202 | if (this.dash) this._set_dash(); | ||
| 182 | this.ctx.lineWidth = width; | 203 | this.ctx.lineWidth = width; |
| 183 | this.ctx.strokeStyle = style; | 204 | this.ctx.strokeStyle = style; |
| 184 | this.ctx.lineCap = 'round'; | 205 | this.ctx.lineCap = 'round'; |
