plot.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. "use strict";
  2. exports.__esModule = true;
  3. exports["default"] = void 0;
  4. var _common = require("../util/common");
  5. var Plot = /*#__PURE__*/function () {
  6. function Plot(cfg) {
  7. (0, _common.mix)(this, cfg);
  8. this._init();
  9. }
  10. var _proto = Plot.prototype;
  11. _proto._init = function _init() {
  12. var self = this;
  13. var start = self.start;
  14. var end = self.end;
  15. var xMin = Math.min(start.x, end.x);
  16. var xMax = Math.max(start.x, end.x);
  17. var yMin = Math.min(start.y, end.y);
  18. var yMax = Math.max(start.y, end.y);
  19. this.tl = {
  20. x: xMin,
  21. y: yMin
  22. };
  23. this.tr = {
  24. x: xMax,
  25. y: yMin
  26. };
  27. this.bl = {
  28. x: xMin,
  29. y: yMax
  30. };
  31. this.br = {
  32. x: xMax,
  33. y: yMax
  34. };
  35. this.width = xMax - xMin;
  36. this.height = yMax - yMin;
  37. }
  38. /**
  39. * reset
  40. * @param {Object} start start point
  41. * @param {Object} end end point
  42. */
  43. ;
  44. _proto.reset = function reset(start, end) {
  45. this.start = start;
  46. this.end = end;
  47. this._init();
  48. }
  49. /**
  50. * check the point is in the range of plot
  51. * @param {Number} x x value
  52. * @param {[type]} y y value
  53. * @return {Boolean} return the result
  54. */
  55. ;
  56. _proto.isInRange = function isInRange(x, y) {
  57. if ((0, _common.isObject)(x)) {
  58. y = x.y;
  59. x = x.x;
  60. }
  61. var tl = this.tl;
  62. var br = this.br;
  63. return tl.x <= x && x <= br.x && tl.y <= y && y <= br.y;
  64. };
  65. return Plot;
  66. }();
  67. var _default = Plot;
  68. exports["default"] = _default;