primitive.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource["dojox.charting.scaler.primitive"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.charting.scaler.primitive"] = true;
  8. dojo.provide("dojox.charting.scaler.primitive");
  9. dojox.charting.scaler.primitive = {
  10. buildScaler: function(/*Number*/ min, /*Number*/ max, /*Number*/ span, /*Object*/ kwArgs){
  11. if(min == max){
  12. // artificially extend bounds
  13. min -= 0.5;
  14. max += 0.5;
  15. // now the line will be centered
  16. }
  17. return {
  18. bounds: {
  19. lower: min,
  20. upper: max,
  21. from: min,
  22. to: max,
  23. scale: span / (max - min),
  24. span: span
  25. },
  26. scaler: dojox.charting.scaler.primitive
  27. };
  28. },
  29. buildTicks: function(/*Object*/ scaler, /*Object*/ kwArgs){
  30. return {major: [], minor: [], micro: []}; // Object
  31. },
  32. getTransformerFromModel: function(/*Object*/ scaler){
  33. var offset = scaler.bounds.from, scale = scaler.bounds.scale;
  34. return function(x){ return (x - offset) * scale; }; // Function
  35. },
  36. getTransformerFromPlot: function(/*Object*/ scaler){
  37. var offset = scaler.bounds.from, scale = scaler.bounds.scale;
  38. return function(x){ return x / scale + offset; }; // Function
  39. }
  40. };
  41. }