base.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. "use strict";
  2. exports.__esModule = true;
  3. exports["default"] = void 0;
  4. var _common = require("../util/common");
  5. var _matrix = _interopRequireDefault(require("../graphic/util/matrix"));
  6. var _vector = _interopRequireDefault(require("../graphic/util/vector2"));
  7. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  8. var defaultMatrix = [1, 0, 0, 1, 0, 0];
  9. var Base = /*#__PURE__*/function () {
  10. var _proto = Base.prototype;
  11. _proto._initDefaultCfg = function _initDefaultCfg() {};
  12. function Base(cfg) {
  13. this._initDefaultCfg();
  14. (0, _common.mix)(this, cfg);
  15. var start;
  16. var end;
  17. if (this.plot) {
  18. start = this.plot.bl;
  19. end = this.plot.tr;
  20. this.start = start;
  21. this.end = end;
  22. } else {
  23. start = this.start;
  24. end = this.end;
  25. }
  26. this.init(start, end);
  27. }
  28. _proto._scale = function _scale(s1, s2) {
  29. var matrix = this.matrix;
  30. var center = this.center;
  31. _matrix["default"].translate(matrix, matrix, [center.x, center.y]);
  32. _matrix["default"].scale(matrix, matrix, [s1, s2]);
  33. _matrix["default"].translate(matrix, matrix, [-center.x, -center.y]);
  34. };
  35. _proto.init = function init(start, end) {
  36. this.matrix = [].concat(defaultMatrix); // 设置中心点
  37. this.center = {
  38. x: (end.x - start.x) / 2 + start.x,
  39. y: (end.y - start.y) / 2 + start.y
  40. };
  41. if (this.scale) {
  42. this._scale(this.scale[0], this.scale[1]);
  43. }
  44. };
  45. _proto.convertPoint = function convertPoint(point) {
  46. var _this$_convertPoint = this._convertPoint(point),
  47. x = _this$_convertPoint.x,
  48. y = _this$_convertPoint.y;
  49. if (!_matrix["default"].isChanged(this.matrix)) {
  50. return {
  51. x: x,
  52. y: y
  53. };
  54. }
  55. var vector = [x, y];
  56. _vector["default"].transformMat2d(vector, vector, this.matrix);
  57. return {
  58. x: vector[0],
  59. y: vector[1]
  60. };
  61. };
  62. _proto.invertPoint = function invertPoint(point) {
  63. return this._invertPoint(point);
  64. };
  65. _proto._convertPoint = function _convertPoint(point) {
  66. return point;
  67. };
  68. _proto._invertPoint = function _invertPoint(point) {
  69. return point;
  70. };
  71. _proto.reset = function reset(plot) {
  72. this.plot = plot;
  73. var bl = plot.bl,
  74. tr = plot.tr;
  75. this.start = bl;
  76. this.end = tr;
  77. this.init(bl, tr);
  78. };
  79. return Base;
  80. }();
  81. var _default = Base;
  82. exports["default"] = _default;