polygon.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 Polygon =
  5. /*#__PURE__*/
  6. function (_Shape) {
  7. _inheritsLoose(Polygon, _Shape);
  8. function Polygon() {
  9. return _Shape.apply(this, arguments) || this;
  10. }
  11. var _proto = Polygon.prototype;
  12. _proto._initProperties = function _initProperties() {
  13. _Shape.prototype._initProperties.call(this);
  14. this._attrs.canFill = true;
  15. this._attrs.canStroke = true;
  16. this._attrs.type = 'polygon';
  17. };
  18. _proto.getDefaultAttrs = function getDefaultAttrs() {
  19. return {
  20. points: null,
  21. lineWidth: 0
  22. };
  23. };
  24. _proto.createPath = function createPath(context) {
  25. var self = this;
  26. var attrs = self.get('attrs');
  27. var points = attrs.points;
  28. context.beginPath();
  29. for (var i = 0, len = points.length; i < len; i++) {
  30. var point = points[i];
  31. if (i === 0) {
  32. context.moveTo(point.x, point.y);
  33. } else {
  34. context.lineTo(point.x, point.y);
  35. }
  36. }
  37. context.closePath();
  38. };
  39. _proto.calculateBox = function calculateBox() {
  40. var attrs = this.get('attrs');
  41. var points = attrs.points;
  42. return bbox.getBBoxFromPoints(points);
  43. };
  44. return Polygon;
  45. }(Shape);
  46. Shape.Polygon = Polygon;
  47. module.exports = Polygon;