rect.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
  4. var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
  5. var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
  6. function _createSuper(Derived) { return function () { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (_isNativeReflectConstruct()) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
  7. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  8. var Util = require('../../util/common');
  9. var GuideBase = require('./base');
  10. var Rect = /*#__PURE__*/function (_GuideBase) {
  11. (0, _inheritsLoose2["default"])(Rect, _GuideBase);
  12. var _super = _createSuper(Rect);
  13. function Rect() {
  14. return _GuideBase.apply(this, arguments) || this;
  15. }
  16. var _proto = Rect.prototype;
  17. _proto._initDefaultCfg = function _initDefaultCfg() {
  18. this.type = 'rect';
  19. this.start = [];
  20. this.end = [];
  21. this.style = {
  22. fill: '#CCD7EB',
  23. opacity: 0.4
  24. };
  25. };
  26. _proto.render = function render(coord, container) {
  27. var start = this.parsePoint(coord, this.start);
  28. var end = this.parsePoint(coord, this.end);
  29. if (!start || !end) {
  30. return;
  31. }
  32. var shape = container.addShape('rect', {
  33. className: 'guide-rect',
  34. attrs: Util.mix({
  35. x: Math.min(start.x, end.x),
  36. y: Math.min(start.y, end.y),
  37. width: Math.abs(end.x - start.x),
  38. height: Math.abs(start.y - end.y)
  39. }, this.style)
  40. });
  41. this.element = shape;
  42. return shape;
  43. };
  44. return Rect;
  45. }(GuideBase);
  46. GuideBase.Rect = Rect;
  47. module.exports = Rect;