diff options
author | Manuel Luis SanmartĂn Rozada | 2015-04-03 19:02:59 +0200 |
---|---|---|
committer | Pim van den Berg | 2015-06-22 11:01:48 +0200 |
commit | e8a4d43c2a55d0a2ebd87b8e6c83d82ac5950291 (patch) | |
tree | d397e3389986a1690a817fc008583804504c602a /js/RrdGfxPdf.js | |
parent | jsrrdgraph: Rewrite data a graph commands parser. (diff) | |
download | apt-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 '')
-rw-r--r-- | js/RrdGfxPdf.js | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/js/RrdGfxPdf.js b/js/RrdGfxPdf.js index cbc552f..7cde098 100644 --- a/js/RrdGfxPdf.js +++ b/js/RrdGfxPdf.js | |||
@@ -81,7 +81,7 @@ var RrdGfxPdf = function (orientation, unit, size) | |||
81 | this.CoreFonts = ['courier', 'helvetica', 'times', 'symbol', 'zapfdingbats']; | 81 | this.CoreFonts = ['courier', 'helvetica', 'times', 'symbol', 'zapfdingbats']; |
82 | // Scale factor (number of points in user unit) | 82 | // Scale factor (number of points in user unit) |
83 | if(unit === 'pt') | 83 | if(unit === 'pt') |
84 | this.k = 1; | 84 | this.k = 1; |
85 | else if(unit === 'mm') | 85 | else if(unit === 'mm') |
86 | this.k = 72/25.4; | 86 | this.k = 72/25.4; |
87 | else if(unit === 'cm') | 87 | else if(unit === 'cm') |
@@ -129,6 +129,10 @@ var RrdGfxPdf = function (orientation, unit, size) | |||
129 | this.SetDisplayMode('default'); | 129 | this.SetDisplayMode('default'); |
130 | // Set default PDF version number | 130 | // Set default PDF version number |
131 | this.PDFVersion = '1.3'; | 131 | this.PDFVersion = '1.3'; |
132 | |||
133 | this.dash = false; | ||
134 | this.dash_array = null; | ||
135 | this.dash_offset = null; | ||
132 | }; | 136 | }; |
133 | 137 | ||
134 | RrdGfxPdf.CORE_FONTS= { | 138 | RrdGfxPdf.CORE_FONTS= { |
@@ -182,6 +186,31 @@ RrdGfxPdf.prototype.size = function (width, height) | |||
182 | 186 | ||
183 | RrdGfxPdf.prototype.set_dash = function (dashes, n, offset) | 187 | RrdGfxPdf.prototype.set_dash = function (dashes, n, offset) |
184 | { | 188 | { |
189 | this.dash = true; | ||
190 | this.dash_array = dashes; | ||
191 | this.dash_offset = offset; | ||
192 | }; | ||
193 | |||
194 | RrdGfxPdf.prototype._set_dash = function () | ||
195 | { | ||
196 | this.dash = true; | ||
197 | |||
198 | if (this.dash_array != undefined && this.dash_array.length > 0) { | ||
199 | for (var n=0; n < this.dash_array.length; n++) { | ||
200 | this.dash_array[n] = this.dash_array[n] * this.k; | ||
201 | } | ||
202 | this.dash_array = this.dash_array.join(' '); | ||
203 | |||
204 | if (this.dash_offset == 0) { | ||
205 | this._out('['+this.dash_array+'] 0 d'); | ||
206 | } else { | ||
207 | this.dash_offset = this.dash_offset * this.k; | ||
208 | this._out('['+this.dash_array+'] '+this.dash_offset+' d'); | ||
209 | } | ||
210 | } | ||
211 | this.dash = false; | ||
212 | this.dash_array = null; | ||
213 | this.dash_offset = 0; | ||
185 | }; | 214 | }; |
186 | 215 | ||
187 | RrdGfxPdf.prototype.line = function (X0, Y0, X1, Y1, width, color) | 216 | RrdGfxPdf.prototype.line = function (X0, Y0, X1, Y1, width, color) |
@@ -190,6 +219,8 @@ RrdGfxPdf.prototype.line = function (X0, Y0, X1, Y1, width, color) | |||
190 | this._setLineWidth(width); | 219 | this._setLineWidth(width); |
191 | var rgba = this.parse_color(color); | 220 | var rgba = this.parse_color(color); |
192 | this._setDrawColor(rgba[0], rgba[1], rgba[2]); | 221 | this._setDrawColor(rgba[0], rgba[1], rgba[2]); |
222 | if (this.dash) | ||
223 | this._set_dash(); | ||
193 | this._moveTo(X0, Y0); | 224 | this._moveTo(X0, Y0); |
194 | this._lineTo(X1, Y1); | 225 | this._lineTo(X1, Y1); |
195 | this._stroke(); | 226 | this._stroke(); |
@@ -215,6 +246,8 @@ RrdGfxPdf.prototype.rectangle = function (X0, Y0, X1, Y1, width, style) | |||
215 | this._setLineWidth(width); | 246 | this._setLineWidth(width); |
216 | var rgba = this.parse_color(style); | 247 | var rgba = this.parse_color(style); |
217 | this._setDrawColor(rgba[0], rgba[1], rgba[2]); | 248 | this._setDrawColor(rgba[0], rgba[1], rgba[2]); |
249 | if (this.dash) | ||
250 | this._set_dash(); | ||
218 | this._moveTo(X0, Y0); | 251 | this._moveTo(X0, Y0); |
219 | this._lineTo(X1, Y0); | 252 | this._lineTo(X1, Y0); |
220 | this._lineTo(X1, Y1); | 253 | this._lineTo(X1, Y1); |
@@ -250,6 +283,8 @@ RrdGfxPdf.prototype.stroke_begin = function (width, style) | |||
250 | this._setLineWidth(width); | 283 | this._setLineWidth(width); |
251 | var rgba = this.parse_color(style); | 284 | var rgba = this.parse_color(style); |
252 | this._setDrawColor(rgba[0], rgba[1], rgba[2]); | 285 | this._setDrawColor(rgba[0], rgba[1], rgba[2]); |
286 | if (this.dash) | ||
287 | this._set_dash(); | ||
253 | this._out('0 J'); // line cap | 288 | this._out('0 J'); // line cap |
254 | this._out('0 j'); // line join | 289 | this._out('0 j'); // line join |
255 | }; | 290 | }; |