diff options
| author | Vincent Brillault | 2013-12-16 21:51:41 +0100 |
|---|---|---|
| committer | Pim van den Berg | 2014-01-12 14:35:02 +0100 |
| commit | 8ea83b0bc5ce2a2d58c8836cc7f293dc3744b3f0 (patch) | |
| tree | 33a2377871df90667a00e4563547e6cc63262341 | |
| parent | jsrrdgraph: RrdDataFile.js: Add async function (fetch_async) to RrdDataFile (diff) | |
| download | apt-panopticon_cgp-8ea83b0bc5ce2a2d58c8836cc7f293dc3744b3f0.zip apt-panopticon_cgp-8ea83b0bc5ce2a2d58c8836cc7f293dc3744b3f0.tar.gz apt-panopticon_cgp-8ea83b0bc5ce2a2d58c8836cc7f293dc3744b3f0.tar.bz2 apt-panopticon_cgp-8ea83b0bc5ce2a2d58c8836cc7f293dc3744b3f0.tar.xz | |
jsrrdgraph: RrdGraph.js: Add RrdGraph.prototype.graph_paint_async method
| -rw-r--r-- | js/RrdGraph.js | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/js/RrdGraph.js b/js/RrdGraph.js index 235b35f..8794888 100644 --- a/js/RrdGraph.js +++ b/js/RrdGraph.js | |||
| @@ -705,6 +705,7 @@ var RrdGraph = function (gfx, data) | |||
| 705 | { | 705 | { |
| 706 | this.gfx = gfx; /* graphics object */ | 706 | this.gfx = gfx; /* graphics object */ |
| 707 | this.data = data; /* fetch data object */ | 707 | this.data = data; /* fetch data object */ |
| 708 | this.data_need_fetch = [] /* List of data that need to be fetched */ | ||
| 708 | 709 | ||
| 709 | this.minval = Number.NaN; /* extreme values in the data */ | 710 | this.minval = Number.NaN; /* extreme values in the data */ |
| 710 | this.maxval = Number.NaN; | 711 | this.maxval = Number.NaN; |
| @@ -1318,6 +1319,92 @@ RrdGraph.prototype.reduce_data = function(gdes, cur_step) | |||
| 1318 | } | 1319 | } |
| 1319 | }; | 1320 | }; |
| 1320 | 1321 | ||
| 1322 | RrdGraph.prototype.data_fetch_async_callback = function (args, ft_step) | ||
| 1323 | { | ||
| 1324 | var j, that; | ||
| 1325 | |||
| 1326 | j = args.j; | ||
| 1327 | that = args.this; | ||
| 1328 | |||
| 1329 | if (ft_step < 0) | ||
| 1330 | return -1; | ||
| 1331 | that.gdes[j].data_first = 1; | ||
| 1332 | // that.gdes[j].step = Math.max(that.gdes[j].step, that.step); // FIXME | ||
| 1333 | if (ft_step < that.gdes[j].step) { | ||
| 1334 | that.reduce_data(that.gdes[j], ft_step); | ||
| 1335 | } else { | ||
| 1336 | that.gdes[j].step = ft_step; | ||
| 1337 | } | ||
| 1338 | that.data_need_fetch[j] = 1; | ||
| 1339 | |||
| 1340 | for (var i = 0, gdes_c = that.gdes.length; i < gdes_c; i++) { | ||
| 1341 | if (that.data_need_fetch[i] == j + 2) { | ||
| 1342 | that.gdes[i].start = that.gdes[j].start; | ||
| 1343 | that.gdes[i].end = that.gdes[j].end; | ||
| 1344 | that.gdes[i].step = that.gdes[j].step; | ||
| 1345 | that.gdes[i].ds_cnt = that.gdes[j].ds_cnt; | ||
| 1346 | that.gdes[i].ds_namv = that.gdes[j].ds_namv; | ||
| 1347 | that.gdes[i].data = that.gdes[j].data; | ||
| 1348 | that.gdes[i].data_first = 0; | ||
| 1349 | that.data_need_fetch[i] = 1; | ||
| 1350 | } | ||
| 1351 | } | ||
| 1352 | |||
| 1353 | for (var i = 0, gdes_c = that.gdes.length; i < gdes_c; i++) { | ||
| 1354 | if (that.data_need_fetch[i] < 0) continue; | ||
| 1355 | if (that.data_need_fetch[i] == 1) continue; | ||
| 1356 | return; | ||
| 1357 | } | ||
| 1358 | |||
| 1359 | for (var i = 0, gdes_c = that.gdes.length; i < gdes_c; i++) { | ||
| 1360 | if (that.gdes[i].gf != RrdGraphDesc.GF_DEF) continue; | ||
| 1361 | |||
| 1362 | /* lets see if the required data source is really there */ | ||
| 1363 | for (var ii = 0; ii < that.gdes[i].ds_cnt; ii++) { | ||
| 1364 | if (that.gdes[i].ds_namv[ii] === that.gdes[i].ds_nam) { | ||
| 1365 | that.gdes[i].ds = ii; | ||
| 1366 | break; | ||
| 1367 | } | ||
| 1368 | } | ||
| 1369 | |||
| 1370 | if (that.gdes[i].ds === -1) { | ||
| 1371 | alert("No DS called '"+that.gdes[i].ds_nam+"' in '"+that.gdes[i].rrd+"'"); | ||
| 1372 | return; | ||
| 1373 | } | ||
| 1374 | } | ||
| 1375 | that.graph_paint_draw(); | ||
| 1376 | }; | ||
| 1377 | |||
| 1378 | RrdGraph.prototype.data_fetch_async = function () | ||
| 1379 | { | ||
| 1380 | for (var i = 0, gdes_c = this.gdes.length; i < gdes_c; i++) { | ||
| 1381 | if (this.gdes[i].gf != RrdGraphDesc.GF_DEF) { | ||
| 1382 | this.data_need_fetch.push(-1); | ||
| 1383 | continue; | ||
| 1384 | } | ||
| 1385 | |||
| 1386 | for (var ii = 0; ii < i; ii++) { | ||
| 1387 | if (this.gdes[ii].gf != RrdGraphDesc.GF_DEF) continue; | ||
| 1388 | if ((this.gdes[i].rrd === this.gdes[ii].rrd) | ||
| 1389 | && (this.gdes[i].cf === this.gdes[ii].cf) | ||
| 1390 | && (this.gdes[i].cf_reduce === this.gdes[ii].cf_reduce) | ||
| 1391 | && (this.gdes[i].start_orig === this.gdes[ii].start_orig) | ||
| 1392 | && (this.gdes[i].end_orig === this.gdes[ii].end_orig) | ||
| 1393 | && (this.gdes[i].step_orig === this.gdes[ii].step_orig)) { | ||
| 1394 | this.data_need_fetch.push(ii + 2); | ||
| 1395 | break; | ||
| 1396 | } | ||
| 1397 | } | ||
| 1398 | this.data_need_fetch.push(0); | ||
| 1399 | } | ||
| 1400 | |||
| 1401 | for (var i = 0, gdes_c = this.gdes.length; i < gdes_c; i++) { | ||
| 1402 | if (this.data_need_fetch[i] == 0) { | ||
| 1403 | this.data_need_fetch[i] = this.data.fetch_async(this.gdes[i], this.gdes[i].step, this.data_fetch_async_callback, {this: this, j:i}); | ||
| 1404 | } | ||
| 1405 | } | ||
| 1406 | }; | ||
| 1407 | |||
| 1321 | RrdGraph.prototype.data_fetch = function() | 1408 | RrdGraph.prototype.data_fetch = function() |
| 1322 | { | 1409 | { |
| 1323 | var skip; | 1410 | var skip; |
| @@ -2835,6 +2922,12 @@ RrdGraph.prototype.graph_paint = function () | |||
| 2835 | return this.graph_paint_draw() | 2922 | return this.graph_paint_draw() |
| 2836 | }; | 2923 | }; |
| 2837 | 2924 | ||
| 2925 | RrdGraph.prototype.graph_paint_async = function () | ||
| 2926 | { | ||
| 2927 | this.graph_paint_init() | ||
| 2928 | this.data_fetch_async() | ||
| 2929 | }; | ||
| 2930 | |||
| 2838 | RrdGraph.prototype.find_var = function(key) | 2931 | RrdGraph.prototype.find_var = function(key) |
| 2839 | { | 2932 | { |
| 2840 | for (var ii = 0, gdes_c = this.gdes.length; ii < gdes_c; ii++) { | 2933 | for (var ii = 0, gdes_c = this.gdes.length; ii < gdes_c; ii++) { |
