Changeset b2951c8a5d06fd47cdc24bb608defb3e643dabd6
 Timestamp:
 03/18/09 19:28:37
(6 years ago)
 Author:
 Theo Schlossnagle <jesus@omniti.com>
 gitcommitter:
 Theo Schlossnagle <jesus@omniti.com> 1237404517 +0000
 gitparent:
[2930d0d6c8d84ea66a26975dd8db10b246042ecf]
 gitauthor:
 Theo Schlossnagle <jesus@omniti.com> 1237404517 +0000
 Message:
hackery to get axis to have more precision

Files:

Legend:
 Unmodified
 Added
 Removed
 Modified
 Copied
 Moved
r2930d0d 
rb2951c8 

451  451  // estimate number of ticks 

452  452  var noTicks; 

 453  var dataManip = null; 

453  454  if (typeof axisOptions.ticks == "number" && axisOptions.ticks > 0) 

454  455  noTicks = axisOptions.ticks; 

…  …  
457  458  else 

458  459  noTicks = canvasHeight / 60; 

459   

460   var delta = (axis.max  axis.min) / noTicks; 

 460  

 461  for(var i=0; i<series.length; i++) { 

 462  if(series[i].yaxis == axes.yaxis && 

 463  series[i].dataManip) { 

 464  dataManip = series[i].dataManip; 

 465  break; 

 466  } 

 467  } 

 468  var delta = (axis.max  axis.min); 

 469  delta /= noTicks; 

461  470  var size, generator, unit, formatter, i, magn, norm; 

462  471  

…  …  
660  669  } 

661  670  else { 

 671  var manip_delta = delta; 

 672  if(axis == axes.yaxis && dataManip) { 

 673  var abs_max = Math.max(Math.abs(axis.max), Math.abs(axis.min)); 

 674  var dmo = { _max: abs_max }; 

 675  manip_delta *= noTicks; 

 676  manip_delta = Math.abs(dataManip(manip_delta, dmo)); 

 677  manip_delta /= noTicks; 

 678  } 

662  679  // pretty rounding of base10 numbers 

663  680  var maxDec = axisOptions.tickDecimals; 

664  681  var dec = Math.floor(Math.log(delta) / Math.LN10); 

 682  var manip_dec = Math.floor(Math.log(manip_delta) / Math.LN10); 

 683  

665  684  if (maxDec != null && dec > maxDec) 

666  685  dec = maxDec; 

 686  if (maxDec != null && manip_dec > maxDec) 

 687  manip_dec = maxDec; 

667  688  

668  689  magn = Math.pow(10, dec); 

669  690  norm = delta / magn; // norm is between 1.0 and 10.0 

670  691  

 692  // for manip_dec, we only care about the case that changes dec 

 693  var manip_norm = manip_delta / Math.pow(10, manip_dec); 

 694  if(manip_norm < 3 && manip_norm > 2.25 && 

 695  (maxDec == null  manip_dec + 1 <= maxDec)) 

 696  ++manip_dec; 

 697  

671  698  if (norm < 1.5) 

672  699  size = 1; 

…  …  
692  719  size = axisOptions.tickSize; 

693  720  

694   axis.tickDecimals = Math.max(0, (maxDec != null) ? maxDec : dec); 

 721  axis.tickDecimals = Math.max(0, (maxDec != null) ? maxDec : manip_dec); 

695  722  

696  723  generator = function (axis) { 

r0693191 
rb2951c8 

40  40  

41  41  function rpn_magic(expr) { 

42   return function(value) { 

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

 42  return function(value, o) { 

 43  return rpn_eval(value, expr, (o != null) ? o : {}); 

44  44  }; 

45  45  } 

46  46  function rpn_eval(value, expr, meta) { 

47   s = []; 

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

 47  var s = []; 

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

49  49  s.unshift(value) 

50   

51   for (i = 0; i < ops.length; i++) { 

52   op = ops[i]; 

 50  for (var i = 0; i < ops.length; i++) { 

 51  var opname = ops[i]; 

 52  if(meta && meta[opname]) 

 53  for(var j = 0; j < meta[opname].length; j++) 

 54  ops.splice(i, (j==0) ? 1 : 0, meta[opname][j]); 

 55  } 

 56  

 57  for (var i = 0; i < ops.length; i++) { 

 58  op = ops[i]; 

53  59  

54  60  switch(op) { 

…  …  
88  94  s.unshift(l / r); 

89  95  break; 

 96  case '~': 

 97  s.shift(); break; 

90  98  case '.': 

91  99  s.unshift(s[s.shift()]); break; 

…  …  
96  104  case 'auto': 

97  105  var units = 1; 

98   if(meta && meta.max) { 

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

 106  if(meta && meta._max) { 

 107  units = Math.pow(1000,Math.floor(Math.log(meta._max)/Math.log(1000))) 

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

101  109  } 

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

217  225  } 

218   if(ddata[i].reconnoiter_display_expression) { 

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

220   } 

221  226  } //end if ydata was a number 

222  227  

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

331  336  ddata[i].reconnoiter_display_expression) { 

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

333   Math.abs(axis.datamin)) 

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

 338  Math.abs(axis.datamin)), 

 339  // for delta calc, we don't want to 

 340  // lose precision 

 341  floor: ['.'], ciel: ['.'], round: ['~','.'] 

334  342  }, 

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

 344  console.log(pval); 

336  345  return pval.toFixed(axis.tickDecimals) + 

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