base.js 2.0 KB

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