diff options
Diffstat (limited to 'js')
-rw-r--r-- | js/RrdCmdLine.js | 189 |
1 files changed, 92 insertions, 97 deletions
diff --git a/js/RrdCmdLine.js b/js/RrdCmdLine.js index fea0753..ab2910f 100644 --- a/js/RrdCmdLine.js +++ b/js/RrdCmdLine.js | |||
@@ -72,43 +72,30 @@ RrdCmdLine.prototype = { | |||
72 | this.parse_textaling(arg); | 72 | this.parse_textaling(arg); |
73 | } else if (/^SHIFT:/.test(arg)) { | 73 | } else if (/^SHIFT:/.test(arg)) { |
74 | this.parse_shift(arg); | 74 | this.parse_shift(arg); |
75 | } else if (arg.charAt(0) === '-') { | 75 | } else if (arg.charAt(0) === '-') { |
76 | var strip = 1; | 76 | var strip = 1; |
77 | if (arg.length > 1 && arg.charAt(1) === '-') { | 77 | if (arg.length > 1 && arg.charAt(1) === '-') { |
78 | strip = 2; | 78 | strip = 2; |
79 | } | 79 | } |
80 | var option = arg.substr(strip); | 80 | var option = arg.substr(strip); |
81 | var value = undefined; | 81 | /* try to parse a flag, otherwise assume --option=value */ |
82 | 82 | if (!this.set_flag(option)) { | |
83 | if (option.indexOf('=') !== -1) { | 83 | var value; |
84 | var index = option.indexOf('='); | 84 | if (option.indexOf('=') !== -1) { |
85 | value = option.substr(index+1); | 85 | var index = option.indexOf('='); |
86 | option = option.substr(0,index); | 86 | value = option.substr(index + 1); |
87 | } else if (i+1 < len) { | 87 | option = option.substr(0, index); |
88 | if (lines[i+1].charAt(0) !== '-' && | 88 | } else if (i + 1 < len) { |
89 | !/^"?LINE[0-9.]+:/.test(lines[i+1]) && | 89 | ++i; |
90 | !/^"?AREA:/.test(lines[i+1]) && | ||
91 | !/^"?DEF:/.test(lines[i+1]) && | ||
92 | !/^"?CDEF:/.test(lines[i+1]) && | ||
93 | !/^"?VDEF:/.test(lines[i+1]) && | ||
94 | !/^"?GPRINT:/.test(lines[i+1]) && | ||
95 | !/^"?COMMENT:/.test(lines[i+1]) && | ||
96 | !/^"?HRULE:/.test(lines[i+1]) && | ||
97 | !/^"?VRULE:/.test(lines[i+1]) && | ||
98 | !/^"?TICK:/.test(lines[i+1]) && | ||
99 | !/^"?TEXTALING:/.test(lines[i+1]) && | ||
100 | !/^"?SHIFT:/.test(lines[i+1]) | ||
101 | ) { | ||
102 | i++; | ||
103 | if (lines[i].charAt(0) === '"' && lines[i].charAt(lines[i].length-1) === '"') | 90 | if (lines[i].charAt(0) === '"' && lines[i].charAt(lines[i].length-1) === '"') |
104 | value = lines[i].substr(1,lines[i].length-2); | 91 | value = lines[i].substr(1,lines[i].length-2); |
105 | else | 92 | else |
106 | value = lines[i]; | 93 | value = lines[i]; |
107 | } | 94 | } |
95 | this.set_option(option, value); | ||
108 | } | 96 | } |
109 | this.set_option(option, value); | ||
110 | } else { | 97 | } else { |
111 | throw "Unknow argument: "+arg; | 98 | throw "Unknown argument: "+arg; |
112 | } | 99 | } |
113 | i++; | 100 | i++; |
114 | } | 101 | } |
@@ -116,13 +103,88 @@ RrdCmdLine.prototype = { | |||
116 | this.graph.start = start_end[0]; | 103 | this.graph.start = start_end[0]; |
117 | this.graph.end = start_end[1]; | 104 | this.graph.end = start_end[1]; |
118 | }, | 105 | }, |
119 | set_option: function(option, value) | 106 | /** Returns true when the option is a flag that got consumed. */ |
120 | { | 107 | set_flag: function(option) { |
121 | switch(option) { | 108 | switch (option) { |
122 | case 'alt-autoscale': | 109 | case 'alt-autoscale': |
123 | case 'A': | 110 | case 'A': |
124 | this.graph.alt_autoscale = true; | 111 | this.graph.alt_autoscale = true; |
125 | break; | 112 | return true; |
113 | case 'full-size-mode': | ||
114 | case 'D': | ||
115 | this.graph.full_size_mode = true; | ||
116 | return true; | ||
117 | case 'slope-mode': | ||
118 | case 'E': | ||
119 | this.graph.slopemode = true; | ||
120 | return true; | ||
121 | case 'force-rules-legend': | ||
122 | case 'F': | ||
123 | this.graph.force_rules_legend = true; | ||
124 | return true; | ||
125 | case 'no-legend': | ||
126 | case 'g': | ||
127 | this.graph.no_legend = true; | ||
128 | return true; | ||
129 | case 'no-minor': | ||
130 | case 'I': | ||
131 | this.graph.no_minor = false; | ||
132 | return true; | ||
133 | case 'interlaced': | ||
134 | case 'i': | ||
135 | return true; | ||
136 | case 'alt-autoscale-min': | ||
137 | case 'J': | ||
138 | this.graph.alt_autoscale_min = true; | ||
139 | return true; | ||
140 | case 'only-graph': | ||
141 | case 'j': | ||
142 | this.graph.only_graph = true; | ||
143 | return true; | ||
144 | case 'alt-autoscale-max': | ||
145 | case 'M': | ||
146 | this.graph.alt_autoscale_max = true; | ||
147 | return true; | ||
148 | case 'no-gridfit': | ||
149 | case 'N': | ||
150 | this.graph.gridfit = true; | ||
151 | return true; | ||
152 | case 'logarithmic': | ||
153 | case 'o': | ||
154 | this.graph.logarithmic = true; | ||
155 | return true; | ||
156 | case 'pango-markup': | ||
157 | case 'P': | ||
158 | // im->with_markup = 1; | ||
159 | return true; | ||
160 | case 'rigid': | ||
161 | case 'r': | ||
162 | this.graph.rigid = true; | ||
163 | return true; | ||
164 | case 'alt-y-grid': | ||
165 | case 'Y': | ||
166 | this.graph.alt_ygrid = true; | ||
167 | return true; | ||
168 | case 'lazy': | ||
169 | case 'z': | ||
170 | this.graph.lazy = true; | ||
171 | return true; | ||
172 | case 'alt-y-mrtg': | ||
173 | return true; | ||
174 | case 'disable-rrdtool-tag': | ||
175 | this.graph.no_rrdtool_tag = true; | ||
176 | return true; | ||
177 | case 'dynamic-labels': | ||
178 | this.graph.dynamic_labels = true; | ||
179 | return true; | ||
180 | default: | ||
181 | /* unrecognized flag, maybe it is an option? */ | ||
182 | return false; | ||
183 | } | ||
184 | }, | ||
185 | set_option: function(option, value) | ||
186 | { | ||
187 | switch(option) { | ||
126 | case 'base': | 188 | case 'base': |
127 | case 'b': | 189 | case 'b': |
128 | this.graph.base = parseInt(value, 10); | 190 | this.graph.base = parseInt(value, 10); |
@@ -139,23 +201,11 @@ RrdCmdLine.prototype = { | |||
139 | throw "invalid color name '"+name+"'" | 201 | throw "invalid color name '"+name+"'" |
140 | this.graph.GRC[name] = value.substr(index); // FIXME check color | 202 | this.graph.GRC[name] = value.substr(index); // FIXME check color |
141 | break; | 203 | break; |
142 | case 'full-size-mode': | ||
143 | case 'D': | ||
144 | this.graph.full_size_mode = true; | ||
145 | break; | ||
146 | case 'slope-mode': | ||
147 | case 'E': | ||
148 | this.graph.slopemode = true; | ||
149 | break; | ||
150 | case 'end': | 204 | case 'end': |
151 | case 'e': | 205 | case 'e': |
152 | this.graph.end_t = new RrdTime(value); | 206 | this.graph.end_t = new RrdTime(value); |
153 | // this.graph.end = parseInt(value, 10); | 207 | // this.graph.end = parseInt(value, 10); |
154 | break; | 208 | break; |
155 | case 'force-rules-legend': | ||
156 | case 'F': | ||
157 | this.graph.force_rules_legend = true; | ||
158 | break; | ||
159 | case 'imginfo': | 209 | case 'imginfo': |
160 | case 'f': | 210 | case 'f': |
161 | // im->imginfo = optarg; | 211 | // im->imginfo = optarg; |
@@ -164,29 +214,10 @@ RrdCmdLine.prototype = { | |||
164 | case 'G': | 214 | case 'G': |
165 | // im->graph_antialias | 215 | // im->graph_antialias |
166 | break; | 216 | break; |
167 | case 'no-legend': | ||
168 | case 'g': | ||
169 | this.graph.no_legend = true; | ||
170 | break; | ||
171 | case 'height': | 217 | case 'height': |
172 | case 'h': | 218 | case 'h': |
173 | this.graph.ysize = parseInt(value, 10); | 219 | this.graph.ysize = parseInt(value, 10); |
174 | break; | 220 | break; |
175 | case 'no-minor': | ||
176 | case 'I': | ||
177 | this.graph.no_minor = false; | ||
178 | break; | ||
179 | case 'interlaced': | ||
180 | case 'i': | ||
181 | break; | ||
182 | case 'alt-autoscale-min': | ||
183 | case 'J': | ||
184 | this.graph.alt_autoscale_min = true; | ||
185 | break; | ||
186 | case 'only-graph': | ||
187 | case 'j': | ||
188 | this.graph.only_graph = true; | ||
189 | break; | ||
190 | case 'units-length': | 221 | case 'units-length': |
191 | case 'L': | 222 | case 'L': |
192 | this.graph.unitslength = parseInt(value, 10); | 223 | this.graph.unitslength = parseInt(value, 10); |
@@ -196,20 +227,12 @@ RrdCmdLine.prototype = { | |||
196 | case 'l': | 227 | case 'l': |
197 | this.graph.setminval = parseFloat(value) | 228 | this.graph.setminval = parseFloat(value) |
198 | break; | 229 | break; |
199 | case 'alt-autoscale-max': | ||
200 | case 'M': | ||
201 | this.graph.alt_autoscale_max = true; | ||
202 | break; | ||
203 | case 'zoom': | 230 | case 'zoom': |
204 | case 'm': | 231 | case 'm': |
205 | this.graph.zoom = parseFloat(value); | 232 | this.graph.zoom = parseFloat(value); |
206 | if (this.graph.zoom <= 0.0) | 233 | if (this.graph.zoom <= 0.0) |
207 | throw "zoom factor must be > 0"; | 234 | throw "zoom factor must be > 0"; |
208 | break; | 235 | break; |
209 | case 'no-gridfit': | ||
210 | case 'N': | ||
211 | this.graph.gridfit = true; | ||
212 | break; | ||
213 | case 'font': | 236 | case 'font': |
214 | case 'n': | 237 | case 'n': |
215 | var args = value.split(':'); | 238 | var args = value.split(':'); |
@@ -222,22 +245,10 @@ RrdCmdLine.prototype = { | |||
222 | if (args[2]) | 245 | if (args[2]) |
223 | this.graph.TEXT[args[0]].font = args[2]; | 246 | this.graph.TEXT[args[0]].font = args[2]; |
224 | break; | 247 | break; |
225 | case 'logarithmic': | ||
226 | case 'o': | ||
227 | this.graph.logarithmic = true; | ||
228 | break; | ||
229 | case 'pango-markup': | ||
230 | case 'P': | ||
231 | // im->with_markup = 1; | ||
232 | break; | ||
233 | case 'font-render-mode': | 248 | case 'font-render-mode': |
234 | case 'R': | 249 | case 'R': |
235 | // im->font_options: normal light mono | 250 | // im->font_options: normal light mono |
236 | break; | 251 | break; |
237 | case 'rigid': | ||
238 | case 'r': | ||
239 | this.graph.rigid = true; | ||
240 | break; | ||
241 | case 'step': | 252 | case 'step': |
242 | this.graph.step = parseInt(value, 10); | 253 | this.graph.step = parseInt(value, 10); |
243 | break; | 254 | break; |
@@ -302,10 +313,6 @@ RrdCmdLine.prototype = { | |||
302 | this.graph.xlab_user.stst = this.graph.xlab_form; | 313 | this.graph.xlab_user.stst = this.graph.xlab_form; |
303 | } | 314 | } |
304 | break; | 315 | break; |
305 | case 'alt-y-grid': | ||
306 | case 'Y': | ||
307 | this.graph.alt_ygrid = true; | ||
308 | break; | ||
309 | case 'y-grid': | 316 | case 'y-grid': |
310 | case 'y': | 317 | case 'y': |
311 | if (value === 'none') { | 318 | if (value === 'none') { |
@@ -322,10 +329,6 @@ RrdCmdLine.prototype = { | |||
322 | throw "label factor must be > 0"; | 329 | throw "label factor must be > 0"; |
323 | } | 330 | } |
324 | break; | 331 | break; |
325 | case 'lazy': | ||
326 | case 'z': | ||
327 | this.graph.lazy = 1; | ||
328 | break; | ||
329 | case 'units': | 332 | case 'units': |
330 | if (this.graph.force_units) | 333 | if (this.graph.force_units) |
331 | throw "--units can only be used once!"; | 334 | throw "--units can only be used once!"; |
@@ -334,11 +337,6 @@ RrdCmdLine.prototype = { | |||
334 | else | 337 | else |
335 | throw "invalid argument for --units: "+value; | 338 | throw "invalid argument for --units: "+value; |
336 | break; | 339 | break; |
337 | case 'alt-y-mrtg': | ||
338 | break; | ||
339 | case 'disable-rrdtool-tag': | ||
340 | this.graph.no_rrdtool_tag = true; | ||
341 | break; | ||
342 | case 'right-axis': | 340 | case 'right-axis': |
343 | var index = value.indexOf(':'); | 341 | var index = value.indexOf(':'); |
344 | if (index === -1) | 342 | if (index === -1) |
@@ -386,11 +384,8 @@ RrdCmdLine.prototype = { | |||
386 | this.graph.grid_dash_on = parseFloat(value.substr(0,index)); | 384 | this.graph.grid_dash_on = parseFloat(value.substr(0,index)); |
387 | this.graph.grid_dash_off = parseFloat(value.substr(index+1)); | 385 | this.graph.grid_dash_off = parseFloat(value.substr(index+1)); |
388 | break; | 386 | break; |
389 | case 'dynamic-labels': | ||
390 | this.graph.dynamic_labels = true; | ||
391 | break; | ||
392 | default: | 387 | default: |
393 | throw 'Unknow option "'+option+'"'; | 388 | throw 'Unknown option "'+option+'"'; |
394 | } | 389 | } |
395 | 390 | ||
396 | }, | 391 | }, |