line.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 Shape = require('../shape');
  9. var bbox = require('../util/bbox');
  10. var Line = /*#__PURE__*/function (_Shape) {
  11. (0, _inheritsLoose2["default"])(Line, _Shape);
  12. var _super = _createSuper(Line);
  13. function Line() {
  14. return _Shape.apply(this, arguments) || this;
  15. }
  16. var _proto = Line.prototype;
  17. _proto._initProperties = function _initProperties() {
  18. _Shape.prototype._initProperties.call(this);
  19. this._attrs.canStroke = true;
  20. this._attrs.type = 'line';
  21. };
  22. _proto.getDefaultAttrs = function getDefaultAttrs() {
  23. return {
  24. x1: 0,
  25. y1: 0,
  26. x2: 0,
  27. y2: 0,
  28. lineWidth: 1
  29. };
  30. };
  31. _proto.createPath = function createPath(context) {
  32. var attrs = this.get('attrs');
  33. var x1 = attrs.x1,
  34. y1 = attrs.y1,
  35. x2 = attrs.x2,
  36. y2 = attrs.y2;
  37. context.beginPath();
  38. context.moveTo(x1, y1);
  39. context.lineTo(x2, y2);
  40. };
  41. _proto.calculateBox = function calculateBox() {
  42. var attrs = this.get('attrs');
  43. var x1 = attrs.x1,
  44. y1 = attrs.y1,
  45. x2 = attrs.x2,
  46. y2 = attrs.y2,
  47. lineWidth = attrs.lineWidth;
  48. return bbox.getBBoxFromLine(x1, y1, x2, y2, lineWidth);
  49. };
  50. return Line;
  51. }(Shape);
  52. Shape.Line = Line;
  53. module.exports = Line;