diff options
author | Peter Wu | 2014-07-25 23:28:21 +0200 |
---|---|---|
committer | Pim van den Berg | 2014-08-02 12:29:32 +0200 |
commit | b6be82b8edefa452e72ed53391971e53d9dccf83 (patch) | |
tree | 01a33ac72f6ef7e6e5c607238bc5e4dd3a8751fe /js/RrdGraph.js | |
parent | support php versions without json support and show a warning message (diff) | |
download | apt-panopticon_cgp-b6be82b8edefa452e72ed53391971e53d9dccf83.zip apt-panopticon_cgp-b6be82b8edefa452e72ed53391971e53d9dccf83.tar.gz apt-panopticon_cgp-b6be82b8edefa452e72ed53391971e53d9dccf83.tar.bz2 apt-panopticon_cgp-b6be82b8edefa452e72ed53391971e53d9dccf83.tar.xz |
jsrrdgraph: Fixed jshint warnings/errors
Many fall in the category missing semicolon, but there are legitimate
bugs (like throwing an error with an undefined variable, using
isInfinite instead of !isFinite or fabs instead of Math.abs).
At some places, I moved the variable declarations to avoid duplicate
definition warnings.
Redundant breaks have been removed (after return / throw).
Global variables were implicitly defined in RrdDataFile (which caught my
attention) and Base64, these have been made local.
Also fixed some whitespace errors. Yay, the consistency. Not all (style)
issues are fixed.
Diffstat (limited to 'js/RrdGraph.js')
-rw-r--r-- | js/RrdGraph.js | 65 |
1 files changed, 31 insertions, 34 deletions
diff --git a/js/RrdGraph.js b/js/RrdGraph.js index 55a131d..7171a9c 100644 --- a/js/RrdGraph.js +++ b/js/RrdGraph.js | |||
@@ -88,7 +88,7 @@ var RrdGraphDesc = function (graph) | |||
88 | 88 | ||
89 | /** ** **/ | 89 | /** ** **/ |
90 | var args = []; // FIXME other way ¿? | 90 | var args = []; // FIXME other way ¿? |
91 | var type = arguments[1] | 91 | var type = arguments[1]; |
92 | args[0] = arguments[0]; | 92 | args[0] = arguments[0]; |
93 | for(var i = 2; i < arguments.length; i++) args[i-1] = arguments[i]; | 93 | for(var i = 2; i < arguments.length; i++) args[i-1] = arguments[i]; |
94 | 94 | ||
@@ -707,7 +707,7 @@ var RrdGraph = function (gfx, data) | |||
707 | { | 707 | { |
708 | this.gfx = gfx; /* graphics object */ | 708 | this.gfx = gfx; /* graphics object */ |
709 | this.data = data; /* fetch data object */ | 709 | this.data = data; /* fetch data object */ |
710 | this.data_need_fetch = [] /* List of data that need to be fetched */ | 710 | this.data_need_fetch = []; /* List of data that need to be fetched */ |
711 | 711 | ||
712 | this.minval = Number.NaN; /* extreme values in the data */ | 712 | this.minval = Number.NaN; /* extreme values in the data */ |
713 | this.maxval = Number.NaN; | 713 | this.maxval = Number.NaN; |
@@ -1197,13 +1197,13 @@ RrdGraph.prototype.print_calc = function() | |||
1197 | case RrdGraphDesc.GF_HRULE: | 1197 | case RrdGraphDesc.GF_HRULE: |
1198 | if (isNaN(this.gdes[i].yrule)) { /* we must set this here or the legend printer can not decide to print the legend */ | 1198 | if (isNaN(this.gdes[i].yrule)) { /* we must set this here or the legend printer can not decide to print the legend */ |
1199 | this.gdes[i].yrule = this.gdes[vidx].vf.val; | 1199 | this.gdes[i].yrule = this.gdes[vidx].vf.val; |
1200 | }; | 1200 | } |
1201 | graphelement = 1; | 1201 | graphelement = 1; |
1202 | break; | 1202 | break; |
1203 | case RrdGraphDesc.GF_VRULE: | 1203 | case RrdGraphDesc.GF_VRULE: |
1204 | if (this.gdes[i].xrule === 0) { /* again ... the legend printer needs it */ | 1204 | if (this.gdes[i].xrule === 0) { /* again ... the legend printer needs it */ |
1205 | this.gdes[i].xrule = this.gdes[vidx].vf.when; | 1205 | this.gdes[i].xrule = this.gdes[vidx].vf.when; |
1206 | }; | 1206 | } |
1207 | graphelement = 1; | 1207 | graphelement = 1; |
1208 | break; | 1208 | break; |
1209 | case RrdGraphDesc.GF_COMMENT: | 1209 | case RrdGraphDesc.GF_COMMENT: |
@@ -1216,7 +1216,6 @@ RrdGraph.prototype.print_calc = function() | |||
1216 | break; | 1216 | break; |
1217 | case RrdGraphDesc.GF_STACK: | 1217 | case RrdGraphDesc.GF_STACK: |
1218 | throw new RrdGraphError("STACK should already be turned into LINE or AREA here"); | 1218 | throw new RrdGraphError("STACK should already be turned into LINE or AREA here"); |
1219 | break; | ||
1220 | } | 1219 | } |
1221 | } | 1220 | } |
1222 | return graphelement; | 1221 | return graphelement; |
@@ -1287,7 +1286,7 @@ RrdGraph.prototype.reduce_data = function(gdes, cur_step) | |||
1287 | newval = gdes.data[srcptr + i*gdes.ds_cnt + col]; | 1286 | newval = gdes.data[srcptr + i*gdes.ds_cnt + col]; |
1288 | break; | 1287 | break; |
1289 | } | 1288 | } |
1290 | } | 1289 | } |
1291 | } | 1290 | } |
1292 | 1291 | ||
1293 | if (validval === 0) { | 1292 | if (validval === 0) { |
@@ -1316,8 +1315,8 @@ RrdGraph.prototype.reduce_data = function(gdes, cur_step) | |||
1316 | row_cnt -= reduce_factor; | 1315 | row_cnt -= reduce_factor; |
1317 | } | 1316 | } |
1318 | if (end_offset) { | 1317 | if (end_offset) { |
1319 | for (col = 0; col < gdes.ds_cnt; col++) | 1318 | for (col = 0; col < gdes.ds_cnt; col++) |
1320 | gdes.data[dstptr++] = Number.NaN; | 1319 | gdes.data[dstptr++] = Number.NaN; |
1321 | } | 1320 | } |
1322 | }; | 1321 | }; |
1323 | 1322 | ||
@@ -1396,7 +1395,7 @@ RrdGraph.prototype.data_fetch_async = function () | |||
1396 | } | 1395 | } |
1397 | } | 1396 | } |
1398 | this.data_need_fetch.push(0); | 1397 | this.data_need_fetch.push(0); |
1399 | } | 1398 | } |
1400 | 1399 | ||
1401 | for (var i = 0, gdes_c = this.gdes.length; i < gdes_c; i++) { | 1400 | for (var i = 0, gdes_c = this.gdes.length; i < gdes_c; i++) { |
1402 | if (this.data_need_fetch[i] == 0) { | 1401 | if (this.data_need_fetch[i] == 0) { |
@@ -1619,7 +1618,6 @@ RrdGraph.prototype.data_proc = function() | |||
1619 | break; | 1618 | break; |
1620 | case RrdGraphDesc.GF_STACK: | 1619 | case RrdGraphDesc.GF_STACK: |
1621 | throw new RrdGraphError("STACK should already be turned into LINE or AREA here"); | 1620 | throw new RrdGraphError("STACK should already be turned into LINE or AREA here"); |
1622 | break; | ||
1623 | default: | 1621 | default: |
1624 | break; | 1622 | break; |
1625 | } | 1623 | } |
@@ -1699,7 +1697,7 @@ RrdGraph.prototype.leg_place = function (calc_width) | |||
1699 | } | 1697 | } |
1700 | 1698 | ||
1701 | if (this.gdes[i].legend != null) { | 1699 | if (this.gdes[i].legend != null) { |
1702 | this.gdes[i].legend = this.gdes[i].legend.replace(/\\t/gi, "\t") /* turn \\t into tab */ | 1700 | this.gdes[i].legend = this.gdes[i].legend.replace(/\\t/gi, "\t"); /* turn \\t into tab */ |
1703 | leg_cc = this.gdes[i].legend.length; | 1701 | leg_cc = this.gdes[i].legend.length; |
1704 | } else { | 1702 | } else { |
1705 | leg_cc = 0; | 1703 | leg_cc = 0; |
@@ -1863,7 +1861,7 @@ RrdGraph.prototype.horizontal_log_grid = function () | |||
1863 | [ 1.0, 2.0, 4.0, 6.0, 8.0, 10., 0.0, 0.0, 0.0, 0.0 ], | 1861 | [ 1.0, 2.0, 4.0, 6.0, 8.0, 10., 0.0, 0.0, 0.0, 0.0 ], |
1864 | [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10. ], | 1862 | [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10. ], |
1865 | [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] /* last line */ | 1863 | [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] /* last line */ |
1866 | ]; | 1864 | ]; |
1867 | var i, j, val_exp, min_exp; | 1865 | var i, j, val_exp, min_exp; |
1868 | var nex; /* number of decades in data */ | 1866 | var nex; /* number of decades in data */ |
1869 | var logscale; /* scale in logarithmic space */ | 1867 | var logscale; /* scale in logarithmic space */ |
@@ -1885,7 +1883,7 @@ RrdGraph.prototype.horizontal_log_grid = function () | |||
1885 | /* major spacing for less dynamic data */ | 1883 | /* major spacing for less dynamic data */ |
1886 | do { | 1884 | do { |
1887 | mid++; | 1885 | mid++; |
1888 | for (i = 0; yloglab[mid][i + 1] < 10.0; i++) {}; | 1886 | for (i = 0; yloglab[mid][i + 1] < 10.0; i++) ; |
1889 | mspac = logscale * Math.log(10.0 / yloglab[mid][i])/Math.LN10; | 1887 | mspac = logscale * Math.log(10.0 / yloglab[mid][i])/Math.LN10; |
1890 | } while (mspac > 1.56 * this.TEXT.LEGEND.size && yloglab[mid][0] > 0); // FIXME 2->1.56 ?? | 1888 | } while (mspac > 1.56 * this.TEXT.LEGEND.size && yloglab[mid][0] > 0); // FIXME 2->1.56 ?? |
1891 | if (mid) mid--; | 1889 | if (mid) mid--; |
@@ -1966,7 +1964,7 @@ RrdGraph.prototype.horizontal_log_grid = function () | |||
1966 | if (mid < 4 && exfrac === 1) { /* minor grid */ | 1964 | if (mid < 4 && exfrac === 1) { /* minor grid */ |
1967 | if (flab === 0) { /* find first and last minor line behind current major line * i is the first line and j tha last */ | 1965 | if (flab === 0) { /* find first and last minor line behind current major line * i is the first line and j tha last */ |
1968 | min_exp = val_exp - 1; | 1966 | min_exp = val_exp - 1; |
1969 | for (i = 1; yloglab[mid][i] < 10.0; i++) {}; | 1967 | for (i = 1; yloglab[mid][i] < 10.0; i++) ; |
1970 | i = yloglab[mid][i - 1] + 1; | 1968 | i = yloglab[mid][i - 1] + 1; |
1971 | j = 10; | 1969 | j = 10; |
1972 | } else { | 1970 | } else { |
@@ -2002,7 +2000,7 @@ RrdGraph.prototype.horizontal_log_grid = function () | |||
2002 | if (mid < 4 && exfrac === 1) { /* draw minor lines after highest major line */ | 2000 | if (mid < 4 && exfrac === 1) { /* draw minor lines after highest major line */ |
2003 | if (flab === 0) { /* find first and last minor line below current major line * i is the first line and j tha last */ | 2001 | if (flab === 0) { /* find first and last minor line below current major line * i is the first line and j tha last */ |
2004 | min_exp = val_exp - 1; | 2002 | min_exp = val_exp - 1; |
2005 | for (i = 1; yloglab[mid][i] < 10.0; i++) {}; | 2003 | for (i = 1; yloglab[mid][i] < 10.0; i++) ; |
2006 | i = yloglab[mid][i - 1] + 1; | 2004 | i = yloglab[mid][i - 1] + 1; |
2007 | j = 10; | 2005 | j = 10; |
2008 | } else { | 2006 | } else { |
@@ -2386,20 +2384,20 @@ RrdGraph.prototype.grid_paint = function() | |||
2386 | this.GRC.FONT, this.TEXT.TITLE, this.tabwidth, 0.0, RrdGraph.GFX_H_CENTER, RrdGraph.GFX_V_TOP, this.title); | 2384 | this.GRC.FONT, this.TEXT.TITLE, this.tabwidth, 0.0, RrdGraph.GFX_H_CENTER, RrdGraph.GFX_V_TOP, this.title); |
2387 | /* rrdtool 'logo' */ | 2385 | /* rrdtool 'logo' */ |
2388 | if (!this.no_rrdtool_tag){ | 2386 | if (!this.no_rrdtool_tag){ |
2389 | var color = this.parse_color(this.GRC.FONT); | 2387 | var color = this.parse_color(this.GRC.FONT); |
2390 | color[3] = 0.3; | 2388 | color[3] = 0.3; |
2391 | var water_color = this.color2rgba(color); | 2389 | var water_color = this.color2rgba(color); |
2392 | var xpos = this.legendposition === RrdGraph.LEGEND_POS_EAST ? this.xOriginLegendY : this.ximg - 4; | 2390 | var xpos = this.legendposition === RrdGraph.LEGEND_POS_EAST ? this.xOriginLegendY : this.ximg - 4; |
2393 | this.gfx.text(xpos, 5, water_color, this.TEXT.WATERMARK, this.tabwidth, | 2391 | this.gfx.text(xpos, 5, water_color, this.TEXT.WATERMARK, this.tabwidth, |
2394 | -90, RrdGraph.GFX_H_LEFT, RrdGraph.GFX_V_TOP, "RRDTOOL / TOBI OETIKER"); | 2392 | -90, RrdGraph.GFX_H_LEFT, RrdGraph.GFX_V_TOP, "RRDTOOL / TOBI OETIKER"); |
2395 | } | 2393 | } |
2396 | /* graph watermark */ | 2394 | /* graph watermark */ |
2397 | if (this.watermark) { | 2395 | if (this.watermark) { |
2398 | var color = this.parse_color(this.GRC.FONT) | 2396 | var color = this.parse_color(this.GRC.FONT); |
2399 | color[3] = 0.3; | 2397 | color[3] = 0.3; |
2400 | var water_color = this.color2rgba(color); | 2398 | var water_color = this.color2rgba(color); |
2401 | this.gfx.text(this.ximg / 2, this.yimg - 6, water_color, this.TEXT.WATERMARK , this.tabwidth, 0, | 2399 | this.gfx.text(this.ximg / 2, this.yimg - 6, water_color, this.TEXT.WATERMARK , this.tabwidth, 0, |
2402 | RrdGraph.GFX_H_CENTER, RrdGraph.GFX_V_BOTTOM, this.watermark); | 2400 | RrdGraph.GFX_H_CENTER, RrdGraph.GFX_V_BOTTOM, this.watermark); |
2403 | } | 2401 | } |
2404 | /* graph labels */ | 2402 | /* graph labels */ |
2405 | if (!(this.no_legend) && !(this.only_graph)) { | 2403 | if (!(this.no_legend) && !(this.only_graph)) { |
@@ -2664,11 +2662,11 @@ RrdGraph.prototype.graph_paint_init = function() | |||
2664 | // this.gdes[i].end_orig = this.end; | 2662 | // this.gdes[i].end_orig = this.end; |
2665 | } | 2663 | } |
2666 | 2664 | ||
2667 | } | 2665 | }; |
2668 | 2666 | ||
2669 | RrdGraph.prototype.graph_paint_draw = function() | 2667 | RrdGraph.prototype.graph_paint_draw = function() |
2670 | { | 2668 | { |
2671 | var areazero = 0.0 | 2669 | var areazero = 0.0; |
2672 | var lastgdes = null; | 2670 | var lastgdes = null; |
2673 | 2671 | ||
2674 | if (this.data_calc() === -1) | 2672 | if (this.data_calc() === -1) |
@@ -2773,7 +2771,7 @@ RrdGraph.prototype.graph_paint_draw = function() | |||
2773 | this.gfx.moveTo(x, y); | 2771 | this.gfx.moveTo(x, y); |
2774 | x = ii + this.xorigin; | 2772 | x = ii + this.xorigin; |
2775 | y = last_y; | 2773 | y = last_y; |
2776 | this.gfx.lineTo(x, y) | 2774 | this.gfx.lineTo(x, y); |
2777 | } else { | 2775 | } else { |
2778 | var x = ii - 1 + this.xorigin; | 2776 | var x = ii - 1 + this.xorigin; |
2779 | var y = this.ytr(this.gdes[i].p_data[ii - 1]); | 2777 | var y = this.ytr(this.gdes[i].p_data[ii - 1]); |
@@ -2886,7 +2884,6 @@ RrdGraph.prototype.graph_paint_draw = function() | |||
2886 | break; | 2884 | break; |
2887 | case RrdGraphDesc.GF_STACK: | 2885 | case RrdGraphDesc.GF_STACK: |
2888 | throw new RrdGraphError("STACK should already be turned into LINE or AREA here"); | 2886 | throw new RrdGraphError("STACK should already be turned into LINE or AREA here"); |
2889 | break; | ||
2890 | } | 2887 | } |
2891 | } | 2888 | } |
2892 | //cairo_reset_clip(this.cr); | 2889 | //cairo_reset_clip(this.cr); |
@@ -2920,16 +2917,16 @@ RrdGraph.prototype.graph_paint_draw = function() | |||
2920 | 2917 | ||
2921 | RrdGraph.prototype.graph_paint = function () | 2918 | RrdGraph.prototype.graph_paint = function () |
2922 | { | 2919 | { |
2923 | this.graph_paint_init() | 2920 | this.graph_paint_init(); |
2924 | if (this.data_fetch() === -1) | 2921 | if (this.data_fetch() === -1) |
2925 | return -1; | 2922 | return -1; |
2926 | return this.graph_paint_draw() | 2923 | return this.graph_paint_draw(); |
2927 | }; | 2924 | }; |
2928 | 2925 | ||
2929 | RrdGraph.prototype.graph_paint_async = function () | 2926 | RrdGraph.prototype.graph_paint_async = function () |
2930 | { | 2927 | { |
2931 | this.graph_paint_init() | 2928 | this.graph_paint_init(); |
2932 | this.data_fetch_async() | 2929 | this.data_fetch_async(); |
2933 | }; | 2930 | }; |
2934 | 2931 | ||
2935 | RrdGraph.prototype.find_var = function(key) | 2932 | RrdGraph.prototype.find_var = function(key) |