line.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  2. var Shape = require('../shape');
  3. var bbox = require('../util/bbox');
  4. var Line =
  5. /*#__PURE__*/
  6. function (_Shape) {
  7. _inheritsLoose(Line, _Shape);
  8. function Line() {
  9. return _Shape.apply(this, arguments) || this;
  10. }
  11. var _proto = Line.prototype;
  12. _proto._initProperties = function _initProperties() {
  13. _Shape.prototype._initProperties.call(this);
  14. this._attrs.canStroke = true;
  15. this._attrs.type = 'line';
  16. };
  17. _proto.getDefaultAttrs = function getDefaultAttrs() {
  18. return {
  19. x1: 0,
  20. y1: 0,
  21. x2: 0,
  22. y2: 0,
  23. lineWidth: 1
  24. };
  25. };
  26. _proto.createPath = function createPath(context) {
  27. var attrs = this.get('attrs');
  28. var x1 = attrs.x1,
  29. y1 = attrs.y1,
  30. x2 = attrs.x2,
  31. y2 = attrs.y2;
  32. context.beginPath();
  33. context.moveTo(x1, y1);
  34. context.lineTo(x2, y2);
  35. };
  36. _proto.calculateBox = function calculateBox() {
  37. var attrs = this.get('attrs');
  38. var x1 = attrs.x1,
  39. y1 = attrs.y1,
  40. x2 = attrs.x2,
  41. y2 = attrs.y2,
  42. lineWidth = attrs.lineWidth;
  43. return bbox.getBBoxFromLine(x1, y1, x2, y2, lineWidth);
  44. };
  45. return Line;
  46. }(Shape);
  47. Shape.Line = Line;
  48. module.exports = Line;