Changeset 06931918adf7389a94684c1dec761f8f6928fba5
 Timestamp:
 03/18/09 15:08:41
(6 years ago)
 Author:
 Theo Schlossnagle <jesus@omniti.com>
 gitcommitter:
 Theo Schlossnagle <jesus@omniti.com> 1237388921 +0000
 gitparent:
[4b3147df2added647239fec9b82e62855afa487b]
 gitauthor:
 Theo Schlossnagle <jesus@omniti.com> 1237388921 +0000
 Message:
add onthefly data postprocessing to flot, hook up the rpn stuff

Files:

Legend:
 Unmodified
 Added
 Removed
 Modified
 Copied
 Moved
r4b3147d 
r0693191 

315  315  

316  316  var x = data[j][0], y = data[j][1]; 

 317  if(series[i].dataManip) y = series[i].dataManip(y); 

317  318  

318  319  // convert to number 

…  …  
1075  1076  

1076  1077  function drawSeriesLines(series) { 

1077   function plotLine(data, offset, axisx, axisy) { 

 1078  function plotLine(data, offset, axisx, axisy, dataManip) { 

1078  1079  var prev, cur = null, drawx = null, drawy = null; 

1079  1080  

…  …  
1081  1082  for (var i = 0; i < data.length; ++i) { 

1082  1083  prev = cur; 

1083   cur = data[i]; 

 1084  cur = [data[i][0], data[i][1]]; 

 1085  if(dataManip) cur[1] = dataManip(cur[1]); 

1084  1086  

1085  1087  if (prev == null  cur == null) 

…  …  
1156  1158  } 

1157  1159  

1158   function plotLineArea(data, axisx, axisy) { 

 1160  function plotLineArea(data, axisx, axisy, dataManip) { 

1159  1161  var prev, cur = null; 

1160  1162  

…  …  
1166  1168  for (var i = 0; i < data.length; ++i) { 

1167  1169  prev = cur; 

1168   cur = data[i]; 

 1170  cur = [data[i][0], data[i][1]]; 

 1171  if(dataManip) cur[1] = dataManip(cur[1]); 

1169  1172  

1170  1173  if (areaOpen && prev != null && cur == null) { 

…  …  
1306  1309  ctx.lineWidth = sw / 2; 

1307  1310  ctx.strokeStyle = "rgba(0,0,0,0.1)"; 

1308   plotLine(series.data, lw/2 + sw/2 + ctx.lineWidth/2, series.xaxis, series.yaxis); 

 1311  plotLine(series.data, lw/2 + sw/2 + ctx.lineWidth/2, series.xaxis, series.yaxis, series.dataManip); 

1309  1312  

1310  1313  ctx.lineWidth = sw / 2; 

1311  1314  ctx.strokeStyle = "rgba(0,0,0,0.2)"; 

1312   plotLine(series.data, lw/2 + ctx.lineWidth/2, series.xaxis, series.yaxis); 

 1315  plotLine(series.data, lw/2 + ctx.lineWidth/2, series.xaxis, series.yaxis, series.dataManip); 

1313  1316  } 

1314  1317  

…  …  
1317  1320  setFillStyle(series.lines, series.color); 

1318  1321  if (series.lines.fill) 

1319   plotLineArea(series.data, series.xaxis, series.yaxis); 

1320   plotLine(series.data, 0, series.xaxis, series.yaxis); 

 1322  plotLineArea(series.data, series.xaxis, series.yaxis, series.dataManip); 

 1323  plotLine(series.data, 0, series.xaxis, series.yaxis, series.dataManip); 

1321  1324  ctx.restore(); 

1322  1325  } 

1323  1326  

1324  1327  function drawSeriesPoints(series) { 

1325   function plotPoints(data, radius, fill, axisx, axisy) { 

 1328  function plotPoints(data, radius, fill, axisx, axisy, dataManip) { 

1326  1329  for (var i = 0; i < data.length; ++i) { 

1327  1330  if (data[i] == null) 

…  …  
1329  1332  

1330  1333  var x = data[i][0], y = data[i][1]; 

 1334  if(dataManip) y = dataManip(y); 

1331  1335  if (x < axisx.min  x > axisx.max  y < axisy.min  y > axisy.max) 

1332  1336  continue; 

…  …  
1340  1344  } 

1341  1345  

1342   function plotPointShadows(data, offset, radius, axisx, axisy) { 

 1346  function plotPointShadows(data, offset, radius, axisx, axisy, dataManip) { 

1343  1347  for (var i = 0; i < data.length; ++i) { 

1344  1348  if (data[i] == null) 

…  …  
1346  1350  

1347  1351  var x = data[i][0], y = data[i][1]; 

 1352  if(dataManip) y = dataManip(y); 

1348  1353  if (x < axisx.min  x > axisx.max  y < axisy.min  y > axisy.max) 

1349  1354  continue; 

…  …  
1364  1369  ctx.strokeStyle = "rgba(0,0,0,0.1)"; 

1365  1370  plotPointShadows(series.data, sw/2 + ctx.lineWidth/2, 

1366   series.points.radius, series.xaxis, series.yaxis); 

 1371  series.points.radius, series.xaxis, series.yaxis, 

 1372  series.dataManip); 

1367  1373  

1368  1374  ctx.lineWidth = sw / 2; 

1369  1375  ctx.strokeStyle = "rgba(0,0,0,0.2)"; 

1370  1376  plotPointShadows(series.data, ctx.lineWidth/2, 

1371   series.points.radius, series.xaxis, series.yaxis); 

 1377  series.points.radius, series.xaxis, series.yaxis, 

 1378  series.dataManip); 

1372  1379  } 

1373  1380  

…  …  
1376  1383  setFillStyle(series.points, series.color); 

1377  1384  plotPoints(series.data, series.points.radius, series.points.fill, 

1378   series.xaxis, series.yaxis); 

 1385  series.xaxis, series.yaxis, series.dataManip); 

1379  1386  ctx.restore(); 

1380  1387  } 

…  …  
1459  1466  

1460  1467  function drawSeriesBars(series) { 

1461   function plotBars(data, barLeft, barRight, offset, fill, axisx, axisy) { 

 1468  function plotBars(data, barLeft, barRight, offset, fill, axisx, axisy, dataManip) { 

1462  1469  for (var i = 0; i < data.length; i++) { 

1463  1470  if (data[i] == null) 

1464  1471  continue; 

1465   drawBar(data[i][0], data[i][1], barLeft, barRight, offset, fill, axisx, axisy, ctx); 

 1472  var y = data[i][1]; 

 1473  if(dataManip) y = dataManip(y); 

 1474  drawBar(data[i][0], y, barLeft, barRight, offset, fill, axisx, axisy, ctx); 

1466  1475  } 

1467  1476  } 

…  …  
1491  1500  setFillStyle(series.bars, series.color); 

1492  1501  var barLeft = series.bars.align == "left" ? 0 : series.bars.barWidth/2; 

1493   plotBars(series.data, barLeft, barLeft + series.bars.barWidth, 0, series.bars.fill, series.xaxis, series.yaxis); 

 1502  plotBars(series.data, barLeft, barLeft + series.bars.barWidth, 0, series.bars.fill, series.xaxis, series.yaxis, series.dataManip); 

1494  1503  ctx.restore(); 

1495  1504  } 

…  …  
1633  1642  

1634  1643  var x = data[j][0], y = data[j][1]; 

 1644  if(series[i].dataManip) y = series[i].dataManip(y); 

1635  1645  

1636  1646  if (checkbar) { 

rd63f273 
r0693191 

39  39  } 

40  40  

41   function rpn_eval(value, expr) { 

 41  function rpn_magic(expr) { 

 42  return function(value) { 

 43  return rpn_eval(value, expr, {}); 

 44  }; 

 45  } 

 46  function rpn_eval(value, expr, meta) { 

42  47  s = []; 

43  48  ops = expr.split(","); 

…  …  
89  94  case '*': 

90  95  s.unshift(s.shift() * s.shift()); break; 

91   // Not implemented 

92   // case 'auto': 

93   // s.unshift( $this>autounits(s.shift())); break; 

 96  case 'auto': 

 97  var units = 1; 

 98  if(meta && meta.max) { 

 99  units = Math.pow(1000,Math.floor(Math.log(meta.max)/Math.log(1000))) 

 100  if(units == 0) units = 1; 

 101  } 

 102  switch(units) { 

 103  case 0.000000001: meta.suffix = 'n'; break; 

 104  case 0.000001: meta.suffix = 'u'; break; 

 105  case 0.001: meta.suffix = 'm'; break; 

 106  case 1000: meta.suffix = 'k'; break; 

 107  case 1000000: meta.suffix = 'M'; break; 

 108  case 1000000000: meta.suffix = 'G'; break; 

 109  case 1000000000000: meta.suffix = 'T'; break; 

 110  default: meta.suffic = null; break; 

 111  } 

 112  s.unshift( s.shift() / units ); 

 113  break; 

94  114  case 'min': 

95  115  s.unshift(min(s.shift(),s.shift())); break; 

…  …  
102  122  } 

103  123  } 

104   value = s.shift(); 

105   return value; 

 124  var newvalue = s.shift(); 

 125  return newvalue; 

106  126  } 

107  127  

…  …  
194  214  if(tdata[1]!=''){ 

195  215  if(ddata[i].reconnoiter_source_expression) { 

196   tdata[1] = rpn_eval(tdata[1], ddata[i].reconnoiter_source_expression); 

 216  tdata[1] = rpn_eval(tdata[1], ddata[i].reconnoiter_source_expression, {}); 

197  217  } 

198  218  if(ddata[i].reconnoiter_display_expression) { 

199   tdata[1] = rpn_eval(tdata[1], ddata[i].reconnoiter_display_expression); 

 219  tdata[1] = rpn_eval(tdata[1], ddata[i].reconnoiter_display_expression, {}); 

200  220  } 

201  221  } //end if ydata was a number 

…  …  
297  317  }; 

298  318  })(this)); 

 319  

299  320  if(!r.options.grid) r.options.grid = {}; 

300  321  r.options.grid.hoverable = true; 

…  …  
305  326  r.options.grid.hoverXOnly = true; 

306  327  if(!r.options.yaxis) r.options.yaxis = {}; 

307   if(r.options.yaxis.suffix) 

308   r.options.yaxis.tickFormatter = function (val, axis) { 

309   return val.toFixed(axis.tickDecimals) + r.options.yaxis.suffix; 

310   }; 

 328  r.options.yaxis.tickFormatter = function (val, axis) { 

 329  for(var i=0; i<ddata.length; i++) { 

 330  if(ddata[i].yaxis == 1 && 

 331  ddata[i].reconnoiter_display_expression) { 

 332  var meta = { max: Math.max(Math.abs(axis.datamax), 

 333  Math.abs(axis.datamin)) 

 334  }, 

 335  pval = rpn_eval(val, ddata[i].reconnoiter_display_expression, meta); 

 336  return pval.toFixed(axis.tickDecimals) + 

 337  ((meta.suffix != null) ? meta.suffix : ''); 

 338  } 

 339  } 

 340  return val.toFixed(axis.tickDecimals); 

 341  }; 

311  342  r.options.xaxis.localtime = true; 

 343  

312  344  doptions = r.options; 

313  345  dplaceholder = placeholder; 

314  346  ddata = r.data; 

 347  for(var i=0; i<r.data.length; i++) { 

 348  if(r.data[i].reconnoiter_display_expression) 

 349  r.data[i].dataManip = rpn_magic(r.data[i].reconnoiter_display_expression); 

 350  } 

315  351  

316  352  var plot = this.flot_plot = $.plot(placeholder, r.data, r.options); 
