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/RrdJson.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 '')
| -rw-r--r-- | js/RrdJson.js | 103 |
1 files changed, 54 insertions, 49 deletions
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 @@ | |||
| 26 | */ | 26 | */ |
| 27 | var RrdJson = function() { | 27 | var RrdJson = function() { |
| 28 | if (arguments.length == 1) { | 28 | if (arguments.length == 1) { |
| 29 | this.init1.apply(this, arguments); | 29 | this.init1.apply(this, arguments); |
| 30 | } else if (arguments.length == 2) { | 30 | } else if (arguments.length == 2) { |
| 31 | this.init2.apply(this, arguments); | 31 | this.init2.apply(this, arguments); |
| 32 | } else if (arguments.length == 3) { | 32 | } else if (arguments.length == 3) { |
| 33 | this.init3.apply(this, arguments); | 33 | this.init3.apply(this, arguments); |
| 34 | } | 34 | } |
| 35 | }; | 35 | }; |
| 36 | 36 | ||
| @@ -40,12 +40,12 @@ RrdJson.prototype = { | |||
| 40 | 40 | ||
| 41 | init1: function (rrdgraph) | 41 | init1: function (rrdgraph) |
| 42 | { | 42 | { |
| 43 | this.graph = rrdgraph | 43 | this.graph = rrdgraph; |
| 44 | }, | 44 | }, |
| 45 | init2: function (rrdgraph, jsonstr) | 45 | init2: function (rrdgraph, jsonstr) |
| 46 | { | 46 | { |
| 47 | this.json = JSON.parse(jsonstr); | 47 | this.json = JSON.parse(jsonstr); |
| 48 | this.graph = rrdgraph | 48 | this.graph = rrdgraph; |
| 49 | }, | 49 | }, |
| 50 | init3: function (gfx, fetch, jsonstr) | 50 | init3: function (gfx, fetch, jsonstr) |
| 51 | { | 51 | { |
| @@ -69,7 +69,7 @@ RrdJson.prototype = { | |||
| 69 | if (color in this.graph.GRC) { | 69 | if (color in this.graph.GRC) { |
| 70 | this.graph.GRC[color] = this.json.color[color]; | 70 | this.graph.GRC[color] = this.json.color[color]; |
| 71 | } else { | 71 | } else { |
| 72 | throw "invalid color name '"+name+"'"; | 72 | throw "invalid color '" + color + "'"; |
| 73 | } | 73 | } |
| 74 | } | 74 | } |
| 75 | break; | 75 | break; |
| @@ -191,16 +191,21 @@ RrdJson.prototype = { | |||
| 191 | this.graph.second_axis_format = this.json.right_axis_format; | 191 | this.graph.second_axis_format = this.json.right_axis_format; |
| 192 | break; | 192 | break; |
| 193 | case 'legend_position': | 193 | case 'legend_position': |
| 194 | if (this.json.legend_position === "north") { | 194 | switch (this.json.legend_position) { |
| 195 | this.graph.legendposition = this.graph.LEGEND_POS.NORTH; | 195 | case "north": |
| 196 | } else if (this.json.legend_position === "west") { | 196 | this.graph.legendposition = this.graph.LEGEND_POS.NORTH; |
| 197 | this.graph.legendposition = this.graph.LEGEND_POS.WEST; | 197 | break; |
| 198 | } else if (this.json.legend_position === "south") { | 198 | case "west": |
| 199 | this.graph.legendposition = this.graph.LEGEND_POS.SOUTH; | 199 | this.graph.legendposition = this.graph.LEGEND_POS.WEST; |
| 200 | } else if (this.json.legend_position === "east") { | 200 | break; |
| 201 | this.graph.legendposition = this.graph.LEGEND_POS.EAST; | 201 | case "south": |
| 202 | } else { | 202 | this.graph.legendposition = this.graph.LEGEND_POS.SOUTH; |
| 203 | throw "unknown legend-position '"+value+"'"; | 203 | break; |
| 204 | case "east": | ||
| 205 | this.graph.legendposition = this.graph.LEGEND_POS.EAST; | ||
| 206 | break; | ||
| 207 | default: | ||
| 208 | throw "unknown legend-position '" + this.json.legend_position + "'"; | ||
| 204 | } | 209 | } |
| 205 | break; | 210 | break; |
| 206 | case 'legend_direction': | 211 | case 'legend_direction': |
| @@ -209,7 +214,7 @@ RrdJson.prototype = { | |||
| 209 | } else if (this.json.legend_direction === "bottomup") { | 214 | } else if (this.json.legend_direction === "bottomup") { |
| 210 | this.graph.legenddirection = this.graph.LEGEND_DIR.BOTTOM_UP; | 215 | this.graph.legenddirection = this.graph.LEGEND_DIR.BOTTOM_UP; |
| 211 | } else { | 216 | } else { |
| 212 | throw "unknown legend-position '"+value+"'"; | 217 | throw "unknown legend-direction'" + this.json.legend_direction + "'"; |
| 213 | } | 218 | } |
| 214 | break; | 219 | break; |
| 215 | case 'border': | 220 | case 'border': |
| @@ -272,21 +277,21 @@ RrdJson.prototype = { | |||
| 272 | switch (gdes[i].align) { | 277 | switch (gdes[i].align) { |
| 273 | case 'left': | 278 | case 'left': |
| 274 | this.graph.gdes_add_textalign(RrdGraphDesc.TXA_LEFT); | 279 | this.graph.gdes_add_textalign(RrdGraphDesc.TXA_LEFT); |
| 275 | break | 280 | break; |
| 276 | case 'right': | 281 | case 'right': |
| 277 | this.graph.gdes_add_textalign(RrdGraphDesc.TXA_RIGHT); | 282 | this.graph.gdes_add_textalign(RrdGraphDesc.TXA_RIGHT); |
| 278 | break | 283 | break; |
| 279 | case 'justified': | 284 | case 'justified': |
| 280 | this.graph.gdes_add_textalign(RrdGraphDesc.TXA_JUSTIFIED); | 285 | this.graph.gdes_add_textalign(RrdGraphDesc.TXA_JUSTIFIED); |
| 281 | break | 286 | break; |
| 282 | case 'center': | 287 | case 'center': |
| 283 | this.graph.gdes_add_textalign(RrdGraphDesc.TXA_CENTER); | 288 | this.graph.gdes_add_textalign(RrdGraphDesc.TXA_CENTER); |
| 284 | break | 289 | break; |
| 285 | } | 290 | } |
| 286 | break; | 291 | break; |
| 287 | // DEF:<vname>=<rrdfile>:<ds-name>:<CF>[:step=<step>][:start=<time>][:end=<time>][:reduce=<CF>] | 292 | // DEF:<vname>=<rrdfile>:<ds-name>:<CF>[:step=<step>][:start=<time>][:end=<time>][:reduce=<CF>] |
| 288 | case 'DEF': | 293 | case 'DEF': |
| 289 | this.graph.gdes_add_def(gdes[i].vname, gdes[i].rrdfile, gdes[i].name, gdes[i].cf, gdes[i].step, gdes[i].start, gdes[i].end, gdes[i].reduce) | 294 | this.graph.gdes_add_def(gdes[i].vname, gdes[i].rrdfile, gdes[i].name, gdes[i].cf, gdes[i].step, gdes[i].start, gdes[i].end, gdes[i].reduce); |
| 290 | break; | 295 | break; |
| 291 | // CDEF:vname=RPN expression | 296 | // CDEF:vname=RPN expression |
| 292 | case 'CDEF': | 297 | case 'CDEF': |
| @@ -311,7 +316,7 @@ RrdJson.prototype = { | |||
| 311 | 316 | ||
| 312 | if (this.graph.alt_autoscale != false || full) | 317 | if (this.graph.alt_autoscale != false || full) |
| 313 | this.json.alt_autoscale = this.graph.alt_autoscale; | 318 | this.json.alt_autoscale = this.graph.alt_autoscale; |
| 314 | 319 | ||
| 315 | if (this.graph.base != 1000 || full) | 320 | if (this.graph.base != 1000 || full) |
| 316 | this.json.base = this.graph.base; | 321 | this.json.base = this.graph.base; |
| 317 | 322 | ||
| @@ -338,7 +343,7 @@ RrdJson.prototype = { | |||
| 338 | if (this.graph.GRC.FRAME != 'rgba(0, 0, 0, 1.0)' || full) | 343 | if (this.graph.GRC.FRAME != 'rgba(0, 0, 0, 1.0)' || full) |
| 339 | this.json.color.FRAME = this.graph.GRC.FRAME; | 344 | this.json.color.FRAME = this.graph.GRC.FRAME; |
| 340 | 345 | ||
| 341 | if (Object.keys(this.json.color) == 0) delete this.json.color; | 346 | if (!Object.keys(this.json.color).length) delete this.json.color; |
| 342 | 347 | ||
| 343 | if (this.graph.full_size_mode != false || full) | 348 | if (this.graph.full_size_mode != false || full) |
| 344 | this.json.full_size_mode = this.graph.full_size_mode; | 349 | this.json.full_size_mode = this.graph.full_size_mode; |
| @@ -351,10 +356,10 @@ RrdJson.prototype = { | |||
| 351 | 356 | ||
| 352 | if (this.graph.force_rules_legend != false || full) | 357 | if (this.graph.force_rules_legend != false || full) |
| 353 | this.json.force_rules_legend = this.graph.force_rules_legend; | 358 | this.json.force_rules_legend = this.graph.force_rules_legend; |
| 354 | 359 | ||
| 355 | if (this.graph.no_legend != false || full) | 360 | if (this.graph.no_legend != false || full) |
| 356 | this.json.no_legend = this.graph.no_legend; | 361 | this.json.no_legend = this.graph.no_legend; |
| 357 | 362 | ||
| 358 | this.json.width = this.graph.xsize; | 363 | this.json.width = this.graph.xsize; |
| 359 | this.json.height = this.graph.ysize; | 364 | this.json.height = this.graph.ysize; |
| 360 | 365 | ||
| @@ -363,10 +368,10 @@ RrdJson.prototype = { | |||
| 363 | 368 | ||
| 364 | if (this.graph.alt_autoscale_min != false || full) | 369 | if (this.graph.alt_autoscale_min != false || full) |
| 365 | this.json.alt_autoscale_min = this.graph.alt_autoscale_min; | 370 | this.json.alt_autoscale_min = this.graph.alt_autoscale_min; |
| 366 | 371 | ||
| 367 | if (this.graph.only_graph != false || full) | 372 | if (this.graph.only_graph != false || full) |
| 368 | this.json.only_graph = this.graph.only_graph; | 373 | this.json.only_graph = this.graph.only_graph; |
| 369 | 374 | ||
| 370 | if (this.graph.unitslength != 6 || full) | 375 | if (this.graph.unitslength != 6 || full) |
| 371 | this.json.units_length = this.graph.unitslength; | 376 | this.json.units_length = this.graph.unitslength; |
| 372 | 377 | ||
| @@ -381,7 +386,7 @@ RrdJson.prototype = { | |||
| 381 | 386 | ||
| 382 | if (this.graph.gridfit != true || full) | 387 | if (this.graph.gridfit != true || full) |
| 383 | this.json.no_gridfit = this.graph.gridfit; | 388 | this.json.no_gridfit = this.graph.gridfit; |
| 384 | 389 | ||
| 385 | this.json.font = {}; | 390 | this.json.font = {}; |
| 386 | if (this.graph.TEXT.DEFAULT.size != 11 || this.graph.TEXT.LEGEND.font != this.graph.DEFAULT_FONT || full) | 391 | if (this.graph.TEXT.DEFAULT.size != 11 || this.graph.TEXT.LEGEND.font != this.graph.DEFAULT_FONT || full) |
| 387 | this.json.font.DEFAULT = { size: this.graph.TEXT.DEFAULT.size, font: this.graph.TEXT.DEFAULT.font}; | 392 | this.json.font.DEFAULT = { size: this.graph.TEXT.DEFAULT.size, font: this.graph.TEXT.DEFAULT.font}; |
| @@ -396,31 +401,31 @@ RrdJson.prototype = { | |||
| 396 | if (this.graph.TEXT.WATERMARK.size != 8 || this.graph.TEXT.WATERMARK.font != this.graph.DEFAULT_FONT || full) | 401 | if (this.graph.TEXT.WATERMARK.size != 8 || this.graph.TEXT.WATERMARK.font != this.graph.DEFAULT_FONT || full) |
| 397 | this.json.font.WATERMARK = { size: this.graph.TEXT.WATERMARK.size, font: this.graph.TEXT.WATERMARK.font}; | 402 | this.json.font.WATERMARK = { size: this.graph.TEXT.WATERMARK.size, font: this.graph.TEXT.WATERMARK.font}; |
| 398 | 403 | ||
| 399 | if (Object.keys(this.json.font) == 0) delete this.json.font; | 404 | if (!Object.keys(this.json.font).length) delete this.json.font; |
| 400 | 405 | ||
| 401 | if (this.graph.logarithmic != false || full) | 406 | if (this.graph.logarithmic != false || full) |
| 402 | this.json.logarithmic = this.graph.logarithmic; | 407 | this.json.logarithmic = this.graph.logarithmic; |
| 403 | 408 | ||
| 404 | if (this.graph.rigid != false || full) | 409 | if (this.graph.rigid != false || full) |
| 405 | this.json.rigid = this.graph.rigid; | 410 | this.json.rigid = this.graph.rigid; |
| 406 | 411 | ||
| 407 | // this.json.step = this.graph.step; // FIXME | 412 | // this.json.step = this.graph.step; // FIXME |
| 408 | 413 | ||
| 409 | if (this.graph.tabwidth != 40 || full) | 414 | if (this.graph.tabwidth != 40 || full) |
| 410 | this.json.tabwidth = this.graph.tabwidth; | 415 | this.json.tabwidth = this.graph.tabwidth; |
| 411 | 416 | ||
| 412 | if (this.graph.title != '' || full) | 417 | if (this.graph.title != '' || full) |
| 413 | this.json.title = this.graph.title; | 418 | this.json.title = this.graph.title; |
| 414 | 419 | ||
| 415 | if (!isNaN(this.graph.setmaxval) || full) | 420 | if (!isNaN(this.graph.setmaxval) || full) |
| 416 | this.json.upper_limit = this.graph.setmaxval; | 421 | this.json.upper_limit = this.graph.setmaxval; |
| 417 | 422 | ||
| 418 | if (this.graph.ylegend != null || full) | 423 | if (this.graph.ylegend != null || full) |
| 419 | this.json.vertical_label = this.graph.ylegend; | 424 | this.json.vertical_label = this.graph.ylegend; |
| 420 | 425 | ||
| 421 | if (this.graph.watermark != null || full) | 426 | if (this.graph.watermark != null || full) |
| 422 | this.json.watermark = this.graph.watermark; | 427 | this.json.watermark = this.graph.watermark; |
| 423 | 428 | ||
| 424 | if (this.graph.unitsexponent != 9999 || full) | 429 | if (this.graph.unitsexponent != 9999 || full) |
| 425 | this.json.units_exponent = this.graph.unitsexponent; | 430 | this.json.units_exponent = this.graph.unitsexponent; |
| 426 | 431 | ||
| @@ -432,10 +437,10 @@ RrdJson.prototype = { | |||
| 432 | // this.json.y_grid = // FIXME | 437 | // this.json.y_grid = // FIXME |
| 433 | 438 | ||
| 434 | // this.json.lazy = this.graph.lazy; | 439 | // this.json.lazy = this.graph.lazy; |
| 435 | 440 | ||
| 436 | if (this.graph.force_units_si != false || full) | 441 | if (this.graph.force_units_si != false || full) |
| 437 | this.json.units = 'si'; // FIXME | 442 | this.json.units = 'si'; // FIXME |
| 438 | 443 | ||
| 439 | if (this.graph.no_rrdtool_tag != false || full) | 444 | if (this.graph.no_rrdtool_tag != false || full) |
| 440 | this.json.disable_rrdtool_tag = this.graph.no_rrdtool_tag; | 445 | this.json.disable_rrdtool_tag = this.graph.no_rrdtool_tag; |
| 441 | 446 | ||
| @@ -451,13 +456,13 @@ RrdJson.prototype = { | |||
| 451 | 456 | ||
| 452 | if (this.graph.draw_3d_border != 2 || full) | 457 | if (this.graph.draw_3d_border != 2 || full) |
| 453 | this.json.border = this.graph.draw_3d_border; | 458 | this.json.border = this.graph.draw_3d_border; |
| 454 | 459 | ||
| 455 | if (this.graph.grid_dash_on != 1 || this.graph.grid_dash_off != 1 || full) | 460 | if (this.graph.grid_dash_on != 1 || this.graph.grid_dash_off != 1 || full) |
| 456 | this.json.grid_dash = [this.graph.grid_dash_on, this.graph.grid_dash_off] | 461 | this.json.grid_dash = [this.graph.grid_dash_on, this.graph.grid_dash_off]; |
| 457 | 462 | ||
| 458 | if (this.graph.dynamic_labels != false || full) | 463 | if (this.graph.dynamic_labels != false || full) |
| 459 | this.json.dynamic_labels = this.graph.dynamic_labels; | 464 | this.json.dynamic_labels = this.graph.dynamic_labels; |
| 460 | 465 | ||
| 461 | this.json.gdes = []; | 466 | this.json.gdes = []; |
| 462 | for (var i = 0, gdes_c = this.graph.gdes.length; i < gdes_c; i++) { | 467 | for (var i = 0, gdes_c = this.graph.gdes.length; i < gdes_c; i++) { |
| 463 | switch (this.graph.gdes[i].gf) { | 468 | switch (this.graph.gdes[i].gf) { |
| @@ -465,7 +470,7 @@ RrdJson.prototype = { | |||
| 465 | case RrdGraphDesc.GF_GPRINT: | 470 | case RrdGraphDesc.GF_GPRINT: |
| 466 | this.json.gdes.push({ | 471 | this.json.gdes.push({ |
| 467 | type: 'GPRINT', | 472 | type: 'GPRINT', |
| 468 | vname: this.graph.gdes[i].vname, | 473 | vname: this.graph.gdes[i].vname, |
| 469 | cf: RrdGraphDesc.cf2str(this.graph.gdes[i].cf), | 474 | cf: RrdGraphDesc.cf2str(this.graph.gdes[i].cf), |
| 470 | format: this.graph.gdes[i].format, | 475 | format: this.graph.gdes[i].format, |
| 471 | strftm: (this.graph.gdes[i].strftm === false ? undefined : this.graph.gdes[i].strftm) }); | 476 | strftm: (this.graph.gdes[i].strftm === false ? undefined : this.graph.gdes[i].strftm) }); |
| @@ -526,16 +531,16 @@ RrdJson.prototype = { | |||
| 526 | switch (this.graph.gdes[i].txtalign) { | 531 | switch (this.graph.gdes[i].txtalign) { |
| 527 | case RrdGraphDesc.TXA_LEFT: | 532 | case RrdGraphDesc.TXA_LEFT: |
| 528 | align = 'left'; | 533 | align = 'left'; |
| 529 | break | 534 | break; |
| 530 | case RrdGraphDesc.TXA_RIGHT: | 535 | case RrdGraphDesc.TXA_RIGHT: |
| 531 | align = 'right'; | 536 | align = 'right'; |
| 532 | break | 537 | break; |
| 533 | case RrdGraphDesc.TXA_JUSTIFIED: | 538 | case RrdGraphDesc.TXA_JUSTIFIED: |
| 534 | align = 'justified'; | 539 | align = 'justified'; |
| 535 | break | 540 | break; |
| 536 | case RrdGraphDesc.TXA_CENTER: | 541 | case RrdGraphDesc.TXA_CENTER: |
| 537 | align = 'center'; | 542 | align = 'center'; |
| 538 | break | 543 | break; |
| 539 | } | 544 | } |
| 540 | 545 | ||
| 541 | this.json.gdes.push({ | 546 | this.json.gdes.push({ |
| @@ -559,7 +564,7 @@ RrdJson.prototype = { | |||
| 559 | // reduce: RrdGraphDesc.cf2str(this.graph.gdes[i].cf_reduce) | 564 | // reduce: RrdGraphDesc.cf2str(this.graph.gdes[i].cf_reduce) |
| 560 | reduce: undefined | 565 | reduce: undefined |
| 561 | }); | 566 | }); |
| 562 | 567 | ||
| 563 | break; | 568 | break; |
| 564 | // CDEF:vname=RPN expression | 569 | // CDEF:vname=RPN expression |
| 565 | case RrdGraphDesc.GF_CDEF: | 570 | case RrdGraphDesc.GF_CDEF: |
