translator1d.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /**
  2. * DevExtreme (viz/translators/translator1d.js)
  3. * Version: 19.1.16
  4. * Build date: Tue Oct 18 2022
  5. *
  6. * Copyright (c) 2012 - 2022 Developer Express Inc. ALL RIGHTS RESERVED
  7. * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
  8. */
  9. "use strict";
  10. var _Number = Number;
  11. function Translator1D() {
  12. this.setDomain(arguments[0], arguments[1]).setCodomain(arguments[2], arguments[3])
  13. }
  14. Translator1D.prototype = {
  15. constructor: Translator1D,
  16. setDomain: function(domain1, domain2) {
  17. var that = this;
  18. that._domain1 = _Number(domain1);
  19. that._domain2 = _Number(domain2);
  20. that._domainDelta = that._domain2 - that._domain1;
  21. return that
  22. },
  23. setCodomain: function(codomain1, codomain2) {
  24. var that = this;
  25. that._codomain1 = _Number(codomain1);
  26. that._codomain2 = _Number(codomain2);
  27. that._codomainDelta = that._codomain2 - that._codomain1;
  28. return that
  29. },
  30. getDomain: function() {
  31. return [this._domain1, this._domain2]
  32. },
  33. getCodomain: function() {
  34. return [this._codomain1, this._codomain2]
  35. },
  36. getDomainStart: function() {
  37. return this._domain1
  38. },
  39. getDomainEnd: function() {
  40. return this._domain2
  41. },
  42. getCodomainStart: function() {
  43. return this._codomain1
  44. },
  45. getCodomainEnd: function() {
  46. return this._codomain2
  47. },
  48. getDomainRange: function() {
  49. return this._domainDelta
  50. },
  51. getCodomainRange: function() {
  52. return this._codomainDelta
  53. },
  54. translate: function(value) {
  55. var ratio = (_Number(value) - this._domain1) / this._domainDelta;
  56. return 0 <= ratio && ratio <= 1 ? this._codomain1 + ratio * this._codomainDelta : NaN
  57. },
  58. adjust: function(value) {
  59. var ratio = (_Number(value) - this._domain1) / this._domainDelta;
  60. var result = NaN;
  61. if (ratio < 0) {
  62. result = this._domain1
  63. } else {
  64. if (ratio > 1) {
  65. result = this._domain2
  66. } else {
  67. if (0 <= ratio && ratio <= 1) {
  68. result = _Number(value)
  69. }
  70. }
  71. }
  72. return result
  73. }
  74. };
  75. exports.Translator1D = Translator1D;