From 937416fa325cfdd1eb9782281a37c2b44ce8a522 Mon Sep 17 00:00:00 2001 From: Manuel Luis SanmartĂ­n Rozada Date: Fri, 3 Apr 2015 16:47:54 +0200 Subject: jsrrdgraph: Rewrite data a graph commands parser. --- js/RrdCmdLine.js | 426 ++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 344 insertions(+), 82 deletions(-) (limited to 'js') diff --git a/js/RrdCmdLine.js b/js/RrdCmdLine.js index 581e2f0..094596f 100644 --- a/js/RrdCmdLine.js +++ b/js/RrdCmdLine.js @@ -25,7 +25,6 @@ * @constructor */ var RrdCmdLine = function() { - // if (arguments.lenght === 3) // XXX this.init.apply(this, arguments); }; @@ -37,7 +36,7 @@ RrdCmdLine.prototype = { this.graph = new RrdGraph(gfx, fetch); this.cmdline(line); }, - cmdline: function(line) // FIXME + cmdline: function(line) { var i = 0; line = line.replace(/\n/g," "); @@ -48,30 +47,30 @@ RrdCmdLine.prototype = { var arg = lines[i]; if (arg.charAt(0) === '"' && arg.charAt(arg.length-1) === '"') arg = arg.substr(1,arg.length-2); - if (/^LINE[0-9.]+:/.test(arg)) { - this.parse_line(arg); - } else if (/^AREA:/.test(arg)) { - this.parse_area(arg); - } else if (/^DEF:/.test(arg)) { - this.parse_def(arg); - } else if (/^CDEF:/.test(arg)) { - this.parse_cdef(arg); - } else if (/^VDEF:/.test(arg)) { - this.parse_vdef(arg); - } else if (/^GPRINT:/.test(arg)) { - this.parse_gprint(arg); - } else if (/^COMMENT:/.test(arg)) { - this.parse_comment(arg); - } else if (/^VRULE:/.test(arg)) { - this.parse_vrule(arg); - } else if (/^HRULE:/.test(arg)) { - this.parse_hrule(arg); - } else if (/^TICK:/.test(arg)) { - this.parse_tick(arg); - } else if (/^TEXTALIGN:/.test(arg)) { - this.parse_textalign(arg); - } else if (/^SHIFT:/.test(arg)) { - this.parse_shift(arg); + if (arg.substring(0,4) === 'LINE') { + this.parse_line(this.split(arg)); + } else if (arg.substring(0,5) === 'AREA:') { + this.parse_area(this.split(arg)); + } else if (arg.substring(0,4) === 'DEF:') { + this.parse_def(this.split(arg)); + } else if (arg.substring(0,5) === 'CDEF:') { + this.parse_cdef(this.split(arg)); + } else if (arg.substring(0,5) === 'VDEF:') { + this.parse_vdef(this.split(arg)); + } else if (arg.substring(0,7) === 'GPRINT:') { + this.parse_gprint(this.split(arg)); + } else if (arg.substring(0,8) === 'COMMENT:') { + this.parse_comment(this.split(arg)); + } else if (arg.substring(0,6) === 'VRULE:') { + this.parse_vrule(this.split(arg)); + } else if (arg.substring(0,6) === 'HRULE:') { + this.parse_hrule(this.split(arg)); + } else if (arg.substring(0,5) === 'TICK:') { + this.parse_tick(this.split(arg)); + } else if (arg.substring(0,10) === 'TEXTALIGN:') { + this.parse_textalign(this.split(arg)); + } else if (arg.substring(0,7) === 'SHIFT:') { + this.parse_shift(this.split(arg)); } else if (arg.charAt(0) === '-') { var strip = 1; if (arg.length > 1 && arg.charAt(1) === '-') { @@ -99,7 +98,7 @@ RrdCmdLine.prototype = { } i++; } - var start_end = RrdTime.proc_start_end(this.graph.start_t, this.graph.end_t); // FIXME here? + var start_end = RrdTime.proc_start_end(this.graph.start_t, this.graph.end_t); this.graph.start = start_end[0]; this.graph.end = start_end[1]; }, @@ -387,79 +386,249 @@ RrdCmdLine.prototype = { } }, + split: function (line) + { + return line.replace(/:/g,'\0').replace(/\\\0/g,':').split('\0'); + }, // DEF:=::[:step=][:start=