aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/js/RrdGfxCanvas.js
diff options
context:
space:
mode:
authorManuel Luis SanmartĂ­n Rozada2015-04-03 19:02:59 +0200
committerPim van den Berg2015-06-22 11:01:48 +0200
commite8a4d43c2a55d0a2ebd87b8e6c83d82ac5950291 (patch)
treed397e3389986a1690a817fc008583804504c602a /js/RrdGfxCanvas.js
parentjsrrdgraph: Rewrite data a graph commands parser. (diff)
downloadapt-panopticon_cgp-e8a4d43c2a55d0a2ebd87b8e6c83d82ac5950291.zip
apt-panopticon_cgp-e8a4d43c2a55d0a2ebd87b8e6c83d82ac5950291.tar.gz
apt-panopticon_cgp-e8a4d43c2a55d0a2ebd87b8e6c83d82ac5950291.tar.bz2
apt-panopticon_cgp-e8a4d43c2a55d0a2ebd87b8e6c83d82ac5950291.tar.xz
jsrrdgraph: Add support for dashes
Diffstat (limited to 'js/RrdGfxCanvas.js')
-rw-r--r--js/RrdGfxCanvas.js21
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
33RrdGfxCanvas.prototype.size = function (width, height) 36RrdGfxCanvas.prototype.size = function (width, height)
@@ -38,7 +41,22 @@ RrdGfxCanvas.prototype.size = function (width, height)
38 41
39RrdGfxCanvas.prototype.set_dash = function (dashes, n, offset) 42RrdGfxCanvas.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
49RrdGfxCanvas.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
44RrdGfxCanvas.prototype.line = function (X0, Y0, X1, Y1, width, color) 62RrdGfxCanvas.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';