plot.js 1.4 KB

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