From fccc378b8f1fc0733a88acbca1a6e98f0ac60447 Mon Sep 17 00:00:00 2001 From: Richard Wall Date: Fri, 12 Aug 2011 23:26:10 +0100 Subject: weird indentation --- docs/examples/assets/js/jsrrdgraph.js | 714 +++++++++++++++++----------------- 1 file changed, 359 insertions(+), 355 deletions(-) (limited to 'docs/examples/assets') diff --git a/docs/examples/assets/js/jsrrdgraph.js b/docs/examples/assets/js/jsrrdgraph.js index 279be04..a7d0b9e 100644 --- a/docs/examples/assets/js/jsrrdgraph.js +++ b/docs/examples/assets/js/jsrrdgraph.js @@ -771,342 +771,346 @@ RRDRpn.prototype = { for (var rpi = 0; this.rpnp[rpi].op != RRDRpn.OP.END; rpi++) { switch (this.rpnp[rpi].op) { - case RRDRpn.OP.NUMBER: - this.rpnstack[++stptr] = this.rpnp[rpi].val; - break; - case RRDRpn.OP.VARIABLE: - case RRDRpn.OP.PREV_OTHER: - if (this.rpnp[rpi].ds_cnt == 0) { - throw "VDEF made it into rpn_calc... aborting"; - } else { - if (this.rpnp[rpi].op == RRDRpn.OP.VARIABLE) { - this.rpnstack[++stptr] = this.rpnp[rpi].data[this.rpnp[rpi].pdata]; - } else { - if ((output_idx) <= 0) this.rpnstack[++stptr] = Number.NaN; - else this.rpnstack[++stptr] = this.rpnp[rpi].data[this.rpnp[rpi].pdata - this.rpnp[rpi].ds_cnt]; - } - if (data_idx % this.rpnp[rpi].step == 0) { - this.rpnp[rpi].pdata += this.rpnp[rpi].ds_cnt; - } - } - break; - case RRDRpn.OP.COUNT: - this.rpnstack[++stptr] = (output_idx + 1); /* Note: Counter starts at 1 */ - break; - case RRDRpn.OP.PREV: - if ((output_idx) <= 0) this.rpnstack[++stptr] = Number.NaN; - else this.rpnstack[++stptr] = output[output_idx - 1]; - break; - case RRDRpn.OP.UNKN: - this.rpnstack[++stptr] = Number.NaN; - break; - case RRDRpn.OP.INF: - this.rpnstack[++stptr] = Infinity; - break; - case RRDRpn.OP.NEGINF: - this.rpnstack[++stptr] = -Infinity; - break; - case RRDRpn.OP.NOW: - this.rpnstack[++stptr] = Math.round((new Date()).getTime() / 1000); - break; - case RRDRpn.OP.TIME: - this.rpnstack[++stptr] = data_idx; - break; - case RRDRpn.OP.LTIME: - var date = new Date(data_idx*1000); // FIXME XXX - this.rpnstack[++stptr] = date.getTimezoneOffset() * 60 + data_idx; - break; - case RRDRpn.OP.ADD: - if(stptr < 1) throw RRDRpn.STACK_UNDERFLOW; - this.rpnstack[stptr - 1] = this.rpnstack[stptr - 1] + this.rpnstack[stptr]; - stptr--; - break; - case RRDRpn.OP.ADDNAN: - if(stptr < 1) throw RRDRpn.STACK_UNDERFLOW; - if (isNaN(this.rpnstack[stptr - 1])) { - this.rpnstack[stptr - 1] = this.rpnstack[stptr]; - } else if (isNaN(this.rpnstack[stptr])) { - /* NOOP */ - /* this.rpnstack[stptr - 1] = this.rpnstack[stptr - 1]; */ + case RRDRpn.OP.NUMBER: + this.rpnstack[++stptr] = this.rpnp[rpi].val; + break; + case RRDRpn.OP.VARIABLE: + case RRDRpn.OP.PREV_OTHER: + if (this.rpnp[rpi].ds_cnt == 0) { + throw "VDEF made it into rpn_calc... aborting"; + } else { + if (this.rpnp[rpi].op == RRDRpn.OP.VARIABLE) { + this.rpnstack[++stptr] = this.rpnp[rpi].data[this.rpnp[rpi].pdata]; } else { - this.rpnstack[stptr - 1] = this.rpnstack[stptr - 1] + this.rpnstack[stptr]; + if ((output_idx) <= 0) this.rpnstack[++stptr] = Number.NaN; + else this.rpnstack[++stptr] = this.rpnp[rpi].data[this.rpnp[rpi].pdata - this.rpnp[rpi].ds_cnt]; } - stptr--; - break; - case RRDRpn.OP.SUB: - if(stptr < 1) throw RRDRpn.STACK_UNDERFLOW; - this.rpnstack[stptr - 1] = this.rpnstack[stptr - 1] - this.rpnstack[stptr]; - stptr--; - break; - case RRDRpn.OP.MUL: - if(stptr < 1) throw RRDRpn.STACK_UNDERFLOW; - this.rpnstack[stptr - 1] = (this.rpnstack[stptr - 1]) * (this.rpnstack[stptr]); - stptr--; - break; - case RRDRpn.OP.DIV: - if(stptr < 1) throw RRDRpn.STACK_UNDERFLOW; - this.rpnstack[stptr - 1] = this.rpnstack[stptr - 1] / this.rpnstack[stptr]; - stptr--; - break; - case RRDRpn.OP.MOD: - if(stptr < 1) throw RRDRpn.STACK_UNDERFLOW; - this.rpnstack[stptr - 1] = this.fmod(this.rpnstack[stptr - 1] , this.rpnstack[stptr]); - stptr--; - break; - case RRDRpn.OP.SIN: - if(stptr < 0) throw RRDRpn.STACK_UNDERFLOW; - this.rpnstack[stptr] = Math.sin(this.rpnstack[stptr]); - break; - case RRDRpn.OP.ATAN: - if(stptr < 0) throw RRDRpn.STACK_UNDERFLOW; - this.rpnstack[stptr] = Math.atan(this.rpnstack[stptr]); - break; - case RRDRpn.OP.RAD2DEG: - if(stptr < 0) throw RRDRpn.STACK_UNDERFLOW; - this.rpnstack[stptr] = 57.29577951 * this.rpnstack[stptr]; - break; - case RRDRpn.OP.DEG2RAD: - if(stptr < 0) throw RRDRpn.STACK_UNDERFLOW; - this.rpnstack[stptr] = 0.0174532952 * this.rpnstack[stptr]; - break; - case RRDRpn.OP.ATAN2: - if(stptr < 1) throw RRDRpn.STACK_UNDERFLOW; - this.rpnstack[stptr - 1] = Math.atan2(this.rpnstack[stptr - 1], this.rpnstack[stptr]); - stptr--; - break; - case RRDRpn.OP.COS: - if(stptr < 0) throw RRDRpn.STACK_UNDERFLOW; - this.rpnstack[stptr] = Math.cos(this.rpnstack[stptr]); - break; - case RRDRpn.OP.CEIL: - if(stptr < 0) throw RRDRpn.STACK_UNDERFLOW; - this.rpnstack[stptr] = Math.ceil(this.rpnstack[stptr]); - break; - case RRDRpn.OP.FLOOR: - if(stptr < 0) throw RRDRpn.STACK_UNDERFLOW; - this.rpnstack[stptr] = Math.floor(this.rpnstack[stptr]); - break; - case RRDRpn.OP.LOG: - if(stptr < 0) throw RRDRpn.STACK_UNDERFLOW; - this.rpnstack[stptr] = Math.log(this.rpnstack[stptr]); - break; - case RRDRpn.OP.DUP: - if(stptr < 0) throw RRDRpn.STACK_UNDERFLOW; - this.rpnstack[stptr + 1] = this.rpnstack[stptr]; - stptr++; - break; - case RRDRpn.OP.POP: - if(stptr < 0) throw RRDRpn.STACK_UNDERFLOW; - stptr--; - break; - case RRDRpn.OP.EXC: - if(stptr < 1) throw RRDRpn.STACK_UNDERFLOW; { - var dummy = this.rpnstack[stptr]; - this.rpnstack[stptr] = this.rpnstack[stptr - 1]; - this.rpnstack[stptr - 1] = dummy; + if (data_idx % this.rpnp[rpi].step == 0) { + this.rpnp[rpi].pdata += this.rpnp[rpi].ds_cnt; } - break; - case RRDRpn.OP.EXP: - if(stptr < 0) throw RRDRpn.STACK_UNDERFLOW; - this.rpnstack[stptr] = Math.exp(this.rpnstack[stptr]); - break; - case RRDRpn.OP.LT: - if(stptr < 1) throw RRDRpn.STACK_UNDERFLOW; - if (isNaN(this.rpnstack[stptr - 1])); - else if (isNaN(this.rpnstack[stptr])) - this.rpnstack[stptr - 1] = this.rpnstack[stptr]; - else - this.rpnstack[stptr - 1] = this.rpnstack[stptr - 1] < this.rpnstack[stptr] ? 1.0 : 0.0; - stptr--; - break; - case RRDRpn.OP.LE: - if(stptr < 1) throw RRDRpn.STACK_UNDERFLOW; - if (isNaN(this.rpnstack[stptr - 1])); - else if (isNaN(this.rpnstack[stptr])) - this.rpnstack[stptr - 1] = this.rpnstack[stptr]; - else - this.rpnstack[stptr - 1] = this.rpnstack[stptr - 1] <= this.rpnstack[stptr] ? 1.0 : 0.0; - stptr--; - break; - case RRDRpn.OP.GT: - if(stptr < 1) throw RRDRpn.STACK_UNDERFLOW; - if (isNaN(this.rpnstack[stptr - 1])); - else if (isNaN(this.rpnstack[stptr])) - this.rpnstack[stptr - 1] = this.rpnstack[stptr]; - else - this.rpnstack[stptr - 1] = this.rpnstack[stptr - 1] > this.rpnstack[stptr] ? 1.0 : 0.0; - stptr--; - break; - case RRDRpn.OP.GE: - if(stptr < 1) throw RRDRpn.STACK_UNDERFLOW; - if (isNaN(this.rpnstack[stptr - 1])); - else if (isNaN(this.rpnstack[stptr])) - this.rpnstack[stptr - 1] = this.rpnstack[stptr]; - else - this.rpnstack[stptr - 1] = this.rpnstack[stptr - 1] >= this.rpnstack[stptr] ? 1.0 : 0.0; - stptr--; - break; - case RRDRpn.OP.NE: - if(stptr < 1) throw RRDRpn.STACK_UNDERFLOW; - if (isNaN(this.rpnstack[stptr - 1])); - else if (isNaN(this.rpnstack[stptr])) - this.rpnstack[stptr - 1] = this.rpnstack[stptr]; - else - this.rpnstack[stptr - 1] = this.rpnstack[stptr - 1] == this.rpnstack[stptr] ? 0.0 : 1.0; - stptr--; - break; - case RRDRpn.OP.EQ: - if(stptr < 1) throw RRDRpn.STACK_UNDERFLOW; - if (isNaN(this.rpnstack[stptr - 1])); - else if (isNaN(this.rpnstack[stptr])) - this.rpnstack[stptr - 1] = this.rpnstack[stptr]; - else - this.rpnstack[stptr - 1] = this.rpnstack[stptr - 1] == this.rpnstack[stptr] ? 1.0 : 0.0; - stptr--; - break; - case RRDRpn.OP.IF: - if(stptr < 2) throw RRDRpn.STACK_UNDERFLOW; - this.rpnstack[stptr - 2] = (isNaN(this.rpnstack[stptr - 2]) || this.rpnstack[stptr - 2] == 0.0) ? this.rpnstack[stptr] : this.rpnstack[stptr - 1]; - stptr--; - stptr--; - break; - case RRDRpn.OP.MIN: - if(stptr < 1) throw RRDRpn.STACK_UNDERFLOW; - if (isNaN(this.rpnstack[stptr - 1])); - else if (isNaN(this.rpnstack[stptr])) - this.rpnstack[stptr - 1] = this.rpnstack[stptr]; - else if (this.rpnstack[stptr - 1] > this.rpnstack[stptr]) - this.rpnstack[stptr - 1] = this.rpnstack[stptr]; - stptr--; - break; - case RRDRpn.OP.MAX: - if(stptr < 1) throw RRDRpn.STACK_UNDERFLOW; - if (isNaN(this.rpnstack[stptr - 1])); - else if (isNaN(this.rpnstack[stptr])) - this.rpnstack[stptr - 1] = this.rpnstack[stptr]; - else if (this.rpnstack[stptr - 1] < this.rpnstack[stptr]) - this.rpnstack[stptr - 1] = this.rpnstack[stptr]; - stptr--; - break; - case RRDRpn.OP.LIMIT: - if(stptr < 2) throw RRDRpn.STACK_UNDERFLOW; - if (isNaN(this.rpnstack[stptr - 2])); - else if (isNaN(this.rpnstack[stptr - 1])) - this.rpnstack[stptr - 2] = this.rpnstack[stptr - 1]; - else if (isNaN(this.rpnstack[stptr])) - this.rpnstack[stptr - 2] = this.rpnstack[stptr]; - else if (this.rpnstack[stptr - 2] < this.rpnstack[stptr - 1]) - this.rpnstack[stptr - 2] = Number.NaN; - else if (this.rpnstack[stptr - 2] > this.rpnstack[stptr]) - this.rpnstack[stptr - 2] = Number.NaN; - stptr -= 2; - break; - case RRDRpn.OP.UN: - if(stptr < 0) throw RRDRpn.STACK_UNDERFLOW; - this.rpnstack[stptr] = isNaN(this.rpnstack[stptr]) ? 1.0 : 0.0; - break; - case RRDRpn.OP.ISINF: - if(stptr < 0) throw RRDRpn.STACK_UNDERFLOW; - this.rpnstack[stptr] = isInfinite(this.rpnstack[stptr]) ? 1.0 : 0.0; - break; - case RRDRpn.OP.SQRT: - if(stptr < 0) throw RRDRpn.STACK_UNDERFLOW; - this.rpnstack[stptr] = Math.sqrt(this.rpnstack[stptr]); - break; - case RRDRpn.OP.SORT: - if(stptr < 0) throw RRDRpn.STACK_UNDERFLOW; - var spn = this.rpnstack[stptr--]; - if(stptr < spn - 1) throw RRDRpn.STACK_UNDERFLOW; - var array = this.rpnstack (stptr - spn + 1, stptr +1); - array.sort(this.rpn_compare_double); - for (var i=stptr - spn + 1, ii=0; i < (stptr +1) ; i++, ii++) - this.rpnstack[i] = array[ii]; - // qsort(this.rpnstack + stptr - spn + 1, spn, sizeof(double), rpn_compare_double); - break; - case RRDRpn.OP.REV: - if(stptr < 0) throw RRDRpn.STACK_UNDERFLOW; - var spn = this.rpnstack[stptr--]; - if(stptr < spn - 1) throw RRDRpn.STACK_UNDERFLOW; - var array = this.rpnstack (stptr - spn + 1, stptr +1); - array.reverse(); - for (var i=stptr - spn + 1, ii=0; i < (stptr +1) ; i++, ii++) - this.rpnstack[i] = array[ii]; -// var p, q; -// p = this.rpnstack + stptr - spn + 1; -// q = this.rpnstack + stptr; -// while (p < q) { -// var x = q; -// q-- = p; -// p++ = x; -// } - break; - case RRDRpn.OP.PREDICT: - case RRDRpn.OP.PREDICTSIGMA: - if(stptr < 2) throw RRDRpn.STACK_UNDERFLOW; - var locstepsize = this.rpnstack[--stptr]; - var shifts = this.rpnstack[--stptr]; - if(stptr < shifts) throw RRDRpn.STACK_UNDERFLOW; - if (shifts<0) stptr--; - else stptr-=shifts; - var val=Number.NaN; + } + break; + case RRDRpn.OP.COUNT: + this.rpnstack[++stptr] = (output_idx + 1); /* Note: Counter starts at 1 */ + break; + case RRDRpn.OP.PREV: + if ((output_idx) <= 0) this.rpnstack[++stptr] = Number.NaN; + else this.rpnstack[++stptr] = output[output_idx - 1]; + break; + case RRDRpn.OP.UNKN: + this.rpnstack[++stptr] = Number.NaN; + break; + case RRDRpn.OP.INF: + this.rpnstack[++stptr] = Infinity; + break; + case RRDRpn.OP.NEGINF: + this.rpnstack[++stptr] = -Infinity; + break; + case RRDRpn.OP.NOW: + this.rpnstack[++stptr] = Math.round((new Date()).getTime() / 1000); + break; + case RRDRpn.OP.TIME: + this.rpnstack[++stptr] = data_idx; + break; + case RRDRpn.OP.LTIME: + var date = new Date(data_idx*1000); // FIXME XXX + this.rpnstack[++stptr] = date.getTimezoneOffset() * 60 + data_idx; + break; + case RRDRpn.OP.ADD: + if(stptr < 1) throw RRDRpn.STACK_UNDERFLOW; + this.rpnstack[stptr - 1] = this.rpnstack[stptr - 1] + this.rpnstack[stptr]; + stptr--; + break; + case RRDRpn.OP.ADDNAN: + if(stptr < 1) throw RRDRpn.STACK_UNDERFLOW; + if (isNaN(this.rpnstack[stptr - 1])) { + this.rpnstack[stptr - 1] = this.rpnstack[stptr]; + } else if (isNaN(this.rpnstack[stptr])) { + /* NOOP */ + /* this.rpnstack[stptr - 1] = this.rpnstack[stptr - 1]; */ + } else { + this.rpnstack[stptr - 1] = this.rpnstack[stptr - 1] + this.rpnstack[stptr]; + } + stptr--; + break; + case RRDRpn.OP.SUB: + if(stptr < 1) throw RRDRpn.STACK_UNDERFLOW; + this.rpnstack[stptr - 1] = this.rpnstack[stptr - 1] - this.rpnstack[stptr]; + stptr--; + break; + case RRDRpn.OP.MUL: + if(stptr < 1) throw RRDRpn.STACK_UNDERFLOW; + this.rpnstack[stptr - 1] = (this.rpnstack[stptr - 1]) * (this.rpnstack[stptr]); + stptr--; + break; + case RRDRpn.OP.DIV: + if(stptr < 1) throw RRDRpn.STACK_UNDERFLOW; + this.rpnstack[stptr - 1] = this.rpnstack[stptr - 1] / this.rpnstack[stptr]; + stptr--; + break; + case RRDRpn.OP.MOD: + if(stptr < 1) throw RRDRpn.STACK_UNDERFLOW; + this.rpnstack[stptr - 1] = this.fmod(this.rpnstack[stptr - 1] , this.rpnstack[stptr]); + stptr--; + break; + case RRDRpn.OP.SIN: + if(stptr < 0) throw RRDRpn.STACK_UNDERFLOW; + this.rpnstack[stptr] = Math.sin(this.rpnstack[stptr]); + break; + case RRDRpn.OP.ATAN: + if(stptr < 0) throw RRDRpn.STACK_UNDERFLOW; + this.rpnstack[stptr] = Math.atan(this.rpnstack[stptr]); + break; + case RRDRpn.OP.RAD2DEG: + if(stptr < 0) throw RRDRpn.STACK_UNDERFLOW; + this.rpnstack[stptr] = 57.29577951 * this.rpnstack[stptr]; + break; + case RRDRpn.OP.DEG2RAD: + if(stptr < 0) throw RRDRpn.STACK_UNDERFLOW; + this.rpnstack[stptr] = 0.0174532952 * this.rpnstack[stptr]; + break; + case RRDRpn.OP.ATAN2: + if(stptr < 1) throw RRDRpn.STACK_UNDERFLOW; + this.rpnstack[stptr - 1] = Math.atan2(this.rpnstack[stptr - 1], this.rpnstack[stptr]); + stptr--; + break; + case RRDRpn.OP.COS: + if(stptr < 0) throw RRDRpn.STACK_UNDERFLOW; + this.rpnstack[stptr] = Math.cos(this.rpnstack[stptr]); + break; + case RRDRpn.OP.CEIL: + if(stptr < 0) throw RRDRpn.STACK_UNDERFLOW; + this.rpnstack[stptr] = Math.ceil(this.rpnstack[stptr]); + break; + case RRDRpn.OP.FLOOR: + if(stptr < 0) throw RRDRpn.STACK_UNDERFLOW; + this.rpnstack[stptr] = Math.floor(this.rpnstack[stptr]); + break; + case RRDRpn.OP.LOG: + if(stptr < 0) throw RRDRpn.STACK_UNDERFLOW; + this.rpnstack[stptr] = Math.log(this.rpnstack[stptr]); + break; + case RRDRpn.OP.DUP: + if(stptr < 0) throw RRDRpn.STACK_UNDERFLOW; + this.rpnstack[stptr + 1] = this.rpnstack[stptr]; + stptr++; + break; + case RRDRpn.OP.POP: + if(stptr < 0) throw RRDRpn.STACK_UNDERFLOW; + stptr--; + break; + case RRDRpn.OP.EXC: + if(stptr < 1) throw RRDRpn.STACK_UNDERFLOW; { + var dummy = this.rpnstack[stptr]; + this.rpnstack[stptr] = this.rpnstack[stptr - 1]; + this.rpnstack[stptr - 1] = dummy; + } + break; + case RRDRpn.OP.EXP: + if(stptr < 0) throw RRDRpn.STACK_UNDERFLOW; + this.rpnstack[stptr] = Math.exp(this.rpnstack[stptr]); + break; + case RRDRpn.OP.LT: + if(stptr < 1) throw RRDRpn.STACK_UNDERFLOW; + if (isNaN(this.rpnstack[stptr - 1])); + else if (isNaN(this.rpnstack[stptr])) + this.rpnstack[stptr - 1] = this.rpnstack[stptr]; + else + this.rpnstack[stptr - 1] = this.rpnstack[stptr - 1] < this.rpnstack[stptr] ? 1.0 : 0.0; + stptr--; + break; + case RRDRpn.OP.LE: + if(stptr < 1) throw RRDRpn.STACK_UNDERFLOW; + if (isNaN(this.rpnstack[stptr - 1])); + else if (isNaN(this.rpnstack[stptr])) + this.rpnstack[stptr - 1] = this.rpnstack[stptr]; + else + this.rpnstack[stptr - 1] = this.rpnstack[stptr - 1] <= this.rpnstack[stptr] ? 1.0 : 0.0; + stptr--; + break; + case RRDRpn.OP.GT: + if(stptr < 1) throw RRDRpn.STACK_UNDERFLOW; + if (isNaN(this.rpnstack[stptr - 1])); + else if (isNaN(this.rpnstack[stptr])) + this.rpnstack[stptr - 1] = this.rpnstack[stptr]; + else + this.rpnstack[stptr - 1] = this.rpnstack[stptr - 1] > this.rpnstack[stptr] ? 1.0 : 0.0; + stptr--; + break; + case RRDRpn.OP.GE: + if(stptr < 1) throw RRDRpn.STACK_UNDERFLOW; + if (isNaN(this.rpnstack[stptr - 1])); + else if (isNaN(this.rpnstack[stptr])) + this.rpnstack[stptr - 1] = this.rpnstack[stptr]; + else + this.rpnstack[stptr - 1] = this.rpnstack[stptr - 1] >= this.rpnstack[stptr] ? 1.0 : 0.0; + stptr--; + break; + case RRDRpn.OP.NE: + if(stptr < 1) throw RRDRpn.STACK_UNDERFLOW; + if (isNaN(this.rpnstack[stptr - 1])); + else if (isNaN(this.rpnstack[stptr])) + this.rpnstack[stptr - 1] = this.rpnstack[stptr]; + else + this.rpnstack[stptr - 1] = this.rpnstack[stptr - 1] == this.rpnstack[stptr] ? 0.0 : 1.0; + stptr--; + break; + case RRDRpn.OP.EQ: + if(stptr < 1) throw RRDRpn.STACK_UNDERFLOW; + if (isNaN(this.rpnstack[stptr - 1])); + else if (isNaN(this.rpnstack[stptr])) + this.rpnstack[stptr - 1] = this.rpnstack[stptr]; + else + this.rpnstack[stptr - 1] = this.rpnstack[stptr - 1] == this.rpnstack[stptr] ? 1.0 : 0.0; + stptr--; + break; + case RRDRpn.OP.IF: + if(stptr < 2) throw RRDRpn.STACK_UNDERFLOW; + this.rpnstack[stptr - 2] = (isNaN(this.rpnstack[stptr - 2]) || this.rpnstack[stptr - 2] == 0.0) ? this.rpnstack[stptr] : this.rpnstack[stptr - 1]; + stptr--; + stptr--; + break; + case RRDRpn.OP.MIN: + if(stptr < 1) throw RRDRpn.STACK_UNDERFLOW; + if (isNaN(this.rpnstack[stptr - 1])); + else if (isNaN(this.rpnstack[stptr])) + this.rpnstack[stptr - 1] = this.rpnstack[stptr]; + else if (this.rpnstack[stptr - 1] > this.rpnstack[stptr]) + this.rpnstack[stptr - 1] = this.rpnstack[stptr]; + stptr--; + break; + case RRDRpn.OP.MAX: + if(stptr < 1) throw RRDRpn.STACK_UNDERFLOW; + if (isNaN(this.rpnstack[stptr - 1])); + else if (isNaN(this.rpnstack[stptr])) + this.rpnstack[stptr - 1] = this.rpnstack[stptr]; + else if (this.rpnstack[stptr - 1] < this.rpnstack[stptr]) + this.rpnstack[stptr - 1] = this.rpnstack[stptr]; + stptr--; + break; + case RRDRpn.OP.LIMIT: + if(stptr < 2) { + throw RRDRpn.STACK_UNDERFLOW; + }; + if (isNaN(this.rpnstack[stptr - 2])) { + } else if (isNaN(this.rpnstack[stptr - 1])) { + this.rpnstack[stptr - 2] = this.rpnstack[stptr - 1]; + } else if (isNaN(this.rpnstack[stptr])) { + this.rpnstack[stptr - 2] = this.rpnstack[stptr]; + } else if ( + this.rpnstack[stptr - 2] < this.rpnstack[stptr - 1]) { + this.rpnstack[stptr - 2] = Number.NaN; + } else if (this.rpnstack[stptr - 2] > this.rpnstack[stptr]) { + this.rpnstack[stptr - 2] = Number.NaN; + } + stptr -= 2; + break; + case RRDRpn.OP.UN: + if(stptr < 0) throw RRDRpn.STACK_UNDERFLOW; + this.rpnstack[stptr] = isNaN(this.rpnstack[stptr]) ? 1.0 : 0.0; + break; + case RRDRpn.OP.ISINF: + if(stptr < 0) throw RRDRpn.STACK_UNDERFLOW; + this.rpnstack[stptr] = isInfinite(this.rpnstack[stptr]) ? 1.0 : 0.0; + break; + case RRDRpn.OP.SQRT: + if(stptr < 0) throw RRDRpn.STACK_UNDERFLOW; + this.rpnstack[stptr] = Math.sqrt(this.rpnstack[stptr]); + break; + case RRDRpn.OP.SORT: + if(stptr < 0) throw RRDRpn.STACK_UNDERFLOW; + var spn = this.rpnstack[stptr--]; + if(stptr < spn - 1) throw RRDRpn.STACK_UNDERFLOW; + var array = this.rpnstack (stptr - spn + 1, stptr +1); + array.sort(this.rpn_compare_double); + for (var i=stptr - spn + 1, ii=0; i < (stptr +1) ; i++, ii++) + this.rpnstack[i] = array[ii]; + // qsort(this.rpnstack + stptr - spn + 1, spn, sizeof(double), rpn_compare_double); + break; + case RRDRpn.OP.REV: + if(stptr < 0) throw RRDRpn.STACK_UNDERFLOW; + var spn = this.rpnstack[stptr--]; + if(stptr < spn - 1) throw RRDRpn.STACK_UNDERFLOW; + var array = this.rpnstack (stptr - spn + 1, stptr +1); + array.reverse(); + for (var i=stptr - spn + 1, ii=0; i < (stptr +1) ; i++, ii++) + this.rpnstack[i] = array[ii]; + // var p, q; + // p = this.rpnstack + stptr - spn + 1; + // q = this.rpnstack + stptr; + // while (p < q) { + // var x = q; + // q-- = p; + // p++ = x; + // } + break; + case RRDRpn.OP.PREDICT: + case RRDRpn.OP.PREDICTSIGMA: + if(stptr < 2) throw RRDRpn.STACK_UNDERFLOW; + var locstepsize = this.rpnstack[--stptr]; + var shifts = this.rpnstack[--stptr]; + if(stptr < shifts) throw RRDRpn.STACK_UNDERFLOW; + if (shifts<0) stptr--; + else stptr-=shifts; + var val=Number.NaN; var dsstep = this.rpnp[rpi - 1].step; - var dscount = this.rpnp[rpi - 1].ds_cnt; - var locstep = Math.ceil(locstepsize/dsstep); - var sum = 0; - var sum2 = 0; - var count = 0; - /* now loop for each position */ - var doshifts=shifts; - if (shifts<0) doshifts=-shifts; - for(var loop=0;loop=0)&&(offset=0)&&(offset0) val = sum/count; - } else { - if (count>1) { - val=count*sum2-sum*sum; - if (val<0) { - val=Number.NaN; - } else { - val=Math.sqrt(val/(count*(count-1.0))); - } + } + val=Number.NaN; + if (this.rpnp[rpi].op == RRDRpn.OP.PREDICT) { + if (count>0) val = sum/count; + } else { + if (count>1) { + val=count*sum2-sum*sum; + if (val<0) { + val=Number.NaN; + } else { + val=Math.sqrt(val/(count*(count-1.0))); } } - this.rpnstack[stptr] = val; - break; - case RRDRpn.OP.TREND: - case RRDRpn.OP.TRENDNAN: - if(stptr < 1) throw RRDRpn.STACK_UNDERFLOW; - if ((rpi < 2) || (this.rpnp[rpi - 2].op != RRDRpn.OP.VARIABLE)) { - throw "malformed trend arguments"; - } else { - var dur = this.rpnstack[stptr]; - var step = this.rpnp[rpi - 2].step; + } + this.rpnstack[stptr] = val; + break; + case RRDRpn.OP.TREND: + case RRDRpn.OP.TRENDNAN: + if(stptr < 1) throw RRDRpn.STACK_UNDERFLOW; + if ((rpi < 2) || (this.rpnp[rpi - 2].op != RRDRpn.OP.VARIABLE)) { + throw "malformed trend arguments"; + } else { + var dur = this.rpnstack[stptr]; + var step = this.rpnp[rpi - 2].step; - if (output_idx > Math.ceil(dur / step)) { - var ignorenan = (this.rpnp[rpi].op == RRDRpn.OP.TREND); - var accum = 0.0; - var i = 0; - var count = 0; + if (output_idx > Math.ceil(dur / step)) { + var ignorenan = (this.rpnp[rpi].op == RRDRpn.OP.TREND); + var accum = 0.0; + var i = 0; + var count = 0; do { var val = this.rpnp[rpi - 2].data[this.rpnp[rpi - 2].ds_cnt * i--]; @@ -1117,33 +1121,33 @@ RRDRpn.prototype = { dur -= step; } while (dur > 0); - this.rpnstack[--stptr] = (count == 0) ? Number.NaN : (accum / count); - } else this.rpnstack[--stptr] = Number.NaN; - } - break; - case RRDRpn.OP.AVG: - if(stptr < 0) throw RRDRpn.STACK_UNDERFLOW; - var i = this.rpnstack[stptr--]; - var sum = 0; - var count = 0; - - if(stptr < i - 1) throw RRDRpn.STACK_UNDERFLOW; - while (i > 0) { - var val = this.rpnstack[stptr--]; - i--; - if (isNaN(val)) continue; - count++; - sum += val; - } - if (count > 0) this.rpnstack[++stptr] = sum / count; - else this.rpnstack[++stptr] = Number.NaN; - break; - case RRDRpn.OP.ABS: - if(stptr < 0) throw RRDRpn.STACK_UNDERFLOW; - this.rpnstack[stptr] = fabs(this.rpnstack[stptr]); - break; - case RRDRpn.OP.END: - break; + this.rpnstack[--stptr] = (count == 0) ? Number.NaN : (accum / count); + } else this.rpnstack[--stptr] = Number.NaN; + } + break; + case RRDRpn.OP.AVG: + if(stptr < 0) throw RRDRpn.STACK_UNDERFLOW; + var i = this.rpnstack[stptr--]; + var sum = 0; + var count = 0; + + if(stptr < i - 1) throw RRDRpn.STACK_UNDERFLOW; + while (i > 0) { + var val = this.rpnstack[stptr--]; + i--; + if (isNaN(val)) continue; + count++; + sum += val; + } + if (count > 0) this.rpnstack[++stptr] = sum / count; + else this.rpnstack[++stptr] = Number.NaN; + break; + case RRDRpn.OP.ABS: + if(stptr < 0) throw RRDRpn.STACK_UNDERFLOW; + this.rpnstack[stptr] = fabs(this.rpnstack[stptr]); + break; + case RRDRpn.OP.END: + break; } } if (stptr != 0) throw "RPN final stack size != 1"; @@ -3178,7 +3182,7 @@ RRDGraph.prototype = { if (mid < 4 && exfrac === 1) { /* minor grid */ if (flab === 0) { /* find first and last minor line behind current major line * i is the first line and j tha last */ min_exp = val_exp - 1; - for (i = 1; yloglab[mid][i] < 10.0; i++); + for (i = 1; yloglab[mid][i] < 10.0; i++) {}; i = yloglab[mid][i - 1] + 1; j = 10; } else { @@ -3214,7 +3218,7 @@ RRDGraph.prototype = { if (mid < 4 && exfrac === 1) { /* draw minor lines after highest major line */ if (flab === 0) { /* find first and last minor line below current major line * i is the first line and j tha last */ min_exp = val_exp - 1; - for (i = 1; yloglab[mid][i] < 10.0; i++); + for (i = 1; yloglab[mid][i] < 10.0; i++) {}; i = yloglab[mid][i - 1] + 1; j = 10; } else { -- cgit v1.2.3-2-g168b