aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/js
diff options
context:
space:
mode:
authorPeter Wu2014-08-02 16:55:18 +0200
committerPim van den Berg2014-11-14 00:09:58 +0100
commitc202908e0cbe1d0dd93e1ef374aec07a348086e4 (patch)
treeca4fd6c890250a514985c2dfd1491c19cd3a20f9 /js
parentjsrrdgraph: Guard out antique browsers for happier debugging (diff)
downloadapt-panopticon_cgp-c202908e0cbe1d0dd93e1ef374aec07a348086e4.zip
apt-panopticon_cgp-c202908e0cbe1d0dd93e1ef374aec07a348086e4.tar.gz
apt-panopticon_cgp-c202908e0cbe1d0dd93e1ef374aec07a348086e4.tar.bz2
apt-panopticon_cgp-c202908e0cbe1d0dd93e1ef374aec07a348086e4.tar.xz
jsrrdgraph: Fix undefined variables
Fixed various typos in references to variables. Also throw an exception if a variable is not found in GPRINT for debugging purposes and move some variable declarations.
Diffstat (limited to 'js')
-rw-r--r--js/RrdGraph.js28
1 files changed, 13 insertions, 15 deletions
diff --git a/js/RrdGraph.js b/js/RrdGraph.js
index a3b0124..038668e 100644
--- a/js/RrdGraph.js
+++ b/js/RrdGraph.js
@@ -266,10 +266,10 @@ RrdGraphDesc.prototype.fshift = function (graph, vname, offset)
266 266
267 this.shidx = graph.find_var(offset); 267 this.shidx = graph.find_var(offset);
268 if (this.shidx >= 0) { 268 if (this.shidx >= 0) {
269 if (graph.gdes[gdp.shidx].gf === RrdGraphDesc.GF_DEF || graph.gdes[gdp.shidx].gf === RrdGraphDesc.GF_CDEF) 269 if (graph.gdes[this.shidx].gf === RrdGraphDesc.GF_DEF || graph.gdes[this.shidx].gf === RrdGraphDesc.GF_CDEF)
270 throw new RrdGraphDescError("Offset cannot be a (C)DEF: '"+graph.gdes[gdp.shidx].gf+"'"); 270 throw new RrdGraphDescError("Offset cannot be a (C)DEF: '"+graph.gdes[this.shidx].gf+"'");
271 if (graph.gdes[gdp.shidx].gf !== RrdGraphDesc.GF_VDEF) 271 if (graph.gdes[this.shidx].gf !== RrdGraphDesc.GF_VDEF)
272 throw new RrdGraphDescError("Encountered unknown type variable '"+graph.gdes[gdp.shidx].vname+"'"); 272 throw new RrdGraphDescError("Encountered unknown type variable '"+graph.gdes[this.shidx].vname+"'");
273 } else { 273 } else {
274 this.shval = parseInt(offset, 10); // FIXME check 274 this.shval = parseInt(offset, 10); // FIXME check
275 this.shidx = -1; 275 this.shidx = -1;
@@ -323,6 +323,9 @@ RrdGraphDesc.prototype.gprint = function (graph, vname, cf, format, strftimefmt)
323 this.vname = vname; 323 this.vname = vname;
324 this.vidx = graph.find_var(vname); 324 this.vidx = graph.find_var(vname);
325 this.legend = ''; 325 this.legend = '';
326 if (this.vidx == -1) {
327 throw new RrdGraphDescError("Cannot find var name: " + vname);
328 }
326 if (!format) { 329 if (!format) {
327 this.format = cf; 330 this.format = cf;
328 switch (graph.gdes[this.vidx].gf) { 331 switch (graph.gdes[this.vidx].gf) {
@@ -437,7 +440,7 @@ var RrdVdef = function(vname, str) /* parse */
437 else if (func === 'LSLINT') this.op = RrdVdef.VDEF_LSLINT; 440 else if (func === 'LSLINT') this.op = RrdVdef.VDEF_LSLINT;
438 else if (func === 'LSLCORREL') this.op = RrdVdef.VDEF_LSLCORREL; 441 else if (func === 'LSLCORREL') this.op = RrdVdef.VDEF_LSLCORREL;
439 else { 442 else {
440 throw new RrdVdefError('Unknown function "'+func+'" in VDEF "'+vame+'"'); 443 throw new RrdVdefError('Unknown function "'+func+'" in VDEF "'+vname+'"');
441 } 444 }
442 445
443 switch (this.op) { 446 switch (this.op) {
@@ -511,15 +514,15 @@ RrdVdef.prototype.calc = function(src)
511{ 514{
512 var data; 515 var data;
513 var step, steps; 516 var step, steps;
517 var array = [];
518 var field;
519 var cnt = 0;
514 520
515 data = src.data; 521 data = src.data;
516 steps = (src.end - src.start) / src.step; 522 steps = (src.end - src.start) / src.step;
517 523
518 switch (this.op) { 524 switch (this.op) {
519 case RrdVdef.VDEF_PERCENT: 525 case RrdVdef.VDEF_PERCENT:
520 var array = [];
521 var field;
522
523 for (step = 0; step < steps; step++) { 526 for (step = 0; step < steps; step++) {
524 array[step] = data[step * src.ds_cnt]; 527 array[step] = data[step * src.ds_cnt];
525 } 528 }
@@ -529,18 +532,15 @@ RrdVdef.prototype.calc = function(src)
529 this.when = 0; /* no time component */ 532 this.when = 0; /* no time component */
530 break; 533 break;
531 case RrdVdef.VDEF_PERCENTNAN: 534 case RrdVdef.VDEF_PERCENTNAN:
532 var array = [];
533 var field;
534
535 field=0; 535 field=0;
536 for (step = 0; step < steps; step++) { 536 for (step = 0; step < steps; step++) {
537 if (!isNaN(data[step * src.ds_cnt])) { 537 if (!isNaN(data[step * src.ds_cnt])) {
538 array[field] = data[step * src.ds_cnt]; 538 array[field] = data[step * src.ds_cnt];
539 } 539 }
540 } 540 }
541 array.sort(vdef_percent_compar); 541 array.sort(this.vdef_percent_compar);
542 field = Math.round(this.param * (field - 1) / 100.0); 542 field = Math.round(this.param * (field - 1) / 100.0);
543 his.val = array[field]; 543 this.val = array[field];
544 this.when = 0; /* no time component */ 544 this.when = 0; /* no time component */
545 break; 545 break;
546 case RrdVdef.VDEF_MAXIMUM: 546 case RrdVdef.VDEF_MAXIMUM:
@@ -566,7 +566,6 @@ RrdVdef.prototype.calc = function(src)
566 case RrdVdef.VDEF_TOTAL: 566 case RrdVdef.VDEF_TOTAL:
567 case RrdVdef.VDEF_STDEV: 567 case RrdVdef.VDEF_STDEV:
568 case RrdVdef.VDEF_AVERAGE: 568 case RrdVdef.VDEF_AVERAGE:
569 var cnt = 0;
570 var sum = 0.0; 569 var sum = 0.0;
571 var average = 0.0; 570 var average = 0.0;
572 571
@@ -645,7 +644,6 @@ RrdVdef.prototype.calc = function(src)
645 case RrdVdef.VDEF_LSLSLOPE: 644 case RrdVdef.VDEF_LSLSLOPE:
646 case RrdVdef.VDEF_LSLINT: 645 case RrdVdef.VDEF_LSLINT:
647 case RrdVdef.VDEF_LSLCORREL: 646 case RrdVdef.VDEF_LSLCORREL:
648 var cnt = 0;
649 var SUMx, SUMy, SUMxy, SUMxx, SUMyy, slope, y_intercept, correl; 647 var SUMx, SUMy, SUMxy, SUMxx, SUMyy, slope, y_intercept, correl;
650 648
651 SUMx = 0; 649 SUMx = 0;