From b6be82b8edefa452e72ed53391971e53d9dccf83 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Fri, 25 Jul 2014 23:28:21 +0200 Subject: 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. --- js/RrdJson.js | 103 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 54 insertions(+), 49 deletions(-) (limited to 'js/RrdJson.js') diff --git a/js/RrdJson.js b/js/RrdJson.js index fcbf76b..4ddcbc2 100644 --- a/js/RrdJson.js +++ b/js/RrdJson.js @@ -26,11 +26,11 @@ */ var RrdJson = function() { if (arguments.length == 1) { - this.init1.apply(this, arguments); + this.init1.apply(this, arguments); } else if (arguments.length == 2) { - this.init2.apply(this, arguments); + this.init2.apply(this, arguments); } else if (arguments.length == 3) { - this.init3.apply(this, arguments); + this.init3.apply(this, arguments); } }; @@ -40,12 +40,12 @@ RrdJson.prototype = { init1: function (rrdgraph) { - this.graph = rrdgraph + this.graph = rrdgraph; }, init2: function (rrdgraph, jsonstr) { this.json = JSON.parse(jsonstr); - this.graph = rrdgraph + this.graph = rrdgraph; }, init3: function (gfx, fetch, jsonstr) { @@ -69,7 +69,7 @@ RrdJson.prototype = { if (color in this.graph.GRC) { this.graph.GRC[color] = this.json.color[color]; } else { - throw "invalid color name '"+name+"'"; + throw "invalid color '" + color + "'"; } } break; @@ -191,16 +191,21 @@ RrdJson.prototype = { this.graph.second_axis_format = this.json.right_axis_format; break; case 'legend_position': - if (this.json.legend_position === "north") { - this.graph.legendposition = this.graph.LEGEND_POS.NORTH; - } else if (this.json.legend_position === "west") { - this.graph.legendposition = this.graph.LEGEND_POS.WEST; - } else if (this.json.legend_position === "south") { - this.graph.legendposition = this.graph.LEGEND_POS.SOUTH; - } else if (this.json.legend_position === "east") { - this.graph.legendposition = this.graph.LEGEND_POS.EAST; - } else { - throw "unknown legend-position '"+value+"'"; + switch (this.json.legend_position) { + case "north": + this.graph.legendposition = this.graph.LEGEND_POS.NORTH; + break; + case "west": + this.graph.legendposition = this.graph.LEGEND_POS.WEST; + break; + case "south": + this.graph.legendposition = this.graph.LEGEND_POS.SOUTH; + break; + case "east": + this.graph.legendposition = this.graph.LEGEND_POS.EAST; + break; + default: + throw "unknown legend-position '" + this.json.legend_position + "'"; } break; case 'legend_direction': @@ -209,7 +214,7 @@ RrdJson.prototype = { } else if (this.json.legend_direction === "bottomup") { this.graph.legenddirection = this.graph.LEGEND_DIR.BOTTOM_UP; } else { - throw "unknown legend-position '"+value+"'"; + throw "unknown legend-direction'" + this.json.legend_direction + "'"; } break; case 'border': @@ -272,21 +277,21 @@ RrdJson.prototype = { switch (gdes[i].align) { case 'left': this.graph.gdes_add_textalign(RrdGraphDesc.TXA_LEFT); - break + break; case 'right': this.graph.gdes_add_textalign(RrdGraphDesc.TXA_RIGHT); - break + break; case 'justified': this.graph.gdes_add_textalign(RrdGraphDesc.TXA_JUSTIFIED); - break + break; case 'center': this.graph.gdes_add_textalign(RrdGraphDesc.TXA_CENTER); - break + break; } break; // DEF:=::[:step=][:start=