aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/js/RrdGfxSvg.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/RrdGfxSvg.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 '')
-rw-r--r--js/RrdGfxSvg.js25
1 files changed, 25 insertions, 0 deletions
diff --git a/js/RrdGfxSvg.js b/js/RrdGfxSvg.js
index ffc0071..927cb14 100644
--- a/js/RrdGfxSvg.js
+++ b/js/RrdGfxSvg.js
@@ -31,6 +31,9 @@ var RrdGfxSvg = function(svgId) {
31 this.path = null; 31 this.path = null;
32 this.path_color = null; 32 this.path_color = null;
33 this.path_width = null; 33 this.path_width = null;
34 this.dash = false;
35 this.dash_offset = null;
36 this.dash_array = null;
34}; 37};
35 38
36RrdGfxSvg.prototype.size = function (width, height) 39RrdGfxSvg.prototype.size = function (width, height)
@@ -45,8 +48,24 @@ RrdGfxSvg.prototype.size = function (width, height)
45 48
46RrdGfxSvg.prototype.set_dash = function (dashes, n, offset) 49RrdGfxSvg.prototype.set_dash = function (dashes, n, offset)
47{ 50{
51 this.dash = true;
52 this.dash_array = dashes;
53 this.dash_offset = offset;
48}; 54};
49 55
56RrdGfxSvg.prototype._set_dash = function (shape)
57{
58 if (this.dash_array != undefined && this.dash_array.length > 0) {
59 shape.setAttributeNS(null, "stroke-dasharray", this.dash_array.join(','));
60 if (this.dash_offset > 0) {
61 shape.setAttributeNS(null, "stroke-dashoffset", this.dash_offset);
62 }
63 }
64 this.dash = false;
65 this.dash_array = null;
66 this.dash_offset = 0;
67}
68
50RrdGfxSvg.prototype.line = function (X0, Y0, X1, Y1, width, color) 69RrdGfxSvg.prototype.line = function (X0, Y0, X1, Y1, width, color)
51{ 70{
52 var shape = document.createElementNS(this.svgns, "line"); 71 var shape = document.createElementNS(this.svgns, "line");
@@ -62,6 +81,8 @@ RrdGfxSvg.prototype.line = function (X0, Y0, X1, Y1, width, color)
62 shape.setAttributeNS(null, "y2", Y1); 81 shape.setAttributeNS(null, "y2", Y1);
63 shape.setAttributeNS(null, "stroke-width", width); 82 shape.setAttributeNS(null, "stroke-width", width);
64 shape.setAttributeNS(null, "stroke", color); 83 shape.setAttributeNS(null, "stroke", color);
84 if (this.dash)
85 this._set_dash(shape);
65 86
66 this.svg.appendChild(shape); 87 this.svg.appendChild(shape);
67}; 88};
@@ -100,6 +121,8 @@ RrdGfxSvg.prototype.rectangle = function (X0, Y0, X1, Y1, width, style)
100 shape.setAttributeNS(null, "stroke-width", width); 121 shape.setAttributeNS(null, "stroke-width", width);
101 shape.setAttributeNS(null, "stroke", style); 122 shape.setAttributeNS(null, "stroke", style);
102 shape.setAttributeNS(null, "fill", "none"); 123 shape.setAttributeNS(null, "fill", "none");
124 if (this.dash)
125 this._set_dash(shape);
103 126
104 this.svg.appendChild(shape); 127 this.svg.appendChild(shape);
105}; 128};
@@ -157,6 +180,8 @@ RrdGfxSvg.prototype.stroke_end = function ()
157 shape.setAttributeNS(null, "stroke-width", this.path_width); 180 shape.setAttributeNS(null, "stroke-width", this.path_width);
158 shape.setAttributeNS(null, "stroke-linecap", 'round'); 181 shape.setAttributeNS(null, "stroke-linecap", 'round');
159 shape.setAttributeNS(null, "stroke-linejoin", 'round'); 182 shape.setAttributeNS(null, "stroke-linejoin", 'round');
183 if (this.dash)
184 this._set_dash(shape);
160 185
161 this.svg.appendChild(shape); 186 this.svg.appendChild(shape);
162}; 187};