plot.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. var Util = require('../util/common');
  2. var Plot =
  3. /*#__PURE__*/
  4. function () {
  5. function Plot(cfg) {
  6. Util.mix(this, cfg);
  7. this._init();
  8. }
  9. var _proto = Plot.prototype;
  10. _proto._init = function _init() {
  11. var self = this;
  12. var start = self.start;
  13. var end = self.end;
  14. var xMin = Math.min(start.x, end.x);
  15. var xMax = Math.max(start.x, end.x);
  16. var yMin = Math.min(start.y, end.y);
  17. var yMax = Math.max(start.y, end.y);
  18. this.tl = {
  19. x: xMin,
  20. y: yMin
  21. };
  22. this.tr = {
  23. x: xMax,
  24. y: yMin
  25. };
  26. this.bl = {
  27. x: xMin,
  28. y: yMax
  29. };
  30. this.br = {
  31. x: xMax,
  32. y: yMax
  33. };
  34. this.width = xMax - xMin;
  35. this.height = yMax - yMin;
  36. };
  37. /**
  38. * reset
  39. * @param {Object} start start point
  40. * @param {Object} end end point
  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. _proto.isInRange = function isInRange(x, y) {
  54. if (Util.isObject(x)) {
  55. y = x.y;
  56. x = x.x;
  57. }
  58. var tl = this.tl;
  59. var br = this.br;
  60. return tl.x <= x && x <= br.x && tl.y <= y && y <= br.y;
  61. };
  62. return Plot;
  63. }();
  64. module.exports = Plot;